GL: use imm* module for 2D cage manipulator

This commit is contained in:
Campbell Barton
2017-04-11 02:32:53 +10:00
parent 304935e02a
commit d8fa3dd7c3

View File

@@ -46,6 +46,8 @@
#include "ED_screen.h" #include "ED_screen.h"
#include "GPU_matrix.h" #include "GPU_matrix.h"
#include "GPU_shader.h"
#include "GPU_immediate.h"
#include "MEM_guardedalloc.h" #include "MEM_guardedalloc.h"
@@ -82,29 +84,39 @@ typedef struct RectTransformManipulator {
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
static void rect_transform_draw_corners(rctf *r, const float offsetx, const float offsety) static void rect_transform_draw_corners(
const rctf *r, const float offsetx, const float offsety, const float color[3])
{ {
glBegin(GL_LINES); unsigned int pos = VertexFormat_add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT);
glVertex2f(r->xmin, r->ymin + offsety);
glVertex2f(r->xmin, r->ymin);
glVertex2f(r->xmin, r->ymin);
glVertex2f(r->xmin + offsetx, r->ymin);
glVertex2f(r->xmax, r->ymin + offsety); immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
glVertex2f(r->xmax, r->ymin); immUniformColor3fv(color);
glVertex2f(r->xmax, r->ymin);
glVertex2f(r->xmax - offsetx, r->ymin);
glVertex2f(r->xmax, r->ymax - offsety); immBegin(PRIM_LINES, 16);
glVertex2f(r->xmax, r->ymax);
glVertex2f(r->xmax, r->ymax);
glVertex2f(r->xmax - offsetx, r->ymax);
glVertex2f(r->xmin, r->ymax - offsety); immVertex2f(pos, r->xmin, r->ymin + offsety);
glVertex2f(r->xmin, r->ymax); immVertex2f(pos, r->xmin, r->ymin);
glVertex2f(r->xmin, r->ymax); immVertex2f(pos, r->xmin, r->ymin);
glVertex2f(r->xmin + offsetx, r->ymax); immVertex2f(pos, r->xmin + offsetx, r->ymin);
glEnd();
immVertex2f(pos, r->xmax, r->ymin + offsety);
immVertex2f(pos, r->xmax, r->ymin);
immVertex2f(pos, r->xmax, r->ymin);
immVertex2f(pos, r->xmax - offsetx, r->ymin);
immVertex2f(pos, r->xmax, r->ymax - offsety);
immVertex2f(pos, r->xmax, r->ymax);
immVertex2f(pos, r->xmax, r->ymax);
immVertex2f(pos, r->xmax - offsetx, r->ymax);
immVertex2f(pos, r->xmin, r->ymax - offsety);
immVertex2f(pos, r->xmin, r->ymax);
immVertex2f(pos, r->xmin, r->ymax);
immVertex2f(pos, r->xmin + offsetx, r->ymax);
immEnd();
immUnbindProgram();
} }
static void rect_transform_draw_interaction( static void rect_transform_draw_interaction(
@@ -206,15 +218,13 @@ static void manipulator_rect_transform_draw(const bContext *UNUSED(C), wmManipul
((cage->style & MANIPULATOR_RECT_TRANSFORM_STYLE_SCALE_UNIFORM) ? cage->scale[0] : cage->scale[1])); ((cage->style & MANIPULATOR_RECT_TRANSFORM_STYLE_SCALE_UNIFORM) ? cage->scale[0] : cage->scale[1]));
/* corner manipulators */ /* corner manipulators */
glColor3f(0.0, 0.0, 0.0);
glLineWidth(cage->manipulator.line_width + 3.0f); glLineWidth(cage->manipulator.line_width + 3.0f);
rect_transform_draw_corners(&r, w, h); rect_transform_draw_corners(&r, w, h, (const float[3]){0, 0, 0});
/* corner manipulators */ /* corner manipulators */
glColor3fv(manipulator->col);
glLineWidth(cage->manipulator.line_width); glLineWidth(cage->manipulator.line_width);
rect_transform_draw_corners(&r, w, h); rect_transform_draw_corners(&r, w, h, manipulator->col);
rect_transform_draw_interaction(manipulator->col, manipulator->highlighted_part, half_w, half_h, rect_transform_draw_interaction(manipulator->col, manipulator->highlighted_part, half_w, half_h,
w, h, cage->manipulator.line_width); w, h, cage->manipulator.line_width);