/*************************************************************************** * __________ __ ___. * Open \______ \ ____ ____ | | _\_ |__ _______ ___ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ * $Id: dice.c,v 1.1 2004/01/08 19:23:46 alex Exp $ * * Copyright (C) 2004 Alex Pleiner * * 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 "plugin.h" #ifdef HAVE_LCD_BITMAP static struct plugin_api* rb; int x=1, y=1; unsigned char icon[] = {0x60, 0x7f, 0x03, 0x33, 0x3f, 0x00}; static unsigned char pixel[] = {0xff, 0xff, 0xff, 0xff}; /* static unsigned char dice[][7] = { { 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00 }, { 0x00, 0x04, 0x00, 0x00, 0x00, 0x40, 0x00 }, { 0x00, 0x04, 0x00, 0x10, 0x00, 0x40, 0x00 }, { 0x00, 0x44, 0x00, 0x00, 0x00, 0x44, 0x00 }, { 0x00, 0x44, 0x00, 0x10, 0x00, 0x44, 0x00 }, { 0x00, 0x44, 0x00, 0x44, 0x00, 0x44, 0x00 }, }; */ /* void roll_dice (void) { int px,py; int bpl = DICE/8+1; int random; int c; int dx; rb->lcd_clear_display(); for (c=0; crand()%6; rb->lcd_fillrect(x+dx, y, size, size); rb->lcd_clearrect(x+dx+BORDER, y+BORDER, DICE*RADIUS, DICE*RADIUS); for (py=0; py>(7-(px%8))) &1) ) rb->lcd_bitmap((char *)eye, x+dx+BORDER+px*RADIUS, y+BORDER+py*RADIUS, RADIUS, RADIUS, false); } rb->lcd_update(); } */ #define LEFT 0x08 #define RIGHT 0x04 #define UP 0x02 #define DOWN 0x01 #define ICON_X 6 #define ICON_Y 8 #define PIXEL 4 #define BORDER 1 #define SIZE 6 /* PIXEL + 2 * BORDER */ #define PRE_X 40 #define PRE_Y 0 void paint_cursor(void) { int cx = 1+(x-1)*SIZE; int cy = 1+(y-1)*SIZE; int d = PIXEL+BORDER; rb->lcd_drawline(cx, cy, cx+d, cy); rb->lcd_drawline(cx+d, cy, cx+d, cy+d); rb->lcd_drawline(cx+d, cy+d, cx, cy+d); rb->lcd_drawline(cx, cy+d, cx, cy); rb->lcd_update_rect(cx, cy, d+1, d+1); } void delete_cursor(void) { int cx = 1+(x-1)*SIZE; int cy = 1+(y-1)*SIZE; int d = PIXEL+BORDER; rb->lcd_clearline(cx, cy, cx+d, cy); rb->lcd_clearline(cx+d, cy, cx+d, cy+d); rb->lcd_clearline(cx+d, cy+d, cx, cy+d); rb->lcd_clearline(cx, cy+d, cx, cy); rb->lcd_update_rect(cx, cy, d+1, d+1); } void paint_matrix (void) { int px,py; /* matrix */ rb->lcd_clearrect(1,1, SIZE*ICON_X,SIZE*ICON_Y); for (py=0; py>(py%8)) &1) ) rb->lcd_bitmap((char *)pixel, 1+BORDER+px*SIZE, 1+BORDER+py*SIZE, PIXEL, PIXEL, false); /* preview */ rb->lcd_clearrect(PRE_X, PRE_Y, ICON_X, ICON_Y); rb->lcd_bitmap((char *)icon, PRE_X, PRE_Y, ICON_X, ICON_Y, false); rb->lcd_update(); /* cursor again */ paint_cursor(); } void paint_frame (void) { /* char buffer[30]; int w, h; */ rb->lcd_clear_display(); rb->lcd_drawrect(0,0, 2*BORDER+SIZE*ICON_X,2*BORDER+SIZE*ICON_Y); rb->lcd_update(); /* other stuff to do */ /* rb->snprintf(buffer, sizeof(buffer), "%s", "Arrows: Move"); rb->lcd_getstringsize(buffer,&w,&h); rb->lcd_putsxy(10+SIZE*ICON_X, 0, buffer); rb->lcd_putsxy(10+SIZE*ICON_X, h, "Play: Toggle"); rb->lcd_putsxy(10+SIZE*ICON_X, 2*h, "F1: Help"); rb->lcd_putsxy(10+SIZE*ICON_X, 3*h, "F2: Save"); */ paint_matrix(); } void move (unsigned char dir) { delete_cursor(); x -= ( ((dir&LEFT )==LEFT ) ?1:0); x += ( ((dir&RIGHT)==RIGHT) ?1:0); y -= ( ((dir&UP )==UP ) ?1:0); y += ( ((dir&DOWN )==DOWN ) ?1:0); if (x > ICON_X) x = 1; if (x < 1) x = ICON_X; if (y > ICON_Y) y = 1; if (y < 1) y = ICON_Y; paint_cursor(); } enum plugin_status plugin_start(struct plugin_api* api, void* parameter) { TEST_PLUGIN_API(api); (void)parameter; rb = api; paint_frame(); while (1) { switch (rb->button_get(true)) { case BUTTON_OFF: return false; case SYS_USB_CONNECTED: rb->usb_screen(); return false; case BUTTON_F1: rb->lcd_clear_display(); rb->lcd_puts(0, 0, "help"); rb->lcd_update(); break; case BUTTON_DOWN: case BUTTON_DOWN | BUTTON_REPEAT: move(DOWN); break; case BUTTON_UP: case BUTTON_UP | BUTTON_REPEAT: move(UP); break; case BUTTON_LEFT: case BUTTON_LEFT | BUTTON_REPEAT: move(LEFT); break; case BUTTON_RIGHT: case BUTTON_RIGHT | BUTTON_REPEAT: move(RIGHT); break; case BUTTON_PLAY: case BUTTON_PLAY | BUTTON_REPEAT: /* toggle current pixel */ icon[x-1] ^= 1 << (y-1); paint_matrix(); break; } } return PLUGIN_OK; } #endif