Jens Arnold | feb5b15 | 2008-01-04 23:42:38 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * New greyscale framework |
| 11 | * Parameter handling |
| 12 | * |
| 13 | * This is a generic framework to display 129 shades of grey on low-depth |
| 14 | * bitmap LCDs (Archos b&w, Iriver & Ipod 4-grey) within plugins. |
| 15 | * |
| 16 | * Copyright (C) 2008 Jens Arnold |
| 17 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 18 | * This program is free software; you can redistribute it and/or |
| 19 | * modify it under the terms of the GNU General Public License |
| 20 | * as published by the Free Software Foundation; either version 2 |
| 21 | * of the License, or (at your option) any later version. |
Jens Arnold | feb5b15 | 2008-01-04 23:42:38 +0000 | [diff] [blame] | 22 | * |
| 23 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 24 | * KIND, either express or implied. |
| 25 | * |
| 26 | ****************************************************************************/ |
| 27 | |
| 28 | #include "plugin.h" |
| 29 | #include "grey.h" |
| 30 | |
| 31 | /* Set position of the top left corner of the greyscale overlay |
| 32 | Note that depending on the target LCD, either x or y gets rounded |
| 33 | to the nearest multiple of 4 or 8 */ |
| 34 | void grey_set_position(int x, int y) |
| 35 | { |
| 36 | #if LCD_PIXELFORMAT == HORIZONTAL_PACKING |
| 37 | _grey_info.bx = (x + 4) >> 3; |
| 38 | x = 8 * _grey_info.bx; |
Jens Arnold | 40919d7 | 2008-03-25 23:21:36 +0000 | [diff] [blame] | 39 | #else /* vertical packing or vertical interleaved */ |
| 40 | #if (LCD_DEPTH == 1) || (LCD_PIXELFORMAT == VERTICAL_INTERLEAVED) |
Jens Arnold | feb5b15 | 2008-01-04 23:42:38 +0000 | [diff] [blame] | 41 | _grey_info.by = (y + 4) >> 3; |
| 42 | y = 8 * _grey_info.by; |
| 43 | #elif LCD_DEPTH == 2 |
| 44 | _grey_info.by = (y + 2) >> 2; |
| 45 | y = 4 * _grey_info.by; |
| 46 | #endif |
| 47 | #endif /* LCD_PIXELFORMAT */ |
| 48 | _grey_info.x = x; |
| 49 | _grey_info.y = y; |
| 50 | |
| 51 | if (_grey_info.flags & _GREY_RUNNING) |
| 52 | { |
| 53 | #ifdef SIMULATOR |
Jens Arnold | fa7eb56 | 2008-01-13 18:39:09 +0000 | [diff] [blame] | 54 | _grey_info.rb->sim_lcd_ex_update_rect(_grey_info.x, _grey_info.y, |
| 55 | _grey_info.width, |
| 56 | _grey_info.height); |
Jens Arnold | feb5b15 | 2008-01-04 23:42:38 +0000 | [diff] [blame] | 57 | grey_deferred_lcd_update(); |
Jens Arnold | feb5b15 | 2008-01-04 23:42:38 +0000 | [diff] [blame] | 58 | #else |
| 59 | _grey_info.flags |= _GREY_DEFERRED_UPDATE; |
| 60 | #endif |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | /* Set the draw mode for subsequent drawing operations */ |
| 65 | void grey_set_drawmode(int mode) |
| 66 | { |
| 67 | _grey_info.drawmode = mode & (DRMODE_SOLID|DRMODE_INVERSEVID); |
| 68 | } |
| 69 | |
| 70 | /* Return the current draw mode */ |
| 71 | int grey_get_drawmode(void) |
| 72 | { |
| 73 | return _grey_info.drawmode; |
| 74 | } |
| 75 | |
| 76 | /* Set the foreground shade for subsequent drawing operations */ |
| 77 | void grey_set_foreground(unsigned brightness) |
| 78 | { |
Jens Arnold | feb5b15 | 2008-01-04 23:42:38 +0000 | [diff] [blame] | 79 | _grey_info.fg_brightness = brightness; |
| 80 | } |
| 81 | |
| 82 | /* Return the current foreground shade */ |
| 83 | unsigned grey_get_foreground(void) |
| 84 | { |
| 85 | return _grey_info.fg_brightness; |
| 86 | } |
| 87 | |
| 88 | /* Set the background shade for subsequent drawing operations */ |
| 89 | void grey_set_background(unsigned brightness) |
| 90 | { |
Jens Arnold | feb5b15 | 2008-01-04 23:42:38 +0000 | [diff] [blame] | 91 | _grey_info.bg_brightness = brightness; |
| 92 | } |
| 93 | |
| 94 | /* Return the current background shade */ |
| 95 | unsigned grey_get_background(void) |
| 96 | { |
| 97 | return _grey_info.bg_brightness; |
| 98 | } |
| 99 | |
| 100 | /* Set draw mode, foreground and background shades at once */ |
| 101 | void grey_set_drawinfo(int mode, unsigned fg_brightness, unsigned bg_brightness) |
| 102 | { |
| 103 | grey_set_drawmode(mode); |
| 104 | grey_set_foreground(fg_brightness); |
| 105 | grey_set_background(bg_brightness); |
| 106 | } |
| 107 | |
| 108 | /* Set font for the text output routines */ |
| 109 | void grey_setfont(int newfont) |
| 110 | { |
| 111 | _grey_info.curfont = newfont; |
| 112 | } |
| 113 | |
| 114 | /* Get width and height of a text when printed with the current font */ |
| 115 | int grey_getstringsize(const unsigned char *str, int *w, int *h) |
| 116 | { |
Jens Arnold | a72499a | 2008-01-13 00:11:43 +0000 | [diff] [blame] | 117 | return _grey_info.rb->font_getstringsize(str, w, h, _grey_info.curfont); |
Jens Arnold | feb5b15 | 2008-01-04 23:42:38 +0000 | [diff] [blame] | 118 | } |