graphics : added two new functions to mangle with
[neuro.git] / src / video / interface.c
bloba573b0fdbb5d187148c488e3bafe4e81cea587e6
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;
91 int
92 Neuro_SetImgPos(v_elem *eng, u16 px, u16 py)
94 Rectan dst;
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;
109 dst.x = eng->current->dx;
110 dst.y = eng->current->dy;
111 dst.w = eng->current->src.w;
112 dst.h = eng->current->src.h;
114 Lib_FillRect(Neuro_GetScreenBuffer(), &dst, 0);
116 eng->current->dx = px;
117 eng->current->dy = py;
119 return 0;
123 Neuro_SetImgSrcPos(v_elem *eng, Rectan *psrc)
125 Rectan dst;
126 if (!eng)
127 return 1;
129 if (!eng->current)
130 return 1;
132 if (Graphics_GetSafeDrawOp() == 0)
133 return 1;
135 if (!psrc)
136 return 1;
138 dst.x = eng->current->dx;
139 dst.y = eng->current->dy;
140 dst.w = eng->current->src.w;
141 dst.h = eng->current->src.h;
143 Lib_FillRect(Neuro_GetScreenBuffer(), &dst, 0);
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 eng->current->type = TDRAW_STATIC;
229 /* flag the algorithm to tell it something changed
230 * and an action needs to be taken.
232 Neuro_RedrawScreen();
233 /* draw_this_cycle = 1; */
235 else
236 return 1;
238 return 0;
242 Neuro_DestroyDraw(v_elem *eng)
244 if (!eng)
245 return 1;
247 if (!eng->current)
248 return 1;
250 if (Graphics_GetSafeDrawOp() == 0)
251 return 1;
253 if (eng->current->type == TDRAW_STATIC)
254 return 1;
256 if (Graphics_DrawIsPresent(eng) == 0)
257 return 1;
259 /* eng->current->type = TDRAW_SDESTROY; */
261 /* the official way of deleting an element */
262 Graphics_DestroyElement(eng);
264 /* clean_object(eng); */
268 Neuro_RedrawScreen();
269 /* draw_this_cycle = 1; */
271 return 0;
274 void
275 Neuro_PushStaticDraw(u32 layer, Rectan *isrc, Rectan *idst, v_object *isurface)
277 Graphics_AddDrawingInstruction(layer, TDRAW_STATIC, isrc, idst, isurface);
280 void
281 Neuro_PushDynamicDraw(u32 layer, Rectan *isrc, Rectan *idst, v_object *isurface)
283 Graphics_AddDrawingInstruction(layer, TDRAW_DYNAMIC, isrc, idst, isurface);
286 /* push a drawing instruction that will be deleted from the queue and raw
287 * after being drawn. This replaces the hackish override method with an
288 * ultra versatile one and much less costy ;P.
290 void
291 Neuro_PushVolatileDraw(u32 layer, Rectan *isrc, Rectan *idst, v_object *isurface)
293 Graphics_AddDrawingInstruction(layer, TDRAW_VOLATILE, isrc, idst, isurface);