Date: | 2014-08-10 13:25:54 (9 years 7 months ago) |
---|---|
Author: | Maarten ter Huurne |
Commit: | 4bd1c799bdf421394331540486425d09501a597c |
Message: | Created separate subclasses for output and off-screen surfaces There are a few exclusive operations for each type. Also we no longer need the freeWhenDone flag since the class now determines whether the surface should be freed or not. |
Files: |
src/battery.cpp (1 diff) src/battery.h (2 diffs) src/browsedialog.cpp (1 diff) src/gmenu2x.cpp (5 diffs) src/gmenu2x.h (2 diffs) src/inputdialog.cpp (2 diffs) src/linkapp.cpp (2 diffs) src/messagebox.cpp (1 diff) src/selector.cpp (2 diffs) src/settingsdialog.cpp (2 diffs) src/surface.cpp (4 diffs) src/surface.h (5 diffs) src/surfacecollection.cpp (5 diffs) src/surfacecollection.h (2 diffs) src/textdialog.cpp (2 diffs) src/textmanualdialog.cpp (2 diffs) src/wallpaperdialog.cpp (1 diff) |
Change Details
src/battery.cpp | ||
---|---|---|
46 | 46 | return 0; |
47 | 47 | } |
48 | 48 | |
49 | Battery::Battery(SurfaceCollection &sc_) | |
49 | Battery::Battery(SurfaceCollection& sc_) | |
50 | 50 | : sc(sc_) |
51 | 51 | { |
52 | 52 | lastUpdate = SDL_GetTicks(); |
53 | 53 | update(); |
54 | 54 | } |
55 | 55 | |
56 | const Surface &Battery::getIcon() | |
56 | OffscreenSurface const& Battery::getIcon() | |
57 | 57 | { |
58 | 58 | // Check battery status every 60 seconds. |
59 | 59 | unsigned int now = SDL_GetTicks(); |
src/battery.h | ||
---|---|---|
3 | 3 | |
4 | 4 | #include <string> |
5 | 5 | |
6 | class Surface; | |
6 | class OffscreenSurface; | |
7 | 7 | class SurfaceCollection; |
8 | 8 | |
9 | 9 | |
... | ... | |
12 | 12 | */ |
13 | 13 | class Battery { |
14 | 14 | public: |
15 | Battery(SurfaceCollection &sc); | |
15 | Battery(SurfaceCollection& sc); | |
16 | 16 | |
17 | 17 | /** |
18 | 18 | * Gets the icon that reflects the current battery status. |
19 | 19 | */ |
20 | const Surface &getIcon(); | |
20 | OffscreenSurface const& getIcon(); | |
21 | 21 | |
22 | 22 | private: |
23 | 23 | void update(); |
24 | 24 | |
25 | SurfaceCollection ≻ | |
25 | SurfaceCollection& sc; | |
26 | 26 | std::string iconPath; |
27 | 27 | unsigned int lastUpdate; |
28 | 28 | }; |
src/browsedialog.cpp | ||
---|---|---|
224 | 224 | |
225 | 225 | void BrowseDialog::paint() |
226 | 226 | { |
227 | Surface& s = *gmenu2x->s; | |
227 | OutputSurface& s = *gmenu2x->s; | |
228 | 228 | |
229 | 229 | unsigned int i, iY; |
230 | 230 | unsigned int firstElement, lastElement; |
231 | 231 | unsigned int offsetY; |
232 | 232 | |
233 | Surface bg(gmenu2x->bg); | |
233 | OffscreenSurface bg(gmenu2x->bg); | |
234 | 234 | drawTitleIcon(bg, "icons/explorer.png", true); |
235 | 235 | writeTitle(bg, title); |
236 | 236 | writeSubTitle(bg, subtitle); |
src/gmenu2x.cpp | ||
---|---|---|
259 | 259 | exit(EXIT_FAILURE); |
260 | 260 | } |
261 | 261 | |
262 | s = Surface::openOutputSurface(resX, resY, confInt["videoBpp"]); | |
262 | s = OutputSurface::open(resX, resY, confInt["videoBpp"]); | |
263 | 263 | |
264 | 264 | if (!fileExists(confStr["wallpaper"])) { |
265 | 265 | DEBUG("No wallpaper defined; we will take the default one.\n"); |
... | ... | |
305 | 305 | |
306 | 306 | fflush(NULL); |
307 | 307 | sc.clear(); |
308 | delete s; | |
309 | 308 | |
310 | 309 | #ifdef ENABLE_INOTIFY |
311 | 310 | delete monitor; |
... | ... | |
317 | 316 | |
318 | 317 | // Load wallpaper. |
319 | 318 | delete bg; |
320 | bg = Surface::loadImage(confStr["wallpaper"]); | |
319 | bg = OffscreenSurface::loadImage(confStr["wallpaper"]); | |
321 | 320 | if (!bg) { |
322 | bg = Surface::emptySurface(resX, resY); | |
321 | bg = OffscreenSurface::emptySurface(resX, resY); | |
323 | 322 | } |
324 | 323 | |
325 | 324 | drawTopBar(*bg); |
326 | 325 | drawBottomBar(*bg); |
327 | 326 | |
328 | Surface *bgmain = sc.add(bg, "bgmain"); | |
327 | OffscreenSurface *bgmain = sc.add(*bg, "bgmain"); | |
329 | 328 | |
330 | Surface *sd = Surface::loadImage("imgs/sd.png", confStr["skin"]); | |
329 | Surface *sd = OffscreenSurface::loadImage("imgs/sd.png", confStr["skin"]); | |
331 | 330 | if (sd) sd->blit(*bgmain, 3, bottomBarIconY); |
332 | 331 | |
333 | 332 | string df = getDiskFree(getHome().c_str()); |
... | ... | |
336 | 335 | |
337 | 336 | cpuX = font->getTextWidth(df)+32; |
338 | 337 | #ifdef ENABLE_CPUFREQ |
339 | Surface *cpu = Surface::loadImage("imgs/cpu.png", confStr["skin"]); | |
338 | Surface *cpu = OffscreenSurface::loadImage("imgs/cpu.png", confStr["skin"]); | |
340 | 339 | if (cpu) cpu->blit(bgmain, cpuX, bottomBarIconY); |
341 | 340 | cpuX += 19; |
342 | 341 | manualX = cpuX+font->getTextWidth("300MHz")+5; |
... | ... | |
348 | 347 | int serviceX = resX-38; |
349 | 348 | if (usbnet) { |
350 | 349 | if (web) { |
351 | Surface *webserver = Surface::loadImage( | |
350 | Surface *webserver = OffscreenSurface::loadImage( | |
352 | 351 | "imgs/webserver.png", confStr["skin"]); |
353 | 352 | if (webserver) webserver->blit(*bgmain, serviceX, bottomBarIconY); |
354 | 353 | serviceX -= 19; |
355 | 354 | delete webserver; |
356 | 355 | } |
357 | 356 | if (samba) { |
358 | Surface *sambaS = Surface::loadImage( | |
357 | Surface *sambaS = OffscreenSurface::loadImage( | |
359 | 358 | "imgs/samba.png", confStr["skin"]); |
360 | 359 | if (sambaS) sambaS->blit(*bgmain, serviceX, bottomBarIconY); |
361 | 360 | serviceX -= 19; |
362 | 361 | delete sambaS; |
363 | 362 | } |
364 | 363 | if (inet) { |
365 | Surface *inetS = Surface::loadImage("imgs/inet.png", confStr["skin"]); | |
364 | Surface *inetS = OffscreenSurface::loadImage("imgs/inet.png", confStr["skin"]); | |
366 | 365 | if (inetS) inetS->blit(*bgmain, serviceX, bottomBarIconY); |
367 | 366 | serviceX -= 19; |
368 | 367 | delete inetS; |
src/gmenu2x.h | ||
---|---|---|
42 | 42 | class Layer; |
43 | 43 | class MediaMonitor; |
44 | 44 | class Menu; |
45 | class OutputSurface; | |
45 | 46 | class Surface; |
46 | 47 | |
47 | 48 | #ifndef GMENU2X_SYSTEM_DIR |
... | ... | |
158 | 159 | |
159 | 160 | SurfaceCollection sc; |
160 | 161 | Translator tr; |
161 | Surface *s, *bg; | |
162 | std::unique_ptr<OutputSurface> s; | |
163 | Surface *bg; | |
162 | 164 | std::unique_ptr<Font> font; |
163 | 165 | |
164 | 166 | //Status functions |
src/inputdialog.cpp | ||
---|---|---|
149 | 149 | Uint32 caretTick = 0, curTick; |
150 | 150 | bool caretOn = true; |
151 | 151 | |
152 | Surface bg(gmenu2x->bg); | |
152 | OffscreenSurface bg(gmenu2x->bg); | |
153 | 153 | drawTitleIcon(bg, icon, false); |
154 | 154 | writeTitle(bg, title); |
155 | 155 | writeSubTitle(bg, text); |
... | ... | |
159 | 159 | close = false; |
160 | 160 | ok = true; |
161 | 161 | while (!close) { |
162 | Surface& s = *gmenu2x->s; | |
162 | OutputSurface& s = *gmenu2x->s; | |
163 | 163 | |
164 | 164 | bg.blit(s, 0, 0); |
165 | 165 |
src/linkapp.cpp | ||
---|---|---|
433 | 433 | gmenu2x->setSafeMaxClock(); |
434 | 434 | #endif |
435 | 435 | |
436 | Surface *pngman = Surface::loadImage(manual); | |
436 | OffscreenSurface *pngman = OffscreenSurface::loadImage(manual); | |
437 | 437 | if (!pngman) { |
438 | 438 | return; |
439 | 439 | } |
440 | Surface *bg = Surface::loadImage(gmenu2x->confStr["wallpaper"]); | |
440 | OffscreenSurface *bg = OffscreenSurface::loadImage(gmenu2x->confStr["wallpaper"]); | |
441 | 441 | if (!bg) { |
442 | bg = Surface::emptySurface(gmenu2x->s->width(), gmenu2x->s->height()); | |
442 | bg = OffscreenSurface::emptySurface(gmenu2x->s->width(), gmenu2x->s->height()); | |
443 | 443 | } |
444 | 444 | bg->convertToDisplayFormat(); |
445 | 445 | |
... | ... | |
459 | 459 | #endif |
460 | 460 | |
461 | 461 | while (!close) { |
462 | Surface& s = *gmenu2x->s; | |
462 | OutputSurface& s = *gmenu2x->s; | |
463 | 463 | |
464 | 464 | if (repaint) { |
465 | 465 | bg->blit(s, 0, 0); |
src/messagebox.cpp | ||
---|---|---|
62 | 62 | } |
63 | 63 | |
64 | 64 | int MessageBox::exec() { |
65 | Surface& s = *gmenu2x->s; | |
66 | Surface bg(s); | |
65 | OutputSurface& s = *gmenu2x->s; | |
66 | OffscreenSurface bg(s); | |
67 | 67 | //Darken background |
68 | 68 | bg.box(0, 0, gmenu2x->resX, gmenu2x->resY, 0,0,0,200); |
69 | 69 |
src/selector.cpp | ||
---|---|---|
59 | 59 | fl.setFilter(link->getSelectorFilter()); |
60 | 60 | fl.browse(); |
61 | 61 | |
62 | Surface bg(gmenu2x->bg); | |
62 | OffscreenSurface bg(gmenu2x->bg); | |
63 | 63 | drawTitleIcon(bg, link->getIconPath(), true); |
64 | 64 | writeTitle(bg, link->getTitle()); |
65 | 65 | writeSubTitle(bg, link->getDescription()); |
... | ... | |
95 | 95 | gmenu2x->sc.addSkinRes("imgs/folder.png"); |
96 | 96 | gmenu2x->sc.defaultAlpha = false; |
97 | 97 | while (!close) { |
98 | Surface& s = *gmenu2x->s; | |
98 | OutputSurface& s = *gmenu2x->s; | |
99 | 99 | |
100 | 100 | bg.blit(s, 0, 0); |
101 | 101 |
src/settingsdialog.cpp | ||
---|---|---|
50 | 50 | } |
51 | 51 | |
52 | 52 | bool SettingsDialog::exec() { |
53 | Surface bg(gmenu2x->bg); | |
53 | OffscreenSurface bg(gmenu2x->bg); | |
54 | 54 | bg.convertToDisplayFormat(); |
55 | 55 | |
56 | 56 | bool close = false, ts_pressed = false; |
... | ... | |
78 | 78 | } |
79 | 79 | |
80 | 80 | while (!close) { |
81 | Surface& s = *gmenu2x->s; | |
81 | OutputSurface& s = *gmenu2x->s; | |
82 | 82 | |
83 | 83 | if (ts.available()) ts.poll(); |
84 | 84 |
src/surface.cpp | ||
---|---|---|
32 | 32 | |
33 | 33 | using namespace std; |
34 | 34 | |
35 | ||
36 | // RGBAColor: | |
37 | ||
35 | 38 | RGBAColor RGBAColor::fromString(const string &strColor) { |
36 | 39 | return { |
37 | 40 | uint8_t(constrain(strtol(strColor.substr(0, 2).c_str(), nullptr, 16), |
... | ... | |
58 | 61 | return os; |
59 | 62 | } |
60 | 63 | |
61 | Surface *Surface::openOutputSurface(int width, int height, int bitsperpixel) { | |
62 | SDL_ShowCursor(SDL_DISABLE); | |
63 | SDL_Surface *raw = SDL_SetVideoMode( | |
64 | width, height, bitsperpixel, SDL_HWSURFACE | SDL_DOUBLEBUF); | |
65 | return raw ? new Surface(raw, false) : NULL; | |
66 | } | |
67 | ||
68 | Surface *Surface::emptySurface(int width, int height) { | |
69 | SDL_Surface *raw = SDL_CreateRGBSurface( | |
70 | SDL_SWSURFACE, width, height, 32, 0, 0, 0, 0); | |
71 | if (!raw) return NULL; | |
72 | SDL_FillRect(raw, NULL, SDL_MapRGB(raw->format, 0, 0, 0)); | |
73 | return new Surface(raw, true); | |
74 | } | |
75 | ||
76 | Surface *Surface::loadImage(const string &img, const string &skin, bool loadAlpha) { | |
77 | string skinpath; | |
78 | if (!skin.empty() && !img.empty() && img[0]!='/') | |
79 | skinpath = SurfaceCollection::getSkinFilePath(skin, img); | |
80 | else | |
81 | skinpath = img; | |
82 | ||
83 | SDL_Surface *raw = loadPNG(skinpath, loadAlpha); | |
84 | if (!raw) { | |
85 | ERROR("Couldn't load surface '%s'\n", img.c_str()); | |
86 | return NULL; | |
87 | } | |
88 | 64 | |
89 | return new Surface(raw, true); | |
90 | } | |
91 | ||
92 | Surface::Surface(SDL_Surface *raw_, bool freeWhenDone_) | |
93 | : raw(raw_) | |
94 | , freeWhenDone(freeWhenDone_) | |
95 | { | |
96 | } | |
65 | // Surface: | |
97 | 66 | |
98 | 67 | Surface::Surface(Surface const& other) |
99 | : Surface(SDL_ConvertSurface( | |
100 | other.raw, other.raw->format, SDL_SWSURFACE), true) | |
68 | : Surface(SDL_ConvertSurface(other.raw, other.raw->format, SDL_SWSURFACE)) | |
101 | 69 | { |
102 | 70 | // Note: A bug in SDL_ConvertSurface() leaves the per-surface alpha |
103 | 71 | // undefined when converting from RGBA to RGBA. This can cause |
... | ... | |
106 | 74 | raw->format->alpha = other.raw->format->alpha; |
107 | 75 | } |
108 | 76 | |
109 | Surface::Surface(Surface&& other) | |
110 | : raw(other.raw) | |
111 | , freeWhenDone(other.freeWhenDone) | |
112 | { | |
113 | other.raw = nullptr; | |
114 | other.freeWhenDone = false; | |
115 | } | |
116 | ||
117 | Surface::~Surface() | |
118 | { | |
119 | if (freeWhenDone) { | |
120 | SDL_FreeSurface(raw); | |
121 | } | |
122 | } | |
123 | ||
124 | Surface& Surface::operator=(Surface other) | |
125 | { | |
126 | swap(other); | |
127 | return *this; | |
128 | } | |
129 | ||
130 | void Surface::swap(Surface& other) | |
131 | { | |
132 | std::swap(raw, other.raw); | |
133 | std::swap(freeWhenDone, other.freeWhenDone); | |
134 | } | |
135 | ||
136 | void Surface::convertToDisplayFormat() { | |
137 | SDL_Surface *newSurface = SDL_DisplayFormat(raw); | |
138 | if (newSurface) { | |
139 | if (freeWhenDone) { | |
140 | SDL_FreeSurface(raw); | |
141 | } | |
142 | raw = newSurface; | |
143 | freeWhenDone = true; | |
144 | } | |
145 | } | |
146 | ||
147 | void Surface::flip() { | |
148 | SDL_Flip(raw); | |
149 | } | |
150 | ||
151 | 77 | void Surface::blit(SDL_Surface *destination, int x, int y, int w, int h, int a) const { |
152 | 78 | if (destination == NULL || a==0) return; |
153 | 79 | |
... | ... | |
351 | 277 | SDL_UnlockSurface(raw); |
352 | 278 | } |
353 | 279 | } |
280 | ||
281 | ||
282 | // OffscreenSurface: | |
283 | ||
284 | OffscreenSurface *OffscreenSurface::emptySurface(int width, int height) | |
285 | { | |
286 | SDL_Surface *raw = SDL_CreateRGBSurface( | |
287 | SDL_SWSURFACE, width, height, 32, 0, 0, 0, 0); | |
288 | if (!raw) return nullptr; | |
289 | SDL_FillRect(raw, nullptr, SDL_MapRGB(raw->format, 0, 0, 0)); | |
290 | return new OffscreenSurface(raw); | |
291 | } | |
292 | ||
293 | OffscreenSurface *OffscreenSurface::loadImage( | |
294 | const string &img, const string &skin, bool loadAlpha) | |
295 | { | |
296 | string skinpath; | |
297 | if (!skin.empty() && !img.empty() && img[0]!='/') | |
298 | skinpath = SurfaceCollection::getSkinFilePath(skin, img); | |
299 | else | |
300 | skinpath = img; | |
301 | ||
302 | SDL_Surface *raw = loadPNG(skinpath, loadAlpha); | |
303 | if (!raw) { | |
304 | ERROR("Couldn't load surface '%s'\n", img.c_str()); | |
305 | return nullptr; | |
306 | } | |
307 | ||
308 | return new OffscreenSurface(raw); | |
309 | } | |
310 | ||
311 | OffscreenSurface::OffscreenSurface(OffscreenSurface&& other) | |
312 | : Surface(other.raw) | |
313 | { | |
314 | other.raw = nullptr; | |
315 | } | |
316 | ||
317 | OffscreenSurface::~OffscreenSurface() | |
318 | { | |
319 | SDL_FreeSurface(raw); | |
320 | } | |
321 | ||
322 | OffscreenSurface& OffscreenSurface::operator=(OffscreenSurface other) | |
323 | { | |
324 | swap(other); | |
325 | return *this; | |
326 | } | |
327 | ||
328 | void OffscreenSurface::swap(OffscreenSurface& other) | |
329 | { | |
330 | std::swap(raw, other.raw); | |
331 | } | |
332 | ||
333 | void OffscreenSurface::convertToDisplayFormat() { | |
334 | SDL_Surface *newSurface = SDL_DisplayFormat(raw); | |
335 | if (newSurface) { | |
336 | SDL_FreeSurface(raw); | |
337 | raw = newSurface; | |
338 | } | |
339 | } | |
340 | ||
341 | ||
342 | // OutputSurface: | |
343 | ||
344 | unique_ptr<OutputSurface> OutputSurface::open( | |
345 | int width, int height, int bitsPerPixel) | |
346 | { | |
347 | SDL_ShowCursor(SDL_DISABLE); | |
348 | SDL_Surface *raw = SDL_SetVideoMode( | |
349 | width, height, bitsPerPixel, SDL_HWSURFACE | SDL_DOUBLEBUF); | |
350 | return unique_ptr<OutputSurface>(raw ? new OutputSurface(raw) : nullptr); | |
351 | } | |
352 | ||
353 | void OutputSurface::flip() { | |
354 | SDL_Flip(raw); | |
355 | } |
src/surface.h | ||
---|---|---|
1 | 1 | /*************************************************************************** |
2 | 2 | * Copyright (C) 2006 by Massimiliano Torromeo * |
3 | * massimiliano.torromeo@gmail.com * | |
3 | * massimiliano.torromeo@gmail.com * | |
4 | * Copyright (C) 2010-2014 by various authors; see Git log * | |
4 | 5 | * * |
5 | 6 | * This program is free software; you can redistribute it and/or modify * |
6 | 7 | * it under the terms of the GNU General Public License as published by * |
... | ... | |
26 | 27 | #include <SDL.h> |
27 | 28 | |
28 | 29 | #include <cstdint> |
30 | #include <memory> | |
29 | 31 | #include <ostream> |
30 | 32 | #include <string> |
31 | 33 | |
... | ... | |
42 | 44 | std::ostream& operator<<(std::ostream& os, RGBAColor const& color); |
43 | 45 | |
44 | 46 | /** |
45 | Wrapper around SDL_Surface | |
46 | @author Massimiliano Torromeo <massimiliano.torromeo@gmail.com> | |
47 | */ | |
47 | * Abstract base class for surfaces; wraps SDL_Surface. | |
48 | */ | |
48 | 49 | class Surface { |
49 | 50 | public: |
50 | static Surface *openOutputSurface(int width, int height, int bitsperpixel); | |
51 | static Surface *emptySurface(int width, int height); | |
52 | static Surface *loadImage(const std::string &img, | |
53 | const std::string &skin="", bool loadAlpha=true); | |
54 | ||
55 | // TODO: Remove this once naked Surface pointers are no longer in use. | |
56 | Surface(Surface *other) : Surface(*other) {} | |
57 | ||
58 | Surface(Surface const& other); | |
59 | Surface(Surface&& other); | |
60 | ~Surface(); | |
61 | Surface& operator=(Surface other); | |
62 | void swap(Surface& other); | |
63 | ||
64 | /** Converts the underlying surface to the same pixel format as the frame | |
65 | * buffer, for faster blitting. This removes the alpha channel if the | |
66 | * image has done. | |
67 | */ | |
68 | void convertToDisplayFormat(); | |
51 | Surface& operator=(Surface const& other) = delete; | |
69 | 52 | |
70 | 53 | int width() const { return raw->w; } |
71 | 54 | int height() const { return raw->h; } |
72 | 55 | |
73 | void flip(); | |
74 | ||
75 | 56 | void clearClipRect(); |
76 | 57 | void setClipRect(int x, int y, int w, int h); |
77 | 58 | void setClipRect(SDL_Rect rect); |
... | ... | |
96 | 77 | rectangle((SDL_Rect){ x, y, w, h }, RGBAColor(r, g, b, a)); |
97 | 78 | } |
98 | 79 | |
80 | protected: | |
81 | Surface(SDL_Surface *raw) : raw(raw) {} | |
82 | Surface(Surface const& other); | |
83 | ||
84 | SDL_Surface *raw; | |
85 | ||
86 | // For direct access to "raw". | |
87 | friend class Font; | |
88 | ||
99 | 89 | private: |
100 | Surface(SDL_Surface *raw, bool freeWhenDone); | |
101 | 90 | void blit(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1) const; |
102 | 91 | void blitCenter(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1) const; |
103 | 92 | void blitRight(SDL_Surface *destination, int x, int y, int w=0, int h=0, int a=-1) const; |
... | ... | |
111 | 100 | * rectangle. |
112 | 101 | */ |
113 | 102 | void applyClipRect(SDL_Rect& rect); |
103 | }; | |
114 | 104 | |
115 | SDL_Surface *raw; | |
116 | bool freeWhenDone; | |
105 | /** | |
106 | * A surface that is off-screen: not visible. | |
107 | */ | |
108 | class OffscreenSurface: public Surface { | |
109 | public: | |
110 | static OffscreenSurface *emptySurface(int width, int height); | |
111 | static OffscreenSurface *loadImage(const std::string &img, | |
112 | const std::string &skin="", bool loadAlpha=true); | |
117 | 113 | |
118 | // For direct access to "raw". | |
119 | friend class Font; | |
114 | // TODO: Remove this once naked Surface pointers are no longer in use. | |
115 | OffscreenSurface(Surface *other) : Surface(*other) {} | |
116 | ||
117 | OffscreenSurface(Surface const& other) : Surface(other) {} | |
118 | OffscreenSurface(OffscreenSurface&& other); | |
119 | ~OffscreenSurface(); | |
120 | OffscreenSurface& operator=(OffscreenSurface other); | |
121 | void swap(OffscreenSurface& other); | |
122 | ||
123 | /** | |
124 | * Converts the underlying surface to the same pixel format as the frame | |
125 | * buffer, for faster blitting. This removes the alpha channel if the | |
126 | * image has one. | |
127 | */ | |
128 | void convertToDisplayFormat(); | |
129 | ||
130 | private: | |
131 | OffscreenSurface(SDL_Surface *raw) : Surface(raw) {} | |
132 | }; | |
133 | ||
134 | /** | |
135 | * A surface that is used for writing to a video output device. | |
136 | */ | |
137 | class OutputSurface: public Surface { | |
138 | public: | |
139 | static std::unique_ptr<OutputSurface> open( | |
140 | int width, int height, int bitsPerPixel); | |
141 | ||
142 | /** | |
143 | * Offers the current buffer to the video system to be presented and | |
144 | * acquires a new buffer to draw into. | |
145 | */ | |
146 | void flip(); | |
147 | ||
148 | private: | |
149 | OutputSurface(SDL_Surface *raw) : Surface(raw) {} | |
120 | 150 | }; |
121 | 151 | |
122 | 152 | #endif |
src/surfacecollection.cpp | ||
---|---|---|
98 | 98 | return surfaces.find(path) != surfaces.end(); |
99 | 99 | } |
100 | 100 | |
101 | Surface *SurfaceCollection::add(Surface const& s, std::string const& path) { | |
101 | OffscreenSurface *SurfaceCollection::add(Surface const& s, std::string const& path) { | |
102 | 102 | if (exists(path)) del(path); |
103 | Surface *copy = new Surface(s); | |
103 | auto copy = new OffscreenSurface(s); | |
104 | 104 | surfaces[path] = copy; |
105 | 105 | return copy; |
106 | 106 | } |
107 | 107 | |
108 | Surface *SurfaceCollection::add(const string &path) { | |
108 | OffscreenSurface *SurfaceCollection::add(const string &path) { | |
109 | 109 | if (path.empty()) return NULL; |
110 | 110 | if (exists(path)) del(path); |
111 | 111 | string filePath = path; |
... | ... | |
120 | 120 | } |
121 | 121 | |
122 | 122 | DEBUG("Adding surface: '%s'\n", path.c_str()); |
123 | Surface *s = Surface::loadImage(filePath, "", defaultAlpha); | |
124 | if (s != NULL) { | |
123 | auto s = OffscreenSurface::loadImage(filePath, "", defaultAlpha); | |
124 | if (s) { | |
125 | 125 | surfaces[path] = s; |
126 | 126 | } |
127 | 127 | return s; |
128 | 128 | } |
129 | 129 | |
130 | Surface *SurfaceCollection::addSkinRes(const string &path, bool useDefault) { | |
130 | OffscreenSurface *SurfaceCollection::addSkinRes(const string &path, bool useDefault) { | |
131 | 131 | if (path.empty()) return NULL; |
132 | 132 | if (exists(path)) del(path); |
133 | 133 | |
... | ... | |
136 | 136 | return NULL; |
137 | 137 | |
138 | 138 | DEBUG("Adding skin surface: '%s'\n", path.c_str()); |
139 | Surface *s = Surface::loadImage(skinpath); | |
140 | if (s != NULL) { | |
139 | auto s = OffscreenSurface::loadImage(skinpath); | |
140 | if (s) { | |
141 | 141 | surfaces[path] = s; |
142 | 142 | } |
143 | 143 | return s; |
... | ... | |
163 | 163 | surfaces.erase(from); |
164 | 164 | } |
165 | 165 | |
166 | Surface *SurfaceCollection::operator[](const string &key) { | |
166 | OffscreenSurface *SurfaceCollection::operator[](const string &key) { | |
167 | 167 | SurfaceHash::iterator i = surfaces.find(key); |
168 | 168 | if (i == surfaces.end()) |
169 | 169 | return add(key); |
... | ... | |
171 | 171 | return i->second; |
172 | 172 | } |
173 | 173 | |
174 | Surface *SurfaceCollection::skinRes(const string &key, bool useDefault) { | |
174 | OffscreenSurface *SurfaceCollection::skinRes(const string &key, bool useDefault) { | |
175 | 175 | if (key.empty()) return NULL; |
176 | 176 | |
177 | 177 | SurfaceHash::iterator i = surfaces.find(key); |
src/surfacecollection.h | ||
---|---|---|
23 | 23 | #include <string> |
24 | 24 | #include <unordered_map> |
25 | 25 | |
26 | class OffscreenSurface; | |
26 | 27 | class Surface; |
27 | 28 | |
28 | typedef std::unordered_map<std::string, Surface *> SurfaceHash; | |
29 | typedef std::unordered_map<std::string, OffscreenSurface *> SurfaceHash; | |
29 | 30 | |
30 | 31 | /** |
31 | 32 | Hash Map of surfaces that loads surfaces not already loaded and reuses already loaded ones. |
... | ... | |
49 | 50 | * Adds a copy of the given surface to this collection under the given |
50 | 51 | * path. Returns the copy. |
51 | 52 | */ |
52 | Surface *add(Surface const& s, std::string const& path); | |
53 | OffscreenSurface *add(Surface const& s, std::string const& path); | |
53 | 54 | |
54 | Surface *add(const std::string &path); | |
55 | Surface *addSkinRes(const std::string &path, bool useDefault = true); | |
55 | OffscreenSurface *add(const std::string &path); | |
56 | OffscreenSurface *addSkinRes(const std::string &path, bool useDefault = true); | |
56 | 57 | void del(const std::string &path); |
57 | 58 | void clear(); |
58 | 59 | void move(const std::string &from, const std::string &to); |
59 | 60 | bool exists(const std::string &path); |
60 | 61 | |
61 | Surface *operator[](const std::string &); | |
62 | Surface *skinRes(const std::string &key, bool useDefault = true); | |
62 | OffscreenSurface *operator[](const std::string &); | |
63 | OffscreenSurface *skinRes(const std::string &key, bool useDefault = true); | |
63 | 64 | |
64 | 65 | private: |
65 | 66 | SurfaceHash surfaces; |
src/textdialog.cpp | ||
---|---|---|
60 | 60 | void TextDialog::exec() { |
61 | 61 | bool close = false; |
62 | 62 | |
63 | Surface bg(gmenu2x->bg); | |
63 | OffscreenSurface bg(gmenu2x->bg); | |
64 | 64 | |
65 | 65 | //link icon |
66 | 66 | if (!fileExists(icon)) |
... | ... | |
87 | 87 | |
88 | 88 | unsigned firstRow = 0; |
89 | 89 | while (!close) { |
90 | Surface& s = *gmenu2x->s; | |
90 | OutputSurface& s = *gmenu2x->s; | |
91 | 91 | |
92 | 92 | bg.blit(s, 0, 0); |
93 | 93 | drawText(text, contentY, firstRow, rowsPerPage); |
src/textmanualdialog.cpp | ||
---|---|---|
68 | 68 | } |
69 | 69 | |
70 | 70 | void TextManualDialog::exec() { |
71 | Surface bg(gmenu2x->bg); | |
71 | OffscreenSurface bg(gmenu2x->bg); | |
72 | 72 | |
73 | 73 | //link icon |
74 | 74 | if (!fileExists(icon)) |
... | ... | |
102 | 102 | bool close = false; |
103 | 103 | |
104 | 104 | while (!close) { |
105 | Surface& s = *gmenu2x->s; | |
105 | OutputSurface& s = *gmenu2x->s; | |
106 | 106 | |
107 | 107 | bg.blit(s,0,0); |
108 | 108 | writeSubTitle(s, pages[page].title); |
src/wallpaperdialog.cpp | ||
---|---|---|
88 | 88 | unsigned int nb_elements = height / fontheight; |
89 | 89 | |
90 | 90 | while (!close) { |
91 | Surface& s = *gmenu2x->s; | |
91 | OutputSurface& s = *gmenu2x->s; | |
92 | 92 | |
93 | 93 | if (selected > firstElement + nb_elements - 1) |
94 | 94 | firstElement = selected - nb_elements + 1; |
Branches:
install_locations
master
opkrun
packages