1
- /************************************************************/ / **
1
+ /*********************************************************************** **
2
2
*
3
- * @file: cheatsheet_graphics.h
4
- * @author: Martin Fouilleul
5
- * @date: 05/09/2023
3
+ * Orca
4
+ * Copyright 2023 Martin Fouilleul and the Orca project contributors
5
+ * See LICENSE.txt for licensing information
6
6
*
7
- *****************************************************************/
7
+ ************************************************************************** /
8
8
9
9
//------------------------------------------------------------------------------------------
10
- // graphics surface
10
+ //graphics surface
11
11
//------------------------------------------------------------------------------------------
12
12
oc_surface oc_surface_nil (void );
13
13
bool oc_surface_is_nil (oc_surface surface );
14
- oc_surface oc_surface_canvas ();
15
- oc_surface oc_surface_gles ();
16
- void oc_surface_destroy (oc_surface surface );
17
14
18
- void oc_surface_select (oc_surface surface );
19
- void oc_surface_deselect (void );
20
- void oc_surface_present (oc_surface surface );
15
+ void oc_surface_destroy (oc_surface surface );
21
16
22
17
oc_vec2 oc_surface_get_size (oc_surface surface );
23
18
oc_vec2 oc_surface_contents_scaling (oc_surface surface );
24
19
void oc_surface_bring_to_front (oc_surface surface );
25
20
void oc_surface_send_to_back (oc_surface surface );
21
+ bool oc_surface_get_hidden (oc_surface surface );
22
+ void oc_surface_set_hidden (oc_surface surface , bool hidden );
23
+
24
+ oc_surface oc_gles_surface_create (void );
25
+ void oc_gles_surface_make_current (oc_surface surface );
26
+ void oc_gles_surface_swap_interval (oc_surface surface , int interval );
27
+ void oc_gles_surface_swap_buffers (oc_surface surface );
28
+
29
+ //------------------------------------------------------------------------------------------
30
+ //color helpers
31
+ //------------------------------------------------------------------------------------------
32
+ oc_color oc_color_rgba (f32 r , f32 g , f32 b , f32 a );
33
+ oc_color oc_color_srgba (f32 r , f32 g , f32 b , f32 a );
34
+ oc_color oc_color_convert (oc_color color , oc_color_space colorSpace );
35
+
36
+ //------------------------------------------------------------------------------------------
37
+ //canvas renderer
38
+ //------------------------------------------------------------------------------------------
39
+ oc_canvas_renderer oc_canvas_renderer_nil (void );
40
+ bool oc_canvas_renderer_is_nil (oc_canvas_renderer renderer );
41
+
42
+ oc_canvas_renderer oc_canvas_renderer_create (void );
43
+ void oc_canvas_renderer_destroy (oc_canvas_renderer renderer );
44
+
45
+ void oc_canvas_render (oc_canvas_renderer renderer , oc_canvas_context context , oc_surface surface );
46
+ void oc_canvas_present (oc_canvas_renderer renderer , oc_surface surface );
47
+
48
+ //------------------------------------------------------------------------------------------
49
+ //canvas surface
50
+ //------------------------------------------------------------------------------------------
51
+ oc_surface oc_canvas_surface_create (oc_canvas_renderer renderer );
52
+ void oc_canvas_surface_swap_interval (oc_surface surface , int swap );
53
+
54
+ //------------------------------------------------------------------------------------------
55
+ //canvas context
56
+ //------------------------------------------------------------------------------------------
57
+ oc_canvas_context oc_canvas_context_nil (void );
58
+ bool oc_canvas_context_is_nil (oc_canvas_context context );
59
+
60
+ oc_canvas_context oc_canvas_context_create (void );
61
+ void oc_canvas_context_destroy (oc_canvas_context context );
62
+ oc_canvas_context oc_canvas_context_select (oc_canvas_context context );
63
+
64
+ void oc_canvas_context_set_msaa_sample_count (oc_canvas_context context , u32 sampleCount );
65
+
66
+ //------------------------------------------------------------------------------------------
67
+ //fonts
68
+ //------------------------------------------------------------------------------------------
69
+ oc_font oc_font_nil (void );
70
+ bool oc_font_is_nil (oc_font font );
71
+
72
+ oc_font oc_font_create_from_memory (oc_str8 mem , u32 rangeCount , oc_unicode_range * ranges );
73
+ oc_font oc_font_create_from_file (oc_file file , u32 rangeCount , oc_unicode_range * ranges );
74
+ oc_font oc_font_create_from_path (oc_str8 path , u32 rangeCount , oc_unicode_range * ranges );
75
+
76
+ void oc_font_destroy (oc_font font );
77
+
78
+ oc_str32 oc_font_get_glyph_indices (oc_font font , oc_str32 codePoints , oc_str32 backing );
79
+ oc_str32 oc_font_push_glyph_indices (oc_arena * arena , oc_font font , oc_str32 codePoints );
80
+ u32 oc_font_get_glyph_index (oc_font font , oc_utf32 codePoint );
81
+
82
+ // metrics
83
+ oc_font_metrics oc_font_get_metrics (oc_font font , f32 emSize );
84
+ oc_font_metrics oc_font_get_metrics_unscaled (oc_font font );
85
+ f32 oc_font_get_scale_for_em_pixels (oc_font font , f32 emSize );
86
+
87
+ oc_text_metrics oc_font_text_metrics_utf32 (oc_font font , f32 fontSize , oc_str32 codepoints );
88
+ oc_text_metrics oc_font_text_metrics (oc_font font , f32 fontSize , oc_str8 text );
26
89
27
90
//------------------------------------------------------------------------------------------
28
- // 2D canvas command buffer
91
+ //images
29
92
//------------------------------------------------------------------------------------------
30
- oc_canvas oc_canvas_nil (void );
31
- bool oc_canvas_is_nil (oc_canvas canvas );
32
- oc_canvas oc_canvas_create (void );
33
- void oc_canvas_destroy (oc_canvas canvas );
34
- oc_canvas oc_canvas_set_current (oc_canvas canvas );
35
- void oc_render (oc_canvas canvas );
93
+ oc_image oc_image_nil (void );
94
+ bool oc_image_is_nil (oc_image a );
95
+ oc_image oc_image_create (oc_canvas_renderer renderer , u32 width , u32 height );
96
+ oc_image oc_image_create_from_rgba8 (oc_canvas_renderer renderer , u32 width , u32 height , u8 * pixels );
97
+ oc_image oc_image_create_from_memory (oc_canvas_renderer renderer , oc_str8 mem , bool flip );
98
+ oc_image oc_image_create_from_file (oc_canvas_renderer renderer , oc_file file , bool flip );
99
+ oc_image oc_image_create_from_path (oc_canvas_renderer renderer , oc_str8 path , bool flip );
100
+ void oc_image_destroy (oc_image image );
101
+ void oc_image_upload_region_rgba8 (oc_image image , oc_rect region , u8 * pixels );
102
+ oc_vec2 oc_image_size (oc_image image );
36
103
37
104
//------------------------------------------------------------------------------------------
38
- // transform and clipping
105
+ //atlasing
39
106
//------------------------------------------------------------------------------------------
40
107
108
+ oc_rect_atlas * oc_rect_atlas_create (oc_arena * arena , i32 width , i32 height );
109
+ oc_rect oc_rect_atlas_alloc (oc_rect_atlas * atlas , i32 width , i32 height );
110
+ void oc_rect_atlas_recycle (oc_rect_atlas * atlas , oc_rect rect );
111
+ oc_image_region oc_image_atlas_alloc_from_rgba8 (oc_rect_atlas * atlas , oc_image backingImage , u32 width , u32 height , u8 * pixels );
112
+ oc_image_region oc_image_atlas_alloc_from_memory (oc_rect_atlas * atlas , oc_image backingImage , oc_str8 mem , bool flip );
113
+ oc_image_region oc_image_atlas_alloc_from_file (oc_rect_atlas * atlas , oc_image backingImage , oc_file file , bool flip );
114
+ oc_image_region oc_image_atlas_alloc_from_path (oc_rect_atlas * atlas , oc_image backingImage , oc_str8 path , bool flip );
115
+ void oc_image_atlas_recycle (oc_rect_atlas * atlas , oc_image_region imageRgn );
116
+
117
+ //------------------------------------------------------------------------------------------
118
+ //transform, viewport and clipping
119
+ //------------------------------------------------------------------------------------------
41
120
void oc_matrix_push (oc_mat2x3 matrix );
42
121
void oc_matrix_multiply_push (oc_mat2x3 matrix );
43
122
void oc_matrix_pop (void );
44
123
oc_mat2x3 oc_matrix_top ();
45
-
46
124
void oc_clip_push (f32 x , f32 y , f32 w , f32 h );
47
125
void oc_clip_pop (void );
48
126
oc_rect oc_clip_top ();
49
127
50
128
//------------------------------------------------------------------------------------------
51
- // graphics attributes setting/getting
129
+ //graphics attributes setting/getting
52
130
//------------------------------------------------------------------------------------------
53
131
void oc_set_color (oc_color color );
54
132
void oc_set_color_rgba (f32 r , f32 g , f32 b , f32 a );
133
+ void oc_set_color_srgba (f32 r , f32 g , f32 b , f32 a );
134
+ void oc_set_gradient (oc_gradient_blend_space blendSpace , oc_color bottomLeft , oc_color bottomRight , oc_color topRight , oc_color topLeft );
55
135
void oc_set_width (f32 width );
56
136
void oc_set_tolerance (f32 tolerance );
57
137
void oc_set_joint (oc_joint_type joint );
@@ -73,9 +153,10 @@ oc_font oc_get_font(void);
73
153
f32 oc_get_font_size (void );
74
154
bool oc_get_text_flip (void );
75
155
oc_image oc_get_image ();
156
+ oc_rect oc_get_image_source_region ();
76
157
77
158
//------------------------------------------------------------------------------------------
78
- // path construction
159
+ //path construction
79
160
//------------------------------------------------------------------------------------------
80
161
oc_vec2 oc_get_position (void );
81
162
void oc_move_to (f32 x , f32 y );
@@ -89,14 +170,14 @@ void oc_codepoints_outlines(oc_str32 string);
89
170
void oc_text_outlines (oc_str8 string );
90
171
91
172
//------------------------------------------------------------------------------------------
92
- // clear/fill/stroke
173
+ //clear/fill/stroke
93
174
//------------------------------------------------------------------------------------------
94
175
void oc_clear (void );
95
176
void oc_fill (void );
96
177
void oc_stroke (void );
97
178
98
179
//------------------------------------------------------------------------------------------
99
- // shapes helpers
180
+ //shapes helpers
100
181
//------------------------------------------------------------------------------------------
101
182
void oc_rectangle_fill (f32 x , f32 y , f32 w , f32 h );
102
183
void oc_rectangle_stroke (f32 x , f32 y , f32 w , f32 h );
@@ -107,60 +188,9 @@ void oc_ellipse_stroke(f32 x, f32 y, f32 rx, f32 ry);
107
188
void oc_circle_fill (f32 x , f32 y , f32 r );
108
189
void oc_circle_stroke (f32 x , f32 y , f32 r );
109
190
void oc_arc (f32 x , f32 y , f32 r , f32 arcAngle , f32 startAngle );
110
- void oc_image_draw (oc_image image , oc_rect rect );
111
- void oc_image_draw_region (oc_image image , oc_rect srcRegion , oc_rect dstRegion );
112
-
113
- //------------------------------------------------------------------------------------------
114
- // fonts
115
- //------------------------------------------------------------------------------------------
116
- oc_font oc_font_nil (void );
117
- bool oc_font_is_nil (oc_font font );
118
191
119
- oc_font oc_font_create_from_memory (oc_str8 mem , u32 rangeCount , oc_unicode_range * ranges );
120
- oc_font oc_font_create_from_file (oc_file file , u32 rangeCount , oc_unicode_range * ranges );
121
- oc_font oc_font_create_from_path (oc_str8 path , u32 rangeCount , oc_unicode_range * ranges );
122
-
123
- void oc_font_destroy (oc_font font );
124
-
125
- oc_str32 oc_font_get_glyph_indices (oc_font font , oc_str32 codePoints , oc_str32 backing );
126
- oc_str32 oc_font_push_glyph_indices (oc_arena * arena , oc_font font , oc_str32 codePoints );
127
- u32 oc_font_get_glyph_index (oc_font font , oc_utf32 codePoint );
128
-
129
- oc_font_metrics oc_font_get_metrics (oc_font font , f32 emSize );
130
- oc_font_metrics oc_font_get_metrics_unscaled (oc_font font );
131
- f32 oc_font_get_scale_for_em_pixels (oc_font font , f32 emSize );
132
-
133
- oc_text_metrics oc_font_text_metrics_utf32 (oc_font font , f32 fontSize , oc_str32 codepoints );
134
- oc_text_metrics oc_font_text_metrics (oc_font font , f32 fontSize , oc_str8 text );
192
+ void oc_text_fill (f32 x , f32 y , oc_str8 text );
135
193
136
- //------------------------------------------------------------------------------------------
137
- // images
138
- //------------------------------------------------------------------------------------------
139
- oc_image oc_image_nil (void );
140
- bool oc_image_is_nil (oc_image a );
141
-
142
- oc_image oc_image_create (oc_surface surface , u32 width , u32 height );
143
- oc_image oc_image_create_from_rgba8 (oc_surface surface , u32 width , u32 height , u8 * pixels );
144
- oc_image oc_image_create_from_memory (oc_surface surface , oc_str8 mem , bool flip );
145
- oc_image oc_image_create_from_file (oc_surface surface , oc_file file , bool flip );
146
- oc_image oc_image_create_from_path (oc_surface surface , oc_str8 path , bool flip );
147
-
148
- void oc_image_destroy (oc_image image );
149
-
150
- void oc_image_upload_region_rgba8 (oc_image image , oc_rect region , u8 * pixels );
151
- oc_vec2 oc_image_size (oc_image image );
152
-
153
- //------------------------------------------------------------------------------------------
154
- // image atlas
155
- //------------------------------------------------------------------------------------------
156
-
157
- oc_rect_atlas * oc_rect_atlas_create (oc_arena * arena , i32 width , i32 height );
158
- oc_rect oc_rect_atlas_alloc (oc_rect_atlas * atlas , i32 width , i32 height );
159
- void oc_rect_atlas_recycle (oc_rect_atlas * atlas , oc_rect rect );
160
-
161
- oc_image_region oc_image_atlas_alloc_from_rgba8 (oc_rect_atlas * atlas , oc_image backingImage , u32 width , u32 height , u8 * pixels );
162
- oc_image_region oc_image_atlas_alloc_from_memory (oc_rect_atlas * atlas , oc_image backingImage , oc_str8 mem , bool flip );
163
- oc_image_region oc_image_atlas_alloc_from_file (oc_rect_atlas * atlas , oc_image backingImage , oc_file file , bool flip );
164
- oc_image_region oc_image_atlas_alloc_from_path (oc_rect_atlas * atlas , oc_image backingImage , oc_str8 path , bool flip );
165
-
166
- void oc_image_atlas_recycle (oc_rect_atlas * atlas , oc_image_region imageRgn );
194
+ //NOTE: image helpers
195
+ void oc_image_draw (oc_image image , oc_rect rect );
196
+ void oc_image_draw_region (oc_image image , oc_rect srcRegion , oc_rect dstRegion );
0 commit comments