2 // DRAGGABLEWINDOW2.CPP
4 // Graphical User Interface draggable window class
7 // JLH = James L. Hammons <jlhamm@acm.org>
10 // --- ---------- ------------------------------------------------------------
11 // JLH 03/17/2006 Created this file
12 // JLH 03/17/2006 Added clipping against parent extents
16 // - Check for parent's extents and clip movement against those extents [DONE]
19 #include "draggablewindow2.h"
20 #include "guimisc.h" // Various support functions
25 //#define DESTRUCTOR_TESTING
26 #define BACKGROUND_IMG_TEST
27 #define USE_COVERAGE_LISTS
29 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
30 #define MASK_R 0xFF000000
31 #define MASK_G 0x00FF0000
32 #define MASK_B 0x0000FF00
33 #define MASK_A 0x000000FF
35 #define MASK_R 0x000000FF
36 #define MASK_G 0x0000FF00
37 #define MASK_B 0x00FF0000
38 #define MASK_A 0xFF000000
42 // DraggableWindow class implementation
44 // NOTE: FG/BG colors are hard-wired
47 DraggableWindow2::DraggableWindow2(uint32_t x/*= 0*/, uint32_t y/*= 0*/, uint32_t w/*= 0*/, uint32_t h/*= 0*/,
48 void (* f)(Element *)/*= NULL*/):
49 Window(x, y, w, h, f), clicked(false)
51 #ifdef BACKGROUND_IMG_TEST
52 uint16_t imgWidth = (floppyDiskImg[0] << 8) | floppyDiskImg[1];
53 uint16_t imgHeight = (floppyDiskImg[2] << 8) | floppyDiskImg[3];
54 img = SDL_CreateRGBSurfaceFrom(&floppyDiskImg[4], imgWidth, imgHeight, 32, imgWidth * 4,
55 MASK_R, MASK_G, MASK_B, MASK_A);
56 // label = SDL_CreateRGBSurface(SDL_SWSURFACE, 16*7, 32, 32,
57 // MASK_R, MASK_G, MASK_B, MASK_A);
59 //Prolly should draw this in the constructor...
61 extern char textChar2e[];
62 uint8_t * fontAddr = (uint8_t *)textChar2e + ((128 + 32) * 7 * 8);
63 SetNewFont(Font(fontAddr, 7, 8));
64 // DrawStringOpaque(label, 0, 0, 0xFF000000, 0xFFFFFFFF, "Ultima III - Boo");
65 // DrawStringOpaque(label, 0, 8, 0xFF000000, 0xFFFFFFFF, "0123456789012345");
66 // DrawStringOpaque(label, 0, 16, 0xFF000000, 0xFFFFFFFF, "1234567890123456");
67 // DrawStringOpaque(label, 0, 24, 0xFF000000, 0xFFFFFFFF, "2345678901234567");
68 DrawStringOpaque(img, 8, 6, 0xFF000000, 0xFFFFFFFF, "Ultima III - Boo");
69 DrawStringOpaque(img, 8, 14, 0xFF000000, 0xFFFFFFFF, "t Disk6789012345");
70 DrawStringOpaque(img, 8, 22, 0xFF000000, 0xFFFFFFFF, "1234567890123456");
71 DrawStringOpaque(img, 6, 30, 0xFF000000, 0xFFFFFFFF, "2345678901234567");
76 //Bleh. We only have to do this here because Window's constructor is doing it too. !!! FIX !!!
77 //Mebbe put this shiaut into Element? What about stuff that doesn't draw itself right away?
78 //Perhaps we should just hit needToRefreshScreen or some such--but will that trigger a redraw?
79 RestoreScreenFromBackstore();
80 Draw(); // Can we do this in the constructor??? Mebbe.
83 DraggableWindow2::~DraggableWindow2()
85 #ifdef DESTRUCTOR_TESTING
86 printf("Inside ~DraggableWindow2()...\n");
89 #ifdef BACKGROUND_IMG_TEST
91 // SDL_FreeSurface(label);
95 void DraggableWindow2::HandleMouseMove(uint32_t x, uint32_t y)
99 //Need to check whether or not we've run into the extents of the screen... !!! FIX !!!
101 int32_t newX = x - offset.x;
102 int32_t newY = y - offset.y;
103 SDL_Rect clip = GetParentRect();
107 else if (newX > (clip.w - extents.w))
108 newX = clip.w - extents.w;
112 else if (newY > (clip.h - extents.h))
113 newY = clip.h - extents.h;
115 RestoreScreenFromBackstore();
118 SaveScreenToBackstore();
119 #ifdef USE_COVERAGE_LISTS
120 //If we don't do this, the coverage list doesn't move with the window...!
123 // SDL_BlitSurface(screen, &extents, backstore, NULL);
129 // Handle the items this window contains...
130 // for(uint32_t i=0; i<list.size(); i++)
131 // Make coords relative to upper right corner of this window...
132 // list[i]->HandleMouseMove(x - extents.x, y - extents.y);
133 Window::HandleMouseMove(x, y);
136 void DraggableWindow2::HandleMouseButton(uint32_t x, uint32_t y, bool mouseDown)
140 if (mouseDown && Inside(x, y))
143 offset.x = x - extents.x;
144 offset.y = y - extents.y;
147 // Handle the items this window contains...
148 for(uint32_t i=0; i<list.size(); i++)
150 // Make coords relative to upper right corner of this window...
151 list[i]->HandleMouseButton(x - extents.x, y - extents.y, mouseDown);
153 if (list[i]->Inside(x - extents.x, y - extents.y))
158 void DraggableWindow2::Draw(void)
160 //NOTE: What we need to do here is render into a surface THEN do the blits from the coverage list. !!! FIX !!!
161 #ifdef USE_COVERAGE_LISTS
162 // These are *always* top level and parentless, so no need to traverse up through
163 // the parent chain...
164 for(std::list<SDL_Rect>::iterator i=coverList.begin(); i!=coverList.end(); i++)
167 src.x = (*i).x - extents.x, src.y = (*i).y - extents.y, src.w = (*i).w, src.h = (*i).h;
168 dst.x = (*i).x, dst.y = (*i).y;
169 SDL_BlitSurface(img, &src, screen, &dst);
172 // HUH??!?!? The label should have been drawn into img already!!! !!! FIX !!! [DONE]
173 //This doesn't get clipped at all... !!! FIX !!!
174 // SDL_Rect src, dst;
175 // src.x = 0, src.y = 0, src.w = label->w, src.h = label->h;
176 // dst.x = extents.x + 8, dst.y = extents.y + 6;
177 // SDL_BlitSurface(label, &src, screen, &dst);
179 // Handle the items this window contains...
180 for(uint32_t i=0; i<list.size(); i++)
183 // These are *always* top level and parentless, so no need to traverse up through
184 // the parent chain...
185 //Perhaps we can make these parentable, put the parent traversal in the base class?
187 #ifdef BACKGROUND_IMG_TEST
189 src.x = 0, src.y = 0, src.w = extents.w, src.h = extents.h;
190 dst.x = extents.x, dst.y = extents.y;
191 SDL_BlitSurface(img, &src, screen, &dst);
194 // extern char textChar2e[];
195 // uint8_t * fontAddr = (uint8_t *)textChar2e + ((128 + 32) * 7 * 8);
196 // SetNewFont(Font(fontAddr, 7, 8));
197 // DrawStringOpaque(screen, extents.x + 8, extents.y + 6, 0xFF000000, 0xFFFFFFFF, "Ultima III - Boo");
198 // DrawStringOpaque(screen, extents.x + 8, extents.y + 14, 0xFF000000, 0xFFFFFFFF, "0123456789012345");
199 // DrawStringOpaque(screen, extents.x + 8, extents.y + 22, 0xFF000000, 0xFFFFFFFF, "1234567890123456");
200 // DrawStringOpaque(screen, extents.x + 8, extents.y + 30, 0xFF000000, 0xFFFFFFFF, "2345678901234567");
203 SDL_FillRect(screen, &extents, bgColor);
206 // Handle the items this window contains...
207 for(uint32_t i=0; i<list.size(); i++)
211 //Prolly don't need this since the close button will do this for us...
212 needToRefreshScreen = true;