Manipulator: fix 2D icon buttons in the 3D view
authorCampbell Barton <ideasman42@gmail.com>
Mon, 14 May 2018 12:46:37 +0000 (14:46 +0200)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 14 May 2018 12:47:52 +0000 (14:47 +0200)
source/blender/editors/manipulator_library/manipulator_types/button2d_manipulator.c

index 73520d1801d9f9e9e08b01328e000b08d62f6810..fbf783c31f7121434976ff52d24ee90fcbaded01 100644 (file)
@@ -98,7 +98,7 @@ static void button2d_geom_draw_backdrop(
 }
 
 static void button2d_draw_intern(
-        const bContext *UNUSED(C), wmManipulator *mpr,
+        const bContext *C, wmManipulator *mpr,
         const bool select, const bool highlight)
 {
        ButtonManipulator2D *button = (ButtonManipulator2D *)mpr;
@@ -131,7 +131,23 @@ static void button2d_draw_intern(
        gpuPushMatrix();
        gpuMultMatrix(matrix_final);
 
-       if (select == false) {
+       bool is_3d = (mpr->parent_mgroup->type->flag & WM_MANIPULATORGROUPTYPE_3D) != 0;
+       if (is_3d) {
+               RegionView3D *rv3d = CTX_wm_region_view3d(C);
+               float matrix_align[4][4];
+               float matrix_final_unit[4][4];
+               normalize_m4_m4(matrix_final_unit, matrix_final);
+               mul_m4_m4m4(matrix_align, rv3d->viewmat, matrix_final_unit);
+               zero_v3(matrix_align[3]);
+               transpose_m4(matrix_align);
+               gpuMultMatrix(matrix_align);
+       }
+
+       if (select) {
+               BLI_assert(is_3d);
+               button2d_geom_draw_backdrop(mpr, color, select);
+       }
+       else {
                glEnable(GL_BLEND);
                if (button->shape_batch[0] != NULL) {
                        glEnable(GL_LINE_SMOOTH);
@@ -150,12 +166,21 @@ static void button2d_draw_intern(
                }
                else if (button->icon != ICON_NONE) {
                        button2d_geom_draw_backdrop(mpr, color, select);
-                       gpuPopMatrix();
-                       need_to_pop = false;
-                       UI_icon_draw(
-                               mpr->matrix_basis[3][0] - (ICON_DEFAULT_WIDTH / 2.0) * UI_DPI_FAC,
-                               mpr->matrix_basis[3][1] - (ICON_DEFAULT_HEIGHT / 2.0) * UI_DPI_FAC,
-                               button->icon);
+                       float size[2];
+                       if (is_3d) {
+                               const float fac = 2.0f;
+                               gpuTranslate2f(-(fac / 2), -(fac / 2));
+                               gpuScale2f(fac / (ICON_DEFAULT_WIDTH *  UI_DPI_FAC), fac / (ICON_DEFAULT_HEIGHT * UI_DPI_FAC));
+                               size[0] = 1.0f;
+                               size[1] = 1.0f;
+                       }
+                       else {
+                               size[0] = mpr->matrix_basis[3][0] - (ICON_DEFAULT_WIDTH / 2.0) * UI_DPI_FAC;
+                               size[1] = mpr->matrix_basis[3][1] - (ICON_DEFAULT_HEIGHT / 2.0) * UI_DPI_FAC;
+                               gpuPopMatrix();
+                               need_to_pop = false;
+                       }
+                       UI_icon_draw(size[0], size[1], button->icon);
                }
                glDisable(GL_BLEND);
        }