Permalink
Browse files

Files for part 13, https://www.youtube.com/watch?v=3fTVUqILuYw

  • Loading branch information...
Viktor Engelmann Viktor Engelmann
Viktor Engelmann authored and Viktor Engelmann committed Jul 4, 2016
1 parent 16476d7 commit 4aa2e76a14c8b690f00bda0bc79e1259c87756de
@@ -0,0 +1,14 @@
#ifndef __MYOS__COMMON__GRAPHICSCONTEXT_H
#define __MYOS__COMMON__GRAPHICSCONTEXT_H
#include <drivers/vga.h>
namespace myos
{
namespace common
{
typedef GraphicsContext VideoGraphicsArray;
}
}
#endif
View
@@ -41,6 +41,9 @@ namespace myos
virtual bool SetMode(common::uint32_t width, common::uint32_t height, common::uint32_t colordepth);
virtual void PutPixel(common::uint32_t x, common::uint32_t y, common::uint8_t r, common::uint8_t g, common::uint8_t b);
virtual void PutPixel(common::uint32_t x, common::uint32_t y, common::uint8_t colorIndex);
virtual void FillRectangle(common::uint32_t x, common::uint32_t y, common::uint32_t w, common::uint32_t h, common::uint8_t r, common::uint8_t g, common::uint8_t b);
};
}
View
@@ -0,0 +1 @@
View
@@ -0,0 +1,77 @@
#ifndef __MYOS__GUI__WIDGET_H
#define __MYOS__GUI__WIDGET_H
#include <common/types.h>
#include <common/graphicscontext.h>
namespace myos
{
namespace gui
{
class Widget
{
protected:
Widget* parent;
common::int32_t x;
common::int32_t y;
common::int32_t w;
common::int32_t h;
common::uint8_t r;
common::uint8_t g;
common::uint8_t b;
bool Focussable;
public:
Widget(Widget* parent,
common::int32_t x, common::int32_t y, common::int32_t w, common::int32_t h,
common::uint8_t r, common::uint8_t g, common::uint8_t b);
~Widget();
virtual void GetFocus(Widget* widget);
virtual void ModelToScreen(common::int32_t &x, common::int32_t& y);
virtual void Draw(GraphicsContext* gc);
virtual void OnMouseDown(common::int32_t x, common::int32_t y);
virtual void OnMouseUp(common::int32_t x, common::int32_t y);
virtual void OnMouseMove(common::int32_t oldx, common::int32_t oldy, common::int32_t newx, common::int32_t newy);
virtual void OnKeyDown(common::int32_t x, common::int32_t y);
virtual void OnKeyUp(common::int32_t x, common::int32_t y);
};
class CompositeWidget : public Widget
{
private:
Widget* children[100];
int numChildren;
Widget* focussedChild;
public:
CompositeWidget(Widget* parent,
common::int32_t x, common::int32_t y, common::int32_t w, common::int32_t h,
common::uint8_t r, common::uint8_t g, common::uint8_t b);
~CompositeWidget();
virtual void GetFocus(Widget* widget);
virtual void Draw(GraphicsContext* gc);
virtual void OnMouseDown(common::int32_t x, common::int32_t y);
virtual void OnMouseUp(common::int32_t x, common::int32_t y);
virtual void OnMouseMove(common::int32_t oldx, common::int32_t oldy, common::int32_t newx, common::int32_t newy);
virtual void OnKeyDown(common::int32_t x, common::int32_t y);
virtual void OnKeyUp(common::int32_t x, common::int32_t y);
};
}
}
#endif
View
@@ -0,0 +1 @@
View
@@ -141,4 +141,10 @@ void VideoGraphicsArray::PutPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g,
PutPixel(x,y, GetColorIndex(r,g,b));
}
void VideoGraphicsArray::FillRectangle(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint8_t r, uint8_t g, uint8_t b)
{
for(int32_t Y = y; Y < y+h; Y++)
for(int32_t X = x; X < x+w; X++)
PutPixel(X, Y, r, g, b);
}
View
@@ -0,0 +1 @@
View
@@ -0,0 +1,156 @@
#include <gui/widget.h>
using namespace myos::common;
using namespace myos::gui;
Widget::Widget(Widget* parent, int32_t x, int32_t y, int32_t w, int32_t h,
uint8_t r, uint8_t g, uint8_t b)
{
this->parent = parent;
this->x = x;
this->y = y;
this->w = w;
this->h = h;
this->r = r;
this->g = g;
this->b = b;
this->Focussable = true;
}
Widget::~Widget()
{
}
void Widget::GetFocus(Widget* widget)
{
if(parent != 0)
parent->GetFocus(widget);
}
void Widget::ModelToScreen(common::int32_t &x, common::int32_t& y)
{
if(parent != 0)
parent->ModelToScreen(x,y);
x += this->x;
y += this->y;
}
void Widget::Draw(GraphicsContext* gc)
{
int X = 0;
int Y = 0;
ModelToScreen(X,Y);
gc->FillRectangle(X,Y,w,h, r,g,b);
}
void Widget::OnMouseDown(common::int32_t x, common::int32_t y)
{
if(Focussable)
GetFocus(this);
}
void Widget::OnMouseUp(common::int32_t x, common::int32_t y)
{
}
void Widget::OnMouseMove(common::int32_t oldx, common::int32_t oldy, common::int32_t newx, common::int32_t newy)
{
}
void Widget::OnKeyDown(char* str)
{
}
void Widget::OnKeyUp(char* str)
{
}
CompositeWidget::CompositeWidget(Widget* parent,
common::int32_t x, common::int32_t y, common::int32_t w, common::int32_t h,
common::uint8_t r, common::uint8_t g, common::uint8_t b)
{
focussedChild = 0;
numChildren = 0;
}
CompositeWidget::~CompositeWidget()
{
}
void CompositeWidget::GetFocus(Widget* widget)
{
this->focussedChild = widget;
if(parent != 0)
parent->GetFocus(this);
}
void CompositeWidget::Draw(GraphicsContext* gc)
{
Widget::Draw(gc);
for(int i = numChildren-1; i >= 0; --i)
children[i]->Draw(gc);
}
void CompositeWidget::OnMouseDown(int32_t x, int32_t y)
{
for(int i = 0; i < numChildren; ++i)
if(children[i]->ContainsCoordinate(x - this->x, y - this->y))
{
children[i]->OnMouseDown(x - this->x, y - this->y);
break;
}
}
void CompositeWidget::OnMouseUp(int32_t x, int32_t y)
{
for(int i = 0; i < numChildren; ++i)
if(children[i]->ContainsCoordinate(x - this->x, y - this->y))
{
children[i]->OnMouseUp(x - this->x, y - this->y);
break;
}
}
void CompositeWidget::OnMouseMove(int32_t oldx, int32_t oldy, int32_t newx, int32_t newy)
{
int firstchild = -1;
for(int i = 0; i < numChildren; ++i)
if(children[i]->ContainsCoordinate(oldx - this->x, oldy - this->y))
{
children[i]->OnMouseMove(oldx - this->x, oldy - this->y, newx - this->x, newy - this->y);
firstchild = i;
break;
}
for(int i = 0; i < numChildren; ++i)
if(children[i]->ContainsCoordinate(newx - this->x, newy - this->y))
{
if(firstchild != i)
children[i]->OnMouseMove(oldx - this->x, oldy - this->y, newx - this->x, newy - this->y);
break;
}
}
void CompositeWidget::OnKeyDown(char* str)
{
if(focussedChild != 0)
focussedChild->OnKeyDown(str);
}
void CompositeWidget::OnKeyUp(char* str)
{
if(focussedChild != 0)
focussedChild->OnKeyUp(str);
}
View
@@ -0,0 +1 @@
View
@@ -162,9 +162,8 @@ extern "C" void kernelMain(const void* multiboot_structure, uint32_t /*multiboot
vga.SetMode(320,200,8);
for(int32_t y = 0; y < 200; y++)
for(int32_t x = 0; x < 320; x++)
vga.PutPixel(x, y, 0x00, 0x00, 0xA8);
vga.FillRectangle(0,0,320,200,0x00,0x00,0xA8);
while(1);

0 comments on commit 4aa2e76

Please sign in to comment.