Revision: 20813
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20813
Author:   ton
Date:     2009-06-11 19:21:27 +0200 (Thu, 11 Jun 2009)

Log Message:
-----------
2.5

Added search-browse to the Python ID template. Also added icon/button
for 'Add new'. (Note, we need icon for it).

Also fixed bug in search menu closing too quick on mouse-release, when
mouse was close to bottom of menu button.
And removed annoying warning if ID pointer was zero.

Modified Paths:
--------------
    
branches/blender2.5/blender/source/blender/editors/interface/interface_handlers.c
    
branches/blender2.5/blender/source/blender/editors/interface/interface_intern.h
    
branches/blender2.5/blender/source/blender/editors/interface/interface_regions.c
    
branches/blender2.5/blender/source/blender/editors/interface/interface_templates.c
    
branches/blender2.5/blender/source/blender/editors/interface/interface_utils.c
    branches/blender2.5/blender/source/blender/editors/preview/previewrender.c

Modified: 
branches/blender2.5/blender/source/blender/editors/interface/interface_handlers.c
===================================================================
--- 
branches/blender2.5/blender/source/blender/editors/interface/interface_handlers.c
   2009-06-11 16:59:59 UTC (rev 20812)
+++ 
branches/blender2.5/blender/source/blender/editors/interface/interface_handlers.c
   2009-06-11 17:21:27 UTC (rev 20813)
@@ -1263,7 +1263,7 @@
                        
                        /* exit on LMB only on RELEASE for searchbox, to mimic 
other popups, and allow multiple menu levels */
                        if(data->searchbox)
-                               inbox= BLI_in_rcti(&data->searchbox->winrct, 
event->x, event->y);
+                               inbox= ui_searchbox_inside(data->searchbox, 
event->x, event->y);
 
                        if(event->val==KM_PRESS) {
                                mx= event->x;
@@ -1287,6 +1287,7 @@
                                }
                        }
                        else if(inbox) {
+                               printf("release inside \n");
                                button_activate_state(C, but, 
BUTTON_STATE_EXIT);
                                retval= WM_UI_HANDLER_BREAK;
                        }

Modified: 
branches/blender2.5/blender/source/blender/editors/interface/interface_intern.h
===================================================================
--- 
branches/blender2.5/blender/source/blender/editors/interface/interface_intern.h 
    2009-06-11 16:59:59 UTC (rev 20812)
+++ 
branches/blender2.5/blender/source/blender/editors/interface/interface_intern.h 
    2009-06-11 17:21:27 UTC (rev 20813)
@@ -357,6 +357,7 @@
 
 /* searchbox for string button */
 ARegion *ui_searchbox_create(struct bContext *C, struct ARegion *butregion, 
uiBut *but);
+int ui_searchbox_inside(struct ARegion *ar, int x, int y);
 void ui_searchbox_update(struct bContext *C, struct ARegion *ar, uiBut *but, 
int reset);
 void ui_searchbox_event(struct bContext *C, struct ARegion *ar, uiBut *but, 
struct wmEvent *event);
 void ui_searchbox_apply(uiBut *but, struct ARegion *ar);

Modified: 
branches/blender2.5/blender/source/blender/editors/interface/interface_regions.c
===================================================================
--- 
branches/blender2.5/blender/source/blender/editors/interface/interface_regions.c
    2009-06-11 16:59:59 UTC (rev 20812)
+++ 
branches/blender2.5/blender/source/blender/editors/interface/interface_regions.c
    2009-06-11 17:21:27 UTC (rev 20813)
@@ -520,6 +520,14 @@
        
 }
 
+/* x and y in screencoords */
+int ui_searchbox_inside(ARegion *ar, int x, int y)
+{
+       uiSearchboxData *data= ar->regiondata;
+       
+       return(BLI_in_rcti(&data->bbox, x-ar->winrct.xmin, y-ar->winrct.ymin));
+}
+
 /* string validated to be of correct length (but->hardmax) */
 void ui_searchbox_apply(uiBut *but, ARegion *ar)
 {
@@ -699,72 +707,81 @@
        
        /* compute position */
        
-       x1f= but->x1 - 5;       /* align text with button */
-       x2f= but->x2 + 5;       /* symmetrical */
        if(but->block->flag & UI_BLOCK_LOOP) {
+               /* this case is search menu inside other menu */
+               /* we copy region size */
+
+               ar->winrct= butregion->winrct;
+               
+               /* widget rect, in region coords */
+               data->bbox.xmin= MENU_SHADOW_SIDE;
+               data->bbox.xmax= (ar->winrct.xmax-ar->winrct.xmin) - 
MENU_SHADOW_SIDE;
+               data->bbox.ymin= MENU_SHADOW_BOTTOM;
+               data->bbox.ymax= (ar->winrct.ymax-ar->winrct.ymin) - 
MENU_SHADOW_BOTTOM;
+               
                /* check if button is lower half */
                if( but->y2 < (but->block->minx+but->block->maxx)/2 ) {
-                       y1f= but->y2;
-                       y2f= y1f + uiSearchBoxhHeight();
+                       data->bbox.ymin += (but->y2-but->y1);
                }
                else {
-                       y2f= but->y1;
-                       y1f= y2f - uiSearchBoxhHeight();
+                       data->bbox.ymax -= (but->y2-but->y1);
                }
        }
        else {
+               x1f= but->x1 - 5;       /* align text with button */
+               x2f= but->x2 + 5;       /* symmetrical */
                y2f= but->y1;
                y1f= y2f - uiSearchBoxhHeight();
-       }
        
-       /* minimal width */
-       if(x2f - x1f < 150) x2f= x1f+150; // XXX arbitrary
-       
-       /* copy to int, gets projected if possible too */
-       x1= x1f; y1= y1f; x2= x2f; y2= y2f; 
-       
-       if(butregion) {
-               if(butregion->v2d.cur.xmin != butregion->v2d.cur.xmax) {
-                       UI_view2d_to_region_no_clip(&butregion->v2d, x1f, y1f, 
&x1, &y1);
-                       UI_view2d_to_region_no_clip(&butregion->v2d, x2f, y2f, 
&x2, &y2);
+               /* minimal width */
+               if(x2f - x1f < 150) x2f= x1f+150; // XXX arbitrary
+               
+               /* copy to int, gets projected if possible too */
+               x1= x1f; y1= y1f; x2= x2f; y2= y2f; 
+               
+               if(butregion) {
+                       if(butregion->v2d.cur.xmin != butregion->v2d.cur.xmax) {
+                               UI_view2d_to_region_no_clip(&butregion->v2d, 
x1f, y1f, &x1, &y1);
+                               UI_view2d_to_region_no_clip(&butregion->v2d, 
x2f, y2f, &x2, &y2);
+                       }
+                       
+                       x1 += butregion->winrct.xmin;
+                       x2 += butregion->winrct.xmin;
+                       y1 += butregion->winrct.ymin;
+                       y2 += butregion->winrct.ymin;
                }
                
-               x1 += butregion->winrct.xmin;
-               x2 += butregion->winrct.xmin;
-               y1 += butregion->winrct.ymin;
-               y2 += butregion->winrct.ymin;
-       }
-       
-       wm_window_get_size(CTX_wm_window(C), &winx, &winy);
-       
-       if(x2 > winx) {
-               /* super size */
-               if(x2 > winx + x1) {
-                       x2= winx;
-                       x1= 0;
+               wm_window_get_size(CTX_wm_window(C), &winx, &winy);
+               
+               if(x2 > winx) {
+                       /* super size */
+                       if(x2 > winx + x1) {
+                               x2= winx;
+                               x1= 0;
+                       }
+                       else {
+                               x1 -= x2-winx;
+                               x2= winx;
+                       }
                }
-               else {
-                       x1 -= x2-winx;
-                       x2= winx;
+               if(y1 < 0) {
+                       y1 += 36;
+                       y2 += 36;
                }
+               
+               /* widget rect, in region coords */
+               data->bbox.xmin= MENU_SHADOW_SIDE;
+               data->bbox.xmax= x2-x1 + MENU_SHADOW_SIDE;
+               data->bbox.ymin= MENU_SHADOW_BOTTOM;
+               data->bbox.ymax= y2-y1 + MENU_SHADOW_BOTTOM;
+               
+               /* region bigger for shadow */
+               ar->winrct.xmin= x1 - MENU_SHADOW_SIDE;
+               ar->winrct.xmax= x2 + MENU_SHADOW_SIDE;
+               ar->winrct.ymin= y1 - MENU_SHADOW_BOTTOM;
+               ar->winrct.ymax= y2;
        }
-       if(y1 < 0) {
-               y1 += 36;
-               y2 += 36;
-       }
        
-       /* widget rect, in region coords */
-       data->bbox.xmin= MENU_SHADOW_SIDE;
-       data->bbox.xmax= x2-x1 + MENU_SHADOW_SIDE;
-       data->bbox.ymin= MENU_SHADOW_BOTTOM;
-       data->bbox.ymax= y2-y1 + MENU_SHADOW_BOTTOM;
-       
-       /* region bigger for shadow */
-       ar->winrct.xmin= x1 - MENU_SHADOW_SIDE;
-       ar->winrct.xmax= x2 + MENU_SHADOW_SIDE;
-       ar->winrct.ymin= y1 - MENU_SHADOW_BOTTOM;
-       ar->winrct.ymax= y2;
-       
        /* adds subwindow */
        ED_region_init(C, ar);
        

Modified: 
branches/blender2.5/blender/source/blender/editors/interface/interface_templates.c
===================================================================
--- 
branches/blender2.5/blender/source/blender/editors/interface/interface_templates.c
  2009-06-11 16:59:59 UTC (rev 20812)
+++ 
branches/blender2.5/blender/source/blender/editors/interface/interface_templates.c
  2009-06-11 17:21:27 UTC (rev 20813)
@@ -78,9 +78,8 @@
 {
        TemplateID *template= (TemplateID*)arg_litem;
        PointerRNA idptr= RNA_property_pointer_get(&template->ptr, 
template->prop);
-       ID *idtest, *id= idptr.data;
-       ListBase *lb= wich_libbase(CTX_data_main(C), template->idtype);
-       int nr, event= GET_INT_FROM_POINTER(arg_event);
+       ID *id= idptr.data;
+       int event= GET_INT_FROM_POINTER(arg_event);
        
        if(event == UI_ID_BROWSE && template->browse == 32767)
                event= UI_ID_ADD_NEW;
@@ -88,31 +87,9 @@
                event= UI_ID_OPEN;
 
        switch(event) {
-               case UI_ID_BROWSE: {
-                       if(template->browse== -2) {
-                               /* XXX implement or find a replacement
-                                * activate_databrowse((ID *)G.buts->lockpoin, 
GS(id->name), 0, B_MESHBROWSE, &template->browse, do_global_buttons); */
-                               return;
-                       }
-                       if(template->browse < 0)
-                               return;
-
-                       for(idtest=lb->first, nr=1; idtest; 
idtest=idtest->next, nr++) {
-                               if(nr==template->browse) {
-                                       if(id == idtest)
-                                               return;
-
-                                       id= idtest;
-                                       RNA_id_pointer_create(id, &idptr);
-                                       
RNA_property_pointer_set(&template->ptr, template->prop, idptr);
-                                       RNA_property_update(C, &template->ptr, 
template->prop);
-                                       /* XXX */
-
-                                       break;
-                               }
-                       }
+               case UI_ID_BROWSE:
+                       printf("warning, id browse shouldnt come here\n");
                        break;
-               }
                case UI_ID_DELETE:
                        memset(&idptr, 0, sizeof(idptr));
                        RNA_property_pointer_set(&template->ptr, 
template->prop, idptr);
@@ -148,10 +125,79 @@
        }
 }
 
+/* ID Search browse menu, assign  */
+static void id_search_call_cb(struct bContext *C, void *arg_litem, void *item)
+{
+       if(item) {
+               TemplateID *template= (TemplateID*)arg_litem;
+               PointerRNA idptr= RNA_property_pointer_get(&template->ptr, 
template->prop);
+
+               RNA_id_pointer_create(item, &idptr);
+               RNA_property_pointer_set(&template->ptr, template->prop, idptr);
+               RNA_property_update(C, &template->ptr, template->prop);
+       }       
+}
+
+/* ID Search browse menu, do the search */
+static void id_search_cb(const struct bContext *C, void *arg_litem, char *str, 
uiSearchItems *items)
+{
+       TemplateID *template= (TemplateID*)arg_litem;
+       ListBase *lb= wich_libbase(CTX_data_main(C), template->idtype);
+       ID *id;
+       
+       for(id= lb->first; id; id= id->next) {
+               
+               if(BLI_strcasestr(id->name+2, str)) {
+                       if(0==uiSearchItemAdd(items, id->name+2, id))
+                               break;
+               }
+       }
+}
+
+/* ID Search browse menu, open */
+static uiBlock *id_search_menu(bContext *C, ARegion *ar, void *arg_litem)
+{
+       static char search[256];
+       static TemplateID template;
+       wmEvent event;
+       wmWindow *win= CTX_wm_window(C);
+       uiBlock *block;
+       uiBut *but;
+       
+       /* clear initial search string, then all items show */
+       search[0]= 0;
+       /* arg_litem is malloced, can be freed by parent button */
+       template= *((TemplateID*)arg_litem);
+       
+       block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
+       uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_RET_1);
+       
+       /* fake button, it holds space for search items */
+       uiDefBut(block, LABEL, 0, "", 10, 15, 150, uiSearchBoxhHeight(), NULL, 
0, 0, 0, 0, NULL);
+       
+       but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, 256, 10, 0, 150, 
19, "");
+       uiButSetSearchFunc(but, id_search_cb, &template, id_search_call_cb);
+       
+       uiBoundsBlock(block, 6);
+       uiBlockSetDirection(block, UI_DOWN);    
+       uiEndBlock(C, block);
+       
+       event= *(win->eventstate);      /* XXX huh huh? make api call */
+       event.type= EVT_BUT_OPEN;
+       event.val= KM_PRESS;
+       event.customdata= but;
+       event.customdatafree= FALSE;
+       wm_event_add(win, &event);
+       
+       return block;
+}
+
+/* ****************** */
+
+
 static void template_header_ID(bContext *C, uiBlock *block, TemplateID 
*template, StructRNA *type)
 {
        uiBut *but;
-       TemplateID *duptemplate;
        PointerRNA idptr;
        ListBase *lb;
 
@@ -165,6 +211,7 @@
 
        uiBlockBeginAlign(block);
        if(template->flag & UI_ID_BROWSE) {
+               /*
                char *extrastr, *str;
                
                if((template->flag & UI_ID_ADD_NEW) && (template->flag & 
UI_ID_OPEN))
@@ -183,6 +230,8 @@
                uiButSetNFunc(but, template_id_cb, duptemplate, 
SET_INT_IN_POINTER(UI_ID_BROWSE));
        
                MEM_freeN(str);
+               */

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to