summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2017-06-24 21:16:44 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2017-06-24 21:16:44 +0200
commite74065e71667d8df1529f8ca32e14f3e54119ea1 (patch)
treed5daa165dd618eda0bf6b8760472a95eefaa80ad
parentfd0782099cab0988311aa80d4a6b0871a6403084 (diff)
downloadabaos-e74065e71667d8df1529f8ca32e14f3e54119ea1.tar.gz
abaos-e74065e71667d8df1529f8ca32e14f3e54119ea1.tar.bz2
started to implement a widget showing text, the problem currently
is the inheritance method in draw is not working correctly
-rw-r--r--src/Makefile8
-rw-r--r--src/gui/composite_widget.h1
-rw-r--r--src/gui/text_widget.c64
-rw-r--r--src/gui/text_widget.h22
-rw-r--r--src/kernel/kernel.c11
5 files changed, 101 insertions, 5 deletions
diff --git a/src/Makefile b/src/Makefile
index d919cbc..c9ccda8 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -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 gui/widget.o gui/composite_widget.o gui/desktop.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 gui/composite_widget.o gui/desktop.o gui/text_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 \
@@ -44,7 +44,8 @@ kernel.elf: kernel/kernel.o kernel/kernel_asm.o kernel/console.o kernel/vgatext.
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 \
- gui/widget.o gui/composite_widget.o gui/desktop.o
+ gui/widget.o gui/composite_widget.o gui/desktop.o \
+ gui/text_widget.o
magic.bin: boot/magic.asm
$(NASM) boot/magic.asm -DMAGIC='"$(MAGIC)"' -f bin -o magic.bin
@@ -112,6 +113,9 @@ gui/composite_widget.o: gui/composite_widget.c gui/composite_widget.h
gui/desktop.o: gui/desktop.c gui/desktop.h
$(CC) $(CFLAGS) -c -o gui/desktop.o gui/desktop.c
+gui/text_widget.o: gui/text_widget.c gui/text_widget.h
+ $(CC) $(CFLAGS) -c -o gui/text_widget.o gui/text_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/composite_widget.h b/src/gui/composite_widget.h
index 2b27e32..28e1e02 100644
--- a/src/gui/composite_widget.h
+++ b/src/gui/composite_widget.h
@@ -16,7 +16,6 @@ typedef struct {
widget_t *children[MAX_NOF_WIDGET_CHILDREN];
int nof_children;
widget_t *focused_child;
- vga_color_t background_color;
} 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 );
diff --git a/src/gui/text_widget.c b/src/gui/text_widget.c
new file mode 100644
index 0000000..fbb3754
--- /dev/null
+++ b/src/gui/text_widget.c
@@ -0,0 +1,64 @@
+#include "text_widget.h"
+
+#include "string.h"
+#include "stddef.h"
+
+static text_widget_vtable_t text_widget_vtable = {
+ {
+ text_widget_draw,
+ widget_get_focus,
+ widget_model_to_screen,
+ widget_contains_coordinate,
+ widget_on_mouse_down,
+ widget_on_mouse_up,
+ widget_on_mouse_move,
+ widget_on_key_down,
+ widget_on_key_up
+ },
+ 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 )
+{
+ memset( widget, 0, sizeof( text_widget_t ) );
+
+ widget_init( &widget->base, parent, x, y, w, h, background_color );
+
+ // TODO: const for now, caller has to preserve the text
+ // maybe with memory manager in place we can do this with a strdup
+ widget->s = s;
+
+ widget->vtable = &text_widget_vtable;
+}
+
+void text_widget_draw( void *obj, graphics_context_t *context )
+{
+ text_widget_t *widget = obj;
+
+ widget->base.vtable->draw( obj, context );
+
+ int x = 0;
+ int y = 0;
+
+ widget->base.vtable->model_to_screen( widget, &x, &y );
+
+ for( char c = widget->s[0]; c != '\0'; c++ ) {
+ vga_draw_char( context, c, x, y, widget->base.background_color,
+ VGA_COLOR_WHITE );
+ x += 9;
+ if( x >= widget->base.w - 9 ) {
+ y += 16;
+ x = 0;
+ }
+ }
+
+}
+
+void text_widget_set_text( void *obj, const char *s )
+{
+ text_widget_t *widget = obj;
+
+ // TODO: see above
+ widget->s = s;
+}
+
diff --git a/src/gui/text_widget.h b/src/gui/text_widget.h
new file mode 100644
index 0000000..4b00b4f
--- /dev/null
+++ b/src/gui/text_widget.h
@@ -0,0 +1,22 @@
+#ifndef TEXT_WIDGET_H
+#define TEXT_WIDGET_H
+
+#include "widget.h"
+
+typedef struct {
+ widget_vtable_t base;
+ void (*set_text)( void *obj, const char *s );
+} text_widget_vtable_t;
+
+typedef struct {
+ widget_t base;
+ text_widget_vtable_t *vtable;
+ const char *s;
+} 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_draw( void *obj, graphics_context_t *context );
+void text_widget_set_text( void *obj, const char *s );
+
+#endif // TEXT_WIDGET_H
diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c
index db3278f..e6462e1 100644
--- a/src/kernel/kernel.c
+++ b/src/kernel/kernel.c
@@ -23,6 +23,7 @@
#include "widget.h"
#include "composite_widget.h"
#include "desktop.h"
+#include "text_widget.h"
static jmp_buf panic_jmp_buf;
@@ -204,12 +205,17 @@ static void handle_keyboard_event( keyboard_event_t *event, void *context )
((composite_widget_vtable_t *)desktop.vtable)->add_child( &desktop, &widget1 );
widget_t widget2;
- widget_init( &widget2, (widget_t *)&desktop, 120, 120, 60, 70, VGA_COLOR_GREEN );
+ widget_init( &widget2, (widget_t *)&desktop, 130, 50, 60, 70, VGA_COLOR_GREEN );
((composite_widget_vtable_t *)desktop.vtable)->add_child( &desktop, &widget2 );
+ text_widget_t widget3;
+ text_widget_init( &widget3, (widget_t *)&desktop, 5, 5, vga->mode.x - 10 , 50, VGA_COLOR_RED, "Hello" );
+ ((composite_widget_vtable_t *)desktop.vtable)->add_child( &desktop, (widget_t *)&widget3 );
+
// as vga_t is equals to the graphical context for now
- ((widget_vtable_t *)desktop.vtable)->draw( &desktop, &global_context->vga );
+ ((widget_vtable_t *)desktop.vtable)->draw( &desktop, vga );
+#if 0
int x = 0;
int y = 0;
for( char c = ' '; c <= '~'; c++ ) {
@@ -221,6 +227,7 @@ static void handle_keyboard_event( keyboard_event_t *event, void *context )
x = 0;
}
}
+#endif
}
global_context->mode = MODE_GRAPHICS;
break;