Linus Nielsen Feltzing | fc72c53 | 2006-02-03 15:19:58 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2006 Dan Everton |
| 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 12 | * 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 Feltzing | fc72c53 | 2006-02-03 15:19:58 +0000 | [diff] [blame] | 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
| 21 | |
Dan Everton | b585e87 | 2006-02-09 21:49:28 +0000 | [diff] [blame] | 22 | #include "lcd-sdl.h" |
Linus Nielsen Feltzing | fc72c53 | 2006-02-03 15:19:58 +0000 | [diff] [blame] | 23 | #include "uisdl.h" |
Linus Nielsen Feltzing | fc72c53 | 2006-02-03 15:19:58 +0000 | [diff] [blame] | 24 | |
Dan Everton | b585e87 | 2006-02-09 21:49:28 +0000 | [diff] [blame] | 25 | int display_zoom = 1; |
Linus Nielsen Feltzing | fc72c53 | 2006-02-03 15:19:58 +0000 | [diff] [blame] | 26 | |
Dan Everton | b585e87 | 2006-02-09 21:49:28 +0000 | [diff] [blame] | 27 | void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width, |
Jens Arnold | 6a972e0 | 2006-02-26 13:37:42 +0000 | [diff] [blame] | 28 | int height, int max_x, int max_y, |
| 29 | unsigned long (*getpixel)(int, int)) |
Linus Nielsen Feltzing | fc72c53 | 2006-02-03 15:19:58 +0000 | [diff] [blame] | 30 | { |
| 31 | int x, y; |
| 32 | int xmax, ymax; |
Dan Everton | b585e87 | 2006-02-09 21:49:28 +0000 | [diff] [blame] | 33 | SDL_Rect dest; |
Linus Nielsen Feltzing | fc72c53 | 2006-02-03 15:19:58 +0000 | [diff] [blame] | 34 | |
| 35 | ymax = y_start + height; |
| 36 | xmax = x_start + width; |
| 37 | |
Dan Everton | b585e87 | 2006-02-09 21:49:28 +0000 | [diff] [blame] | 38 | if(xmax > max_x) |
| 39 | xmax = max_x; |
| 40 | if(ymax >= max_y) |
| 41 | ymax = max_y; |
Linus Nielsen Feltzing | fc72c53 | 2006-02-03 15:19:58 +0000 | [diff] [blame] | 42 | |
Dan Everton | b585e87 | 2006-02-09 21:49:28 +0000 | [diff] [blame] | 43 | SDL_LockSurface(surface); |
Linus Nielsen Feltzing | fc72c53 | 2006-02-03 15:19:58 +0000 | [diff] [blame] | 44 | |
Dan Everton | b585e87 | 2006-02-09 21:49:28 +0000 | [diff] [blame] | 45 | 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 Feltzing | fc72c53 | 2006-02-03 15:19:58 +0000 | [diff] [blame] | 50 | |
Dan Everton | b585e87 | 2006-02-09 21:49:28 +0000 | [diff] [blame] | 51 | for (y = y_start; y < ymax; y++) { |
| 52 | dest.y = y * display_zoom; |
| 53 | |
Jens Arnold | 6a972e0 | 2006-02-26 13:37:42 +0000 | [diff] [blame] | 54 | SDL_FillRect(surface, &dest, (Uint32)getpixel(x, y)); |
Linus Nielsen Feltzing | fc72c53 | 2006-02-03 15:19:58 +0000 | [diff] [blame] | 55 | } |
| 56 | } |
| 57 | |
Dan Everton | b585e87 | 2006-02-09 21:49:28 +0000 | [diff] [blame] | 58 | SDL_UnlockSurface(surface); |
Jens Arnold | 6a972e0 | 2006-02-26 13:37:42 +0000 | [diff] [blame] | 59 | } |
Linus Nielsen Feltzing | fc72c53 | 2006-02-03 15:19:58 +0000 | [diff] [blame] | 60 | |
Jens Arnold | 6a972e0 | 2006-02-26 13:37:42 +0000 | [diff] [blame] | 61 | void 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 Everton | b585e87 | 2006-02-09 21:49:28 +0000 | [diff] [blame] | 79 | SDL_BlitSurface(surface, &src, gui_surface, &dest); |
Linus Nielsen Feltzing | fc72c53 | 2006-02-03 15:19:58 +0000 | [diff] [blame] | 80 | SDL_Flip(gui_surface); |
Linus Nielsen Feltzing | fc72c53 | 2006-02-03 15:19:58 +0000 | [diff] [blame] | 81 | } |
| 82 | |
Linus Nielsen Feltzing | fc72c53 | 2006-02-03 15:19:58 +0000 | [diff] [blame] | 83 | /* set a range of bitmap indices to a gradient from startcolour to endcolour */ |
Jens Arnold | 6a972e0 | 2006-02-26 13:37:42 +0000 | [diff] [blame] | 84 | void sdl_set_gradient(SDL_Surface *surface, SDL_Color *start, SDL_Color *end, |
| 85 | int first, int steps) |
Linus Nielsen Feltzing | fc72c53 | 2006-02-03 15:19:58 +0000 | [diff] [blame] | 86 | { |
| 87 | int i; |
Dan Everton | b585e87 | 2006-02-09 21:49:28 +0000 | [diff] [blame] | 88 | SDL_Color palette[steps]; |
Linus Nielsen Feltzing | fc72c53 | 2006-02-03 15:19:58 +0000 | [diff] [blame] | 89 | |
Dan Everton | b585e87 | 2006-02-09 21:49:28 +0000 | [diff] [blame] | 90 | for (i = 0; i < steps; i++) { |
Dan Everton | 7c64631 | 2006-02-16 18:55:36 +0000 | [diff] [blame] | 91 | 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 Feltzing | fc72c53 | 2006-02-03 15:19:58 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Jens Arnold | 6a972e0 | 2006-02-26 13:37:42 +0000 | [diff] [blame] | 96 | SDL_SetPalette(surface, SDL_LOGPAL|SDL_PHYSPAL, palette, first, steps); |
Linus Nielsen Feltzing | fc72c53 | 2006-02-03 15:19:58 +0000 | [diff] [blame] | 97 | } |
Linus Nielsen Feltzing | fc72c53 | 2006-02-03 15:19:58 +0000 | [diff] [blame] | 98 | |