Skip to content

Commit 9158ace

Browse files
committed
SDL: screen canvas is now the direct window surface
1 parent 2a3c30a commit 9158ace

File tree

4 files changed

+16
-24
lines changed

4 files changed

+16
-24
lines changed

src/platform/sdl/display.cpp

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ bool Canvas::create(int w, int h) {
4646
return _canvas != NULL;
4747
}
4848

49+
bool Canvas::create(int w, int h, SDL_Window *window) {
50+
logEntered();
51+
_w = w;
52+
_h = h;
53+
_canvas = SDL_GetWindowSurface(window);
54+
return _canvas != NULL;
55+
}
56+
4957
void Canvas::copy(Canvas *src, const MARect *srcRect, int dstx, int dsty) {
5058
SDL_Rect srcrect;
5159
srcrect.x = srcRect->left;
@@ -94,12 +102,11 @@ Graphics::~Graphics() {
94102
bool Graphics::construct(const char *font, const char *boldFont) {
95103
logEntered();
96104

97-
_surface = SDL_GetWindowSurface(_window);
98105
SDL_GetWindowSize(_window, &_w, &_h);
99106
bool result = false;
100107
if (loadFonts(font, boldFont)) {
101108
_screen = new Canvas();
102-
if (_screen && _screen->create(getWidth(), getHeight())) {
109+
if (_screen && _screen->create(getWidth(), getHeight(), _window)) {
103110
_drawTarget = _screen;
104111
maSetColor(DEFAULT_BACKGROUND);
105112
result = true;
@@ -109,20 +116,6 @@ bool Graphics::construct(const char *font, const char *boldFont) {
109116
}
110117

111118
void Graphics::redraw() {
112-
SDL_Surface *src = ((Canvas *)_screen)->_canvas;
113-
SDL_Rect srcrect;
114-
srcrect.x = 0;
115-
srcrect.y = 0;
116-
srcrect.w = _screen->_w;
117-
srcrect.h = _screen->_h;
118-
119-
SDL_Rect dstrect;
120-
dstrect.x = 0;
121-
dstrect.y = 0;
122-
dstrect.w = _w;
123-
dstrect.h = _h;
124-
125-
SDL_BlitSurface(src, &srcrect, _surface, &dstrect);
126119
SDL_UpdateWindowSurface(_window);
127120
}
128121

@@ -131,9 +124,8 @@ void Graphics::resize() {
131124
bool drawScreen = (_drawTarget == _screen);
132125
delete _screen;
133126
_screen = new ::Canvas();
134-
_screen->create(getWidth(), getHeight());
127+
_screen->create(getWidth(), getHeight(), _window);
135128
_drawTarget = drawScreen ? _screen : NULL;
136-
_surface = SDL_GetWindowSurface(_window);
137129
}
138130

139131
bool Graphics::loadFonts(const char *font, const char *boldFont) {

src/platform/sdl/display.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ struct Graphics : common::Graphics {
2828
bool loadFont(const char *filename, FT_Face &face);
2929

3030
SDL_Window *_window;
31-
SDL_Surface *_surface;
3231
};
3332

3433
#endif

src/ui/canvas.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct Canvas {
2424
virtual ~Canvas();
2525

2626
bool create(int w, int h);
27+
bool create(int w, int h, SDL_Window *window);
2728
void copy(Canvas *src, const MARect *srcRect, int dstx, int dsty);
2829
void setClip(int x, int y, int w, int h);
2930
pixel_t *getLine(int y);

src/ui/system.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -914,12 +914,12 @@ void System::showMenu() {
914914
items->add(new String(buffer));
915915
_systemMenu[index++] = MENU_ZOOM_UP;
916916
_systemMenu[index++] = MENU_ZOOM_DN;
917-
}
918917

919-
sprintf(buffer, "Editor [%s]", (opt_ide == IDE_NONE ? "OFF" :
920-
opt_ide == IDE_EXTERNAL ? "Live Mode" : "ON"));
921-
items->add(new String(buffer));
922-
_systemMenu[index++] = MENU_EDITMODE;
918+
sprintf(buffer, "Editor [%s]", (opt_ide == IDE_NONE ? "OFF" :
919+
opt_ide == IDE_EXTERNAL ? "Live Mode" : "ON"));
920+
items->add(new String(buffer));
921+
_systemMenu[index++] = MENU_EDITMODE;
922+
}
923923

924924
sprintf(buffer, "Audio [%s]", (opt_mute_audio ? "OFF" : "ON"));
925925
items->add(new String(buffer));

0 commit comments

Comments
 (0)