Compare commits

..

2 Commits

Author SHA1 Message Date
f0651ef972 Added some fun GUI primitives 2021-12-02 21:02:14 +01:00
405b9468d5 Graphics: Moved VBE/VESA driver to drivers folder 2021-12-02 21:01:33 +01:00
10 changed files with 185 additions and 12 deletions

View File

@ -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

5
src/gui/Graphics.h Normal file
View File

@ -0,0 +1,5 @@
#pragma once
class Graphics {
};

7
src/gui/Widget.h Normal file
View File

@ -0,0 +1,7 @@
#pragma once
class Widget{
virtual void draw();
};

17
src/gui/cursor.cpp Normal file
View File

@ -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;
}

38
src/gui/cursor.h Normal file
View File

@ -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,
};
};

33
src/gui/window.cpp Normal file
View File

@ -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 );
}

37
src/gui/window.h Normal file
View File

@ -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;
};

View File

@ -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();
}

View File

@ -15,13 +15,13 @@ void initVBEDevice(multiboot_info_t* mbt){
}
void putPixel( int x, int y , uint32_t colour){
printf_serial("putPixel x: %d, y: %d\n", x, y);
// printf_serial("putPixel x: %d, y: %d\n", x, y);
///fb + mbt->framebuffer_pitch * y + 4 * x ,NOTE: this calculation is very important
*(uint32_t*) ( VbeModeInfo->framebuffer + VbeModeInfo->pitch * y + 4 * x ) = colour;
}
void drawLine(int x1, int y1, int x2, int y2, uint32_t colour ){
print_serial("drawline\n");
// Bresenham's line algorithm??
// See Bresenham's line algorithm
int deltaX = x2 - x1;
int deltaY = y2 - y1;
int D = 2 * deltaY - deltaX;
@ -41,6 +41,14 @@ void drawLine(int x1, int y1, int x2, int y2, uint32_t colour ){
}
void drawRect ( int x, int y, int width, int height, uint32_t colour ){
print_serial("drawRect\n");
for ( int i = x; i < x + width; i ++)
{
for(int j = y; j < y + height; j++){
putPixel(i,j, colour);
}
}
}

View File

@ -1,7 +1,7 @@
#pragma once
#include <stdint.h>
#include "bootloader/multiboot.h"
#include "serial.h"
#include "../../bootloader/multiboot.h"
#include "../../serial.h"
struct vbe_mode_info_structure{
uint16_t attributes;