[CHG] GRRLIB_HotZone changed to GRRLIB_PtInRect

[NEW] GRRLIB_Exit to free the memory allocated by GRRLIB
This commit is contained in:
Crayon2000 2009-01-21 23:16:15 +00:00
parent 8aea904788
commit fda4c0c33b
4 changed files with 57 additions and 33 deletions

View file

@ -50,7 +50,9 @@ ChangeLog :
* InitVideo() and GRRLIB_Start() merge into GRRLIB_Init(). * InitVideo() and GRRLIB_Start() merge into GRRLIB_Init().
* add GRRLIB_HotZone that return True/False if the wpad is in a specific zone * add GRRLIB_PtInRect that return True/False if a point is in a specific zone
* add GRRLIB_Exit to free the memory allocated by GRRLIB
have a look at the sample code to see how all this work ;) have a look at the sample code to see how all this work ;)

View file

@ -29,10 +29,10 @@ inline void GRRLIB_FillScreen(u32 color) {
} }
/** /**
* * Draw a dot.
* @param x * @param x specifies the x-coordinate of the dot.
* @param y * @param y specifies the y-coordinate of the dot.
* @param color * @param color the color of the dot.
*/ */
inline void GRRLIB_Plot(f32 x, f32 y, u32 color) { inline void GRRLIB_Plot(f32 x, f32 y, u32 color) {
Vector v[] = {{x,y,0.0f}}; Vector v[] = {{x,y,0.0f}};
@ -66,12 +66,12 @@ inline void GRRLIB_Line(f32 x1, f32 y1, f32 x2, f32 y2, u32 color) {
/** /**
* Draw a rectangle. * Draw a rectangle.
* @param x * @param x specifies the x-coordinate of the upper-left corner of the rectangle.
* @param y * @param y specifies the y-coordinate of the upper-left corner of the rectangle.
* @param width * @param width the width of the rectangle.
* @param height * @param height the height of the rectangle.
* @param color * @param color the color of the rectangle.
* @param filled * @param filled true to fill the rectangle with a color.
*/ */
inline void GRRLIB_Rectangle(f32 x, f32 y, f32 width, f32 height, u32 color, u8 filled) { inline void GRRLIB_Rectangle(f32 x, f32 y, f32 width, f32 height, u32 color, u8 filled) {
f32 x2 = x+width; f32 x2 = x+width;
@ -257,7 +257,7 @@ GRRLIB_texImg GRRLIB_LoadTextureJPG(const unsigned char my_jpg[]) {
} }
/** /**
* * Draw a texture.
* @param xpos * @param xpos
* @param ypos * @param ypos
* @param tex * @param tex
@ -314,7 +314,7 @@ inline void GRRLIB_DrawImg(f32 xpos, f32 ypos, GRRLIB_texImg tex, float degrees,
} }
/** /**
* Draw a tile on the screen. * Draw a tile.
* @param xpos * @param xpos
* @param ypos * @param ypos
* @param tex * @param tex
@ -377,7 +377,7 @@ inline void GRRLIB_DrawTile(f32 xpos, f32 ypos, GRRLIB_texImg tex, float degrees
} }
/** /**
* Print formatted output to the screen. * Print formatted output.
* @param xpos * @param xpos
* @param ypos * @param ypos
* @param tex * @param tex
@ -401,23 +401,21 @@ void GRRLIB_Printf(f32 xpos, f32 ypos, GRRLIB_texImg tex, u32 color, f32 zoom, c
} }
/** /**
* Detect if the wiimote is in a zone * Determines whether the specified point lies within the specified rectangle.
* @param hotx * @param hotx specifies the x-coordinate of the upper-left corner of the rectangle.
* @param hoty * @param hoty specifies the y-coordinate of the upper-left corner of the rectangle.
* @param hotw * @param hotw the width of the rectangle.
* @param hoth * @param hoth the height of the rectangle.
* @param padx * @param wpadx specifies the x-coordinate of the point.
* @param pady * @param wpady specifies the y-coordinate of the point.
* @return true/false if you are in or out * @return If the specified point lies within the rectangle, the return value is true otherwise it's false.
*/ */
bool GRRLIB_HotZone(int hotx, int hoty, int hotw, int hoth, int wpadx, int wpady) { bool GRRLIB_PtInRect(int hotx, int hoty, int hotw, int hoth, int wpadx, int wpady) {
bool test=false; if(((wpadx>hotx) & (wpadx<(hotx+hotw))) & ((wpady>hoty) & (wpady<(hoty+hoth)))) {
return true;
if(((wpadx>hotx) & (wpadx<(hotx+hotw))) & ((wpady>hoty) & (wpady<(hoty+hoth)))){
test=true;
} }
return(test); return false;
} }
/** /**
@ -440,7 +438,7 @@ void GRRLIB_GXEngine(Vector v[], u32 color, long n, u8 fmt) {
/** /**
* Initialize GRRLIB. * Initialize GRRLIB.
*/ */
void GRRLIB_Init () { void GRRLIB_Init() {
f32 yscale; f32 yscale;
u32 xfbHeight; u32 xfbHeight;
Mtx44 perspective; Mtx44 perspective;
@ -528,7 +526,7 @@ void GRRLIB_Init () {
/** /**
* Call this function after drawing. * Call this function after drawing.
*/ */
void GRRLIB_Render () { void GRRLIB_Render() {
GX_DrawDone (); GX_DrawDone ();
fb ^= 1; // flip framebuffer fb ^= 1; // flip framebuffer
@ -539,3 +537,24 @@ void GRRLIB_Render () {
VIDEO_Flush(); VIDEO_Flush();
VIDEO_WaitVSync(); VIDEO_WaitVSync();
} }
/**
* Call this before exiting your application.
*/
void GRRLIB_Exit() {
GX_Flush();
GX_AbortFrame();
if(xfb[0] != NULL) {
free(MEM_K1_TO_K0(xfb[0]));
xfb[0] = NULL;
}
if(xfb[1] != NULL) {
free(MEM_K1_TO_K0(xfb[1]));
xfb[1] = NULL;
}
if(gp_fifo != NULL) {
free(gp_fifo);
gp_fifo = NULL;
}
}

View file

@ -58,14 +58,16 @@ inline void GRRLIB_DrawTile(f32 xpos, f32 ypos, GRRLIB_texImg tex, float degrees
void GRRLIB_Printf(f32 xpos, f32 ypos, GRRLIB_texImg tex, u32 color, f32 zoom, const char *text, ...); void GRRLIB_Printf(f32 xpos, f32 ypos, GRRLIB_texImg tex, u32 color, f32 zoom, const char *text, ...);
bool GRRLIB_HotZone(int hotx, int hoty, int hotw, int hoth, int wpadx, int wpady); bool GRRLIB_PtInRect(int hotx, int hoty, int hotw, int hoth, int wpadx, int wpady);
void GRRLIB_GXEngine(Vector v[], u32 color, long count, u8 fmt); void GRRLIB_GXEngine(Vector v[], u32 color, long count, u8 fmt);
void GRRLIB_Init (); void GRRLIB_Init();
void GRRLIB_Render (); void GRRLIB_Render();
void GRRLIB_Exit();
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -70,5 +70,6 @@ int main() {
if (wpadheld & WPAD_BUTTON_LEFT) left--; if (wpadheld & WPAD_BUTTON_LEFT) left--;
if (wpadheld & WPAD_BUTTON_RIGHT) left++; if (wpadheld & WPAD_BUTTON_RIGHT) left++;
} }
GRRLIB_Exit(); // Be a good boy, clear the memory allocated by GRRLIB
return 0; return 0;
} }