1 /* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // -------------------------------------------------------------------------*/
12 #include "sjme/util.h"
13 #include "lib/scritchui/scritchui.h"
14 #include "lib/scritchui/scritchuiPencil.h"
15 #include "lib/scritchui/scritchuiTypes.h"
16 #include "lib/scritchui/core/coreRaster.h"
17 #include "sjme/debug.h"
18 #include "sjme/fixed.h"
20 sjme_errorCode
sjme_scritchpen_core_drawRect(
21 sjme_attrInNotNull sjme_scritchui_pencil g
,
22 sjme_attrInValue sjme_jint x
,
23 sjme_attrInValue sjme_jint y
,
24 sjme_attrInPositive sjme_jint w
,
25 sjme_attrInPositive sjme_jint h
)
31 return SJME_ERROR_NULL_ARGUMENTS
;
33 /* Nothing to draw? */
35 return SJME_ERROR_NONE
;
38 if (sjme_error_is(error
= sjme_scritchpen_core_lock(g
)))
39 return sjme_error_default(error
);
42 sjme_scritchpen_coreUtil_applyTranslate(g
, &x
, &y
);
44 /* Pre-calculate coordinates. */
48 /* Clear error state. */
49 error
= SJME_ERROR_NONE
;
51 /* Draw horizontal spans first. */
52 error
|= g
->prim
.drawHoriz(g
, x
, y
, w
);
53 error
|= g
->prim
.drawHoriz(g
, x
, yh
, w
);
55 /* Draw vertical spans. */
56 error
|= g
->prim
.drawLine(g
, x
, y
, x
, yh
);
57 error
|= g
->prim
.drawLine(g
, xw
, y
, xw
, yh
);
60 if (sjme_error_is(error
))
64 if (sjme_error_is(error
= sjme_scritchpen_core_lockRelease(g
)))
65 return sjme_error_default(error
);
68 return SJME_ERROR_NONE
;
71 /* Need to release the lock? */
72 if (sjme_error_is(sjme_scritchpen_core_lockRelease(g
)))
73 return sjme_error_default(error
);
75 return sjme_error_default(error
);
78 sjme_errorCode
sjme_scritchpen_core_drawTriangle(
79 sjme_attrInNotNull sjme_scritchui_pencil g
,
80 sjme_attrInValue sjme_jint x1
,
81 sjme_attrInValue sjme_jint y1
,
82 sjme_attrInValue sjme_jint x2
,
83 sjme_attrInValue sjme_jint y2
,
84 sjme_attrInValue sjme_jint x3
,
85 sjme_attrInValue sjme_jint y3
)
90 return SJME_ERROR_NULL_ARGUMENTS
;
93 if (sjme_error_is(error
= sjme_scritchpen_core_lock(g
)))
94 return sjme_error_default(error
);
97 sjme_scritchpen_coreUtil_applyTranslate(g
, &x1
, &y1
);
98 sjme_scritchpen_coreUtil_applyTranslate(g
, &x2
, &y2
);
99 sjme_scritchpen_coreUtil_applyTranslate(g
, &x3
, &y3
);
101 /* Clear error state. */
102 error
= SJME_ERROR_NONE
;
104 /* Draw lines via primitives. */
105 error
|= g
->prim
.drawLine(g
, x1
, y1
, x2
, y2
);
106 error
|= g
->prim
.drawLine(g
, x2
, y2
, x3
, y3
);
107 error
|= g
->prim
.drawLine(g
, x3
, y3
, x1
, y1
);
110 if (sjme_error_is(error
))
114 if (sjme_error_is(error
= sjme_scritchpen_core_lockRelease(g
)))
115 return sjme_error_default(error
);
118 return SJME_ERROR_NONE
;
121 /* Need to release the lock? */
122 if (sjme_error_is(sjme_scritchpen_core_lockRelease(g
)))
123 return sjme_error_default(error
);
125 return sjme_error_default(error
);
128 sjme_errorCode
sjme_scritchpen_core_fillRect(
129 sjme_attrInNotNull sjme_scritchui_pencil g
,
130 sjme_attrInValue sjme_jint x
,
131 sjme_attrInValue sjme_jint y
,
132 sjme_attrInPositive sjme_jint w
,
133 sjme_attrInPositive sjme_jint h
)
135 sjme_errorCode error
;
136 sjme_scritchui_pencilDrawHorizFunc drawHoriz
;
140 return SJME_ERROR_NULL_ARGUMENTS
;
143 if (sjme_error_is(error
= sjme_scritchpen_core_lock(g
)))
144 return sjme_error_default(error
);
147 sjme_scritchpen_coreUtil_applyTranslate(g
, &x
, &y
);
149 /* Cap width and height to 1 always. */
155 /* Use primitives otherwise. */
156 error
= SJME_ERROR_NONE
;
157 drawHoriz
= g
->prim
.drawHoriz
;
158 for (yz
= y
, yze
= y
+ h
; yz
< yze
; yz
++)
159 if (sjme_error_is(error
= drawHoriz(g
, x
, yz
, w
)))
163 if (sjme_error_is(error
))
167 if (sjme_error_is(error
= sjme_scritchpen_core_lockRelease(g
)))
168 return sjme_error_default(error
);
174 /* Need to release the lock? */
175 if (sjme_error_is(sjme_scritchpen_core_lockRelease(g
)))
176 return sjme_error_default(error
);
178 return sjme_error_default(error
);
181 sjme_errorCode
sjme_scritchpen_core_fillTriangle(
182 sjme_attrInNotNull sjme_scritchui_pencil g
,
183 sjme_attrInValue sjme_jint x1
,
184 sjme_attrInValue sjme_jint y1
,
185 sjme_attrInValue sjme_jint x2
,
186 sjme_attrInValue sjme_jint y2
,
187 sjme_attrInValue sjme_jint x3
,
188 sjme_attrInValue sjme_jint y3
)
190 sjme_errorCode error
;
193 return SJME_ERROR_NULL_ARGUMENTS
;
196 if (sjme_error_is(error
= sjme_scritchpen_core_lock(g
)))
197 return sjme_error_default(error
);
200 return sjme_error_notImplemented(0);
203 if (sjme_error_is(error
= sjme_scritchpen_core_lockRelease(g
)))
204 return sjme_error_default(error
);
206 return sjme_error_notImplemented(0);
209 /* Need to release the lock? */
210 if (sjme_error_is(sjme_scritchpen_core_lockRelease(g
)))
211 return sjme_error_default(error
);
213 return sjme_error_default(error
);