pmc/surface.cc
author Markus Bröker <mbroeker@largo.dyndns.tv>
Thu, 16 Apr 2009 12:49:12 +0200
changeset 53 6b3d7e3418c1
parent 46 4b9e1ac40246
child 54 c064ce9f40f5
permissions -rw-r--r--
getch.c renamed to cross_getch.c committer: Markus Bröker <mbroeker@largo.homelinux.org>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     1
/**
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     2
 * test/demos/pmc/surface.cc
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     3
 * Copyright (C) 2008 Markus Broeker
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     4
 */
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     5
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     6
#include <surface.h>
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     7
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     8
#define max(a,b) (((a) > (b)) ? (a) : (b))
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     9
#define min(a,b) (((a) < (b)) ? (a) : (b))
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    10
#define abs(a) (((a)<0) ? -(a) : (a))
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    11
#define sign(a) (((a)<0) ? -1 : (a)>0 ? 1 : 0)
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    12
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    13
Surface::Surface (int w, int h, int d)
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    14
{
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    15
    width = w;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    16
    height = h;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    17
    depth = d;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    18
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    19
    SDL_Init (SDL_INIT_VIDEO);
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    20
    screen = SDL_SetVideoMode (width, height, depth, SDL_HWSURFACE);
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    21
    red = SDL_MapRGB (screen->format, 0xff, 0x00, 0x00);
46
4b9e1ac40246 pmc: Screen Depth Fix: Paint on 8, 16 and 32 bpp
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 42
diff changeset
    22
    green = SDL_MapRGB (screen->format, 0x00, 0xff, 0x00);
4b9e1ac40246 pmc: Screen Depth Fix: Paint on 8, 16 and 32 bpp
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 42
diff changeset
    23
    blue = SDL_MapRGB (screen->format, 0x00, 0x00, 0xff);
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    24
    black = SDL_MapRGB (screen->format, 0x00, 0x00, 0x00);
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    25
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    26
    color = red;
46
4b9e1ac40246 pmc: Screen Depth Fix: Paint on 8, 16 and 32 bpp
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 42
diff changeset
    27
    bpp = screen->format->BytesPerPixel;
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    28
}
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    29
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    30
Surface::~Surface ()
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    31
{
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    32
    SDL_Quit ();
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    33
}
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    34
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    35
void Surface::drawPixel (int x, int y)
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    36
{
46
4b9e1ac40246 pmc: Screen Depth Fix: Paint on 8, 16 and 32 bpp
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 42
diff changeset
    37
    if (x < 0 || y < 0)
4b9e1ac40246 pmc: Screen Depth Fix: Paint on 8, 16 and 32 bpp
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 42
diff changeset
    38
        return;
4b9e1ac40246 pmc: Screen Depth Fix: Paint on 8, 16 and 32 bpp
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 42
diff changeset
    39
4b9e1ac40246 pmc: Screen Depth Fix: Paint on 8, 16 and 32 bpp
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 42
diff changeset
    40
    if (x > width || y > height)
4b9e1ac40246 pmc: Screen Depth Fix: Paint on 8, 16 and 32 bpp
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 42
diff changeset
    41
        return;
4b9e1ac40246 pmc: Screen Depth Fix: Paint on 8, 16 and 32 bpp
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 42
diff changeset
    42
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    43
    if (SDL_MUSTLOCK (screen)) {
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    44
        if (SDL_LockSurface (screen) < 0) {
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    45
            return;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    46
        }
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    47
    }
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    48
46
4b9e1ac40246 pmc: Screen Depth Fix: Paint on 8, 16 and 32 bpp
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 42
diff changeset
    49
    switch (bpp) {
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    50
    case 1:{                   /* vermutlich 8 Bit */
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    51
            Uint8 *bufp;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    52
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    53
            bufp = (Uint8 *) screen->pixels + y * screen->pitch + x;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    54
            *bufp = color;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    55
        }
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    56
        break;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    57
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    58
    case 2:{                   /* vermutlich 15 Bit oder 16 Bit */
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    59
            Uint16 *bufp;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    60
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    61
            bufp = (Uint16 *) screen->pixels + y * screen->pitch / 2 + x;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    62
            *bufp = color;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    63
        }
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    64
        break;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    65
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    66
    case 3:{                   /* langsamer 24-Bit-Modus, selten verwendet */
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    67
            Uint8 *bufp;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    68
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    69
            bufp = (Uint8 *) screen->pixels + y * screen->pitch + x * 3;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    70
            if (SDL_BYTEORDER == SDL_LIL_ENDIAN) {
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    71
                bufp[0] = color;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    72
                bufp[1] = color >> 8;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    73
                bufp[2] = color >> 16;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    74
            } else {
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    75
                bufp[2] = color;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    76
                bufp[1] = color >> 8;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    77
                bufp[0] = color >> 16;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    78
            }
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    79
        }
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    80
        break;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    81
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    82
    case 4:{                   /* vermutlich 32 Bit */
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    83
            Uint32 *bufp;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    84
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    85
            bufp = (Uint32 *) screen->pixels + y * screen->pitch / 4 + x;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    86
            *bufp = color;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    87
        }
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    88
        break;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    89
    }
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    90
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    91
    if (SDL_MUSTLOCK (screen)) {
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    92
        SDL_UnlockSurface (screen);
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    93
    }
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    94
}
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    95
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    96
void Surface::drawLine (int x1, int y1, int x2, int y2)
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    97
{
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    98
    int d;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    99
    int x;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   100
    int y;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   101
    int ax;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   102
    int ay;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   103
    int sx;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   104
    int sy;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   105
    int dx;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   106
    int dy;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   107
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   108
    dx = x2 - x1;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   109
    ax = abs (dx) << 1;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   110
    sx = sign (dx);
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   111
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   112
    dy = y2 - y1;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   113
    ay = abs (dy) << 1;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   114
    sy = sign (dy);
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   115
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   116
    x = x1;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   117
    y = y1;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   118
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   119
    if (ax > ay) {              /* x dominant */
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   120
        d = ay - (ax >> 1);
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   121
        for (;;) {
46
4b9e1ac40246 pmc: Screen Depth Fix: Paint on 8, 16 and 32 bpp
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 42
diff changeset
   122
            drawPixel (x, y);
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   123
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   124
            if (x == x2) {
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   125
                return;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   126
            }
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   127
            if (d >= 0) {
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   128
                y += sy;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   129
                d -= ax;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   130
            }
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   131
            x += sx;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   132
            d += ay;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   133
        }
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   134
    } else {                    /* y dominant */
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   135
        d = ax - (ay >> 1);
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   136
        for (;;) {
46
4b9e1ac40246 pmc: Screen Depth Fix: Paint on 8, 16 and 32 bpp
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 42
diff changeset
   137
            drawPixel (x, y);
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   138
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   139
            if (y == y2) {
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   140
                return;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   141
            }
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   142
            if (d >= 0) {
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   143
                x += sx;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   144
                d -= ay;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   145
            }
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   146
            y += sy;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   147
            d += ax;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   148
        }
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   149
    }
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   150
}
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   151
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   152
void Surface::flip ()
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   153
{
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   154
    SDL_Flip (screen);
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   155
}
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   156
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   157
void Surface::setColor (foregroundColor c)
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   158
{
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   159
    switch (c) {
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   160
    case BLACK:
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   161
        color = black;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   162
        break;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   163
    case RED:
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   164
        color = red;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   165
        break;
46
4b9e1ac40246 pmc: Screen Depth Fix: Paint on 8, 16 and 32 bpp
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 42
diff changeset
   166
    case GREEN:
4b9e1ac40246 pmc: Screen Depth Fix: Paint on 8, 16 and 32 bpp
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 42
diff changeset
   167
        color = green;
4b9e1ac40246 pmc: Screen Depth Fix: Paint on 8, 16 and 32 bpp
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 42
diff changeset
   168
        break;
4b9e1ac40246 pmc: Screen Depth Fix: Paint on 8, 16 and 32 bpp
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 42
diff changeset
   169
    case BLUE:
4b9e1ac40246 pmc: Screen Depth Fix: Paint on 8, 16 and 32 bpp
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 42
diff changeset
   170
        color = blue;
4b9e1ac40246 pmc: Screen Depth Fix: Paint on 8, 16 and 32 bpp
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 42
diff changeset
   171
        break;
4b9e1ac40246 pmc: Screen Depth Fix: Paint on 8, 16 and 32 bpp
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 42
diff changeset
   172
    default:
4b9e1ac40246 pmc: Screen Depth Fix: Paint on 8, 16 and 32 bpp
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 42
diff changeset
   173
        color = red;
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   174
    };
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   175
}