/[pearpc]/src/system/display.h
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /src/system/display.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations)
Wed Sep 5 17:11:21 2007 UTC (16 years, 6 months ago) by dpavlin
File MIME type: text/plain
File size: 7084 byte(s)
import upstream CVS
1 /*
2 * HT Editor
3 * display.h
4 *
5 * Copyright (C) 2003,2004 Stefan Weyergraf
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #ifndef __SYSTEM_DISPLAY_H__
22 #define __SYSTEM_DISPLAY_H__
23
24 #include "tools/data.h"
25 #include "tools/stream.h"
26 #include "types.h"
27 #include "keyboard.h"
28
29 /* codepages */
30
31 #define CP_DEVICE 0
32 #define CP_GRAPHICAL 1
33 #define CP_WINDOWS 0x100
34
35 /* "graphical" chars (ie. lines, corners and patterns like in ASCII) */
36
37 #define GC_TRANSPARENT '0' // transparent
38
39 extern byte * gFrameBuffer;
40 extern int gDamageAreaFirstAddr, gDamageAreaLastAddr;
41
42 inline void damageFrameBuffer(int addr)
43 {
44 if (addr < gDamageAreaFirstAddr) {
45 gDamageAreaFirstAddr = addr;
46 }
47
48 if (addr > gDamageAreaLastAddr) {
49 gDamageAreaLastAddr = addr;
50 }
51 }
52
53 inline void damageFrameBufferAll()
54 {
55 gDamageAreaFirstAddr = 0;
56 gDamageAreaLastAddr = 0xffffff0;
57 }
58
59 inline void healFrameBuffer()
60 {
61 gDamageAreaFirstAddr = 0xffffff0;
62 gDamageAreaLastAddr = 0;
63 }
64
65 /* virtual colors */
66
67 typedef int vc;
68
69 #define VC_BLACK 0
70 #define VC_BLUE 1
71 #define VC_GREEN 2
72 #define VC_CYAN 3
73 #define VC_RED 4
74 #define VC_MAGENTA 5
75 #define VC_YELLOW 6
76 #define VC_WHITE 7
77 #define VC_TRANSPARENT 8
78
79 #define VC_LIGHT(vc) ((vc) | 0x80)
80
81 #define VC_GET_LIGHT(vc) ((vc) & 0x80)
82 #define VC_GET_BASECOLOR(vc) ((vc) & 0x7f)
83
84 /* virtual color pairs (fg/bg) */
85
86 typedef int vcp;
87
88 #define VCP(vc_fg, vc_bg) (vcp)((vc_bg) | ((vc_fg)<<8))
89 #define VCP_BACKGROUND(v) ((v) & 0xff)
90 #define VCP_FOREGROUND(v) ((v>>8) & 0xff)
91
92 struct BufferedChar {
93 uint rawchar;
94 vcp color;
95 };
96
97 class DisplayCharacteristics: public Object {
98 public:
99 int width, height;
100 int bytesPerPixel; // may only be 1, 2 or 4
101 int scanLineLength;
102 int vsyncFrequency;
103
104 int redShift;
105 int redSize;
106 int greenShift;
107 int greenSize;
108 int blueShift;
109 int blueSize;
110
111 inline DisplayCharacteristics & operator =(const DisplayCharacteristics &chr)
112 {
113 width = chr.width;
114 height = chr.height;
115 bytesPerPixel = chr.bytesPerPixel;
116 scanLineLength = chr.scanLineLength;
117 vsyncFrequency = chr.vsyncFrequency;
118
119 redShift = chr.redShift;
120 redSize = chr.redSize;
121 greenShift = chr.greenShift;
122 greenSize = chr.greenSize;
123 blueShift = chr.blueShift;
124 blueSize = chr.blueSize;
125 return *this;
126 }
127
128 #define COMPARE(a) do { \
129 if (a < ((DisplayCharacteristics *)obj)->a) return -1; \
130 if (a > ((DisplayCharacteristics *)obj)->a) return 1; \
131 } while (0);
132
133 virtual int compareTo(const Object *obj) const
134 {
135 COMPARE(width);
136 COMPARE(height);
137 COMPARE(bytesPerPixel);
138 COMPARE(scanLineLength);
139 COMPARE(vsyncFrequency);
140 COMPARE(redShift);
141 COMPARE(redSize);
142 COMPARE(greenShift);
143 COMPARE(greenSize);
144 COMPARE(blueShift);
145 COMPARE(blueSize);
146 return 0;
147 }
148 #undef COMPARE
149
150 };
151
152 void dumpDisplayChar(const DisplayCharacteristics &chr);
153
154 typedef uint32 RGB;
155 typedef uint32 RGBA;
156
157 #define RGBA_R(rgba) (rgba & 0xff)
158 #define RGBA_G(rgba) ((rgba>>8) & 0xff)
159 #define RGBA_B(rgba) ((rgba>>16) & 0xff)
160 #define RGBA_A(rgba) ((rgba>>24) & 0xff)
161 #define MK_RGBA(r, g, b, a) ((r) | ((g)<<8) | ((b)<<16) | ((a)<<24))
162 #define RGBA_SETA(rgba, a) (((rgba) & 0xffffff) | (a<<24));
163
164 #define RGB_R(rgb) (rgb & 0xff)
165 #define RGB_G(rgb) ((rgb>>8) & 0xff)
166 #define RGB_B(rgb) ((rgb>>16) & 0xff)
167 #define MK_RGB(r, g, b) ((r) | ((g)<<8) | ((b)<<16))
168
169 #define KEYB_LED_NUM 1
170 #define KEYB_LED_CAPS 2
171 #define KEYB_LED_SCROLL 3
172
173 class SystemDisplay: public Object
174 {
175 protected:
176 Object *vt;
177 Object *mFont;
178 int mVTWidth;
179 int mVTHeight;
180 int mVTDX;
181 int mVTDY;
182 bool mExposed;
183 RGB palette[256]; // only used in indexed modes
184
185 /* hw cursor */
186 int mHWCursorX, mHWCursorY;
187 int mHWCursorVisible;
188 byte * mHWCursorData;
189
190 public: // until we know better
191 /* menu */
192 int mMenuX, mMenuHeight;
193 Array * mMenu;
194
195 bool mMouseGrabbed;
196 int mRedraw_ms;
197 int mCurMouseX, mCurMouseY;
198 int mResetMouseX, mResetMouseY;
199 int mHomeMouseX, mHomeMouseY;
200 bool mFullscreen;
201 bool mFullscreenChanged;
202
203 static inline void convertBaseColor(uint &b, uint fromBits, uint toBits)
204 {
205 if (toBits > fromBits) {
206 b <<= toBits - fromBits;
207 } else {
208 b >>= fromBits - toBits;
209 }
210 }
211
212 void mixRGB();
213 public:
214 DisplayCharacteristics mClientChar;
215 BufferedChar *buf;
216
217 SystemDisplay(const DisplayCharacteristics &aClientChr, int redraw_ms);
218 virtual ~SystemDisplay();
219
220 virtual void displayShow() = 0;
221
222 /*
223 * Note: this function might do different things when in / not in fullscreen
224 * mode.
225 */
226 virtual void convertCharacteristicsToHost(DisplayCharacteristics &aHostChar, const DisplayCharacteristics &aClientChar) = 0;
227
228 virtual bool changeResolution(const DisplayCharacteristics &aChar) = 0;
229 bool setFullscreenMode(bool fullscreen);
230 virtual void getHostCharacteristics(Container &modes) = 0;
231
232 /* VT */
233 bool openVT(int width, int height, int dx, int dy, File &font);
234 void closeVT();
235 void print(const char *s);
236 void printf(const char *s, ...);
237 virtual void drawChar(int x, int y, vcp color, byte chr);
238 virtual void fillVT(int x, int y, int w, int h, vcp color, byte chr);
239 virtual void fillAllVT(vcp color, byte chr);
240 void setAnsiColor(vcp color);
241
242 /* ui */
243 void insertMenuButton(Stream &str, void (*callback)(void *), void *p);
244 virtual void updateTitle() = 0;
245 virtual void finishMenu() = 0;
246 void drawMenu();
247 void clickMenu(int x, int y);
248 void composeKeyDialog();
249 void drawCircleFilled(int x, int y, int w, int h, int cx, int cy, int radius, RGBA fg, RGBA bg);
250 void drawBox(int x, int y, int w, int h, RGBA fg, RGBA bg);
251 void setHWCursor(int x, int y, bool visible, byte *data);
252 void setColor(int idx, RGB color);
253 RGB getColor(int idx);
254 void fillRGB(int x, int y, int w, int h, RGB rgb);
255 void fillRGBA(int x, int y, int w, int h, RGBA rgba);
256 void mixRGB(byte *pixel, RGB rgb);
257 void mixRGBA(byte *pixel, RGBA rgba);
258 void outText(int x, int y, RGBA fg, RGBA bg, const char *text);
259 void putPixelRGB(int x, int y, RGB rgb);
260 void putPixelRGBA(int x, int y, RGBA rgba);
261
262 inline void setExposed(bool exposed)
263 {
264 mExposed = exposed;
265 }
266
267 inline bool isExposed()
268 {
269 return mExposed;
270 }
271
272 inline bool isMouseGrabbed()
273 {
274 return mMouseGrabbed;
275 }
276
277 virtual void setMouseGrab(bool mouseGrab);
278 };
279
280 extern SystemDisplay *gDisplay;
281
282 // should be declared elsewhere
283 void initUI(const char *title, const DisplayCharacteristics &aCharacteristics, int redraw_ms, const KeyboardCharacteristics &keyCharacteristics, bool fullscreen);
284 void doneUI();
285
286 #endif /* __SYSTEM_DISPLAY_H__ */

  ViewVC Help
Powered by ViewVC 1.1.26