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

« back to all changes in this revision

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