From f0651ef97252233f1fc40e2908a3af7f2bf3433a Mon Sep 17 00:00:00 2001 From: Nigel Date: Thu, 2 Dec 2021 21:02:14 +0100 Subject: [PATCH] Added some fun GUI primitives --- Makefile | 10 ++++++++-- src/gui/Graphics.h | 5 +++++ src/gui/Widget.h | 7 +++++++ src/gui/cursor.cpp | 17 +++++++++++++++++ src/gui/cursor.h | 38 ++++++++++++++++++++++++++++++++++++++ src/gui/window.cpp | 33 +++++++++++++++++++++++++++++++++ src/gui/window.h | 37 +++++++++++++++++++++++++++++++++++++ src/kernel/bootcheck.h | 34 ++++++++++++++++++++++++++++------ 8 files changed, 173 insertions(+), 8 deletions(-) create mode 100644 src/gui/Graphics.h create mode 100644 src/gui/Widget.h create mode 100644 src/gui/cursor.cpp create mode 100644 src/gui/cursor.h create mode 100644 src/gui/window.cpp create mode 100644 src/gui/window.h diff --git a/Makefile b/Makefile index 8d3982d..84c0114 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ CC = ${HOME}/opt/cross/bin/i686-elf-gcc CPP = ${HOME}/opt/cross/bin/i686-elf-g++ CFLAGS = -ffreestanding -O2 -Wall -Wextra -OFILES = $(BUILD_DIR)/boot.o $(BUILD_DIR)/kterm.o $(BUILD_DIR)/kernel.o $(BUILD_DIR)/PhysicalMemoryManager.o $(BUILD_DIR)/io.o $(BUILD_DIR)/vesa.o $(BUILD_DIR)/PageDirectory.o $(BUILD_DIR)/gdtc.o $(BUILD_DIR)/idt.o $(BUILD_DIR)/pic.o $(BUILD_DIR)/string.o +OFILES = $(BUILD_DIR)/boot.o $(BUILD_DIR)/window.o $(BUILD_DIR)/cursor.o $(BUILD_DIR)/kterm.o $(BUILD_DIR)/kernel.o $(BUILD_DIR)/PhysicalMemoryManager.o $(BUILD_DIR)/io.o $(BUILD_DIR)/vesa.o $(BUILD_DIR)/PageDirectory.o $(BUILD_DIR)/gdtc.o $(BUILD_DIR)/idt.o $(BUILD_DIR)/pic.o $(BUILD_DIR)/string.o SRC_DIR = src BUILD_DIR = build @@ -89,4 +89,10 @@ $(BUILD_DIR)/PhysicalMemoryManager.o: $(CPP) -c $(SRC_DIR)/kernel/memory/PhysicalMemoryManager.cpp -o $(BUILD_DIR)/PhysicalMemoryManager.o $(CFLAGS) -fno-exceptions -fno-rtti $(BUILD_DIR)/vesa.o: - $(CPP) -c $(SRC_DIR)/kernel/vesa.cpp -o $(BUILD_DIR)/vesa.o $(CFLAGS) -fno-exceptions -fno-rtti + $(CPP) -c $(SRC_DIR)/kernel/drivers/vesa/vesa.cpp -o $(BUILD_DIR)/vesa.o $(CFLAGS) -fno-exceptions -fno-rtti + +$(BUILD_DIR)/window.o: + $(CPP) -c $(SRC_DIR)/gui/window.cpp -o $(BUILD_DIR)/window.o $(CFLAGS) -fno-exceptions -fno-rtti + +$(BUILD_DIR)/cursor.o: + $(CPP) -c $(SRC_DIR)/gui/cursor.cpp -o $(BUILD_DIR)/cursor.o $(CFLAGS) -fno-exceptions -fno-rtti diff --git a/src/gui/Graphics.h b/src/gui/Graphics.h new file mode 100644 index 0000000..5fae422 --- /dev/null +++ b/src/gui/Graphics.h @@ -0,0 +1,5 @@ +#pragma once + +class Graphics { + +}; \ No newline at end of file diff --git a/src/gui/Widget.h b/src/gui/Widget.h new file mode 100644 index 0000000..58ac642 --- /dev/null +++ b/src/gui/Widget.h @@ -0,0 +1,7 @@ +#pragma once + + +class Widget{ + virtual void draw(); + +}; \ No newline at end of file diff --git a/src/gui/cursor.cpp b/src/gui/cursor.cpp new file mode 100644 index 0000000..bf433a7 --- /dev/null +++ b/src/gui/cursor.cpp @@ -0,0 +1,17 @@ +#include "cursor.h" + + void Cursor::draw(){ + for(int i = 0; i < this->width; i++){ + for(int j = 0; j < this->height; j++){ + if(this->bitmap[j * this->width + i] == 1 ){ + putPixel(i + this->x,j + this->y, 0xFF000000); + } + } + } + } + + + Cursor::Cursor(int x, int y){ + this->x = x; + this->y = y; + } \ No newline at end of file diff --git a/src/gui/cursor.h b/src/gui/cursor.h new file mode 100644 index 0000000..2827d8d --- /dev/null +++ b/src/gui/cursor.h @@ -0,0 +1,38 @@ +#pragma once +#include "../kernel/drivers/vesa/vesa.h" + + +class Cursor{ + public: + void draw(); + Cursor(int x, int y); + + + + private: + int x; + int y; + const int width= 16; + const int height= 10; + const int bitmap [160] = { + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + + 0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + + 0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0, + + 0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0, + + 0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0, + + 0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0, + + 0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0, + + 0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0, + + 0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0, + + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + }; +}; \ No newline at end of file diff --git a/src/gui/window.cpp b/src/gui/window.cpp new file mode 100644 index 0000000..c5771c4 --- /dev/null +++ b/src/gui/window.cpp @@ -0,0 +1,33 @@ +#include "window.h" + +int Window::getWidth(){ + return this->rect.width; +} + +int Window::getHeight(){ + return this->rect.height; +} + +void Window::setWidth(int& width){ + this->rect.width = width; +} +void Window::setHeight(int& height){ + this->rect.height = height; +} + +int Window::getX(){ + return this->rect.x; +} + +int Window::getY(){ + return this->rect.y; +} + +Window::Window (Rect& rect , uint32_t colour){ + this->rect = rect; + this->Background_colour = colour; +} + +void Window::draw(){ + drawRect(this->getX() , this->getY() , this->getWidth() , this->getHeight() ,this->Background_colour ); +} diff --git a/src/gui/window.h b/src/gui/window.h new file mode 100644 index 0000000..a37105c --- /dev/null +++ b/src/gui/window.h @@ -0,0 +1,37 @@ +#pragma once +#include "../kernel/drivers/vesa/vesa.h" +#include "Widget.h" + +struct Rect { + int width; + int height; + int x; + int y; + +}; + + + +class Window : Widget{ + +public: + int getX(); + int getY(); + + int getWidth(); + int getHeight(); + void setWidth(int&); + void setHeight(int&); + + Window (Rect& rect , uint32_t colour); + void draw(); + + +private: + Rect rect; + uint32_t Background_colour; + + + + +}; diff --git a/src/kernel/bootcheck.h b/src/kernel/bootcheck.h index aa22d63..8afc0fa 100644 --- a/src/kernel/bootcheck.h +++ b/src/kernel/bootcheck.h @@ -1,9 +1,10 @@ #pragma once #include "bootloader/multiboot.h" #define CHECK_FLAG(flags, bit) ((flags) & (1 <<(bit))) - +#include "../gui/window.h" +#include "../gui/cursor.h" #include "tty/kterm.h" -#include "vesa.h" +#include "drivers/vesa/vesa.h" void CheckMBT ( multiboot_info_t* mbt ){ /* Set MBI to the addresss of the multiboot information structure*/ @@ -75,11 +76,32 @@ void CheckMBT ( multiboot_info_t* mbt ){ // Init vesa driver initVBEDevice(mbt); - // Turn pixel on in the middle of the screen; - putPixel( 50, 50 , 0x00FFFFFF); + // Fill screen with blue + // colours AARRGGBB + drawRect(0, 0 , VbeModeInfo->width,VbeModeInfo->height, 0xFF0000FF); - putPixel(VbeModeInfo->width / 2 , VbeModeInfo->height / 2 , 0x00FF0000); - drawLine(50,10, 150, 8, 0x00FF00FF); + // Create two windows + Rect rect_window1 {}; + Rect rect_window2 {}; + rect_window1.height =200; + rect_window1.width = 300; + rect_window1.x = 50; + rect_window1.y = 50; + + rect_window2.height =200; + rect_window2.width = 300; + rect_window2.x = 300; + rect_window2.y = 200; + + Window window_1 ( rect_window1, 0xFF00F0FF); + Window window_2 (rect_window2, 0xFFAACCDD); + + window_1.draw(); + window_2.draw(); + + Cursor cursor (70,100); + + cursor.draw(); }