|
Rockbox mail archiveSubject: uisimulator: battery displayuisimulator: battery display
From: The Phoenix <rhak_at_ramapo.edu>
Date: Tue, 02 Apr 2002 03:11:46 -0500 (EST) Hey all, I was playing with the uisimulator and wanted to get used to the graphic api we are playing with, so I hacked out a quick battery display. It is as close as I can get it to the one that I see on my recorder. I didnt want to post it into the CVS until we decide that 1. we need it and 2. where it should go. If you could take a look and comment I would appreciate it. /Rob /* I hacked this function to be placed inside uibasic.c because I wasn't sure where else to place it. Arguements are fairly straight forward. int color: the rest of the api seemed to use color, so I follow suit. int xbaseline: location of "bottom" of battery on screen int ybaseline: location of "left" edge of battery on screen int length: how long is the battery to be (in pixels) int width: how tall is the battery to be (in pixels) int percent: what percentage of the charge has been used Note: I am making use of the Logf() function until logging is straightened out. */ void draw_battery(int color, int xbaseline, int ybaseline, int length, int width, int percent) { float capacity = 0; int bar_xoffset = 2; int bar_yoffset = 2; int bar_len = 0; int bar_wid = width - (bar_xoffset*2); int i = 0; /* We only worry about length and width because if you place the battery off the screen, its your own damn fault. We log and then just draw an empty battery */ if((percent > 100) || (percent < 0) || (length < 0) || (width < 0)) { Logf("Error: Battery data invalid"); percent = 0; } /* top batt. edge */ drawline(color, xbaseline, ybaseline, xbaseline+length-2, ybaseline); /* bot batt. edge */ drawline(color, xbaseline, ybaseline+width, xbaseline+length-2, ybaseline+width); /* left batt. edge */ drawline(color, xbaseline, ybaseline, xbaseline, ybaseline+width); /* right batt. edge */ drawline(color, xbaseline+length, ybaseline+1, xbaseline+length, ybaseline+width-1); /* 2 dots that account for the nub on the right side of the battery */ drawdot(color, xbaseline+length-1, ybaseline+1); drawdot(color, xbaseline+length-1, ybaseline+width-1); if(percent > 0) { /* % battery is full, 100% is length-bar_xoffset-1 pixels */ capacity = ((float)percent / 100.0) * (length-(bar_xoffset*2)-1); bar_len = capacity; for(i = 0; i < bar_wid+1; i++) { drawline(color, xbaseline+bar_xoffset, ybaseline+bar_yoffset+i, xbaseline+bar_xoffset+bar_len, ybaseline+bar_yoffset+i); } } } ===+===+===+===+===+===+===+===+===+===+===+=== "If you find it in your heart to care for somebody else, you will have succeeded." - Maya Angelou
Page template was last modified "Tue Sep 7 00:00:02 2021" The Rockbox Crew -- Privacy Policy |