Browse Source

Cleanup

master
Patrick Jakobsen 7 months ago
parent
commit
fe179f2eee
1 changed files with 55 additions and 103 deletions
  1. +55
    -103
      gui/gui.c

+ 55
- 103
gui/gui.c View File

@ -1566,7 +1566,6 @@ void test_gui__scrollbars(
gui_push_parent(context, scrollbox_layout);
{
static GUI_Node_Reference scrollregion_layout = {0};
static GUI_Node_Reference scrollbar_layout = {0};
static GUI_Size scrollregion_size[2] = {
{GUI_SIZERULE_PERCENTOFPARENT, 90, 100},
{GUI_SIZERULE_PERCENTOFPARENT, 100, 100}};
@ -1613,6 +1612,7 @@ void test_gui__scrollbars(
} gui_pop_subtree(context);
#endif
#if 0
static GUI_Node_Reference scrollbar_layout = {0};
scrollbar_layout = gui_layout(
context, scrollbar_layout, GUI_LAYOUT_VERTICAL,
&outer_style, scrollbar_size);
@ -2121,13 +2121,8 @@ void fill_pixel_buffer(
}
}
}
void draw_pixel_buffer(
unsigned int width,
unsigned int height,
Display *game_display,
Window game_window,
XImage *game_image,
GC x_graphics_context)
void draw_window(
X11_Window *xwindow)
{
/*
int XPutImage(Display *display, Drawable d, GC gc, XImage *image, int src_x, int src_y, int
@ -2135,13 +2130,13 @@ void draw_pixel_buffer(
*/
int error = XPutImage(
game_display,
game_window,
x_graphics_context,
game_image,
xwindow->display,
xwindow->window,
xwindow->graphics_context,
xwindow->screen_image,
0, 0,
0, 0,
width, height);
xwindow->width, xwindow->height);
assert(error == 0);
}
@ -3114,7 +3109,7 @@ int init_x11(
XImage *game_image = XCreateImage(
XImage *screen_image = XCreateImage(
xwindow->display,
xwindow->visual,
XDefaultDepth(xwindow->display, xwindow->screen),
@ -3128,35 +3123,14 @@ int init_x11(
8, // NOTE(Zelaven): No clue
// NOTE(Zelaven): This is how many bytes there are in a row of pixels.
xwindow->width * sizeof(uint32_t));
assert(game_image != NULL);
fill_pixel_buffer(
pixels,
xwindow->width,
xwindow->height,
0,
0);
draw_rect(
pixels,
xwindow->width,
xwindow->height,
20, 40, 25, 50,
0xFFFF00);
GUI_Draw_Command my_draw_command = {
.rectangle = {60, 60, 100, 90},
.color = 0xFF00FF,
};
assert(screen_image != NULL);
xwindow->pixel_buffer = (Pixel_Buffer){
.pixels = (GUI_Color*)pixels,
.width = xwindow->width,
.height = xwindow->height,
};
draw_rect2(
&xwindow->pixel_buffer,
&my_draw_command);
xwindow->screen_image = game_image;
xwindow->screen_image = screen_image;
return EXIT_SUCCESS;
}
@ -3406,6 +3380,32 @@ void gui_draw_text(
#endif
}
void gui_draw_image_direct(
Pixel_Buffer *pixel_buffer,
Pixel_Buffer *image,
int off_x, int off_y)
{
if(image == NULL) {
return;
}
int w = image->width;
int h = image->height;
for(int j=0; j < h; ++j)
{
for(int i=0; i < w; ++i)
{
int image_x = i;
int image_y = j;
int image_index = image_y * w + image_x;
GUI_Color pixel = image->pixels[image_index];
SET_PIXEL(pixel_buffer, off_x+i, off_y+j, pixel);
}
}
}
void gui_draw_image(
Pixel_Buffer *pixel_buffer,
GUI_Draw_Command *draw_command)
@ -3589,16 +3589,24 @@ void gui_layout_and_draw_subtree(
void gui_layout_and_draw(GUI_Context *context)
{
// TODO(Zelaven): Handle all layers.
// TODO(Zelaven): Make the layers in the context iteratable.
GUI_Layer *layers[] = {
&context->background_layer,
&context->top_layer,
};
for(
GUI_Subtree *current = (GUI_Subtree*)context->background_layer.subtree_rdic.root;
current != NULL;
current = NULL)//current->next)
{
gui_layout_and_draw_subtree(
context,
current,
context->background_layer.pixel_buffer);
size_t i = 0;
i < ARRAYLENGTH(layers);
i++)
{
GUI_Layer *layer = layers[i];
GUI_Subtree *subtree_root = (GUI_Subtree*)layer->subtree_rdic.root;
if(subtree_root != NULL) {
gui_layout_and_draw_subtree(
context,
subtree_root,
layer->pixel_buffer);
}
}
}
@ -3691,34 +3699,6 @@ int main(void)
.x0 = 0, .y0 = 0,
.x1 = xwindow.width, .y1 = xwindow.height,
};
//gui(&context, screen_rectangle);
//gui_layout_nodes(&context);
#if 0
gui_generate_draw_commands(
context.root,
&draw_command_arena,
&context.num_draw_commands);
GUI_Draw_Command *draw_commands = (GUI_Draw_Command*)(draw_command_arena.memory);
for(int i = 0; i < context.num_draw_commands; i++)
{
draw_rect2(
&pixel_buffer,
&draw_commands[i]);
}
for(int i = 4; i < 100; i += 5)
{
pixel_buffer.pixels[i*xwindow.width + 10] = 0x0000FFFF;
}
draw_pixel_buffer(
xwindow.width,
xwindow.height,
xwindow.display,
xwindow.window,
xwindow.screen_image,
xwindow.graphics_context);
#endif
//getc(stdin);
bool running = true;
while(running)
@ -3935,37 +3915,9 @@ int main(void)
0, 0, 512, 100);
//SET_PIXEL(&xwindow.pixel_buffer, 100, 100, 0x00ffffff);
#endif
draw_pixel_buffer(
xwindow.width,
xwindow.height,
xwindow.display,
xwindow.window,
xwindow.screen_image,
xwindow.graphics_context);
#if 1
// NOTE(Zelaven): What does this _really_ do and why would you want it?
//XClearWindow(xwindow.display, xwindow.window);
/*
GUI_Draw_Command *draw_command =
(GUI_Draw_Command*)(draw_command_arena.memory);
for(int i = 0; i < context.num_draw_commands; i++)
{
//xstuff_filled_rect(&xwindow, draw_command+i);
xstuff_draw_rect(
&xwindow,
draw_command+i);
}
*/
//xstuff_blit_window(
// &xwindow);
draw_window(&xwindow);
XFlush(xwindow.display);
#endif
}
}

Loading…
Cancel
Save