blob: 1014a371c05a98c71e7ce1c5756e864e8f68af4a [file] [log] [blame]
Linus Nielsen Feltzingfc72c532006-02-03 15:19:58 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 Dan Everton
11 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
Linus Nielsen Feltzingfc72c532006-02-03 15:19:58 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
Dan Evertonb585e872006-02-09 21:49:28 +000022#include "lcd-sdl.h"
Linus Nielsen Feltzingfc72c532006-02-03 15:19:58 +000023#include "uisdl.h"
Linus Nielsen Feltzingfc72c532006-02-03 15:19:58 +000024
Dan Evertonb585e872006-02-09 21:49:28 +000025int display_zoom = 1;
Linus Nielsen Feltzingfc72c532006-02-03 15:19:58 +000026
Dan Evertonb585e872006-02-09 21:49:28 +000027void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width,
Jens Arnold6a972e02006-02-26 13:37:42 +000028 int height, int max_x, int max_y,
29 unsigned long (*getpixel)(int, int))
Linus Nielsen Feltzingfc72c532006-02-03 15:19:58 +000030{
31 int x, y;
32 int xmax, ymax;
Dan Evertonb585e872006-02-09 21:49:28 +000033 SDL_Rect dest;
Linus Nielsen Feltzingfc72c532006-02-03 15:19:58 +000034
35 ymax = y_start + height;
36 xmax = x_start + width;
37
Dan Evertonb585e872006-02-09 21:49:28 +000038 if(xmax > max_x)
39 xmax = max_x;
40 if(ymax >= max_y)
41 ymax = max_y;
Linus Nielsen Feltzingfc72c532006-02-03 15:19:58 +000042
Dan Evertonb585e872006-02-09 21:49:28 +000043 SDL_LockSurface(surface);
Linus Nielsen Feltzingfc72c532006-02-03 15:19:58 +000044
Dan Evertonb585e872006-02-09 21:49:28 +000045 dest.w = display_zoom;
46 dest.h = display_zoom;
47
48 for (x = x_start; x < xmax; x++) {
49 dest.x = x * display_zoom;
Linus Nielsen Feltzingfc72c532006-02-03 15:19:58 +000050
Dan Evertonb585e872006-02-09 21:49:28 +000051 for (y = y_start; y < ymax; y++) {
52 dest.y = y * display_zoom;
53
Jens Arnold6a972e02006-02-26 13:37:42 +000054 SDL_FillRect(surface, &dest, (Uint32)getpixel(x, y));
Linus Nielsen Feltzingfc72c532006-02-03 15:19:58 +000055 }
56 }
57
Dan Evertonb585e872006-02-09 21:49:28 +000058 SDL_UnlockSurface(surface);
Jens Arnold6a972e02006-02-26 13:37:42 +000059}
Linus Nielsen Feltzingfc72c532006-02-03 15:19:58 +000060
Jens Arnold6a972e02006-02-26 13:37:42 +000061void sdl_gui_update(SDL_Surface *surface, int x_start, int y_start, int width,
62 int height, int max_x, int max_y, int ui_x, int ui_y)
63{
64 int xmax, ymax;
65
66 ymax = y_start + height;
67 xmax = x_start + width;
68
69 if(xmax > max_x)
70 xmax = max_x;
71 if(ymax >= max_y)
72 ymax = max_y;
73
74 SDL_Rect src = {x_start * display_zoom, y_start * display_zoom,
75 xmax * display_zoom, ymax * display_zoom};
76 SDL_Rect dest= {(ui_x + x_start) * display_zoom, (ui_y + y_start) * display_zoom,
77 xmax * display_zoom, ymax * display_zoom};
78
Dan Evertonb585e872006-02-09 21:49:28 +000079 SDL_BlitSurface(surface, &src, gui_surface, &dest);
Linus Nielsen Feltzingfc72c532006-02-03 15:19:58 +000080 SDL_Flip(gui_surface);
Linus Nielsen Feltzingfc72c532006-02-03 15:19:58 +000081}
82
Linus Nielsen Feltzingfc72c532006-02-03 15:19:58 +000083/* set a range of bitmap indices to a gradient from startcolour to endcolour */
Jens Arnold6a972e02006-02-26 13:37:42 +000084void sdl_set_gradient(SDL_Surface *surface, SDL_Color *start, SDL_Color *end,
85 int first, int steps)
Linus Nielsen Feltzingfc72c532006-02-03 15:19:58 +000086{
87 int i;
Dan Evertonb585e872006-02-09 21:49:28 +000088 SDL_Color palette[steps];
Linus Nielsen Feltzingfc72c532006-02-03 15:19:58 +000089
Dan Evertonb585e872006-02-09 21:49:28 +000090 for (i = 0; i < steps; i++) {
Dan Everton7c646312006-02-16 18:55:36 +000091 palette[i].r = start->r + (end->r - start->r) * i / (steps - 1);
92 palette[i].g = start->g + (end->g - start->g) * i / (steps - 1);
93 palette[i].b = start->b + (end->b - start->b) * i / (steps - 1);
Linus Nielsen Feltzingfc72c532006-02-03 15:19:58 +000094 }
95
Jens Arnold6a972e02006-02-26 13:37:42 +000096 SDL_SetPalette(surface, SDL_LOGPAL|SDL_PHYSPAL, palette, first, steps);
Linus Nielsen Feltzingfc72c532006-02-03 15:19:58 +000097}
Linus Nielsen Feltzingfc72c532006-02-03 15:19:58 +000098