Line data Source code
1 : /* File: gui_sketch_marker.c; Copyright and License: see below */
2 :
3 : #include "sketch/gui_sketch_marker.h"
4 : #include "u8/u8_trace.h"
5 : #include <stdio.h>
6 : #include <stdlib.h>
7 : #include <assert.h>
8 :
9 : static const double BLACK_R = 0.0;
10 : static const double BLACK_G = 0.0;
11 : static const double BLACK_B = 0.0;
12 : static const double BLACK_A = 1.0;
13 : static const double WHITE_R = 1.0;
14 : static const double WHITE_G = 1.0;
15 : static const double WHITE_B = 1.0;
16 : static const double WHITE_A = 1.0;
17 :
18 : static const double LINE_W = 1.0;
19 :
20 0 : void gui_sketch_marker_prepare_draw ( const gui_sketch_marker_t *this_,
21 : data_id_t element_id,
22 : const gui_marked_set_t *marked_set,
23 : shape_int_rectangle_t rect,
24 : cairo_t *cr )
25 : {
26 0 : const data_id_t focused_id = gui_marked_set_get_focused_obj ( marked_set );
27 0 : const data_id_t highlighted_id = gui_marked_set_get_highlighted ( marked_set );
28 0 : const data_id_t highlighted_diag_id = gui_marked_set_get_highlighted_diagram ( marked_set );
29 0 : const data_small_set_t *const selected_set = gui_marked_set_get_selected_set_const ( marked_set );
30 :
31 0 : const int32_t left = shape_int_rectangle_get_left( &rect );
32 0 : const int32_t top = shape_int_rectangle_get_top( &rect );
33 0 : const uint32_t width = shape_int_rectangle_get_width( &rect );
34 0 : const uint32_t height = shape_int_rectangle_get_height( &rect );
35 :
36 : /* mark highlighted */
37 0 : if (( data_id_equals( &element_id, &highlighted_id ) )
38 0 : ||( data_id_equals( &element_id, &highlighted_diag_id ) ))
39 : {
40 : /* draw a white border around the target rectangle */
41 : {
42 0 : cairo_set_source_rgba( cr, WHITE_R, WHITE_G, WHITE_B, WHITE_A );
43 0 : cairo_rectangle ( cr, left-3, top-1, 2.0*LINE_W, height+2 );
44 0 : cairo_rectangle ( cr, left-3, top-3, width+6, 2.0*LINE_W );
45 0 : cairo_rectangle ( cr, left+width+1, top-1, 2.0*LINE_W, height+2 );
46 0 : cairo_rectangle ( cr, left-3, top+height+1, width+6, 2.0*LINE_W );
47 0 : cairo_fill (cr);
48 : }
49 : }
50 :
51 : /* mark focused diagram */
52 0 : if ( data_id_equals( &element_id, &focused_id ) )
53 : {
54 0 : cairo_set_source_rgba( cr, BLACK_R, BLACK_G, BLACK_B, BLACK_A );
55 0 : cairo_rectangle ( cr, left-2, top-1, LINE_W, height+2 );
56 0 : cairo_rectangle ( cr, left-2, top-2, width+4, LINE_W );
57 0 : cairo_rectangle ( cr, left+width+1, top-1, LINE_W, height+2 );
58 0 : cairo_rectangle ( cr, left-2, top+height+1, width+4, LINE_W );
59 0 : cairo_fill (cr);
60 : }
61 :
62 : /* mark focused */
63 0 : if ( data_id_equals( &element_id, &focused_id ) && (*this_).with_pencil_markers )
64 : {
65 : geometry_rectangle_t pencil_rect;
66 0 : geometry_rectangle_init( &pencil_rect, left, top, width, height );
67 0 : pencil_marker_mark_focused_rectangle( &((*this_).pencil_marker), pencil_rect, cr );
68 : }
69 :
70 : /* mark selected */
71 0 : if ( data_small_set_contains( selected_set, element_id ) && (*this_).with_pencil_markers )
72 : {
73 : geometry_rectangle_t pencil_rect;
74 0 : geometry_rectangle_init( &pencil_rect, left, top, width, height );
75 0 : pencil_marker_mark_selected_rectangle( &((*this_).pencil_marker), pencil_rect, cr );
76 : }
77 :
78 : /* set color to mark highlighted */
79 0 : if ( data_id_equals( &element_id, &highlighted_id ) )
80 : {
81 : /* use same color as in pencil_size.inl */
82 0 : cairo_set_source_rgba( cr, 0.0, 0.6, 0.4, 1.0 );
83 : }
84 : else
85 : {
86 0 : cairo_set_source_rgba( cr, BLACK_R, BLACK_G, BLACK_B, BLACK_A );
87 : }
88 0 : }
89 :
90 :
91 : /*
92 : Copyright 2018-2024 Andreas Warnke
93 :
94 : Licensed under the Apache License, Version 2.0 (the "License");
95 : you may not use this file except in compliance with the License.
96 : You may obtain a copy of the License at
97 :
98 : http://www.apache.org/licenses/LICENSE-2.0
99 :
100 : Unless required by applicable law or agreed to in writing, software
101 : distributed under the License is distributed on an "AS IS" BASIS,
102 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
103 : See the License for the specific language governing permissions and
104 : limitations under the License.
105 : */
|