Fix for new UI system and vertexpaint/faceselect/weightpaint/texturepaint
authorTon Roosendaal <ton@blender.org>
Sun, 3 Oct 2004 20:02:22 +0000 (20:02 +0000)
committerTon Roosendaal <ton@blender.org>
Sun, 3 Oct 2004 20:02:22 +0000 (20:02 +0000)
If backbuffer is in use for selection codes, the system switches back to
frontbuffer drawing temporally. Is easier solution now.

Next commit; fix for new 'zbuffer clipped selection', which also doesnt
work after using a pulldown or popup menu.

source/blender/include/BIF_interface.h
source/blender/include/interface.h
source/blender/src/drawview.c
source/blender/src/interface.c
source/blender/src/interface_draw.c

index 9f8afd76ea6da265e36e3bd74191e61a85ba0850..01fc74430e1b5d7084d212cd40454a16a504af27 100644 (file)
@@ -75,6 +75,7 @@ struct ScrArea;
 #define UI_BLOCK_NUMSELECT     16
 #define UI_BLOCK_ENTER_OK      32
 #define UI_BLOCK_NOSHADOW      64
+#define UI_BLOCK_FRONTBUFFER   128
 
        /* block->flag bits 12-15 are identical to but->flag bits */
 
index 281e2e4be10ad1a57ce67a7581e751452bff8951..baa5e0d74188dea1d14e20107c93dfeb5931cbef 100644 (file)
@@ -41,8 +41,6 @@
 #define UI_MAX_NAME_STR        64
 #define UI_ARRAY       29
 
-
-
 /* uiBut->flag */
 #define UI_SELECT              1
 #define UI_MOUSE_OVER  2
 /* warn: rest of uiBut->flag in BIF_interface.c */
 
 
-/* block->frontbuf: (only internal here). this signals something was drawn, for flush */
-#define UI_HAS_DRAWN   1
-
-
 /* internal panel drawing defines */
 #define PNL_GRID       4
 #define PNL_DIST       8
@@ -186,7 +180,8 @@ struct uiBlock {
        int afterval, flag;
        void *curfont;
        
-       short autofill, win, winq, direction, dt, frontbuf, auto_open, pad;  //frontbuf see below
+       short autofill, win, winq, direction, dt;
+       short needflush, auto_open, in_use, pad;  //flush see below
        void *overdraw;
        
        float xofs, yofs;       // offset to parent button
index 47d158476dd812cf0c03d1c028691480f9be47d4..1c1e83932a1d1da2c686199a5e98baf7b1c8f4b0 100644 (file)
@@ -1476,7 +1476,10 @@ static void view3d_panel_object(short cntrl)     // VIEW3D_HANDLER_OBJECT
 
        if(uiNewPanel(curarea, block, "Transform Properties", "View3d", 10, 230, 318, 204)==0) return;
        
-       if((G.f & (G_VERTEXPAINT|G_TEXTUREPAINT))==0) {
+       if(G.f & (G_VERTEXPAINT|G_FACESELECT|G_TEXTUREPAINT|G_WEIGHTPAINT)) {
+               uiBlockSetFlag(block, UI_BLOCK_FRONTBUFFER);    // force old style frontbuffer draw
+       }
+       else {
                uiDefBut(block, TEX, B_IDNAME, "OB: ",  10,180,140,20, ob->id.name+2, 0.0, 19.0, 0, 0, "");
                uiDefIDPoinBut(block, test_obpoin_but, B_OBJECTPANELPARENT, "Par:", 160, 180, 140, 20, &ob->parent, "Parent Object"); 
        }
@@ -1532,6 +1535,10 @@ static void view3d_panel_background(short cntrl) // VIEW3D_HANDLER_BACKGROUND
        uiSetPanelHandler(VIEW3D_HANDLER_BACKGROUND);  // for close and esc
        if(uiNewPanel(curarea, block, "Background Image", "View3d", 340, 10, 318, 204)==0) return;
 
+       if(G.f & (G_VERTEXPAINT|G_FACESELECT|G_TEXTUREPAINT|G_WEIGHTPAINT)) {
+               uiBlockSetFlag(block, UI_BLOCK_FRONTBUFFER);    // force old style frontbuffer draw
+       }
+       
        if(vd->flag & V3D_DISPBGPIC) {
                if(vd->bgpic==0) {
                        vd->bgpic= MEM_callocN(sizeof(BGpic), "bgpic");
@@ -1623,6 +1630,10 @@ static void view3d_panel_properties(short cntrl) // VIEW3D_HANDLER_SETTINGS
        uiSetPanelHandler(VIEW3D_HANDLER_PROPERTIES);  // for close and esc
        if(uiNewPanel(curarea, block, "View Properties", "View3d", 340, 10, 318, 204)==0) return;
 
+       if(G.f & (G_VERTEXPAINT|G_FACESELECT|G_TEXTUREPAINT|G_WEIGHTPAINT)) {
+               uiBlockSetFlag(block, UI_BLOCK_FRONTBUFFER);    // force old style frontbuffer draw
+       }
+
        uiDefBut(block, LABEL, 1, "Grid:",                                      10, 180, 150, 19, NULL, 0.0, 0.0, 0, 0, "");
        uiDefButF(block, NUM, REDRAWVIEW3D, "Spacing:",         10, 160, 140, 19, &vd->grid, 0.001, 100.0, 10, 0, "Set the distance between grid lines");
        uiDefButS(block, NUM, REDRAWVIEW3D, "Lines:",           10, 136, 140, 19, &vd->gridlines, 0.0, 100.0, 100, 0, "Set the number of grid lines");
index f96ccd6f6cd9fb2caae1f63e7bde496ecaba33ef..91d4334a81dd160efec7889e6d60596e0e688e6d 100644 (file)
@@ -316,8 +316,16 @@ void ui_block_flush_back(uiBlock *block)
        int minx, miny, sizex, sizey;
        
        /* note; this routine also has to work for block loop */
-       if(block->frontbuf==0) return;
+       if(block->needflush==0) return;
 
+       /* exception, when we cannot use backbuffer for draw... */
+       if(block->flag & UI_BLOCK_FRONTBUFFER) {
+               glFlush();
+               glDrawBuffer(GL_BACK);
+               block->needflush= 0;
+               return;
+       }
+       
        /* copy pixels works on window coords, so we move to window space */
 
        ui_graphics_to_window(block->win, &block->flush.xmin, &block->flush.ymin);
@@ -346,7 +354,7 @@ void ui_block_flush_back(uiBlock *block)
                markdirty_win_back(block->win);
        }
        
-       block->frontbuf= 0; 
+       block->needflush= 0; 
 }
 
 /* merge info for live updates in frontbuf */
@@ -354,13 +362,17 @@ void ui_block_set_flush(uiBlock *block, uiBut *but)
 {
        /* clear signal */
        if(but==NULL) {
-               block->frontbuf= 0; 
+               block->needflush= 0; 
 
                block->flush.xmin= 0.0;
                block->flush.xmax= 0.0;
        }
        else {
-               if(block->frontbuf==0) {
+               /* exception, when we cannot use backbuffer for draw... */
+               if(block->flag & UI_BLOCK_FRONTBUFFER) {
+                       glDrawBuffer(GL_FRONT);
+               }
+               else if(block->needflush==0) {
                        /* first rect */
                        block->flush.xmin= but->x1;
                        block->flush.xmax= but->x2;
@@ -374,7 +386,8 @@ void ui_block_set_flush(uiBlock *block, uiBut *but)
                        if(block->flush.ymin > but->y1) block->flush.ymin= but->y1;
                        if(block->flush.ymax < but->y2) block->flush.ymax= but->y2;
                }
-               block->frontbuf= UI_HAS_DRAWN;
+               
+               block->needflush= 1;
                
        }
 }
@@ -3421,20 +3434,23 @@ int uiDoBlocks(ListBase *lb, int event)
                                if( block->flag & UI_BLOCK_LOOP) {
                                        block->overdraw= ui_begin_overdraw((int)block->minx-1, (int)block->miny-6, (int)block->maxx+6, (int)block->maxy+1);
                                }
+                               block->in_use= 1;       // is always a menu
                                uiDrawBlock(block);
                                block->flag &= ~UI_BLOCK_REDRAW;
                        }
-
+                       
+                       block->in_use= 1; // bit awkward, but now we can detect if frontbuf flush should be set
                        retval= ui_do_block(block, &uevent);
+                       block->in_use= 0;
                        if(retval==UI_EXIT_LOOP) break;
                        
                        /* now a new block could be created for menus, this is 
                           inserted in the beginning of a list */
                        
                        /* is there a flush cached? */
-                       if(block->frontbuf == UI_HAS_DRAWN) {
+                       if(block->needflush) {
                                ui_flush_overdraw(block->overdraw);
-                               block->frontbuf= 0;
+                               block->needflush= 0;
                        }
                        
                        /* to make sure the matrix of the panel works for menus too */
@@ -3460,17 +3476,19 @@ int uiDoBlocks(ListBase *lb, int event)
                                uiDrawBlock(block);
                                block->flag &= ~UI_BLOCK_REDRAW;
                                ui_flush_overdraw(block->overdraw);
-                               block->frontbuf= 0;
+                               block->needflush= 0;
                        }
                        
                        uevent.event= extern_qread(&uevent.val);
                        
                        if(uevent.event) {
+                               block->in_use= 1; // bit awkward, but now we can detect if frontbuf flush should be set
                                retval= ui_do_block(block, &uevent);
+                               block->in_use= 0;
                        
-                               if(block->frontbuf == UI_HAS_DRAWN) { // flush now, maybe new menu was opened
+                               if(block->needflush) { // flush now, maybe new menu was opened
                                        ui_flush_overdraw(block->overdraw);
-                                       block->frontbuf= 0;
+                                       block->needflush= 0;
                                }
 
                                if(retval & UI_RETURN) {
index ea16229074cbdb3ec483a863f034082c1228b706..3ef7d80273043696ecc415a1ac0e4dd86f1c8e71 100644 (file)
@@ -1715,10 +1715,10 @@ void ui_draw_but(uiBut *but)
        double value;
        float x1, x2, y1, y2, fac;
        
-       if(but==0) return;
+       if(but==NULL) return;
 
        /* signal for flush buttons and menus */
-       ui_block_set_flush(but->block, but);
+       if(but->block->in_use) ui_block_set_flush(but->block, but);
                
        switch (but->type) {