11#define RETROHTR_TREE_FLAG_GUI_ACTIVE 1
13#define RETROHTR_NODE_FLAG_DIRTY 2
15#ifndef RETROHTR_RENDER_NODES_INIT_SZ
16# define RETROHTR_RENDER_NODES_INIT_SZ 10
19#ifndef RETROHTR_TRACE_LVL
20# define RETROHTR_TRACE_LVL 0
23#define RETROHTR_EDGE_UNKNOWN 0
24#define RETROHTR_EDGE_LEFT 1
25#define RETROHTR_EDGE_TOP 2
26#define RETROHTR_EDGE_INSIDE 4
44#ifdef RETROGXC_PRESENT
56 struct RETROFLAT_BITMAP bitmap;
73#define retrohtr_node( tree, idx ) \
74 (0 <= (ssize_t)idx ? &((tree)->nodes[idx]) : NULL)
76#define retrohtr_node_parent( tree, idx ) \
77 (0 <= idx && 0 <= (tree)->nodes[idx].parent ? \
78 &((tree)->nodes[(tree)->nodes[idx].parent]) : NULL)
80#define retrohtr_tree_lock( tree ) \
81 if( NULL == (tree)->nodes ) { \
82 maug_mlock( (tree)->nodes_h, (tree)->nodes ); \
83 maug_cleanup_if_null_alloc( struct RETROHTR_RENDER_NODE*, (tree)->nodes ); \
86#define retrohtr_tree_unlock( tree ) \
87 if( NULL != (tree)->nodes ) { \
88 maug_munlock( (tree)->nodes_h, (tree)->nodes ); \
91#define retrohtr_tree_is_locked( tree ) (NULL != (tree)->nodes)
95#define retrohtr_node_screen_x( tree, node_idx ) \
96 ((tree)->nodes[node_idx].x)
98#define retrohtr_node_screen_y( tree, node_idx ) \
99 ((tree)->nodes[node_idx].y)
103 size_t x,
size_t y,
size_t w,
size_t h,
104 ssize_t tag_idx, ssize_t node_idx,
size_t d );
119 struct MCSS_STYLE* parent_style,
struct MCSS_STYLE* effect_style,
124 struct MCSS_STYLE* prev_sibling_style,
125 struct MCSS_STYLE* parent_style, ssize_t node_idx,
size_t d );
129 struct MCSS_STYLE* prev_sibling_style,
130 struct MCSS_STYLE* parent_style, ssize_t node_idx,
size_t d );
134 ssize_t node_idx,
size_t d );
138 RETROFLAT_IN_KEY* input,
143 ssize_t iter,
size_t d );
152 uint8_t auto_unlocked = 0;
154 MAUG_MHANDLE new_nodes_h = (MAUG_MHANDLE)NULL;
156 if( NULL != tree->
nodes ) {
157 debug_printf( RETROHTR_TRACE_LVL,
"auto-unlocking nodes..." );
158 maug_munlock( tree->nodes_h, tree->
nodes );
163 assert( NULL == tree->
nodes );
164 assert( (MAUG_MHANDLE)NULL != tree->nodes_h );
168 new_nodes_h = maug_mrealloc( tree->nodes_h, tree->
nodes_sz_max * 2,
170 if( (MAUG_MHANDLE)NULL == new_nodes_h ) {
172 "unable to reallocate " SIZE_T_FMT
" nodes!",
176 tree->nodes_h = new_nodes_h;
181 assert( NULL == tree->
nodes );
182 maug_mlock( tree->nodes_h, tree->
nodes );
183 if( NULL == tree->
nodes ) {
184 error_printf(
"unable to lock nodes!" );
189 debug_printf( RETROHTR_TRACE_LVL,
190 "zeroing node " SIZE_T_FMT
" (of " SIZE_T_FMT
")...",
198 maug_munlock( tree->nodes_h, tree->
nodes );
202 if( auto_unlocked ) {
203 debug_printf( RETROHTR_TRACE_LVL,
"auto-locking nodes..." );
204 maug_mlock( tree->nodes_h, tree->
nodes );
210ssize_t retrohtr_add_node_child(
213 ssize_t node_new_idx = -1,
214 node_sibling_idx = -1;
216 node_new_idx = retrohtr_get_next_free_node( tree );
217 if( 0 > node_new_idx ) {
221#ifdef RETROGXC_PRESENT
222 retrohtr_node( tree, node_new_idx )->font_idx = -1;
224 retrohtr_node( tree, node_new_idx )->parent = node_parent_idx;
225 retrohtr_node( tree, node_new_idx )->first_child = -1;
226 retrohtr_node( tree, node_new_idx )->next_sibling = -1;
228 if( 0 > node_parent_idx ) {
230 1,
"adding root node under " SSIZE_T_FMT
"...", node_parent_idx );
234 1,
"adding node " SSIZE_T_FMT
" under " SSIZE_T_FMT,
235 node_new_idx, node_parent_idx );
239 if( 0 > retrohtr_node( tree, node_parent_idx )->first_child ) {
240 debug_printf( RETROHTR_TRACE_LVL,
"adding first child..." );
241 assert( -1 == retrohtr_node( tree, node_parent_idx )->first_child );
242 retrohtr_node( tree, node_parent_idx )->first_child = node_new_idx;
244 assert( NULL != retrohtr_node( tree, node_parent_idx ) );
245 node_sibling_idx = retrohtr_node( tree, node_parent_idx )->first_child;
246 assert( NULL != retrohtr_node( tree, node_sibling_idx ) );
247 while( 0 <= retrohtr_node( tree, node_sibling_idx )->next_sibling ) {
249 retrohtr_node( tree, node_sibling_idx )->next_sibling;
251 retrohtr_node( tree, node_sibling_idx )->next_sibling = node_new_idx;
261 size_t x,
size_t y,
size_t w,
size_t h,
262 ssize_t tag_idx, ssize_t node_idx,
size_t d
264 ssize_t node_new_idx = -1;
265 ssize_t tag_iter_idx = -1;
268 ssize_t tag_next_idx = 0;
270 debug_printf( RETROHTR_TRACE_LVL,
271 "creating render node for tag: " SSIZE_T_FMT, tag_idx );
273 mdata_vector_lock( &(parser->tags) );
278 p_tag_iter = mdata_vector_get( &(parser->tags), tag_idx,
union MHTML_TAG );
279 if( NULL == p_tag_iter ) {
285 assert( MHTML_TAG_TYPE_BODY == p_tag_iter->base.type );
287 node_new_idx = retrohtr_add_node_child( tree, node_idx );
288 if( 0 > node_new_idx ) {
291 debug_printf( RETROHTR_TRACE_LVL,
292 "created initial root node: " SIZE_T_FMT, node_new_idx );
294 node_idx = node_new_idx;
297 retrohtr_node( tree, node_idx )->tag = tag_idx;
299 retrohtr_node( tree, node_idx )->x = x;
300 retrohtr_node( tree, node_idx )->y = y;
301 retrohtr_node( tree, node_idx )->w = w;
302 retrohtr_node( tree, node_idx )->h = h;
305 tag_iter_idx = p_tag_iter->base.first_child;
306 while( 0 <= tag_iter_idx ) {
307 node_new_idx = retrohtr_add_node_child( tree, node_idx );
308 p_tag_iter = mdata_vector_get(
309 &(parser->tags), tag_iter_idx,
union MHTML_TAG );
310 assert( NULL != p_tag_iter );
311 if( 0 > node_new_idx ) {
315 retrohtr_node( tree, node_new_idx )->tag = tag_iter_idx;
317 debug_printf( RETROHTR_TRACE_LVL,
318 "rendering node " SSIZE_T_FMT
" (%s) under node " SSIZE_T_FMT,
320 gc_mhtml_tag_names[p_tag_iter->base.type],
324 if( MHTML_TAG_TYPE_IMG == p_tag_iter->base.type ) {
328 &(retrohtr_node( tree, node_new_idx )->bitmap),
330 if( MERROR_OK == retval ) {
331 debug_printf( RETROHTR_TRACE_LVL,
"loaded img: %s",
332 p_tag_iter->IMG.src );
334 error_printf(
"could not load img: %s", p_tag_iter->IMG.src );
338 tag_next_idx = p_tag_iter->base.next_sibling;
340 mdata_vector_unlock( &(parser->tags) );
342 retval = retrohtr_tree_create( parser, tree, x, y, w, h,
343 tag_iter_idx, node_new_idx, d + 1 );
344 maug_cleanup_if_not_ok();
346 mdata_vector_lock( &(parser->tags) );
348 tag_iter_idx = tag_next_idx;
353 if( mdata_vector_is_locked( &(parser->tags) ) ) {
354 mdata_vector_unlock( &(parser->tags) );
362 struct MCSS_STYLE* parent_style,
struct MCSS_STYLE* effect_style,
366 ssize_t tag_style_idx = -1;
369 struct MCSS_STYLE* style = NULL;
372 debug_printf( RETROHTR_TRACE_LVL,
373 "applying styles for tag: " SSIZE_T_FMT, tag_idx );
375 assert( !mdata_vector_is_locked( &(parser->tags) ) );
376 mdata_vector_lock( &(parser->styler.styles) );
377 mdata_vector_lock( &(parser->tags) );
379 maug_mzero( effect_style,
sizeof(
struct MCSS_STYLE ) );
384 p_tag_iter = mdata_vector_get( &(parser->tags), tag_idx,
union MHTML_TAG );
385 if( NULL == p_tag_iter ) {
389 tag_type = p_tag_iter->base.type;
392 if( 0 < p_tag_iter->base.classes_sz ) {
393 for( i = 0 ; mdata_vector_ct( &(parser->styler.styles) ) > i ; i++ ) {
394 style = mdata_vector_get(
395 &(parser->styler.styles), i,
struct MCSS_STYLE );
400 p_tag_iter->base.classes,
402 p_tag_iter->base.classes_sz
405 debug_printf( RETROHTR_TRACE_LVL,
"found style for tag class: %s",
408 mcssmerge_styles( effect_style, parent_style, style, tag_type );
414 if( 0 < p_tag_iter->base.id_sz ) {
415 for( i = 0 ; mdata_vector_ct( &(parser->styler.styles) ) > i ; i++ ) {
416 style = mdata_vector_get(
417 &(parser->styler.styles), i,
struct MCSS_STYLE );
424 p_tag_iter->base.id_sz
427 debug_printf( RETROHTR_TRACE_LVL,
"found style for tag ID: %s",
430 mcssmerge_styles( effect_style, parent_style, style, tag_type );
436 tag_style_idx = p_tag_iter->base.style;
443 style = mdata_vector_get(
444 &(parser->styler.styles), tag_style_idx,
struct MCSS_STYLE );
447 mcssmerge_styles( effect_style, parent_style, style, tag_type );
449 mdata_vector_unlock( &(parser->tags) );
450 mdata_vector_unlock( &(parser->styler.styles) );
456 struct MCSS_PARSER* styler,
457#ifdef RETROGXC_PRESENT
460 MAUG_MHANDLE* font_h_p,
462 struct MCSS_STYLE* effect_style
465 char* strpool = NULL;
467#ifdef RETROGXC_PRESENT
468 if( 0 <= *font_idx_p ) {
469 error_printf(
"tried to load font but font already loaded, idx: "
470 SSIZE_T_FMT, *font_idx_p );
472 if( (MAUG_MHANDLE)NULL != *font_h_p ) {
473 error_printf(
"tried to load font but font already loaded, p: %p",
479 mdata_strpool_lock( &(styler->strpool), strpool );
481 debug_printf( RETROHTR_TRACE_LVL,
482 "loading font: %s (" SSIZE_T_FMT
")",
483 &(strpool[effect_style->FONT_FAMILY]), effect_style->FONT_FAMILY );
485 if( 0 >= effect_style->FONT_FAMILY ) {
486 error_printf(
"style has no font associated!" );
493#ifdef RETROGXC_PRESENT
495 retrogxc_load_font( &(strpool[effect_style->FONT_FAMILY]), 0, 33, 93 );
498 &(strpool[effect_style->FONT_FAMILY]), font_h_p, 0, 33, 93 );
503 mdata_strpool_unlock( &(styler->strpool), strpool );
510 struct MCSS_STYLE* effect_style
516 RETROHTR_TREE_FLAG_GUI_ACTIVE ==
517 (RETROHTR_TREE_FLAG_GUI_ACTIVE & tree->flags)
519 debug_printf( RETROHTR_TRACE_LVL,
"tree GUI already active!" );
526 retval = retrogui_init( &(tree->gui) );
527 maug_cleanup_if_not_ok();
529 retval = retrohtr_load_font(
531#ifdef RETROGXC_PRESENT
532 &(tree->gui.font_idx),
537 maug_cleanup_if_not_ok();
539 tree->flags |= RETROHTR_TREE_FLAG_GUI_ACTIVE;
541 debug_printf( RETROHTR_TRACE_LVL,
"tree GUI initialized!" );
549 struct MCSS_STYLE* prev_sibling_style,
550 struct MCSS_STYLE* parent_style, ssize_t node_idx,
size_t d
552 struct MCSS_STYLE effect_style;
553 struct MCSS_STYLE child_prev_sibling_style;
554 struct MCSS_STYLE child_style;
555 char* strpool = NULL;
556 ssize_t child_iter_idx = -1;
557 ssize_t tag_idx = -1;
558 ssize_t node_iter_idx = -1;
559 size_t this_line_w = 0;
560 size_t this_line_h = 0;
566 if( NULL == retrohtr_node( tree, node_idx ) ) {
570 tag_idx = retrohtr_node( tree, node_idx )->tag;
573 parser, tree, parent_style, &effect_style, tag_idx );
574 maug_cleanup_if_not_ok();
576 assert( !mdata_vector_is_locked( &(parser->tags) ) );
577 mdata_vector_lock( &(parser->tags) );
579 p_tag_iter = mdata_vector_get( &(parser->tags), tag_idx,
union MHTML_TAG );
580 assert( NULL != p_tag_iter );
584 if( mcss_prop_is_active( effect_style.POSITION ) ) {
585 debug_printf( RETROHTR_TRACE_LVL,
586 "node " SSIZE_T_FMT
": applying %s positioning",
587 node_idx, gc_mcss_position_names[effect_style.POSITION] );
595 retrohtr_node( tree, node_idx )->pos = effect_style.POSITION;
596 retrohtr_node( tree, node_idx )->pos_flags = effect_style.POSITION_flags;
604 if( mcss_prop_is_active_NOT_flag( effect_style.WIDTH, AUTO ) ) {
605 retrohtr_node( tree, node_idx )->w = effect_style.WIDTH;
608 if( mcss_prop_is_active_NOT_flag( effect_style.HEIGHT, AUTO ) ) {
609 retrohtr_node( tree, node_idx )->h = effect_style.HEIGHT;
615 retval = retrohtr_load_font(
617#ifdef RETROGXC_PRESENT
618 &(retrohtr_node( tree, node_idx )->font_idx),
620 &(retrohtr_node( tree, node_idx )->font_h),
623 maug_cleanup_if_not_ok();
625 if( 0 <= tag_idx && MHTML_TAG_TYPE_TEXT == p_tag_iter->base.type ) {
628 mdata_strpool_lock( &(parser->strpool), strpool );
630#ifdef RETROGXC_PRESENT
635 NULL, &(strpool[p_tag_iter->TEXT.content_idx]),
636 p_tag_iter->TEXT.content_sz,
637#ifdef RETROGXC_PRESENT
638 retrohtr_node( tree, node_idx )->font_idx,
640 retrohtr_node( tree, node_idx )->font_h,
643 retrohtr_node_parent( tree, node_idx )->w,
644 retrohtr_node_parent( tree, node_idx )->h,
645 &(retrohtr_node( tree, node_idx )->w),
646 &(retrohtr_node( tree, node_idx )->h), 0 );
648 debug_printf( RETROHTR_TRACE_LVL,
"TEXT w: " SIZE_T_FMT,
649 retrohtr_node( tree, node_idx )->w );
651 mdata_strpool_unlock( &(parser->strpool), strpool );
655 MHTML_TAG_TYPE_INPUT == p_tag_iter->base.type
659 retval = retrohtr_tree_gui( tree, &(parser->styler), &effect_style );
663 MERROR_OK != retrogui_init_ctl(
664 &ctl, RETROGUI_CTL_TYPE_BUTTON, node_idx )
666 error_printf(
"could not initialize control!" );
670 p_tag_node = mdata_vector_get(
672 retrohtr_node( tree, node_idx )->tag,
union MHTML_TAG );
674 ctl.base.x = retrohtr_node( tree, node_idx )->x;
675 ctl.base.y = retrohtr_node( tree, node_idx )->y;
678 ctl.BUTTON.label = p_tag_node->INPUT.value;
681 retrohtr_node( tree, node_idx )->w = ctl.base.w;
682 retrohtr_node( tree, node_idx )->h = ctl.base.h;
684 debug_printf( RETROHTR_TRACE_LVL,
"initialized control for INPUT..." );
686 retrogui_push_ctl( &(tree->gui), &ctl );
688 }
else if( 0 <= tag_idx && MHTML_TAG_TYPE_IMG == p_tag_iter->base.type ) {
690 if( retroflat_bitmap_ok( &(retrohtr_node( tree, node_idx )->bitmap) ) ) {
691 retrohtr_node( tree, node_idx )->w =
692 retroflat_bitmap_w( &(retrohtr_node( tree, node_idx )->bitmap) );
693 retrohtr_node( tree, node_idx )->h =
694 retroflat_bitmap_h( &(retrohtr_node( tree, node_idx )->bitmap) );
697 debug_printf( RETROHTR_TRACE_LVL,
"TEXT w: " SIZE_T_FMT,
698 retrohtr_node( tree, node_idx )->w );
703 maug_mzero( &child_prev_sibling_style,
sizeof(
struct MCSS_STYLE ) );
704 node_iter_idx = retrohtr_node( tree, node_idx )->first_child;
705 mdata_vector_unlock( &(parser->tags) );
706 while( 0 <= node_iter_idx ) {
708 parser, tree, &child_prev_sibling_style, &effect_style,
709 node_iter_idx, d + 1 );
711 node_iter_idx = retrohtr_node( tree, node_iter_idx )->next_sibling;
715 if( mdata_vector_is_locked( &(parser->tags) ) ) {
716 mdata_vector_unlock( &(parser->tags) );
720 if( 0 == retrohtr_node( tree, node_idx )->w ) {
722 MCSS_DISPLAY_BLOCK == effect_style.DISPLAY &&
723 0 <= retrohtr_node( tree, node_idx )->parent
727 retrohtr_node( tree, node_idx )->w =
728 retrohtr_node_parent( tree, node_idx )->w;
732 child_iter_idx = retrohtr_node( tree, node_idx )->first_child;
733 while( 0 <= child_iter_idx ) {
734 assert( !mdata_vector_is_locked( &(parser->tags) ) );
736 parser, tree, &effect_style, &child_style,
737 retrohtr_node( tree, child_iter_idx )->tag );
738 maug_cleanup_if_not_ok();
741 if( MCSS_POSITION_ABSOLUTE == child_style.POSITION ) {
743 retrohtr_node( tree, child_iter_idx )->next_sibling;
747 if( MCSS_DISPLAY_BLOCK == child_style.DISPLAY ) {
752 retrohtr_node( tree, child_iter_idx )->w >
753 retrohtr_node( tree, node_idx )->w
756 retrohtr_node( tree, node_idx )->w =
757 retrohtr_node( tree, child_iter_idx )->w;
761 this_line_w += retrohtr_node( tree, child_iter_idx )->w;
763 if( this_line_w > retrohtr_node( tree, node_idx )->w ) {
765 retrohtr_node( tree, node_idx )->w = this_line_w;
768 child_iter_idx = retrohtr_node( tree, child_iter_idx )->next_sibling;
773 if( 0 == retrohtr_node( tree, node_idx )->h ) {
775 child_iter_idx = retrohtr_node( tree, node_idx )->first_child;
776 while( 0 <= child_iter_idx ) {
777 assert( !mdata_vector_is_locked( &(parser->tags) ) );
779 parser, tree, &effect_style, &child_style,
780 retrohtr_node( tree, child_iter_idx )->tag );
783 if( MCSS_POSITION_ABSOLUTE == child_style.POSITION ) {
784 child_iter_idx = retrohtr_node( tree, child_iter_idx )->next_sibling;
788 if( MCSS_DISPLAY_BLOCK == child_style.DISPLAY ) {
790 retrohtr_node( tree, node_idx )->h += this_line_h;
793 this_line_h = retrohtr_node( tree, child_iter_idx )->h;
796 if( this_line_h < retrohtr_node( tree, child_iter_idx )->h ) {
797 this_line_h = retrohtr_node( tree, child_iter_idx )->h;
801 child_iter_idx = retrohtr_node( tree, child_iter_idx )->next_sibling;
805 retrohtr_node( tree, node_idx )->h += this_line_h;
814 if( mcss_prop_is_active_NOT_flag( effect_style.PADDING_LEFT, AUTO ) ) {
815 retrohtr_node( tree, node_idx )->w += effect_style.PADDING_LEFT;
816 }
else if( mcss_prop_is_active_NOT_flag( effect_style.PADDING, AUTO ) ) {
817 retrohtr_node( tree, node_idx )->w += effect_style.PADDING;
821 if( mcss_prop_is_active_NOT_flag( effect_style.PADDING_RIGHT, AUTO ) ) {
822 retrohtr_node( tree, node_idx )->w += effect_style.PADDING_RIGHT;
823 }
else if( mcss_prop_is_active_NOT_flag( effect_style.PADDING, AUTO ) ) {
824 retrohtr_node( tree, node_idx )->w += effect_style.PADDING;
828 if( mcss_prop_is_active_NOT_flag( effect_style.PADDING_TOP, AUTO ) ) {
829 retrohtr_node( tree, node_idx )->h += effect_style.PADDING_TOP;
830 }
else if( mcss_prop_is_active_NOT_flag( effect_style.PADDING, AUTO ) ) {
831 retrohtr_node( tree, node_idx )->h += effect_style.PADDING;
835 if( mcss_prop_is_active_NOT_flag( effect_style.PADDING_BOTTOM, AUTO ) ) {
836 retrohtr_node( tree, node_idx )->h += effect_style.PADDING_BOTTOM;
837 }
else if( mcss_prop_is_active_NOT_flag( effect_style.PADDING, AUTO ) ) {
838 retrohtr_node( tree, node_idx )->h += effect_style.PADDING;
841 debug_printf( RETROHTR_TRACE_LVL,
842 "setting node " SIZE_T_FMT
" dirty...", node_idx );
843 retrohtr_node( tree, node_idx )->flags |= RETROHTR_NODE_FLAG_DIRTY;
847 if( mdata_vector_is_locked( &(parser->tags) ) ) {
848 mdata_vector_unlock( &(parser->tags) );
854 if( NULL != prev_sibling_style ) {
856 prev_sibling_style, &effect_style,
857 sizeof(
struct MCSS_STYLE ) );
865#define retrohtr_break_on_active_pos( iter_idx ) \
866 if( mcss_prop_is_active( retrohtr_node( tree, iter_idx )->pos ) ) { \
870static ssize_t retrohtr_find_prev_sibling_in_box_model(
874 ssize_t sibling_iter_idx = -1;
875 ssize_t sibling_found_idx = -1;
877 if( 0 > retrohtr_node( tree, node_idx )->parent ) {
882 sibling_iter_idx = retrohtr_node_parent( tree, node_idx )->first_child;
884 if( sibling_iter_idx == node_idx ) {
889 while( 0 <= sibling_iter_idx && node_idx != sibling_iter_idx ) {
892 MCSS_POSITION_ABSOLUTE != retrohtr_node( tree, sibling_iter_idx )->pos
894 sibling_found_idx = sibling_iter_idx;
899 sibling_iter_idx = retrohtr_node( tree, sibling_iter_idx )->next_sibling;
903 return sibling_found_idx;
908 ssize_t node_parent_idx
910 ssize_t node_sibling_idx = -1;
912 struct MCSS_STYLE effect_style;
917 node_sibling_idx = retrohtr_node( tree, node_parent_idx )->first_child;
918 while( 0 <= node_sibling_idx ) {
919 maug_mzero( &effect_style,
sizeof(
struct MCSS_STYLE ) );
921 parser, tree, NULL, &effect_style,
922 retrohtr_node( tree, node_sibling_idx )->tag );
924 if( MCSS_POSITION_ABSOLUTE == effect_style.POSITION ) {
926 retrohtr_node( tree, node_sibling_idx )->edge |= RETROHTR_EDGE_INSIDE;
928 }
else if( MCSS_DISPLAY_INLINE == effect_style.DISPLAY ) {
931 retrohtr_node( tree, node_sibling_idx )->edge |= RETROHTR_EDGE_LEFT;
934 retrohtr_node( tree, node_sibling_idx )->edge |= RETROHTR_EDGE_TOP;
936 if( 0 < row_idx && 0 < col_idx ) {
937 retrohtr_node( tree, node_sibling_idx )->edge |= RETROHTR_EDGE_INSIDE;
950 retrohtr_node( tree, node_sibling_idx )->edge |= RETROHTR_EDGE_TOP;
954 retrohtr_node( tree, node_sibling_idx )->edge |= RETROHTR_EDGE_LEFT;
957 assert( !mdata_vector_is_locked( &(parser->tags) ) );
958 mdata_vector_lock( &(parser->tags) );
960 p_tag_iter = mdata_vector_get( &(parser->tags),
961 retrohtr_node( tree, node_sibling_idx )->tag,
963 assert( NULL != p_tag_iter );
965 debug_printf( 1,
"marking node " SIZE_T_FMT
" (%s) edge: %u",
967 gc_mhtml_tag_names[p_tag_iter->base.type],
968 retrohtr_node( tree, node_sibling_idx )->edge );
970 mdata_vector_unlock( &(parser->tags) );
973 retrohtr_node( tree, node_sibling_idx )->next_sibling;
978 if( mdata_vector_is_locked( &(parser->tags) ) ) {
979 mdata_vector_unlock( &(parser->tags) );
987 struct MCSS_STYLE* prev_sibling_style,
988 struct MCSS_STYLE* parent_style, ssize_t node_idx,
size_t d
990 struct MCSS_STYLE child_prev_sibling_style;
991 struct MCSS_STYLE effect_style;
992 ssize_t child_iter_idx = -1;
993 ssize_t tag_idx = -1;
994 ssize_t node_iter_idx = -1;
995 ssize_t prev_sibling_idx = -1;
999 if( NULL == retrohtr_node( tree, node_idx ) ) {
1003 tag_idx = retrohtr_node( tree, node_idx )->tag;
1006 parser, tree, parent_style, &effect_style, tag_idx );
1009 retrohtr_find_prev_sibling_in_box_model( tree, node_idx );
1013 if( MCSS_POSITION_ABSOLUTE == effect_style.POSITION ) {
1016 if( mcss_prop_is_active_NOT_flag( effect_style.LEFT, AUTO ) ) {
1018 child_iter_idx = retrohtr_node( tree, node_idx )->parent;
1019 while( 0 <= retrohtr_node( tree, child_iter_idx )->parent ) {
1020 retrohtr_break_on_active_pos( child_iter_idx );
1021 child_iter_idx = retrohtr_node( tree, child_iter_idx )->parent;
1025 retrohtr_node( tree, node_idx )->x =
1026 retrohtr_node( tree, child_iter_idx )->x + effect_style.LEFT;
1028 if( mcss_prop_is_active_NOT_flag( effect_style.RIGHT, AUTO ) ) {
1030 child_iter_idx = retrohtr_node( tree, node_idx )->parent;
1031 while( 0 <= retrohtr_node( tree, child_iter_idx )->parent ) {
1032 retrohtr_break_on_active_pos( child_iter_idx );
1033 child_iter_idx = retrohtr_node( tree, child_iter_idx )->parent;
1037 retrohtr_node( tree, node_idx )->x =
1038 retrohtr_node( tree, child_iter_idx )->w -
1039 retrohtr_node( tree, node_idx )->w -
1044 MCSS_DISPLAY_INLINE == effect_style.DISPLAY &&
1045 MCSS_DISPLAY_INLINE == prev_sibling_style->DISPLAY &&
1046 0 <= prev_sibling_idx
1049 retrohtr_node( tree, node_idx )->x =
1050 retrohtr_node( tree, prev_sibling_idx )->x +
1051 retrohtr_node( tree, prev_sibling_idx )->w;
1053 }
else if( 0 <= retrohtr_node( tree, node_idx )->parent ) {
1054 retrohtr_node( tree, node_idx )->x = retrohtr_node_parent( tree, node_idx )->x;
1061 if( MCSS_POSITION_ABSOLUTE == effect_style.POSITION ) {
1064 if( mcss_prop_is_active_NOT_flag( effect_style.TOP, AUTO ) ) {
1066 child_iter_idx = retrohtr_node( tree, node_idx )->parent;
1067 while( 0 <= retrohtr_node( tree, child_iter_idx )->parent ) {
1068 retrohtr_break_on_active_pos( child_iter_idx );
1069 child_iter_idx = retrohtr_node( tree, child_iter_idx )->parent;
1073 retrohtr_node( tree, node_idx )->y =
1074 retrohtr_node( tree, child_iter_idx )->y + effect_style.TOP;
1076 if( mcss_prop_is_active_NOT_flag( effect_style.BOTTOM, AUTO ) ) {
1078 child_iter_idx = retrohtr_node( tree, node_idx )->parent;
1079 while( 0 <= retrohtr_node( tree, child_iter_idx )->parent ) {
1080 retrohtr_break_on_active_pos( child_iter_idx );
1081 child_iter_idx = retrohtr_node( tree, child_iter_idx )->parent;
1085 retrohtr_node( tree, node_idx )->y =
1086 retrohtr_node( tree, child_iter_idx )->h -
1087 retrohtr_node( tree, node_idx )->h -
1088 effect_style.BOTTOM;
1092 MCSS_DISPLAY_INLINE == effect_style.DISPLAY &&
1093 MCSS_DISPLAY_INLINE == prev_sibling_style->DISPLAY &&
1094 0 <= prev_sibling_idx
1097 retrohtr_node( tree, node_idx )->y = retrohtr_node( tree, prev_sibling_idx )->y;
1099 }
else if( 0 <= prev_sibling_idx ) {
1106 retrohtr_node( tree, node_idx )->y =
1107 retrohtr_node( tree, prev_sibling_idx )->y +
1108 retrohtr_node( tree, prev_sibling_idx )->h;
1110 }
else if( 0 <= retrohtr_node( tree, node_idx )->parent ) {
1113 retrohtr_node( tree, node_idx )->y = retrohtr_node_parent( tree, node_idx )->y;
1119 MCSS_POSITION_ABSOLUTE != retrohtr_node( tree, node_idx )->pos &&
1120 0 <= retrohtr_node( tree, node_idx )->parent &&
1121 mcss_prop_is_active_flag( effect_style.MARGIN_LEFT, AUTO ) &&
1122 mcss_prop_is_active_flag( effect_style.MARGIN_RIGHT, AUTO )
1125 retrohtr_node( tree, node_idx )->x =
1126 retrohtr_node_parent( tree, node_idx )->x +
1127 (retrohtr_node_parent( tree, node_idx )->w >> 1) -
1128 (retrohtr_node( tree, node_idx )->w >> 1);
1131 0 <= retrohtr_node( tree, node_idx )->parent &&
1132 mcss_prop_is_active_flag( effect_style.MARGIN_LEFT, AUTO ) &&
1133 mcss_prop_is_active_NOT_flag( effect_style.MARGIN_RIGHT, AUTO )
1137 retrohtr_node( tree, node_idx )->x =
1138 retrohtr_node_parent( tree, node_idx )->w -
1139 retrohtr_node( tree, node_idx )->w;
1141 }
else if( mcss_prop_is_active( effect_style.MARGIN_LEFT ) ) {
1143 retrohtr_node( tree, node_idx )->x += effect_style.MARGIN_LEFT;
1152 debug_printf( 1,
"(d: " SIZE_T_FMT
") node " SIZE_T_FMT
" is on edge: %u",
1153 d, node_idx, retrohtr_node( tree, node_idx )->edge );
1157 RETROHTR_EDGE_UNKNOWN != retrohtr_node( tree, node_idx )->edge );
1160 RETROHTR_EDGE_LEFT ==
1161 (RETROHTR_EDGE_LEFT & retrohtr_node( tree, node_idx )->edge)
1164 if( mcss_prop_is_active_NOT_flag( parent_style->PADDING_LEFT, AUTO ) ) {
1165 retrohtr_node( tree, node_idx )->x += parent_style->PADDING_LEFT;
1166 }
else if( mcss_prop_is_active_NOT_flag( parent_style->PADDING, AUTO ) ) {
1167 retrohtr_node( tree, node_idx )->x += parent_style->PADDING;
1172 RETROHTR_EDGE_TOP ==
1173 (RETROHTR_EDGE_TOP & retrohtr_node( tree, node_idx )->edge) &&
1175 RETROHTR_EDGE_LEFT ==
1176 (RETROHTR_EDGE_LEFT & retrohtr_node( tree, node_idx )->edge)
1179 if( mcss_prop_is_active_NOT_flag( parent_style->PADDING_TOP, AUTO ) ) {
1180 retrohtr_node( tree, node_idx )->y += parent_style->PADDING_TOP;
1181 }
else if( mcss_prop_is_active_NOT_flag( parent_style->PADDING, AUTO ) ) {
1182 retrohtr_node( tree, node_idx )->y += parent_style->PADDING;
1188 if( mcss_prop_is_active( effect_style.COLOR ) ) {
1189 retrohtr_node( tree, node_idx )->fg = effect_style.COLOR;
1192 if( mcss_prop_is_active( effect_style.BACKGROUND_COLOR ) ) {
1193 retrohtr_node( tree, node_idx )->bg = effect_style.BACKGROUND_COLOR;
1198 retrohtr_mark_edge_child_nodes( parser, tree, node_idx );
1200 maug_mzero( &child_prev_sibling_style,
sizeof(
struct MCSS_STYLE ) );
1201 node_iter_idx = retrohtr_node( tree, node_idx )->first_child;
1202 while( 0 <= node_iter_idx ) {
1207 parser, tree, &child_prev_sibling_style, &effect_style,
1208 node_iter_idx, d + 1 );
1210 node_iter_idx = retrohtr_node( tree, node_iter_idx )->next_sibling;
1213 assert( !mdata_vector_is_locked( &(parser->tags) ) );
1214 mdata_vector_lock( &(parser->tags) );
1215 p_tag_iter = mdata_vector_get( &(parser->tags), tag_idx,
union MHTML_TAG );
1216 assert( NULL != p_tag_iter );
1218 if( MHTML_TAG_TYPE_INPUT == p_tag_iter->base.type ) {
1220 retval = retrogui_pos_ctl( &(tree->gui), node_idx,
1221 retrohtr_node_screen_x( tree, node_idx ),
1222 retrohtr_node_screen_y( tree, node_idx ),
1223 retrohtr_node( tree, node_idx )->w,
1224 retrohtr_node( tree, node_idx )->h );
1225 maug_cleanup_if_not_ok();
1228 debug_printf( RETROHTR_TRACE_LVL,
1229 "setting node " SIZE_T_FMT
" dirty...", node_idx );
1230 retrohtr_node( tree, node_idx )->flags |= RETROHTR_NODE_FLAG_DIRTY;
1234 if( mdata_vector_is_locked( &(parser->tags) ) ) {
1235 mdata_vector_unlock( &(parser->tags) );
1241 if( NULL != prev_sibling_style ) {
1243 prev_sibling_style, &effect_style,
1244 sizeof(
struct MCSS_STYLE ) );
1252 ssize_t node_idx,
size_t d
1254 char* strpool = NULL;
1259 node = retrohtr_node( tree, node_idx );
1261 if( NULL == node ) {
1267 if( 0 > node->tag ) {
1271 if( RETROHTR_NODE_FLAG_DIRTY != (RETROHTR_NODE_FLAG_DIRTY & node->flags) ) {
1275 assert( !mdata_vector_is_locked( &(parser->tags) ) );
1276 mdata_vector_lock( &(parser->tags) );
1278 p_tag = mdata_vector_get( &(parser->tags), node->tag,
union MHTML_TAG );
1279 if( NULL == p_tag ) {
1284 if( MHTML_TAG_TYPE_TEXT == p_tag->base.type ) {
1287 0 > p_tag->TEXT.content_idx ||
1288#ifdef RETROGXC_PRESENT
1291 (MAUG_MHANDLE)NULL == node->font_h
1297 mdata_strpool_lock( &(parser->strpool), strpool );
1299#ifdef RETROGXC_PRESENT
1305 &(strpool[p_tag->TEXT.content_idx]), p_tag->TEXT.content_sz,
1306#ifdef RETROGXC_PRESENT
1311 retrohtr_node_screen_x( tree, node_idx ),
1312 retrohtr_node_screen_y( tree, node_idx ),
1313 node->w, node->h, 0 );
1315 mdata_strpool_unlock( &(parser->strpool), strpool );
1317 }
else if( MHTML_TAG_TYPE_BODY == p_tag->base.type ) {
1320 RETROHTR_TRACE_LVL,
"drawing BODY node " SIZE_T_FMT
"...", node_idx );
1323 if( RETROFLAT_COLOR_NULL != node->bg ) {
1326 retrohtr_node_screen_x( tree, node_idx ),
1327 retrohtr_node_screen_y( tree, node_idx ),
1328 retrohtr_node( tree, node_idx )->w,
1329 retrohtr_node( tree, node_idx )->h,
1330 RETROFLAT_FLAGS_FILL );
1333 }
else if( MHTML_TAG_TYPE_IMG == p_tag->base.type ) {
1336 if( !retroflat_bitmap_ok( &(retrohtr_node( tree, node_idx )->bitmap) ) ) {
1341 RETROHTR_TRACE_LVL,
"drawing IMG node " SIZE_T_FMT
"...", node_idx );
1344 NULL, &(retrohtr_node( tree, node_idx )->bitmap),
1346 retrohtr_node_screen_x( tree, node_idx ),
1347 retrohtr_node_screen_y( tree, node_idx ),
1348 retroflat_bitmap_w( &(retrohtr_node( tree, node_idx )->bitmap) ),
1349 retroflat_bitmap_h( &(retrohtr_node( tree, node_idx )->bitmap) ),
1354 }
else if( MHTML_TAG_TYPE_INPUT == p_tag->base.type ) {
1357 RETROHTR_TRACE_LVL,
"setting tree GUI dirty..." );
1359 tree->gui.flags |= RETROGUI_FLAGS_DIRTY;
1362 if( RETROFLAT_COLOR_NULL == node->bg ) {
1367 RETROHTR_TRACE_LVL,
"drawing xs node " SIZE_T_FMT
"...",
1374 retrohtr_node_screen_x( tree, node_idx ),
1375 retrohtr_node_screen_y( tree, node_idx ),
1380 node->flags &= ~RETROHTR_NODE_FLAG_DIRTY;
1384 if( mdata_vector_is_locked( &(parser->tags) ) ) {
1385 mdata_vector_unlock( &(parser->tags) );
1388 if( MERROR_OK != retval ) {
1389 error_printf(
"failed drawing node: " SIZE_T_FMT, node_idx );
1394 retrohtr_tree_draw( parser, tree, node->
first_child, d + 1 );
1396 retrohtr_tree_draw( parser, tree, node->
next_sibling, d );
1401 RETROHTR_TREE_FLAG_GUI_ACTIVE ==
1402 (tree->flags & RETROHTR_TREE_FLAG_GUI_ACTIVE)
1404 retrogui_redraw_ctls( &(tree->gui) );
1412 RETROFLAT_IN_KEY* input,
1418 assert( retrohtr_tree_is_locked( tree ) );
1421 RETROHTR_TREE_FLAG_GUI_ACTIVE !=
1422 (RETROHTR_TREE_FLAG_GUI_ACTIVE & tree->flags)
1432 RETROHTR_TRACE_LVL,
"setting node " SIZE_T_FMT
" dirty...", idc );
1433 retrohtr_node( tree, idc )->flags |= RETROHTR_NODE_FLAG_DIRTY;
1436 if( MERROR_OK != retval ) {
1445 ssize_t node_idx,
size_t d
1452 if( 0 > node_idx ) {
1456 assert( !mdata_vector_is_locked( &(parser->tags) ) );
1457 mdata_vector_lock( &(parser->tags) );
1459 p_tag_iter = mdata_vector_get(
1461 if( NULL == p_tag_iter ) {
1466 maug_mzero( indents, 30 );
1467 for( i = 0 ; d > i ; i++ ) {
1468 if( maug_strlen( indents ) >= 30 ) {
1471 strcat( indents,
" " );
1477 "%s" SSIZE_T_FMT
" (tag %s): x: " SSIZE_T_FMT
", y: " SSIZE_T_FMT
1478 " (" SSIZE_T_FMT
" x " SSIZE_T_FMT
") f: "
1479#ifdef RETROGXC_PRESENT
1485 0 <= tree->
nodes[node_idx].tag ?
1486 gc_mhtml_tag_names[p_tag_iter->base.type] :
"ROOT",
1487 tree->
nodes[node_idx].x, tree->
nodes[node_idx].y,
1488 tree->
nodes[node_idx].w, tree->
nodes[node_idx].h,
1489#ifdef RETROGXC_PRESENT
1490 tree->
nodes[node_idx].font_idx
1492 tree->
nodes[node_idx].font_h
1496 mdata_vector_unlock( &(parser->tags) );
1498 retval = retrohtr_tree_dump(
1500 maug_cleanup_if_not_ok();
1502 retval = retrohtr_tree_dump(
1504 maug_cleanup_if_not_ok();
1513 debug_printf( RETROHTR_TRACE_LVL,
"freeing render nodes..." );
1521 RETROHTR_TREE_FLAG_GUI_ACTIVE ==
1522 (tree->flags & RETROHTR_TREE_FLAG_GUI_ACTIVE)
1524 retrogui_destroy( &(tree->gui) );
1528 retrohtr_tree_unlock( tree );
1530 if( (MAUG_MHANDLE)NULL != tree->nodes_h ) {
1531 maug_mfree( tree->nodes_h );
1542 debug_printf( RETROHTR_TRACE_LVL,
1543 "allocating " SIZE_T_FMT
" nodes...", tree->
nodes_sz_max );
1544 tree->nodes_h = maug_malloc(
1546 maug_cleanup_if_null_alloc( MAUG_MHANDLE, tree->nodes_h );
int MERROR_RETVAL
Return type indicating function returns a value from this list.
Definition merror.h:19
MERROR_RETVAL retroflat_blit_bitmap(struct RETROFLAT_BITMAP *target, struct RETROFLAT_BITMAP *src, size_t s_x, size_t s_y, int16_t d_x, int16_t d_y, size_t w, size_t h, int16_t instance)
Blit the contents of a ::RETROFLAT_BITMAP onto another ::RETROFLAT_BITMAP.
MERROR_RETVAL retroflat_load_bitmap(const char *filename, struct RETROFLAT_BITMAP *bmp_out, uint8_t flags)
Load a bitmap into the given ::RETROFLAT_BITMAP structure if it is available. Bitmaps are subject to ...
#define RETROFLAT_INSTANCE_NULL
Pass to retroflat_blit_bitmap() instance arg if this is not a sprite (i.e. if it is a background tile...
Definition retroflt.h:569
int8_t RETROFLAT_COLOR
Defines an index in the platform-specific color-table.
Definition retroflt.h:325
#define RETROFLAT_FLAGS_LITERAL_PATH
Flag for retroflat_load_bitmap() to not use assets path.
Definition retroflt.h:384
#define RETROFLAT_FLAGS_BITMAP_SILENT
flag for retroflat_load_bitmap() to not show an error dialog if a bitmap fails to load (on supported ...
Definition retroflt.h:390
void retroflat_rect(struct RETROFLAT_BITMAP *target, const RETROFLAT_COLOR color, int16_t x, int16_t y, int16_t w, int16_t h, uint8_t flags)
Draw a rectangle onto the target ::RETROFLAT_BITMAP.
#define RETROFLAT_FLAGS_FILL
Flag for retroflat_rect() or retroflat_ellipse(), indicating drawn shape should be filled.
Definition retroflt.h:373
retrogui_idc_t retrogui_poll_ctls(struct RETROGUI *gui, RETROFLAT_IN_KEY *p_input, struct RETROFLAT_INPUT *input_evt)
Poll for the last clicked control and maintain listboxes and menus.
int16_t retrogui_idc_t
Unique identifying constant number for controls.
Definition retrogui.h:292
void retrofont_string(retroflat_blit_t *target, RETROFLAT_COLOR color, const char *str, size_t str_sz, MAUG_MHANDLE font_h, size_t x, size_t y, size_t max_w, size_t max_h, uint8_t flags)
Draw a string with the given font.
MERROR_RETVAL retrofont_load(const char *font_name, MAUG_MHANDLE *p_font_h, uint8_t glyph_h, uint16_t first_glyph, uint16_t glyphs_count)
Load a font for drawing.
size_t nodes_sz_max
Current alloc'd number of nodes in RETROHTR_RENDER_NODE::nodes_h.
Definition retrohtr.h:67
ssize_t parent
Index of container's render node in RETROHTR_RENDER_TREE.
Definition retrohtr.h:51
ssize_t first_child
Index of first child's render node in RETROHTR_RENDER_TREE.
Definition retrohtr.h:53
MERROR_RETVAL retrohtr_apply_styles(struct MHTML_PARSER *parser, struct RETROHTR_RENDER_TREE *tree, struct MCSS_STYLE *parent_style, struct MCSS_STYLE *effect_style, ssize_t tag_idx)
Create a style node that is a composite of a parent style and the styles applicable to the classes/ID...
ssize_t next_sibling
Index of next sibling's render node in RETROHTR_RENDER_TREE.
Definition retrohtr.h:55
size_t nodes_sz
Current active number of nodes in RETROHTR_RENDER_NODE::nodes_h.
Definition retrohtr.h:65
struct RETROHTR_RENDER_NODE * nodes
Locked pointer to nodes when locked with retrohtr_tree_lock().
Definition retrohtr.h:63
Definition retrogui.h:430
MAUG_MHANDLE font_h
Font used to draw any attached RETROGUI_CTL.
Definition retrogui.h:456
Definition retrogui.h:412