summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2017-07-22 09:14:51 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2017-07-22 09:14:51 +0200
commit95292027625e905080f37f585402f49ec49bc97f (patch)
treefe056d9bc402a38e47fe96afef2376f3f2653bb8 /src
parent1ac14d73950798e9a867778a2943adfe88557e61 (diff)
downloadabaos-95292027625e905080f37f585402f49ec49bc97f.tar.gz
abaos-95292027625e905080f37f585402f49ec49bc97f.tar.bz2
moved color handling to video driver from generic VGA driver
Diffstat (limited to 'src')
-rw-r--r--src/drivers/video/vga.c60
-rw-r--r--src/drivers/video/vga.h26
-rw-r--r--src/drivers/video/video.c30
-rw-r--r--src/drivers/video/video.h18
-rw-r--r--src/gui/composite_widget.c2
-rw-r--r--src/gui/composite_widget.h2
-rw-r--r--src/gui/desktop.c10
-rw-r--r--src/gui/desktop.h2
-rw-r--r--src/gui/text_widget.c4
-rw-r--r--src/gui/text_widget.h2
-rw-r--r--src/gui/widget.c2
-rw-r--r--src/gui/widget.h4
-rw-r--r--src/gui/window.c2
-rw-r--r--src/gui/window.h2
-rw-r--r--src/kernel/kernel.c10
15 files changed, 97 insertions, 79 deletions
diff --git a/src/drivers/video/vga.c b/src/drivers/video/vga.c
index c38bee1..75e96e6 100644
--- a/src/drivers/video/vga.c
+++ b/src/drivers/video/vga.c
@@ -261,44 +261,32 @@ bool vga_switch_mode( void *obj, const video_mode_t *mode )
return true;
}
-vga_color_t vga_make_RGB( int R, int G, int B )
-{
- vga_color_t c;
-
- c.R = R;
- c.G = G;
- c.B = B;
-
- return c;
-}
-
-const vga_color_t VGA_COLOR_BLACK = { 0x00, 0x00, 0x00 };
-const vga_color_t VGA_COLOR_BLUE = { 0x00, 0x00, 0xAA };
-const vga_color_t VGA_COLOR_GREEN = { 0x00, 0xAA, 0x00 };
-const vga_color_t VGA_COLOR_CYAN = { 0x00, 0xAA, 0xAA };
-const vga_color_t VGA_COLOR_RED = { 0xAA, 0x00, 0x00 };
-const vga_color_t VGA_COLOR_MAGENTA = { 0xAA, 0x00, 0xAA };
-const vga_color_t VGA_COLOR_BROWN = { 0xAA, 0x55, 0x00 };
-const vga_color_t VGA_COLOR_LIGHT_GREY = { 0xAA, 0xAA, 0xAA };
-const vga_color_t VGA_COLOR_WHITE = { 0xFF, 0xFF, 0xFF };
-
-static bool is_same( const vga_color_t c1, const vga_color_t c2 )
+static bool is_same( const video_rgb_color_t c1, const video_rgb_color_t c2 )
{
return c1.R == c2.R && c1.G == c2.G && c1.B == c2.B;
}
-static uint8_t get_color_index( const vga_color_t c )
+static uint8_t get_color_index( const video_rgb_color_t c )
{
- if( is_same( c, VGA_COLOR_BLACK ) ) return 0x00;
- if( is_same( c, VGA_COLOR_BLUE ) ) return 0x01;
- if( is_same( c, VGA_COLOR_GREEN ) ) return 0x02;
- if( is_same( c, VGA_COLOR_CYAN ) ) return 0x03;
- if( is_same( c, VGA_COLOR_RED ) ) return 0x04;
- if( is_same( c, VGA_COLOR_MAGENTA ) ) return 0x05;
- if( is_same( c, VGA_COLOR_BROWN ) ) return 0x06;
- if( is_same( c, VGA_COLOR_LIGHT_GREY ) ) return 0x07;
- if( is_same( c, VGA_COLOR_WHITE ) ) return 0x3F;
+ if( is_same( c, VIDEO_RGB_COLOR_BLACK ) ) return 0x00;
+ if( is_same( c, VIDEO_RGB_COLOR_BLUE ) ) return 0x01;
+ if( is_same( c, VIDEO_RGB_COLOR_GREEN ) ) return 0x02;
+ if( is_same( c, VIDEO_RGB_COLOR_CYAN ) ) return 0x03;
+ if( is_same( c, VIDEO_RGB_COLOR_RED ) ) return 0x04;
+ if( is_same( c, VIDEO_RGB_COLOR_MAGENTA ) ) return 0x05;
+ if( is_same( c, VIDEO_RGB_COLOR_BROWN ) ) return 0x06;
+ if( is_same( c, VIDEO_RGB_COLOR_GRAY ) ) return 0x07;
+ if( is_same( c, VIDEO_RGB_COLOR_WHITE ) ) return 0x3F;
return 0x00;
+/*
+0x8 0x38 21,21,21 85,85,85 #555555 dark gray
+0x9 0x39 21,21,63 85,85,255 #5555ff bright blue
+0xA 0x3A 21,63,21 85,255,85 #55ff55 bright green
+0xB 0x3B 21,63,63 85,255,255 #55ffff bright cyan
+0xC 0x3C 63,21,21 255,85,85 #ff5555 bright red
+0xD 0X3D 63,21,63 255,85,255 #ff55ff bright magenta
+0xE 0x3E 63,63,21 255,255,85 #ffff55 yellow
+*/
}
static bool params_ok( vga_t *vga, const int x, const int y )
@@ -310,7 +298,7 @@ static bool params_ok( vga_t *vga, const int x, const int y )
return true;
}
-void vga_set_pixel( vga_t *vga, const int x, const int y, const vga_color_t color )
+void vga_set_pixel( vga_t *vga, const int x, const int y, const video_rgb_color_t color )
{
if( !params_ok( vga, x, y ) ) {
kernel_panic( "Pixel coordinates are out of bounds: (%d, %d), resolution is only (%d, %d)",
@@ -324,7 +312,7 @@ void vga_set_pixel( vga_t *vga, const int x, const int y, const vga_color_t colo
*addr = color_idx;
}
-void vga_draw_rectangle( vga_t *vga, const int x, const int y, const int w, const int h, const vga_color_t color )
+void vga_draw_rectangle( vga_t *vga, const int x, const int y, const int w, const int h, const video_rgb_color_t color )
{
if( !params_ok( vga, x, y ) ) {
kernel_panic( "Rectangle start coordinates are out of bounds: (%d, %d), resolution is only (%d, %d)",
@@ -344,13 +332,13 @@ void vga_draw_rectangle( vga_t *vga, const int x, const int y, const int w, cons
}
}
-void vga_clear_screen( vga_t *vga, const vga_color_t color )
+void vga_clear_screen( vga_t *vga, const video_rgb_color_t color )
{
memset( vga->base_addr, get_color_index( color ),
vga->mode->base.x * vga->mode->base.y );
}
-void vga_draw_char( vga_t *vga, const unsigned char c, const int x, const int y, const vga_color_t background, const vga_color_t foreground )
+void vga_draw_char( vga_t *vga, const unsigned char c, const int x, const int y, const video_rgb_color_t background, const video_rgb_color_t foreground )
{
//const struct bitmap_font font = {
diff --git a/src/drivers/video/vga.h b/src/drivers/video/vga.h
index fed47a1..6934856 100644
--- a/src/drivers/video/vga.h
+++ b/src/drivers/video/vga.h
@@ -53,28 +53,10 @@ void vga_print_info( void *obj );
bool vga_switch_mode( void *obj, const video_mode_t *mode );
-typedef struct {
- int R;
- int G;
- int B;
-} vga_color_t;
-
-extern const vga_color_t VGA_COLOR_BLACK;
-extern const vga_color_t VGA_COLOR_BLUE;
-extern const vga_color_t VGA_COLOR_GREEN;
-extern const vga_color_t VGA_COLOR_CYAN;
-extern const vga_color_t VGA_COLOR_RED;
-extern const vga_color_t VGA_COLOR_MAGENTA;
-extern const vga_color_t VGA_COLOR_BROWN;
-extern const vga_color_t VGA_COLOR_LIGHT_GREY;
-extern const vga_color_t VGA_COLOR_WHITE;
-
-vga_color_t vga_make_RGB( int R, int G, int B );
-
-void vga_set_pixel( vga_t *vga, const int x, const int y, const vga_color_t color );
-void vga_draw_rectangle( vga_t *vga, const int x, const int y, const int w, const int h, const vga_color_t color );
-void vga_clear_screen( vga_t *vga, const vga_color_t color );
-void vga_draw_char( vga_t *vga, const unsigned char c, const int x, const int y, const vga_color_t background, const vga_color_t foreground );
+void vga_set_pixel( vga_t *vga, const int x, const int y, const video_rgb_color_t color );
+void vga_draw_rectangle( vga_t *vga, const int x, const int y, const int w, const int h, const video_rgb_color_t color );
+void vga_clear_screen( vga_t *vga, const video_rgb_color_t color );
+void vga_draw_char( vga_t *vga, const unsigned char c, const int x, const int y, const video_rgb_color_t background, const video_rgb_color_t foreground );
void vga_wait_for_retrace( vga_t *vga );
void vga_use_z_buffer( vga_t *vga, bool use );
void vga_refresh( vga_t *vga );
diff --git a/src/drivers/video/video.c b/src/drivers/video/video.c
index bdadf53..ca57269 100644
--- a/src/drivers/video/video.c
+++ b/src/drivers/video/video.c
@@ -119,3 +119,33 @@ bool video_switch_mode( void *obj, const video_mode_t *mode )
return false;
}
+video_rgb_color_t video_make_rgb_color( const int R, const int G, const int B )
+{
+ video_rgb_color_t c;
+
+ c.R = R;
+ c.G = G;
+ c.B = B;
+
+ return c;
+}
+
+const video_rgb_color_t VIDEO_RGB_COLOR_BLACK = { 0x00, 0x00, 0x00 };
+const video_rgb_color_t VIDEO_RGB_COLOR_BLUE = { 0x00, 0x00, 0xAA };
+const video_rgb_color_t VIDEO_RGB_COLOR_GREEN = { 0x00, 0xAA, 0x00 };
+const video_rgb_color_t VIDEO_RGB_COLOR_CYAN = { 0x00, 0xAA, 0xAA };
+const video_rgb_color_t VIDEO_RGB_COLOR_RED = { 0xAA, 0x00, 0x00 };
+const video_rgb_color_t VIDEO_RGB_COLOR_MAGENTA = { 0xAA, 0x00, 0xAA };
+const video_rgb_color_t VIDEO_RGB_COLOR_BROWN = { 0xAA, 0x55, 0x00 };
+const video_rgb_color_t VIDEO_RGB_COLOR_GRAY = { 0xAA, 0xAA, 0xAA };
+const video_rgb_color_t VIDEO_RGB_COLOR_WHITE = { 0xFF, 0xFF, 0xFF };
+
+/*
+0x8 0x38 21,21,21 85,85,85 #555555 dark gray
+0x9 0x39 21,21,63 85,85,255 #5555ff bright blue
+0xA 0x3A 21,63,21 85,255,85 #55ff55 bright green
+0xB 0x3B 21,63,63 85,255,255 #55ffff bright cyan
+0xC 0x3C 63,21,21 255,85,85 #ff5555 bright red
+0xD 0X3D 63,21,63 255,85,255 #ff55ff bright magenta
+0xE 0x3E 63,63,21 255,255,85 #ffff55 yellow
+*/
diff --git a/src/drivers/video/video.h b/src/drivers/video/video.h
index d17a51d..6da8e60 100644
--- a/src/drivers/video/video.h
+++ b/src/drivers/video/video.h
@@ -46,4 +46,22 @@ bool video_supports_mode( void *obj, const video_mode_t mode );
bool video_set_mode( void *obj, const video_mode_t mode );
bool video_switch_mode( void *obj, const video_mode_t *mode );
+typedef struct {
+ int R;
+ int G;
+ int B;
+} video_rgb_color_t;
+
+extern const video_rgb_color_t VIDEO_RGB_COLOR_BLACK;
+extern const video_rgb_color_t VIDEO_RGB_COLOR_BLUE;
+extern const video_rgb_color_t VIDEO_RGB_COLOR_GREEN;
+extern const video_rgb_color_t VIDEO_RGB_COLOR_CYAN;
+extern const video_rgb_color_t VIDEO_RGB_COLOR_RED;
+extern const video_rgb_color_t VIDEO_RGB_COLOR_MAGENTA;
+extern const video_rgb_color_t VIDEO_RGB_COLOR_BROWN;
+extern const video_rgb_color_t VIDEO_RGB_COLOR_GRAY;
+extern const video_rgb_color_t VIDEO_RGB_COLOR_WHITE;
+
+video_rgb_color_t video_make_rgb_color( const int R, const int G, const int B );
+
#endif // VIDEO_H
diff --git a/src/gui/composite_widget.c b/src/gui/composite_widget.c
index 07056c0..e167b43 100644
--- a/src/gui/composite_widget.c
+++ b/src/gui/composite_widget.c
@@ -18,7 +18,7 @@ static composite_widget_vtable_t const composite_widget_vtable = {
composite_widget_add_child
};
-void composite_widget_init( composite_widget_t *widget, widget_t *parent, const int x, const int y, const int w, const int h, const vga_color_t background_color )
+void composite_widget_init( composite_widget_t *widget, widget_t *parent, const int x, const int y, const int w, const int h, const video_rgb_color_t background_color )
{
memset( widget, 0, sizeof( composite_widget_t ) );
diff --git a/src/gui/composite_widget.h b/src/gui/composite_widget.h
index c055e09..ed8518d 100644
--- a/src/gui/composite_widget.h
+++ b/src/gui/composite_widget.h
@@ -17,7 +17,7 @@ typedef struct {
widget_t *focused_child;
} composite_widget_t;
-void composite_widget_init( composite_widget_t *widget, widget_t *parent, const int x, const int y, const int w, const int h, const vga_color_t background_color );
+void composite_widget_init( composite_widget_t *widget, widget_t *parent, const int x, const int y, const int w, const int h, const video_rgb_color_t background_color );
void composite_widget_draw( void *obj, graphics_context_t *context );
void composite_widget_get_focus( void *obj, widget_t *widget );
diff --git a/src/gui/desktop.c b/src/gui/desktop.c
index e0cb69b..33afed6 100644
--- a/src/gui/desktop.c
+++ b/src/gui/desktop.c
@@ -20,7 +20,7 @@ static desktop_vtable_t const desktop_vtable = {
}
};
-void desktop_init( desktop_t *desktop, const int w, const int h, const vga_color_t background_color )
+void desktop_init( desktop_t *desktop, const int w, const int h, const video_rgb_color_t background_color )
{
memset( desktop, 0, sizeof( desktop_t ) );
@@ -47,16 +47,16 @@ void desktop_draw( void *obj, graphics_context_t *context )
for( int i = 0; i < 4; i++ ) {
if( desktop->mouse_x > i ) {
- vga_set_pixel( context, desktop->mouse_x - i, desktop->mouse_y, VGA_COLOR_WHITE );
+ vga_set_pixel( context, desktop->mouse_x - i, desktop->mouse_y, VIDEO_RGB_COLOR_WHITE );
}
if( desktop->mouse_x < context->mode->base.x - i ) {
- vga_set_pixel( context, desktop->mouse_x + i, desktop->mouse_y, VGA_COLOR_WHITE );
+ vga_set_pixel( context, desktop->mouse_x + i, desktop->mouse_y, VIDEO_RGB_COLOR_WHITE );
}
if( desktop->mouse_y > i ) {
- vga_set_pixel( context, desktop->mouse_x, desktop->mouse_y - i, VGA_COLOR_WHITE );
+ vga_set_pixel( context, desktop->mouse_x, desktop->mouse_y - i, VIDEO_RGB_COLOR_WHITE );
}
if( desktop->mouse_y < context->mode->base.y - i ) {
- vga_set_pixel( context, desktop->mouse_x, desktop->mouse_y + i, VGA_COLOR_WHITE );
+ vga_set_pixel( context, desktop->mouse_x, desktop->mouse_y + i, VIDEO_RGB_COLOR_WHITE );
}
}
diff --git a/src/gui/desktop.h b/src/gui/desktop.h
index 09a2d75..4215a79 100644
--- a/src/gui/desktop.h
+++ b/src/gui/desktop.h
@@ -18,7 +18,7 @@ typedef struct {
bool needs_redrawing;
} desktop_t;
-void desktop_init( desktop_t *widget, const int w, const int h, const vga_color_t background_color );
+void desktop_init( desktop_t *widget, const int w, const int h, const video_rgb_color_t background_color );
void desktop_draw( void *obj, graphics_context_t *context );
void desktop_on_mouse_down( void *obj, const int x, const int y );
diff --git a/src/gui/text_widget.c b/src/gui/text_widget.c
index 5e468c7..3aa09cc 100644
--- a/src/gui/text_widget.c
+++ b/src/gui/text_widget.c
@@ -18,7 +18,7 @@ static text_widget_vtable_t const text_widget_vtable = {
text_widget_set_text
};
-void text_widget_init( text_widget_t *widget, widget_t *parent, const int x, const int y, const int w, const int h, const vga_color_t background_color, const char *s )
+void text_widget_init( text_widget_t *widget, widget_t *parent, const int x, const int y, const int w, const int h, const video_rgb_color_t background_color, const char *s )
{
memset( widget, 0, sizeof( text_widget_t ) );
@@ -47,7 +47,7 @@ void text_widget_draw( void *obj, graphics_context_t *context )
for( const char *p = widget->s; *p != '\0'; p++ ) {
vga_draw_char( context, *p, x + w, y + h,
((widget_t *)widget)->background_color,
- VGA_COLOR_WHITE );
+ VIDEO_RGB_COLOR_WHITE );
w += 9;
if( w >= ((widget_t *)widget)->w - 10 ) {
h += 16;
diff --git a/src/gui/text_widget.h b/src/gui/text_widget.h
index 2604eff..305ec65 100644
--- a/src/gui/text_widget.h
+++ b/src/gui/text_widget.h
@@ -15,7 +15,7 @@ typedef struct {
char s[TEXT_WIDGET_MAX_TEXT_SIZE];
} text_widget_t;
-void text_widget_init( text_widget_t *widget, widget_t *parent, const int x, const int y, const int w, const int h, const vga_color_t background_color, const char *s );
+void text_widget_init( text_widget_t *widget, widget_t *parent, const int x, const int y, const int w, const int h, const video_rgb_color_t background_color, const char *s );
void text_widget_draw( void *obj, graphics_context_t *context );
void text_widget_set_text( void *obj, const char *s );
diff --git a/src/gui/widget.c b/src/gui/widget.c
index 58b03ef..70e0dbc 100644
--- a/src/gui/widget.c
+++ b/src/gui/widget.c
@@ -15,7 +15,7 @@ static widget_vtable_t const widget_vtable = {
widget_on_key_up
};
-void widget_init( widget_t *widget, widget_t *parent, const int x, const int y, const int w, const int h, const vga_color_t background_color )
+void widget_init( widget_t *widget, widget_t *parent, const int x, const int y, const int w, const int h, const video_rgb_color_t background_color )
{
memset( widget, 0, sizeof( widget_t ) );
diff --git a/src/gui/widget.h b/src/gui/widget.h
index 87b8c62..01ce361 100644
--- a/src/gui/widget.h
+++ b/src/gui/widget.h
@@ -24,13 +24,13 @@ typedef struct widget_t {
int y;
int w;
int h;
- vga_color_t background_color;
+ video_rgb_color_t background_color;
bool focusable;
struct widget_t *parent;
widget_vtable_t const *vtable;
} widget_t;
-void widget_init( widget_t *widget, widget_t *parent, const int x, const int y, const int w, const int h, const vga_color_t background_color );
+void widget_init( widget_t *widget, widget_t *parent, const int x, const int y, const int w, const int h, const video_rgb_color_t background_color );
void widget_draw( void *obj, graphics_context_t *context );
void widget_get_focus( void *obj, widget_t *widget );
diff --git a/src/gui/window.c b/src/gui/window.c
index 681c3b7..1cb1fb1 100644
--- a/src/gui/window.c
+++ b/src/gui/window.c
@@ -21,7 +21,7 @@ static window_vtable_t const window_vtable = {
};
-void window_init( window_t *window, widget_t *parent, const int x, const int y, const int w, const int h, const vga_color_t background_color )
+void window_init( window_t *window, widget_t *parent, const int x, const int y, const int w, const int h, const video_rgb_color_t background_color )
{
memset( window, 0, sizeof( window_t ) );
diff --git a/src/gui/window.h b/src/gui/window.h
index 793d8b3..269ff8c 100644
--- a/src/gui/window.h
+++ b/src/gui/window.h
@@ -14,7 +14,7 @@ typedef struct {
bool dragging;
} window_t;
-void window_init( window_t *window, widget_t *parent, const int x, const int y, const int w, const int h, const vga_color_t background_color );
+void window_init( window_t *window, widget_t *parent, const int x, const int y, const int w, const int h, const video_rgb_color_t background_color );
void window_draw( void *obj, graphics_context_t *context );
void window_on_mouse_down( void *obj, const int x, const int y );
diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c
index 102fb69..d11d6c6 100644
--- a/src/kernel/kernel.c
+++ b/src/kernel/kernel.c
@@ -352,13 +352,13 @@ static void switch_to_graphics_mode( global_context_t *global_context )
if( ((video_vtable_t *)(vga->base.base.vtable))->set_mode( vga, mode ) ) {
vga_text_save( vga_text );
- desktop_init( desktop, 320, 200, VGA_COLOR_BLUE );
+ desktop_init( desktop, 320, 200, VIDEO_RGB_COLOR_BLUE );
- window_init( &global_context->window1, (widget_t *)desktop, 60, 90, 60, 70, VGA_COLOR_LIGHT_GREY );
+ window_init( &global_context->window1, (widget_t *)desktop, 60, 90, 60, 70, VIDEO_RGB_COLOR_GRAY );
// TODO: this looks clunky!
((composite_widget_vtable_t *)global_context->desktop.base.base.vtable)->add_child( desktop, (widget_t *)&global_context->window1 );
- window_init( &global_context->window2, (widget_t *)desktop, 130, 80, 60, 70, VGA_COLOR_GREEN );
+ window_init( &global_context->window2, (widget_t *)desktop, 130, 80, 60, 70, VIDEO_RGB_COLOR_GREEN );
((composite_widget_vtable_t *)global_context->desktop.base.base.vtable)->add_child( desktop, (widget_t *)&global_context->window2 );
char s[100];
@@ -369,10 +369,10 @@ static void switch_to_graphics_mode( global_context_t *global_context )
}
*p = '\0';
- window_init( &global_context->window3, (widget_t *)desktop, 55, 5, vga->mode->base.x - 65, 100, VGA_COLOR_CYAN );
+ window_init( &global_context->window3, (widget_t *)desktop, 55, 5, vga->mode->base.x - 65, 100, VIDEO_RGB_COLOR_CYAN );
((composite_widget_vtable_t *)global_context->desktop.base.base.vtable)->add_child( desktop, (widget_t *)&global_context->window3 );
- text_widget_init( &global_context->widget3, (widget_t *)&global_context->window3, 1, 1, global_context->window3.base.base.w - 2, global_context->window3.base.base.h - 2, VGA_COLOR_RED, s );
+ text_widget_init( &global_context->widget3, (widget_t *)&global_context->window3, 1, 1, global_context->window3.base.base.w - 2, global_context->window3.base.base.h - 2, VIDEO_RGB_COLOR_RED, s );
((composite_widget_vtable_t *)global_context->window3.base.base.vtable)->add_child( (composite_widget_t *)&global_context->window3, (widget_t *)&global_context->widget3 );
((mouse_vtable_t *)(mouse->base.vtable))->set_resolution( mouse, vga->mode->base.x, vga->mode->base.y );