1 /*****************************************************************************/
5 /* Tiny graphics interface */
9 /* (C) 2002-2013, 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-error.h>
47 /*****************************************************************************/
49 /*****************************************************************************/
53 /* Font constants for use with tgi_settextstyle */
54 #define TGI_FONT_BITMAP 0
55 #define TGI_FONT_VECTOR 1
57 /* Direction constants for use with tgi_settextstyle */
58 #define TGI_TEXT_HORIZONTAL 0
59 #define TGI_TEXT_VERTICAL 1
61 /* The name of the standard tgi driver for a platform */
62 extern const char tgi_stddrv[];
64 /* The address of the static standard tgi driver for a platform */
65 extern const void tgi_static_stddrv[];
67 /* A vector font definition */
68 typedef struct tgi_vectorfont tgi_vectorfont;
72 /*****************************************************************************/
74 /*****************************************************************************/
78 void __fastcall__ tgi_load_driver (const char* name);
79 /* Load and install the given driver. */
81 void tgi_unload (void);
82 /* Uninstall, then unload the currently loaded driver. Will call tgi_done if
86 void __fastcall__ tgi_install (void* driver);
87 /* Install an already loaded driver. */
89 void tgi_uninstall (void);
90 /* Uninstall the currently loaded driver but do not unload it. Will call
91 * tgi_done if necessary.
95 /* Initialize the already loaded graphics driver. */
98 /* End graphics mode, switch back to text mode. Will NOT uninstall or unload
102 const tgi_vectorfont* __fastcall__ tgi_load_vectorfont (const char* name);
103 /* Load a vector font into memory and return it. In case of errors, NULL is
104 * returned and an error is set, which can be retrieved using tgi_geterror.
105 * To use the font, it has to be installed using tgi_install_vectorfont.
108 void __fastcall__ tgi_install_vectorfont (const tgi_vectorfont* font);
109 /* Install a vector font for use. More than one vector font can be loaded,
110 * but only one can be active. This function is used to tell which one. Call
111 * with a NULL pointer to uninstall the currently installed font.
114 void __fastcall__ tgi_free_vectorfont (const tgi_vectorfont* font);
115 /* Free a vector font that was previously loaded into memory. */
117 unsigned char tgi_geterror (void);
118 /* Return the error code for the last operation. This will also clear the
122 const char* __fastcall__ tgi_geterrormsg (unsigned char code);
123 /* Get an error message describing the error in code. */
125 void tgi_clear (void);
126 /* Clear the drawpage. */
128 unsigned tgi_getpagecount (void);
129 /* Returns the number of screen pages available. */
131 void __fastcall__ tgi_setviewpage (unsigned char page);
132 /* Set the visible page. Will set an error if the page is not available. */
134 void __fastcall__ tgi_setdrawpage (unsigned char page);
135 /* Set the drawable page. Will set an error if the page is not available. */
137 unsigned char tgi_getcolorcount (void);
138 /* Get the number of available colors. */
140 unsigned char tgi_getmaxcolor (void);
141 /* Return the maximum supported color number (the number of colors would
142 * then be getmaxcolor()+1).
145 void __fastcall__ tgi_setcolor (unsigned char color);
146 /* Set the current drawing color. */
148 unsigned char tgi_getcolor (void);
149 /* Return the current drawing color. */
151 void __fastcall__ tgi_setpalette (const unsigned char* palette);
152 /* Set the palette (not available with all drivers/hardware). palette is
153 * a pointer to as many entries as there are colors.
156 const unsigned char* tgi_getpalette (void);
157 /* Return the current palette. */
159 const unsigned char* tgi_getdefpalette (void);
160 /* Return the default palette. */
162 unsigned tgi_getxres (void);
163 /* Return the resolution in X direction. */
165 unsigned tgi_getmaxx (void);
166 /* Return the maximum x coordinate. The resolution in x direction is
170 unsigned tgi_getyres (void);
171 /* Return the resolution in Y direction. */
173 unsigned tgi_getmaxy (void);
174 /* Return the maximum y coordinate. The resolution in y direction is
178 unsigned tgi_getaspectratio (void);
179 /* Returns the aspect ratio for the loaded driver. The aspect ratio is an
180 * 8.8 fixed point value.
183 void __fastcall__ tgi_setaspectratio (unsigned aspectratio);
184 /* Set a new aspect ratio for the loaded driver. The aspect ratio is an
185 * 8.8 fixed point value.
188 unsigned char __fastcall__ tgi_getpixel (int x, int y);
189 /* Get the color value of a pixel. */
191 void __fastcall__ tgi_setpixel (int x, int y);
192 /* Plot a pixel in the current drawing color. */
194 void __fastcall__ tgi_gotoxy (int x, int y);
195 /* Set the graphics cursor to the given position. */
197 void __fastcall__ tgi_line (int x1, int y1, int x2, int y2);
198 /* Draw a line in the current drawing color. The graphics cursor will
199 * be set to x2/y2 by this call.
202 void __fastcall__ tgi_lineto (int x2, int y2);
203 /* Draw a line in the current drawing color from the graphics cursor to the
204 * new end point. The graphics cursor will be updated to x2/y2.
207 void __fastcall__ tgi_circle (int x, int y, unsigned char radius);
208 /* Draw a circle in the current drawing color. */
210 void __fastcall__ tgi_ellipse (int x, int y, unsigned char rx, unsigned char ry);
211 /* Draw a full ellipse with center at x/y and radii rx/ry using the current
215 void __fastcall__ tgi_arc (int x, int y, unsigned char rx, unsigned char ry,
216 unsigned sa, unsigned ea);
217 /* Draw an ellipse arc with center at x/y and radii rx/ry using the current
218 * drawing color. The arc covers the angle between sa and ea (startangle and
219 * endangle), which must be in the range 0..360 (otherwise the function may
220 * bevave unextectedly).
223 void __fastcall__ tgi_pieslice (int x, int y, unsigned char rx, unsigned char ry,
224 unsigned sa, unsigned ea);
225 /* Draw an ellipse pie slice with center at x/y and radii rx/ry using the
226 * current drawing color. The pie slice covers the angle between sa and ea
227 * (startangle and endangle), which must be in the range 0..360 (otherwise the
228 * function may behave unextectedly).
231 void __fastcall__ tgi_bar (int x1, int y1, int x2, int y2);
232 /* Draw a bar (a filled rectangle) using the current color. */
234 void __fastcall__ tgi_settextdir (unsigned char dir);
235 /* Set the direction for text output. dir is one of the TGI_TEXT_XXX
239 void __fastcall__ tgi_settextscale (unsigned width, unsigned height);
240 /* Set the scaling for text output. The scaling factors for width and height
241 * are 8.8 fixed point values. This means that $100 = 1 $200 = 2 etc.
244 void __fastcall__ tgi_settextstyle (unsigned width, unsigned height,
245 unsigned char dir, unsigned char font);
246 /* Set the style for text output. The scaling factors for width and height
247 * are 8.8 fixed point values. This means that $100 = 1 $200 = 2 etc.
248 * dir is one of the TGI_TEXT_XXX constants. font is one of the TGI_FONT_XXX
252 unsigned __fastcall__ tgi_gettextwidth (const char* s);
253 /* Calculate the width of the text in pixels according to the current text
257 unsigned __fastcall__ tgi_gettextheight (const char* s);
258 /* Calculate the height of the text in pixels according to the current text
262 void __fastcall__ tgi_outtext (const char* s);
263 /* Output text at the current graphics cursor position. The graphics cursor
264 * is moved to the end of the text.
267 void __fastcall__ tgi_outtextxy (int x, int y, const char* s);
268 /* Output text at the given cursor position. The graphics cursor is moved to
269 * the end of the text.
272 unsigned __fastcall__ tgi_ioctl (unsigned char code, void* data);
273 /* Call the driver specific control function. What this function does for
274 * a specific code depends on the driver. The driver will set an error
275 * for unknown codes or values.
278 int __fastcall__ tgi_imulround (int rhs, int lhs);
279 /* Helper function for functions using sine/cosine: Multiply two values, one
280 * being an 8.8 fixed point one, and return the rounded and scaled result.