4 // Graphical User Interface disk window class
7 // JLH = James L. Hammons <jlhamm@acm.org>
10 // --- ---------- ------------------------------------------------------------
11 // JLH 02/02/2009 Created this file
15 IDEA: Make a recently used file list when ejecting a disk, either here or in
19 #include "diskwindow.h"
23 //#include "guimisc.h" // Various support functions
24 //#include <algorithm>
27 //#define DESTRUCTOR_TESTING
29 // Rendering experiment...
31 //#define USE_COVERAGE_LISTS
33 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
34 #define MASK_R 0xFF000000
35 #define MASK_G 0x00FF0000
36 #define MASK_B 0x0000FF00
37 #define MASK_A 0x000000FF
39 #define MASK_R 0x000000FF
40 #define MASK_G 0x0000FF00
41 #define MASK_B 0x00FF0000
42 #define MASK_A 0xFF000000
46 // DiskWindow class implementation
48 // NOTE: FG/BG colors are hard-wired
51 DiskWindow::DiskWindow(FloppyDrive * fdp, uint32 x/*= 0*/, uint32 y/*= 0*/): Window(x, y, 200, 140, NULL), floppyDrive(fdp)
53 //Could probably move this into the initializer list as well...
54 // closeButton = new Button(w - (cbWidth + 1), 1, cbUp, cbHover, cbDown, this);
55 // list.push_back(closeButton);
57 name1 = new Text(4, 4, floppyDrive->GetImageName(0), 0xFF00FF00, 0xFF23239F, this);
58 name2 = new Text(4, 24, floppyDrive->GetImageName(1), 0xFF00FF00, 0xFF23239F, this);
63 load1 = new Button(4, 44, "Load1", this);
64 eject1 = new Button(4, 64, "Eject1", this);
65 load2 = new Button(4, 88, "Load2", this);
66 eject2 = new Button(4, 108, "Eject2", this);
68 load1->SetVisible(false);
69 load2->SetVisible(false);
76 newDisk1 = new Button(4, 132, "NewDisk1", this);
77 newDisk2 = new Button(4, 152, "NewDisk2", this);
78 swap = new Button(4, 176, "Swap Disks", this);
84 SetBackgroundDraw(false);
86 Draw(); // Can we do this in the constructor??? Mebbe.
89 DiskWindow::~DiskWindow()
91 #ifdef DESTRUCTOR_TESTING
92 printf("Inside ~DiskWindow()...\n");
96 void DiskWindow::HandleKey(SDLKey key)
98 Window::HandleKey(key);
100 if (key == SDLK_ESCAPE)
103 event.type = SDL_USEREVENT, event.user.code = WINDOW_CLOSE;
104 SDL_PushEvent(&event);
107 // Handle the items this window contains...
108 for(uint32 i=0; i<list.size(); i++)
109 list[i]->HandleKey(key);
113 void DiskWindow::HandleMouseMove(uint32 x, uint32 y)
115 Window::HandleMouseMove(x, y);
117 // Handle the items this window contains...
118 for(uint32 i=0; i<list.size(); i++)
119 // Make coords relative to upper right corner of this window...
120 list[i]->HandleMouseMove(x - extents.x, y - extents.y);
124 void DiskWindow::HandleMouseButton(uint32 x, uint32 y, bool mouseDown)
126 Window::HandleMouseButton(x, y, mouseDown);
129 // Handle the items this window contains...
130 for(uint32 i=0; i<list.size(); i++)
131 // Make coords relative to upper right corner of this window...
132 list[i]->HandleMouseButton(x - extents.x, y - extents.y, mouseDown);
133 #else //? This works in draggablewindow2...
134 // Handle the items this window contains...
135 for(uint32 i=0; i<list.size(); i++)
137 // Make coords relative to upper right corner of this window...
138 list[i]->HandleMouseButton(x - extents.x, y - extents.y, mouseDown);
140 if (list[i]->Inside(x - extents.x, y - extents.y))
147 void DiskWindow::Draw(void)
151 // These are *always* top level and parentless, so no need to traverse up through
152 // the parent chain...
153 SDL_FillRect(screen, &extents, bgColor);
155 // Handle the items this window contains...
156 for(uint32 i=0; i<list.size(); i++)
159 needToRefreshScreen = true;
163 void DiskWindow::Notify(Element * e)
165 /* if (e == closeButton)
168 event.type = SDL_USEREVENT;
169 event.user.code = WINDOW_CLOSE;
170 event.user.data1 = (void *)this;
171 SDL_PushEvent(&event);
175 // Load up file selector, etc... BLEAH
176 // If load was successful, then hide load and show eject, else, fuggetaboutit
178 else if (e == eject1)
180 floppyDrive->EjectImage(0);
183 eject1->SetVisible(false);
184 load1->SetVisible(true);
190 // Load up file selector, etc... BLEAH
191 // If load was successful, then hide load and show eject, else, fuggetaboutit
193 else if (e == eject2)
195 floppyDrive->EjectImage(1);
198 eject2->SetVisible(false);
199 load2->SetVisible(true);
203 else if (e == newDisk1)
205 if (!floppyDrive->DriveIsEmpty(0))
207 // Put up a warning and give user a chance to exit this potentially
211 floppyDrive->SaveImage(0);
212 floppyDrive->CreateBlankImage(0);
215 eject1->SetVisible(true);
216 load1->SetVisible(false);
217 name1->SetText(floppyDrive->GetImageName(0));
220 else if (e == newDisk2)
222 if (!floppyDrive->DriveIsEmpty(1))
224 // Put up a warning and give user a chance to exit this potentially
228 floppyDrive->SaveImage(1);
229 floppyDrive->CreateBlankImage(1);
232 eject2->SetVisible(true);
233 load2->SetVisible(false);
234 name2->SetText(floppyDrive->GetImageName(1));
239 floppyDrive->SwapImages();
242 name1->SetText(floppyDrive->GetImageName(0));
243 name2->SetText(floppyDrive->GetImageName(1));