]> Shamusworld >> Repos - apple2/blob - src/gui/gui.cpp
6960a9675cf87f4b8d5916f8a666507069730654
[apple2] / src / gui / gui.cpp
1 //
2 // gui.cpp
3 //
4 // Graphical User Interface support
5 // by James Hammons
6 // © 2014-2019 Underground Software
7 //
8 // JLH = James Hammons <jlhamm@acm.org>
9 //
10 // WHO  WHEN        WHAT
11 // ---  ----------  -----------------------------------------------------------
12 // JLH  02/03/2006  Created this file
13 // JLH  03/13/2006  Added functions to allow shutting down GUI externally
14 // JLH  03/22/2006  Finalized basic multiple window support
15 // JLH  03/03/2014  Refactored GUI to use SDL 2, more modern approach as well
16 //
17 // STILL TO DO:
18 //
19 // - Memory leak on quitting with a window active [DONE]
20 // - Multiple window handling [DONE]
21 //
22
23 #include "gui.h"
24 #include <vector>
25 #include "apple2.h"
26 #include "config.h"
27 #include "diskselector.h"
28 #include "elements.h"
29 #include "floppydrive.h"
30 #include "font10pt.h"
31 #include "log.h"
32 #include "video.h"
33
34 // Icons, in GIMP "C" format
35 #include "gfx/icon-selection.c"
36 #include "gfx/disk-icon.c"
37 #include "gfx/power-off-icon.c"
38 #include "gfx/power-on-icon.c"
39 #include "gfx/disk-swap-icon.c"
40 #include "gfx/disk-door-open.c"
41 #include "gfx/disk-door-closed.c"
42 #include "gfx/save-state-icon.c"
43 #include "gfx/load-state-icon.c"
44 #include "gfx/config-icon.c"
45
46
47 // Okay, this is ugly but works and I can't think of any better way to handle
48 // this. So what we do when we pass the GIMP bitmaps into a function is pass
49 // them as a (void *) and then cast them as type (Bitmap *) in order to use
50 // them. Yes, it's ugly. Come up with something better!
51
52 struct Bitmap {
53         unsigned int width;
54         unsigned int height;
55         unsigned int bytesPerPixel;                                     // 3:RGB, 4:RGBA
56         unsigned char pixelData[];
57 };
58
59
60 const char numeralOne[(7 * 7) + 1] =
61         "  @@   "
62         " @@@   "
63         "@@@@   "
64         "  @@   "
65         "  @@   "
66         "  @@   "
67         "@@@@@@ ";
68
69 const char numeralTwo[(7 * 7) + 1] =
70         " @@@@@ "
71         "@@   @@"
72         "    @@@"
73         "  @@@@ "
74         " @@@   "
75         "@@     "
76         "@@@@@@@";
77
78 const char ejectIcon[(8 * 7) + 1] =
79         "   @@   "
80         "  @@@@  "
81         " @@@@@@ "
82         "@@@@@@@@"
83         "        "
84         "@@@@@@@@"
85         "@@@@@@@@";
86
87 const char newDiskIcon[(30 * 6) + 1] =
88         "@@   @@ @@@@@ @@   @@     @@  "
89         "@@@  @@ @@    @@   @@    @@@@ "
90         "@@@@ @@ @@@@  @@ @ @@   @@@@@@"
91         "@@ @@@@ @@    @@@@@@@     @@  "
92         "@@  @@@ @@    @@@@@@@  @@@@@  "
93         "@@   @@ @@@@@ @@   @@  @@@@   ";
94
95 const char driveLight[(5 * 5) + 1] =
96         " @@@ "
97         "@@@@@"
98         "@@@@@"
99         "@@@@@"
100         " @@@ ";
101
102
103 SDL_Texture * GUI::overlay = NULL;
104 SDL_Rect GUI::olDst;
105 int GUI::sidebarState = SBS_HIDDEN;
106 int32_t GUI::dx = 0;
107 int32_t GUI::iconSelected = -1;
108 bool GUI::hasKeyboardFocus = false;
109 bool GUI::powerOnState = true;
110
111 int32_t lastIconSelected = -1;
112 SDL_Texture * iconSelection = NULL;
113 SDL_Texture * diskIcon = NULL;
114 SDL_Texture * disk1Icon = NULL;
115 SDL_Texture * disk2Icon = NULL;
116 SDL_Texture * powerOnIcon = NULL;
117 SDL_Texture * powerOffIcon = NULL;
118 SDL_Texture * diskSwapIcon = NULL;
119 SDL_Texture * stateSaveIcon = NULL;
120 SDL_Texture * stateLoadIcon = NULL;
121 SDL_Texture * configIcon = NULL;
122 SDL_Texture * doorOpen = NULL;
123 SDL_Texture * doorClosed = NULL;
124 uint32_t texturePointer[128 * 380];
125 const char iconHelp[7][80] = { "Turn emulated Apple off/on",
126         "Insert floppy image into drive #1", "Insert floppy image into drive #2",
127         "Swap disks", "Save emulator state", "Load emulator state",
128         "Configure Apple2" };
129 bool disk1EjectHovered = false;
130 bool disk2EjectHovered = false;
131 bool disk1NewDiskHovered = false;
132 bool disk2NewDiskHovered = false;
133
134 SDL_Texture * GUI::charStamp = NULL;
135 uint32_t GUI::stamp[FONT_WIDTH * FONT_HEIGHT];
136
137 #define SIDEBAR_X_POS  (VIRTUAL_SCREEN_WIDTH - 80)
138
139 //std::vector<void *> objList;
140
141
142 GUI::GUI(void)
143 {
144 }
145
146
147 GUI::~GUI(void)
148 {
149 }
150
151
152 void GUI::Init(SDL_Renderer * renderer)
153 {
154         overlay = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ABGR8888,
155                 SDL_TEXTUREACCESS_TARGET, 128, 380);
156         charStamp = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888,
157                 SDL_TEXTUREACCESS_TARGET, FONT_WIDTH, FONT_HEIGHT);
158
159         if (!overlay)
160         {
161                 WriteLog("GUI: Could not create overlay!\n");
162                 return;
163         }
164
165         if (SDL_SetTextureBlendMode(overlay, SDL_BLENDMODE_BLEND) == -1)
166                 WriteLog("GUI: Could not set blend mode for overlay.\n");
167
168         if (SDL_SetTextureBlendMode(charStamp, SDL_BLENDMODE_BLEND) == -1)
169                 WriteLog("GUI: Could not set blend mode for charStamp.\n");
170
171         for(uint32_t i=0; i<128*380; i++)
172                 texturePointer[i] = 0xB0A000A0;
173
174         SDL_UpdateTexture(overlay, NULL, texturePointer, 128 * sizeof(Uint32));
175
176         olDst.x = VIRTUAL_SCREEN_WIDTH;
177         olDst.y = 2;
178         olDst.w = 128;
179         olDst.h = 380;
180
181         iconSelection  = CreateTexture(renderer, &icon_selection);
182         diskIcon       = CreateTexture(renderer, &disk_icon);
183         doorOpen       = CreateTexture(renderer, &door_open);
184         doorClosed     = CreateTexture(renderer, &door_closed);
185         disk1Icon      = CreateTexture(renderer, &disk_icon);
186         disk2Icon      = CreateTexture(renderer, &disk_icon);
187         powerOffIcon   = CreateTexture(renderer, &power_off);
188         powerOnIcon    = CreateTexture(renderer, &power_on);
189         diskSwapIcon   = CreateTexture(renderer, &disk_swap);
190         stateSaveIcon  = CreateTexture(renderer, &save_state);
191         stateLoadIcon  = CreateTexture(renderer, &load_state);
192         configIcon     = CreateTexture(renderer, &config);
193
194         // Set up drive icons in their current states
195 //      AssembleDriveIcon(renderer, 0);
196 //      AssembleDriveIcon(renderer, 1);
197
198         if (SDL_SetRenderTarget(renderer, overlay) < 0)
199         {
200                 WriteLog("GUI: Could not set Render Target to overlay... (%s)\n", SDL_GetError());
201         }
202         else
203         {
204                 DrawSidebarIcons(renderer);
205                 // Set render target back to default
206                 SDL_SetRenderTarget(renderer, NULL);
207         }
208
209         DiskSelector::Init(renderer);
210         Config::Init(renderer);
211         WriteLog("GUI: Successfully initialized.\n");
212 }
213
214
215 SDL_Texture * GUI::CreateTexture(SDL_Renderer * renderer, const void * source)
216 {
217         Bitmap * bitmap = (Bitmap *)source;
218         SDL_Texture * texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ABGR8888,
219 //              SDL_TEXTUREACCESS_STATIC, bitmap->width, bitmap->height);
220                 SDL_TEXTUREACCESS_TARGET, bitmap->width, bitmap->height);
221         SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
222         SDL_UpdateTexture(texture, NULL, (Uint32 *)bitmap->pixelData,
223                 bitmap->width * sizeof(Uint32));
224
225         return texture;
226 }
227
228
229 void GUI::MouseDown(int32_t x, int32_t y, uint32_t buttons)
230 {
231         DiskSelector::MouseDown(x, y, buttons);
232         Config::MouseDown(x, y, buttons);
233
234         if (sidebarState != SBS_SHOWN)
235                 return;
236
237         switch (iconSelected)
238         {
239         // Power
240         case 0:
241                 powerOnState = !powerOnState;
242                 SetPowerState();
243
244                 if (!powerOnState)
245                         SpawnMessage("*** POWER OFF ***");
246
247                 break;
248         // Disk #1
249         case 1:
250                 SpawnMessage("*** DISK #1 ***");
251
252                 if (disk1EjectHovered && !floppyDrive[0].IsEmpty(0))
253                 {
254                         floppyDrive[0].EjectImage(0);
255                         SpawnMessage("*** DISK #1 EJECTED ***");
256                 }
257
258                 if (!disk1EjectHovered && !disk1NewDiskHovered)
259                 {
260                         // Load the disk selector
261                         Config::HideWindow();
262                         DiskSelector::ShowWindow(0);
263                 }
264
265                 break;
266         // Disk #2
267         case 2:
268                 SpawnMessage("*** DISK #2 ***");
269
270                 if (disk2EjectHovered && !floppyDrive[0].IsEmpty(1))
271                 {
272                         floppyDrive[0].EjectImage(1);
273                         SpawnMessage("*** DISK #2 EJECTED ***");
274                 }
275
276                 if (!disk2EjectHovered && !disk2NewDiskHovered)
277                 {
278                         // Load the disk selector
279                         Config::HideWindow();
280                         DiskSelector::ShowWindow(1);
281                 }
282
283                 break;
284         // Swap disks
285         case 3:
286                 floppyDrive[0].SwapImages();
287                 SpawnMessage("*** DISKS SWAPPED ***");
288                 break;
289         // Save state
290         case 4:
291                 SpawnMessage("*** SAVE STATE ***");
292                 break;
293         // Load state
294         case 5:
295                 SpawnMessage("*** LOAD STATE ***");
296                 break;
297         // Configuration
298         case 6:
299                 SpawnMessage("*** CONFIGURATION ***");
300                 // Load the configuration window
301                 DiskSelector::HideWindow();
302                 Config::ShowWindow();
303                 break;
304         }
305 }
306
307
308 void GUI::MouseUp(int32_t x, int32_t y, uint32_t buttons)
309 {
310         DiskSelector::MouseUp(x, y, buttons);
311         Config::MouseUp(x, y, buttons);
312 }
313
314
315 void GUI::MouseMove(int32_t x, int32_t y, uint32_t buttons)
316 {
317         DiskSelector::MouseMove(x, y, buttons);
318         Config::MouseMove(x, y, buttons);
319
320         if (sidebarState != SBS_SHOWN)
321         {
322                 iconSelected = -1;
323
324                 if (x > SIDEBAR_X_POS)
325                 {
326 //printf("GUI: sidebar showing (x = %i)...\n", x);
327                         sidebarState = SBS_SHOWING;
328                         dx = -8;
329                 }
330                 else
331                 {
332 //printf("GUI: sidebar hiding[1] (x = %i)...\n", x);
333                         sidebarState = SBS_HIDING;
334                         dx = 8;
335                 }
336         }
337         else
338         {
339                 if (x < SIDEBAR_X_POS)
340                 {
341                         iconSelected = lastIconSelected = -1;
342                         HandleIconSelection(sdlRenderer);
343 //printf("GUI: sidebar hiding[2] (x = %i)...\n", x);
344                         sidebarState = SBS_HIDING;
345                         dx = 8;
346                 }
347                 // We're in the right zone, and the sidebar is shown, so let's select
348                 // something!
349                 else
350                 {
351                         if (y < 4 || y > 383)
352                         {
353                                 iconSelected = -1;
354                         }
355                         else
356                                 iconSelected = (y - 4) / 54;
357
358                         // It's y+2 because the sidebar sits at (SIDEBAR_X_POS, 2)
359                         disk1EjectHovered = ((x >= (SIDEBAR_X_POS + 24 + 29))
360                                 && (x < (SIDEBAR_X_POS + 24 + 29 + 8))
361                                 && (y >= (63 + 31 + 2))
362                                 && (y < (63 + 31 + 2 + 7)) ? true : false);
363
364                         disk2EjectHovered = ((x >= (SIDEBAR_X_POS + 24 + 29))
365                                 && (x < (SIDEBAR_X_POS + 24 + 29 + 8))
366                                 && (y >= (117 + 31 + 2))
367                                 && (y < (117 + 31 + 2 + 7)) ? true : false);
368
369                         disk1NewDiskHovered = ((x >= (SIDEBAR_X_POS + 24 + 6))
370                                 && (x < (SIDEBAR_X_POS + 24 + 6 + 30))
371                                 && (y >= (63 + 31 + 2))
372                                 && (y < (63 + 31 + 2 + 6)) ? true : false);
373
374                         disk2NewDiskHovered = ((x >= (SIDEBAR_X_POS + 24 + 6))
375                                 && (x < (SIDEBAR_X_POS + 24 + 6 + 30))
376                                 && (y >= (117 + 31 + 2))
377                                 && (y < (117 + 31 + 2 + 6)) ? true : false);
378
379                         if (iconSelected != lastIconSelected)
380                         {
381                                 HandleIconSelection(sdlRenderer);
382                                 lastIconSelected = iconSelected;
383
384                                 if ((iconSelected >= 0) && (iconSelected <= 6))
385                                         SpawnMessage("%s", iconHelp[iconSelected]);
386
387                                 // Show what's in the selected drive
388                                 if (iconSelected >= 1 && iconSelected <= 2)
389                                 {
390                                         if (!floppyDrive[0].IsEmpty(iconSelected - 1))
391                                                 SpawnMessage("\"%s\"", floppyDrive[0].ImageName(iconSelected - 1));
392                                 }
393                         }
394                 }
395         }
396 }
397
398
399 bool GUI::KeyDown(uint32_t key)
400 {
401         return Config::KeyDown(key);
402 }
403
404
405 void GUI::HandleIconSelection(SDL_Renderer * renderer)
406 {
407         // Set up drive icons in their current states
408         AssembleDriveIcon(renderer, 0);
409         AssembleDriveIcon(renderer, 1);
410
411         // Reload the background...
412         SDL_UpdateTexture(overlay, NULL, texturePointer, 128 * sizeof(Uint32));
413
414         if (SDL_SetRenderTarget(renderer, overlay) < 0)
415         {
416                 WriteLog("GUI: Could not set Render Target to overlay... (%s)\n", SDL_GetError());
417                 return;
418         }
419
420         // Draw the icon selector, if an icon is selected
421         if (iconSelected >= 0)
422         {
423                 SDL_Rect dst;// = { 54, 54, 24 - 7, 2 };
424                 dst.w = dst.h = 54, dst.x = 24 - 7, dst.y = 2 + (iconSelected * 54);
425                 SDL_RenderCopy(renderer, iconSelection, NULL, &dst);
426         }
427
428         DrawSidebarIcons(renderer);
429
430         // Set render target back to default
431         SDL_SetRenderTarget(renderer, NULL);
432 }
433
434
435 void GUI::AssembleDriveIcon(SDL_Renderer * renderer, int driveNumber)
436 {
437         SDL_Texture * drive[2] = { disk1Icon, disk2Icon };
438         const char * number[2] = { numeralOne, numeralTwo };
439
440         if (SDL_SetRenderTarget(renderer, drive[driveNumber]) < 0)
441         {
442                 WriteLog("GUI: Could not set Render Target to overlay... (%s)\n", SDL_GetError());
443                 return;
444         }
445
446         SDL_RenderClear(renderer);
447         SDL_RenderCopy(renderer, diskIcon, NULL, NULL);
448
449         // Drive door @ (16, 7)
450         SDL_Rect dst;
451         dst.w = 8, dst.h = 10, dst.x = 16, dst.y = 7;
452         SDL_RenderCopy(renderer, (floppyDrive[0].IsEmpty(driveNumber) ?
453                 doorOpen : doorClosed), NULL, &dst);
454
455         // Numeral @ (30, 20)
456         DrawCharArray(renderer, number[driveNumber], 30, 20, 7, 7, 0xD0, 0xE0, 0xF0);
457         DrawDriveLight(renderer, driveNumber);
458         DrawEjectButton(renderer, driveNumber);
459         DrawNewDiskButton(renderer, driveNumber);
460
461         // Set render target back to default
462         SDL_SetRenderTarget(renderer, NULL);
463 }
464
465
466 void GUI::DrawEjectButton(SDL_Renderer * renderer, int driveNumber)
467 {
468         if (floppyDrive[0].IsEmpty(driveNumber))
469                 return;
470
471         uint8_t r = 0x00, g = 0xAA, b = 0x00;
472
473         if ((driveNumber == 0 && disk1EjectHovered)
474                 || (driveNumber == 1 && disk2EjectHovered))
475                 r = 0x20, g = 0xFF, b = 0x20;
476
477         DrawCharArray(renderer, ejectIcon, 29, 31, 8, 7, r, g, b);
478 }
479
480
481 void GUI::DrawNewDiskButton(SDL_Renderer * renderer, int driveNumber)
482 {
483         if (!floppyDrive[0].IsEmpty(driveNumber))
484                 return;
485
486         uint8_t r = 0x00, g = 0xAA, b = 0x00;
487
488         if ((driveNumber == 0 && disk1NewDiskHovered)
489                 || (driveNumber == 1 && disk2NewDiskHovered))
490                 r = 0x20, g = 0xFF, b = 0x20;
491
492         DrawCharArray(renderer, newDiskIcon, 6, 31, 30, 6, r, g, b);
493 }
494
495
496 void GUI::DrawDriveLight(SDL_Renderer * renderer, int driveNumber)
497 {
498         int lightState = floppyDrive[0].DriveLightStatus(driveNumber);
499         int r = 0x77, g = 0x00, b = 0x00;
500
501         if (lightState == DLS_READ)
502                 r = 0x20, g = 0xFF, b = 0x20;
503         else if (lightState == DLS_WRITE)
504                 r = 0xFF, g = 0x30, b = 0x30;
505
506         // Drive light @ (8, 21)
507         DrawCharArray(renderer, driveLight, 8, 21, 5, 5, r, g, b);
508 }
509
510
511 void GUI::DrawCharArray(SDL_Renderer * renderer, const char * array, int x,
512         int y, int w, int h, int r, int g, int b)
513 {
514         SDL_SetRenderDrawColor(renderer, r, g, b, 0xFF);
515
516         for(int j=0; j<h; j++)
517         {
518                 for(int i=0; i<w; i++)
519                 {
520                         if (array[(j * w) + i] != ' ')
521                                 SDL_RenderDrawPoint(renderer, x + i, y + j);
522                 }
523         }
524
525         SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00);
526 }
527
528
529 void GUI::DrawCharacter(SDL_Renderer * renderer, int x, int y, uint8_t c, bool invert/*= false*/)
530 {
531         uint32_t inv = (invert ? 0x000000FF : 0x00000000);
532         uint32_t pixel = 0xFFFFC000;    // RRGGBBAA
533         uint8_t * ptr = (uint8_t *)&font10pt[(c - 0x20) * FONT_WIDTH * FONT_HEIGHT];
534         SDL_Rect dst;
535         dst.x = x * FONT_WIDTH, dst.y = y * FONT_HEIGHT, dst.w = FONT_WIDTH, dst.h = FONT_HEIGHT;
536
537         for(int i=0; i<FONT_WIDTH*FONT_HEIGHT; i++)
538                 stamp[i] = (pixel | ptr[i]) ^ inv;
539
540         SDL_UpdateTexture(charStamp, NULL, stamp, FONT_WIDTH * sizeof(Uint32));
541         SDL_RenderCopy(renderer, charStamp, NULL, &dst);
542 }
543
544
545 //
546 // N.B.: This draws a char at an abosulte X/Y position, not on a grid
547 //
548 void GUI::DrawCharacterVert(SDL_Renderer * renderer, int x, int y, uint8_t c, bool invert/*= false*/)
549 {
550         uint32_t inv = (invert ? 0x000000FF : 0x00000000);
551         uint32_t pixel = 0xFFFFC000;    // RRGGBBAA
552         uint8_t * ptr = (uint8_t *)&font10pt[(c - 0x20) * FONT_WIDTH * FONT_HEIGHT];
553         SDL_Rect dst;
554         dst.x = x, dst.y = y, dst.w = FONT_WIDTH, dst.h = FONT_HEIGHT;
555         SDL_Point pt = { FONT_WIDTH - 1, FONT_HEIGHT - 1 };
556
557         for(int i=0; i<FONT_WIDTH*FONT_HEIGHT; i++)
558                 stamp[i] = (pixel | ptr[i]) ^ inv;
559
560         SDL_SetTextureBlendMode(charStamp, SDL_BLENDMODE_NONE);
561         SDL_UpdateTexture(charStamp, NULL, stamp, FONT_WIDTH * sizeof(Uint32));
562         SDL_RenderCopyEx(renderer, charStamp, NULL, &dst, 270.0, &pt, SDL_FLIP_NONE);
563         SDL_SetTextureBlendMode(charStamp, SDL_BLENDMODE_BLEND);
564 }
565
566
567 void GUI::DrawString(SDL_Renderer * renderer, int x, int y, const char * s, bool invert/*= false*/)
568 {
569         int len = strlen(s);
570
571         for(int i=0; i<len; i++)
572                 DrawCharacter(renderer, x + i, y, s[i], invert);
573 }
574
575
576 //
577 // N.B.: This draws a char at an abosulte X/Y position, not on a grid
578 //
579 void GUI::DrawStringVert(SDL_Renderer * renderer, int x, int y, const char * s, bool invert/*= false*/)
580 {
581         int len = strlen(s);
582
583         for(int i=0; i<len; i++)
584                 DrawCharacterVert(renderer, x, y - (FONT_WIDTH * i), s[i], invert);
585 }
586
587
588 void GUI::DrawBox(SDL_Renderer * renderer, int x, int y, int w, int h, int r/*= 0x00*/, int g/*= 0xAA*/, int b/*= 0x00*/)
589 {
590         SDL_SetRenderDrawColor(renderer, r, g, b, 0xFF);
591
592         for(int i=0; i<w; i++)
593         {
594                 SDL_RenderDrawPoint(renderer, x + i, y);
595                 SDL_RenderDrawPoint(renderer, x + i, y + h - 1);
596         }
597
598         for(int i=0; i<h; i++)
599         {
600                 SDL_RenderDrawPoint(renderer, x, y + i);
601                 SDL_RenderDrawPoint(renderer, x + w - 1, y + i);
602         }
603
604         SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00);
605 }
606
607
608 void GUI::HandleGUIState(void)
609 {
610         olDst.x += dx;
611
612         if (olDst.x < SIDEBAR_X_POS && sidebarState == SBS_SHOWING)
613         {
614                 olDst.x = SIDEBAR_X_POS;
615                 sidebarState = SBS_SHOWN;
616                 dx = 0;
617         }
618         else if (olDst.x > VIRTUAL_SCREEN_WIDTH && sidebarState == SBS_HIDING)
619         {
620                 olDst.x = VIRTUAL_SCREEN_WIDTH;
621                 sidebarState = SBS_HIDDEN;
622                 dx = 0;
623         }
624 }
625
626
627 void GUI::DrawSidebarIcons(SDL_Renderer * renderer)
628 {
629         SDL_Texture * icons[7] = { powerOnIcon, disk1Icon, disk2Icon, diskSwapIcon,
630                 stateSaveIcon, stateLoadIcon, configIcon };
631
632         icons[0] = (powerOnState ? powerOnIcon : powerOffIcon);
633         SDL_Rect dst = { 24, 2 + 7, 40, 40 };
634
635         for(int i=0; i<7; i++)
636         {
637                 SDL_RenderCopy(renderer, icons[i], NULL, &dst);
638                 dst.y += 54;
639         }
640 }
641
642
643 void GUI::Render(SDL_Renderer * renderer)
644 {
645         // Sanity check
646         if (!overlay)
647                 return;
648
649         HandleGUIState();
650
651         if (sidebarState != SBS_HIDDEN)
652                 HandleIconSelection(renderer);
653
654         SDL_RenderCopy(renderer, overlay, NULL, &olDst);
655
656         // Hmm.
657         DiskSelector::Render(renderer);
658         Config::Render(renderer);
659 }
660
661
662 /*
663 GUI Considerations:
664
665 screen is 560 x 384
666
667 cut into 7 pieces give ~54 pix per piece
668 So, let's try 40x40 icons, and see if that's good enough...
669 Selection is 54x54.
670
671 drive proportions: 1.62 : 1
672
673 Icon order:
674
675 +-----+
676 |     |
677 |Power|
678 |     |
679 +-----+
680
681 +-----+
682 |     |
683 |Disk1|
684 |    ^| <-- eject button
685 +-----+
686
687 +-----+
688 |     |
689 |Disk2|
690 |    ^|
691 +-----+
692
693 +-----+
694 |     |
695 |Swap |
696 |     |
697 +-----+
698
699 +-----+
700 |     |
701 |Confg|
702 |     |
703 +-----+
704
705 maybe state save/load
706
707 */
708