From: Mikko L. <laz...@us...> - 2004-06-19 15:10:24
|
Update of /cvsroot/rtk/rtk/src/gui In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10377 Added Files: Brush.cpp Color.cpp Group.cpp Gui.cpp Pen.cpp Rect.cpp Widget.cpp Window.cpp Log Message: Added first GUI files. NOTE: Nothing usable yet, just sandbox for developing :) --- NEW FILE: Color.cpp --- // Color.cpp: implementation of the Color class. // ////////////////////////////////////////////////////////////////////// #include "RTK\Color.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// --- NEW FILE: Pen.cpp --- #include <rtk/Pen.h> #include <rtk/GD.h> using namespace Rtk; Pen::Pen() { _width = 1; } Pen::Pen(const Color &clr, int width) { _clr = clr; _width = width; } Pen::~Pen() { } void Pen::CopyFrom(const Pen &p) { _clr = p._clr; _width = p._width; } void Pen::SetColor(const Color &clr) { _clr = clr; } void Pen::SetWidth(int w) { _width = w; } --- NEW FILE: Rect.cpp --- #include <rtk/Rect.h> #undef MIN #undef MAX #define MIN(a,b) ((a) < (b) ? (a) : (b)) #define MAX(a,b) ((a) > (b) ? (a) : (b)) const Rect Rect::operator+( const Rect &r ) const { Rect ret; ret._x1 = MIN(_x1, r._x1); ret._x2 = MAX(_x2, r._x2); ret._y1 = MIN(_y1, r._y1); ret._y2 = MAX(_y2, r._y2); return ret; } Rect Rect::Intersect(Rect &r) { Rect ret; ret._x1 = MAX(_x1, r._x1); ret._x2 = MIN(_x2, r._x2); ret._y1 = MAX(_y1, r._y1); ret._y2 = MIN(_y2, r._y2); return ret; } bool Rect::Overlap(Rect &r) { return ( MAX( _x1, r._x1 ) <= MIN( _x2, r._x2 ) && MAX( _y1, r._y1 ) <= MIN( _y2, r._y2 ) ); } --- NEW FILE: Window.cpp --- #include <rtk/Window.h> #include <rtk/VDAL.h> #include <rtk/Rect.h> #include <rtk/error.h> using namespace Rtk; static SList window_list; SList *Window::GetWindowList() { return &window_list; } Window::Window() : Group() { window_list.Append(this); _wnd = 0; _create_flags = 0; } Window::Window(int w, int h) : Group() { window_list.Append(this); _wnd = 0; _create_flags = 0; W = w; H = h; } Window::~Window() { window_list.Remove(this); Destroy(); } void Window::Flush() { if(_wnd) { // Prepare GD for flushing, this sets clip region & friends GD *gd = WMAL::Instance()->PrepareGD(_wnd); if(_damage) { // Draw only if there's something to draw DoDraw(gd); } // This is only does something if window is double buffered: WMAL::Instance()->FlushWindow(_wnd); // We're done, free clip region and release window GD WMAL::Instance()->UnprepareGD(_wnd, gd); } } int Window::Create() { _wnd = CreateWin(_create_flags); if(!_wnd) ERROR_RETURN(OPERATION_FAILED); RETURN_SUCCESS; } int Window::Destroy() { if(_wnd) { DestroyWin(_wnd); _wnd = 0; RETURN_SUCCESS; } ERROR_RETURN(OPERATION_FAILED); } WMALHandle Window::CreateWin(unsigned flags) { WMALHandle ret = WMAL::Instance()->CreateWin(X, Y, W, H, flags, this, Window::StaticWmalCb); return ret; } void Window::DestroyWin(WMALHandle hwnd) { WMAL::Instance()->DestroyWin(hwnd); } void Window::WmalCb(WMALHandle h, int event, long *args) { switch(event) { case WIN_FLUSH: if((_create_flags & DOUBLEBUFFER) == 0) { // Window is not double buffered, we must draw everything. // This will not blink, since WIN_FLUSH is called only // when window exposed by underlying system and dirty area // is merged to window GD clip region. _damage = DAMAGE_ALL; } Flush(); break; case WIN_RESIZE: _damage = DAMAGE_ALL; W = args[0]; H = args[1]; break; case WIN_CLOSE: Destroy(); default: break; }; } --- NEW FILE: Widget.cpp --- #include <rtk\Widget.h> using namespace Rtk; Widget::Widget() { X = Y = 0; W = H = 0; _damage = DAMAGE_ALL; } Widget::Widget(int x, int y, int w, int h) { X = x; Y = y; W = w; H = h; _damage = DAMAGE_ALL; } Widget::~Widget() { } void Widget::Resize(int x, int y, int w, int h) { X = x; Y = y; W = w; H = h; } void Widget::DoLayout() { } void Widget::DoDraw(GD *gd) { // NOTE TESTING // Do some ugly drawing to see flickering :) if(_damage & DAMAGE_ALL) { gd->SetPen(Color::Red); gd->SetBrush(Color::Blue); gd->DrawRect(0,0,W,H); for(int n=0; n<W; n+=2) { if(n%4==0) gd->SetPen(Color::Red); else gd->SetPen(Color::Green); gd->DrawLine(n, 0, 0, n); } } _damage = 0; } --- NEW FILE: Brush.cpp --- #include <rtk/Brush.h> using namespace Rtk; Brush::Brush() { } Brush::Brush(const Color &clr) { _clr = clr; } Brush::~Brush() { } void Brush::CopyFrom(const Brush &br) { _clr = br._clr; } --- NEW FILE: Gui.cpp --- #include <rtk/Gui.h> #include <rtk/Window.h> #include <rtk/SList.h> namespace Rtk { VDAL *VDAL::vdal_instance = 0; WMAL *WMAL::wmal_instance = 0; // Noone.. }; --- NEW FILE: Group.cpp --- #include <rtk/Group.h> using namespace Rtk; Group::Group() { } Group::~Group() { } |