![]() |
|
#1
|
|||
|
|||
|
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;
}
}
__________________
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! |
|
#2
|
|||
|
|||
|
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);
}
Instead of 2 sprites , use a stretched quad or something. Apply some nice filters , and voila!... |
|
#3
|
|||
|
|||
|
Quote:
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! |
|
#4
|
|||
|
|||
|
what do you mean by manual functions of the psp ? o.O
|
|
#5
|
|||
|
|||
|
@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. |
|
#6
|
|||
|
|||
|
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! |
|
#7
|
|||
|
|||
|
oh ok, I thought you meant GU but wanted to make sure
|
|
#8
|
|||
|
|||
|
Quote:
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! |
|
#9
|
|||
|
|||
|
trial and error is the best way to learn in my opinion.
|
|
#10
|
||||
|
||||
|
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. |
![]() |
|
|
|||
|
|||
|
|
| Thread Tools | |
| Display Modes | |
|
|