Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
1805 yogev_ezra 1
#ifndef _GRAPHIC_DRAW_H
2
#define _GRAPHIC_DRAW_H
3
 
4
#include 
5
#include 
6
 
7
#ifdef _Windows
8
# include 
9
#endif
10
 
5123 clevermous 11
template
12
class TBaseGraphDraw
1805 yogev_ezra 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;
5123 clevermous 23
      TRealGraphDraw *drw;
1805 yogev_ezra 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:
5123 clevermous 42
  TBaseGraphDraw(const char *s = 0) : title(0), about_info(0),
1805 yogev_ezra 43
                evfunc(0), id(0), data(0) {CopyTitle(s);}
5123 clevermous 44
  ~TBaseGraphDraw() {FreeTitle();}
1805 yogev_ezra 45
 
5123 clevermous 46
  unsigned long GetBlackColor() {return 0;}
47
  unsigned long GetWhiteColor() {return 0xFFFFFFL;}
48
  unsigned long CreateColor(unsigned short red,
1805 yogev_ezra 49
                         unsigned short green, unsigned short blue);
5123 clevermous 50
  void FreeColor(unsigned long c) {}
51
  unsigned long GetBgColor() {return GetWhiteColor();}
52
  void SetBgColor(unsigned long c) {}
1805 yogev_ezra 53
 
5123 clevermous 54
  void SetTitle(const char *s) {CopyTitle(s);}
1805 yogev_ezra 55
  const char *GetTitle() const {return title;}
56
 
5123 clevermous 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;}
1805 yogev_ezra 61
 
5123 clevermous 62
  void GetSize(int &w, int &h) {w = 200; h = 200;}
63
  int OpenDraw() {return 0;}
64
  int IsDraw() {return 0;}
65
  void CloseDraw() {}
1805 yogev_ezra 66
 
5123 clevermous 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;}
1805 yogev_ezra 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
 
5123 clevermous 88
template
89
unsigned long TBaseGraphDraw::CreateColor(unsigned short red,
1805 yogev_ezra 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
 
5123 clevermous 96
template
97
void TBaseGraphDraw::CopyTitle(const char *s)
1805 yogev_ezra 98
{
99
  FreeTitle();
100
  if (s) {title = new char[strlen(s) + 1]; strcpy(title, s);}
101
}
102
 
5123 clevermous 103
#if defined _KOLIBRI
104
# include "kolibri-draw.h"
105
  typedef TKlbrGraphDraw TMainGraphDraw;
106
#elif defined __GNUC__
1805 yogev_ezra 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
5123 clevermous 116
#error "Unknown platform"
1805 yogev_ezra 117
#endif
5123 clevermous 118
typedef TMainGraphDraw TGraphDraw;
1805 yogev_ezra 119
 
120
#endif  //_GRAPHIC_DRAW_H