For cursor movement, how do you prevent the cursor from moving off of the screen?
Printable View
For cursor movement, how do you prevent the cursor from moving off of the screen?
cx = cursorx
cy = cursory
if (cx<0){
cx=0;
}
if (cx>480){
cx=480;
}
if(cy<0){
cy=0;
}
if(cy>272){
cy=272;
}
also neither of those ideas worked
slice - The PSPs screen:
xaxis = 0-479
yaxis = 0-271
Plus, if you have an image as your cursor (or some type of graphic, which im sure you do) youd need to have it so the entire cursor cant go off screen, so you might have subtract your cursor image's width/height when checking if greater than 271/479.
ok maybe it's not the xloader because i created a new object just as a test and i can't get that to appear so i'll have to work on that now and once i get that to appear it might solve my prob
-= Double Post =-
@sg57 i was just giving him a quick example also i had believed it was 480 by 272 now i know
The code slice gave me earlier worked as well. But it only worked for the tip of the cursor. In other words, the cursor didn't go off screen when you were trying to go left or up (if not both). It did go off screen when i went right or down. Also, SG57, could you give me an example, or the code for it? I am still a bit confused.
he was just saying that your image is placed at the top right so when it's at 480 cx then the whole image is offsceen same with the bottom so just do:
cx = cursorx
cy = cursory
if (cx<0){
cx=0;
}
if (cx>480-cusors_image_width){
cx=480;
}
if(cy<0){
cy=0;
}
if(cy>272-_cursor_image_height){
cy=272;
}
my best description of why:
the image is drawn from the dot leftward and downward
edit: also my prob may have been solved it is now displaying something
-= Double Post =-
nvm again i guess it was my test object
-= Double Post =-
ok well i'm ganna post my latest code build:
Spoiler for code:
well thats my current build and i still can't figure out my prob
-= Double Post =-
well i figured out that if i move my xloader function out of a function and just include it directly in the main loop it actually loads and displays my object but if i do that it'll be pretty hard on loading multiply objects i just thought i should tell any1 who wants to help me
-= Double Post =-
arg i figured out my prob but i'm unsure of how to fix it and keep this a function:
Spoiler for xloader:
you may notice that my function is an Object function
in my main.cpp file i make an object:
Object test_object
in my function i return the Object return_name thinking that if i called the xloader file like so:
loadxfile(test_object,"te st.x");
and it well return all the info to the test_object but i've discovered it doesn't but for some reason if i change my loadxfile function so the info is saved directly to my test_object Object then it well display my x file(which is a cube) yet this of course means i can only load 1 object so i need a way to return all the info in the function back to where the function is called
hope i got across what my prob is i'll work at it and hope i can fix it but i need some help here
-= Double Post =-
alright i figured it out my thinking was wrong i should have test_object = loadxfile("test.x") and had to change the function slightly now it's working all be with some bugs still but i'm working on that (yea!!)
The PSP screen is 480x272.Zitat:
Zitat von SG57
The dimensions, as in pixels, yes. But they range from 0 to 479 on the x axis, and 0 - 272 on the y axis. Draw something at 480,0 | 0,272 | 480,272 and tell me if you see any part of them. Im sure you misunderstood what i was saying.
Xylem - As slice4ever kind of pointed out (a bit wrong, downward left?) it goes off screen to the right and down because all images are drawn from the top,left of them down. Meaning:
It draws from the top left of the image ( the + in my ASCII drawing there) downward and to the right.Code:+-----|
|_____|
To prevent your entire cursor from going off screen, youd do as slice said, have the boundaries take the cursor width/height into consideration:
Now, if you have a fairly large cursor, youll find this a bit of a problem. Notice on your current OS (or web browser if your on PSP) that when you move it all the way to the right, it goes off. Could you imagine if it stopped it? Youd never be able to reach the scroll bar to scroll up and down a page had your cursor been big enough. A simple fix for this, is to either allow the cursor to move all the way, or just allow it part way off. And a way to do this is to lower the number you checking boundaries for. (change the above 479 to say 470 to show 9 more pixels of the cursor image)Code:if cursor.x + cursor.image:width() >= 479 then cursor.x = 479-cursor.image:width() end
if cursor.y + cursor.image:height() >= 271 then cursor.y = 271-cursor.image:height() end
Hey guys i wonder if you can help. I've been working on my code and need to know how to open a text file permanently so that it is viewable by the user. Then he can close it whenever he wants. I tried using this
FILE *ELVES_ptr;
ELVES_ptr = fopen("ELVES.txt", "r")
But the program just seemed to ignore that.
I don't really understand what you want. But the file stays open as long as you don't close it (using fclose()).Zitat:
Zitat von eldiablov
If you just want the user to be able to see the content of it you could just copy the content in the file into memory. (using fread())
ok thanks waterbottle. But i was saying when i used that above command it didnt do anything. The program just ignored it.
What do you mean by that it ignored it? Are you not able to read from the file after opening it?Zitat:
Zitat von eldiablov
Are you expecting the psp to automatically print the content to the screen when you open the file?
Something like this should work for printing it.
Code:FILE *ELVES_ptr;
int size;
char *buffer = NULL;
ELVES_ptr = fopen("ELVES.txt", "r")
fseek( ELVES_ptr, 0, SEEK_END );
size = ftell( ELVES_ptr );
rewind( ELVES_ptr );
buffer = (char*) malloc( size ); // allocate enough memory to store the file's content
fread( buffer, size, 1, ELVES_ptr );// copy the file content into buffer
fclose( ELVES_ptr );
printf( buffer );// Print what is in buffer (and also in the file)
arg...yet again i need to ask some help:
Spoiler for x loader code:
now then it loads the model and colors it yet if your loading in a cube the backside is weird it doesn't make a square
i'll try to draw it in ASCII:
|------|
|_____|
|........|
|------|
the line in the middle is a flat triangle facing inward and i'm unsure as 2 y i've made this same thing for my comp(just reads out stuff) and i don't see where the prob is
Waterbottle, it's not for the psp and you misunderstand me. I want to open the file so the user can see it in a seperate window.
XArt OpenSoft
Tetris++ Source Code
This is the basic source code for Tetris in C++
I am no longer using XArt Software, it now be XArt OpenSoft as all software that i do will be Open Source
Guys, i have a question. I finally got the wav support working on my config menu. However, there is a problem. I did "WAV_Init();", in my main loop. If you press R, it takes you to "int configuration". Now, once you are done with int configuration, it takes you back to the main loop. However, it freezes then. This is obviously because if it tries to go back to the main loop twice, wav is initialized again. How do i prevent the "WAV_Init();" if you go to the main loop twice?
Try calling your main loop from another function that dose the init, so it will not get called twise.
It shouldn't go inside the loop. It should look something like this.Zitat:
Zitat von superbatxs
Code:int main()
WAV_Init();
for(;;) {
//stuff
}
}
is what I would personaly used instead ofCode:int done=0;
while (!done)
{
}
, so you can easly exit your program and return to the PSP XMBCode:for(;;)
call another fuction like ApplicationMain() from main after your main() has done all the init stuff
I thought of that. However, if i did put the wav init in the int configuration, i would be calling the wav init more than once also because every time i press R in the main loop, it would take me to the configuration. For example, if my wav init was in my configuration, and i would be starting out with my main loop, and i would press R to go to the configuration, and after i was finished with the configuration, it would return to the menu. Now, what if i pressed R again? It would init the wav again, causing it to freeze. My point is, i call my main loop from the configuration, and call my configuration from my main loop (back and forth). If i put it in either one of those, it would eventually do init wav the second time. :PC:Zitat:
Zitat von xart
Edit:
Hm.......after initing it eh........ok, i am going to try that. Sounds good. Yea.....so if i init everything i need to at first, and do applicationmain(); or all the rest of the stuff in my main loop, it just might work......thanks.Zitat:
Zitat von xart
Super - Your code design should never have to call the 'main' function, so if you really need a one time initializing of anything, set it right after the int main() {
Thanks for the advice SG. It's funny that as soon as i looked at your post, i had already done what you just said before i looked at it. But it works!Zitat:
Zitat von SG57
I'm having a problem displaying time on my background. Here is the code:
Then i used "blitAlphaImageToScreen(0 , 0 , 480, 272, background, 0, 0);", and then "printTextScreen(200, 200, CurrentTime, Black);" to print my background. Yes, did declare "Color Black = RGB(0, 0, 255);", and i also loaded my background with the variable background. Obviously, i also did this:Code:char *CurrentTime() {
char timeText[8];
pspTime rtime;
sceRtcGetCurrentClockLocalTime(&rtime);
snprintf(timeText, 8, "%i : %i" , rtime.hour , rtime.minutes);
return timeText;
}
sceDisplayWaitVblankStart ();
flipScreen();
The background does blit successfully, but the text displays in a scrambled way (unreadable, but wierd text does display). Thanks.
Xylem - Post your exact code. The code you put in quotes is wrong...
printTextScreen(200,200,CurrentTime,black);
You need to make sure it's a function by adding () to the end of it:
printTextScreen(200,200,CurrentTime(),black);
Do i need to put theZitat:
Zitat von SG57
char *CurrentTime() {
char timeText[8];
pspTime rtime;
sceRtcGetCurrentClockLoca lTime(&rtime);
snprintf(timeText, 8, "%i : %i" , rtime.hour , rtime.minutes);
return timeText;
}
outside the main loop and before it?
IF i coulse see your code, I could answer your question. But yes, you need to either:
Code:char *CurrentTime() {
char timeText[8];
pspTime rtime;
sceRtcGetCurrentClockLoca lTime(&rtime);
snprintf(timeText, 8, "%i : %i" , rtime.hour , rtime.minutes);
return timeText;
}
int main() {
// main loop
}
OR
char *CurrentTime();
int main() {
// main loop
}
char *CurrentTime() {
char timeText[8];
pspTime rtime;
sceRtcGetCurrentClockLoca lTime(&rtime);
snprintf(timeText, 8, "%i : %i" , rtime.hour , rtime.minutes);
return timeText;
}
If i tell you, you will probably be disappointed like Yaustar was. Ok, i don't know anyone nice enough to give me his source so i can learn C (by looking at examples) than SuperbatXS. Yaustar said that he was disappointed because SuperbatXS' code isn't a good source to look at if i needed examples, but SuperbatXS is really nice. Anyways, here is SuperbatXS' code of G-Pack v.3 (i really hope he doesn't mind). I slightly edited it so that i could add time (although SuperbatXS already added a clock with hours and minutes, he removed it by my request). Here is his code, slightly edited by me to add a clock (he gave it to me about two hours ago, and said he was still working on it; he also said for me to look at the help thread if i needed help, and he said he went there for help quite often, so i go here!):
Spoiler for SuperbatXS' G-Pack v.3 Code:
---No way i should quote that----^
Wow, if you weren't a good friend, i would be really really angry right now. But it's ok, the source code right now isn't much anyways. I should also tell you this: my menu system is horrible right now. I am trying to work on a different one that should make the G-Pack almost 2/3 of what it is right now. I learned this menu code from psp-programming, but their's isn't that amazing now that i realize it. Sg and Yaustar told me a good method. Btw, i am glad you didn't ask me Xylem and posted it here. Even i don't understand my clock function. If anyone posts the clock function for Xylem, could you explain it also so that i can learn it and not just use it?
If you mean this:
Its simple if you read through it.Code:char *CurrentTime() {
char timeText[8];
pspTime rtime;
sceRtcGetCurrentClockLocalTime(&rtime);
snprintf(timeText, 8, "%i : %i" , rtime.hour , rtime.minutes);
return timeText;
}
Code:char timeText[8]; // storage for our hour,seconds string
pspTime rtime; // pspTime is a structure, containing 2 members (prob more, like time zones) named 'minute' and 'hour'
sceRtcGetCurrentClockLocalTime(&rtime); // feed the current 'minute' and 'hour' values into our rtime structure's members named 'minute' and 'hour'
// place the hours and minutes into the timeText string, the 8 in there means
// it limits the amount of characters to feed into timeText, this prevents a buffer overflow
// if the time string would somehow exceed 8 cahracters (it shouldnt)
snprintf(timeText, 8, "%i : %i" , rtime.hour , rtime.minutes);
return timeText; // return our time string
So what was wrong with my main.c? How do i fix the text from being scrambled?Zitat:
Zitat von SG57
That code looks wrong. timeText is declared local to CurrentTime(), on the stack, so you shouldn't return it because after CurrentTime() returns, the 8 bytes you allocated for timeText are freed and can be filled with other data. At least, I think that's the problem. I can't see what else could be wrong...Code:char *CurrentTime() {
char timeText[8];
pspTime rtime;
sceRtcGetCurrentClockLocalTime(&rtime);
snprintf(timeText, 8, "%i : %i" , rtime.hour , rtime.minutes);
return timeText;
}
Yeah, that sounds right. What is being returned is a pointer to memory on the stack that is popped when the function ends. (GCC should have a warning about this?).Zitat:
Zitat von coolguy5678
This should be better.Code:void CurrentTime( char * timeText) {
pspTime rtime;
sceRtcGetCurrentClockLocalTime(&rtime);
snprintf(timeText, 8, "%i : %i" , rtime.hour , rtime.minutes);
}
int main()
{
char aTime[16] = "";
CurrentTime( aTime );
return 0;
}
in the pspusb.h , i found this
but how do i use that adresse?Code:#define PSP_USB_CABLE_CONNECTED 0x020
If you would have read farther for five more seconds, you would have seen this.Zitat:
Zitat von hallo007
Use that, and if it returns 0x020, then the USB is connected.Code:/**
* Get USB state
*
* @return OR'd PSP_USB_* constants
*/
int sceUsbGetState(void);
Actually, I think you're meant to bitwise-AND the result with PSP_USB_CABLE_CONNECTED.Zitat:
Zitat von Access_Denied
I haven't got the header file with me, but the "@return" comment suggests that there might be other PSP_USB_* constants that are true at the same time (similar to control checking).
Code:if (sceUsbGetState() & PSP_USB_CABLE_CONNECTED) {...}
When you ever see macros giving values were only one bit is set, you can bet you are supose to use & with it.
one good way to know for sure is to look at any other macros for the USB and see if they all have only one bit set, that is a big givaway.
so this
if (sceUsbGetState() & PSP_USB_CABLE_CONNECTED) {...}
will be the same as
if (sceUsbGetState() == PSP_USB_CABLE_CONNECTED) {...}
No.Zitat:
Zitat von hallo007
If you look in the pspusb.h file you see there are three defines for USB states
#define PSP_USB_ACTIVATED 0x200
#define PSP_USB_CABLE_CONNECTED 0x020
#define PSP_USB_CONNECTION_ESTABL ISHED 0x002
if (sceUsbGetState() & PSP_USB_CABLE_CONNECTED)
means if the usb cable is connected, ignoring whether the other 2 options are set.
But if (sceUsbGetState() == PSP_USB_CABLE_CONNECTED)
means if the usb cable is connected and usb isn't activated and no usb connection is established.
Explination of the bitwise operators.
thnx waterbottle , this explains much to me
-= Double Post =-
some problem with the makefile
line 37:Code:Makefile:37: *** missing separator (did you mean TAB instead of 8 spaces?). Stop
rUsb.o is the end of the objectsCode:ad-hoc/stubs.o \
rUsb.o
-= Double Post =-
the same error with my libs
Code:LIBS = -lpsprtc \
-lpspwlan \
-lstdc++ \
-lpsputility \
-lpsppower \
-lpspgu \
-lpng \
-lz \
-lm \
-lmad \
-lpspaudiolib \
-lpspaudio \
-lpspusb \
-lpspusbstor
Read the error...Zitat:
Zitat von hallo007
Makefile:37: *** missing separator (did you mean TAB instead of 8 spaces?).
replace the spaces with TAB
Code:ad-hoc/stubs.o \
rUsb.o