@@ -48,7 +48,7 @@ Board *board_create(int width, int height) {
4848
4949 cairo_t * canvas = cairo_create (cr_surface );
5050
51- SDL_SetRenderDrawColor (renderer , BOARD_BG );
51+ SDL_SetRenderDrawColor (renderer , BOARD_BG_CAIRO );
5252 SDL_RenderClear (renderer );
5353
5454 if (canvas == NULL )
@@ -68,12 +68,6 @@ Board *board_create(int width, int height) {
6868 if (strokes == NULL )
6969 goto defer ;
7070
71- #ifdef USE_TOOLBAR
72- ToolBar * toolbar = toolbar_create (50 , sdl_surface -> format );
73- if (toolbar == NULL )
74- goto defer ;
75- #endif
76-
7771 board -> window = window ;
7872 board -> renderer = renderer ;
7973 board -> sdl_surface = sdl_surface ;
@@ -84,21 +78,14 @@ Board *board_create(int width, int height) {
8478 board -> cr = canvas ;
8579 board -> width = window_width ;
8680 board -> height = window_height ;
87- #ifdef USE_TOOLBAR
88- board -> toolbar = toolbar ;
89- #endif
9081 board -> current_stroke_points = current_stroke_points ;
9182 board -> current_stroke_paths = current_stroke_paths ;
9283 board -> strokes = strokes ;
9384 board -> dx = 0 ;
9485 board -> dy = 0 ;
95- #ifdef USE_TOOLBAR
96- board -> stroke_width = get_width (toolbar -> selected_width );
97- board -> stroke_color = get_color (toolbar -> selected_color );
98- #else
99- board -> stroke_width = get_width (STROKE_WIDTH_MEDIUM );
100- board -> stroke_color = get_color (COLOR_PRIMARY );
101- #endif
86+ board -> stroke_width = STROKE_WIDTH_MEDIUM ;
87+ board -> stroke_color = COLOR_PRIMARY ;
88+ board -> stroke_width_previous = board -> stroke_width ;
10289 board -> mouse_x = 0 ;
10390 board -> mouse_x_raw = 0 ;
10491 board -> mouse_y = 0 ;
@@ -127,10 +114,6 @@ Board *board_create(int width, int height) {
127114 vector_free (current_stroke_paths );
128115 if (strokes != NULL )
129116 vector_free (strokes );
130- #ifdef USE_TOOLBAR
131- if (toolbar != NULL )
132- toolbar_free (toolbar );
133- #endif
134117 if (default_cursor != NULL )
135118 SDL_FreeCursor (default_cursor );
136119 return NULL ;
@@ -150,17 +133,11 @@ void board_free(Board *board) {
150133 SDL_DestroyRenderer (board -> renderer );
151134 SDL_DestroyWindow (board -> window );
152135
153- #ifdef USE_TOOLBAR
154- toolbar_free (board -> toolbar );
155- #endif
156136 free (board );
157137}
158138
159139void board_resize_surface (Board * board ) {
160140 SDL_GetWindowSize (board -> window , & board -> width , & board -> height );
161- #ifdef USE_TOOLBAR
162- board_update_toolbar_area (board );
163- #endif
164141
165142 int renderer_width ;
166143 int renderer_height ;
@@ -206,7 +183,7 @@ void board_resize_surface(Board *board) {
206183}
207184
208185void board_clear (Board * board ) {
209- cairo_set_source_rgba (board -> cr , BOARD_BG );
186+ cairo_set_source_rgba (board -> cr , BOARD_BG_CAIRO );
210187 cairo_paint (board -> cr );
211188 cairo_fill (board -> cr );
212189}
@@ -231,16 +208,6 @@ void board_render(Board *board, SDL_Rect *update_area) {
231208 }
232209 SDL_UpdateTexture (board -> sdl_texture , update_area , data , board -> sdl_surface -> pitch );
233210
234- #ifdef USE_TOOLBAR
235- SDL_Rect result ;
236- bool is_intersecting = SDL_IntersectRect (update_area , & board -> toolbar_area , & result ) == SDL_TRUE ;
237- if (board -> toolbar -> visible && (is_intersecting || update_area == NULL )) {
238- toolbar_render (board -> toolbar );
239- // draw toolbar on texture
240- unsigned char * toolbar_data = cairo_image_surface_get_data (board -> toolbar -> cr_surface );
241- SDL_UpdateTexture (board -> sdl_texture , & board -> toolbar_area , toolbar_data , board -> toolbar -> pitch );
242- }
243- #endif
244211 SDL_RenderClear (board -> renderer );
245212 SDL_RenderCopy (board -> renderer , board -> sdl_texture , NULL , NULL );
246213 SDL_RenderPresent (board -> renderer );
@@ -329,6 +296,18 @@ void board_update_cursor(Board *board) {
329296 cairo_arc (cr , w / 2 , h / 2 , 0 , 0 , M_PI * 2 );
330297 cairo_stroke (cr );
331298
299+ // if stroke_color is the same as the background color
300+ // add an outline to the cursor
301+ if (board -> stroke_color == BOARD_BG ) {
302+ Uint8 r , g , b , a ;
303+ SDL_GetRGBA (BOARD_BG_INVERTED , cursor_surface -> format , & r , & g , & b , & a );
304+ cairo_set_source_rgba (cr , r / 255.0 , g / 255.0 , b / 255.0 , a / 255.0 );
305+
306+ cairo_set_line_width (cr , 2 );
307+ cairo_arc (cr , w / 2 , h / 2 , width / 2 , 0 , M_PI * 2 );
308+ cairo_stroke (cr );
309+ }
310+
332311 // render to sdl surface
333312 unsigned char * data = cairo_image_surface_get_data (cr_surface );
334313 Uint32 * cursor_surface_pixels = cursor_surface -> pixels ;
@@ -347,52 +326,19 @@ void board_update_cursor(Board *board) {
347326 SDL_FreeSurface (cursor_surface );
348327}
349328
350- #ifdef USE_TOOLBAR
351- void board_update_toolbar_area (Board * board ) {
352- SDL_Rect toolbar_area = {
353- .x = (board -> width - board -> toolbar -> width ) / 2 ,
354- .y = board -> height - board -> toolbar -> height ,
355- .w = board -> toolbar -> width ,
356- .h = board -> toolbar -> height ,
357- };
358- board -> toolbar_area = toolbar_area ;
359- }
360-
361- void board_click_toolbar (Board * board , double x ) {
362- int color , width ;
363- toolbar_select_button (board -> toolbar , x - board -> toolbar_area .x , & width , & color );
364- if (width >= 0 ) {
365- board -> stroke_width = get_width (width );
366- }
367-
368- if (color >= 0 ) {
369- board -> stroke_color = get_color (color );
370- }
371-
372- board_update_cursor (board );
373- board_refresh (board );
374- }
375- #endif
376-
377329void board_reset_current_stroke (Board * board ) {
378330 vector_reset (board -> current_stroke_points );
379331 vector_reset (board -> current_stroke_paths );
380332}
381333
382- void board_set_stroke_width (Board * board , StrokeWidth width ) {
383- #ifdef USE_TOOLBAR
384- board -> toolbar -> selected_width = width ;
385- #endif
386- board -> stroke_width = get_width (width );
334+ void board_set_stroke_width (Board * board , double width ) {
335+ board -> stroke_width = width ;
387336 board_update_cursor (board );
388337 board_refresh (board );
389338}
390339
391- void board_set_stroke_color (Board * board , Color color ) {
392- #ifdef USE_TOOLBAR
393- board -> toolbar -> selected_color = color ;
394- #endif
395- board -> stroke_color = get_color (color );
340+ void board_set_stroke_color (Board * board , unsigned int color ) {
341+ board -> stroke_color = color ;
396342 board_update_cursor (board );
397343 board_refresh (board );
398344}
0 commit comments