UI: Display alpha checkers in image info's color swatch.
authorCampbell Barton <ideasman42@gmail.com>
Tue, 24 Dec 2013 06:20:37 +0000 (17:20 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 24 Dec 2013 06:20:37 +0000 (17:20 +1100)
source/blender/editors/include/BIF_glutil.h
source/blender/editors/include/UI_interface.h
source/blender/editors/interface/interface_draw.c
source/blender/editors/interface/interface_intern.h
source/blender/editors/interface/interface_widgets.c
source/blender/editors/screen/glutil.c
source/blender/editors/space_image/image_draw.c

index dd1995a5428b5c3c086d19630a6b8d62dd6dbaed..48440d10ae3636b9e8f817285e5a40c5d859c4c7 100644 (file)
@@ -59,6 +59,7 @@ extern const unsigned char stipple_halftone[128];
 extern const unsigned char stipple_quarttone[128];
 extern const unsigned char stipple_diag_stripes_pos[128];
 extern const unsigned char stipple_diag_stripes_neg[128];
+extern const unsigned char stipple_checker_8px[128];
 
 /**
  * Draw a lined (non-looping) arc with the given
index cfd6d74dcefa97da20d2bed1051199b2ca87583f..735e7f35d61157f9eaf89e80db39ae1e9162fda7 100644 (file)
@@ -726,8 +726,8 @@ void UI_exit(void);
 #define UI_LAYOUT_MENU          2
 #define UI_LAYOUT_TOOLBAR       3
 
-#define UI_UNIT_X               U.widget_unit
-#define UI_UNIT_Y               U.widget_unit
+#define UI_UNIT_X               ((void)0, U.widget_unit)
+#define UI_UNIT_Y               ((void)0, U.widget_unit)
 
 #define UI_LAYOUT_ALIGN_EXPAND  0
 #define UI_LAYOUT_ALIGN_LEFT    1
@@ -748,6 +748,10 @@ void UI_exit(void);
 #define UI_LAYOUT_OP_SHOW_TITLE 1
 #define UI_LAYOUT_OP_SHOW_EMPTY 2
 
+/* used for transp checkers */
+#define UI_ALPHA_CHECKER_DARK 100
+#define UI_ALPHA_CHECKER_LIGHT 160
+
 /* flags to set which corners will become rounded:
  *
  * 1------2
index b6f93726bfc4a1ebbc79e652b3c485c33278f562..3301f1f1e5aa9dc3a95a64de6ce7191f21a297f4 100644 (file)
@@ -935,11 +935,11 @@ void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti
 
        /* first background, to show tranparency */
 
-       glColor4ub(UI_TRANSP_DARK, UI_TRANSP_DARK, UI_TRANSP_DARK, 255);
+       glColor4ub(UI_ALPHA_CHECKER_DARK, UI_ALPHA_CHECKER_DARK, UI_ALPHA_CHECKER_DARK, 255);
        glRectf(x1, y1, x1 + sizex, y1 + sizey);
        glEnable(GL_POLYGON_STIPPLE);
-       glColor4ub(UI_TRANSP_LIGHT, UI_TRANSP_LIGHT, UI_TRANSP_LIGHT, 255);
-       glPolygonStipple(checker_stipple_sml);
+       glColor4ub(UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT, 255);
+       glPolygonStipple(stipple_checker_8px);
        glRectf(x1, y1, x1 + sizex, y1 + sizey);
        glDisable(GL_POLYGON_STIPPLE);
 
index e11b93ca69b6421cc9c11da4b2bddc1ccd852b91..5500df624cf40a29d615baa903f4d83d2f96c4da 100644 (file)
@@ -544,11 +544,6 @@ void ui_widget_color_init(struct ThemeUI *tui);
 void ui_draw_menu_item(struct uiFontStyle *fstyle, rcti *rect, const char *name, int iconid, int state, bool use_sep);
 void ui_draw_preview_item(struct uiFontStyle *fstyle, rcti *rect, const char *name, int iconid, int state);
 
-extern const unsigned char checker_stipple_sml[32 * 32 / 8];
-/* used for transp checkers */
-#define UI_TRANSP_DARK 100
-#define UI_TRANSP_LIGHT 160
-
 #define UI_TEXT_MARGIN_X 0.4f
 
 /* interface_style.c */
index 5c2ce7ad6350bd5ba66afab3a8c30ff5a3334bcc..477b7c4e8f3649a18ba2d73146c759ae3f56a046 100644 (file)
@@ -181,18 +181,6 @@ static const unsigned int check_tria_face[4][3] = {
        {3, 2, 4}, {3, 4, 5}, {1, 0, 3}, {0, 2, 3}
 };
 
-GLubyte const checker_stipple_sml[32 * 32 / 8] =
-{
-       255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0,
-       255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0,
-       0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255,
-       0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255,
-       255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0,
-       255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0,
-       0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255,
-       0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255,
-};
-
 /* ************************************************* */
 
 void ui_draw_anti_tria(float x1, float y1, float x2, float y2, float x3, float y3)
@@ -681,15 +669,15 @@ static void widgetbase_draw(uiWidgetBase *wtb, uiWidgetColors *wcol)
                                float x_mid = 0.0f; /* used for dumb clamping of values */
 
                                /* dark checkers */
-                               glColor4ub(UI_TRANSP_DARK, UI_TRANSP_DARK, UI_TRANSP_DARK, 255);
+                               glColor4ub(UI_ALPHA_CHECKER_DARK, UI_ALPHA_CHECKER_DARK, UI_ALPHA_CHECKER_DARK, 255);
                                glEnableClientState(GL_VERTEX_ARRAY);
                                glVertexPointer(2, GL_FLOAT, 0, wtb->inner_v);
                                glDrawArrays(GL_POLYGON, 0, wtb->totvert);
 
                                /* light checkers */
                                glEnable(GL_POLYGON_STIPPLE);
-                               glColor4ub(UI_TRANSP_LIGHT, UI_TRANSP_LIGHT, UI_TRANSP_LIGHT, 255);
-                               glPolygonStipple(checker_stipple_sml);
+                               glColor4ub(UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT, 255);
+                               glPolygonStipple(stipple_checker_8px);
 
                                glVertexPointer(2, GL_FLOAT, 0, wtb->inner_v);
                                glDrawArrays(GL_POLYGON, 0, wtb->totvert);
index 230c3a11108236b64618a977586451dcab5200c8..9cdb6de99b0467570ab22af7de50ea446bb8453f 100644 (file)
@@ -137,6 +137,16 @@ const GLubyte stipple_diag_stripes_neg[128] = {
        0x0f, 0xf0, 0x0f, 0xf0, 0x1f, 0xe0, 0x1f, 0xe0,
        0x3f, 0xc0, 0x3f, 0xc0, 0x7f, 0x80, 0x7f, 0x80};
 
+const GLubyte stipple_checker_8px[128] = {
+       255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0,
+       255,  0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0,
+       0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255,
+       0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255,
+       255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0,
+       255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0,
+       0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255,
+       0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255};
+
 
 void fdrawbezier(float vec[4][3])
 {
@@ -204,22 +214,12 @@ void fdrawcheckerboard(float x1, float y1, float x2, float y2)
 {
        unsigned char col1[4] = {40, 40, 40}, col2[4] = {50, 50, 50};
 
-       GLubyte checker_stipple[32 * 32 / 8] = {
-               255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0,
-               255,  0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0,
-               0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255,
-               0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255,
-               255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0,
-               255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0,
-               0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255,
-               0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255};
-       
        glColor3ubv(col1);
        glRectf(x1, y1, x2, y2);
        glColor3ubv(col2);
 
        glEnable(GL_POLYGON_STIPPLE);
-       glPolygonStipple(checker_stipple);
+       glPolygonStipple(stipple_checker_8px);
        glRectf(x1, y1, x2, y2);
        glDisable(GL_POLYGON_STIPPLE);
 }
index 0b697d85b28899c89a48825a5d378deea61b6e79..672549f0402902650350e757d9975f9974d11c41 100644 (file)
@@ -165,6 +165,7 @@ static void draw_render_info(Scene *scene, Image *ima, ARegion *ar, float zoomx,
 void ED_image_draw_info(Scene *scene, ARegion *ar, int color_manage, int use_default_view, int channels, int x, int y,
                         const unsigned char cp[4], const float fp[4], const float linearcol[4], int *zp, float *zpf)
 {
+       rcti color_rect;
        char str[256];
        int dx = 6;
        const int dy = 0.3f * UI_UNIT_Y;
@@ -317,23 +318,47 @@ void ED_image_draw_info(Scene *scene, ARegion *ar, int color_manage, int use_def
        }
 
        glDisable(GL_BLEND);
-       glColor3fv(finalcol);
        dx += 0.25f * UI_UNIT_X;
-       glBegin(GL_QUADS);
-       glVertex2f(dx, 0.15f * UI_UNIT_Y);
-       glVertex2f(dx, 0.85f * UI_UNIT_Y);
-       glVertex2f(dx + 1.5f * UI_UNIT_X, 0.85 * UI_UNIT_Y);
-       glVertex2f(dx + 1.5f * UI_UNIT_X, 0.15f * UI_UNIT_Y);
-       glEnd();
+
+       BLI_rcti_init(&color_rect, dx, dx + (1.5f * UI_UNIT_X), 0.15f * UI_UNIT_Y, 0.85f * UI_UNIT_Y);
+
+       if (channels == 4) {
+               rcti color_rect_half;
+               int color_quater_x, color_quater_y;
+
+               color_rect_half = color_rect;
+               color_rect_half.xmax = BLI_rcti_cent_x(&color_rect);
+               glRecti(color_rect.xmin, color_rect.ymin, color_rect.xmax, color_rect.ymax);
+
+               color_rect_half = color_rect;
+               color_rect_half.xmin = BLI_rcti_cent_x(&color_rect);
+
+               color_quater_x = BLI_rcti_cent_x(&color_rect_half);
+               color_quater_y = BLI_rcti_cent_y(&color_rect_half);
+
+               glColor4ub(UI_ALPHA_CHECKER_DARK, UI_ALPHA_CHECKER_DARK, UI_ALPHA_CHECKER_DARK, 255);
+               glRecti(color_rect_half.xmin, color_rect_half.ymin, color_rect_half.xmax, color_rect_half.ymax);
+
+               glColor4ub(UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT, 255);
+               glRecti(color_quater_x, color_quater_y, color_rect_half.xmax, color_rect_half.ymax);
+               glRecti(color_rect_half.xmin, color_rect_half.ymin, color_quater_x, color_quater_y);
+
+               glEnable(GL_BLEND);
+               glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+               glColor4f(UNPACK3(finalcol), fp ? fp[3] : (cp[3] / 255.0f));
+               glRecti(color_rect.xmin, color_rect.ymin, color_rect.xmax, color_rect.ymax);
+               glDisable(GL_BLEND);
+       }
+       else {
+               glColor3fv(finalcol);
+               glRecti(color_rect.xmin, color_rect.ymin, color_rect.xmax, color_rect.ymax);
+       }
 
        /* draw outline */
        glColor3ub(128, 128, 128);
-       glBegin(GL_LINE_LOOP);
-       glVertex2f(dx, 0.15f * UI_UNIT_Y);
-       glVertex2f(dx, 0.85f * UI_UNIT_Y);
-       glVertex2f(dx + 1.5f * UI_UNIT_X, 0.85f * UI_UNIT_Y);
-       glVertex2f(dx + 1.5f * UI_UNIT_X, 0.15f * UI_UNIT_Y);
-       glEnd();
+       glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+       glRecti(color_rect.xmin, color_rect.ymin, color_rect.xmax, color_rect.ymax);
+       glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
 
        dx += 1.75f * UI_UNIT_X;