// // G A M E.O.N.E - LOW LEVEL LIB V1.0 // Copyright (C) 2001 LEVEL ONE ENTERTAINMENT, // Licensed under the terms of LGPL. //:--------------------------------------------------------------------------- //:Description // // LOW LEVEL GFX DRIVER // //:----------------------------------------------------------------------------- #if !defined(LLGFX_INCLUDED) #define LLGFX_INCLUDED /* * Grafik ID. erzeugt durch CreateGfx und LoadGfx */ typedef int llgfx_id; // gfxindex #include "lib_base.h" #include "llgfx_ctexture.h" /* * LOAD FLAGS */ #define LLGFX_COLORKEY (0x01) // COLORKEY setzen #define LLGFX_CACHE (0x02) // Importfile cachen #define LLGFX_CENTERORIGIN (0x04) // Origin auf Texturemittelpunkt setzen /* * OPTIONEN FÜR SetFrameCount(); */ #define LLGFX_FRAME_COUNT (0x0) // Parameter ist Frameanzahl #define LLGFX_FRAME_HEIGHT (0x1) // Parameter ist Framehöhe (llgfx_SetFrameCount()) //:Include #include "llgfx_color.h" #include "llgfx_sscreen.h" #include "ll2d_rect.h" #include "llqueue.h" #include "llqueue_squeue.h" #include "llgfx_vd.h" #include "llgfx_smode.h" #include "llgfx_sfont.h" #include "llgfx_blit.h" /* * RUNTIME OPTIONEN */ extern bool llgfx_enable_singlebuffer; // Singlebuffer Modus explizit auch für Fullscreen modus setzen extern bool llgfx_enable_stretchwindow; // Wenn true, kann man im Fenstermodus das Window ziehen extern TxU32 llgfx_clearcolor; // Löschfarbe bei llgfx_ClearScreen() oder llgfx_ClearGfx() extern float llgfx_window_scale; // scale faktor beim anlegen eines nicht-fullscreen fensters extern bool llgfx_dirtyrect_enabled; // Wenn true, werden alle Änderungen in Form des rectangles gespeichert /* * RUNTIME GLOBALE */ extern int llgfx_displaywidth; // Breite des aktuellen Bildschirms extern int llgfx_displayheight; // Höhe des aktuellen Bildschirms extern int llgfx_bitspixel; // Pixel des aktuellen Bildschirms extern int llgfx_pixsize; // Anzahl Bytes pro Pixel des aktuellen Bildschirms extern int llgfx_refreshrate; // Refreschrate des aktuellen Bildschirms extern int llgfx_frame_counter; // zählt die anzahl der llgfx_FlipScreen() Aufrufe extern bool llgfx_fullscreen; // True bei Vollschirmmodus extern s_surface llgfx_sGfxBuffer; // Bei jedem lock vom Backbuffer ist diese Struktur gültig extern queue llgfx_displaymodes;// Liste der unterstützten Displaymodes extern int llgfx_displaychanged; // Erhöht sich bei jedem Bildschirmmodus Wechsel. z.B. Vollschirm<->Fenster extern squeue llgfx_dirtyrects; // Rectangle liste der Änderungen /* * TEXT OUT OPTIONEN */ extern int llgfx_text_xpos; // XPos relativ zu llgfx_text_rect extern int llgfx_text_ypos; // YPos relativ zu llgfx_text_rect extern float llgfx_text_xspacing; // Abstand x extern float llgfx_text_yspacing; // Abstand y; extern int llgfx_text_format; // 0=Links, 1=Rechts, 2= mitte, 3=Block extern s_rect llgfx_text_rect; // Ausgabe Rectangle extern int llgfx_tab_pos[8]; // tabpositionen in EM's (Durchschnitss breite) extern int llgfx_tab_chars[8]; // tabFüllzeichen extern s_font * llgfx_cur_font; // Fontstruct für Textausgabe extern bool llgfx_text_wrap; // true=wrapx, false=clip //:> +------------------------------------+ //:>-------------------| Bildschirm Funktionen |------------------- //:> +------------------------------------+ // Setzt einen neuen Bildschirm Modus. // Liefert OK bei Erfolg. // #define llgfx_SetMode llgfx_SetDisplayMode int llgfx_SetDisplayMode( int w, // Bildschirm breite in Pixel int h, // Bildschirm Höhe in Pixel int bpp, // gewünschte Bittiefe bool want_fullscreen, // true setzten für Vollschirm Modus int refreshrate=0); // Refreshrate // Löscht Backbuffer. Default rectangle = VD, bzw ganzer Schirm wenn // VD nicht gesetzt int llgfx_ClearScreen( TxU32 color=llgfx_clearcolor, // Löschfarbe llgfx_sRECT *dstrect=0); // optionales ziel rectangle // Wechselt Backbuffer zum Frontbuffer. // Parameter: wait=true bewirkt das erst auf den VBI gewartet wird bevor der Flip // durchgeführt wird und das nach dem Flip auf das Ende des Flips gewartet wird. // void llgfx_FlipScreen(bool wait); // true=wartet auf VBI // Speichert den aktuellen FRONTBUFFER in ein tga file // Liefert OK bei Erfolg // int llgfx_ScreenShot( const char* filename); // Wechselt Bildschirm Modus zwischen Vollschirm und Fenster Modus. // Beim wechseln können Probleme auftreten, insbesonders da am // Desktop kein Hardware-Flip aufgesetzt wird und daher hörere Bittiefen // möglich sein können. // // Die Funktion setzt bei einem Fehler wieder auf den letzten Bildschirm modus auf. // Returnwert = OK bei Erfolg sonst Fehler // int llgfx_ToggleFullscreen(); // Wartet bis ein VBI Eintritt. (Rasterstrahl im Vertical Blank Bereich). void llgfx_WaitVBI( void); //:> +------------------------------------+ //:>-------------------| Grafik Funktionen |------------------- //:> +------------------------------------+ // Ladet ein Grafikfile in einen neuen Grafikbuffer. // Liefert index des Grafikbuffers zurück. // Bei Fehler ist der Returnwert 0. // // Existiert bereits ein Grafikbuffer mit dem Pfad, dann wird die Referenz erhöht // und der existierende Bufferindex wird zurückgeliefert. Es sind dann mehrere // llgfx_ReleaseGFX Aufrufe notwendig um den Grafikbuffer zu entfernen. Ist eine // eigene Kopie des Grafikbuffers gewünscht, dann sollte man einen Buffer mit // llgfx_CreateGfx allokieren und anschliessend mit llgfx_BLITFAST kopieren. // // Parameter: // filename = Pfad der zur ladenden Grafik // flags = sind mit Oder verknüpfte Optionen: // // LLGFX_COLORKEY, Colorkey einschalten und setzten. (Linkes Oberes Pixel = // Colorkey) // // LLGFX_CACHE, Das File wird aus dem Speicher geladen, liefert 0 wenn nicht vorhanden // // filename="RES:filename"... lädt aus der resource // filename="ZIP:filename"... lädt aus dem Zipstream // filename="filename".... lädt aus dem Filesystem // llgfx_id llgfx_LoadGfx( const char * filename, // vollständiger Pfad mit extension int flags=0); // LLGFX_COLORKEY | LLGFX_CACHE // Liefert soundnamen const char* llgfx_GetName ( llgfx_id gfxid ); // Setzt neuen Namen void llgfx_SetName ( llgfx_id gfxid , const char *newName); // Wie LoadGfx, aber lädt zusätzlich eine Map datei // Erzeugt Einzel grafiken aufgrund der Map daten // Einzelgrafiken sind durch die Einzelnen Namen aus der MAP ansprechbar // // z.b. masterfile = llgfx_LoadTileMap("tiles.png"); // tile1 = llgfx_LoadGfx("tilemname"); // RETURN: 0 = OK int llgfx_LoadTileMap( const char * filename, // vollständiger Pfad mit extension int flags=0); // LLGFX_COLORKEY | LLGFX_CACHE // Liefert die Anzahl der allokierten Grafikbuffer. int llgfx_GetNumGfx(void); // Erstellt eine Grafik mit breite, höhe und bittiefe des Backbuffers // sysmem gibt an ob der Grafikbuffer auf der Grafikkarte sein soll oder im // Systemmemory. // Return: llgfx_id oder 0 bei Fehler // llgfx_id llgfx_CreateGfx( int width, int height, const char *name=0); // Optional namen setzen // Erstellt Kopie des Parameter-gfxbuffers // Colorkey and AlphaMap werden mitkopiert. // Return: llgfx_id oder 0 bei Fehler // llgfx_id llgfx_CloneGfx( llgfx_id srcgfx, const char *name=0); // Optional namen setzen char * llgfx_GetGfxName( llgfx_id idx); llgfx_id llgfx_GetGfxIdx( const char * name); // Der Grafikbuffer mit dem Parameter "filename" wird gelöscht, egal wieviele // Referenzen darauf existieren. // Return: OK wenn der Grafikbuffer gefunden und gelöscht wurde, // FAIL wenn der Grafikbuffer nicht gefunden wurde. // int llgfx_DeleteGfx(const char *filename); // Löschen nach filename void llgfx_DeleteGfx(llgfx_id gfx); // Löschen nach id // Löscht Grafikbuffer mit dem Blitter. // Parameter color = Löschfarbe (default=BLACK) // Parameter dstrect = Zielrechteck (default=ganze Grafik) // int llgfx_ClearGfx( llgfx_id idx, // gfx id TxU32 color=llgfx_clearcolor, // Löschfarbe llgfx_sRECT *dstrect=0); // Referenzcount einer Grafik erhöhen. Returnwert ist parameter Gfx llgfx_id llgfx_AddRef( llgfx_id gfx); // Liefert Anzahl Rererenzierungen. int llgfx_GetRefCount( llgfx_id gfx); // Setzt den Colorkey ausser Kraft void llgfx_DisableColorKey(llgfx_id idx); // Schaltet Colorkey ein void llgfx_EnableColorKey(llgfx_id idx); // Liefert colorkey im RGB888 Format. TxU32 llgfx_GetColorKey(llgfx_id idx); // Liefert Höhe der Grafik in Pixel int llgfx_GetGfxHeight(llgfx_id idx); // Liefert Breite der Grafik in Pixel. int llgfx_GetGfxWidth(llgfx_id idx); bool llgfx_IsColorkeyEnabled(llgfx_id idx); // Grafikbuffer freigeben der mit diesem Pfad über llgfx_LoadGfx erzeugt wurde. // Wenn der Referenzcount 0 erreicht wird der Grafikbuffer aus dem Speicher // entfernt. // // Parameter: Wenn der filename "ALL" übergeben wird, werden alle Grafiken // die angelegt wurden gelöscht. // Return: // OK wenn der Grafikbuffer mit dem Pfad gefunden und freigeben wurde, // sonst ungleich 0. // int llgfx_ReleaseGfx( const char *filename); void llgfx_ReleaseGfx( llgfx_id idx); // Vermindert den Referenzzähler um eins. // // Wenn der Referenzhzähler bereits 1 oder 0 ist, // dann wird der Referenzzähler nicht weiter vermindert. // Im Gegensatz zu llgfx_ReleaseGfx() wo bei einer Referenzzählerstand von 1 die // Grafik aus dem Speicher entfernt wird. // // Liefert die Anzahl verbleibender Referenzen. // int llgfx_ReleaseRef(llgfx_id gfx); // Setzt die Colorkeyfarbe. // ColorValue in 32 Bit RGB Farbe angeben, nicht in DeviceColor ! // Zusäztlich wird der colorkey enabled durch einen Implizieten Aufruf von // llgfx_EnableColorkey(). // void llgfx_SetColorKey( llgfx_id idx, TxU32 ColorValue); // Setzt die Colorkeyfarbe nach der Farbe des Pixels links/oben im Grafikbuffer. // Zusätzlich wird der colorkey enabled durch einen Impliziten Aufruf von // llgfx_EnableColorkey(). // // siehe auch: // llgfx_EnableColorKey(llgfx_id) // llgfx_DisableColorKey(llgfx_id) // llgfx_LoadGfx(const char,flags) // void llgfx_SetColorKeyFromTOPLEFTpixel( llgfx_id gfxnum); // Setzt anzahl von Animationsframes in einer Grafik. // Die Frames müssen alle untereinander liegen. // Als Angabe der Frameanzahl kann die Framehöhe einer Einzelgrafik, // oder die Frameanzahl selbst übergeben werden. // In beiden Fällen muss die Frameanzahl * Framehöhe ganzzahlig in der // Original Höhe enthalten sein. // Nach einem Aufruf von SetFrameCount liefert llgfx_GetGfxHeigt() nurmehr // die Single-Frame Höhe. Ein Blit() ohne Angabe eines Source-Frames blittet // nurmehr das erste Frame. Um die weiteren Frames zu blitten wird anstatt // eines Source-Rectangles, die Frame-Nummer übergeben; // bsp: // int aktframe = 4; // llgfx_VD_BLIT( srcgfx, x, y, (llgfx_sRECT*) aktframe ); // // Achtung:! der cast (llgfx_sRECT*) ist nur erlaubt wenn die FrameAnzahl // gesetzt ist. Falls nicht wird eine ASSERTION ausgelöst da aktframe kein // gültiger Zeiger auf ein RECT ist. // // Ein Aufruf mit einem parameter 0 oder 1, setzt die Frames wieder zurück. // // RETURN: // Anzahl der Frames die gesetzt wurden // int llgfx_SetFrameCount( llgfx_id idx, int parametertyp, // FRAME_HEIGHT, FRAME_COUNT int parameter); // Liefert Anzahl frames, 0= keine gesetzt, >0 = anzahl frames int llgfx_GetFrameCount( llgfx_id idx ); // Erstellt Cache texture nach Grafikmanipulation void llgfx_RebuildTexture( llgfx_id idx); void llgfx_RestoreTexture(llgfx_id idx); // liefert rgba texture (import file) llgfx_CTexture * llgfx_GetTexture( llgfx_id idx ); // Setzt z order blit überlappungsreihenfolge void llgfx_SetZOrder( llgfx_id idx, float z_order); // Setzt x/y offset werte für Blit Funktionen. // X,Y Offset werden bei jeder Blit Funktion zum Ziel dazu addiert, // mit Ausnahme wenn im BlitFlag ein BLIT_SRC_CENTERED gesetzt ist. void llgfx_SetOrigin( llgfx_id idx, int xoffset, int yoffset ); // Setzte x/y offset genau in die Mitte void llgfx_CenterOrigin( llgfx_id idx); // Liefert aktuellen xoffset/yoffset void llgfx_GetOrigin( llgfx_id idx, int &xoffset, int &yoffset ); // liefert das umschliesende Rechteck der Grafik. // X/Y Offset wird mit einberechnet. void llgfx_GetBoundingRect( llgfx_id idx, llgfx_sRECT & rect ); void llgfx_GetBoundingRect( llgfx_id idx, llgfx_sRECT * rect ); llgfx_CTexture * llgfx_CreateTextureFromGfx( llgfx_id idx); //:> +------------------------------------+ //:>-------------------| Grafik Buffer Funktionen |------------------- //:> +------------------------------------+ void * llgfx_GetGFXptr( llgfx_id idx); // fills llgfx_sGfxBuffer void * llgfx_GetGFXptr( llgfx_id idx, llgfx_sSURFACE *surfaceptr ); void * llgfx_GetGFXptr( llgfx_id idx, llgfx_sSURFACE *surfaceptr, llgfx_sRECT *rect ); // liefert zeiger auf mask daten. Maske wird erzeugt wenn noch nicht vorhanden // breite,höhe ist immer die von der grafik idx, pitch ist immer breite void * llgfx_GetMaskPtr(llgfx_id idx); void * llgfx_GetMaskPtr(llgfx_id idx, llgfx_sSURFACE *surfaceptr ); // Grafikbuffer aus dem LOCK Modus wieder freigeben. void llgfx_UnGetGFXptr(llgfx_id idx); // Mask freigeben inline void llgfx_UnGetMaskPtr(llgfx_id idx){}; // dummy, nicht notwenidg void llgfx_SetPalette(TxU8 index, TxU32 rgbcolor ); TxU32 llgfx_GetPalette(TxU8 index ); //:> +------------------------------------+ //:>-------------------| BLITTER FUNKTIONEN |------------------- //:> +------------------------------------+ int llgfx_BLIT(llgfx_id dest, // Destinantion GFX llgfx_id src, // Source GFX int x=0, // Dest POS int y=0, // * llgfx_sRECT *rect=0, // Sourcerect(Srcgfx), 0 = ganze Src-grafik int blitflags=0, // Copy,stippeld,srcalpha,fixalpha llgfx_sBLITFX *blitfx=0 // FixAlpha,Scale,etc ); int llgfx_BLIT(llgfx_id dest, // Destinantion GFX llgfx_id src, // Source GFX float x, // Dest POS float y, // * llgfx_sRECT *rect=0, // Sourcerect(Srcgfx), 0 = ganze Src-grafik int blitflags=0, // Copy,stippeld,srcalpha,fixalpha llgfx_sBLITFX *blitfx=0 // FixAlpha,Scale,etc ); int llgfx_BLITColor( llgfx_id dest, // Destinantion GFX int x, // Dest POS int y, // * llgfx_sRECT *rect, // dimension vom Bereich (0,0,w,h) int blitflags, // Copy,stippeld,srcalpha,fixalpha llgfx_sBLITFX *blitfx // bei FixAlpha ); // Wie llgfx_BLIT, statt srcgfx nur ein Pixel mit fixer Farbe in llgfx_sBLITFX.color int llgfx_BLITColor( llgfx_id dest, // Destinantion GFX TxU32 color, // Source Color int x, // Dest POS int y, // * llgfx_sRECT *rect, // dimension vom Bereich (0,0,w,h) int blitflags=0, // Copy,stippeld,srcalpha,fixalpha llgfx_sBLITFX *blitfx=0 // bei FixAlpha ); int llgfx_BLITFast( llgfx_id dest, // Zielgrafik llgfx_id src ); // +---------------------+ // | llgfx_TILE_BLIT() | // +---------------------+ int llgfx_TILE_BLIT( llgfx_id dstgfx, llgfx_id srcgfx, int start_offsetx=0, int start_offsety=0, llgfx_sRECT *srect=0, int blitflags=0, llgfx_sBLITFX *blitfx=0); int llgfx_TILE_BLIT( llgfx_id dstgfx, llgfx_id srcgfx, float start_offsetx, float start_offsety, llgfx_sRECT *srect=0, int blitflags=0, llgfx_sBLITFX *blitfx=0); //::22 // +----------------------+ // | llgfx_SCALE_BLIT() | // +----------------------+ int llgfx_SCALE_BLIT( llgfx_id dstgfx, llgfx_id srcgfx); int llgfx_BLIT_DIRTY( llgfx_id destgfx, llgfx_id u_gfxnum); int llgfx_VD_BLIT_DIRTY(llgfx_id srcgfx); /* * Erstellt eine rotierte Grafik vom srcgfx. * Wenn srect==NULL, dann wird die ganze Grafik routiert, * Wenn srect = (int)frame_number oder llgfx_sRECT* dann wird nur ein Teil rotiert * Die zurückgeliefert Grafik ist immer ein wenig grösser als die Srcgrafik. * Nach Gebrauch mit llgfx_ReleaseGFX freigeben. * x_zoom und y_zoom können während dem rotieren noch strecken */ llgfx_id llgfx_ROTATE_BLIT( llgfx_id src, llgfx_sRECT * rect, float angle, float x_zoom = 1.0f, float y_zoom = 1.0f ); //:> +------------------------------------+ //:>-------------------| Textausgabe mit systemfonts |------------------- //:> +------------------------------------+ inline void llgfx_SetTextPos(int xpos, int ypos ) { llgfx_text_xpos = xpos; llgfx_text_ypos = ypos; } inline void llgfx_SelectFont( s_font * font ) { llgfx_cur_font = font; } inline void llgfx_SetTextRect( int width, int height ) { llgfx_text_rect.left = llgfx_text_xpos; llgfx_text_rect.top = llgfx_text_ypos; llgfx_text_rect.width = llgfx_text_rect.left+ width; llgfx_text_rect.height = llgfx_text_rect.height + height; } // // DrawText, Zeichenweises blitten eines C-Strings // // Parameter: // // dst id Zielgrafik // text Null-Terminierter String der ausgegeben wird // [blitflag Blittermodus] // [blitfx Zeiger auf Blitfx Struktur // // Defaultwerte: // blitflag = SRC_COLORKEY // Zielgrafik = Backbuffer // Position = llgfx_text_xpos, llgfx_text_ypos // Fontgrafik = llgfx_cur_font // void llgfx_DrawText( llgfx_id dstgfx, const char * text, int blitflags, llgfx_sBLITFX *blitfx ); inline void llgfx_DrawText( const char * text, TxU32 color ) { llgfx_sBLITFX blitfx; blitfx.color1 = color; blitfx.fixalpha = 1.0f; llgfx_DrawText(/*dstgfx*/0,text,BLIT_FXCOLOR|BLIT_SRC_ALPHA,&blitfx); } inline void llgfx_DrawText( const char * text) { llgfx_DrawText(text,WHITE); } inline void llgfx_DrawText( int x, int y, const char * text ) { llgfx_text_xpos = x; llgfx_text_ypos = y; llgfx_SetTextRect(llgfx_displaywidth-x,llgfx_displayheight-y); llgfx_DrawText(text); } inline void llgfx_DrawText( int x, int y, const char * text, TxU32 color ) { llgfx_text_xpos = x; llgfx_text_ypos = y; llgfx_SetTextRect(llgfx_displaywidth-x,llgfx_displayheight-y); llgfx_sBLITFX blitfx; blitfx.color1 = color; blitfx.fixalpha = 1.0f; llgfx_DrawText(/*dstgfx*/0,text,BLIT_FXCOLOR|BLIT_SRC_ALPHA,&blitfx); } inline void llgfx_DrawText( llgfx_id dst, const char * text, TxU32 color ) { llgfx_sBLITFX blitfx; blitfx.color1 = color; blitfx.fixalpha = 1.0f; llgfx_DrawText(dst,text,BLIT_FXCOLOR|BLIT_SRC_ALPHA,&blitfx); } inline void llgfx_DrawText( const char * text, int blitflags, llgfx_sBLITFX *blitfx ) { llgfx_DrawText( /*dstgfx*/0, text, blitflags, blitfx ); } inline void llgfx_DrawText( llgfx_id id, const char * text) { llgfx_sBLITFX blitfx; blitfx.color1 = WHITE; blitfx.fixalpha = 1.0f; llgfx_DrawText(id,text,BLIT_FXCOLOR|BLIT_SRC_ALPHA,&blitfx); } void llgfx_Printf(const char *fmt,...); // calls drawtext(0,pritnfstring,0,0); void llgfx_Printf(llgfx_id dstgfx, const char *fmt,...); // calls drawtext(dstgfx,pritnfstring,0,0); void llgfx_GetTextRect( s_rect * rect, const char * text); //:> +------------------------------------+ //:>-------------------| Dirty Rect Funktionen |------------------- //:> +------------------------------------+ // void llgfx_AddDirtyRect( llgfx_sRECT &rect ); // Ein Rechteck zur dirtyrect Liste hinzufügen. // Setzt automatisches AddDirtyRect ausser Kraft. // Aktuelle Dirtylist wird gelöscht. void llgfx_DisableDirtyRect(void); // Schaltet automatisches Hinzufügen der Dirtyrects ein. // Löscht aktuelle dirtyrect liste. void llgfx_EnableDirtyRect(void); // llgfx_IsDirtyRectEnabled() // bool llgfx_IsDirtyRectEnabled(void); //::112 // +------------------------+ // | llgfx_GetPointPosQ() | // +------------------------+ //:Description // // ------------------------------------------------------------------------------ // llgfx_GetPointPosQ() // // Qualifiziert die Position von Punkt(x,y) zum Rechteck. // Return: // PPQ_INSIDE,PPQ_TOPLEFT,PPQ_ABOVE,PPQ_TOPRIGHT,PPQ_LEFT,PPQ_RIGHT,PPQ_BELOW, // PPQ_BOTTOMLEFT,PPQ_BOTTOMRIGHT // Bit 76543210 // |||| // |+|+--- %00=y inside R %01=x above R R %10=y below R // | | // +-+---- %00=x inside R %01=x left of R %10=x right of R // // 0011 0001 1001 TOPLEFT ABOVE TOPRIGHT // +-------+ +-------+ // 0010 | 0000 | 1000 LEFT |INSIDE | RIGHT // +-------+ +-------+ // 0110 0100 1100 BOTTOMLEFT BELOW BOTTOMRIGHT // #define PPQ_TOPBIT (0x1) #define PPQ_LEFTBIT (0x2) #define PPQ_BOTTOMBIT (0x4) #define PPQ_RIGHTBIT (0x8) typedef enum{ PPQ_INSIDE = (0x0), PPQ_TOPLEFT = (PPQ_TOPBIT|PPQ_LEFTBIT), PPQ_ABOVE = (PPQ_TOPBIT), PPQ_TOPRIGHT = (PPQ_TOPBIT|PPQ_RIGHTBIT), PPQ_LEFT = (PPQ_LEFTBIT), PPQ_RIGHT = (PPQ_RIGHTBIT), PPQ_BELOW = (PPQ_BOTTOMBIT), PPQ_BOTTOMLEFT = (PPQ_BOTTOMBIT|PPQ_LEFTBIT), PPQ_BOTTOMRIGHT = (PPQ_BOTTOMBIT|PPQ_RIGHTBIT) } ePPQ; inline ePPQ llgfx_GetPointPosQ( int tx, int ty, llgfx_sRECT *R); // // Float version. // Beispiel: // { float R[4]; // R[0] = rect.x1 + 0.5f; // R[1] = rect.y1 + 0.5f; // R[2] = rect.x2 + 0.5f; // R[3] = rect.y2 + 0.5f; // ePPQ ppq = llgfx_GetPointPosQ( fx, fy, &R ); //} inline ePPQ llgfx_GetPointPosQ( float tx, float ty, float *R ); //:> +-----------------------------------+ //:>-------------------| Global Function Definitions |-------------------- //:> +-----------------------------------+ //::112 // +------------------------+ // | llgfx_GetPointPosQ() | // +------------------------+ // // Bit 76543210 // |||| // |+|+--- %00=y inside R %01=x above R R %10=y below R // | | // +-+---- %00=x inside R %01=x left of R %10=x right of R // // 0011 0001 1001 TOPLEFT ABOVE TOPRIGHT // +-------+ +-------+ // 0010 | 0000 | 1000 LEFT |INSIDE | RIGHT // +-------+ +-------+ // 0110 0100 1100 BOTTOMLEFT BELOW BOTTOMRIGHT // inline ePPQ llgfx_GetPointPosQ( int tx, int ty, llgfx_sRECT *R ) { int a; if( tx < R->x1 ) a = PPQ_LEFTBIT; else if( tx >= R->x2 ) a = PPQ_RIGHTBIT; else a = 0; if( ty < R->y1 ) a |= PPQ_TOPBIT; else if( ty >= R->y2 ) a |= PPQ_BOTTOMBIT; return (ePPQ)a; } inline ePPQ llgfx_GetPointPosQ( float tx, float ty, float *R ) { int a; if( tx < R[0] ) a = PPQ_LEFTBIT; else if( tx >= R[2] ) a = PPQ_RIGHTBIT; else a = 0; if( ty < R[1] ) a |= PPQ_TOPBIT; else if( ty >= R[2] ) a |= PPQ_BOTTOMBIT; return (ePPQ)a; } #endif // LLGFX_INCLUDED