2.5
authorTon Roosendaal <ton@blender.org>
Sun, 21 Dec 2008 11:05:43 +0000 (11:05 +0000)
committerTon Roosendaal <ton@blender.org>
Sun, 21 Dec 2008 11:05:43 +0000 (11:05 +0000)
- View3D: added ALT+B clipping operator. Note this needs a call to
  the new function view3d_operator_needs_opengl(C) to ensure you
  can use opengl functions. Event handling by default doesn't set
  opengl per subwindow, it's also forbidden to draw then!

  We might consider to tag operators that need opengl...

- Forgot to include creator.c fix for loading builtin vector font

source/blender/editors/include/BIF_glutil.h
source/blender/editors/screen/glutil.c
source/blender/editors/space_view3d/view3d_header.c
source/blender/editors/space_view3d/view3d_intern.h
source/blender/editors/space_view3d/view3d_ops.c
source/blender/editors/space_view3d/view3d_select.c
source/blender/editors/space_view3d/view3d_view.c
source/blender/windowmanager/intern/wm_operators.c
source/creator/creator.c

index 6364b8bf1af63113b257a62304c2113f5b7b9c3f..0d34c122392c6718fb5daaef343111c85ef13d29 100644 (file)
@@ -44,15 +44,6 @@ void sdrawXORline4(int nr, int x0, int y0, int x1, int y1);
 void fdrawXORellipse(float xofs, float yofs, float hw, float hh);
 void fdrawXORcirc(float xofs, float yofs, float rad);
 
-       /**
-        * Draw an XOR'd line in the front buffer between
-        * the given points. 
-        *
-        * @attention This function also handles flushing the GL
-        * pipeline, which means it is inappropriate for drawing
-        * a large number of lines at once.
-        */
-void glutil_draw_front_xor_line(int x0, int y0, int x1, int y1);
 
        /**
         * Draw a lined (non-looping) arc with the given
index d500c9f37c190fd27b7fc9ec88fe349bfa39ccc7..bead9a6399f9127f6c2fb533c5fa5ed196c7d76f 100644 (file)
@@ -199,17 +199,6 @@ void sdrawXORline(int x0, int y0, int x1, int y1)
        set_inverted_drawing(0);
 }
 
-void glutil_draw_front_xor_line(int x0, int y0, int x1, int y1)
-{
-       glReadBuffer(GL_FRONT);
-       glDrawBuffer(GL_FRONT);
-       sdrawXORline(x0, y0, x1, y1);
-       glFlush();
-       glReadBuffer(GL_BACK);
-       glDrawBuffer(GL_BACK);
-       
-}
-
 void sdrawXORline4(int nr, int x0, int y0, int x1, int y1)
 {
        static short old[4][2][2];
index 9838976a10cada855dcb51bf186491fa5ae0867f..674291e7e5d3a3f4ca85e3d48be32d9952a101d7 100644 (file)
@@ -117,7 +117,6 @@ void editmesh_align_view_to_selected(void *x, int y) {}
 void play_anim(int x) {}
 void add_blockhandler(void *x, int y, int z) {}
 void toggle_blockhandler(void *x, int y, int z) {}
-void view3d_edit_clipping(void *x);
 void view3d_border_zoom(void);
 void selectlinks(void) {}
 void countall(void) {}
@@ -563,7 +562,7 @@ static void do_view3d_viewmenu(bContext *C, void *arg, int event)
                add_blockhandler(sa, VIEW3D_HANDLER_PROPERTIES, UI_PNL_UNSTOW);
                break;
        case 17: /* Set Clipping Border */
-               view3d_edit_clipping(v3d);
+               WM_operator_call(C, "ED_VIEW3D_OT_clipping", WM_OP_REGION_WIN, NULL);
                break;
        case 18: /* render preview */
                toggle_blockhandler(sa, VIEW3D_HANDLER_PREVIEW, 0);
index ec7138a190b5c5495cce17d743916f5a6dad93bc..f6b3bd0ced0b637710c118435cd2f465a706f5e9 100644 (file)
@@ -73,8 +73,6 @@ void ED_VIEW3D_OT_viewmove(struct wmOperatorType *ot);
 void ED_VIEW3D_OT_viewrotate(struct wmOperatorType *ot);
 void ED_VIEW3D_OT_viewhome(struct wmOperatorType *ot);
 void ED_VIEW3D_OT_viewcenter(struct wmOperatorType *ot);
-void ED_VIEW3D_OT_select(struct wmOperatorType *ot);
-void ED_VIEW3D_OT_borderselect(struct wmOperatorType *ot);
 
 /* drawobject.c */
 void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag);
@@ -108,7 +106,13 @@ void circf(float x, float y, float rad);
 void circ(float x, float y, float rad);
 void view3d_update_depths(ARegion *ar, View3D *v3d);
 
+/* view3d_select.c */
+void ED_VIEW3D_OT_clipping(struct wmOperatorType *ot);
+void ED_VIEW3D_OT_select(struct wmOperatorType *ot);
+void ED_VIEW3D_OT_borderselect(struct wmOperatorType *ot);
+
 /* view3d_view.c */
+void view3d_operator_needs_opengl(const struct bContext *C);
 float *give_cursor(Scene *scene, View3D *v3d);
 void viewline(ARegion *ar, View3D *v3d, short mval[2], float ray_start[3], float ray_end[3]);
 void viewray(ARegion *ar, View3D *v3d, short mval[2], float ray_start[3], float ray_normal[3]);
index bd818f6c747c9c9a5167f16fe3109d03d6592156..92564d8b20b762bbc9b28d28b4fd6ade0669ec22 100644 (file)
@@ -68,6 +68,8 @@ void view3d_operatortypes(void)
        WM_operatortype_append(ED_VIEW3D_OT_viewcenter);
        WM_operatortype_append(ED_VIEW3D_OT_select);
        WM_operatortype_append(ED_VIEW3D_OT_borderselect);
+       WM_operatortype_append(ED_VIEW3D_OT_clipping);
+       
 }
 
 void view3d_keymap(wmWindowManager *wm)
@@ -89,6 +91,7 @@ void view3d_keymap(wmWindowManager *wm)
 
        WM_keymap_add_item(keymap, "ED_VIEW3D_OT_select", SELECTMOUSE, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "ED_VIEW3D_OT_borderselect", BKEY, KM_PRESS, 0, 0);
+       WM_keymap_add_item(keymap, "ED_VIEW3D_OT_clipping", BKEY, KM_PRESS, KM_ALT, 0);
 
 }
 
index 9d0616d4f54b27b13582af79f77c97d1aad17bbf..351dfad4cc5451694f1921294b80b528016936d6 100644 (file)
@@ -1673,14 +1673,12 @@ void ED_VIEW3D_OT_borderselect(wmOperatorType *ot)
        
        ot->poll= ED_operator_areaactive;
        
-       
        /* rna */
        RNA_def_property(ot->srna, "event_type", PROP_INT, PROP_NONE);
        RNA_def_property(ot->srna, "xmin", PROP_INT, PROP_NONE);
        RNA_def_property(ot->srna, "xmax", PROP_INT, PROP_NONE);
        RNA_def_property(ot->srna, "ymin", PROP_INT, PROP_NONE);
        RNA_def_property(ot->srna, "ymax", PROP_INT, PROP_NONE);
-       
 }
 
 
@@ -2019,74 +2017,106 @@ void view3d_border_zoom(Scene *scene, ARegion *ar, View3D *v3d)
        smooth_view(v3d, new_ofs, NULL, &new_dist, NULL);
 }
 
+/* ********************* set clipping operator ****************** */
 
-void view3d_edit_clipping(ARegion *ar, View3D *v3d)
+static int view3d_clipping_exec(bContext *C, wmOperator *op)
 {
+       ScrArea *sa= CTX_wm_area(C);
+       View3D *v3d= sa->spacedata.first;
+       rcti rect;
+       double mvmatrix[16];
+       double projmatrix[16];
+       double xs, ys, p[3];
+       GLint viewport[4];
+       short val;
        
-       if(v3d->flag & V3D_CLIPPING) {
-               v3d->flag &= ~V3D_CLIPPING;
-               ED_region_tag_redraw(ar);
-               if(v3d->clipbb) MEM_freeN(v3d->clipbb);
-               v3d->clipbb= NULL;
-       }
-       else {
-               rcti rect;
-               double mvmatrix[16];
-               double projmatrix[16];
-               double xs, ys, p[3];
-               GLint viewport[4];
-               short val;
-               
-               /* get border in window coords */
-               setlinestyle(2);
-               val= 0; // XX get_border(&rect, 3);
-               setlinestyle(0);
-               if(val==0) return;
-               
-               v3d->flag |= V3D_CLIPPING;
-               v3d->clipbb= MEM_callocN(sizeof(BoundBox), "clipbb");
+       rect.xmin= RNA_int_get(op->ptr, "xmin");
+       rect.ymin= RNA_int_get(op->ptr, "ymin");
+       rect.xmax= RNA_int_get(op->ptr, "xmax");
+       rect.ymax= RNA_int_get(op->ptr, "ymax");
+       
+       v3d->flag |= V3D_CLIPPING;
+       v3d->clipbb= MEM_callocN(sizeof(BoundBox), "clipbb");
+       
+       /* note; otherwise opengl won't work */
+       view3d_operator_needs_opengl(C);
+       
+       /* Get the matrices needed for gluUnProject */
+       glGetIntegerv(GL_VIEWPORT, viewport);
+       glGetDoublev(GL_MODELVIEW_MATRIX, mvmatrix);
+       glGetDoublev(GL_PROJECTION_MATRIX, projmatrix);
+
+       /* near zero floating point values can give issues with gluUnProject
+          in side view on some implementations */
+       if(fabs(mvmatrix[0]) < 1e-6) mvmatrix[0]= 0.0;
+       if(fabs(mvmatrix[5]) < 1e-6) mvmatrix[5]= 0.0;
+       
+       /* Set up viewport so that gluUnProject will give correct values */
+       viewport[0] = 0;
+       viewport[1] = 0;
+       
+       /* four clipping planes and bounding volume */
+       /* first do the bounding volume */
+       for(val=0; val<4; val++) {
                
-               /* convert border to 3d coordinates */
+               xs= (val==0||val==3)?rect.xmin:rect.xmax;
+               ys= (val==0||val==1)?rect.ymin:rect.ymax;
                
-               /* Get the matrices needed for gluUnProject */
-               glGetIntegerv(GL_VIEWPORT, viewport);
-               glGetDoublev(GL_MODELVIEW_MATRIX, mvmatrix);
-               glGetDoublev(GL_PROJECTION_MATRIX, projmatrix);
-
-               /* near zero floating point values can give issues with gluUnProject
-                  in side view on some implementations */
-               if(fabs(mvmatrix[0]) < 1e-6) mvmatrix[0]= 0.0;
-               if(fabs(mvmatrix[5]) < 1e-6) mvmatrix[5]= 0.0;
+               gluUnProject(xs, ys, 0.0, mvmatrix, projmatrix, viewport, &p[0], &p[1], &p[2]);
+               VECCOPY(v3d->clipbb->vec[val], p);
                
-               /* Set up viewport so that gluUnProject will give correct values */
-               viewport[0] = 0;
-               viewport[1] = 0;
+               gluUnProject(xs, ys, 1.0, mvmatrix, projmatrix, viewport, &p[0], &p[1], &p[2]);
+               VECCOPY(v3d->clipbb->vec[4+val], p);
+       }
+       
+       /* then plane equations */
+       for(val=0; val<4; val++) {
                
-               /* four clipping planes and bounding volume */
-               /* first do the bounding volume */
-               for(val=0; val<4; val++) {
-                       
-                       xs= (val==0||val==3)?rect.xmin:rect.xmax;
-                       ys= (val==0||val==1)?rect.ymin:rect.ymax;
-                       
-                       gluUnProject(xs, ys, 0.0, mvmatrix, projmatrix, viewport, &p[0], &p[1], &p[2]);
-                       VECCOPY(v3d->clipbb->vec[val], p);
-                       
-                       gluUnProject(xs, ys, 1.0, mvmatrix, projmatrix, viewport, &p[0], &p[1], &p[2]);
-                       VECCOPY(v3d->clipbb->vec[4+val], p);
-               }
+               CalcNormFloat(v3d->clipbb->vec[val], v3d->clipbb->vec[val==3?0:val+1], v3d->clipbb->vec[val+4],
+                                         v3d->clip[val]); 
                
-               /* then plane equations */
-               for(val=0; val<4; val++) {
-                       
-                       CalcNormFloat(v3d->clipbb->vec[val], v3d->clipbb->vec[val==3?0:val+1], v3d->clipbb->vec[val+4],
-                                                 v3d->clip[val]); 
-                       
-                       v3d->clip[val][3]= - v3d->clip[val][0]*v3d->clipbb->vec[val][0] 
-                                                          - v3d->clip[val][1]*v3d->clipbb->vec[val][1] 
-                                                          - v3d->clip[val][2]*v3d->clipbb->vec[val][2];
-               }
+               v3d->clip[val][3]= - v3d->clip[val][0]*v3d->clipbb->vec[val][0] 
+                                                  - v3d->clip[val][1]*v3d->clipbb->vec[val][1] 
+                                                  - v3d->clip[val][2]*v3d->clipbb->vec[val][2];
        }
+       return OPERATOR_FINISHED;
 }
 
+static int view3d_clipping_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+       ScrArea *sa= CTX_wm_area(C);
+       View3D *v3d= sa->spacedata.first;
+       
+       if(v3d->flag & V3D_CLIPPING) {
+               v3d->flag &= ~V3D_CLIPPING;
+               ED_area_tag_redraw(sa);
+               if(v3d->clipbb) MEM_freeN(v3d->clipbb);
+               v3d->clipbb= NULL;
+               return OPERATOR_FINISHED;
+       }
+       else {
+               return WM_border_select_invoke(C, op, event);
+       }
+}
 
+/* toggles */
+void ED_VIEW3D_OT_clipping(wmOperatorType *ot)
+{
+       
+       /* identifiers */
+       ot->name= "Border Select";
+       ot->idname= "ED_VIEW3D_OT_clipping";
+       
+       /* api callbacks */
+       ot->invoke= view3d_clipping_invoke;
+       ot->exec= view3d_clipping_exec;
+       ot->modal= WM_border_select_modal;
+       
+       ot->poll= ED_operator_areaactive;
+       
+       /* rna */
+       RNA_def_property(ot->srna, "xmin", PROP_INT, PROP_NONE);
+       RNA_def_property(ot->srna, "xmax", PROP_INT, PROP_NONE);
+       RNA_def_property(ot->srna, "ymin", PROP_INT, PROP_NONE);
+       RNA_def_property(ot->srna, "ymax", PROP_INT, PROP_NONE);
+}
index 5f1957b84b6ed926f0081f24bc04c714c72d0f76..7c2f5a7d5ab9efb745a9ac1bf5d0719b7ad08468 100644 (file)
@@ -51,6 +51,7 @@
 
 #include "BKE_anim.h"
 #include "BKE_action.h"
+#include "BKE_context.h"
 #include "BKE_object.h"
 #include "BKE_global.h"
 #include "BKE_main.h"
 
 #define BL_NEAR_CLIP 0.001
 
+/* use this call when executing an operator,
+   event system doesn't set for each event the
+   opengl drawing context */
+void view3d_operator_needs_opengl(const bContext *C)
+{
+       ARegion *ar= CTX_wm_region(C);
+
+       /* for debugging purpose, context should always be OK */
+       if(ar->regiontype!=RGN_TYPE_WINDOW)
+               printf("view3d_operator_needs_opengl error, wrong region\n");
+       else {
+               ScrArea *sa= CTX_wm_area(C);
+               View3D *v3d= sa->spacedata.first;
+               
+               wmSubWindowSet(CTX_wm_window(C), ar->swinid);
+               glMatrixMode(GL_PROJECTION);
+               wmLoadMatrix(v3d->winmat);
+               glMatrixMode(GL_MODELVIEW);
+               wmLoadMatrix(v3d->viewmat);
+       }
+}
+
 float *give_cursor(Scene *scene, View3D *v3d)
 {
        if(v3d && v3d->localview) return v3d->cursor;
index 11f6f8fa93ab9ce2ca2af179ea88af8e76ddf03e..3158ea0759cb89e792027c9002cf78097cb54ab1 100644 (file)
@@ -264,8 +264,8 @@ static void border_select_apply(bContext *C, wmOperator *op, int event_type)
        RNA_int_set(op->ptr, "ymin", rect->ymin);
        RNA_int_set(op->ptr, "xmax", rect->xmax);
        RNA_int_set(op->ptr, "ymax", rect->ymax);
-       
-       RNA_int_set(op->ptr, "event_type", event_type);
+       if( RNA_property_is_set(op->ptr, "event_type"))
+               RNA_int_set(op->ptr, "event_type", event_type);
        
        op->type->exec(C, op);
 }
index 5c10b0c346cf44fec7ffc3f3f86a2452d02fa6e4..0d0f4f7bb01875fb6572c18eb020ae3d6fc113cb 100644 (file)
@@ -72,7 +72,7 @@
 
 //XXX #include "playanim_ext.h"
 #include "wm_event_types.h"
-//XXX #include "nla.h"
+#include "ED_datafiles.h"
 //XXX #include "datatoc.h"
 
 #include "WM_api.h"
@@ -403,7 +403,7 @@ int main(int argc, char **argv)
        if(G.background) signal(SIGINT, blender_esc);   /* ctrl c out bg render */
        
        /* background render uses this font too */
-       //XXX BKE_font_register_builtin(datatoc_Bfont, datatoc_Bfont_size);
+       BKE_font_register_builtin(datatoc_Bfont, datatoc_Bfont_size);
        
        init_def_material();