summaryrefslogtreecommitdiff
path: root/src/editor/toolview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/editor/toolview.cpp')
-rw-r--r--src/editor/toolview.cpp103
1 files changed, 94 insertions, 9 deletions
diff --git a/src/editor/toolview.cpp b/src/editor/toolview.cpp
index df1d79a..56e55f2 100644
--- a/src/editor/toolview.cpp
+++ b/src/editor/toolview.cpp
@@ -7,6 +7,9 @@ const I32 TOOLVIEW_INNER_PAD = 20;
const I32 TOOLVIEW_ROW_HEIGHT = 20;
const I32 TOOLVIEW_ROW_GAP = 4;
const I32 TOOLVIEW_WALL_SHAPE_LIST_HEIGHT = 54;
+const I32 TOOLVIEW_SCROLL_STEP = 20;
+const I32 TOOLVIEW_SCROLLBAR_W = 8;
+const I32 TOOLVIEW_SCROLLBAR_MIN_H = 18;
GUI_EDITOR_TOOLVIEW* gui_editor_toolview_from_item_child( GUI_BASE* child ) {
if( !child || !child->parent || !child->parent->parent )
@@ -15,6 +18,25 @@ GUI_EDITOR_TOOLVIEW* gui_editor_toolview_from_item_child( GUI_BASE* child ) {
return (GUI_EDITOR_TOOLVIEW*)child->parent->parent;
}
+I32 gui_editor_toolview_visible_h( GUI_EDITOR_TOOLVIEW* view ) {
+ return std::max( 1, view->h - 4 );
+}
+
+I32 gui_editor_toolview_max_scroll( GUI_EDITOR_TOOLVIEW* view ) {
+ return std::max( 0, view->content_h - gui_editor_toolview_visible_h( view ) );
+}
+
+void gui_editor_toolview_clamp_scroll( GUI_EDITOR_TOOLVIEW* view ) {
+ if( !view )
+ return;
+
+ I32 max_scroll = gui_editor_toolview_max_scroll( view );
+ view->scroll = std::min( std::max( 0, view->scroll ), max_scroll );
+ if( view->itemview ) {
+ view->itemview->y = TOOLVIEW_TITLE_OFFSET - view->scroll;
+ }
+}
+
void gui_editor_toolview_sanitize_float_input( void* ptr ) {
GUI_FLOATINPUT* input = (GUI_FLOATINPUT*)ptr;
F32* pval = input->pval;
@@ -23,7 +45,6 @@ void gui_editor_toolview_sanitize_float_input( void* ptr ) {
if( !isfinite( *pval ) ) *pval = EDITOR_DEFAULT_POLY_SIDES;
F32 rounded = floorf( *pval + 0.5f );
if( rounded < EDITOR_POLY_SIDES_MIN ) rounded = EDITOR_POLY_SIDES_MIN;
- if( rounded > EDITOR_POLY_SIDES_MAX ) rounded = EDITOR_POLY_SIDES_MAX;
*pval = rounded;
return;
}
@@ -148,7 +169,7 @@ I32 gui_editor_toolview_create_poly_sides_input( GUI_EDITOR_TOOLVIEW* view, I32
"sides",
&editor->tool.polysides,
(F32)EDITOR_POLY_SIDES_MIN,
- (F32)EDITOR_POLY_SIDES_MAX,
+ INFINITY,
1.f,
"%.0f"
);
@@ -168,14 +189,15 @@ I32 gui_editor_toolview_create_wall_height_input( GUI_EDITOR_TOOLVIEW* view, I32
}
I32 gui_editor_toolview_create_placement_height_input( GUI_EDITOR_TOOLVIEW* view, I32 y ) {
+ F32 step = isfinite( editor->grid ) && editor->grid > 0.f ? editor->grid : 1.f;
return gui_editor_toolview_create_float_input(
view,
y,
"placement z",
&editor->tool.placementheight,
- -4096.f,
- 4096.f,
- 1.f,
+ -INFINITY,
+ INFINITY,
+ step,
"%.0f"
);
}
@@ -204,6 +226,8 @@ void gui_editor_toolview_update( GUI_EDITOR_TOOLVIEW* view ) {
if( editor->tool.type == EDITOR_TOOL_WALL ) {
y = gui_editor_toolview_create_wallshape_dropdown( view, y );
if( view->wallshape_dropdown_open ) {
+ view->content_h = y + 6;
+ gui_editor_toolview_clamp_scroll( view );
gui_set_view( oldview );
return;
}
@@ -220,9 +244,31 @@ void gui_editor_toolview_update( GUI_EDITOR_TOOLVIEW* view ) {
y = gui_editor_toolview_create_placement_height_input( view, y );
}
+ view->content_h = y + 6;
+ gui_editor_toolview_clamp_scroll( view );
gui_set_view( oldview );
}
+void gui_editor_toolview_draw_scrollbar( GUI_EDITOR_TOOLVIEW* view, I32 x, I32 y, I32 h ) {
+ I32 max_scroll = gui_editor_toolview_max_scroll( view );
+ if( max_scroll <= 0 )
+ return;
+
+ I32 track_x = x + view->w - TOOLVIEW_SCROLLBAR_W - 3;
+ I32 track_y = y + 2;
+ I32 track_h = std::max( 8, h - 4 );
+ gui_draw_frect( track_x, track_y, TOOLVIEW_SCROLLBAR_W, track_h, ui_clr.bg_alt );
+ gui_draw_rect( track_x, track_y, TOOLVIEW_SCROLLBAR_W, track_h, ui_clr.border );
+
+ I32 visible_h = gui_editor_toolview_visible_h( view );
+ I32 thumb_h = std::max( TOOLVIEW_SCROLLBAR_MIN_H, ( track_h * visible_h ) / std::max( 1, view->content_h ) );
+ thumb_h = std::min( thumb_h, track_h );
+ I32 travel = std::max( 1, track_h - thumb_h );
+ I32 thumb_y = track_y + ( travel * view->scroll ) / std::max( 1, max_scroll );
+
+ gui_draw_frect( track_x + 1, thumb_y + 1, TOOLVIEW_SCROLLBAR_W - 2, std::max( 1, thumb_h - 2 ), ui_clr.txt );
+}
+
void gui_editor_toolview_draw_fn( void* ptr ) {
if( !editor->map ) return;
@@ -233,16 +279,52 @@ void gui_editor_toolview_draw_fn( void* ptr ) {
I32 w = view->w;
I32 h = view->h;
- STR<64> title{};
- gui_editor_toolview_get_title( view, title );
- gui_draw_str( x, y, ALIGN_L, FNT_JPN12, ui_clr.txt, title );
+ gui_draw_str( x, y, ALIGN_L, FNT_JPN12, ui_clr.txt, "contextual tool options" );
y += TOOLVIEW_TITLE_OFFSET;
CLR col = gui_is_fg_window( view )? ui_clr.border : ui_clr.border_inactive;
gui_draw_frect( x, y, w, h, col );
gui_draw_frect( x+1, y+1, w-2, h-2, ui_clr.bg_sec );
+ gui_editor_toolview_clamp_scroll( view );
+ I32 max_scroll = gui_editor_toolview_max_scroll( view );
+ I32 clip_w = w - 4;
+ if( max_scroll > 0 )
+ clip_w -= TOOLVIEW_SCROLLBAR_W + 2;
+
+ gui_draw_push_clip( x + 2, y + 2, std::max( 1, clip_w ), std::max( 1, h - 4 ) );
view->itemview->draw_fn( view->itemview );
+ gui_draw_pop_clip();
+ gui_editor_toolview_draw_scrollbar( view, x, y, h );
+}
+
+void gui_editor_toolview_input_fn( void* ptr ) {
+ GUI_EDITOR_TOOLVIEW* view = (GUI_EDITOR_TOOLVIEW*)ptr;
+ gui_base_input_fn( ptr );
+
+ I32 x = gui_relx( view );
+ I32 y = gui_rely( view ) + TOOLVIEW_TITLE_OFFSET;
+ I32 w = view->w;
+ I32 h = view->h;
+
+ I32 mx, my;
+ gui_cursor_pos( &mx, &my );
+ U8 inbounds = mx >= x && mx <= x + w && my >= y && my <= y + h;
+
+ if( inbounds ) {
+ U8 scroll = gui_mbutton_down( GUI_MBTNSCROLL );
+ if( scroll && gui_editor_toolview_max_scroll( view ) > 0 ) {
+ if( scroll == 1 )
+ view->scroll -= TOOLVIEW_SCROLL_STEP;
+ else if( scroll == (U8)-1 )
+ view->scroll += TOOLVIEW_SCROLL_STEP;
+
+ gui_editor_toolview_clamp_scroll( view );
+ gui_capture_scroll();
+ }
+ }
+
+ gui_editor_toolview_clamp_scroll( view );
}
GUI_EDITOR_TOOLVIEW* gui_editor_toolview( I32 x, I32 y, I32 w, I32 h ) {
@@ -257,8 +339,10 @@ GUI_EDITOR_TOOLVIEW* gui_editor_toolview( I32 x, I32 y, I32 w, I32 h ) {
view->ybound = view->h + TOOLVIEW_TITLE_OFFSET;
strcpy( view->name, "EDITOR_PROP_VIEW" );
view->draw_fn = gui_editor_toolview_draw_fn;
- view->input_fn = gui_base_input_fn;
+ view->input_fn = gui_editor_toolview_input_fn;
view->wallshape_dropdown_open = 0;
+ view->scroll = 0;
+ view->content_h = 0;
GUI_VIEW* parent = gui_get_view();
parent->children.push( view );
@@ -266,6 +350,7 @@ GUI_EDITOR_TOOLVIEW* gui_editor_toolview( I32 x, I32 y, I32 w, I32 h ) {
gui_set_view( view );
view->itemview = gui_view( 0, TOOLVIEW_TITLE_OFFSET, w, h );
+ view->itemview->initheld = 1;
gui_set_view( parent );