Subversion Repositories Kolibri OS

Rev

Rev 1805 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #ifndef _GRAPHIC_DRAW_H
  2. #define _GRAPHIC_DRAW_H
  3.  
  4. #include <limits.h>
  5. #include <string.h>
  6.  
  7. #ifdef _Windows
  8. # include <windows.h>
  9. #endif
  10.  
  11. template<class TRealGraphDraw>
  12. class TBaseGraphDraw
  13. {
  14. public:
  15.   union event
  16.   {
  17.     enum evtype {noevent = 0, draw, button_down, button_up,
  18.                  mouse_move, key_down, key_up, start, close} type;
  19.  
  20.     struct evany
  21.     {
  22.       evtype type;
  23.       TRealGraphDraw *drw;
  24.     } any;
  25.  
  26.     struct evbutton : public evany
  27.     {
  28.       int x, y, n;
  29.     } button;
  30.  
  31.     struct evkey : public evany
  32.     {
  33.       unsigned long k;
  34.     } key;
  35.   };
  36.  
  37.   enum {button_down_mask = 0x1, button_up_mask = 0x2, key_down_mask = 0x4,
  38.         key_up_mask = 0x8, mouse_move_mask = 0x10, mouse_drag_mask = 0x20};
  39.  
  40.   enum {ret_setcapture = 0x10};
  41. public:
  42.   TBaseGraphDraw(const char *s = 0) : title(0), about_info(0),
  43.                 evfunc(0), id(0), data(0) {CopyTitle(s);}
  44.   ~TBaseGraphDraw() {FreeTitle();}
  45.  
  46.   unsigned long GetBlackColor() {return 0;}
  47.   unsigned long GetWhiteColor() {return 0xFFFFFFL;}
  48.   unsigned long CreateColor(unsigned short red,
  49.                          unsigned short green, unsigned short blue);
  50.   void FreeColor(unsigned long c) {}
  51.   unsigned long GetBgColor() {return GetWhiteColor();}
  52.   void SetBgColor(unsigned long c) {}
  53.  
  54.   void SetTitle(const char *s) {CopyTitle(s);}
  55.   const char *GetTitle() const {return title;}
  56.  
  57.   int GetStatus() {return 0;}  //1 - can draw, 0 - can't draw, <0 - error
  58.   int Init() {return 0;}
  59.   void UnInit() {}
  60.   int Run(int evmask = 0, int w = INT_MIN, int h = INT_MIN) {return -100;}
  61.  
  62.   void GetSize(int &w, int &h) {w = 200; h = 200;}
  63.   int OpenDraw() {return 0;}
  64.   int IsDraw() {return 0;}
  65.   void CloseDraw() {}
  66.  
  67.   int SetColor(unsigned long c) {return 0;}
  68.   int DrawLine(int x0, int y0, int x1, int y1) {return 0;}
  69.   int DrawText(int x0, int y0, char *text) {return 0;}
  70.   int DrawClear() {return 0;}
  71.   int GetTextH(const char *s) {return 16;}
  72.   int GetTextW(const char *s) {return 8 * strlen(s);}
  73.   void Quit(int q = 1) {}
  74.   void ResReinit(int w = INT_MIN, int h = INT_MIN) {}
  75.   int GetAboutInfo() {return about_info;}
  76.   void SetAboutInfo(int inf) {about_info = inf;}
  77. protected:
  78.   void FreeTitle() {if (title) {delete[] title; title = 0;}}
  79.   void CopyTitle(const char *s);
  80.   char *title;
  81.   int about_info;
  82. public:
  83.   int (*evfunc)(const event &ev);
  84.   int id;
  85.   void *data;
  86. };
  87.  
  88. template<class TRealGraphDraw>
  89. unsigned long TBaseGraphDraw<TRealGraphDraw>::CreateColor(unsigned short red,
  90.                           unsigned short green, unsigned short blue)
  91. {
  92.   return (unsigned long)(red >> 8) + ((unsigned long)(green >> 8) << 8) +
  93.          ((unsigned long)(blue >> 8) << 16);
  94. }
  95.  
  96. template<class TRealGraphDraw>
  97. void TBaseGraphDraw<TRealGraphDraw>::CopyTitle(const char *s)
  98. {
  99.   FreeTitle();
  100.   if (s) {title = new char[strlen(s) + 1]; strcpy(title, s);}
  101. }
  102.  
  103. #if defined _KOLIBRI
  104. # include "kolibri-draw.h"
  105.   typedef TKlbrGraphDraw TMainGraphDraw;
  106. #elif defined __GNUC__
  107. # include "gnu-draw.h"
  108.   typedef TGnuGraphDraw TMainGraphDraw;
  109. #elif defined _Windows
  110. # include "win-draw.h"
  111.   typedef TWinGraphDraw TMainGraphDraw;
  112. #elif defined __MSDOS__
  113. # include "dos-draw.h"
  114.   typedef TDosGraphDraw TMainGraphDraw;
  115. #else
  116. #error "Unknown platform"
  117. #endif
  118. typedef TMainGraphDraw TGraphDraw;
  119.  
  120. #endif  //_GRAPHIC_DRAW_H
  121.