1- use crate :: color:: Color ;
21use bevy:: prelude:: Entity ;
2+ use renderer:: render:: command:: DrawCommand ;
3+
4+ use crate :: color:: Color ;
35
46mod color;
57mod error;
@@ -72,15 +74,40 @@ pub extern "C" fn processing_background_color(window_id: u64, color: Color) {
7274 error:: check ( || renderer:: background_color ( window_entity, color. into ( ) ) ) ;
7375}
7476
75- /// Step the application forward .
77+ /// Begins the draw for the given window .
7678///
7779/// SAFETY:
7880/// - Init has been called and exit has not been called.
7981/// - This is called from the same thread as init.
8082#[ unsafe( no_mangle) ]
81- pub extern "C" fn processing_update ( ) {
83+ pub extern "C" fn processing_begin_draw ( window_id : u64 ) {
8284 error:: clear_error ( ) ;
83- error:: check ( || renderer:: update ( ) ) ;
85+ let window_entity = Entity :: from_bits ( window_id) ;
86+ error:: check ( || renderer:: begin_draw ( window_entity) ) ;
87+ }
88+
89+ /// Flushes recorded draw commands for the given window.
90+ ///
91+ /// SAFETY:
92+ /// - Init has been called and exit has not been called.
93+ /// - This is called from the same thread as init.
94+ #[ unsafe( no_mangle) ]
95+ pub extern "C" fn processing_flush ( window_id : u64 ) {
96+ error:: clear_error ( ) ;
97+ let window_entity = Entity :: from_bits ( window_id) ;
98+ error:: check ( || renderer:: flush ( window_entity) ) ;
99+ }
100+
101+ /// Ends the draw for the given window and presents the frame.
102+ ///
103+ /// SAFETY:
104+ /// - Init has been called and exit has not been called.
105+ /// - This is called from the same thread as init.
106+ #[ unsafe( no_mangle) ]
107+ pub extern "C" fn processing_end_draw ( window_id : u64 ) {
108+ error:: clear_error ( ) ;
109+ let window_entity = Entity :: from_bits ( window_id) ;
110+ error:: check ( || renderer:: end_draw ( window_entity) ) ;
84111}
85112
86113/// Shuts down internal resources with given exit code, but does *not* terminate the process.
@@ -93,3 +120,104 @@ pub extern "C" fn processing_exit(exit_code: u8) {
93120 error:: clear_error ( ) ;
94121 error:: check ( || renderer:: exit ( exit_code) ) ;
95122}
123+
124+ /// Set the fill color.
125+ ///
126+ /// SAFETY:
127+ /// - Init and create_surface have been called.
128+ /// - window_id is a valid ID returned from create_surface.
129+ /// - This is called from the same thread as init.
130+ #[ unsafe( no_mangle) ]
131+ pub extern "C" fn processing_set_fill ( window_id : u64 , r : f32 , g : f32 , b : f32 , a : f32 ) {
132+ error:: clear_error ( ) ;
133+ let window_entity = Entity :: from_bits ( window_id) ;
134+ let color = bevy:: color:: Color :: srgba ( r, g, b, a) ;
135+ error:: check ( || renderer:: record_command ( window_entity, DrawCommand :: Fill ( color) ) ) ;
136+ }
137+
138+ /// Set the stroke color.
139+ ///
140+ /// SAFETY:
141+ /// - Init and create_surface have been called.
142+ /// - window_id is a valid ID returned from create_surface.
143+ /// - This is called from the same thread as init.
144+ #[ unsafe( no_mangle) ]
145+ pub extern "C" fn processing_set_stroke_color ( window_id : u64 , r : f32 , g : f32 , b : f32 , a : f32 ) {
146+ error:: clear_error ( ) ;
147+ let window_entity = Entity :: from_bits ( window_id) ;
148+ let color = bevy:: color:: Color :: srgba ( r, g, b, a) ;
149+ error:: check ( || renderer:: record_command ( window_entity, DrawCommand :: StrokeColor ( color) ) ) ;
150+ }
151+
152+ /// Set the stroke weight.
153+ ///
154+ /// SAFETY:
155+ /// - Init and create_surface have been called.
156+ /// - window_id is a valid ID returned from create_surface.
157+ /// - This is called from the same thread as init.
158+ #[ unsafe( no_mangle) ]
159+ pub extern "C" fn processing_set_stroke_weight ( window_id : u64 , weight : f32 ) {
160+ error:: clear_error ( ) ;
161+ let window_entity = Entity :: from_bits ( window_id) ;
162+ error:: check ( || renderer:: record_command ( window_entity, DrawCommand :: StrokeWeight ( weight) ) ) ;
163+ }
164+
165+ /// Disable fill for subsequent shapes.
166+ ///
167+ /// SAFETY:
168+ /// - Init and create_surface have been called.
169+ /// - window_id is a valid ID returned from create_surface.
170+ /// - This is called from the same thread as init.
171+ #[ unsafe( no_mangle) ]
172+ pub extern "C" fn processing_no_fill ( window_id : u64 ) {
173+ error:: clear_error ( ) ;
174+ let window_entity = Entity :: from_bits ( window_id) ;
175+ error:: check ( || renderer:: record_command ( window_entity, DrawCommand :: NoFill ) ) ;
176+ }
177+
178+ /// Disable stroke for subsequent shapes.
179+ ///
180+ /// SAFETY:
181+ /// - Init and create_surface have been called.
182+ /// - window_id is a valid ID returned from create_surface.
183+ /// - This is called from the same thread as init.
184+ #[ unsafe( no_mangle) ]
185+ pub extern "C" fn processing_no_stroke ( window_id : u64 ) {
186+ error:: clear_error ( ) ;
187+ let window_entity = Entity :: from_bits ( window_id) ;
188+ error:: check ( || renderer:: record_command ( window_entity, DrawCommand :: NoStroke ) ) ;
189+ }
190+
191+ /// Draw a rectangle.
192+ ///
193+ /// SAFETY:
194+ /// - Init and create_surface have been called.
195+ /// - window_id is a valid ID returned from create_surface.
196+ /// - This is called from the same thread as init.
197+ #[ unsafe( no_mangle) ]
198+ pub extern "C" fn processing_rect (
199+ window_id : u64 ,
200+ x : f32 ,
201+ y : f32 ,
202+ w : f32 ,
203+ h : f32 ,
204+ tl : f32 ,
205+ tr : f32 ,
206+ br : f32 ,
207+ bl : f32 ,
208+ ) {
209+ error:: clear_error ( ) ;
210+ let window_entity = Entity :: from_bits ( window_id) ;
211+ error:: check ( || {
212+ renderer:: record_command (
213+ window_entity,
214+ DrawCommand :: Rect {
215+ x,
216+ y,
217+ w,
218+ h,
219+ radii : [ tl, tr, br, bl] ,
220+ } ,
221+ )
222+ } ) ;
223+ }
0 commit comments