| 1 |
|
| 2 |
|
| 3 |
#include "sketch/gui_sketch_nav_tree.h" |
| 4 |
#include "geometry/geometry_rectangle.h" |
| 5 |
#include "u8/u8_trace.h" |
| 6 |
#include "u8/u8_log.h" |
| 7 |
#include "u8/u8_i32.h" |
| 8 |
#include "gui_gdk.h" |
| 9 |
|
| 10 |
static const int GUI_SKETCH_NAV_TREE_INDENT = 12; |
| 11 |
static const int OBJ_GAP = 3; |
| 12 |
static const int GAP_HEIGHT = 2; |
| 13 |
static const int GUI_SKETCH_NAV_TREE_PANGO_AUTO_DETECT_LENGTH = -1; |
| 14 |
|
| 15 |
void gui_sketch_nav_tree_init( gui_sketch_nav_tree_t *this_, |
| 16 |
const gui_resources_t *resources, |
| 17 |
gui_sketch_texture_t *texture_downloader ) |
| 18 |
{ |
| 19 |
U8_TRACE_BEGIN(); |
| 20 |
assert( resources != NULL ); |
| 21 |
assert( texture_downloader != NULL ); |
| 22 |
|
| 23 |
(*this_).ancestors_count = 0; |
| 24 |
(*this_).siblings_count = 0; |
| 25 |
(*this_).children_count = 0; |
| 26 |
(*this_).siblings_self_index = -1; |
| 27 |
|
| 28 |
(*this_).node_count = 0; |
| 29 |
(*this_).gap_count = 0; |
| 30 |
|
| 31 |
(*this_).visible = false; |
| 32 |
shape_int_rectangle_init( &((*this_).bounds), 0, 0, 0, 0 ); |
| 33 |
|
| 34 |
gui_sketch_style_init( &((*this_).sketch_style) ); |
| 35 |
gui_sketch_marker_init( &((*this_).sketch_marker), true ); |
| 36 |
(*this_).resources = resources; |
| 37 |
(*this_).texture_downloader = texture_downloader; |
| 38 |
|
| 39 |
U8_TRACE_END(); |
| 40 |
} |
| 41 |
|
| 42 |
void gui_sketch_nav_tree_destroy( gui_sketch_nav_tree_t *this_ ) |
| 43 |
{ |
| 44 |
U8_TRACE_BEGIN(); |
| 45 |
|
| 46 |
(*this_).resources = NULL; |
| 47 |
(*this_).texture_downloader = NULL; |
| 48 |
gui_sketch_marker_destroy( &((*this_).sketch_marker) ); |
| 49 |
gui_sketch_style_destroy( &((*this_).sketch_style) ); |
| 50 |
|
| 51 |
gui_sketch_nav_tree_invalidate_data( this_ ); |
| 52 |
|
| 53 |
shape_int_rectangle_destroy( &((*this_).bounds) ); |
| 54 |
|
| 55 |
U8_TRACE_END(); |
| 56 |
} |
| 57 |
|
| 58 |
void gui_sketch_nav_tree_load_data( gui_sketch_nav_tree_t *this_, data_row_t diagram_id, data_database_reader_t *db_reader ) |
| 59 |
{ |
| 60 |
U8_TRACE_BEGIN(); |
| 61 |
assert( NULL != db_reader ); |
| 62 |
|
| 63 |
gui_sketch_nav_tree_invalidate_data( this_ ); |
| 64 |
|
| 65 |
u8_error_t db_err = U8_ERROR_NONE; |
| 66 |
|
| 67 |
|
| 68 |
bool finished = false; |
| 69 |
for ( unsigned int anc_index = 0; ( anc_index < GUI_SKETCH_NAV_TREE_CONST_MAX_ANCESTORS ) && ( db_err == U8_ERROR_NONE ) && ( ! finished ); anc_index ++ ) |
| 70 |
{ |
| 71 |
data_row_t id_to_load; |
| 72 |
if ( anc_index == 0 ) |
| 73 |
{ |
| 74 |
id_to_load = diagram_id; |
| 75 |
} |
| 76 |
else |
| 77 |
{ |
| 78 |
id_to_load = data_diagram_get_parent_row_id( &((*this_).ancestor_diagrams[anc_index-1]) ); |
| 79 |
} |
| 80 |
|
| 81 |
if ( id_to_load != DATA_ROW_VOID ) |
| 82 |
{ |
| 83 |
db_err = data_database_reader_get_diagram_by_id ( db_reader, id_to_load, &((*this_).ancestor_diagrams[anc_index]) ); |
| 84 |
if ( db_err == U8_ERROR_NONE ) |
| 85 |
{ |
| 86 |
(*this_).ancestors_count = anc_index+1; |
| 87 |
} |
| 88 |
} |
| 89 |
else |
| 90 |
{ |
| 91 |
finished = true; |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
if ( diagram_id != DATA_ROW_VOID ) |
| 96 |
{ |
| 97 |
if ( (*this_).ancestors_count == 0 ) |
| 98 |
{ |
| 99 |
db_err = U8_ERROR_INVALID_REQUEST; |
| 100 |
U8_LOG_ANOMALY_INT( "gui_sketch_nav_tree_load_data cannot load diagram", diagram_id ); |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
if ( db_err == U8_ERROR_NONE ) |
| 106 |
{ |
| 107 |
const data_row_t parent_id |
| 108 |
= ( (*this_).ancestors_count == 0 ) |
| 109 |
? DATA_ROW_VOID |
| 110 |
: data_diagram_get_parent_row_id( &((*this_).ancestor_diagrams[0]) ); |
| 111 |
|
| 112 |
data_diagram_iterator_t diagram_iterator; |
| 113 |
db_err |= data_diagram_iterator_init_empty( &diagram_iterator ); |
| 114 |
db_err |= data_database_reader_get_diagrams_by_parent_id( db_reader, |
| 115 |
parent_id, |
| 116 |
&diagram_iterator |
| 117 |
); |
| 118 |
uint_fast32_t next_idx = 0; |
| 119 |
for ( ; (next_idx < GUI_SKETCH_NAV_TREE_CONST_MAX_SIBLINGS) && data_diagram_iterator_has_next( &diagram_iterator ); next_idx++ ) |
| 120 |
{ |
| 121 |
db_err |= data_diagram_iterator_next( &diagram_iterator, &( (*this_).sibling_diagrams[next_idx] ) ); |
| 122 |
|
| 123 |
if ( diagram_id == data_diagram_get_row_id( &((*this_).sibling_diagrams[next_idx]) ) ) |
| 124 |
{ |
| 125 |
(*this_).siblings_self_index = next_idx; |
| 126 |
} |
| 127 |
} |
| 128 |
(*this_).siblings_count = next_idx; |
| 129 |
if ( data_diagram_iterator_has_next( &diagram_iterator ) ) |
| 130 |
{ |
| 131 |
db_err |= U8_ERROR_ARRAY_BUFFER_EXCEEDED; |
| 132 |
U8_LOG_WARNING_INT( "gui_sketch_nav_tree_load_data finds too many sibling diagrams", GUI_SKETCH_NAV_TREE_CONST_MAX_SIBLINGS ); |
| 133 |
} |
| 134 |
db_err |= data_diagram_iterator_destroy( &diagram_iterator ); |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
if ( db_err == U8_ERROR_NONE ) |
| 139 |
{ |
| 140 |
data_diagram_iterator_t diagram_iterator; |
| 141 |
db_err |= data_diagram_iterator_init_empty( &diagram_iterator ); |
| 142 |
db_err |= data_database_reader_get_diagrams_by_parent_id( db_reader, |
| 143 |
diagram_id, |
| 144 |
&diagram_iterator |
| 145 |
); |
| 146 |
uint_fast32_t next_idx = 0; |
| 147 |
for ( ; (next_idx < GUI_SKETCH_NAV_TREE_CONST_MAX_CHILDREN) && data_diagram_iterator_has_next( &diagram_iterator ); next_idx++ ) |
| 148 |
{ |
| 149 |
db_err |= data_diagram_iterator_next( &diagram_iterator, &( (*this_).child_diagrams[next_idx] ) ); |
| 150 |
} |
| 151 |
(*this_).children_count = next_idx; |
| 152 |
if ( data_diagram_iterator_has_next( &diagram_iterator ) ) |
| 153 |
{ |
| 154 |
db_err |= U8_ERROR_ARRAY_BUFFER_EXCEEDED; |
| 155 |
U8_LOG_WARNING_INT( "gui_sketch_nav_tree_load_data finds too many children diagrams", GUI_SKETCH_NAV_TREE_CONST_MAX_CHILDREN ); |
| 156 |
} |
| 157 |
db_err |= data_diagram_iterator_destroy( &diagram_iterator ); |
| 158 |
} |
| 159 |
|
| 160 |
|
| 161 |
{ |
| 162 |
(*this_).node_count = 0; |
| 163 |
(*this_).gap_count = 0; |
| 164 |
} |
| 165 |
|
| 166 |
U8_TRACE_END(); |
| 167 |
} |
| 168 |
|
| 169 |
void gui_sketch_nav_tree_do_layout( gui_sketch_nav_tree_t *this_, cairo_t *cr ) |
| 170 |
{ |
| 171 |
U8_TRACE_BEGIN(); |
| 172 |
assert( (*this_).ancestors_count <= GUI_SKETCH_NAV_TREE_CONST_MAX_ANCESTORS ); |
| 173 |
assert( (*this_).siblings_count <= GUI_SKETCH_NAV_TREE_CONST_MAX_SIBLINGS ); |
| 174 |
assert( (*this_).children_count <= GUI_SKETCH_NAV_TREE_CONST_MAX_CHILDREN ); |
| 175 |
|
| 176 |
|
| 177 |
PangoLayout *font_layout; |
| 178 |
{ |
| 179 |
font_layout = pango_cairo_create_layout (cr); |
| 180 |
const PangoFontDescription *const std_font |
| 181 |
= gui_sketch_style_get_standard_font_description( &((*this_).sketch_style ) ); |
| 182 |
pango_layout_set_font_description( font_layout, std_font ); |
| 183 |
} |
| 184 |
|
| 185 |
int32_t y_pos = shape_int_rectangle_get_top( &((*this_).bounds) ) + OBJ_GAP; |
| 186 |
const int_fast32_t left = shape_int_rectangle_get_left( &((*this_).bounds) ); |
| 187 |
const uint_fast32_t width = shape_int_rectangle_get_width( &((*this_).bounds) ); |
| 188 |
|
| 189 |
(*this_).node_count = 0; |
| 190 |
(*this_).gap_count = 0; |
| 191 |
|
| 192 |
if ( (*this_).ancestors_count == 0 ) |
| 193 |
{ |
| 194 |
pos_nav_tree_node_t *const new_root_node = &((*this_).node_pos[0]); |
| 195 |
(*this_).node_count = 1; |
| 196 |
|
| 197 |
|
| 198 |
assert( 1 <= GUI_SKETCH_NAV_TREE_CONST_MAX_NODES ); |
| 199 |
pos_nav_tree_node_init( new_root_node, POS_NAV_TREE_NODE_TYPE_NEW_ROOT, NULL ); |
| 200 |
gui_sketch_nav_tree_private_layout_node( this_, new_root_node, 0, &y_pos, font_layout ); |
| 201 |
|
| 202 |
|
| 203 |
assert( 0 == (*this_).gap_count ); |
| 204 |
assert( 1 == (*this_).node_count ); |
| 205 |
} |
| 206 |
else |
| 207 |
{ |
| 208 |
|
| 209 |
const unsigned int anc_count = (*this_).ancestors_count; |
| 210 |
assert( anc_count > 0 ); |
| 211 |
assert( anc_count <= GUI_SKETCH_NAV_TREE_CONST_MAX_ANCESTORS ); |
| 212 |
assert( (*this_).node_count + (anc_count-1) <= GUI_SKETCH_NAV_TREE_CONST_MAX_NODES ); |
| 213 |
for ( unsigned int anc_idx = 1; anc_idx < anc_count; anc_idx ++ ) |
| 214 |
{ |
| 215 |
const data_diagram_t *const anc_diag = &((*this_).ancestor_diagrams[anc_count-anc_idx]); |
| 216 |
|
| 217 |
|
| 218 |
{ |
| 219 |
pos_nav_tree_gap_t *const upper_gap = &((*this_).gap_pos[(*this_).gap_count]); |
| 220 |
(*this_).gap_count ++; |
| 221 |
|
| 222 |
pos_nav_tree_gap_init( upper_gap, data_diagram_get_parent_data_id(anc_diag), 0 ); |
| 223 |
const int indent = (anc_idx-1) * GUI_SKETCH_NAV_TREE_INDENT; |
| 224 |
|
| 225 |
pos_nav_tree_gap_set_gap_box_coords( upper_gap, left+indent, y_pos, width-indent, GAP_HEIGHT ); |
| 226 |
y_pos += GAP_HEIGHT; |
| 227 |
} |
| 228 |
|
| 229 |
|
| 230 |
{ |
| 231 |
pos_nav_tree_node_t *const anc_node = &((*this_).node_pos[(*this_).node_count]); |
| 232 |
(*this_).node_count ++; |
| 233 |
|
| 234 |
const pos_nav_tree_node_type_t n_type |
| 235 |
= ((anc_idx+1)==anc_count) ? POS_NAV_TREE_NODE_TYPE_OPEN : POS_NAV_TREE_NODE_TYPE_ANCESTOR; |
| 236 |
pos_nav_tree_node_init( anc_node, n_type, anc_diag ); |
| 237 |
gui_sketch_nav_tree_private_layout_node( this_, anc_node, (anc_idx-1), &y_pos, font_layout ); |
| 238 |
} |
| 239 |
} |
| 240 |
|
| 241 |
const unsigned int tree_depth = (*this_).ancestors_count-1; |
| 242 |
|
| 243 |
|
| 244 |
const unsigned int sibl_count = (*this_).siblings_count; |
| 245 |
assert( sibl_count > 0 ); |
| 246 |
assert( sibl_count <= GUI_SKETCH_NAV_TREE_CONST_MAX_SIBLINGS ); |
| 247 |
const unsigned int child_count = (*this_).children_count; |
| 248 |
assert( child_count <= GUI_SKETCH_NAV_TREE_CONST_MAX_CHILDREN ); |
| 249 |
assert( (*this_).node_count + sibl_count + child_count + 2 <= GUI_SKETCH_NAV_TREE_CONST_MAX_NODES ); |
| 250 |
int32_t previous_sibl_order = INT32_MIN; |
| 251 |
for ( unsigned int sibl_idx = 0; sibl_idx < sibl_count; sibl_idx ++ ) |
| 252 |
{ |
| 253 |
const data_diagram_t *const sibl_diag = &((*this_).sibling_diagrams[sibl_idx]); |
| 254 |
const bool is_self = ( sibl_idx == (*this_).siblings_self_index ); |
| 255 |
|
| 256 |
|
| 257 |
{ |
| 258 |
pos_nav_tree_gap_t *const upper_gap = &((*this_).gap_pos[(*this_).gap_count]); |
| 259 |
(*this_).gap_count ++; |
| 260 |
|
| 261 |
const int32_t gap_sibl_order |
| 262 |
= (previous_sibl_order/2)+(data_diagram_get_list_order( sibl_diag )/2); |
| 263 |
pos_nav_tree_gap_init( upper_gap, data_diagram_get_parent_data_id(sibl_diag), gap_sibl_order ); |
| 264 |
const int indent = tree_depth * GUI_SKETCH_NAV_TREE_INDENT; |
| 265 |
pos_nav_tree_gap_set_gap_box_coords( upper_gap, left+indent, y_pos, width-indent, GAP_HEIGHT ); |
| 266 |
y_pos += GAP_HEIGHT; |
| 267 |
} |
| 268 |
|
| 269 |
|
| 270 |
{ |
| 271 |
pos_nav_tree_node_t *const sibl_node = &((*this_).node_pos[(*this_).node_count]); |
| 272 |
(*this_).node_count ++; |
| 273 |
|
| 274 |
const pos_nav_tree_node_type_t n_type = is_self ? POS_NAV_TREE_NODE_TYPE_OPEN : POS_NAV_TREE_NODE_TYPE_CLOSED; |
| 275 |
pos_nav_tree_node_init( sibl_node, n_type, sibl_diag ); |
| 276 |
gui_sketch_nav_tree_private_layout_node( this_, sibl_node, tree_depth, &y_pos, font_layout ); |
| 277 |
} |
| 278 |
|
| 279 |
|
| 280 |
if ( is_self ) |
| 281 |
{ |
| 282 |
int32_t prev_child_order = INT32_MIN; |
| 283 |
for ( unsigned int chld_idx = 0; chld_idx < child_count; chld_idx ++ ) |
| 284 |
{ |
| 285 |
const data_diagram_t *const chld_diag = &((*this_).child_diagrams[chld_idx]); |
| 286 |
|
| 287 |
|
| 288 |
{ |
| 289 |
pos_nav_tree_gap_t *const upper_gap = &((*this_).gap_pos[(*this_).gap_count]); |
| 290 |
(*this_).gap_count ++; |
| 291 |
|
| 292 |
const int32_t gap_child_order |
| 293 |
= (prev_child_order/2)+(data_diagram_get_list_order( chld_diag )/2); |
| 294 |
pos_nav_tree_gap_init( upper_gap, data_diagram_get_parent_data_id(chld_diag), gap_child_order ); |
| 295 |
const int indent = (tree_depth+1) * GUI_SKETCH_NAV_TREE_INDENT; |
| 296 |
pos_nav_tree_gap_set_gap_box_coords( upper_gap, left+indent, y_pos, width-indent, GAP_HEIGHT ); |
| 297 |
y_pos += GAP_HEIGHT; |
| 298 |
} |
| 299 |
|
| 300 |
|
| 301 |
{ |
| 302 |
pos_nav_tree_node_t *const chld_node = &((*this_).node_pos[(*this_).node_count]); |
| 303 |
(*this_).node_count ++; |
| 304 |
|
| 305 |
pos_nav_tree_node_init( chld_node, POS_NAV_TREE_NODE_TYPE_CLOSED, chld_diag ); |
| 306 |
gui_sketch_nav_tree_private_layout_node( this_, chld_node, tree_depth+1, &y_pos, font_layout ); |
| 307 |
} |
| 308 |
|
| 309 |
prev_child_order = data_diagram_get_list_order( chld_diag ); |
| 310 |
} |
| 311 |
|
| 312 |
|
| 313 |
{ |
| 314 |
pos_nav_tree_gap_t *const lower_gap = &((*this_).gap_pos[(*this_).gap_count]); |
| 315 |
(*this_).gap_count ++; |
| 316 |
|
| 317 |
const int32_t gap_child_order = (prev_child_order/2)+(INT32_MAX/2); |
| 318 |
pos_nav_tree_gap_init( lower_gap, data_diagram_get_data_id(sibl_diag), gap_child_order ); |
| 319 |
const int indent = (tree_depth+1) * GUI_SKETCH_NAV_TREE_INDENT; |
| 320 |
pos_nav_tree_gap_set_gap_box_coords( lower_gap, left+indent, y_pos, width-indent, GAP_HEIGHT ); |
| 321 |
y_pos += GAP_HEIGHT; |
| 322 |
} |
| 323 |
|
| 324 |
|
| 325 |
{ |
| 326 |
pos_nav_tree_node_t *const new_chld_node = &((*this_).node_pos[(*this_).node_count]); |
| 327 |
(*this_).node_count ++; |
| 328 |
|
| 329 |
pos_nav_tree_node_init( new_chld_node, POS_NAV_TREE_NODE_TYPE_NEW_CHILD, NULL ); |
| 330 |
gui_sketch_nav_tree_private_layout_node( this_, new_chld_node, tree_depth+1, &y_pos, font_layout ); |
| 331 |
} |
| 332 |
} |
| 333 |
|
| 334 |
previous_sibl_order = data_diagram_get_list_order( sibl_diag ); |
| 335 |
} |
| 336 |
|
| 337 |
const bool self_is_root = ( (*this_).ancestors_count == 1 ); |
| 338 |
if ( ! self_is_root ) |
| 339 |
{ |
| 340 |
|
| 341 |
const data_diagram_t *const self_diag = &((*this_).ancestor_diagrams[0]); |
| 342 |
{ |
| 343 |
pos_nav_tree_gap_t *const lower_gap = &((*this_).gap_pos[(*this_).gap_count]); |
| 344 |
(*this_).gap_count ++; |
| 345 |
|
| 346 |
const int32_t gap_sibl_order = (previous_sibl_order/2)+(INT32_MAX/2); |
| 347 |
pos_nav_tree_gap_init( lower_gap, data_diagram_get_parent_data_id(self_diag), gap_sibl_order ); |
| 348 |
const int indent = tree_depth * GUI_SKETCH_NAV_TREE_INDENT; |
| 349 |
pos_nav_tree_gap_set_gap_box_coords( lower_gap, left+indent, y_pos, width-indent, GAP_HEIGHT ); |
| 350 |
y_pos += GAP_HEIGHT; |
| 351 |
} |
| 352 |
|
| 353 |
|
| 354 |
{ |
| 355 |
pos_nav_tree_node_t *const new_sibl_node = &((*this_).node_pos[(*this_).node_count]); |
| 356 |
(*this_).node_count ++; |
| 357 |
|
| 358 |
pos_nav_tree_node_init( new_sibl_node, POS_NAV_TREE_NODE_TYPE_NEW_SIBLING, NULL ); |
| 359 |
gui_sketch_nav_tree_private_layout_node( this_, new_sibl_node, tree_depth, &y_pos, font_layout ); |
| 360 |
} |
| 361 |
} |
| 362 |
|
| 363 |
assert( (*this_).gap_count == (*this_).node_count ); |
| 364 |
} |
| 365 |
|
| 366 |
|
| 367 |
g_object_unref(font_layout); |
| 368 |
|
| 369 |
U8_TRACE_END(); |
| 370 |
} |
| 371 |
|
| 372 |
void gui_sketch_nav_tree_private_layout_node ( gui_sketch_nav_tree_t *this_, |
| 373 |
pos_nav_tree_node_t *node, |
| 374 |
uint32_t tree_depth, |
| 375 |
int32_t *io_y_pos, |
| 376 |
PangoLayout *font_layout ) |
| 377 |
{ |
| 378 |
U8_TRACE_BEGIN(); |
| 379 |
assert( NULL != node ); |
| 380 |
assert( NULL != io_y_pos ); |
| 381 |
assert( NULL != font_layout ); |
| 382 |
|
| 383 |
const int_fast32_t left = shape_int_rectangle_get_left( &((*this_).bounds) ); |
| 384 |
const uint_fast32_t width = shape_int_rectangle_get_width( &((*this_).bounds) ); |
| 385 |
const uint_fast32_t indent = tree_depth*GUI_SKETCH_NAV_TREE_INDENT; |
| 386 |
const data_diagram_t *data_or_null = pos_nav_tree_node_get_data_const( node ); |
| 387 |
|
| 388 |
|
| 389 |
{ |
| 390 |
const pos_nav_tree_node_type_t node_type = pos_nav_tree_node_get_type( node ); |
| 391 |
GdkTexture *icon = pos_nav_tree_node_type_get_icon( node_type, false, (*this_).resources ); |
| 392 |
const double icon_width = gdk_texture_get_width( icon ); |
| 393 |
const double icon_height = gdk_texture_get_height( icon ); |
| 394 |
|
| 395 |
const shape_int_rectangle_t new_icon_box = (shape_int_rectangle_t) { |
| 396 |
.left=left+indent+OBJ_GAP, |
| 397 |
.top=(*io_y_pos)+OBJ_GAP, |
| 398 |
.width=icon_width+0.999, |
| 399 |
.height=icon_height+0.999 }; |
| 400 |
pos_nav_tree_node_set_icon_box( node, &new_icon_box ); |
| 401 |
} |
| 402 |
|
| 403 |
|
| 404 |
const shape_int_rectangle_t *const icon_box = pos_nav_tree_node_get_icon_box_const( node ); |
| 405 |
shape_int_rectangle_t new_label_box; |
| 406 |
if ( data_or_null == NULL ) |
| 407 |
{ |
| 408 |
shape_int_rectangle_init( &new_label_box, shape_int_rectangle_get_right(icon_box), (*io_y_pos), 0, 0 ); |
| 409 |
} |
| 410 |
else |
| 411 |
{ |
| 412 |
int_fast32_t proposed_pango_width = width - indent - shape_int_rectangle_get_width(icon_box) - (4*OBJ_GAP); |
| 413 |
pango_layout_set_text( font_layout, |
| 414 |
data_diagram_get_name_const( data_or_null ), |
| 415 |
GUI_SKETCH_NAV_TREE_PANGO_AUTO_DETECT_LENGTH |
| 416 |
); |
| 417 |
pango_layout_set_width(font_layout, proposed_pango_width * PANGO_SCALE ); |
| 418 |
int text_width; |
| 419 |
int text_height; |
| 420 |
pango_layout_get_pixel_size(font_layout, &text_width, &text_height); |
| 421 |
|
| 422 |
int_fast32_t x_pos = shape_int_rectangle_get_right(icon_box); |
| 423 |
shape_int_rectangle_init( &new_label_box, x_pos+OBJ_GAP, (*io_y_pos)+OBJ_GAP, text_width, text_height ); |
| 424 |
} |
| 425 |
pos_nav_tree_node_set_label_box( node, &new_label_box ); |
| 426 |
|
| 427 |
*io_y_pos |
| 428 |
= u8_i32_max2( shape_int_rectangle_get_bottom(icon_box), shape_int_rectangle_get_bottom(&new_label_box) ) |
| 429 |
+ OBJ_GAP; |
| 430 |
|
| 431 |
shape_int_rectangle_destroy( &new_label_box ); |
| 432 |
|
| 433 |
U8_TRACE_END(); |
| 434 |
} |
| 435 |
|
| 436 |
void gui_sketch_nav_tree_invalidate_data( gui_sketch_nav_tree_t *this_ ) |
| 437 |
{ |
| 438 |
U8_TRACE_BEGIN(); |
| 439 |
assert( (*this_).ancestors_count <= GUI_SKETCH_NAV_TREE_CONST_MAX_ANCESTORS ); |
| 440 |
assert( (*this_).siblings_count <= GUI_SKETCH_NAV_TREE_CONST_MAX_SIBLINGS ); |
| 441 |
assert( (*this_).children_count <= GUI_SKETCH_NAV_TREE_CONST_MAX_CHILDREN ); |
| 442 |
|
| 443 |
|
| 444 |
for ( int anc_index = 0; anc_index < (*this_).ancestors_count; anc_index ++ ) |
| 445 |
{ |
| 446 |
data_diagram_destroy( &((*this_).ancestor_diagrams[anc_index]) ); |
| 447 |
} |
| 448 |
(*this_).ancestors_count = 0; |
| 449 |
|
| 450 |
for ( int sib_index = 0; sib_index < (*this_).siblings_count; sib_index ++ ) |
| 451 |
{ |
| 452 |
data_diagram_destroy( &((*this_).sibling_diagrams[sib_index]) ); |
| 453 |
} |
| 454 |
(*this_).siblings_count = 0; |
| 455 |
(*this_).siblings_self_index = -1; |
| 456 |
|
| 457 |
for ( int chi_index = 0; chi_index < (*this_).children_count; chi_index ++ ) |
| 458 |
{ |
| 459 |
data_diagram_destroy( &((*this_).child_diagrams[chi_index]) ); |
| 460 |
} |
| 461 |
(*this_).children_count = 0; |
| 462 |
|
| 463 |
|
| 464 |
assert( (*this_).node_count <= GUI_SKETCH_NAV_TREE_CONST_MAX_NODES ); |
| 465 |
for ( int node_index = 0; node_index < (*this_).node_count; node_index ++ ) |
| 466 |
{ |
| 467 |
pos_nav_tree_node_destroy( &((*this_).node_pos[node_index]) ); |
| 468 |
} |
| 469 |
(*this_).node_count = 0; |
| 470 |
|
| 471 |
assert( (*this_).gap_count <= GUI_SKETCH_NAV_TREE_CONST_MAX_GAPS ); |
| 472 |
for ( int gap_index = 0; gap_index < (*this_).gap_count; gap_index ++ ) |
| 473 |
{ |
| 474 |
pos_nav_tree_gap_destroy( &((*this_).gap_pos[gap_index]) ); |
| 475 |
} |
| 476 |
(*this_).gap_count = 0; |
| 477 |
|
| 478 |
U8_TRACE_END(); |
| 479 |
} |
| 480 |
|
| 481 |
gui_error_t gui_sketch_nav_tree_get_gap_info_at_pos ( const gui_sketch_nav_tree_t *this_, |
| 482 |
int32_t x, |
| 483 |
int32_t y, |
| 484 |
data_id_t *out_parent_id, |
| 485 |
int32_t *out_list_order, |
| 486 |
shape_int_rectangle_t *out_gap_line ) |
| 487 |
{ |
| 488 |
U8_TRACE_BEGIN(); |
| 489 |
assert ( NULL != out_parent_id ); |
| 490 |
assert ( NULL != out_list_order ); |
| 491 |
assert ( NULL != out_gap_line ); |
| 492 |
|
| 493 |
gui_error_t ret_error; |
| 494 |
|
| 495 |
|
| 496 |
if ( shape_int_rectangle_contains( &((*this_).bounds), x, y ) ) |
| 497 |
{ |
| 498 |
const unsigned int gap_count = (*this_).gap_count; |
| 499 |
assert( gap_count <= GUI_SKETCH_NAV_TREE_CONST_MAX_GAPS ); |
| 500 |
if ( gap_count == 0 ) |
| 501 |
{ |
| 502 |
ret_error = GUI_ERROR_OUT_OF_BOUNDS; |
| 503 |
} |
| 504 |
else |
| 505 |
{ |
| 506 |
const pos_nav_tree_gap_t *closest = &((*this_).gap_pos[0]); |
| 507 |
int closest_dist = INT32_MAX; |
| 508 |
for ( unsigned int idx = 0; idx < gap_count; idx ++ ) |
| 509 |
{ |
| 510 |
const pos_nav_tree_gap_t *const current = &((*this_).gap_pos[idx]); |
| 511 |
const shape_int_rectangle_t *const current_box = pos_nav_tree_gap_get_gap_box_const( current ); |
| 512 |
const int current_dist |
| 513 |
= ( y < shape_int_rectangle_get_top( current_box ) ) |
| 514 |
? ( shape_int_rectangle_get_top( current_box ) - y ) |
| 515 |
: (( y > shape_int_rectangle_get_bottom( current_box ) ) |
| 516 |
? ( y - shape_int_rectangle_get_bottom( current_box ) ) |
| 517 |
: 0 ); |
| 518 |
if ( current_dist < closest_dist ) |
| 519 |
{ |
| 520 |
closest = current; |
| 521 |
closest_dist = current_dist; |
| 522 |
} |
| 523 |
} |
| 524 |
*out_parent_id = pos_nav_tree_gap_get_parent_id( closest ); |
| 525 |
*out_list_order = pos_nav_tree_gap_get_list_order( closest ); |
| 526 |
shape_int_rectangle_replace( out_gap_line, pos_nav_tree_gap_get_gap_box_const( closest ) ); |
| 527 |
ret_error = GUI_ERROR_NONE; |
| 528 |
} |
| 529 |
} |
| 530 |
else |
| 531 |
{ |
| 532 |
ret_error = GUI_ERROR_OUT_OF_BOUNDS; |
| 533 |
} |
| 534 |
|
| 535 |
U8_TRACE_END_ERR( ret_error ); |
| 536 |
return ret_error; |
| 537 |
} |
| 538 |
|
| 539 |
void gui_sketch_nav_tree_get_object_id_at_pos ( const gui_sketch_nav_tree_t *this_, |
| 540 |
int32_t x, |
| 541 |
int32_t y, |
| 542 |
data_id_t *out_selected_id ) |
| 543 |
{ |
| 544 |
U8_TRACE_BEGIN(); |
| 545 |
assert ( NULL != out_selected_id ); |
| 546 |
|
| 547 |
|
| 548 |
{ |
| 549 |
data_id_reinit_void( out_selected_id ); |
| 550 |
} |
| 551 |
|
| 552 |
|
| 553 |
if ( shape_int_rectangle_contains( &((*this_).bounds), x, y ) ) |
| 554 |
{ |
| 555 |
const unsigned int count = (*this_).node_count; |
| 556 |
assert( count <= GUI_SKETCH_NAV_TREE_CONST_MAX_NODES ); |
| 557 |
for ( unsigned int idx = 0; idx < count; idx ++ ) |
| 558 |
{ |
| 559 |
const pos_nav_tree_node_t *const node = &((*this_).node_pos[idx]); |
| 560 |
const shape_int_rectangle_t *icon_box = pos_nav_tree_node_get_icon_box_const( node ); |
| 561 |
const shape_int_rectangle_t *label_box = pos_nav_tree_node_get_label_box_const( node ); |
| 562 |
|
| 563 |
if ( shape_int_rectangle_contains( icon_box, x, y ) || shape_int_rectangle_contains( label_box, x, y ) ) |
| 564 |
{ |
| 565 |
|
| 566 |
const data_diagram_t *const data_or_null = pos_nav_tree_node_get_data_const( node ); |
| 567 |
if ( data_or_null != NULL ) |
| 568 |
{ |
| 569 |
*out_selected_id = data_diagram_get_data_id( data_or_null ); |
| 570 |
break; |
| 571 |
} |
| 572 |
} |
| 573 |
} |
| 574 |
} |
| 575 |
|
| 576 |
U8_TRACE_END(); |
| 577 |
} |
| 578 |
|
| 579 |
void gui_sketch_nav_tree_draw ( gui_sketch_nav_tree_t *this_, gui_marked_set_t *marker, cairo_t *cr ) |
| 580 |
{ |
| 581 |
U8_TRACE_BEGIN(); |
| 582 |
assert( NULL != marker ); |
| 583 |
assert( NULL != cr ); |
| 584 |
|
| 585 |
if ( (*this_).visible ) |
| 586 |
{ |
| 587 |
PangoLayout *font_layout = pango_cairo_create_layout (cr); |
| 588 |
{ |
| 589 |
const PangoFontDescription *const std_font |
| 590 |
= gui_sketch_style_get_standard_font_description( &((*this_).sketch_style ) ); |
| 591 |
pango_layout_set_font_description ( font_layout, std_font ); |
| 592 |
} |
| 593 |
|
| 594 |
|
| 595 |
const unsigned int count = (*this_).node_count; |
| 596 |
assert( count <= GUI_SKETCH_NAV_TREE_CONST_MAX_NODES ); |
| 597 |
for ( unsigned int idx = 0; idx < count; idx ++ ) |
| 598 |
{ |
| 599 |
const pos_nav_tree_node_t *const node = &((*this_).node_pos[idx]); |
| 600 |
gui_sketch_nav_tree_private_draw_node( this_, node, marker, font_layout, cr ); |
| 601 |
} |
| 602 |
|
| 603 |
g_object_unref(font_layout); |
| 604 |
} |
| 605 |
|
| 606 |
U8_TRACE_END(); |
| 607 |
} |
| 608 |
|
| 609 |
void gui_sketch_nav_tree_private_draw_node( gui_sketch_nav_tree_t *this_, |
| 610 |
const pos_nav_tree_node_t *node, |
| 611 |
const gui_marked_set_t *marker, |
| 612 |
PangoLayout *font_layout, |
| 613 |
cairo_t *cr ) |
| 614 |
{ |
| 615 |
U8_TRACE_BEGIN(); |
| 616 |
assert( NULL != cr ); |
| 617 |
assert( NULL != node ); |
| 618 |
assert( NULL != marker ); |
| 619 |
assert( NULL != font_layout ); |
| 620 |
|
| 621 |
const data_diagram_t *const diag_or_null = pos_nav_tree_node_get_data_const( node ); |
| 622 |
|
| 623 |
|
| 624 |
if ( diag_or_null != NULL ) |
| 625 |
{ |
| 626 |
shape_int_rectangle_t destination_rect; |
| 627 |
shape_int_rectangle_init_by_bounds( &destination_rect, |
| 628 |
pos_nav_tree_node_get_icon_box_const(node), |
| 629 |
pos_nav_tree_node_get_label_box_const(node) |
| 630 |
); |
| 631 |
|
| 632 |
gui_sketch_marker_prepare_draw( &((*this_).sketch_marker), |
| 633 |
data_diagram_get_data_id( diag_or_null ), |
| 634 |
marker, |
| 635 |
destination_rect, |
| 636 |
cr |
| 637 |
); |
| 638 |
|
| 639 |
shape_int_rectangle_destroy( &destination_rect ); |
| 640 |
} |
| 641 |
else |
| 642 |
{ |
| 643 |
const GdkRGBA std_color = gui_sketch_style_get_standard_color( &((*this_).sketch_style) ); |
| 644 |
cairo_set_source_rgba( cr, std_color.red, std_color.green, std_color.blue, std_color.alpha ); |
| 645 |
} |
| 646 |
|
| 647 |
|
| 648 |
if ( diag_or_null != NULL ) |
| 649 |
{ |
| 650 |
|
| 651 |
const char *const label = data_diagram_get_name_const( diag_or_null ); |
| 652 |
|
| 653 |
|
| 654 |
const shape_int_rectangle_t *const label_box |
| 655 |
= pos_nav_tree_node_get_label_box_const( node ); |
| 656 |
|
| 657 |
|
| 658 |
cairo_move_to( cr, shape_int_rectangle_get_left(label_box), shape_int_rectangle_get_top(label_box) ); |
| 659 |
pango_layout_set_text( font_layout, label, GUI_SKETCH_NAV_TREE_PANGO_AUTO_DETECT_LENGTH ); |
| 660 |
const unsigned int text_width |
| 661 |
= shape_int_rectangle_get_width(label_box) |
| 662 |
+(2.0*OBJ_GAP); |
| 663 |
pango_layout_set_width(font_layout, text_width * PANGO_SCALE ); |
| 664 |
pango_cairo_show_layout( cr, font_layout ); |
| 665 |
} |
| 666 |
|
| 667 |
|
| 668 |
{ |
| 669 |
|
| 670 |
const pos_nav_tree_node_type_t node_type = pos_nav_tree_node_get_type( node ); |
| 671 |
const gui_sketch_action_t btn_act = gui_marked_set_get_highlighted_button( marker ); |
| 672 |
const bool highlight |
| 673 |
= (( node_type == POS_NAV_TREE_NODE_TYPE_NEW_ROOT )&&( btn_act == GUI_SKETCH_ACTION_NEW_ROOT_DIAGRAM )) |
| 674 |
|| (( node_type == POS_NAV_TREE_NODE_TYPE_NEW_SIBLING )&&( btn_act == GUI_SKETCH_ACTION_NEW_SIBLING_DIAGRAM )) |
| 675 |
|| (( node_type == POS_NAV_TREE_NODE_TYPE_NEW_CHILD )&&( btn_act == GUI_SKETCH_ACTION_NEW_CHILD_DIAGRAM )); |
| 676 |
GdkTexture *icon = pos_nav_tree_node_type_get_icon( node_type, highlight, (*this_).resources ); |
| 677 |
|
| 678 |
|
| 679 |
const shape_int_rectangle_t *const icon_box |
| 680 |
= pos_nav_tree_node_get_icon_box_const( node ); |
| 681 |
const int x = shape_int_rectangle_get_left(icon_box); |
| 682 |
const int y = shape_int_rectangle_get_top(icon_box); |
| 683 |
|
| 684 |
|
| 685 |
gui_sketch_texture_draw( (*this_).texture_downloader, icon, x, y, cr ); |
| 686 |
} |
| 687 |
|
| 688 |
U8_TRACE_END(); |
| 689 |
} |
| 690 |
|
| 691 |
void gui_sketch_nav_tree_draw_overlay( const gui_sketch_nav_tree_t *this_, |
| 692 |
const gui_sketch_drag_state_t *drag_state, |
| 693 |
cairo_t *cr ) |
| 694 |
{ |
| 695 |
U8_TRACE_BEGIN(); |
| 696 |
assert( NULL != drag_state ); |
| 697 |
assert( NULL != cr ); |
| 698 |
|
| 699 |
if ( (*this_).visible && gui_sketch_drag_state_is_dragging( drag_state ) ) |
| 700 |
{ |
| 701 |
const int32_t to_x = gui_sketch_drag_state_get_to_x( drag_state ); |
| 702 |
const int32_t to_y = gui_sketch_drag_state_get_to_y( drag_state ); |
| 703 |
data_id_t out_parent_id; |
| 704 |
int32_t out_list_order; |
| 705 |
shape_int_rectangle_t out_gap_line; |
| 706 |
gui_error_t gap_err; |
| 707 |
gap_err = gui_sketch_nav_tree_get_gap_info_at_pos( this_, |
| 708 |
to_x, |
| 709 |
to_y, |
| 710 |
&out_parent_id, |
| 711 |
&out_list_order, |
| 712 |
&out_gap_line |
| 713 |
); |
| 714 |
if ( gap_err == GUI_ERROR_NONE ) |
| 715 |
{ |
| 716 |
const GdkRGBA high_color = gui_sketch_style_get_highlight_color( &((*this_).sketch_style) ); |
| 717 |
cairo_set_source_rgba( cr, high_color.red, high_color.green, high_color.blue, high_color.alpha ); |
| 718 |
cairo_rectangle( cr, |
| 719 |
shape_int_rectangle_get_left(&out_gap_line), |
| 720 |
shape_int_rectangle_get_top(&out_gap_line), |
| 721 |
shape_int_rectangle_get_width(&out_gap_line), |
| 722 |
shape_int_rectangle_get_height(&out_gap_line) |
| 723 |
); |
| 724 |
cairo_fill (cr); |
| 725 |
} |
| 726 |
else |
| 727 |
{ |
| 728 |
U8_TRACE_INFO("dragging diagram outside nav_tree"); |
| 729 |
} |
| 730 |
} |
| 731 |
U8_TRACE_END(); |
| 732 |
} |
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|