PSP Hacks

#1 Spot for PSP Hacks



Home | PSP News | PSP Hacks | PSP Saves | PSP Downloads | PSP Backgrounds | PSP Hacks Live Chat | Free PSP | Contact Us


You are not logged in.

Announcement

#1  2008-06-29 03:48:27

foebea
Homebrew Comp '07 Winner
Registered: 2007-03-20
Posts: 282

PoorlyWritten BatteryBar, source for graphics.c and oslib

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.

                                        http://www.poorlywritten.com/piki/images/c/c0/Batt-n-prog.jpg

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/index … _New_Shard

Long live the one complete orbit or cycle!

Offline

 

#2  2008-06-29 05:25:49

Brick
Programmer
Registered: 2008-03-26
Posts: 138

Re: PoorlyWritten BatteryBar, source for graphics.c and oslib

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!...

Last edited by Brick (2008-06-29 09:00:02)

Offline

 

#3  2008-06-29 11:40:37

foebea
Homebrew Comp '07 Winner
Registered: 2007-03-20
Posts: 282

Re: PoorlyWritten BatteryBar, source for graphics.c and oslib

Brick wrote:

This will do exactly the same tongue

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.

Last edited by foebea (2008-06-29 12:02:45)


RosettaShard v.8.7 Download: www.psp-hacks.com/file/1114
RosettaShard Status: http://www.poorlywritten.com/piki/index … _New_Shard

Long live the one complete orbit or cycle!

Offline

 

#4  2008-06-29 13:08:56

pirata nervo
Programmer
From: www.consoleworld.net
Registered: 2007-03-13
Posts: 4834
Website

Re: PoorlyWritten BatteryBar, source for graphics.c and oslib

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


http://forums.consoleworld.net/logos/sig.png
Upgrade your PSP Slim or FAT now!
NervOS Official Forum

Offline

 

#5  2008-06-29 13:57:46

Brick
Programmer
Registered: 2008-03-26
Posts: 138

Re: PoorlyWritten BatteryBar, source for graphics.c and oslib

@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.

Offline

 

#6  2008-06-29 14:02:39

foebea
Homebrew Comp '07 Winner
Registered: 2007-03-20
Posts: 282

Re: PoorlyWritten BatteryBar, source for graphics.c and oslib

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/index … _New_Shard

Long live the one complete orbit or cycle!

Offline

 

#7  2008-06-29 14:08:19

pirata nervo
Programmer
From: www.consoleworld.net
Registered: 2007-03-13
Posts: 4834
Website

Re: PoorlyWritten BatteryBar, source for graphics.c and oslib

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


http://forums.consoleworld.net/logos/sig.png
Upgrade your PSP Slim or FAT now!
NervOS Official Forum

Offline

 

#8  2008-06-29 14:09:52

foebea
Homebrew Comp '07 Winner
Registered: 2007-03-20
Posts: 282

Re: PoorlyWritten BatteryBar, source for graphics.c and oslib

Brick wrote:

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.

Last edited by foebea (2008-06-29 14:10:26)


RosettaShard v.8.7 Download: www.psp-hacks.com/file/1114
RosettaShard Status: http://www.poorlywritten.com/piki/index … _New_Shard

Long live the one complete orbit or cycle!

Offline

 

#9  2008-06-29 14:18:56

pirata nervo
Programmer
From: www.consoleworld.net
Registered: 2007-03-13
Posts: 4834
Website

Re: PoorlyWritten BatteryBar, source for graphics.c and oslib

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


http://forums.consoleworld.net/logos/sig.png
Upgrade your PSP Slim or FAT now!
NervOS Official Forum

Offline

 

#10  2008-06-29 14:32:18

pspjoke
PSP User
From: Somewhere
Registered: 2008-03-22
Posts: 598

Re: PoorlyWritten BatteryBar, source for graphics.c and oslib

thats how im doing it. twothumbs


dot dot dot dot dot dot dot dot dot dot dot dot dot dot dot dot dot dot dot dot dot dot dot dot dot...

Type: PHAT.(TA-086) - firmware: 4.01(5)M33-2 - addons: 371 mem stick driver and 1.50 addon. Me: newbie programmer sigh...  Levone == pspjoke;

Offline

 
Home | PSP News | PSP Hacks | PSP Saves | PSP Downloads | PSP Backgrounds | PSP Hacks Live Chat | Free PSP | Contact Us



Board footer

Powered by PunBB
© Copyright 2002–2008 PunBB