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