Line data Source code
1 : /* File: gui_sketch_area.inl; Copyright and License: see below */
2 :
3 : #include "u8/u8_log.h"
4 : #include <assert.h>
5 :
6 0 : static inline data_diagram_t *gui_sketch_area_private_get_focused_diagram_ptr ( gui_sketch_area_t *this_ )
7 : {
8 : gui_sketch_card_t *result_card;
9 0 : result_card = &((*this_).cards[GUI_SKETCH_AREA_CONST_FOCUSED_CARD]);
10 0 : return gui_sketch_card_get_diagram_ptr( result_card );
11 : }
12 :
13 0 : static inline data_row_t gui_sketch_area_private_get_focused_diagram_id ( gui_sketch_area_t *this_ )
14 : {
15 0 : const data_diagram_t *focused_diag = gui_sketch_area_private_get_focused_diagram_ptr( this_ );
16 0 : const data_row_t focused_diagram_id = data_diagram_get_row_id( focused_diag );
17 0 : return focused_diagram_id;
18 : }
19 :
20 0 : static inline void gui_sketch_area_private_get_diagram_and_object_id_at_pos ( gui_sketch_area_t *this_,
21 : int32_t x,
22 : int32_t y,
23 : data_id_t* out_diagram_id,
24 : data_id_t* out_object_id )
25 : {
26 0 : assert( NULL != out_diagram_id );
27 0 : assert( NULL != out_object_id );
28 0 : assert( (*this_).card_num <= GUI_SKETCH_AREA_CONST_MAX_CARDS );
29 0 : data_id_reinit_void( out_diagram_id );
30 0 : data_id_reinit_void( out_object_id );
31 :
32 0 : if ( gui_sketch_nav_tree_is_visible( &((*this_).nav_tree) ) )
33 : {
34 0 : gui_sketch_nav_tree_get_object_id_at_pos( &((*this_).nav_tree), x, y, out_diagram_id );
35 0 : data_id_replace( out_object_id, out_diagram_id );
36 : }
37 0 : else if ( gui_sketch_result_list_is_visible( &((*this_).result_list) ) )
38 : {
39 0 : gui_sketch_result_list_get_object_id_at_pos ( &((*this_).result_list),
40 : x,
41 : y,
42 : out_object_id, /* = out_selected_id */
43 : out_diagram_id /* = out_diagram_id */
44 : );
45 : }
46 :
47 0 : for ( int idx = 0; idx < (*this_).card_num; idx ++ )
48 : {
49 0 : const gui_sketch_card_t *card = &((*this_).cards[idx]);
50 0 : const shape_int_rectangle_t card_bounds = gui_sketch_card_get_bounds( card );
51 0 : if ( shape_int_rectangle_contains( &card_bounds, x, y ) )
52 : {
53 : const data_diagram_t *selected_diag
54 0 : = gui_sketch_card_get_diagram_const( card );
55 0 : data_id_reinit( out_diagram_id, DATA_TABLE_DIAGRAM, data_diagram_get_row_id( selected_diag ) );
56 0 : data_id_replace( out_object_id, out_diagram_id );
57 0 : break;
58 : }
59 : }
60 0 : }
61 :
62 0 : static inline void gui_sketch_area_private_get_element_id_at_pos ( gui_sketch_area_t *this_,
63 : int32_t x,
64 : int32_t y,
65 : bool filter_lifelines,
66 : data_full_id_t* out_element_id,
67 : data_id_t* out_diagram_id )
68 : {
69 0 : assert( (*this_).card_num <= GUI_SKETCH_AREA_CONST_MAX_CARDS );
70 0 : assert( NULL != out_element_id );
71 0 : assert( NULL != out_diagram_id );
72 0 : data_full_id_reinit_void( out_element_id );
73 0 : data_id_reinit_void( out_diagram_id );
74 :
75 0 : for ( int idx = 0; idx < (*this_).card_num; idx ++ )
76 : {
77 0 : const gui_sketch_card_t *const card = &((*this_).cards[idx]);
78 0 : const shape_int_rectangle_t card_bounds = gui_sketch_card_get_bounds( card );
79 0 : if ( shape_int_rectangle_contains( &card_bounds, x, y ) )
80 : {
81 0 : *out_diagram_id = gui_sketch_card_get_diagram_id( card );
82 : const layout_subelement_id_t subelement
83 0 : = gui_sketch_card_get_element_at_pos( card, x, y, filter_lifelines );
84 0 : if ( LAYOUT_SUBELEMENT_KIND_SPACE == layout_subelement_id_get_kind( &subelement ) )
85 : {
86 : /* do not report space areas, in EDIT mode these are of no concern, */
87 : /* in CREATE mode during dragging, these are also of no concern. */
88 : }
89 : else
90 : {
91 0 : data_full_id_replace( out_element_id, layout_subelement_id_get_id_const( &subelement ) );
92 : }
93 0 : break;
94 : }
95 : }
96 0 : }
97 :
98 0 : static inline gui_sketch_card_t *gui_sketch_area_private_get_card_at_pos ( gui_sketch_area_t *this_, int32_t x, int32_t y )
99 : {
100 0 : assert( (*this_).card_num <= GUI_SKETCH_AREA_CONST_MAX_CARDS );
101 0 : gui_sketch_card_t *result = NULL;
102 :
103 0 : for ( int idx = 0; idx < (*this_).card_num; idx ++ )
104 : {
105 0 : gui_sketch_card_t *card = &((*this_).cards[idx]);
106 0 : const shape_int_rectangle_t card_bounds = gui_sketch_card_get_bounds( card );
107 0 : if ( shape_int_rectangle_contains( &card_bounds, x, y ) )
108 : {
109 0 : result = card;
110 0 : break;
111 : }
112 : }
113 0 : return result;
114 : }
115 :
116 :
117 : /*
118 : Copyright 2016-2025 Andreas Warnke
119 :
120 : Licensed under the Apache License, Version 2.0 (the "License");
121 : you may not use this file except in compliance with the License.
122 : You may obtain a copy of the License at
123 :
124 : http://www.apache.org/licenses/LICENSE-2.0
125 :
126 : Unless required by applicable law or agreed to in writing, software
127 : distributed under the License is distributed on an "AS IS" BASIS,
128 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
129 : See the License for the specific language governing permissions and
130 : limitations under the License.
131 : */
|