summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/LINKS.TODO3
-rw-r--r--src/Makefile10
-rw-r--r--src/gui/widget.c35
-rw-r--r--src/gui/widget.h29
-rw-r--r--src/kernel/kernel.c21
5 files changed, 88 insertions, 10 deletions
diff --git a/doc/LINKS.TODO b/doc/LINKS.TODO
index f86b68b..b404185 100644
--- a/doc/LINKS.TODO
+++ b/doc/LINKS.TODO
@@ -88,3 +88,6 @@ http://files.osdev.org/mirrors/geezer/osd/graphics/modes.c
http://www.osdever.net/FreeVGA/home.htm
http://wiki.osdev.org/VGA_Fonts
http://bos.asmhackers.net/docs/vga_without_bios/
+
+GUI:
+https://github.com/vurtun/nuklear
diff --git a/src/Makefile b/src/Makefile
index 3b1964f..fd418ef 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,5 +1,5 @@
CC := gcc
-INCLUDES = -I. -Ilibc -Ihardware -Idrivers -Idrivers/hdi -Idrivers/hdi/ps2 -Ikernel
+INCLUDES = -I. -Ilibc -Ihardware -Idrivers -Idrivers/hdi -Idrivers/hdi/ps2 -Ikernel -Igui
CFLAGS := -std=c99 -m32 -ffreestanding -O0 -g -Wall -Werror $(INCLUDES)
LD := ld
NASMFLAGS := -f elf32
@@ -33,7 +33,7 @@ kernel.bin: kernel.elf
kernel.sym: kernel.elf
$(OBJCOPY) --only-keep-debug kernel.elf kernel.sym
-kernel.elf: kernel/kernel.o kernel/kernel_asm.o kernel/console.o kernel/vgatext.o kernel/serial.o hardware/port.o hardware/port_asm.o hardware/interrupts.o hardware/interrupts_asm.o hardware/pci.o drivers/driver.o drivers/hdi/ps2/keyboard.o drivers/hdi/ps2/mouse.o drivers/video/vga.o drivers/video/vga_font.o libc/string.o libc/stdlib.o libc/stdio.o libc/setjmp.o
+kernel.elf: kernel/kernel.o kernel/kernel_asm.o kernel/console.o kernel/vgatext.o kernel/serial.o hardware/port.o hardware/port_asm.o hardware/interrupts.o hardware/interrupts_asm.o hardware/pci.o drivers/driver.o drivers/hdi/ps2/keyboard.o drivers/hdi/ps2/mouse.o drivers/video/vga.o drivers/video/vga_font.o gui/widget.o libc/string.o libc/stdlib.o libc/stdio.o libc/setjmp.o
$(LD) -o kernel.elf -N -n -Ttext 0x8800 --oformat elf32-i386 \
kernel/kernel.o kernel/kernel_asm.o \
kernel/console.o kernel/vgatext.o kernel/serial.o \
@@ -43,7 +43,8 @@ kernel.elf: kernel/kernel.o kernel/kernel_asm.o kernel/console.o kernel/vgatext.
drivers/driver.o \
drivers/hdi/ps2/keyboard.o drivers/hdi/ps2/mouse.o \
drivers/video/vga.o drivers/video/vga_font.o \
- libc/string.o libc/stdlib.o libc/stdio.o libc/setjmp.o
+ libc/string.o libc/stdlib.o libc/stdio.o libc/setjmp.o \
+ gui/widget.o
magic.bin: boot/magic.asm
$(NASM) boot/magic.asm -DMAGIC='"$(MAGIC)"' -f bin -o magic.bin
@@ -102,6 +103,9 @@ libc/stdio.o: libc/stdio.c libc/stdio.h
libc/setjmp.o: libc/setjmp.asm
$(NASM) libc/setjmp.asm $(NASMFLAGS) -o libc/setjmp.o
+gui/widget.o: gui/widget.c gui/widget.h
+ $(CC) $(CFLAGS) -c -o gui/widget.o gui/widget.c
+
clean:
-rm -f boot.bin kernel.bin kernel.sym kernel.elf image.bin magic.bin boot.map image.tmp \
serial.log \
diff --git a/src/gui/widget.c b/src/gui/widget.c
new file mode 100644
index 0000000..313fd49
--- /dev/null
+++ b/src/gui/widget.c
@@ -0,0 +1,35 @@
+#include "widget.h"
+
+#include "string.h"
+#include "stddef.h"
+
+static widget_vtable_t widget_vtable = {
+ widget_draw,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
+void widget_init( widget_t *widget, widget_t *parent, const int x, const int y, const int w, const int h )
+{
+ memset( widget, 0, sizeof( widget_t ) );
+
+ widget->parent = parent;
+ widget->x = x;
+ widget->y = y;
+ widget->w = w;
+ widget->h = h;
+
+ widget->vtable = &widget_vtable;
+}
+
+void widget_draw( void *obj, graphics_context_t *context )
+{
+ widget_t *widget = obj;
+
+ vga_draw_rectangle( context, widget->x, widget->y, widget->w, widget->h,
+ vga_make_RGB( 0xFF, 0xFF, 0xFF ) );
+}
diff --git a/src/gui/widget.h b/src/gui/widget.h
new file mode 100644
index 0000000..a1e9a21
--- /dev/null
+++ b/src/gui/widget.h
@@ -0,0 +1,29 @@
+#ifndef WIDGET_H
+#define WIDGET_H
+
+#include "graphics_context.h"
+
+typedef struct {
+ void (*draw)( void *obj, graphics_context_t *context );
+ void (*get_focus)( void *obj );
+ void (*widget_model_to_screen)( void *obj, int *x, int *y );
+ void (*on_mouse_down)( void *obj, const int x, const int y );
+ void (*on_mouse_up)( void *obj, const int x, const int y );
+ void (*on_mouse_move)( void *obj, const int old_x, const int old_y, const int x, const int y );
+ void (*on_key_down)( void *obj, char c );
+} widget_vtable_t;
+
+typedef struct widget_t {
+ int x;
+ int y;
+ int w;
+ int h;
+ struct widget_t *parent;
+ widget_vtable_t *vtable;
+} widget_t;
+
+void widget_init( widget_t *widget, widget_t *parent, const int x, const int y, const int w, const int h );
+
+void widget_draw( void *obj, graphics_context_t *context );
+
+#endif // WIDGET_H
diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c
index e7f3e26..ee63295 100644
--- a/src/kernel/kernel.c
+++ b/src/kernel/kernel.c
@@ -19,6 +19,8 @@
// TODO: move away from main!
#include "drivers/video/vga.h"
+#include "graphics_context.h"
+#include "widget.h"
static jmp_buf panic_jmp_buf;
@@ -193,20 +195,25 @@ static void handle_keyboard_event( keyboard_event_t *event, void *context )
case MODE_TEXT:
if( vga_set_mode( vga, vga_make_mode( VGA_MODE_TYPE_GRAPHICS, 320, 200, 8 ) ) ) {
vga_clear_screen( vga, vga_make_RGB( 0x00, 0x00, 0xA8 ) );
- vga_draw_char( vga, 'A', 100, 100, vga_make_RGB( 0x00, 0x00, 0xA8 ),
+ vga_draw_char( vga, 'A', 10, 10, vga_make_RGB( 0x00, 0x00, 0xA8 ),
vga_make_RGB( 0xFF, 0xFF, 0xFF ) );
- vga_draw_char( vga, 'B', 110, 100, vga_make_RGB( 0x00, 0x00, 0xA8 ),
+ vga_draw_char( vga, 'B', 20, 10, vga_make_RGB( 0x00, 0x00, 0xA8 ),
vga_make_RGB( 0xFF, 0xFF, 0xFF ) );
- vga_draw_char( vga, 'C', 120, 100, vga_make_RGB( 0x00, 0x00, 0xA8 ),
+ vga_draw_char( vga, 'C', 30, 10, vga_make_RGB( 0x00, 0x00, 0xA8 ),
vga_make_RGB( 0xFF, 0xFF, 0xFF ) );
- vga_draw_char( vga, 'D', 130, 100, vga_make_RGB( 0x00, 0x00, 0xA8 ),
+ vga_draw_char( vga, 'D', 40, 10, vga_make_RGB( 0x00, 0x00, 0xA8 ),
vga_make_RGB( 0xFF, 0xFF, 0xFF ) );
- vga_draw_char( vga, 'E', 140, 100, vga_make_RGB( 0x00, 0x00, 0xA8 ),
+ vga_draw_char( vga, 'E', 50, 10, vga_make_RGB( 0x00, 0x00, 0xA8 ),
vga_make_RGB( 0xFF, 0xFF, 0xFF ) );
- vga_draw_char( vga, 'F', 150, 100, vga_make_RGB( 0x00, 0x00, 0xA8 ),
+ vga_draw_char( vga, 'F', 60, 10, vga_make_RGB( 0x00, 0x00, 0xA8 ),
vga_make_RGB( 0xFF, 0xFF, 0xFF ) );
- vga_draw_char( vga, 'G', 160, 100, vga_make_RGB( 0x00, 0x00, 0xA8 ),
+ vga_draw_char( vga, 'G', 70, 10, vga_make_RGB( 0x00, 0x00, 0xA8 ),
vga_make_RGB( 0xFF, 0xFF, 0xFF ) );
+
+ widget_t widget;
+ widget_init( &widget, NULL, 50, 50, 60, 70 );
+ // as vga_t is equals to the graphical context for now
+ widget.vtable->draw( &widget, &global_context->vga );
}
global_context->mode = MODE_GRAPHICS;
break;