~ubuntu-branches/ubuntu/trusty/manaplus/trusty-proposed

« back to all changes in this revision

Viewing changes to src/sdlgraphics.cpp

  • Committer: Package Import Robot
  • Author(s): Patrick Matthäi
  • Date: 2013-09-17 10:35:51 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20130917103551-az7p3nz9jgxwqjfn
Tags: 1.3.9.15-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  The ManaPlus Client
3
 
 *  Copyright (C) 2004-2009  The Mana World Development Team
4
 
 *  Copyright (C) 2009-2010  The Mana Developers
5
 
 *  Copyright (C) 2011-2013  The ManaPlus Developers
6
 
 *
7
 
 *  This file is part of The ManaPlus Client.
8
 
 *
9
 
 *  This program is free software; you can redistribute it and/or modify
10
 
 *  it under the terms of the GNU General Public License as published by
11
 
 *  the Free Software Foundation; either version 2 of the License, or
12
 
 *  any later version.
13
 
 *
14
 
 *  This program is distributed in the hope that it will be useful,
15
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 
 *  GNU General Public License for more details.
18
 
 *
19
 
 *  You should have received a copy of the GNU General Public License
20
 
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 
 */
22
 
 
23
 
#ifndef USE_SDL2
24
 
 
25
 
#include "sdlgraphics.h"
26
 
 
27
 
#include "main.h"
28
 
 
29
 
#include "configuration.h"
30
 
#include "graphicsmanager.h"
31
 
#include "graphicsvertexes.h"
32
 
#include "logger.h"
33
 
 
34
 
#include "resources/imagehelper.h"
35
 
 
36
 
#include "utils/sdlcheckutils.h"
37
 
 
38
 
#include <guichan/sdl/sdlpixel.hpp>
39
 
 
40
 
#include "debug.h"
41
 
 
42
 
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
43
 
static unsigned int *cR = nullptr;
44
 
static unsigned int *cG = nullptr;
45
 
static unsigned int *cB = nullptr;
46
 
#endif
47
 
 
48
 
SDLGraphics::SDLGraphics() :
49
 
    Graphics(),
50
 
    mOldPixel(0),
51
 
    mOldAlpha(0)
52
 
{
53
 
}
54
 
 
55
 
SDLGraphics::~SDLGraphics()
56
 
{
57
 
}
58
 
 
59
 
bool SDLGraphics::drawRescaledImage(const Image *const image,
60
 
                                    int srcX, int srcY,
61
 
                                    int dstX, int dstY,
62
 
                                    const int width, const int height,
63
 
                                    const int desiredWidth,
64
 
                                    const int desiredHeight,
65
 
                                    const bool useColor A_UNUSED)
66
 
{
67
 
    FUNC_BLOCK("Graphics::drawRescaledImage", 1)
68
 
    // Check that preconditions for blitting are met.
69
 
    if (!mWindow || !image)
70
 
        return false;
71
 
    if (!image->mSDLSurface)
72
 
        return false;
73
 
 
74
 
    Image *const tmpImage = image->SDLgetScaledImage(
75
 
        desiredWidth, desiredHeight);
76
 
 
77
 
    if (!tmpImage)
78
 
        return false;
79
 
    if (!tmpImage->mSDLSurface)
80
 
        return false;
81
 
 
82
 
    const gcn::ClipRectangle &top = mClipStack.top();
83
 
    const SDL_Rect &bounds = image->mBounds;
84
 
 
85
 
    SDL_Rect srcRect =
86
 
    {
87
 
        static_cast<int16_t>(srcX + bounds.x),
88
 
        static_cast<int16_t>(srcY + bounds.y),
89
 
        static_cast<uint16_t>(width),
90
 
        static_cast<uint16_t>(height)
91
 
    };
92
 
 
93
 
    SDL_Rect dstRect =
94
 
    {
95
 
        static_cast<int16_t>(dstX + top.xOffset),
96
 
        static_cast<int16_t>(dstY + top.yOffset),
97
 
        0,
98
 
        0
99
 
    };
100
 
 
101
 
    const bool returnValue = !(SDL_BlitSurface(tmpImage->mSDLSurface,
102
 
        &srcRect, mWindow, &dstRect) < 0);
103
 
 
104
 
    delete tmpImage;
105
 
 
106
 
    return returnValue;
107
 
}
108
 
 
109
 
bool SDLGraphics::drawImage2(const Image *const image, int srcX, int srcY,
110
 
                             int dstX, int dstY, const int width,
111
 
                             const int height, const bool useColor A_UNUSED)
112
 
{
113
 
    FUNC_BLOCK("Graphics::drawImage2", 1)
114
 
    // Check that preconditions for blitting are met.
115
 
    if (!mWindow || !image || !image->mSDLSurface)
116
 
        return false;
117
 
 
118
 
    const gcn::ClipRectangle &top = mClipStack.top();
119
 
    const SDL_Rect &bounds = image->mBounds;
120
 
 
121
 
 
122
 
    SDL_Surface *const src = image->mSDLSurface;
123
 
 
124
 
    srcX += bounds.x;
125
 
    srcY += bounds.y;
126
 
    dstX += top.xOffset;
127
 
    dstY += top.yOffset;
128
 
 
129
 
    int w = width;
130
 
    int h = height;
131
 
    if (srcX < 0)
132
 
    {
133
 
        w += srcX;
134
 
        dstX -= static_cast<int16_t>(srcX);
135
 
        srcX = 0;
136
 
    }
137
 
    const int maxw = src->w - srcX;
138
 
    if (maxw < w)
139
 
        w = maxw;
140
 
 
141
 
    if (srcY < 0)
142
 
    {
143
 
        h += srcY;
144
 
        dstY -= static_cast<int16_t>(srcY);
145
 
        srcY = 0;
146
 
    }
147
 
    const int maxh = src->h - srcY;
148
 
    if (maxh < h)
149
 
        h = maxh;
150
 
 
151
 
    const SDL_Rect *const clip = &mWindow->clip_rect;
152
 
    const int clipX = clip->x;
153
 
    const int clipY = clip->y;
154
 
    int dx = clipX - dstX;
155
 
    if (dx > 0)
156
 
    {
157
 
        w -= dx;
158
 
        dstX += static_cast<int16_t>(dx);
159
 
        srcX += dx;
160
 
    }
161
 
    dx = dstX + w - clipX - clip->w;
162
 
    if (dx > 0)
163
 
        w -= dx;
164
 
 
165
 
    int dy = clipY - dstY;
166
 
    if (dy > 0)
167
 
    {
168
 
        h -= dy;
169
 
        dstY += static_cast<int16_t>(dy);
170
 
        srcY += dy;
171
 
    }
172
 
    dy = dstY + h - clipY - clip->h;
173
 
    if (dy > 0)
174
 
        h -= dy;
175
 
 
176
 
    if (w > 0 && h > 0)
177
 
    {
178
 
        SDL_Rect srcRect =
179
 
        {
180
 
            static_cast<int16_t>(srcX),
181
 
            static_cast<int16_t>(srcY),
182
 
            static_cast<uint16_t>(w),
183
 
            static_cast<uint16_t>(h)
184
 
        };
185
 
 
186
 
        SDL_Rect dstRect =
187
 
        {
188
 
            static_cast<int16_t>(dstX),
189
 
            static_cast<int16_t>(dstY),
190
 
            static_cast<uint16_t>(w),
191
 
            static_cast<uint16_t>(h)
192
 
        };
193
 
 
194
 
        return SDL_LowerBlit(src, &srcRect, mWindow, &dstRect);
195
 
    }
196
 
    return 0;
197
 
}
198
 
 
199
 
void SDLGraphics::drawImagePattern(const Image *const image,
200
 
                                   const int x, const int y,
201
 
                                   const int w, const int h)
202
 
{
203
 
    FUNC_BLOCK("Graphics::drawImagePattern", 1)
204
 
    // Check that preconditions for blitting are met.
205
 
    if (!mWindow || !image)
206
 
        return;
207
 
    if (!image->mSDLSurface)
208
 
        return;
209
 
 
210
 
    const SDL_Rect &bounds = image->mBounds;
211
 
    const int iw = bounds.w;
212
 
    const int ih = bounds.h;
213
 
    if (iw == 0 || ih == 0)
214
 
        return;
215
 
 
216
 
    const gcn::ClipRectangle &top = mClipStack.top();
217
 
    const int xOffset = top.xOffset + x;
218
 
    const int yOffset = top.yOffset + y;
219
 
    const int srcX = bounds.x;
220
 
    const int srcY = bounds.y;
221
 
    SDL_Surface *const src = image->mSDLSurface;
222
 
    const SDL_Rect *const clip = &mWindow->clip_rect;
223
 
    const int clipX = clip->x;
224
 
    const int clipY = clip->y;
225
 
 
226
 
    for (int py = 0; py < h; py += ih)
227
 
    {
228
 
        const int dh = (py + ih >= h) ? h - py : ih;
229
 
        int dstY = py + yOffset;
230
 
        int y2 = srcY;
231
 
        int h2 = dh;
232
 
        if (y2 < 0)
233
 
        {
234
 
            h2 += y2;
235
 
            dstY -= static_cast<int16_t>(y2);
236
 
            y2 = 0;
237
 
        }
238
 
        const int maxh = src->h - y2;
239
 
        if (maxh < h2)
240
 
            h2 = maxh;
241
 
 
242
 
        int dy = clipY - dstY;
243
 
        if (dy > 0)
244
 
        {
245
 
            h2 -= dy;
246
 
            dstY += static_cast<int16_t>(dy);
247
 
            y2 += dy;
248
 
        }
249
 
        dy = dstY + h2 - clipY - clip->h;
250
 
        if (dy > 0)
251
 
            h2 -= dy;
252
 
 
253
 
        if (h2 > 0)
254
 
        {
255
 
            for (int px = 0; px < w; px += iw)
256
 
            {
257
 
                const int dw = (px + iw >= w) ? w - px : iw;
258
 
                int dstX = px + xOffset;
259
 
                int x2 = srcX;
260
 
                int w2 = dw;
261
 
                if (x2 < 0)
262
 
                {
263
 
                    w2 += x2;
264
 
                    dstX -= static_cast<int16_t>(x2);
265
 
                    x2 = 0;
266
 
                }
267
 
                const int maxw = src->w - x2;
268
 
                if (maxw < w2)
269
 
                    w2 = maxw;
270
 
 
271
 
                int dx = clipX - dstX;
272
 
                if (dx > 0)
273
 
                {
274
 
                    w2 -= dx;
275
 
                    dstX += static_cast<int16_t>(dx);
276
 
                    x2 += dx;
277
 
                }
278
 
                dx = dstX + w2 - clipX - clip->w;
279
 
                if (dx > 0)
280
 
                    w2 -= dx;
281
 
 
282
 
                if (w2 > 0)
283
 
                {
284
 
                    SDL_Rect srcRect =
285
 
                    {
286
 
                        static_cast<int16_t>(x2),
287
 
                        static_cast<int16_t>(y2),
288
 
                        static_cast<uint16_t>(w2),
289
 
                        static_cast<uint16_t>(h2)
290
 
                    };
291
 
 
292
 
                    SDL_Rect dstRect =
293
 
                    {
294
 
                        static_cast<int16_t>(dstX),
295
 
                        static_cast<int16_t>(dstY),
296
 
                        static_cast<uint16_t>(w2),
297
 
                        static_cast<uint16_t>(h2)
298
 
                    };
299
 
 
300
 
                    SDL_LowerBlit(src, &srcRect, mWindow, &dstRect);
301
 
                }
302
 
 
303
 
//            SDL_BlitSurface(image->mSDLSurface, &srcRect, mWindow, &dstRect);
304
 
            }
305
 
        }
306
 
    }
307
 
}
308
 
 
309
 
void SDLGraphics::drawRescaledImagePattern(const Image *const image,
310
 
                                           const int x, const int y,
311
 
                                           const int w, const int h,
312
 
                                           const int scaledWidth,
313
 
                                           const int scaledHeight)
314
 
{
315
 
    // Check that preconditions for blitting are met.
316
 
    if (!mWindow || !image)
317
 
        return;
318
 
    if (!image->mSDLSurface)
319
 
        return;
320
 
 
321
 
    if (scaledHeight == 0 || scaledWidth == 0)
322
 
        return;
323
 
 
324
 
    Image *const tmpImage = image->SDLgetScaledImage(
325
 
        scaledWidth, scaledHeight);
326
 
    if (!tmpImage)
327
 
        return;
328
 
 
329
 
    const SDL_Rect &bounds = tmpImage->mBounds;
330
 
    const int iw = bounds.w;
331
 
    const int ih = bounds.h;
332
 
    if (iw == 0 || ih == 0)
333
 
        return;
334
 
 
335
 
    const gcn::ClipRectangle &top = mClipStack.top();
336
 
    const int xOffset = top.xOffset + x;
337
 
    const int yOffset = top.yOffset + y;
338
 
    const int srcX = bounds.x;
339
 
    const int srcY = bounds.y;
340
 
 
341
 
    for (int py = 0; py < h; py += ih)  // Y position on pattern plane
342
 
    {
343
 
        const int dh = (py + ih >= h) ? h - py : ih;
344
 
        const int dstY = py + yOffset;
345
 
 
346
 
        for (int px = 0; px < w; px += iw)  // X position on pattern plane
347
 
        {
348
 
            const int dw = (px + iw >= w) ? w - px : iw;
349
 
            const int dstX = px + xOffset;
350
 
 
351
 
            SDL_Rect srcRect =
352
 
            {
353
 
                static_cast<int16_t>(srcX),
354
 
                static_cast<int16_t>(srcY),
355
 
                static_cast<uint16_t>(dw),
356
 
                static_cast<uint16_t>(dh)
357
 
            };
358
 
 
359
 
            SDL_Rect dstRect =
360
 
            {
361
 
                static_cast<int16_t>(dstX),
362
 
                static_cast<int16_t>(dstY),
363
 
                0,
364
 
                0
365
 
            };
366
 
 
367
 
            SDL_BlitSurface(tmpImage->mSDLSurface, &srcRect,
368
 
                            mWindow, &dstRect);
369
 
        }
370
 
    }
371
 
 
372
 
    delete tmpImage;
373
 
}
374
 
 
375
 
void SDLGraphics::calcImagePattern(ImageVertexes* const vert,
376
 
                                   const Image *const image,
377
 
                                   const int x, const int y,
378
 
                                   const int w, const int h) const
379
 
{
380
 
    // Check that preconditions for blitting are met.
381
 
    if (!vert || !mWindow || !image || !image->mSDLSurface)
382
 
        return;
383
 
 
384
 
    const SDL_Rect &bounds = image->mBounds;
385
 
    const int iw = bounds.w;
386
 
    const int ih = bounds.h;
387
 
    if (iw == 0 || ih == 0)
388
 
        return;
389
 
 
390
 
    const gcn::ClipRectangle &top = mClipStack.top();
391
 
    const int xOffset = top.xOffset + x;
392
 
    const int yOffset = top.yOffset + y;
393
 
    const int srcX = bounds.x;
394
 
    const int srcY = bounds.y;
395
 
 
396
 
    for (int py = 0; py < h; py += ih)  // Y position on pattern plane
397
 
    {
398
 
        const int dh = (py + ih >= h) ? h - py : ih;
399
 
        const int dstY = py + yOffset;
400
 
 
401
 
        for (int px = 0; px < w; px += iw)  // X position on pattern plane
402
 
        {
403
 
            const int dw = (px + iw >= w) ? w - px : iw;
404
 
            const int dstX = px + xOffset;
405
 
 
406
 
            DoubleRect *const r = new DoubleRect();
407
 
            SDL_Rect &srcRect = r->src;
408
 
            srcRect.x = static_cast<int16_t>(srcX);
409
 
            srcRect.y = static_cast<int16_t>(srcY);
410
 
            srcRect.w = static_cast<uint16_t>(dw);
411
 
            srcRect.h = static_cast<uint16_t>(dh);
412
 
            SDL_Rect &dstRect = r->dst;
413
 
            dstRect.x = static_cast<int16_t>(dstX);
414
 
            dstRect.y = static_cast<int16_t>(dstY);
415
 
 
416
 
            if (SDL_FakeUpperBlit(image->mSDLSurface, &srcRect,
417
 
                mWindow, &dstRect) == 1)
418
 
            {
419
 
                vert->sdl.push_back(r);
420
 
            }
421
 
            else
422
 
            {
423
 
                delete r;
424
 
            }
425
 
        }
426
 
    }
427
 
}
428
 
 
429
 
void SDLGraphics::calcImagePattern(ImageCollection* const vertCol,
430
 
                                   const Image *const image,
431
 
                                   const int x, const int y,
432
 
                                   const int w, const int h) const
433
 
{
434
 
    ImageVertexes *vert = nullptr;
435
 
    if (vertCol->currentImage != image)
436
 
    {
437
 
        vert = new ImageVertexes();
438
 
        vertCol->currentImage = image;
439
 
        vertCol->currentVert = vert;
440
 
        vert->image = image;
441
 
        vertCol->draws.push_back(vert);
442
 
    }
443
 
    else
444
 
    {
445
 
        vert = vertCol->currentVert;
446
 
    }
447
 
 
448
 
    calcImagePattern(vert, image, x, y, w, h);
449
 
}
450
 
 
451
 
void SDLGraphics::calcTile(ImageVertexes *const vert,
452
 
                           const Image *const image,
453
 
                           int x, int y) const
454
 
{
455
 
    vert->image = image;
456
 
    calcTileSDL(vert, x, y);
457
 
}
458
 
 
459
 
void SDLGraphics::calcTileSDL(ImageVertexes *const vert, int x, int y) const
460
 
{
461
 
    // Check that preconditions for blitting are met.
462
 
    if (!vert || !vert->image || !vert->image->mSDLSurface)
463
 
        return;
464
 
 
465
 
    const Image *const image = vert->image;
466
 
    const gcn::ClipRectangle &top = mClipStack.top();
467
 
    const SDL_Rect &bounds = image->mBounds;
468
 
 
469
 
    DoubleRect *rect = new DoubleRect();
470
 
    rect->src.x = static_cast<int16_t>(bounds.x);
471
 
    rect->src.y = static_cast<int16_t>(bounds.y);
472
 
    rect->src.w = static_cast<uint16_t>(bounds.w);
473
 
    rect->src.h = static_cast<uint16_t>(bounds.h);
474
 
    rect->dst.x = static_cast<int16_t>(x + top.xOffset);
475
 
    rect->dst.y = static_cast<int16_t>(y + top.yOffset);
476
 
    if (SDL_FakeUpperBlit(image->mSDLSurface, &rect->src,
477
 
        mWindow, &rect->dst) == 1)
478
 
    {
479
 
        vert->sdl.push_back(rect);
480
 
    }
481
 
    else
482
 
    {
483
 
        delete rect;
484
 
    }
485
 
}
486
 
 
487
 
void SDLGraphics::calcTile(ImageCollection *const vertCol,
488
 
                           const Image *const image,
489
 
                           int x, int y)
490
 
{
491
 
    if (vertCol->currentImage != image)
492
 
    {
493
 
        ImageVertexes *const vert = new ImageVertexes();
494
 
        vertCol->currentImage = image;
495
 
        vertCol->currentVert = vert;
496
 
        vert->image = image;
497
 
        vertCol->draws.push_back(vert);
498
 
        calcTileSDL(vert, x, y);
499
 
    }
500
 
    else
501
 
    {
502
 
        calcTileSDL(vertCol->currentVert, x, y);
503
 
    }
504
 
}
505
 
 
506
 
void SDLGraphics::drawTile(const ImageCollection *const vertCol)
507
 
{
508
 
    const ImageVertexesVector &draws = vertCol->draws;
509
 
    const ImageCollectionCIter it_end = draws.end();
510
 
    for (ImageCollectionCIter it = draws.begin(); it != it_end; ++ it)
511
 
    {
512
 
        const ImageVertexes *const vert = *it;
513
 
        const Image *const img = vert->image;
514
 
        const DoubleRects *const rects = &vert->sdl;
515
 
        DoubleRects::const_iterator it2 = rects->begin();
516
 
        const DoubleRects::const_iterator it2_end = rects->end();
517
 
        while (it2 != it2_end)
518
 
        {
519
 
            SDL_LowerBlit(img->mSDLSurface, &(*it2)->src,
520
 
                mWindow, &(*it2)->dst);
521
 
            ++ it2;
522
 
        }
523
 
    }
524
 
}
525
 
 
526
 
void SDLGraphics::drawTile(const ImageVertexes *const vert)
527
 
{
528
 
    // vert and img must be != 0
529
 
    const Image *const img = vert->image;
530
 
    const DoubleRects *const rects = &vert->sdl;
531
 
    DoubleRects::const_iterator it = rects->begin();
532
 
    const DoubleRects::const_iterator it_end = rects->end();
533
 
    while (it != it_end)
534
 
    {
535
 
        SDL_LowerBlit(img->mSDLSurface, &(*it)->src, mWindow, &(*it)->dst);
536
 
        ++ it;
537
 
    }
538
 
}
539
 
 
540
 
void SDLGraphics::updateScreen()
541
 
{
542
 
    BLOCK_START("Graphics::updateScreen")
543
 
    if (mDoubleBuffer)
544
 
    {
545
 
        SDL_Flip(mWindow);
546
 
    }
547
 
    else
548
 
    {
549
 
        SDL_UpdateRects(mWindow, 1, &mRect);
550
 
//        SDL_UpdateRect(mWindow, 0, 0, 0, 0);
551
 
    }
552
 
    BLOCK_END("Graphics::updateScreen")
553
 
}
554
 
 
555
 
SDL_Surface *SDLGraphics::getScreenshot()
556
 
{
557
 
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
558
 
    const int rmask = 0xff000000;
559
 
    const int gmask = 0x00ff0000;
560
 
    const int bmask = 0x0000ff00;
561
 
#else
562
 
    const int rmask = 0x000000ff;
563
 
    const int gmask = 0x0000ff00;
564
 
    const int bmask = 0x00ff0000;
565
 
#endif
566
 
    const int amask = 0x00000000;
567
 
 
568
 
    SDL_Surface *const screenshot = MSDL_CreateRGBSurface(SDL_SWSURFACE,
569
 
        mRect.w, mRect.h, 24, rmask, gmask, bmask, amask);
570
 
 
571
 
    if (screenshot)
572
 
        SDL_BlitSurface(mWindow, nullptr, screenshot, nullptr);
573
 
 
574
 
    return screenshot;
575
 
}
576
 
 
577
 
bool SDLGraphics::drawNet(const int x1, const int y1,
578
 
                          const int x2, const int y2,
579
 
                          const int width, const int height)
580
 
{
581
 
    for (int y = y1; y < y2; y += height)
582
 
        drawLine(x1, y, x2, y);
583
 
 
584
 
    for (int x = x1; x < x2; x += width)
585
 
        drawLine(x, y1, x, y2);
586
 
 
587
 
    return true;
588
 
}
589
 
 
590
 
bool SDLGraphics::calcWindow(ImageCollection *const vertCol,
591
 
                             const int x, const int y,
592
 
                             const int w, const int h,
593
 
                             const ImageRect &imgRect)
594
 
{
595
 
    ImageVertexes *vert = nullptr;
596
 
    Image *const image = imgRect.grid[4];
597
 
    if (vertCol->currentImage != image)
598
 
    {
599
 
        vert = new ImageVertexes();
600
 
        vertCol->currentImage = image;
601
 
        vertCol->currentVert = vert;
602
 
        vert->image = image;
603
 
        vertCol->draws.push_back(vert);
604
 
    }
605
 
    else
606
 
    {
607
 
        vert = vertCol->currentVert;
608
 
    }
609
 
 
610
 
    const Image *const *const grid = &imgRect.grid[0];
611
 
    return calcImageRect(vert, x, y, w, h,
612
 
        grid[0], grid[2], grid[6], grid[8],
613
 
        grid[1], grid[5], grid[7], grid[3],
614
 
        grid[4]);
615
 
}
616
 
 
617
 
int SDLGraphics::SDL_FakeUpperBlit(const SDL_Surface *const src,
618
 
                                   SDL_Rect *const srcrect,
619
 
                                   const SDL_Surface *const dst,
620
 
                                   SDL_Rect *dstrect) const
621
 
{
622
 
    int srcx, srcy, w, h;
623
 
 
624
 
    // Make sure the surfaces aren't locked
625
 
    if (!src || !dst)
626
 
        return -1;
627
 
 
628
 
    if (!srcrect || !dstrect)
629
 
        return -1;
630
 
 
631
 
    srcx = srcrect->x;
632
 
    w = srcrect->w;
633
 
    if (srcx < 0)
634
 
    {
635
 
        w += srcx;
636
 
        dstrect->x -= static_cast<int16_t>(srcx);
637
 
        srcx = 0;
638
 
    }
639
 
    int maxw = src->w - srcx;
640
 
    if (maxw < w)
641
 
        w = maxw;
642
 
 
643
 
    srcy = srcrect->y;
644
 
    h = srcrect->h;
645
 
    if (srcy < 0)
646
 
    {
647
 
        h += srcy;
648
 
        dstrect->y -= static_cast<int16_t>(srcy);
649
 
        srcy = 0;
650
 
    }
651
 
    int maxh = src->h - srcy;
652
 
    if (maxh < h)
653
 
        h = maxh;
654
 
 
655
 
    const SDL_Rect *const clip = &dst->clip_rect;
656
 
    const int clipX = clip->x;
657
 
    const int clipY = clip->y;
658
 
    int dx = clipX - dstrect->x;
659
 
    if (dx > 0)
660
 
    {
661
 
        w -= dx;
662
 
        dstrect->x += static_cast<int16_t>(dx);
663
 
        srcx += dx;
664
 
    }
665
 
    dx = dstrect->x + w - clipX - clip->w;
666
 
    if (dx > 0)
667
 
        w -= dx;
668
 
 
669
 
    int dy = clipY - dstrect->y;
670
 
    if (dy > 0)
671
 
    {
672
 
        h -= dy;
673
 
        dstrect->y += static_cast<int16_t>(dy);
674
 
        srcy += dy;
675
 
    }
676
 
    dy = dstrect->y + h - clipY - clip->h;
677
 
    if (dy > 0)
678
 
        h -= dy;
679
 
 
680
 
    if (w > 0 && h > 0)
681
 
    {
682
 
        if (srcrect)
683
 
        {
684
 
            srcrect->x = static_cast<int16_t>(srcx);
685
 
            srcrect->y = static_cast<int16_t>(srcy);
686
 
            srcrect->w = static_cast<int16_t>(w);
687
 
            srcrect->h = static_cast<int16_t>(h);
688
 
        }
689
 
        dstrect->w = static_cast<int16_t>(w);
690
 
        dstrect->h = static_cast<int16_t>(h);
691
 
 
692
 
        return 1;
693
 
//        return SDL_LowerBlit(src, &sr, dst, dstrect);
694
 
    }
695
 
    dstrect->w = dstrect->h = 0;
696
 
    return 0;
697
 
}
698
 
 
699
 
void SDLGraphics::fillRectangle(const gcn::Rectangle& rectangle)
700
 
{
701
 
    FUNC_BLOCK("Graphics::fillRectangle", 1)
702
 
    if (mClipStack.empty())
703
 
        return;
704
 
 
705
 
    const gcn::ClipRectangle& top = mClipStack.top();
706
 
 
707
 
    gcn::Rectangle area = rectangle;
708
 
    area.x += top.xOffset;
709
 
    area.y += top.yOffset;
710
 
 
711
 
    if (!area.isIntersecting(top))
712
 
        return;
713
 
 
714
 
    if (mAlpha)
715
 
    {
716
 
        const int x1 = area.x > top.x ? area.x : top.x;
717
 
        const int y1 = area.y > top.y ? area.y : top.y;
718
 
        const int x2 = area.x + area.width < top.x + top.width ?
719
 
            area.x + area.width : top.x + top.width;
720
 
        const int y2 = area.y + area.height < top.y + top.height ?
721
 
            area.y + area.height : top.y + top.height;
722
 
        int x, y;
723
 
 
724
 
        SDL_LockSurface(mWindow);
725
 
 
726
 
        const int bpp = mWindow->format->BytesPerPixel;
727
 
        const uint32_t pixel = SDL_MapRGB(mWindow->format,
728
 
            static_cast<uint8_t>(mColor.r), static_cast<uint8_t>(mColor.g),
729
 
            static_cast<uint8_t>(mColor.b));
730
 
 
731
 
        switch (bpp)
732
 
        {
733
 
            case 1:
734
 
                for (y = y1; y < y2; y++)
735
 
                {
736
 
                    uint8_t *const p = static_cast<uint8_t *>(mWindow->pixels)
737
 
                        + y * mWindow->pitch;
738
 
                    for (x = x1; x < x2; x++)
739
 
                        *(p + x) = static_cast<uint8_t>(pixel);
740
 
                }
741
 
                break;
742
 
            case 2:
743
 
                for (y = y1; y < y2; y++)
744
 
                {
745
 
                    uint8_t *const p0 = static_cast<uint8_t *>(mWindow->pixels)
746
 
                        + y * mWindow->pitch;
747
 
                    for (x = x1; x < x2; x++)
748
 
                    {
749
 
                        uint8_t *const p = p0 + x * 2;
750
 
                        *reinterpret_cast<uint16_t *>(p) = gcn::SDLAlpha16(
751
 
                            static_cast<uint16_t>(pixel),
752
 
                            *reinterpret_cast<uint16_t *>(p),
753
 
                            static_cast<uint8_t>(mColor.a), mWindow->format);
754
 
                    }
755
 
                }
756
 
                break;
757
 
            case 3:
758
 
            {
759
 
                const int ca = 255 - mColor.a;
760
 
                const int cr = mColor.r * mColor.a;
761
 
                const int cg = mColor.g * mColor.a;
762
 
                const int cb = mColor.b * mColor.a;
763
 
 
764
 
                for (y = y1; y < y2; y++)
765
 
                {
766
 
                    uint8_t *const p0 = static_cast<uint8_t *>(mWindow->pixels)
767
 
                        + y * mWindow->pitch;
768
 
                    for (x = x1; x < x2; x++)
769
 
                    {
770
 
                        uint8_t *const p = p0 + x * 3;
771
 
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
772
 
                        p[2] = static_cast<uint8_t>((p[2] * ca + cb) >> 8);
773
 
                        p[1] = static_cast<uint8_t>((p[1] * ca + cg) >> 8);
774
 
                        p[0] = static_cast<uint8_t>((p[0] * ca + cr) >> 8);
775
 
#else
776
 
                        p[0] = static_cast<uint8_t>((p[0] * ca + cb) >> 8);
777
 
                        p[1] = static_cast<uint8_t>((p[1] * ca + cg) >> 8);
778
 
                        p[2] = static_cast<uint8_t>((p[2] * ca + cr) >> 8);
779
 
#endif
780
 
                    }
781
 
                }
782
 
                break;
783
 
            }
784
 
            case 4:
785
 
            {
786
 
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
787
 
                const unsigned pb = (pixel & 0xff) * mColor.a;
788
 
                const unsigned pg = (pixel & 0xff00) * mColor.a;
789
 
                const unsigned pr = (pixel & 0xff0000) * mColor.a;
790
 
                const unsigned a1 = (255 - mColor.a);
791
 
 
792
 
                for (y = y1; y < y2; y++)
793
 
                {
794
 
                    uint8_t *const p0 = static_cast<uint8_t *>(mWindow->pixels)
795
 
                        + y * mWindow->pitch;
796
 
                    for (x = x1; x < x2; x++)
797
 
                    {
798
 
                        uint8_t *p = p0 + x * 4;
799
 
                        uint32_t dst = *reinterpret_cast<uint32_t *>(p);
800
 
                        const unsigned int b = (pb + (dst & 0xff) * a1) >> 8;
801
 
                        const unsigned int g = (pg + (dst & 0xff00) * a1) >> 8;
802
 
                        const unsigned int r = (pr
803
 
                            + (dst & 0xff0000) * a1) >> 8;
804
 
 
805
 
                        *reinterpret_cast<uint32_t *>(p) = ((b & 0xff)
806
 
                            | (g & 0xff00) | (r & 0xff0000));
807
 
                    }
808
 
                }
809
 
#else
810
 
                if (!cR)
811
 
                {
812
 
                    cR = new unsigned int[0x100];
813
 
                    cG = new unsigned int[0x100];
814
 
                    cB = new unsigned int[0x100];
815
 
                    mOldPixel = 0;
816
 
                    mOldAlpha = mColor.a;
817
 
                }
818
 
 
819
 
                const SDL_PixelFormat * const format = mWindow->format;
820
 
                const unsigned rMask = format->Rmask;
821
 
                const unsigned gMask = format->Gmask;
822
 
                const unsigned bMask = format->Bmask;
823
 
//                const unsigned aMask = format->Amask;
824
 
                unsigned rShift = rMask / 0xff;
825
 
                unsigned gShift = gMask / 0xff;
826
 
                unsigned bShift = bMask / 0xff;
827
 
                if (!rShift)
828
 
                    rShift = 1;
829
 
                if (!gShift)
830
 
                    gShift = 1;
831
 
                if (!bShift)
832
 
                    bShift = 1;
833
 
                if (pixel != mOldPixel || mColor.a != mOldAlpha)
834
 
                {
835
 
                    const unsigned pb = (pixel & bMask) * mColor.a;
836
 
                    const unsigned pg = (pixel & gMask) * mColor.a;
837
 
                    const unsigned pr = (pixel & rMask) * mColor.a;
838
 
                    const unsigned a0 = (255 - mColor.a);
839
 
 
840
 
                    const unsigned int a1 = a0 * bShift;
841
 
                    const unsigned int a2 = a0 * gShift;
842
 
                    const unsigned int a3 = a0 * rShift;
843
 
 
844
 
                    for (int f = 0; f <= 0xff; f ++)
845
 
                    {
846
 
                        cB[f] = ((pb + f * a1) >> 8) & bMask;
847
 
                        cG[f] = ((pg + f * a2) >> 8) & gMask;
848
 
                        cR[f] = ((pr + f * a3) >> 8) & rMask;
849
 
                    }
850
 
 
851
 
                    mOldPixel = pixel;
852
 
                    mOldAlpha = mColor.a;
853
 
                }
854
 
 
855
 
                for (y = y1; y < y2; y++)
856
 
                {
857
 
                    uint32_t *const p0 = reinterpret_cast<uint32_t*>(
858
 
                        static_cast<uint8_t*>(mWindow->pixels)
859
 
                        + y * mWindow->pitch);
860
 
                    for (x = x1; x < x2; x++)
861
 
                    {
862
 
                        uint32_t *const p = p0 + x;
863
 
                        const uint32_t dst = *p;
864
 
                        *p = cB[dst & bMask / bShift]
865
 
                            | cG[(dst & gMask) / gShift]
866
 
                            | cR[(dst & rMask) / rShift];
867
 
                    }
868
 
                }
869
 
#endif
870
 
                break;
871
 
            }
872
 
            default:
873
 
                break;
874
 
        }
875
 
 
876
 
        SDL_UnlockSurface(mWindow);
877
 
    }
878
 
    else
879
 
    {
880
 
        SDL_Rect rect =
881
 
        {
882
 
            static_cast<int16_t>(area.x),
883
 
            static_cast<int16_t>(area.y),
884
 
            static_cast<uint16_t>(area.width),
885
 
            static_cast<uint16_t>(area.height)
886
 
        };
887
 
 
888
 
        const uint32_t color = SDL_MapRGBA(mWindow->format,
889
 
            static_cast<int8_t>(mColor.r),
890
 
            static_cast<int8_t>(mColor.g),
891
 
            static_cast<int8_t>(mColor.b),
892
 
            static_cast<int8_t>(mColor.a));
893
 
        SDL_FillRect(mWindow, &rect, color);
894
 
    }
895
 
}
896
 
 
897
 
void SDLGraphics::_beginDraw()
898
 
{
899
 
    pushClipArea(gcn::Rectangle(0, 0, mRect.w, mRect.h));
900
 
}
901
 
 
902
 
void SDLGraphics::_endDraw()
903
 
{
904
 
    popClipArea();
905
 
}
906
 
 
907
 
bool SDLGraphics::pushClipArea(gcn::Rectangle area)
908
 
{
909
 
    const bool result = gcn::Graphics::pushClipArea(area);
910
 
    const gcn::ClipRectangle &carea = mClipStack.top();
911
 
    const SDL_Rect rect =
912
 
    {
913
 
        static_cast<int16_t>(carea.x),
914
 
        static_cast<int16_t>(carea.y),
915
 
        static_cast<uint16_t>(carea.width),
916
 
        static_cast<uint16_t>(carea.height)
917
 
    };
918
 
    SDL_SetClipRect(mWindow, &rect);
919
 
 
920
 
    return result;
921
 
}
922
 
 
923
 
void SDLGraphics::popClipArea()
924
 
{
925
 
    gcn::Graphics::popClipArea();
926
 
 
927
 
    if (mClipStack.empty())
928
 
        return;
929
 
 
930
 
    const gcn::ClipRectangle &carea = mClipStack.top();
931
 
    const SDL_Rect rect =
932
 
    {
933
 
        static_cast<int16_t>(carea.x),
934
 
        static_cast<int16_t>(carea.y),
935
 
        static_cast<uint16_t>(carea.width),
936
 
        static_cast<uint16_t>(carea.height)
937
 
    };
938
 
 
939
 
    SDL_SetClipRect(mWindow, &rect);
940
 
}
941
 
 
942
 
void SDLGraphics::drawPoint(int x, int y)
943
 
{
944
 
    if (mClipStack.empty())
945
 
        return;
946
 
 
947
 
    const gcn::ClipRectangle& top = mClipStack.top();
948
 
 
949
 
    x += top.xOffset;
950
 
    y += top.yOffset;
951
 
 
952
 
    if (!top.isPointInRect(x, y))
953
 
        return;
954
 
 
955
 
    if (mAlpha)
956
 
        SDLputPixelAlpha(mWindow, x, y, mColor);
957
 
    else
958
 
        SDLputPixel(mWindow, x, y, mColor);
959
 
}
960
 
 
961
 
void SDLGraphics::drawHLine(int x1, int y, int x2)
962
 
{
963
 
    if (mClipStack.empty())
964
 
        return;
965
 
 
966
 
    const gcn::ClipRectangle& top = mClipStack.top();
967
 
 
968
 
    const int xOffset = top.xOffset;
969
 
    x1 += xOffset;
970
 
    y += top.yOffset;
971
 
    x2 += xOffset;
972
 
 
973
 
    const int topY = top.y;
974
 
    if (y < topY || y >= topY + top.height)
975
 
        return;
976
 
 
977
 
    if (x1 > x2)
978
 
    {
979
 
        x1 ^= x2;
980
 
        x2 ^= x1;
981
 
        x1 ^= x2;
982
 
    }
983
 
 
984
 
    const int topX = top.x;
985
 
    if (topX > x1)
986
 
    {
987
 
        if (topX > x2)
988
 
            return;
989
 
 
990
 
        x1 = topX;
991
 
    }
992
 
 
993
 
    const int sumX = topX + top.width;
994
 
    if (sumX <= x2)
995
 
    {
996
 
        if (sumX <= x1)
997
 
            return;
998
 
 
999
 
        x2 = sumX -1;
1000
 
    }
1001
 
 
1002
 
    const int bpp = mWindow->format->BytesPerPixel;
1003
 
 
1004
 
    SDL_LockSurface(mWindow);
1005
 
 
1006
 
    uint8_t *p = static_cast<uint8_t*>(mWindow->pixels)
1007
 
        + y * mWindow->pitch + x1 * bpp;
1008
 
 
1009
 
    const uint32_t pixel = SDL_MapRGB(mWindow->format,
1010
 
        static_cast<uint8_t>(mColor.r),
1011
 
        static_cast<uint8_t>(mColor.g),
1012
 
        static_cast<uint8_t>(mColor.b));
1013
 
    switch (bpp)
1014
 
    {
1015
 
        case 1:
1016
 
            for (; x1 <= x2; ++x1)
1017
 
                *(p++) = static_cast<uint8_t>(pixel);
1018
 
            break;
1019
 
 
1020
 
        case 2:
1021
 
        {
1022
 
            uint16_t* q = reinterpret_cast<uint16_t*>(p);
1023
 
            for (; x1 <= x2; ++x1)
1024
 
                *(q++) = pixel;
1025
 
            break;
1026
 
        }
1027
 
 
1028
 
        case 3:
1029
 
        {
1030
 
            const uint8_t b0 = static_cast<uint8_t>((pixel >> 16) & 0xff);
1031
 
            const uint8_t b1 = static_cast<uint8_t>((pixel >> 8) & 0xff);
1032
 
            const uint8_t b2 = static_cast<uint8_t>(pixel & 0xff);
1033
 
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
1034
 
            for (; x1 <= x2; ++x1)
1035
 
            {
1036
 
                p[0] = b0;
1037
 
                p[1] = b1;
1038
 
                p[2] = b2;
1039
 
                p += 3;
1040
 
            }
1041
 
#else
1042
 
            for (; x1 <= x2; ++x1)
1043
 
            {
1044
 
                p[0] = b2;
1045
 
                p[1] = b1;
1046
 
                p[2] = b0;
1047
 
                p += 3;
1048
 
            }
1049
 
#endif
1050
 
            break;
1051
 
        }
1052
 
 
1053
 
        case 4:
1054
 
        {
1055
 
            uint32_t *q = reinterpret_cast<uint32_t*>(p);
1056
 
            if (mAlpha)
1057
 
            {
1058
 
                unsigned char a = static_cast<unsigned char>(mColor.a);
1059
 
                unsigned char a1 = 255 - a;
1060
 
                const int b0 = (pixel & 0xff) * a;
1061
 
                const int g0 = (pixel & 0xff00) * a;
1062
 
                const int r0 = (pixel & 0xff0000) * a;
1063
 
                for (; x1 <= x2; ++x1)
1064
 
                {
1065
 
                    const unsigned int b = (b0 + (*q & 0xff) * a1) >> 8;
1066
 
                    const unsigned int g = (g0 + (*q & 0xff00) * a1) >> 8;
1067
 
                    const unsigned int r = (r0 + (*q & 0xff0000) * a1) >> 8;
1068
 
                    *q = (b & 0xff) | (g & 0xff00) | (r & 0xff0000);
1069
 
 
1070
 
                    q++;
1071
 
                }
1072
 
            }
1073
 
            else
1074
 
            {
1075
 
                for (; x1 <= x2; ++x1)
1076
 
                    *(q++) = pixel;
1077
 
            }
1078
 
            break;
1079
 
        }
1080
 
        default:
1081
 
            break;
1082
 
    }  // end switch
1083
 
 
1084
 
    SDL_UnlockSurface(mWindow);
1085
 
}
1086
 
 
1087
 
void SDLGraphics::drawVLine(int x, int y1, int y2)
1088
 
{
1089
 
    if (mClipStack.empty())
1090
 
        return;
1091
 
 
1092
 
    const gcn::ClipRectangle& top = mClipStack.top();
1093
 
 
1094
 
    const int yOffset = top.yOffset;
1095
 
    x += top.xOffset;
1096
 
    y1 += yOffset;
1097
 
    y2 += yOffset;
1098
 
 
1099
 
    if (x < top.x || x >= top.x + top.width)
1100
 
        return;
1101
 
 
1102
 
    if (y1 > y2)
1103
 
    {
1104
 
        y1 ^= y2;
1105
 
        y2 ^= y1;
1106
 
        y1 ^= y2;
1107
 
    }
1108
 
 
1109
 
    if (top.y > y1)
1110
 
    {
1111
 
        if (top.y > y2)
1112
 
            return;
1113
 
 
1114
 
        y1 = top.y;
1115
 
    }
1116
 
 
1117
 
    const int sumY = top.y + top.height;
1118
 
    if (sumY <= y2)
1119
 
    {
1120
 
        if (sumY <= y1)
1121
 
            return;
1122
 
 
1123
 
        y2 = sumY - 1;
1124
 
    }
1125
 
 
1126
 
    const int bpp = mWindow->format->BytesPerPixel;
1127
 
 
1128
 
    SDL_LockSurface(mWindow);
1129
 
 
1130
 
    uint8_t *p = static_cast<uint8_t*>(mWindow->pixels)
1131
 
        + y1 * mWindow->pitch + x * bpp;
1132
 
 
1133
 
    const uint32_t pixel = SDL_MapRGB(mWindow->format,
1134
 
        static_cast<uint8_t>(mColor.r),
1135
 
        static_cast<uint8_t>(mColor.g),
1136
 
        static_cast<uint8_t>(mColor.b));
1137
 
 
1138
 
    const int pitch = mWindow->pitch;
1139
 
    switch (bpp)
1140
 
    {
1141
 
        case 1:
1142
 
            for (; y1 <= y2; ++y1)
1143
 
            {
1144
 
                *p = static_cast<uint8_t>(pixel);
1145
 
                p += pitch;
1146
 
            }
1147
 
            break;
1148
 
 
1149
 
        case 2:
1150
 
            for (; y1 <= y2; ++ y1)
1151
 
            {
1152
 
                *reinterpret_cast<uint16_t*>(p)
1153
 
                    = static_cast<uint16_t>(pixel);
1154
 
                p += pitch;
1155
 
            }
1156
 
            break;
1157
 
 
1158
 
        case 3:
1159
 
        {
1160
 
            const uint8_t b0 = static_cast<uint8_t>((pixel >> 16) & 0xff);
1161
 
            const uint8_t b1 = static_cast<uint8_t>((pixel >> 8) & 0xff);
1162
 
            const uint8_t b2 = static_cast<uint8_t>(pixel & 0xff);
1163
 
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
1164
 
            for (; y1 <= y2; ++y1)
1165
 
            {
1166
 
                p[0] = b0;
1167
 
                p[1] = b1;
1168
 
                p[2] = b2;
1169
 
                p += pitch;
1170
 
            }
1171
 
#else
1172
 
            for (; y1 <= y2; ++y1)
1173
 
            {
1174
 
                p[0] = b2;
1175
 
                p[1] = b1;
1176
 
                p[2] = b0;
1177
 
                p += pitch;
1178
 
            }
1179
 
#endif
1180
 
            break;
1181
 
        }
1182
 
 
1183
 
        case 4:
1184
 
        {
1185
 
            if (mAlpha)
1186
 
            {
1187
 
                unsigned char a = static_cast<unsigned char>(mColor.a);
1188
 
                unsigned char a1 = 255 - a;
1189
 
                const int b0 = (pixel & 0xff) * a;
1190
 
                const int g0 = (pixel & 0xff00) * a;
1191
 
                const int r0 = (pixel & 0xff0000) * a;
1192
 
                for (; y1 <= y2; ++y1)
1193
 
                {
1194
 
                    const unsigned int dst = *reinterpret_cast<uint32_t*>(p);
1195
 
                    const unsigned int b = (b0 + (dst & 0xff) * a1) >> 8;
1196
 
                    const unsigned int g = (g0 + (dst & 0xff00) * a1) >> 8;
1197
 
                    const unsigned int r = (r0 + (dst & 0xff0000) * a1) >> 8;
1198
 
                    *reinterpret_cast<uint32_t*>(p) =
1199
 
                        (b & 0xff) | (g & 0xff00) | (r & 0xff0000);
1200
 
 
1201
 
                    p += pitch;
1202
 
                }
1203
 
            }
1204
 
            else
1205
 
            {
1206
 
                for (; y1 <= y2; ++y1)
1207
 
                {
1208
 
                    *reinterpret_cast<uint32_t*>(p) = pixel;
1209
 
                    p += pitch;
1210
 
                }
1211
 
            }
1212
 
            break;
1213
 
        }
1214
 
 
1215
 
        default:
1216
 
            break;
1217
 
    }  // end switch
1218
 
 
1219
 
    SDL_UnlockSurface(mWindow);
1220
 
}
1221
 
 
1222
 
void SDLGraphics::drawRectangle(const gcn::Rectangle &rectangle)
1223
 
{
1224
 
    const int x1 = rectangle.x;
1225
 
    const int x2 = x1 + rectangle.width - 1;
1226
 
    const int y1 = rectangle.y;
1227
 
    const int y2 = y1 + rectangle.height - 1;
1228
 
 
1229
 
    drawHLine(x1, y1, x2);
1230
 
    drawHLine(x1, y2, x2);
1231
 
 
1232
 
    drawVLine(x1, y1, y2);
1233
 
    drawVLine(x2, y1, y2);
1234
 
}
1235
 
 
1236
 
void SDLGraphics::drawLine(int x1, int y1, int x2, int y2)
1237
 
{
1238
 
    if (x1 == x2)
1239
 
    {
1240
 
        drawVLine(x1, y1, y2);
1241
 
        return;
1242
 
    }
1243
 
    if (y1 == y2)
1244
 
    {
1245
 
        drawHLine(x1, y1, x2);
1246
 
        return;
1247
 
    }
1248
 
 
1249
 
    //  other cases not implimented
1250
 
}
1251
 
 
1252
 
bool SDLGraphics::setVideoMode(const int w, const int h, const int bpp,
1253
 
                               const bool fs, const bool hwaccel,
1254
 
                               const bool resize, const bool noFrame)
1255
 
{
1256
 
    setMainFlags(w, h, bpp, fs, hwaccel, resize, noFrame);
1257
 
 
1258
 
    if (!(mWindow = graphicsManager.createWindow(w, h, bpp,
1259
 
        getSoftwareFlags())))
1260
 
    {
1261
 
        mRect.w = 0;
1262
 
        mRect.h = 0;
1263
 
        return false;
1264
 
    }
1265
 
 
1266
 
    mRect.w = static_cast<uint16_t>(mWindow->w);
1267
 
    mRect.h = static_cast<uint16_t>(mWindow->h);
1268
 
 
1269
 
    return videoInfo();
1270
 
}
1271
 
 
1272
 
#endif  // USE_SDL2