got overlapped gui clipping working

This commit is contained in:
Allen Webster 2016-04-26 17:09:41 -04:00
parent efc042af3e
commit 2e3262dd18
3 changed files with 98 additions and 73 deletions

View File

@ -3650,6 +3650,7 @@ step_file_view(System_Functions *system, View *view, b32 is_active){
if (view->showing_ui == VUI_None){ if (view->showing_ui == VUI_None){
gui_begin_overlap(target); gui_begin_overlap(target);
{
do_widget(view, target); do_widget(view, target);
gui_begin_serial_section(target); gui_begin_serial_section(target);
@ -3683,13 +3684,11 @@ step_file_view(System_Functions *system, View *view, b32 is_active){
} }
gui_begin_scrollable(target, view->showing_ui, view->file_scroll, delta); gui_begin_scrollable(target, view->showing_ui, view->file_scroll, delta);
gui_do_file(target); gui_do_file(target);
gui_end_scrollable(target); gui_end_scrollable(target);
} }
gui_end_serial_section(target); gui_end_serial_section(target);
}
gui_end_overlap(target); gui_end_overlap(target);
} }
else{ else{
@ -4071,7 +4070,7 @@ do_input_file_view(System_Functions *system, Exchange *exchange,
case guicom_file: case guicom_file:
{ {
f32 new_min_y = -(f32)(gui_session.clip_rect.y0 - gui_session.rect.y0); f32 new_min_y = -(f32)(gui_session_get_eclipsed_y(&gui_session) - gui_session.rect.y0);
f32 new_max_y = view_compute_max_target_y(view); f32 new_max_y = view_compute_max_target_y(view);
view->gui_target.scroll_updated.min_y = new_min_y; view->gui_target.scroll_updated.min_y = new_min_y;
@ -4663,10 +4662,19 @@ do_render_file_view(System_Functions *system, Exchange *exchange,
v = view_get_scroll_y(view); v = view_get_scroll_y(view);
i32_Rect clip_rect = rect;
draw_push_clip(target, clip_rect);
for (h = (GUI_Header*)gui_target->push.base; for (h = (GUI_Header*)gui_target->push.base;
h->type; h->type;
h = NextHeader(h)){ h = NextHeader(h)){
if (gui_interpret(&view->gui_target, &gui_session, h)){ if (gui_interpret(&view->gui_target, &gui_session, h)){
if (gui_session.clip_y > clip_rect.y0){
clip_rect.y0 = gui_session.clip_y;
draw_change_clip(target, clip_rect);
}
switch (h->type){ switch (h->type){
case guicom_top_bar: case guicom_top_bar:
{ {
@ -4778,18 +4786,20 @@ do_render_file_view(System_Functions *system, Exchange *exchange,
}break; }break;
case guicom_begin_scrollable_section: case guicom_begin_scrollable_section:
{ clip_rect.x1 -= gui_session.scroll_bar_w;
target->push_clip(target, gui_session.absolute_rect); draw_push_clip(target, clip_rect);
}break; break;
case guicom_end_scrollable_section: case guicom_end_scrollable_section:
{ clip_rect.x1 += gui_session.scroll_bar_w;
target->pop_clip(target); draw_pop_clip(target);
}break; break;
} }
} }
} }
draw_pop_clip(target);
return(result); return(result);
#if 0 #if 0

View File

@ -428,6 +428,8 @@ internal void
gui_begin_scrollable(GUI_Target *target, u32 scroll_id, GUI_Scroll_Vars scroll_vars, f32 delta){ gui_begin_scrollable(GUI_Target *target, u32 scroll_id, GUI_Scroll_Vars scroll_vars, f32 delta){
GUI_Header *h; GUI_Header *h;
gui_begin_serial_section(target);
target->delta = delta; target->delta = delta;
h = gui_push_simple_command(target, guicom_scrollable); h = gui_push_simple_command(target, guicom_scrollable);
@ -444,6 +446,7 @@ gui_begin_scrollable(GUI_Target *target, u32 scroll_id, GUI_Scroll_Vars scroll_v
internal void internal void
gui_end_scrollable(GUI_Target *target){ gui_end_scrollable(GUI_Target *target){
gui_push_simple_command(target, guicom_end_scrollable_section); gui_push_simple_command(target, guicom_end_scrollable_section);
gui_end_serial_section(target);
} }
internal void internal void
@ -453,17 +456,16 @@ gui_activate_scrolling(GUI_Target *target){
struct GUI_Section{ struct GUI_Section{
b32 overlapped; b32 overlapped;
i32 max_v, v; i32 max_v, v, top_v;
}; };
struct GUI_Session{ struct GUI_Session{
i32_Rect full_rect; i32_Rect full_rect;
i32_Rect clip_rect;
i32_Rect rect; i32_Rect rect;
i32_Rect absolute_rect;
f32 suggested_min_y; f32 suggested_min_y;
f32 suggested_max_y; f32 suggested_max_y;
i32 clip_y;
i32 line_height; i32 line_height;
i32 scroll_bar_w; i32 scroll_bar_w;
@ -479,6 +481,26 @@ struct GUI_Session{
#define GUIScrollbarWidth 16 #define GUIScrollbarWidth 16
internal i32
gui_session_get_eclipsed_y(GUI_Session *session){
GUI_Section *section = session->sections;
i32 count = session->t + 1, i;
i32 max_v = 0;
for (i = 0; i < count; ++i, ++section){
if (section->overlapped){
max_v = Max(max_v, section->max_v);
}
}
max_v = Max(max_v, session->sections[count-1].top_v);
return(max_v);
}
internal i32
gui_session_get_current_top(GUI_Session *session){
i32 result = session->sections[session->t].top_v;
return(result);
}
internal void internal void
gui_session_init(GUI_Session *session, i32_Rect full_rect, i32 line_height){ gui_session_init(GUI_Session *session, i32_Rect full_rect, i32 line_height){
GUI_Section *section; GUI_Section *section;
@ -498,8 +520,10 @@ gui_section_end_item(GUI_Section *section, i32 v){
if (!section->overlapped){ if (!section->overlapped){
section->v = v; section->v = v;
} }
if (section->max_v < v){
section->max_v = v; section->max_v = v;
} }
}
inline i32_Rect inline i32_Rect
gui_layout_top_bottom(GUI_Session *session, i32 y0, i32 y1){ gui_layout_top_bottom(GUI_Session *session, i32 y0, i32 y1){
@ -608,6 +632,7 @@ gui_interpret(GUI_Target *target, GUI_Session *session, GUI_Header *h){
new_section->overlapped = 1; new_section->overlapped = 1;
new_section->v = y; new_section->v = y;
new_section->max_v = y; new_section->max_v = y;
new_section->top_v = y;
break; break;
case guicom_end_overlap: case guicom_end_overlap:
@ -625,6 +650,7 @@ gui_interpret(GUI_Target *target, GUI_Session *session, GUI_Header *h){
new_section->overlapped = 0; new_section->overlapped = 0;
new_section->v = y; new_section->v = y;
new_section->max_v = y; new_section->max_v = y;
new_section->top_v = y;
break; break;
case guicom_end_serial: case guicom_end_serial:
@ -732,7 +758,7 @@ gui_interpret(GUI_Target *target, GUI_Session *session, GUI_Header *h){
case guicom_end_scrollable_section: case guicom_end_scrollable_section:
always_give_to_user = 1; always_give_to_user = 1;
session->suggested_min_y = -(f32)(session->clip_rect.y0 - session->rect.y0); session->suggested_min_y = -(f32)(gui_session_get_eclipsed_y(session) - gui_session_get_current_top(session));
session->suggested_max_y = (f32)(session->scrollable_items_bottom - session->full_rect.y1 * .5f); session->suggested_max_y = (f32)(session->scrollable_items_bottom - session->full_rect.y1 * .5f);
if (session->suggested_max_y < 0){ if (session->suggested_max_y < 0){
session->suggested_max_y = 0; session->suggested_max_y = 0;
@ -741,19 +767,7 @@ gui_interpret(GUI_Target *target, GUI_Session *session, GUI_Header *h){
} }
if (do_layout){ if (do_layout){
GUI_Section *section = session->sections;
i32 max_v = 0;
i32 i = 0;
session->absolute_rect = rect;
if (give_to_user){ if (give_to_user){
for (i = 0; i <= session->t; ++i, ++section){
if (section->overlapped){
max_v = Max(max_v, section->max_v);
}
}
if (session->is_scrollable){ if (session->is_scrollable){
session->scrollable_items_bottom = Max(session->scrollable_items_bottom, rect.y1); session->scrollable_items_bottom = Max(session->scrollable_items_bottom, rect.y1);
} }
@ -763,13 +777,6 @@ gui_interpret(GUI_Target *target, GUI_Session *session, GUI_Header *h){
if (rect.y1 > session->full_rect.y0){ if (rect.y1 > session->full_rect.y0){
session->rect = rect; session->rect = rect;
rect.y0 += scroll_v;
if (rect.y0 < max_v){
rect.y0 = max_v;
}
rect.y0 -= scroll_v;
session->clip_rect = rect;
} }
else{ else{
give_to_user = 0; give_to_user = 0;
@ -785,6 +792,8 @@ gui_interpret(GUI_Target *target, GUI_Session *session, GUI_Header *h){
} }
} }
session->clip_y = gui_session_get_eclipsed_y(session);
return(give_to_user || always_give_to_user); return(give_to_user || always_give_to_user);
} }

View File

@ -19,6 +19,12 @@ draw_pop_clip(Render_Target *target){
target->pop_clip(target); target->pop_clip(target);
} }
inline void
draw_change_clip(Render_Target *target, i32_Rect clip_box){
target->pop_clip(target);
target->push_clip(target, clip_box);
}
internal void internal void
begin_render_section(Render_Target *target, System_Functions *system){ begin_render_section(Render_Target *target, System_Functions *system){
Font_Set *font_set = &target->font_set; Font_Set *font_set = &target->font_set;