Debian Codegraph @

pencil/source/pencil_marker.c

raw
1 /* File: pencil_marker.c; Copyright and License: see below */
2
3 #include "pencil_marker.h"
4 #include "u8/u8_trace.h"
5 #include <math.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <assert.h>
9
10 void pencil_marker_init( pencil_marker_t *this_ )
11 {
12 U8_TRACE_BEGIN();
13
14 (*this_).dummy = 0; /* prevent warnings on uninitialized usage */
15
16 U8_TRACE_END();
17 }
18
19 void pencil_marker_destroy( pencil_marker_t *this_ )
20 {
21 U8_TRACE_BEGIN();
22
23 U8_TRACE_END();
24 }
25
26 void pencil_marker_mark_focused_rectangle ( const pencil_marker_t *this_, geometry_rectangle_t rect, cairo_t *cr )
27 {
28 U8_TRACE_BEGIN();
29 assert( NULL != cr );
30
31 static const double YELLOW_BOX_SIZE = 8.0;
32 static const double TOTAL_SIZE = 9.0;
33 static const double LINE_WIDTH = 1.0;
34 static const double GAP = 1.0;
35
36 const double left = floor(geometry_rectangle_get_left ( &rect )); /* floor needed to position on pixel boundary*/
37 const double top = floor(geometry_rectangle_get_top ( &rect ));
38 const double right = floor(geometry_rectangle_get_right ( &rect ));
39 const double bottom = floor(geometry_rectangle_get_bottom ( &rect ));
40
41 /* gray lines */
42 cairo_set_source_rgba( cr, 0.55, 0.55, 0.55, 1.0 );
43
44 cairo_rectangle ( cr, left-GAP-LINE_WIDTH, top-GAP-TOTAL_SIZE, LINE_WIDTH, YELLOW_BOX_SIZE );
45 cairo_rectangle ( cr, left-GAP-TOTAL_SIZE, top-GAP-LINE_WIDTH, TOTAL_SIZE, LINE_WIDTH );
46 cairo_fill (cr);
47
48 cairo_rectangle ( cr, right+GAP, top-GAP-TOTAL_SIZE, LINE_WIDTH, YELLOW_BOX_SIZE );
49 cairo_rectangle ( cr, right+GAP, top-GAP-LINE_WIDTH, TOTAL_SIZE, LINE_WIDTH );
50 cairo_fill (cr);
51
52 cairo_rectangle ( cr, right+GAP, bottom+GAP+LINE_WIDTH, LINE_WIDTH, YELLOW_BOX_SIZE );
53 cairo_rectangle ( cr, right+GAP, bottom+GAP, TOTAL_SIZE, LINE_WIDTH );
54 cairo_fill (cr);
55
56 cairo_rectangle ( cr, left-GAP-LINE_WIDTH, bottom+GAP+LINE_WIDTH, LINE_WIDTH, YELLOW_BOX_SIZE );
57 cairo_rectangle ( cr, left-GAP-TOTAL_SIZE, bottom+GAP, TOTAL_SIZE, LINE_WIDTH );
58 cairo_fill (cr);
59
60 /* yellow box */
61 cairo_set_source_rgba( cr, 0.95, 1.0, 0.0, 1.0 );
62
63 cairo_rectangle ( cr, left-GAP-TOTAL_SIZE, top-GAP-TOTAL_SIZE, YELLOW_BOX_SIZE, YELLOW_BOX_SIZE );
64 cairo_fill (cr);
65
66 cairo_rectangle ( cr, right+GAP+LINE_WIDTH, top-GAP-TOTAL_SIZE, YELLOW_BOX_SIZE, YELLOW_BOX_SIZE );
67 cairo_fill (cr);
68
69 cairo_rectangle ( cr, left-GAP-TOTAL_SIZE, bottom+GAP+LINE_WIDTH, YELLOW_BOX_SIZE, YELLOW_BOX_SIZE );
70 cairo_fill (cr);
71
72 cairo_rectangle ( cr, right+GAP+LINE_WIDTH, bottom+GAP+LINE_WIDTH, YELLOW_BOX_SIZE, YELLOW_BOX_SIZE );
73 cairo_fill (cr);
74
75 U8_TRACE_END();
76 }
77
78 void pencil_marker_mark_selected_rectangle ( const pencil_marker_t *this_, geometry_rectangle_t rect, cairo_t *cr )
79 {
80 U8_TRACE_BEGIN();
81 assert( NULL != cr );
82
83 static const double EXPAND_OVER_BORDER = 2.0;
84 static const double INNER_EDGE = 8.0;
85
86 const double left = floor(geometry_rectangle_get_left ( &rect )); /* floor needed to position on pixel boundary*/
87 const double top = floor(geometry_rectangle_get_top ( &rect ));
88 const double right = floor(geometry_rectangle_get_right ( &rect ));
89 const double bottom = floor(geometry_rectangle_get_bottom ( &rect ));
90
91 cairo_set_source_rgba( cr, 1.0, 0.3, 0.8, 1.0 );
92
93 cairo_move_to( cr, left+INNER_EDGE, top-EXPAND_OVER_BORDER );
94 cairo_line_to( cr, left-EXPAND_OVER_BORDER, top-EXPAND_OVER_BORDER );
95 cairo_line_to( cr, left-EXPAND_OVER_BORDER, top+INNER_EDGE );
96 cairo_close_path( cr );
97 cairo_fill (cr);
98
99 cairo_move_to( cr, right-INNER_EDGE, top-EXPAND_OVER_BORDER );
100 cairo_line_to( cr, right+EXPAND_OVER_BORDER, top-EXPAND_OVER_BORDER );
101 cairo_line_to( cr, right+EXPAND_OVER_BORDER, top+INNER_EDGE );
102 cairo_close_path( cr );
103 cairo_fill (cr);
104
105 cairo_move_to( cr, right-INNER_EDGE, bottom+EXPAND_OVER_BORDER );
106 cairo_line_to( cr, right+EXPAND_OVER_BORDER, bottom+EXPAND_OVER_BORDER );
107 cairo_line_to( cr, right+EXPAND_OVER_BORDER, bottom-INNER_EDGE );
108 cairo_close_path( cr );
109 cairo_fill (cr);
110
111 cairo_move_to( cr, left-EXPAND_OVER_BORDER, bottom-INNER_EDGE );
112 cairo_line_to( cr, left-EXPAND_OVER_BORDER, bottom+EXPAND_OVER_BORDER );
113 cairo_line_to( cr, left+INNER_EDGE, bottom+EXPAND_OVER_BORDER );
114 cairo_close_path( cr );
115 cairo_fill (cr);
116
117 const double width = right-left;
118 static const double LINE_LENGTH = 16.0;
119 static const double LINE_WIDTH = 1.0;
120 if ( width > 2.0*EXPAND_OVER_BORDER + LINE_LENGTH )
121 {
122 cairo_rectangle ( cr, left, bottom + EXPAND_OVER_BORDER - LINE_WIDTH, LINE_LENGTH, LINE_WIDTH );
123 cairo_rectangle ( cr, right - LINE_LENGTH, bottom + EXPAND_OVER_BORDER - LINE_WIDTH, LINE_LENGTH, LINE_WIDTH );
124 cairo_fill (cr);
125 cairo_rectangle ( cr, left, top - EXPAND_OVER_BORDER, LINE_LENGTH, LINE_WIDTH );
126 cairo_rectangle ( cr, right - LINE_LENGTH, top - EXPAND_OVER_BORDER, LINE_LENGTH, LINE_WIDTH );
127 cairo_fill (cr);
128 }
129 const double height = bottom-top;
130 if ( height > 2.0*EXPAND_OVER_BORDER + LINE_LENGTH )
131 {
132 cairo_rectangle ( cr, left - EXPAND_OVER_BORDER, top, LINE_WIDTH, LINE_LENGTH );
133 cairo_rectangle ( cr, left - EXPAND_OVER_BORDER, bottom - LINE_LENGTH, LINE_WIDTH, LINE_LENGTH );
134 cairo_fill (cr);
135 cairo_rectangle ( cr, right + EXPAND_OVER_BORDER - LINE_WIDTH, top, LINE_WIDTH, LINE_LENGTH );
136 cairo_rectangle ( cr, right + EXPAND_OVER_BORDER - LINE_WIDTH, bottom - LINE_LENGTH, LINE_WIDTH, LINE_LENGTH );
137 cairo_fill (cr);
138 }
139
140 U8_TRACE_END();
141 }
142
143
144 /*
145 Copyright 2016-2026 Andreas Warnke
146
147 Licensed under the Apache License, Version 2.0 (the "License");
148 you may not use this file except in compliance with the License.
149 You may obtain a copy of the License at
150
151 http://www.apache.org/licenses/LICENSE-2.0
152
153 Unless required by applicable law or agreed to in writing, software
154 distributed under the License is distributed on an "AS IS" BASIS,
155 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
156 See the License for the specific language governing permissions and
157 limitations under the License.
158 */