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());
134 void ViewMan::update(int z)
136 // get the region for the whole view, could be less than that
137 // for smaller updates
139 Region r = views[z]->area;
145 boxSplit(r, z+1, numViews, 1, rl);
156 void ViewMan::repaintRevealed(int x, Region r)
159 boxSplit(r, x - 1, -1, -1, rl);
165 views[r2.z]->show(r2);
170 void ViewMan::boxSplit(Region r, int start, int end, int direction, RegionList& rl)
172 // 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);
174 for(int z = start; z != end; z += direction)
176 if (r.overlappedBy(views[z]->area))
178 // printf("Z=%i S=%i E=%i D=%i: %i overlaps\n", z, start, end, direction, z);
183 if (views[z]->area.y > r.y)
185 // 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);
186 top = views[z]->area.y;
191 newR.h = views[z]->area.y - r.y;
192 boxSplit(newR, z + direction, end, direction, rl);
198 newR2.y = views[z]->area.y;
200 newR2.h = r.h - newR.h;
201 boxSplit(newR2, z, end, -1, rl);
206 if (views[z]->area.y2() < r.y2())
208 // 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);
209 btm = views[z]->area.y2();
212 newR.y = views[z]->area.y2() + 1;
214 newR.h = r.y2() - newR.y + 1;
215 boxSplit(newR, z + direction, end, direction, rl);
223 newR2.h = r.h - newR.h;
224 boxSplit(newR2, z, end, -1, rl);
229 if (views[z]->area.x > r.x)
231 // 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);
235 newR.w = views[z]->area.x - r.x;
236 newR.h = btm - top + 1;
237 boxSplit(newR, z + direction, end, direction, rl);
242 newR2.x = r.x + newR.w;
244 newR2.w = r.w - newR.w;
246 boxSplit(newR2, z, end, -1, rl);
251 if (views[z]->area.x2() < r.x2())
253 // 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);
255 newR.x = views[z]->area.x2() + 1;
257 newR.w = r.x2() - newR.x + 1;
258 newR.h = btm - top + 1;
259 boxSplit(newR, z + direction, end, direction, rl);
266 newR2.w = r.w - newR.w;
268 boxSplit(newR2, z, end, -1, rl);
275 // we are going down the stack
276 // r is underlapped by views[z]
277 // but we have not split
278 // Therefore this region under test is
279 // completely covering views[z]
281 // don't go any further down, generate a region and quit
283 // printf("Repaint region: %i %i %i %i\n", r.x, r.y, r.w, r.h);
288 // printf("Returning from Z=%i\n", z);
293 // printf("Z=%i S=%i E=%i D=%i: %i does not overlap\n", z, start, end, direction, z);
297 // if direction = 1 then we have come to a region that is
298 // entirely clear of higher views and needs to be redrawn
300 // if direction = -1 then we have come to a region that is on
301 // the very bottom with nothing below it to repaint.
302 // do nothing. stale window data will be left on screen?
311 void ViewMan::drawBlack(Region& r)
313 Surface* surface = Surface::getScreen();
314 surface->fillblt(r.x, r.y, r.w, r.h, surface->rgba(0, 0, 0, 255));
317 /////////////////////////////////////////////////////////////////////////////
319 /////////////////////////////////////////////////////////////////////////////
321 // ---------------------------------------------------- END OF REMOVE CODE
324 void ViewMan::removeAll()
326 // 1.. Don't delete wallpaper. No point.
327 for (; numViews > 1; --numViews)
329 delete views[numViews-1];
333 int ViewMan::handleCommand(UCHAR command)
339 if (command != Remote::NA_NONE)
341 // handle command return values
342 // 0 - drop through to next view
343 // 1 - dont drop to next view, but not handled
344 // 2 - handled - stop command here
345 // 4 - handled - delete this view
347 for (i=numViews-1; i>=0; i--)
349 Log::getInstance()->log("ViewMan", Log::DEBUG, "Giving command to i=%i", i);
350 retVal = views[i]->handleCommand(command);
353 // not handled but don't give to any more views
363 else if (retVal == 4)
365 Log::getInstance()->log("ViewMan", Log::DEBUG, "Return 4: i=%i, views[i]=%p", i, views[i]);
366 removeView(views[i], 1);
374 // fake the return code
378 Log::getInstance()->log("ViewMan", Log::DEBUG, "out of handlecommand code, now on to messages");
380 processMessageQueue();
385 void ViewMan::processMessage(Message* m)
389 for (int i = numViews-1; i >= 0; i--)
391 if (views[i] == m->to)
393 Log::getInstance()->log("ViewMan", Log::DEBUG, "sending message to view");
394 Log::getInstance()->log("ViewMan", Log::DEBUG, "%p %p %lu", m->from, m->to, m->message);
395 views[i]->processMessage(m);
401 Log::getInstance()->log("ViewMan", Log::DEBUG, "it's for meeee!");
405 case Message::CLOSE_ME:
407 removeView((View*)m->from, 1);
410 case Message::ADD_VIEW:
412 View* toAdd = (View*)m->parameter;