From: Mikko L. <laz...@us...> - 2004-06-19 15:08:41
|
Update of /cvsroot/rtk/rtk/rtk In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8951 Added Files: Brush.h Color.h Dummy_WMAL.h Fake_WMAL.h GD.h Group.h Gui.h Pen.h Rect.h VDAL.h WMAL.h Widget.h Win32_GD.h Win32_VDAL.h Win32_WMAL.h Window.h Log Message: Added first GUI files. NOTE: Nothing usable yet, just sandbox for developing :) --- NEW FILE: GD.h --- #ifndef _GD_H_ #define _GD_H_ #include "Pen.h" #include "Brush.h" #include "Matrix.h" namespace Rtk { class GD { public: GD() { _caps = 0; } virtual ~GD() { } unsigned int GetCaps() { return _caps; } void SetPen(const Color &clr, int width=1) { Pen c(clr, width); SetPen(c); } void SetPen(const Pen &pen); const Pen &GetPen() const { return _pen; } void SetBrush(const Color &clr) { Brush br(clr); SetBrush(br); } void SetBrush(const Brush &br); const Brush &GetBrush() const { return _brush; } /* Virtual functions */ virtual bool BeginDraw(); virtual bool EndDraw(); /* Drawing primitives */ virtual void DrawRect(int x, int y, int w, int h) = 0; virtual void DrawLine(int x1, int y1, int x2, int y2) = 0; /* GD specific */ virtual void UpdatePen(Pen &pen) { } virtual void UpdateBrush(Brush &br) { } virtual void UpdateMatrix(Matrix &m) { } protected: unsigned int _caps; Pen _pen; Brush _brush; Matrix _matrix; }; }; #endif /* _GD_H_ */ --- NEW FILE: Widget.h --- #ifndef _WIDGET_H_ #define _WIDGET_H_ #include "GD.h" namespace Rtk { enum { DAMAGE_ALL = (1<<0), DAMAGE_CHILD = (1<<1) }; class Widget { public: Widget(); Widget(int x, int y, int w, int h); virtual ~Widget(); void Redraw(unsigned flags = 0); void Resize(int x, int y, int w, int h); int x() const { return X; } int y() const { return Y; } int w() const { return W; } int h() const { return H; } virtual void DoLayout(); virtual void DoDraw(GD *gd); unsigned GetDamage() const { return _damage; } protected: int X,Y,W,H; unsigned _damage; }; }; #endif // _WIDGET_H_ --- NEW FILE: Group.h --- #ifndef _GROUP_H_ #define _GROUP_H_ #include "Widget.h" namespace Rtk { class Group : public Widget { public: Group(); virtual ~Group(); }; }; #endif // _GROUP_H_ --- NEW FILE: Fake_WMAL.h --- #ifndef _FAKE_WMAL_H_ #define _FAKE_WMAL_H_ #include "WMAL.h" namespace Rtk { class FakeWMAL : public WMAL { public: FakeWMAL(); virtual ~FakeWMAL(); unsigned GetCaps() { return WMAL::MANAGED; } int Init(); WMALHandle CreateWin(int x, int y, int w, int h, unsigned flags); bool DestroyWin(WMALHandle win); bool SetWindowSize(WMALHandle win, int x, int y, int w, int h, unsigned flags); bool GetWindowSize(WMALHandle win, int &x, int &y, int &w, int &h); bool SetWindowCaption(WMALHandle win, const RCHAR *caption); bool GetWindowCaption(WMALHandle win, RCHAR *caption, int size); bool ShowWin(WMALHandle win, unsigned flags); bool HideWin(WMALHandle win); bool SetForeground(WMALHandle win); }; }; #endif --- NEW FILE: Rect.h --- #ifndef _RECT_H_ #define _RECT_H_ class Rect { public: Rect() : _x1(0), _y1(0), _x2(-1), _y2(-1) { } Rect(int x, int y, int w, int h) : _x1(x), _y1(y), _x2(x+w-1), _y2(y+h-1) { } Rect(const Rect &r) { _x1=r._x1; _y1=r._y1; _x2=r._x2; _y2=r._y2; } Rect &operator=( const Rect &r ) { _x1=r._x1; _y1=r._y1; _x2=r._x2; _y2=r._y2; return *this; } const Rect operator+( const Rect &r ) const; bool Overlap(Rect &r); Rect Intersect(Rect &r); bool Contains(int xs, int ys) { return (xs >= _x1 && xs <= _x2 && ys >= _y1 && ys <= _y2); } int x1() const { return _x1; } int y1() const { return _y1; } int x2() const { return _x2; } int y2() const { return _y2; } int GetLeft() const { return _x1; } int GetTop() const { return _y1; } int GetRight() const { return _x2; } int GetBottom() const { return _y2; } int SetLeft(int v) { return (_x1=v); } int SetTop(int v) { return (_y1=v); } int SetRight(int v) { return (_x2=v); } int SetBottom(int v) { return (_y2=v); } int x() const { return _x1; } int y() const { return _y1; } void x(int x) { _x1 = x; } void y(int y) { _y1 = y; } int GetWidth() const { return (_x2-_x1+1); } void SetWidth(int w) { _x2 = (_x1+w-1); } int w() const { return (_x2-_x1+1); } void w(int w) { _x2 = (_x1+w-1); } int GetHeight() const { return (_y2-_y1+1); } void SetHeight(int h) { _y2 = (_y1+h-1); } int h() const { return (_y2-_y1+1); } void h(int h) { _y2 = (_y1+h-1); } void MoveBy(int dx, int dy) { _x1+=dx; _x2+=dx; _y1+=dy; _y2+=dy; } void SetBox(int x, int y, int w, int h) { _x1=x; _y1=y; _x2=x+w-1; _y2=y+h-1; } void Set(int x1, int y1, int x2, int y2) { _x1=x1; _y1=y1; _x2=x2; _y2=y2; } private: int _x1, _y1, _x2, _y2; }; #endif // _RECT_H_ --- NEW FILE: Gui.h --- #ifndef _GUI_H_ #define _GUI_H_ #include "GD.h" #include "WMAL.h" #include "Rect.h" namespace Rtk { // Noone }; #endif --- NEW FILE: Color.h --- #ifndef _COLOR_H_ #define _COLOR_H_ namespace Rtk { class GD; typedef unsigned int RCOLOR; class Color { public: enum { Red = 0xFF000000, Green = 0x00FF0000, Blue = 0x0000FF00, NoColor = 0x000000FF }; Color() { _clr = 0; } Color(RCOLOR clr) { _clr = clr; } ~Color() { } operator const RCOLOR &() const { return _clr; } //operator RCOLOR &() { return _clr; } private: RCOLOR _clr; }; }; #endif // _COLOR_H_ --- NEW FILE: Win32_WMAL.h --- #ifndef _WIN32_WMAL_H_ #define _WIN32_WMAL_H_ #include "WMAL.h" namespace Rtk { class Win32WMAL : public WMAL { public: Win32WMAL(); ~Win32WMAL(); unsigned GetCaps() { return MANAGED; } int Init(); WMALHandle CreateWin(int x, int y, int w, int h, unsigned flags, void *data, WMALCallback cb); bool DestroyWin(WMALHandle win); bool SetWindowSize(WMALHandle win, int x, int y, int w, int h, unsigned flags); bool GetWindowSize(WMALHandle win, int &x, int &y, int &w, int &h); bool SetWindowCaption(WMALHandle win, const RCHAR *caption); bool GetWindowCaption(WMALHandle win, RCHAR *caption, int size); bool ShowWin(WMALHandle win, unsigned flags); bool HideWin(WMALHandle win); bool SetForeground(WMALHandle win); GD *PrepareGD(WMALHandle win); void UnprepareGD(WMALHandle win, GD *gd); void FlushWindow(WMALHandle win); protected: /* Called by VDAL */ void VdalCb(VDALHandle h, int event, long *args); }; }; #endif // _WIN32_WMAL_H_ --- NEW FILE: Window.h --- #ifndef _WINDOW_H_ #define _WINDOW_H_ #include "Group.h" #include "WMAL.h" #include "SList.h" namespace Rtk { class Window : public Group { public: static SList *GetWindowList(); enum CreateFlags { DOUBLEBUFFER = (1<<0) }; Window(); Window(int w, int h); virtual ~Window(); virtual void Flush(); int Create(); int Destroy(); WMALHandle GetHandle() const { return _wnd; } void SetCreateFlags(unsigned flags) { _create_flags = flags; } unsigned GetCreateFlags() const { return _create_flags; } protected: virtual WMALHandle CreateWin(unsigned flags); virtual void DestroyWin(WMALHandle hwnd); void WmalCb(WMALHandle h, int event, long *args); static void StaticWmalCb(WMALHandle h, int event, long *args) { ((Window*)h->userdata)->WmalCb(h, event, args); } private: WMALHandle _wnd; unsigned _create_flags; }; }; /* namespace Rtk */ #endif // _WINDOW_H_ --- NEW FILE: Win32_VDAL.h --- #ifndef _WIN32_VDAL_H_ #define _WIN32_VDAL_H_ #include "VDAL.h" #include <windows.h> namespace Rtk { class Win32VDAL : public VDAL { public: Win32VDAL(); virtual ~Win32VDAL(); VDALHandle CreateWin(int x, int y, int w, int h, unsigned flags, void *data, VDALCallback cb); bool DestroyWin(VDALHandle win); VDALHandle CreateOffscreen(int w, int h); bool ResizeOffscreen(VDALHandle offscr, int w, int h); bool DestroyOffscreen(VDALHandle offscr); bool Copy(VDALHandle dst, int x, int y, int w, int h, VDALHandle src, int srcx, int srcy); GD *CreateGD(VDALHandle win); GD *PrepareGD(VDALHandle win); void UnprepareGD(VDALHandle win, GD *gd); unsigned GetCaps() { return 0; } int Init(); int WaitEvent(int timeout); void Wakeup(); HINSTANCE Instance() const { return instance; } private: static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); HINSTANCE instance; bool owndc; DWORD procid; }; }; #endif // _VDAL_H_ --- NEW FILE: Pen.h --- #ifndef _PEN_H_ #define _PEN_H_ #include "Color.h" namespace Rtk { class GD; class Pen { public: Pen(); Pen(const Color &clr, int width = 1); Pen(const Pen &pen) { CopyFrom(pen); } virtual ~Pen(); Pen& operator = (const Pen& p) { CopyFrom(p); return *this; } Pen& operator = (const Color& c) { SetColor(c); return *this; } bool operator != (const Pen &p) const { return (_clr != p._clr || _width != p._width); } bool operator == (const Pen &p) const { return (_clr == p._clr && _width == p._width); } const Color &GetColor() const { return _clr; } void SetColor(const Color &clr); int GetWidth() const { return _width; } void SetWidth(int w); private: void CopyFrom(const Pen &p); Color _clr; int _width; }; }; #endif // _PEN_H_ --- NEW FILE: WMAL.h --- #ifndef _WMAL_H_ #define _WMAL_H_ #include "rchar.h" #include "VDAL.h" #include "GD.h" namespace Rtk { /* Forward declarations */ struct WMAL_DATA; /* Type definitions */ typedef WMAL_DATA *WMALHandle; typedef void (*WMALCallback)(WMALHandle h, int event, long *args); struct WMAL_DATA { void *userdata; WMALCallback cb; }; /** WMAL - Window Management Abstraction Layer * * @note This is just preliminary description * * WMAL controls all RTK windows. * WMAL is one level higher than VDAL, and is used by Rtk::Window class. * It's purpose is control window movement, stacking, caption, style and flushing. * * WMAL will manage window double buffering, if VDAL does not support it. * It uses VDAL offscreens to handle double buffering, if needed. * * WMAL uses VDAL to create WM specific windows. * However, WMAL does not have to use VDAL to create WM windows. * For example, when VDAL does not support that (framebuffer) * In that case, WMAL will create offscreen handles and manage windows it self (FakeWMAL) * * @note This is just preliminary description * * Most likely the flow is: * Rtk::Window -> WMAL -> VDAL -> OS * And other way around: * OS -> VDAL -> WMAL ->Rtk::Window * * In case there's no OS WM environment available (such as framebuffer) * Will VDAL report events for whole display and WMAL (FameWMAL) sends them to correct * Rtk::Window's. * * WMAL is responsible to pass events (such as KEYDOWN) to Rtk evetn subsystem. * */ class WMAL { public: enum { MANAGED = (1<<1) ///< OS WM managed windows }; WMAL() { wmal_instance = this; } virtual ~WMAL() { } static WMAL *Instance() { return wmal_instance; } void SetUserData(WMALHandle win, void *data) { win->userdata = data; } void *GetUserData(WMALHandle win) const { return win->userdata; } void SetCallback(WMALHandle win, WMALCallback cb) { win->cb = cb; } WMALCallback GetCallback(WMALHandle win) const { return win->cb; } virtual unsigned GetCaps() = 0; virtual int Init() = 0; virtual WMALHandle CreateWin(int x, int y, int w, int h, unsigned flags, void *data, WMALCallback cb) = 0; virtual bool DestroyWin(WMALHandle win) = 0; virtual bool SetWindowSize(WMALHandle win, int x, int y, int w, int h, unsigned flags) = 0; virtual bool GetWindowSize(WMALHandle win, int &x, int &y, int &w, int &h) = 0; virtual bool SetWindowCaption(WMALHandle win, const RCHAR *caption) = 0; virtual bool GetWindowCaption(WMALHandle win, RCHAR *caption, int size) = 0; virtual bool ShowWin(WMALHandle win, unsigned flags) = 0; virtual bool HideWin(WMALHandle win) = 0; virtual bool SetForeground(WMALHandle win) = 0; virtual GD *PrepareGD(WMALHandle win) = 0; virtual void UnprepareGD(WMALHandle win, GD *gd) = 0; /** Flush window to the screen. This does only something if window is double buffered */ virtual void FlushWindow(WMALHandle win) = 0; protected: static WMAL *wmal_instance; /* Called by VDAL */ virtual void VdalCb(VDALHandle h, int event, long *args) = 0; static void StaticVdalCb(VDALHandle h, int event, long *args) { wmal_instance->VdalCb(h, event, args); } }; }; #endif // _WMAL_H_ --- NEW FILE: Brush.h --- #ifndef _BRUSH_H_ #define _BRUSH_H_ #include "Color.h" namespace Rtk { class Brush { public: Brush(); Brush(const Color &clr); ~Brush(); const Color &GetColor() const { return _clr; } void SetColor(const Color &clr) { _clr = clr; } Brush& operator = (const Brush& b) { CopyFrom(b); return *this; } bool operator != (const Brush &b) const { return (_clr != b._clr); } bool operator == (const Brush &b) const { return (_clr == b._clr); } private: void CopyFrom(const Brush &br); Color _clr; }; }; #endif // _BRUSH_H_ --- NEW FILE: VDAL.h --- #ifndef _VDAL_H_ #define _VDAL_H_ namespace Rtk { class GD; /* Forward declarations */ struct VDAL_DATA; /* Type definitions */ typedef VDAL_DATA* VDALHandle; typedef void (*VDALCallback)(VDALHandle h, int event, long *args); struct VDAL_DATA { void *userdata; VDALCallback cb; }; enum { /** Called when window needs to be flushed by the underlying windowing environment, * such as X11 or Win32. * Args: * NONE */ WIN_FLUSH = 0, /** Called when window size has changed by the underlying windowing environment. * This happends, for example, when user drag the window corner to change size. * Args: * args[0]: New width * args[1]: New height * args[2]: Flags */ WIN_RESIZE, /** Called when user clicks the "X" (close) button in window titlebar or tries to close * some other way from underlying windowing environment. * Args: * NONE */ WIN_CLOSE, VDAL_LAST_EVENT }; /** VDAL - Video Device Abstraction Layer * * @note This is just preliminary description * * VDAL is the lowest level on RTK video system. * It is supposed to create instances underlying windowing system * handles, such as windows or offscreens. * * VDAL does not necessarily need underlying windowing system. * If no windowing system available, VDAL::CreateWin will return NULL. * VDAL::Init will create main display for RTK, for example, framebuffer access. * VDAL::CreateGD with NULL argument creates GD instance to main display. * In order to use such VDAL as a normal windowing environment "FakeWMAL" must be used (default) * * Events: * VDAL is not supposed to post anything to RTK internal event subsystem. * Instead VDAL passes ALL events to window handle associated callback, * which usually is WMAL internal callback. All events passed to RTK evet subsystem, * are passed from WMAL if needed. * * @note This is just preliminary description * * VDAL functions should not be called directly ever. * It is used only by WMAL and some RTK internal components. * */ class VDAL { public: VDAL() { vdal_instance = this; } virtual ~VDAL() { } /** Return pointer to current instance of VDAL */ static VDAL *Instance() { return vdal_instance; } void SetUserData(VDALHandle win, void *data) { win->userdata = data; } void *GetUserData(VDALHandle win) const { return win->userdata; } void SetCallback(VDALHandle win, VDALCallback cb) { win->cb = cb; } VDALCallback GetCallback(VDALHandle win) const { return win->cb; } /** Create window instance * If this is native VDAL implementation (such as framebuffer), * this function will return NULL. * * @param x X position of windowin screen, if -1 default position is used * @param y Y position of windowin screen, if -1 default position is used * @param w Width of the window * @param h Height of the window * @param flags Creation flags (TBD) * @param data Userdata to associate with window handle * @param cb Callback function to receive VDAL events * * @return VDALHandle to created window, or NULL on error. */ virtual VDALHandle CreateWin(int x, int y, int w, int h, unsigned flags, void *data, VDALCallback cb) = 0; /** Destroys the window */ virtual bool DestroyWin(VDALHandle win) = 0; /** Create offscreen instance * @param w Width of the offscreen image * @param h Height of the offscreen image * * @return VDALHandle to created offscreen, or NULL on error. */ virtual VDALHandle CreateOffscreen(int w, int h) = 0; /** Resize offscreen to specific size. */ virtual bool ResizeOffscreen(VDALHandle offscr, int w, int h) = 0; /** Destroy offscreen */ virtual bool DestroyOffscreen(VDALHandle offscr) = 0; /** Copy bits from handle to other. * @note High subject to change in future * * @param dst Handle to destination window or offscreen * @param x destination X position * @param y destination Y position * @param w destination width * @param h destination height * @param src Handle to source window or offscreen * @param srcx source X position * @param srcy source Y position */ virtual bool Copy(VDALHandle hdst, int x, int y, int w, int h, VDALHandle hsrc, int srcx, int srcy) = 0; /** Create new GD for window or offscreen. * Returned GD must be deleted with 'delete' operator after use */ virtual GD *CreateGD(VDALHandle handle) = 0; /** Prepare GD for use with specific window. * This sets underlying WM clip region if there's one. */ virtual GD *PrepareGD(VDALHandle handle) = 0; /** End GD drawing started by PrepareGD and free clipping region */ virtual void UnprepareGD(VDALHandle handle, GD *gd) = 0; /** Get capabilities of VDAL (TBD) */ virtual unsigned GetCaps() = 0; /** Init VDAL (TBD) */ virtual int Init() = 0; /** Wait for event * @param timeout Max time to wait in milliseconds * * @return Number of events received */ virtual int WaitEvent(int timeout) = 0; /** Make VDAL::WaitEvent return immediately. */ virtual void Wakeup() = 0; protected: static VDAL *vdal_instance; }; }; /* namespace Rtk */ #endif // _VDAL_H_ --- NEW FILE: Dummy_WMAL.h --- #ifndef _DUMMY_WMAL_H_ #define _DUMMY_WMAL_H_ #include "WMAL.h" namespace Rtk { class DummyWMAL : public WMAL { public: DummyWMAL(); ~DummyWMAL(); unsigned GetCaps() { return 0; } int Init() { return 1; } WMALHandle CreateWin(int x, int y, int w, int h, unsigned flags) { return 0; } bool DestroyWin(WMALHandle win) { return false; } bool SetWindowSize(WMALHandle win, int x, int y, int w, int h, unsigned flags) { return false; } bool GetWindowSize(WMALHandle win, int &x, int &y, int &w, int &h) { return false; } bool SetWindowCaption(WMALHandle win, const RCHAR *caption) { return false; } bool GetWindowCaption(WMALHandle win, RCHAR *caption, int size) { return false; } bool ShowWin(WMALHandle win, unsigned flags) { return false; } bool HideWin(WMALHandle win) { return false; } bool SetForeground(WMALHandle win) { return false; } }; }; #endif // _DUMMY_WMAL_H_ --- NEW FILE: Win32_GD.h --- #ifndef _WIN32_GD_H_ #define _WIN32_GD_H_ #include "Pen.h" #include "GD.h" #include <windows.h> namespace Rtk { class Win32GD : public GD { public: Win32GD(); virtual ~Win32GD(); void SetHWND(HWND wnd) { _wnd = wnd; } HWND GetHWND() const { return _wnd; } void SetHDC(HDC dc) { _dc = dc; } HDC GetHDC() const { return _dc; } /***********************/ /* Virtual functions */ unsigned GetCaps() { return 0; } bool BeginDraw(); bool EndDraw(); void DrawRect(int x, int y, int w, int h); void DrawLine(int x1, int y1, int x2, int y2); void UpdatePen(Pen &pen); void UpdateBrush(Brush &br); private: HWND _wnd; HDC _dc; HPEN _pen; HBRUSH _brush; }; }; #endif // _WIN32_GD_H_ |