Permalink
Browse files

Files for part 14, https://www.youtube.com/watch?v=HS1Kp1WJWBU

  • Loading branch information...
Viktor Engelmann Viktor Engelmann
Viktor Engelmann authored and Viktor Engelmann committed Jul 4, 2016
1 parent 4aa2e76 commit 15e5fa7a0701a89860a06b9e7c5142f878f0285a
@@ -7,7 +7,7 @@ namespace myos
{
namespace common
{
typedef GraphicsContext VideoGraphicsArray;
typedef myos::drivers::VideoGraphicsArray GraphicsContext;
}
}
View
@@ -39,8 +39,8 @@ namespace myos
virtual bool SupportsMode(common::uint32_t width, common::uint32_t height, common::uint32_t colordepth);
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 PutPixel(common::int32_t x, common::int32_t y, common::uint8_t r, common::uint8_t g, common::uint8_t b);
virtual void PutPixel(common::int32_t x, common::int32_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
@@ -1 +1,35 @@
#ifndef __MYOS__GUI__DESKTOP_H
#define __MYOS__GUI__DESKTOP_H
#include <gui/widget.h>
#include <drivers/mouse.h>
namespace myos
{
namespace gui
{
class Desktop : public CompositeWidget, public myos::drivers::MouseEventHandler
{
protected:
common::uint32_t MouseX;
common::uint32_t MouseY;
public:
Desktop(common::int32_t w, common::int32_t h,
common::uint8_t r, common::uint8_t g, common::uint8_t b);
~Desktop();
void Draw(common::GraphicsContext* gc);
void OnMouseDown(myos::common::uint8_t button);
void OnMouseUp(myos::common::uint8_t button);
void OnMouseMove(int x, int y);
};
}
}
#endif
View
@@ -5,13 +5,14 @@
#include <common/types.h>
#include <common/graphicscontext.h>
#include <drivers/keyboard.h>
namespace myos
{
namespace gui
{
class Widget
class Widget : public myos::drivers::KeyboardEventHandler
{
protected:
Widget* parent;
@@ -34,15 +35,12 @@ namespace myos
virtual void GetFocus(Widget* widget);
virtual void ModelToScreen(common::int32_t &x, common::int32_t& y);
virtual bool ContainsCoordinate(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 Draw(common::GraphicsContext* gc);
virtual void OnMouseDown(common::int32_t x, common::int32_t y, common::uint8_t button);
virtual void OnMouseUp(common::int32_t x, common::int32_t y, common::uint8_t button);
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);
};
@@ -60,14 +58,15 @@ namespace myos
~CompositeWidget();
virtual void GetFocus(Widget* widget);
virtual bool AddChild(Widget* child);
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 Draw(common::GraphicsContext* gc);
virtual void OnMouseDown(common::int32_t x, common::int32_t y, common::uint8_t button);
virtual void OnMouseUp(common::int32_t x, common::int32_t y, common::uint8_t button);
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);
virtual void OnKeyDown(char);
virtual void OnKeyUp(char);
};
}
View
@@ -1 +1,32 @@
#ifndef __MYOS__GUI__WINDOW_H
#define __MYOS__GUI__WINDOW_H
#include <gui/widget.h>
#include <drivers/mouse.h>
namespace myos
{
namespace gui
{
class Window : public CompositeWidget
{
protected:
bool Dragging;
public:
Window(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);
~Window();
void OnMouseDown(common::int32_t x, common::int32_t y, common::uint8_t button);
void OnMouseUp(common::int32_t x, common::int32_t y, common::uint8_t button);
void OnMouseMove(common::int32_t oldx, common::int32_t oldy, common::int32_t newx, common::int32_t newy);
};
}
}
#endif
View
@@ -16,6 +16,9 @@ objects = obj/loader.o \
obj/drivers/keyboard.o \
obj/drivers/mouse.o \
obj/drivers/vga.o \
obj/gui/widget.o \
obj/gui/window.o \
obj/gui/desktop.o \
obj/kernel.o
View
@@ -81,7 +81,7 @@ void printf(char*);
{
if(buffer[1] != 0 || buffer[2] != 0)
{
handler->OnMouseMove(buffer[1], -buffer[2]);
handler->OnMouseMove((int8_t)buffer[1], -((int8_t)buffer[2]));
}
for(uint8_t i = 0; i < 3; i++)
View
@@ -123,20 +123,27 @@ uint8_t* VideoGraphicsArray::GetFrameBufferSegment()
}
}
void VideoGraphicsArray::PutPixel(uint32_t x, uint32_t y, uint8_t colorIndex)
void VideoGraphicsArray::PutPixel(int32_t x, int32_t y, uint8_t colorIndex)
{
if(x < 0 || 320 <= x
|| y < 0 || 200 <= y)
return;
uint8_t* pixelAddress = GetFrameBufferSegment() + 320*y + x;
*pixelAddress = colorIndex;
}
uint8_t VideoGraphicsArray::GetColorIndex(uint8_t r, uint8_t g, uint8_t b)
{
if(r == 0x00, g == 0x00, b == 0xA8)
return 0x01;
if(r == 0x00 && g == 0x00 && b == 0x00) return 0x00; // black
if(r == 0x00 && g == 0x00 && b == 0xA8) return 0x01; // blue
if(r == 0x00 && g == 0xA8 && b == 0x00) return 0x02; // green
if(r == 0xA8 && g == 0x00 && b == 0x00) return 0x04; // red
if(r == 0xFF && g == 0xFF && b == 0xFF) return 0x3F; // white
return 0x00;
}
void VideoGraphicsArray::PutPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t b)
void VideoGraphicsArray::PutPixel(int32_t x, int32_t y, uint8_t r, uint8_t g, uint8_t b)
{
PutPixel(x,y, GetColorIndex(r,g,b));
}
View
@@ -1 +1,62 @@
#include <gui/desktop.h>
using namespace myos;
using namespace myos::common;
using namespace myos::gui;
Desktop::Desktop(common::int32_t w, common::int32_t h,
common::uint8_t r, common::uint8_t g, common::uint8_t b)
: CompositeWidget(0,0,0, w,h,r,g,b),
MouseEventHandler()
{
MouseX = w/2;
MouseY = h/2;
}
Desktop::~Desktop()
{
}
void Desktop::Draw(common::GraphicsContext* gc)
{
CompositeWidget::Draw(gc);
for(int i = 0; i < 4; i++)
{
gc -> PutPixel(MouseX-i, MouseY, 0xFF, 0xFF, 0xFF);
gc -> PutPixel(MouseX+i, MouseY, 0xFF, 0xFF, 0xFF);
gc -> PutPixel(MouseX, MouseY-i, 0xFF, 0xFF, 0xFF);
gc -> PutPixel(MouseX, MouseY+i, 0xFF, 0xFF, 0xFF);
}
}
void Desktop::OnMouseDown(myos::common::uint8_t button)
{
CompositeWidget::OnMouseDown(MouseX, MouseY, button);
}
void Desktop::OnMouseUp(myos::common::uint8_t button)
{
CompositeWidget::OnMouseUp(MouseX, MouseY, button);
}
void Desktop::OnMouseMove(int x, int y)
{
x /= 4;
y /= 4;
int32_t newMouseX = MouseX + x;
if(newMouseX < 0) newMouseX = 0;
if(newMouseX >= w) newMouseX = w - 1;
int32_t newMouseY = MouseY + y;
if(newMouseY < 0) newMouseY = 0;
if(newMouseY >= h) newMouseY = h - 1;
CompositeWidget::OnMouseMove(MouseX, MouseY, newMouseX, newMouseY);
MouseX = newMouseX;
MouseY = newMouseY;
}
View
@@ -7,6 +7,7 @@ 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)
: KeyboardEventHandler()
{
this->parent = parent;
this->x = x;
@@ -45,25 +46,23 @@ void Widget::Draw(GraphicsContext* gc)
gc->FillRectangle(X,Y,w,h, r,g,b);
}
void Widget::OnMouseDown(common::int32_t x, common::int32_t y)
void Widget::OnMouseDown(common::int32_t x, common::int32_t y, common::uint8_t button)
{
if(Focussable)
GetFocus(this);
}
void Widget::OnMouseUp(common::int32_t x, common::int32_t y)
bool Widget::ContainsCoordinate(common::int32_t x, common::int32_t y)
{
return this->x <= x && x < this->x + this->w
&& this->y <= y && y < this->y + this->h;
}
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::OnMouseUp(common::int32_t x, common::int32_t y, common::uint8_t button)
{
}
void Widget::OnKeyUp(char* str)
void Widget::OnMouseMove(common::int32_t oldx, common::int32_t oldy, common::int32_t newx, common::int32_t newy)
{
}
@@ -74,9 +73,11 @@ 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)
: Widget(parent, x,y,w,h, r,g,b)
{
focussedChild = 0;
numChildren = 0;
@@ -93,6 +94,15 @@ void CompositeWidget::GetFocus(Widget* widget)
parent->GetFocus(this);
}
bool CompositeWidget::AddChild(Widget* child)
{
if(numChildren >= 100)
return false;
children[numChildren++] = child;
return true;
}
void CompositeWidget::Draw(GraphicsContext* gc)
{
Widget::Draw(gc);
@@ -101,22 +111,22 @@ void CompositeWidget::Draw(GraphicsContext* gc)
}
void CompositeWidget::OnMouseDown(int32_t x, int32_t y)
void CompositeWidget::OnMouseDown(int32_t x, int32_t y, common::uint8_t button)
{
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);
children[i]->OnMouseDown(x - this->x, y - this->y, button);
break;
}
}
void CompositeWidget::OnMouseUp(int32_t x, int32_t y)
void CompositeWidget::OnMouseUp(int32_t x, int32_t y, common::uint8_t button)
{
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);
children[i]->OnMouseUp(x - this->x, y - this->y, button);
break;
}
}
@@ -142,13 +152,13 @@ void CompositeWidget::OnMouseMove(int32_t oldx, int32_t oldy, int32_t newx, int3
}
void CompositeWidget::OnKeyDown(char* str)
void CompositeWidget::OnKeyDown(char str)
{
if(focussedChild != 0)
focussedChild->OnKeyDown(str);
}
void CompositeWidget::OnKeyUp(char* str)
void CompositeWidget::OnKeyUp(char str)
{
if(focussedChild != 0)
focussedChild->OnKeyUp(str);
Oops, something went wrong.

0 comments on commit 15e5fa7

Please sign in to comment.