PSP Hacks - Forums
Go Back   PSP Hacks - Forums > PSP Community > PSP Programming & Development

Notices

Reply
 
Thread Tools Display Modes
  #1  
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
  #2  
Old 06-29-2008, 06:25 AM
Brick Brick is offline
Programmer
PSP Smarty
 
Join Date: Mar 2008
Posts: 145
Brick User Has a Beginner Reputation
Default

This will do exactly the same :P

Code:
SPRITE    fillImage,bgImage; (size: 1x10)



max battery life = 100
min batterry life = 0

for ( int i =min batterry life ; i<=max battery life; i++)
	{
		//battery bar background
		drawSprite(bgImage,head_x_point + (i* sprite width),head_y_point);
                //actual percentage
		drawSprite(fillImage,( head_x_point +( (i%getBatteryLife)*sprite width) ) ,head_y_point);
	}
Another option :
Instead of 2 sprites , use a stretched quad or something.
Apply some nice filters , and voila!...
Reply With Quote
  #3  
Old 06-29-2008, 12:40 PM
foebea foebea is offline
Programmer
PSP Hacks Member
 
Join Date: Mar 2007
Posts: 281
foebea User Has a Beginner Reputation
Default

Quote:
Originally Posted by Brick
This will do exactly the same :P
I guess it still applies as well as from my perl days, TIMTOWTDI. There's more than one way to do it.

The reason I made it as I did is that I am learning the manual drawing functions of the psp so I can add them to an interface design program, half flash-like half illustrator-like. Im working on pixel based drawing stuff. The battery bar was the last thing I did under graphics.c and the first thing I did under OSLib to learn how to get simple lines to draw. It gained me important lessons sucha as transparent lines overtop one another change the gradient. It never did that in graphics.c (no transparancy) and it is useful to know when desining functions for makiing images.

Also, with line drawn items it would be much easier to add custmization of width or height or colors without any distortion. if a user would want it to display less bars stretched to fill the screen instead of removing them as they get empty, they could just add another variable to the x locations. with an image, the edge pixels would be made very wide quickly.
__________________
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
  #4  
Old 06-29-2008, 02:08 PM
pirata nervo pirata nervo is offline
Programmer
PSP Titan
 
Join Date: Mar 2007
Location: www.consoleworld.net
Posts: 4,931
pirata nervo User Has a Beginner Reputation
Default

what do you mean by manual functions of the psp ? o.O
__________________

Upgrade your PSP Slim or FAT now!
NervOS Official Forum
Reply With Quote
  #5  
Old 06-29-2008, 02:57 PM
Brick Brick is offline
Programmer
PSP Smarty
 
Join Date: Mar 2008
Posts: 145
Brick User Has a Beginner Reputation
Default

@foebea:
What im trying to say (with the code snippet) , is , that there's no reason to write all this bad looking code for something so simple.


@pirata:
He probably means GU.
Reply With Quote
  #6  
Old 06-29-2008, 03:02 PM
foebea foebea is offline
Programmer
PSP Hacks Member
 
Join Date: Mar 2007
Posts: 281
foebea User Has a Beginner Reputation
Default

sorry, my language use is not always clear. By manual i just meant direct coordinate location, by of the psp is just because that is what i am writing for.

developing variable routines to plot pixel by pixel to create objects like circles, stars, split wheels, arcs polygons, rounded rectangles, gradients, layer pathng, tweening and morphing etc. Once I have my math and loops sorted out, they should be independant of any graphics library so I can reuse them in any way needed.
__________________
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
  #7  
Old 06-29-2008, 03:08 PM
pirata nervo pirata nervo is offline
Programmer
PSP Titan
 
Join Date: Mar 2007
Location: www.consoleworld.net
Posts: 4,931
pirata nervo User Has a Beginner Reputation
Default

oh ok, I thought you meant GU but wanted to make sure
__________________

Upgrade your PSP Slim or FAT now!
NervOS Official Forum
Reply With Quote
  #8  
Old 06-29-2008, 03:09 PM
foebea foebea is offline
Programmer
PSP Hacks Member
 
Join Date: Mar 2007
Posts: 281
foebea User Has a Beginner Reputation
Default

Quote:
Originally Posted by Brick
bad looking code
Hence my work is available at www.poorlywritten.com :mrgreen:

I'm trying to learn to code by tearing apart existing source and via trial and error. It will very likely remain bad looking if that is what it is as I write it so it is easy for me to follow and understand instead of by following a best practices guide.
__________________
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
  #9  
Old 06-29-2008, 03:18 PM
pirata nervo pirata nervo is offline
Programmer
PSP Titan
 
Join Date: Mar 2007
Location: www.consoleworld.net
Posts: 4,931
pirata nervo User Has a Beginner Reputation
Default

trial and error is the best way to learn in my opinion.
__________________

Upgrade your PSP Slim or FAT now!
NervOS Official Forum
Reply With Quote
  #10  
Old 06-29-2008, 03:32 PM
pspjoke's Avatar
pspjoke pspjoke is offline
Programmer
PSP Hacker
 
Join Date: Mar 2008
Location: U.S.
Posts: 804
pspjoke User Has a Beginner Reputation
Default

thats how im doing it. :twothumbs:
__________________
PHAT(TA-086) & GOW Slim(TA-088v2) - firmware: 5.00M33-3 - addons: 1.50 addon(phat). Me: newbie programmer...
Levone == pspjoke;
releases
ignorance is forgivable.. stupidity is a sin i can never forgive.
Reply With Quote
Reply

 



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 11:34 AM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©