removed the obsolete Lib_GetKeyState function
[neuro.git] / src / video / interface.c
blob982072c669d433b4f89a8db417d0dc2fb5d26b36
1 /*
2 * libneuro, a light weight abstraction of high or lower libraries
3 * and toolkit for applications.
4 * Copyright (C) 2005-2006 Nicholas Niro, Robert Lemay
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 /* interface.c
23 * interface functions to core functions
26 /*-------------------- Extern Headers Including --------------------*/
27 #include <string.h> /* memcpy */
29 /*-------------------- Local Headers Including ---------------------*/
30 #include <graphics.h>
31 #include <extlib.h>
33 /*-------------------- Main Module Header --------------------------*/
34 #include "video.h"
37 /*-------------------- Other ----------------------------*/
39 /*-------------------- Global Variables ----------------------------*/
41 /*-------------------- Static Variables ----------------------------*/
43 /*-------------------- Static Prototypes ---------------------------*/
47 /*-------------------- Static Functions ----------------------------*/
49 /*-------------------- Global Functions ----------------------------*/
50 v_elem *
51 Neuro_PushDraw(u32 layer, Rectan *isrc, Rectan *idst, v_object *isurface)
53 if (Graphics_GetSafeDrawOp() == 0)
54 return NULL;
57 return Graphics_AddDrawingInstruction(layer, TDRAW_STATIC, isrc, idst, isurface);
60 int
61 Neuro_FetchDraw(v_elem *eng, Rectan *psrc, u16 *px, u16 *py, v_object **osurface)
63 if (!eng)
64 return 1;
66 if (!eng->current)
67 return 1;
69 if (Graphics_GetSafeDrawOp() == 0)
70 return 1;
72 if (psrc)
73 memcpy(psrc, &eng->current->src, sizeof(Rectan));
75 if (px)
76 *px = eng->current->dx;
78 if (py)
79 *py = eng->current->dy;
81 if (osurface)
83 /*Debug_Val(0, "surface_ptr 0x%x addr surface_ptr 0x%x\n",
84 eng->surface_ptr, &eng->surface_ptr);*/
85 *osurface = eng->current->surface_ptr;
88 return 0;
92 int
93 Neuro_SetImgPos(v_elem *eng, u16 px, u16 py)
95 if (!eng)
96 return 1;
98 if (!eng->current)
99 return 1;
101 if (Graphics_GetSafeDrawOp() == 0)
102 return 1;
104 if (!px || !py)
105 return 1;
107 eng->current->dx = px;
108 eng->current->dy = py;
110 return 0;
114 Neuro_SetImgLayer(v_elem *eng, u32 layer)
116 if (!eng)
117 return 1;
119 if (!eng->current)
120 return 1;
122 if (Graphics_GetSafeDrawOp() == 0)
123 return 1;
125 eng->current->layer = layer;
127 return 0;
131 Neuro_SetImgSrcPos(v_elem *eng, Rectan *psrc)
133 if (!eng)
134 return 1;
136 if (!eng->current)
137 return 1;
139 if (Graphics_GetSafeDrawOp() == 0)
140 return 1;
142 if (!psrc)
143 return 1;
145 memcpy(&eng->current->src, psrc, sizeof(Rectan));
147 return 0;
151 Neuro_SetDraw(v_elem *eng, v_object *isurface)
153 if (!eng)
154 return 1;
156 if (!eng->current)
157 return 1;
159 if (!isurface)
160 return 1;
162 if (Graphics_GetSafeDrawOp() == 0)
163 return 1;
165 eng->current->surface_ptr = isurface;
167 return 0;
171 Neuro_CleanDraw(v_elem *eng)
173 Rectan buf;
174 v_object *screen;
176 if (!eng)
177 return 1;
179 if (!eng->current)
180 return 1;
182 if (Graphics_GetSafeDrawOp() == 0)
183 return 1;
185 buf.x = eng->current->dx;
186 buf.y = eng->current->dy;
187 buf.w = eng->current->src.w;
188 buf.h = eng->current->src.h;
190 /* we start by redrawing above the static
191 * image location to reset its image.
192 * it may be the background or black.
194 /*if (background)
196 Lib_BlitObject(background, &buf, sclScreen2, NULL);
198 else*/
200 screen = Neuro_GetScreenBuffer();
202 Lib_FillRect(screen, &buf, 0);
204 /* redraw_erased_for_object(eng); */
205 Graphics_RedrawSection(eng);
207 return 0;
210 /* this function is to tag the element to be
211 * redrawn.
214 Neuro_FlushDraw(v_elem *eng)
216 if (!eng)
217 return 1;
219 if (!eng->current)
220 return 1;
222 if (Graphics_GetSafeDrawOp() == 0)
223 return 1;
225 if (eng->current->type == TDRAW_SDRAWN)
227 Rectan dst;
229 dst.x = eng->current->dx;
230 dst.y = eng->current->dy;
231 dst.w = eng->current->src.w;
232 dst.h = eng->current->src.h;
235 eng->current->type = TDRAW_STATIC;
237 /* flag the algorithm to tell it something changed
238 * and an action needs to be taken.
240 Neuro_RedrawScreen();
241 /* draw_this_cycle = 1; */
243 else
244 return 1;
246 return 0;
250 Neuro_DestroyDraw(v_elem *eng)
252 if (!eng)
253 return 1;
255 if (!eng->current)
256 return 1;
258 if (Graphics_GetSafeDrawOp() == 0)
259 return 1;
261 if (eng->current->type == TDRAW_STATIC)
262 return 1;
264 if (Graphics_DrawIsPresent(eng) == 0)
265 return 1;
267 /* eng->current->type = TDRAW_SDESTROY; */
269 /* the official way of deleting an element */
270 Graphics_DestroyElement(eng);
272 /* clean_object(eng); */
276 Neuro_RedrawScreen();
277 /* draw_this_cycle = 1; */
279 return 0;
282 void
283 Neuro_PushStaticDraw(u32 layer, Rectan *isrc, Rectan *idst, v_object *isurface)
285 Graphics_AddDrawingInstruction(layer, TDRAW_STATIC, isrc, idst, isurface);
288 void
289 Neuro_PushDynamicDraw(u32 layer, Rectan *isrc, Rectan *idst, v_object *isurface)
291 Graphics_AddDrawingInstruction(layer, TDRAW_DYNAMIC, isrc, idst, isurface);
294 /* push a drawing instruction that will be deleted from the queue and raw
295 * after being drawn. This replaces the hackish override method with an
296 * ultra versatile one and much less costy ;P.
298 void
299 Neuro_PushVolatileDraw(u32 layer, Rectan *isrc, Rectan *idst, v_object *isurface)
301 Graphics_AddDrawingInstruction(layer, TDRAW_VOLATILE, isrc, idst, isurface);