summaryrefslogtreecommitdiffstats
path: root/uisimulator/sdl/lcd-sdl.c
blob: 3327dd8350058fad8e9f5e52f480724fb65b89ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Copyright (C) 2006 Dan Everton
 *
 * All files in this archive are subject to the GNU General Public License.
 * See the file COPYING in the source tree root for full license agreement.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/

#include "lcd-sdl.h"
#include "uisdl.h"

int display_zoom = 1;

void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width,
    int height, int max_x, int max_y, int ui_x, int ui_y,
    Uint32 (*getpixel)(int, int))
{
    int x, y;
    int xmax, ymax;
    SDL_Rect dest;

    ymax = y_start + height;
    xmax = x_start + width;

    if(xmax > max_x)
        xmax = max_x;
    if(ymax >= max_y)
        ymax = max_y;

    SDL_LockSurface(surface);

    dest.w = display_zoom;
    dest.h = display_zoom;
    
    for (x = x_start; x < xmax; x++) {
        dest.x = x * display_zoom;

        for (y = y_start; y < ymax; y++) {
            dest.y = y * display_zoom;
            
            SDL_FillRect(surface, &dest, getpixel(x, y));
        }
    }

    SDL_UnlockSurface(surface);

    SDL_Rect src = {x_start * display_zoom, y_start * display_zoom, xmax * display_zoom, ymax * display_zoom};
    dest.x = (ui_x + x_start) * display_zoom;
    dest.y = (ui_y + y_start) * display_zoom;;
    dest.w = xmax * display_zoom;
    dest.h = ymax * display_zoom;
    
    SDL_BlitSurface(surface, &src, gui_surface, &dest);
    SDL_UpdateRect(gui_surface, dest.x, dest.y, dest.w, dest.h);
    SDL_Flip(gui_surface);
}

/* set a range of bitmap indices to a gradient from startcolour to endcolour */
void sdl_set_gradient(SDL_Surface *surface, SDL_Color *start, SDL_Color *end, int steps)
{
    int i;
    SDL_Color palette[steps];

    for (i = 0; i < steps; i++) {
        palette[i].r = start->r + (end->r - start->r) * i / (steps - 1);
        palette[i].g = start->g + (end->g - start->g) * i / (steps - 1);
        palette[i].b = start->b + (end->b - start->b) * i / (steps - 1);
    }

    SDL_SetPalette(surface, SDL_LOGPAL|SDL_PHYSPAL, palette, 0, steps);
}