mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-10 19:00:08 +00:00
broadway: Add color nodes
This commit is contained in:
parent
cfdb3952c6
commit
0b38ab339e
@ -11,6 +11,7 @@ typedef struct {
|
||||
typedef enum { /* Sync changes with broadway.js */
|
||||
BROADWAY_NODE_TEXTURE,
|
||||
BROADWAY_NODE_CONTAINER,
|
||||
BROADWAY_NODE_COLOR,
|
||||
} BroadwayNodeType;
|
||||
|
||||
typedef enum {
|
||||
|
@ -347,6 +347,31 @@ SwapNodes.prototype.handle_node = function(parent, node_data, data_pos)
|
||||
data_pos = this.handle_node(parent, node_data, data_pos);
|
||||
}
|
||||
break;
|
||||
|
||||
case 2: // COLOR
|
||||
var x = node_data[data_pos++];
|
||||
var y = node_data[data_pos++];
|
||||
var width = node_data[data_pos++];
|
||||
var height = node_data[data_pos++];
|
||||
var rgba = node_data[data_pos++];
|
||||
var div = document.createElement('div');
|
||||
div.style["position"] = "absolute";
|
||||
div.style["left"] = x + "px";
|
||||
div.style["top"] = y + "px";
|
||||
div.style["width"] = width + "px";
|
||||
div.style["height"] = height + "px";
|
||||
a = (rgba >> 24) & 0xff;
|
||||
r = (rgba >> 16) & 0xff;
|
||||
g = (rgba >> 8) & 0xff;
|
||||
b = (rgba >> 0) & 0xff;
|
||||
if (a == 0)
|
||||
c = "rgb(" + r + "," + g + "," + b + ")";
|
||||
else
|
||||
c = "rgba(" + r + "," + g + "," + b + "," + (a / 255.0) + ")";
|
||||
div.style["background-color"] = c;
|
||||
parent.appendChild(div);
|
||||
break;
|
||||
|
||||
default:
|
||||
alert("Unexpected node type " + type);
|
||||
}
|
||||
|
@ -226,6 +226,9 @@ rewrite_node_textures (BroadwayClient *client,
|
||||
|
||||
type = data[pos++];
|
||||
switch (type) {
|
||||
case BROADWAY_NODE_COLOR:
|
||||
pos += 5;
|
||||
break;
|
||||
case BROADWAY_NODE_TEXTURE:
|
||||
data[pos+4] = GPOINTER_TO_INT (g_hash_table_lookup (client->textures,
|
||||
GINT_TO_POINTER (data[pos+4])));
|
||||
|
@ -89,6 +89,24 @@ add_uint32 (GArray *nodes, guint32 v)
|
||||
g_array_append_val (nodes, v);
|
||||
}
|
||||
|
||||
static guint32
|
||||
rgba_to_uint32 (const GdkRGBA *rgba)
|
||||
{
|
||||
return
|
||||
((guint32)(0.5 + CLAMP (rgba->alpha, 0., 1.) * 255.) << 24) |
|
||||
((guint32)(0.5 + CLAMP (rgba->red, 0., 1.) * 255.) << 16) |
|
||||
((guint32)(0.5 + CLAMP (rgba->green, 0., 1.) * 255.) << 8) |
|
||||
((guint32)(0.5 + CLAMP (rgba->blue, 0., 1.) * 255.) << 0);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
add_rgba (GArray *nodes, const GdkRGBA *rgba)
|
||||
{
|
||||
guint32 c = rgba_to_uint32 (rgba);
|
||||
g_array_append_val (nodes, c);
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_broadway_renderer_add_node (GskRenderer *self,
|
||||
GArray *nodes,
|
||||
@ -96,6 +114,10 @@ gsk_broadway_renderer_add_node (GskRenderer *self,
|
||||
GskRenderNode *node)
|
||||
{
|
||||
GdkDisplay *display = gsk_renderer_get_display (self);
|
||||
int x = floorf (node->bounds.origin.x);
|
||||
int y = floorf (node->bounds.origin.y);
|
||||
int width = ceil (node->bounds.origin.x + node->bounds.size.width) - x;
|
||||
int height = ceil (node->bounds.origin.y + node->bounds.size.height) - y;
|
||||
|
||||
switch (gsk_render_node_get_node_type (node))
|
||||
{
|
||||
@ -115,12 +137,20 @@ gsk_broadway_renderer_add_node (GskRenderer *self,
|
||||
}
|
||||
return;
|
||||
|
||||
case GSK_COLOR_NODE:
|
||||
{
|
||||
|
||||
add_uint32 (nodes, BROADWAY_NODE_COLOR);
|
||||
add_uint32 (nodes, x);
|
||||
add_uint32 (nodes, y);
|
||||
add_uint32 (nodes, width);
|
||||
add_uint32 (nodes, height);
|
||||
add_rgba (nodes, gsk_color_node_peek_color (node));
|
||||
}
|
||||
return;
|
||||
|
||||
default:
|
||||
{
|
||||
int x = floorf (node->bounds.origin.x);
|
||||
int y = floorf (node->bounds.origin.y);
|
||||
int width = ceil (node->bounds.origin.x + node->bounds.size.width) - x;
|
||||
int height = ceil (node->bounds.origin.y + node->bounds.size.height) - y;
|
||||
cairo_surface_t *surface;
|
||||
GdkTexture *texture;
|
||||
guint32 texture_id;
|
||||
|
Loading…
Reference in New Issue
Block a user