1 /*****************************************************************************/
5 /* Tiny graphics interface */
9 /* (C) 2002-2009, Ullrich von Bassewitz */
10 /* Roemerstrasse 52 */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
42 #include <tgi/tgi-mode.h>
45 #include <tgi/tgi-error.h>
50 /*****************************************************************************/
52 /*****************************************************************************/
57 #define TGI_COLOR_BLACK 0
58 #define TGI_COLOR_WHITE 1
60 /* Font constants for use with tgi_textstyle */
61 #define TGI_FONT_BITMAP 0
62 #define TGI_FONT_VECTOR 1
64 /* Direction constants for use with tgi_textstyle */
65 #define TGI_TEXT_HORIZONTAL 0
66 #define TGI_TEXT_VERTICAL 1
68 /* The name of the standard tgi driver for a platform */
69 extern const char tgi_stddrv[];
71 /* The default tgi mode for a platform */
72 extern const unsigned char tgi_stdmode;
74 /* A vector font definition */
75 typedef struct tgi_vectorfont tgi_vectorfont;
79 /*****************************************************************************/
81 /*****************************************************************************/
85 void __fastcall__ tgi_load (unsigned char mode);
86 /* Load and install the matching driver for the given mode. Will just load
87 * the driver and check if loading was successul. Will not switch to gaphics
91 void __fastcall__ tgi_load_driver (const char* name);
92 /* Load and install the given driver. This function is identical to tgi_load
93 * with the only difference that the name of the driver is specified
97 void __fastcall__ tgi_unload (void);
98 /* Uninstall, then unload the currently loaded driver. Will call tgi_done if
102 void __fastcall__ tgi_install (void* driver);
103 /* Install an already loaded driver. */
105 void __fastcall__ tgi_uninstall (void);
106 /* Uninstall the currently loaded driver but do not unload it. Will call
107 * tgi_done if necessary.
110 void __fastcall__ tgi_init (void);
111 /* Initialize the already loaded graphics driver. */
113 void __fastcall__ tgi_done (void);
114 /* End graphics mode, switch back to text mode. Will NOT uninstall or unload
118 const tgi_vectorfont* __fastcall__ tgi_load_vectorfont (const char* name);
119 /* Load a vector font into memory and return it. In case of errors, NULL is
120 * returned and an error is set, which can be retrieved using tgi_geterror.
121 * To use the font, it has to be installed using tgi_install_vectorfont.
124 void __fastcall__ tgi_install_vectorfont (const tgi_vectorfont* font);
125 /* Install a vector font for use. More than one vector font can be loaded,
126 * but only one can be active. This function is used to tell which one. Call
127 * with a NULL pointer to uninstall the currently installed font.
130 void tgi_free_vectorfont (const tgi_vectorfont* font);
131 /* Free a vector font that was previously loaded into memory. */
133 unsigned char __fastcall__ tgi_geterror (void);
134 /* Return the error code for the last operation. This will also clear the
138 const char* __fastcall__ tgi_geterrormsg (unsigned char code);
139 /* Get an error message describing the error in code. */
141 void __fastcall__ tgi_clear (void);
142 /* Clear the drawpage. */
144 unsigned __fastcall__ tgi_getpagecount (void);
145 /* Returns the number of screen pages available. */
147 void __fastcall__ tgi_setviewpage (unsigned char page);
148 /* Set the visible page. Will set an error if the page is not available. */
150 void __fastcall__ tgi_setdrawpage (unsigned char page);
151 /* Set the drawable page. Will set an error if the page is not available. */
153 unsigned char __fastcall__ tgi_getcolorcount (void);
154 /* Get the number of available colors. */
156 unsigned char __fastcall__ tgi_getmaxcolor (void);
157 /* Return the maximum supported color number (the number of colors would
158 * then be getmaxcolor()+1).
161 void __fastcall__ tgi_setcolor (unsigned char color);
162 /* Set the current drawing color. */
164 unsigned char __fastcall__ tgi_getcolor (void);
165 /* Return the current drawing color. */
167 void __fastcall__ tgi_setpalette (const unsigned char* palette);
168 /* Set the palette (not available with all drivers/hardware). palette is
169 * a pointer to as many entries as there are colors.
172 const unsigned char* __fastcall__ tgi_getpalette (void);
173 /* Return the current palette. */
175 const unsigned char* __fastcall__ tgi_getdefpalette (void);
176 /* Return the default palette. */
178 unsigned __fastcall__ tgi_getxres (void);
179 /* Return the resolution in X direction. */
181 unsigned __fastcall__ tgi_getmaxx (void);
182 /* Return the maximum x coordinate. The resolution in x direction is
186 unsigned __fastcall__ tgi_getyres (void);
187 /* Return the resolution in Y direction. */
189 unsigned __fastcall__ tgi_getmaxy (void);
190 /* Return the maximum y coordinate. The resolution in y direction is
194 unsigned char __fastcall__ tgi_getpixel (int x, int y);
195 /* Get the color value of a pixel. */
197 void __fastcall__ tgi_setpixel (int x, int y);
198 /* Plot a pixel in the current drawing color. */
200 void __fastcall__ tgi_gotoxy (int x, int y);
201 /* Set the graphics cursor to the given position. */
203 void __fastcall__ tgi_line (int x1, int y1, int x2, int y2);
204 /* Draw a line in the current drawing color. The graphics cursor will
205 * be set to x2/y2 by this call.
208 void __fastcall__ tgi_lineto (int x2, int y2);
209 /* Draw a line in the current drawing color from the graphics cursor to the
210 * new end point. The graphics cursor will be updated to x2/y2.
213 void __fastcall__ tgi_circle (int x, int y, unsigned char radius);
214 /* Draw a circle in the current drawing color. */
216 void __fastcall__ tgi_ellipse (int x, int y, unsigned char rx, unsigned char ry);
217 /* Draw a full ellipse with center at x/y and radii rx/ry using the current
221 void __fastcall__ tgi_arc (int x, int y, unsigned char rx, unsigned char ry,
222 unsigned sa, unsigned ea);
223 /* Draw an ellipse arc with center at x/y and radii rx/ry using the current
224 * drawing color. The arc covers the angle between sa and ea (startangle and
225 * endangle), which must be in the range 0..360 (otherwise the function may
226 * bevave unextectedly).
229 void __fastcall__ tgi_pieslice (int x, int y, unsigned char rx, unsigned char ry,
230 unsigned sa, unsigned ea);
231 /* Draw an ellipse pie slice with center at x/y and radii rx/ry using the
232 * current drawing color. The pie slice covers the angle between sa and ea
233 * (startangle and endangle), which must be in the range 0..360 (otherwise the
234 * function may behave unextectedly).
237 void __fastcall__ tgi_bar (int x1, int y1, int x2, int y2);
238 /* Draw a bar (a filled rectangle) using the current color. */
240 void __fastcall__ tgi_textscale (unsigned width, unsigned height);
241 /* Set the scaling for text output. The scaling factors for width and height
242 * are 8.8 fixed point values. This means that $100 = 1 $200 = 2 etc.
245 void __fastcall__ tgi_textstyle (unsigned width, unsigned height,
246 unsigned char dir, unsigned char font);
247 /* Set the style for text output. The scaling factors for width and height
248 * are 8.8 fixed point values. This means that $100 = 1 $200 = 2 etc.
249 * dir is one of the TGI_TEXT_XXX constants. font is one of the TGI_FONT_XXX
253 unsigned __fastcall__ tgi_textwidth (const char* s);
254 /* Calculate the width of the text in pixels according to the current text
258 unsigned __fastcall__ tgi_textheight (const char* s);
259 /* Calculate the height of the text in pixels according to the current text
263 void __fastcall__ tgi_outtext (const char* s);
264 /* Output text at the current graphics cursor position. The graphics cursor
265 * is moved to the end of the text.
268 void __fastcall__ tgi_outtextxy (int x, int y, const char* s);
269 /* Output text at the given cursor position. The graphics cursor is moved to
270 * the end of the text.
273 unsigned __fastcall__ tgi_ioctl (unsigned char code, void* data);
274 /* Call the driver specific control function. What this function does for
275 * a specific code depends on the driver. The driver will set an error
276 * for unknown codes or values.