@@ -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+
4957void 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() {
94102bool 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
111118void 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
139131bool Graphics::loadFonts (const char *font, const char *boldFont) {
0 commit comments