2 Copyright 2004-2005 Chris Tallon
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 ViewMan* ViewMan::instance = NULL;
38 ViewMan* ViewMan::getInstance()
45 if (initted) return 0;
50 int ViewMan::shutdown()
52 if (!initted) return 0;
54 // FIXME don't think this can work properly, removeAll leaves the wallpaper there!
61 int ViewMan::add(View* v)
63 if (!initted) return 0;
64 if (numViews == 16) return 0;
66 views[numViews++] = v;
71 // ---------------------------------------------------- REMOVE CODE
73 int ViewMan::removeView(View* toDelete)
75 if (!initted) return 0;
76 if (numViews == 0) return 0;
78 Log::getInstance()->log("ViewMan", Log::DEBUG, "entering remove, numViews=%i", numViews);
84 toDelete = views[numViews-1];
89 // to be deleted view is more likely to be at the top
90 for (i = numViews-1; i >= 0; i--)
92 Log::getInstance()->log("ViewMan", Log::DEBUG, "todel: %p, i=%i, views[i]=%p", toDelete, i, views[i]);
93 if (views[i] == toDelete) break;
98 // not a View we have!
103 Log::getInstance()->log("ViewMan", Log::DEBUG, "Starting deleteView");
105 Log::getInstance()->log("ViewMan", Log::DEBUG, "Done deleteView");
107 // Shift the views on top down one
109 for(int j = i; j < numViews; j++) views[j] = views[j+1];
117 /////////////////////////////////////////////////////////////////////////////
119 /////////////////////////////////////////////////////////////////////////////
121 void ViewMan::deleteView(int z)
123 Log::getInstance()->log("ViewMan", Log::DEBUG, "Delete view %i of %i", z, numViews);
125 boxSplit(views[z]->area, z + 1, numViews, 1, rl);
128 repaintRevealed(z, rl.front());
133 void ViewMan::updateView(View* toUpdate, Region* regionToUpdate)
135 // Get the z index of the view
138 for (z = 0; z < numViews; z++)
140 if (views[z] == toUpdate) break;
145 // not a View we have!
149 // get the region for the whole view, could be less than that
150 // for smaller updates
152 Region r = views[z]->area;
156 // Can be null if the whole view should be updated
157 // If this is given the numbers are relative to the size of the view, not the screen
159 r.x += regionToUpdate->x;
160 r.y += regionToUpdate->y;
161 r.w = regionToUpdate->w;
162 r.h = regionToUpdate->h;
168 boxSplit(r, z+1, numViews, 1, rl);
178 void ViewMan::repaintRevealed(int x, Region r)
181 boxSplit(r, x - 1, -1, -1, rl);
187 views[r2.z]->show(r2);
192 void ViewMan::boxSplit(Region r, int start, int end, int direction, RegionList& rl)
194 // printf("Y= S=%i E=%i D=%i: Boxsplit: %i %i %i %i\n", start, end, direction, r.x, r.y, r.w, r.h);
196 for(int z = start; z != end; z += direction)
198 if (r.overlappedBy(views[z]->area))
200 // printf("Z=%i S=%i E=%i D=%i: %i overlaps\n", z, start, end, direction, z);
205 if (views[z]->area.y > r.y)
207 // printf("Z=%i S=%i E=%i D=%i: Case 1 for %i %i %i %i split by %i: %i %i %i %i\n", z, start, end, direction, r.x, r.y, r.w, r.h, z, views[z]->area.x, views[z]->area.y, views[z]->area.w, views[z]->area.h);
208 top = views[z]->area.y;
213 newR.h = views[z]->area.y - r.y;
214 boxSplit(newR, z + direction, end, direction, rl);
220 newR2.y = views[z]->area.y;
222 newR2.h = r.h - newR.h;
223 boxSplit(newR2, z, end, -1, rl);
228 if (views[z]->area.y2() < r.y2())
230 // printf("Z=%i S=%i E=%i D=%i: Case 2 for %i %i %i %i split by %i: %i %i %i %i\n", z, start, end, direction, r.x, r.y, r.w, r.h, z, views[z]->area.x, views[z]->area.y, views[z]->area.w, views[z]->area.h);
231 btm = views[z]->area.y2();
234 newR.y = views[z]->area.y2() + 1;
236 newR.h = r.y2() - newR.y + 1;
237 boxSplit(newR, z + direction, end, direction, rl);
245 newR2.h = r.h - newR.h;
246 boxSplit(newR2, z, end, -1, rl);
251 if (views[z]->area.x > r.x)
253 // printf("Z=%i S=%i E=%i D=%i: Case 3 for %i %i %i %i split by %i: %i %i %i %i\n", z, start, end, direction, r.x, r.y, r.w, r.h, z, views[z]->area.x, views[z]->area.y, views[z]->area.w, views[z]->area.h);
257 newR.w = views[z]->area.x - r.x;
258 newR.h = btm - top + 1;
259 boxSplit(newR, z + direction, end, direction, rl);
264 newR2.x = r.x + newR.w;
266 newR2.w = r.w - newR.w;
268 boxSplit(newR2, z, end, -1, rl);
273 if (views[z]->area.x2() < r.x2())
275 // printf("Z=%i S=%i E=%i D=%i: Case 4 for %i %i %i %i split by %i: %i %i %i %i\n", z, start, end, direction, r.x, r.y, r.w, r.h, z, views[z]->area.x, views[z]->area.y, views[z]->area.w, views[z]->area.h);
277 newR.x = views[z]->area.x2() + 1;
279 newR.w = r.x2() - newR.x + 1;
280 newR.h = btm - top + 1;
281 boxSplit(newR, z + direction, end, direction, rl);
288 newR2.w = r.w - newR.w;
290 boxSplit(newR2, z, end, -1, rl);
297 // we are going down the stack
298 // r is underlapped by views[z]
299 // but we have not split
300 // Therefore this region under test is
301 // completely covering views[z]
303 // don't go any further down, generate a region and quit
305 // printf("Repaint region: %i %i %i %i\n", r.x, r.y, r.w, r.h);
310 // printf("Returning from Z=%i\n", z);
315 // printf("Z=%i S=%i E=%i D=%i: %i does not overlap\n", z, start, end, direction, z);
319 // if direction = 1 then we have come to a region that is
320 // entirely clear of higher views and needs to be redrawn
322 // if direction = -1 then we have come to a region that is on
323 // the very bottom with nothing below it to repaint.
324 // do nothing. stale window data will be left on screen?
333 void ViewMan::drawBlack(Region& r)
335 Surface* surface = Surface::getScreen();
336 surface->fillblt(r.x, r.y, r.w, r.h, surface->rgba(0, 0, 0, 255));
339 /////////////////////////////////////////////////////////////////////////////
341 /////////////////////////////////////////////////////////////////////////////
343 // ---------------------------------------------------- END OF REMOVE CODE
346 void ViewMan::removeAll()
348 // 1.. Don't delete wallpaper. No point.
349 for (; numViews > 1; --numViews)
351 delete views[numViews-1];
355 int ViewMan::handleCommand(UCHAR command)
361 if (command != Remote::NA_NONE)
363 // handle command return values
364 // 0 - drop through to next view
365 // 1 - dont drop to next view, but not handled
366 // 2 - handled - stop command here
367 // 4 - handled - delete this view
369 for (i=numViews-1; i>=0; i--)
371 Log::getInstance()->log("ViewMan", Log::DEBUG, "Giving command to i=%i", i);
372 retVal = views[i]->handleCommand(command);
375 // not handled but don't give to any more views
385 else if (retVal == 4)
387 Log::getInstance()->log("ViewMan", Log::DEBUG, "Return 4: i=%i, views[i]=%p", i, views[i]);
388 removeView(views[i]);
396 // fake the return code
400 Log::getInstance()->log("ViewMan", Log::DEBUG, "out of handlecommand code, now on to messages");
402 processMessageQueue();
407 void ViewMan::processMessage(Message* m)
411 for (int i = numViews-1; i >= 0; i--)
413 if (views[i] == m->to)
415 Log::getInstance()->log("ViewMan", Log::DEBUG, "sending message to view");
416 Log::getInstance()->log("ViewMan", Log::DEBUG, "%p %p %lu", m->from, m->to, m->message);
417 views[i]->processMessage(m);
423 Log::getInstance()->log("ViewMan", Log::DEBUG, "it's for meeee!");
427 case Message::CLOSE_ME:
429 removeView((View*)m->from);
432 case Message::ADD_VIEW:
434 View* toAdd = (View*)m->parameter;