]> Shamusworld >> Repos - apple2/blob - src/gui/diskwindow.cpp
Add new files that makes this stuff work. D'oh!
[apple2] / src / gui / diskwindow.cpp
1 //
2 // DISKWINDOW.CPP
3 //
4 // Graphical User Interface disk window class
5 // by James L. Hammons
6 //
7 // JLH = James L. Hammons <jlhamm@acm.org>
8 //
9 // WHO  WHEN        WHAT
10 // ---  ----------  ------------------------------------------------------------
11 // JLH  02/02/2009  Created this file
12 //
13
14 /*
15 IDEA: Make a recently used file list when ejecting a disk, either here or in
16       another window.
17 */
18
19 #include "diskwindow.h"
20 #include "floppy.h"
21 #include "text.h"
22 #include "button.h"
23 //#include "guimisc.h"                                                          // Various support functions
24 //#include <algorithm>
25
26 // Debug support...
27 //#define DESTRUCTOR_TESTING
28
29 // Rendering experiment...
30 //BAH
31 //#define USE_COVERAGE_LISTS
32
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
38 #else
39 #define MASK_R 0x000000FF
40 #define MASK_G 0x0000FF00
41 #define MASK_B 0x00FF0000
42 #define MASK_A 0xFF000000
43 #endif
44
45 //
46 // DiskWindow class implementation
47 //
48 // NOTE: FG/BG colors are hard-wired
49 //
50
51 DiskWindow::DiskWindow(FloppyDrive * fdp, uint32 x/*= 0*/, uint32 y/*= 0*/): Window(x, y, 200, 140, NULL), floppyDrive(fdp)
52 {
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);
56
57         name1 = new Text(4, 4, floppyDrive->GetImageName(0), 0xFF00FF00, 0xFF23239F, this);
58         name2 = new Text(4, 24, floppyDrive->GetImageName(1), 0xFF00FF00, 0xFF23239F, this);
59
60         AddElement(name1);
61         AddElement(name2);
62
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);
67
68         load1->SetVisible(false);
69         load2->SetVisible(false);
70
71         AddElement(load1);
72         AddElement(eject1);
73         AddElement(load2);
74         AddElement(eject2);
75
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);
79
80         AddElement(newDisk1);
81         AddElement(newDisk2);
82         AddElement(swap);
83
84         SetBackgroundDraw(false);
85 //      CreateBackstore();
86         Draw(); // Can we do this in the constructor??? Mebbe.
87 }
88
89 DiskWindow::~DiskWindow()
90 {
91 #ifdef DESTRUCTOR_TESTING
92 printf("Inside ~DiskWindow()...\n");
93 #endif
94 }
95
96 void DiskWindow::HandleKey(SDLKey key)
97 {
98         Window::HandleKey(key);
99 #if 0
100         if (key == SDLK_ESCAPE)
101         {
102                 SDL_Event event;
103                 event.type = SDL_USEREVENT, event.user.code = WINDOW_CLOSE;
104                 SDL_PushEvent(&event);
105         }
106
107         // Handle the items this window contains...
108         for(uint32 i=0; i<list.size(); i++)
109                 list[i]->HandleKey(key);
110 #endif
111 }
112
113 void DiskWindow::HandleMouseMove(uint32 x, uint32 y)
114 {
115         Window::HandleMouseMove(x, y);
116 #if 0
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);
121 #endif
122 }
123
124 void DiskWindow::HandleMouseButton(uint32 x, uint32 y, bool mouseDown)
125 {
126         Window::HandleMouseButton(x, y, mouseDown);
127 #if 0
128 #if 1
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++)
136         {
137                 // Make coords relative to upper right corner of this window...
138                 list[i]->HandleMouseButton(x - extents.x, y - extents.y, mouseDown);
139
140                 if (list[i]->Inside(x - extents.x, y - extents.y))
141                         clicked = false;
142         }
143 #endif
144 #endif
145 }
146
147 void DiskWindow::Draw(void)
148 {
149         Window::Draw();
150 #if 0
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);
154
155         // Handle the items this window contains...
156         for(uint32 i=0; i<list.size(); i++)
157                 list[i]->Draw();
158
159         needToRefreshScreen = true;
160 #endif
161 }
162
163 void DiskWindow::Notify(Element * e)
164 {
165 /*      if (e == closeButton)
166         {
167                 SDL_Event event;
168                 event.type = SDL_USEREVENT;
169                 event.user.code = WINDOW_CLOSE;
170                 event.user.data1 = (void *)this;
171                 SDL_PushEvent(&event);
172         }*/
173         if (e == load1)
174         {
175                 // Load up file selector, etc... BLEAH
176                 // If load was successful, then hide load and show eject, else, fuggetaboutit
177         }
178         else if (e == eject1)
179         {
180                 floppyDrive->EjectImage(0);
181
182                 // Housekeeping
183                 eject1->SetVisible(false);
184                 load1->SetVisible(true);
185                 name1->SetText("");
186                 Draw();
187         }
188         else if (e == load2)
189         {
190                 // Load up file selector, etc... BLEAH
191                 // If load was successful, then hide load and show eject, else, fuggetaboutit
192         }
193         else if (e == eject2)
194         {
195                 floppyDrive->EjectImage(1);
196
197                 // Housekeeping
198                 eject2->SetVisible(false);
199                 load2->SetVisible(true);
200                 name2->SetText("");
201                 Draw();
202         }
203         else if (e == newDisk1)
204         {
205                 if (!floppyDrive->DriveIsEmpty(0))
206                 {
207                         // Put up a warning and give user a chance to exit this potentially
208                         // disastrous action
209                 }
210
211                 floppyDrive->SaveImage(0);
212                 floppyDrive->CreateBlankImage(0);
213
214                 // Housekeeping
215                 eject1->SetVisible(true);
216                 load1->SetVisible(false);
217                 name1->SetText(floppyDrive->GetImageName(0));
218                 Draw();
219         }
220         else if (e == newDisk2)
221         {
222                 if (!floppyDrive->DriveIsEmpty(1))
223                 {
224                         // Put up a warning and give user a chance to exit this potentially
225                         // disastrous action
226                 }
227
228                 floppyDrive->SaveImage(1);
229                 floppyDrive->CreateBlankImage(1);
230
231                 // Housekeeping
232                 eject2->SetVisible(true);
233                 load2->SetVisible(false);
234                 name2->SetText(floppyDrive->GetImageName(1));
235                 Draw();
236         }
237         else if (e == swap)
238         {
239                 floppyDrive->SwapImages();
240
241                 // Housekeeping
242                 name1->SetText(floppyDrive->GetImageName(0));
243                 name2->SetText(floppyDrive->GetImageName(1));
244                 Draw();
245         }
246 }