View Single Post
 
Old 06-29-2008, 04:48 AM
foebea foebea is offline
Programmer
PSP Hacks Member
 
Join Date: Mar 2007
Posts: 281
foebea User Has a Beginner Reputation
Default

I worked this up yesterday and am really very pleased with how it came out, so thought I would share it with you here. The design is based.. stolen from? Hmm... no. Based on an old program I used for the Pocket PC about 5 years ago which did essentially the same thing. I plan on making it into a prx someday which could be used in xmb and over any other program as well, if I ever figure out how that is supposed to work. Future enhancements to this could include arguments by which colorschemes and opacity could be set, and low and critical percentage warnings could be introduced such as if only 5% is left (2 bars) then the other 38 bars could be made visible as flashing red bars.

The top 2 pixel rows of the image hold the battery bar in white and black at about 60% opacity. Each block of the battery bar represents 2.5% of a full charge. The bar updates a variable with the current charge within the function which displays it, so the entire code can be left in .c and .h files and called from within whatever program you want to use it with.



I have made the source with graphics.c first, and then commented out those specific bits and then coded it for OSLib. In order to change it to graphics.c just comment out all the sections which start with a comment saying OSLib Version, and then uncomment the sections that start with a comment saying Graphics.c version.

The graphics.c version does not do opacity.

Here is the source:

Code:
//Graphics.c version
//#include "graphics.h"
//#include "framebuffer.h"

//OSLib Version
#include <oslib/oslib.h>


#define RGB(r,v,b)              ((r) | ((v)<<8) | ((b)<<16) | (0xff<<24))

void drawBar(int xloc, int xsiz, int yloc, int ysiz, int color1, int color2, int color3){
    /*Graphics.c version*/
    //fillScreenRect(RGB(color1, color2, color3),xloc, yloc, xsiz, ysiz);
    
    /*OSLib Version, the 150 at the end is the Alpha amount for opacity*/
    oslDrawLine(xloc, yloc, xsiz, ysiz, RGBA(color1, color2, color3, 150));
}
void showBatteryBar(){
    float barLife = 0;
    if (scePowerIsBatteryExist()) barLife = scePowerGetBatteryLifePercent();
    
    int xLoc = 0;
    int yLoc = 0;
    float barCount = 0;
    
    /*Uncomment the below line to draw the bar for 100%*/
    //barLife = 100;
    
    while(barCount < barLife){
        barCount+=2.5;
        /*OSLib version uses 4 coordinates describing the corners of the line like a box.
        If both x's and y's are equal, like x,x,y,y 3,3,6,6 then nothing shows up on screen.
        I do not know why. If you use x,x,y,y, 3,40,6,6 it will draw a line from x3,y6 to x40,y6*/
        drawBar(xLoc,xLoc+10,yLoc,yLoc,255,255,255);
        drawBar(xLoc,xLoc+10,yLoc+1,yLoc+1,0,0,0);
        drawBar(xLoc,xLoc,yLoc,yLoc+2,255,255,255);
        drawBar(xLoc+10,xLoc+10,yLoc,yLoc+2,0,0,0);
        
        /*Graphics.c version uses x,y to show startpoint and endpoint of the line*/
        /*drawBar(xLoc,yLoc,10,1,250,250,250);
        drawBar(xLoc,yLoc+1,1,1,250,250,250);
        drawBar(xLoc+10,yLoc,1,1,100,100,100);
        drawBar(xLoc+1,yLoc+1,10,1,100,100,100);*/
        
        xLoc+=12;
    }
}
Thoughts?
__________________
RosettaShard v.8.7 Download: www.psp-hacks.com/file/1114
RosettaShard Status: http://www.poorlywritten.com/piki/in...=The_New_Shard

Long live the one complete orbit or cycle!
Reply With Quote