Usability: Logic editor
authorTon Roosendaal <ton@blender.org>
Tue, 30 Oct 2012 15:33:03 +0000 (15:33 +0000)
committerTon Roosendaal <ton@blender.org>
Tue, 30 Oct 2012 15:33:03 +0000 (15:33 +0000)
- View now restricts to the actual region you work on. Makes zoom and pan nicer.
- Added HOME for reset view to 1:1 zoom level.

Also: fixed nasty bug in view2d code that checked validity of 2d views, only
showed (afaik) in the logic eidtor though.

Effect was that zoom in/out would weirdly jump when going across zoomlevel 1.

source/blender/editors/interface/view2d.c
source/blender/editors/space_logic/logic_window.c
source/blender/editors/space_logic/space_logic.c

index fb7a26155838fcd6e161ba548449c180047c0104..f1a3f59bc22ddab075872f3bdd5a8a630019eaac 100644 (file)
@@ -599,7 +599,7 @@ void UI_view2d_curRect_validate_resize(View2D *v2d, int resize)
                        if ((cur->xmin < tot->xmin) && (cur->xmax > tot->xmax)) {
                                /* outside boundaries on both sides, so take middle-point of tot, and place in balanced way */
                                temp = BLI_rctf_cent_x(tot);
-                               diff = curheight * 0.5f;
+                               diff = curwidth * 0.5f;
                                
                                cur->xmin = temp - diff;
                                cur->xmax = temp + diff;
index bffabe6d16074fd9b41a4bcc118ed6ba2905b25b..5a8a7cef119e9b7d2c0ffc789d036445510d04a0 100644 (file)
@@ -56,6 +56,7 @@
 #include "BKE_library.h"
 #include "BKE_main.h"
 #include "BKE_sca.h"
+#include "BKE_screen.h"
 
 #include "ED_util.h"
 
@@ -66,6 +67,7 @@
 #include "BLF_translation.h"
 
 #include "UI_interface.h"
+#include "UI_view2d.h"
 
 #include "RNA_access.h"
 
@@ -2208,15 +2210,13 @@ void logic_buttons(bContext *C, ARegion *ar)
        SpaceLogic *slogic= CTX_wm_space_logic(C);
        Object *ob= CTX_data_active_object(C);
        ID **idar;
-       
        PointerRNA logic_ptr, settings_ptr, object_ptr;
-       
        uiLayout *layout, *row, *box;
        uiBlock *block;
        uiBut *but;
        char uiblockstr[32];
        short a, count;
-       int xco, yco, width;
+       int xco, yco, width, height;
        
        if (ob==NULL) return;
        
@@ -2270,7 +2270,7 @@ void logic_buttons(bContext *C, ARegion *ar)
        
        /* ****************** Controllers ****************** */
        
-       xco= 420; yco= 170; width= 300;
+       xco= 420; yco= -10; width= 300;
        layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, xco, yco, width, 20, UI_GetStyle());
        row = uiLayoutRow(layout, TRUE);
        
@@ -2373,11 +2373,11 @@ void logic_buttons(bContext *C, ARegion *ar)
                }
        }
        uiBlockLayoutResolve(block, NULL, &yco);        /* stores final height in yco */
-       
+       height = yco;
        
        /* ****************** Sensors ****************** */
        
-       xco= 10; yco= 170; width= 340;
+       xco= 10; yco= -10; width= 340;
        layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, xco, yco, width, 20, UI_GetStyle());
        row = uiLayoutRow(layout, TRUE);
        
@@ -2442,10 +2442,11 @@ void logic_buttons(bContext *C, ARegion *ar)
                }
        }
        uiBlockLayoutResolve(block, NULL, &yco);        /* stores final height in yco */
+       height = MIN2(height, yco);
        
        /* ****************** Actuators ****************** */
        
-       xco= 800; yco= 170; width= 340;
+       xco= 800; yco= -10; width= 340;
        layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, xco, yco, width, 20, UI_GetStyle());
        row = uiLayoutRow(layout, TRUE);
        
@@ -2513,13 +2514,21 @@ void logic_buttons(bContext *C, ARegion *ar)
                }
        }
        uiBlockLayoutResolve(block, NULL, &yco);        /* stores final height in yco */
+       height = MIN2(height, yco);
+
+       UI_view2d_totRect_set(&ar->v2d, 1150, height);
        
-       
+       /* set the view */
+       UI_view2d_view_ortho(&ar->v2d);
+
        uiComposeLinks(block);
        
        uiEndBlock(C, block);
        uiDrawBlock(C, block);
        
+       /* restore view matrix */
+       UI_view2d_view_restore(C);
+       
        if (idar) MEM_freeN(idar);
 }
 
index f965969504c5b00b7eb7e5db4ca7f491ed14abab..4cd53215697a9cc3840b6ccc7d69621c1a27a0cf 100644 (file)
@@ -84,8 +84,9 @@ ARegion *logic_has_buttons_region(ScrArea *sa)
 
 /* ******************** default callbacks for image space ***************** */
 
-static SpaceLink *logic_new(const bContext *UNUSED(C))
+static SpaceLink *logic_new(const bContext *C)
 {
+       ScrArea *sa= CTX_wm_area(C);
        ARegion *ar;
        SpaceLogic *slogic;
        
@@ -120,14 +121,11 @@ static SpaceLink *logic_new(const bContext *UNUSED(C))
        ar->regiontype= RGN_TYPE_WINDOW;
 
        ar->v2d.tot.xmin =  0.0f;
-       ar->v2d.tot.ymin =  0.0f;
-       ar->v2d.tot.xmax = 1280;
-       ar->v2d.tot.ymax = 240.0f;
+       ar->v2d.tot.ymax =  0.0f;
+       ar->v2d.tot.xmax = 1150.0f;
+       ar->v2d.tot.ymin = ( 1150.0f/(float)sa->winx ) * (float)-sa->winy;
        
-       ar->v2d.cur.xmin =  0.0f;
-       ar->v2d.cur.ymin =  0.0f;
-       ar->v2d.cur.xmax = 1280.0f;
-       ar->v2d.cur.ymax = 240.0f;
+       ar->v2d.cur = ar->v2d.tot;
        
        ar->v2d.min[0] = 1.0f;
        ar->v2d.min[1] = 1.0f;
@@ -136,12 +134,13 @@ static SpaceLink *logic_new(const bContext *UNUSED(C))
        ar->v2d.max[1] = 32000.0f;
        
        ar->v2d.minzoom = 0.5f;
-       ar->v2d.maxzoom = 1.21f;
+       ar->v2d.maxzoom = 1.5f;
        
        ar->v2d.scroll = (V2D_SCROLL_RIGHT | V2D_SCROLL_BOTTOM);
-       ar->v2d.keepzoom = V2D_LIMITZOOM | V2D_KEEPASPECT;
-       ar->v2d.keeptot = 0;
-       
+       ar->v2d.keepzoom = V2D_KEEPZOOM | V2D_LIMITZOOM | V2D_KEEPASPECT;
+       ar->v2d.keeptot = V2D_KEEPTOT_BOUNDS;
+       ar->v2d.align = V2D_ALIGN_NO_POS_Y | V2D_ALIGN_NO_NEG_X;
+       ar->v2d.keepofs = V2D_KEEPOFS_Y;
        
        return (SpaceLink *)slogic;
 }
@@ -183,6 +182,9 @@ static void logic_keymap(struct wmKeyConfig *keyconf)
        WM_keymap_add_item(keymap, "LOGIC_OT_properties", NKEY, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "LOGIC_OT_links_cut", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
        WM_keymap_add_menu(keymap, "LOGIC_MT_logicbricks_add", AKEY, KM_PRESS, KM_SHIFT, 0);
+       
+       WM_keymap_add_item(keymap, "VIEW2D_OT_reset", HOMEKEY, KM_PRESS, 0, 0);
+
 }
 
 static void logic_refresh(const bContext *UNUSED(C), ScrArea *UNUSED(sa))
@@ -234,7 +236,7 @@ static void logic_main_area_init(wmWindowManager *wm, ARegion *ar)
        wmKeyMap *keymap;
        
        UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
-
+       
        /* own keymaps */
        keymap = WM_keymap_find(wm->defaultconf, "Logic Editor", SPACE_LOGIC, 0);
        WM_event_add_keymap_handler(&ar->handlers, keymap);
@@ -259,7 +261,7 @@ static void logic_main_area_draw(const bContext *C, ARegion *ar)
        UI_view2d_view_restore(C);
        
        /* scrollers */
-       scrollers= UI_view2d_scrollers_calc(C, v2d, 10, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
+       scrollers= UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
        UI_view2d_scrollers_draw(C, v2d, scrollers);
        UI_view2d_scrollers_free(scrollers);