Skip to content

Commit

Permalink
Added images
Browse files Browse the repository at this point in the history
  • Loading branch information
portasynthinca3 committed Dec 14, 2019
1 parent 2844df3 commit 85dafa7
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 3 deletions.
Binary file modified build/neutron.img
Binary file not shown.
Binary file modified build/obj/cbuild.o
Binary file not shown.
Binary file modified build/obj/gfx.c.o
Binary file not shown.
Binary file modified build/obj/gui.c.o
Binary file not shown.
Binary file modified build/quark.bin
Binary file not shown.
4 changes: 2 additions & 2 deletions src/quark-c/drivers/gfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ void gfx_draw_xbm(p2d_t position, uint8_t* xbm_ptr, p2d_t xbm_size, color32_t co
//Check the position
if(pos.x - position.x < xbm_size.x){
//If it is in bounds, draw the pixel
if((data >> x) & 1)
if(((data >> x) & 1) && color_h.a != 0)
buffer[(pos.y * res_x) + pos.x] = COLOR24(color_h);
else
else if(color_l.a != 0)
buffer[(pos.y * res_x) + pos.x] = COLOR24(color_l);
}
//Increment the position
Expand Down
29 changes: 29 additions & 0 deletions src/quark-c/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "./drivers/diskio.h"
#include "./drivers/pit.h"

#include "./images/neutron_logo.xbm"

//Mouse position on the screen
signed short mx, my;
//Mouse buttons state
Expand Down Expand Up @@ -94,6 +96,8 @@ void gui_init(void){
COLOR32(255, 0, 255, 0),
COLOR32(255, 255, 255, 255),
100, 0)->extended;
gui_create_image(ex_win, (p2d_t){.x = 1, .y = 110}, (p2d_t){.x = neutron_logo_width, .y = neutron_logo_height}, GUI_IMAGE_FORMAT_XBM,
neutron_logo_bits, COLOR32(0, 0, 0, 0), COLOR32(255, 0, 0, 0));
}

/*
Expand Down Expand Up @@ -205,6 +209,21 @@ control_t* gui_create_progress_bar(window_t* win, p2d_t pos, p2d_t size, color32
return gui_create_control(win, GUI_WIN_CTRL_PROGRESS_BAR, (void*)progress, pos, size);
}

/*
* Creates a progress bar and adds it to the window
*/
control_t* gui_create_image(window_t* win, p2d_t pos, p2d_t size, uint32_t format, void* data, color32_t color_lo, color32_t color_hi){
//Create the "extended control" of image type
control_ext_image_t* image = (control_ext_image_t*)malloc(sizeof(control_ext_image_t));
//Assign properties
image->image_format = format;
image->image = data;
image->color_lo = color_lo;
image->color_hi = color_hi;
//Create a normal control with this extension
return gui_create_control(win, GUI_WIN_CTRL_IMAGE, (void*)image, pos, size);
}

/*
* Initializes the PS/2 controller
*/
Expand Down Expand Up @@ -444,6 +463,16 @@ void gui_render_control(window_t* win_ptr, control_t* ptr, uint8_t handle_pointe
ptr->size, progress->border_color);
}
break;
case GUI_WIN_CTRL_IMAGE: {
//Fetch the extended data
control_ext_image_t* image = (control_ext_image_t*)ptr->extended;
//Draw the image
if(image->image_format == GUI_IMAGE_FORMAT_XBM)
gfx_draw_xbm((p2d_t){.x = ptr->position.x + win_ptr->position.x + 1,
.y = ptr->position.y + win_ptr->position.y + 12},
(uint8_t*)image->image, ptr->size, image->color_hi, image->color_lo);
}
break;
}
}

Expand Down
17 changes: 16 additions & 1 deletion src/quark-c/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ typedef struct {
uint8_t pressed_last_frame;
} control_ext_button_t;

//Structure defining a progress bas
//Structure defining a progress bar
typedef struct {
color32_t bg_color;
color32_t fill_color;
Expand All @@ -78,11 +78,24 @@ typedef struct {
uint32_t val;
} control_ext_progress_t;

//Structure defining an image
typedef struct {
uint32_t image_format;
void* image;
color32_t color_hi;
color32_t color_lo;
} control_ext_image_t;

//UI event types

#define GUI_EVENT_UNDEFINED 0
#define GUI_EVENT_CLICK 1

//Image formats

#define GUI_IMAGE_FORMAT_XBM 1
#define GUI_IMAGE_FORMAT_RAW 2

//Keyboard buffer size in bytes
#define GUI_KEYBOARD_BUFFER_SIZE 128
//Mouse buffer size in bytes
Expand All @@ -105,6 +118,7 @@ typedef struct {
#define GUI_WIN_CTRL_LABEL 1
#define GUI_WIN_CTRL_BUTTON 2
#define GUI_WIN_CTRL_PROGRESS_BAR 3
#define GUI_WIN_CTRL_IMAGE 4

void gui_init(void);
void gui_update(void);
Expand All @@ -116,6 +130,7 @@ control_t* gui_create_button(window_t* win, p2d_t pos, p2d_t size, char* text, v
color32_t text_color, color32_t bg_color, color32_t pressed_bg_color, color32_t border_color);
control_t* gui_create_progress_bar(window_t* win, p2d_t pos, p2d_t size, color32_t bg_color, color32_t fill_color,
color32_t border_color, uint32_t max_val, uint32_t val);
control_t* gui_create_image(window_t* win, p2d_t pos, p2d_t size, uint32_t format, void* data, color32_t color_lo, color32_t color_hi);

void gui_render_windows(void);
void gui_process_window(window_t* ptr);
Expand Down

0 comments on commit 85dafa7

Please sign in to comment.