sdk: const correctness
[sdk] / ecere / src / gfx / drivers / Win32ConsoleDisplayDriver.ec
1 namespace gfx::drivers;
2
3 import "instance"
4
5 #if defined(__WIN32__)
6
7 #define WIN32_LEAN_AND_MEAN
8 #define Method _Method
9 #define String _String
10 #include <windows.h>
11 #undef String
12 #undef Method
13
14 import "Display"
15
16 class CONDisplay : LFBDisplay
17 {
18    CHAR_INFO * charInfo;
19 };
20
21 class Win32ConsoleDisplayDriver : DisplayDriver
22 {
23    class_property(name) = "Win32Console";
24
25    bool CreateDisplaySystem(DisplaySystem displaySystem)
26    {
27       displaySystem.flags.text = true;
28       return true;
29    }
30
31    void DestroyDisplaySystem(DisplaySystem displaySystem)
32    {
33
34    }
35
36    void DestroyDisplay(Display display)
37    {
38       CONDisplay conDisplay = display.driverData;
39
40       ((subclass(DisplayDriver))class(LFBDisplayDriver)).DestroyDisplay(display);
41       delete conDisplay.charInfo;
42       delete conDisplay;
43       display.driverData = null;
44    }
45
46    void SetPalette(Display display, ColorAlpha * palette, bool colorMatch)
47    {
48
49    }
50
51    bool CreateDisplay(Display display)
52    {
53       bool result = false;
54       CONDisplay conDisplay = display.driverData = CONDisplay { };
55
56       if(display)
57       {
58          if(((subclass(DisplayDriver))class(LFBDisplayDriver)).CreateDisplay(display))
59          {
60
61             conDisplay.bitmap.pixelFormat = pixelFormatText;
62             result = true;
63          }
64       }
65       return result;
66    }
67
68    bool DisplaySize(Display display, int width, int height)
69    {
70       CONDisplay conDisplay = display.driverData;
71       bool result = false;
72
73       delete conDisplay.charInfo;
74
75       if((conDisplay.charInfo = new CHAR_INFO[width/textCellW * height/textCellH]))
76       {
77          display.width = width;
78          display.height = height;
79
80          result = true;
81       }
82       return result;
83    }
84
85    void DisplayPosition(Display display, int x, int y)
86    {
87
88    }
89
90    void RestorePalette(Display display)
91    {
92
93    }
94
95    void StartUpdate(Display display)
96    {
97    }
98
99    void EndUpdate(Display display)
100    {
101    }
102
103    void Scroll(Display display, Box scroll, int x, int y, Extent dirty)
104    {
105    }
106
107    void Update(Display display, Box updateBox)
108    {
109       CONDisplay conDisplay = display.driverData;
110
111       Box * box = updateBox;// ? updateBox : &conDisplay.updateBox;
112       COORD size, coord;
113       SMALL_RECT rect;
114
115       size.X = (short)(display.width / textCellW);
116       size.Y = (short)(display.height / textCellH);
117       coord.X = (short)(box->left / textCellW);
118       coord.Y = (short)(box->top / textCellH);
119       rect.Left = (short)(box->left / textCellW);
120       rect.Top = (short)(box->top / textCellH);
121       rect.Right = (short)(box->right / textCellW);
122       rect.Bottom = (short)(box->bottom / textCellH);
123
124       WriteConsoleOutput(display.window, conDisplay.charInfo,size,coord,&rect);
125
126       //((subclass(DisplayDriver))class(LFBDisplayDriver)).DisplayScreen(display, updateBox);
127    }
128
129    void FreeBitmap(DisplaySystem displaySystem, Bitmap bitmap)
130    {
131
132    }
133
134    bool MakeDDBitmap(DisplaySystem displaySystem, Bitmap bitmap, bool mipMaps)
135    {
136       return true;
137    }
138
139    bool GetSurface(Display display, Surface surface, int x,int y, Box clip)
140    {
141       if((surface.driverData = LFBSurface { }))
142          return ((subclass(DisplayDriver))class(LFBDisplayDriver)).GetSurface(display, surface, x, y, clip);
143       return false;
144    }
145
146    bool GetBitmapSurface(DisplaySystem displaySystem, Surface surface, Bitmap bitmap, int x,int y,Box clip)
147    {
148       return false;
149    }
150
151    void ReleaseSurface(Display display, Surface surface)
152    {
153       ((subclass(DisplayDriver))class(LFBDisplayDriver)).ReleaseSurface(display, surface);
154    }
155
156    void Clip(Display display, Surface surface, Box clip)
157    {
158       ((subclass(DisplayDriver))class(LFBDisplayDriver)).Clip(display, surface, clip);
159    }
160
161    bool GrabScreen(Display display, Bitmap bitmap, int x, int y, unsigned int w, unsigned int h)
162    {
163       return false;
164    }
165
166    void SetForeground(Display display, Surface surface, ColorAlpha color)
167    {
168       ((subclass(DisplayDriver))class(LFBDisplayDriver)).SetForeground(display, surface, color);
169    }
170
171    void SetBackground(Display display, Surface surface, ColorAlpha color)
172    {
173       ((subclass(DisplayDriver))class(LFBDisplayDriver)).SetBackground(display, surface, color);
174    }
175
176    ColorAlpha GetPixel(Display display, Surface surface, int x,int y)
177    {
178       return 0;
179    }
180
181    void PutPixel(Display display, Surface surface, int x,int y)
182    {
183       CONDisplay conDisplay = display.driverData;
184       LFBSurface conSurface = surface.driverData;
185
186       x /= textCellW;
187       y /= textCellH;
188       if((x<=surface.box.right)&&(y<=surface.box.bottom)&&(x>=surface.box.left)&&(y>=surface.box.top))
189       {
190          ((uint*)conDisplay.charInfo)[(y+surface.offset.y)*display.width / textCellW+x+surface.offset.x] =
191             ((conSurface.background|conSurface.foreground)<<8) | conSurface.drawingChar;
192       }
193    }
194
195    void DrawLine(Display display, Surface surface, int x1, int y1, int x2, int y2)
196    {
197       CONDisplay conDisplay = display.driverData;
198       LFBSurface conSurface = surface.driverData;
199
200       x1 /= textCellW;
201       x2 /= textCellW;
202       y1 /= textCellH;
203       y2 /= textCellH;
204       if(x1 == x2)
205       {
206          int y;
207          CHAR_INFO * lfbPtr;
208
209          if(y1>y2) { int tmp = y2; y2 = y1; y1 = tmp; }
210
211          if((x1>surface.box.right)||(x1<surface.box.left))return;
212          if((y1>surface.box.bottom)||(y2<surface.box.top))return;
213          if(y1<surface.box.top)y1=surface.box.top;
214          if(y2>surface.box.bottom)y2=surface.box.bottom;
215          if(y2 < y1) return;
216
217          lfbPtr = conDisplay.charInfo +
218             (y1+surface.offset.y)*display.width / textCellW+x1+surface.offset.x;
219          for(y = y1; y <= y2; y++)
220          {
221             if(conSurface.opaqueText)
222                lfbPtr->Attributes = (uint16)((conSurface.background | conSurface.foreground) >> 8);
223             else
224                lfbPtr->Attributes = (uint16)((conSurface.foreground >> 8) | (lfbPtr->Attributes & 0xF0));
225             lfbPtr->Char.AsciiChar = conSurface.drawingChar;
226             lfbPtr += display.width / textCellW;
227          }
228       }
229       else if(y1 == y2)
230       {
231          CHAR_INFO * lfbPtr;
232
233          if(x1>x2) { int tmp = x2; x2 = x1; x1 = tmp; }
234
235          if((y1>surface.box.bottom)||(y1<surface.box.top))return;
236          if((x1>surface.box.right)||(x2<surface.box.left))return;
237          if(x1<surface.box.left)x1=surface.box.left;
238          if(x2>surface.box.right)x2=surface.box.right;
239          if(x2 < x1) return;
240
241          lfbPtr = conDisplay.charInfo +
242             (y1+surface.offset.y)*display.width / textCellW+x1+surface.offset.x;
243
244          if(conSurface.opaqueText)
245             FillBytesBy4((DWORD*) lfbPtr,
246                ((conSurface.background | conSurface.foreground) << 8) | conSurface.drawingChar,
247                x2-x1+1);
248          else
249          {
250             int x;
251             for(x=x1;x<=x2; x++, lfbPtr++)
252             {
253                lfbPtr->Attributes = (uint16)((conSurface.foreground >> 8) | (lfbPtr->Attributes & 0xF0));
254                lfbPtr->Char.AsciiChar = conSurface.drawingChar;
255             }
256          }
257       }
258    }
259
260    void Rectangle(Display display, Surface surface,int x1,int y1,int x2,int y2)
261    {
262
263    }
264
265    void Area(Display display, Surface surface,int x1,int y1,int x2,int y2)
266    {
267       CONDisplay conDisplay = display.driverData;
268       LFBSurface conSurface = surface.driverData;
269
270       x1 /= textCellW;
271       x2 /= textCellW;
272       y1 /= textCellH;
273       y2 /= textCellH;
274
275       if(x1>x2) { int tmp = x2; x2 = x1; x1 = tmp; }
276
277       if(x1<surface.box.left)  x1=surface.box.left;
278       if(x2>surface.box.right) x2=surface.box.right;
279       if(y1<surface.box.top)   y1=surface.box.top;
280       if(y2>surface.box.bottom)  y2=surface.box.bottom;
281
282       if(x2>=x1 && y2>=y1)
283       {
284          CHAR_INFO *lfbPtr = conDisplay.charInfo +
285             (y1+surface.offset.y)*display.width / textCellW+x1+surface.offset.x;
286          int y;
287          for(y=y1;y<=y2; y++)
288          {
289             FillBytesBy4((DWORD *)lfbPtr,((conSurface.background | conSurface.foreground)<<8)|conSurface.drawingChar,x2-x1+1);
290             lfbPtr+=display.width / textCellW;
291          }
292       }
293    }
294
295    void Clear(Display display, Surface surface, ClearType flags)
296    {
297       Area(display, surface, 0, 0, surface.width - 1, surface.height - 1);
298    }
299
300    bool ConvertBitmap(DisplaySystem displaySystem, Bitmap src, PixelFormat format, ColorAlpha * palette)
301    {
302       return true;
303    }
304
305    bool AllocateBitmap(DisplaySystem displaySystem, Bitmap bitmap, int width, int height, int stride, PixelFormat format, bool allocatePalette)
306    {
307       return false;
308    }
309
310    void Blit(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h)
311    {
312
313    }
314
315    void Stretch(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
316    {
317
318    }
319
320    void Filter(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
321    {
322
323    }
324
325    void BlitDI(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h)
326    {
327
328    }
329
330    void StretchDI(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
331    {
332
333    }
334
335    void FilterDI(Display display, Surface surface, Bitmap src, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
336    {
337
338    }
339
340    Font LoadFont(DisplaySystem displaySystem, const char * string, float size, FontFlags flags)
341    {
342       return (void *) bool::true;
343    }
344
345    void UnloadFont(DisplaySystem displaySystem, Font font)
346    {
347
348    }
349
350    void TextFont(Display display, Surface surface, void * font)
351    {
352    }
353
354    void TextOpacity(Display display, Surface surface, bool opaque)
355    {
356       ((subclass(DisplayDriver))class(LFBDisplayDriver)).TextOpacity(display, surface, opaque);
357    }
358
359    void WriteText(Display display, Surface surface, int x, int y, const char * text, int len)
360    {
361       CONDisplay conDisplay = display.driverData;
362       LFBSurface conSurface = surface.driverData;
363       CHAR_INFO * lfbPtr = conDisplay.charInfo;
364       int c;
365
366       x /= textCellW;
367       y /= textCellH;
368
369       if(y > surface.box.bottom || y < surface.box.top)
370          return;
371       lfbPtr += (y+surface.offset.y) * display.width / textCellW + x + surface.offset.x;
372       for(c=0; (c<len && x < surface.box.left); c++, x++,lfbPtr++);
373       for(; (c<len && x <= surface.box.right); c++, x++,lfbPtr++)
374       {
375          if(!conSurface.opaqueText)
376          {
377             lfbPtr->Attributes = (uint16)((conSurface.foreground >> 8) | (lfbPtr->Attributes & 0xF0));
378             lfbPtr->Char.AsciiChar = text[c];
379          }
380          else
381          {
382             lfbPtr->Attributes = (uint16)((conSurface.background|conSurface.foreground) >> 8);
383             lfbPtr->Char.AsciiChar = text[c];
384          }
385       }
386    }
387
388    void FontExtent(DisplaySystem displaySystem, void * font, const char * text, int len, int * width, int * height)
389    {
390       ((subclass(DisplayDriver))class(LFBDisplayDriver)).FontExtent(displaySystem, font, text, len, width, height);
391    }
392
393    void TextExtent(Display display, Surface surface, const char * text, int len, int * width, int * height)
394    {
395       FontExtent(display.displaySystem, null, text, len, width, height);
396    }
397
398    void DrawingChar(Display display, Surface surface, char character)
399    {
400       ((subclass(DisplayDriver))class(LFBDisplayDriver)).DrawingChar(display, surface, character);
401    }
402
403    void LineStipple(Display display, Surface surface, uint stipple)
404    {
405
406    }
407
408    bool Lock(Display display)
409    {
410       return true;
411    }
412
413    void Unlock(Display display)
414    {
415    }
416 }
417
418 #endif