OpenGL immediate mode: interface_widgets.c
Added rgba_float_args_set_ch to BLI_math_color.h
This commit is contained in:
parent
5c39aad283
commit
4f2375b82f
Notes:
blender-bot
2023-02-14 05:25:44 +01:00
Referenced by commit 20a105d54c
, Fix errors in new immediate mode for interface_widgets.c
|
@ -141,6 +141,9 @@ MINLINE void float_to_byte_dither_v3(unsigned char b[3], const float f[3], float
|
|||
#define rgba_char_args_set_fl(col, r, g, b, a) \
|
||||
rgba_char_args_set(col, (r) * 255, (g) * 255, (b) * 255, (a) * 255)
|
||||
|
||||
#define rgba_float_args_set_ch(col, r, g, b, a) \
|
||||
rgba_float_args_set(col, (r) / 255.0f, (g) / 255.0f, (b) / 255.0f, (a) / 255.0f)
|
||||
|
||||
MINLINE void rgba_char_args_set(char col[4], const char r, const char g, const char b, const char a);
|
||||
MINLINE void rgba_float_args_set(float col[4], const float r, const float g, const float b, const float a);
|
||||
MINLINE void rgba_char_args_test_set(char col[4], const char r, const char g, const char b, const char a);
|
||||
|
|
|
@ -499,6 +499,7 @@ static int ui_but_calc_float_precision(uiBut *but, double value)
|
|||
static void ui_draw_linkline(uiLinkLine *line, int highlightActiveLines, int dashInactiveLines)
|
||||
{
|
||||
rcti rect;
|
||||
float color[4] = {1.0f};
|
||||
|
||||
if (line->from == NULL || line->to == NULL) return;
|
||||
|
||||
|
@ -508,15 +509,15 @@ static void ui_draw_linkline(uiLinkLine *line, int highlightActiveLines, int das
|
|||
rect.ymax = BLI_rctf_cent_y(&line->to->rect);
|
||||
|
||||
if (dashInactiveLines)
|
||||
UI_ThemeColor(TH_GRID);
|
||||
UI_GetThemeColor4fv(TH_GRID, color);
|
||||
else if (line->flag & UI_SELECT)
|
||||
glColor3ub(100, 100, 100);
|
||||
rgba_float_args_set_ch(color, 100, 100, 100, 255);
|
||||
else if (highlightActiveLines && ((line->from->flag & UI_ACTIVE) || (line->to->flag & UI_ACTIVE)))
|
||||
UI_ThemeColor(TH_TEXT_HI);
|
||||
UI_GetThemeColor4fv(TH_TEXT_HI, color);
|
||||
else
|
||||
glColor3ub(0, 0, 0);
|
||||
rgba_float_args_set_ch(color, 0, 0, 0, 255);
|
||||
|
||||
ui_draw_link_bezier(&rect);
|
||||
ui_draw_link_bezier(&rect, color);
|
||||
}
|
||||
|
||||
static void ui_draw_links(uiBlock *block)
|
||||
|
|
|
@ -690,7 +690,7 @@ uiWidgetColors *ui_tooltip_get_theme(void);
|
|||
void ui_draw_tooltip_background(uiStyle *UNUSED(style), uiBlock *block, rcti *rect);
|
||||
void ui_draw_search_back(struct uiStyle *style, uiBlock *block, rcti *rect);
|
||||
bool ui_link_bezier_points(const rcti *rect, float coord_array[][2], int resol);
|
||||
void ui_draw_link_bezier(const rcti *rect);
|
||||
void ui_draw_link_bezier(const rcti *rect, const float color[4]);
|
||||
|
||||
extern void ui_draw_but(const struct bContext *C, ARegion *ar, struct uiStyle *style, uiBut *but, rcti *rect);
|
||||
/* theme color init */
|
||||
|
|
|
@ -59,6 +59,7 @@
|
|||
|
||||
#include "GPU_basic_shader.h"
|
||||
#include "GPU_immediate.h"
|
||||
#include "GPU_matrix.h"
|
||||
|
||||
#ifdef WITH_INPUT_IME
|
||||
# include "WM_types.h"
|
||||
|
@ -545,12 +546,27 @@ static void widget_scroll_circle(uiWidgetTrias *tria, const rcti *rect, float tr
|
|||
scroll_circle_face, ARRAY_SIZE(scroll_circle_face));
|
||||
}
|
||||
|
||||
static void widget_trias_draw(uiWidgetTrias *tria)
|
||||
static void widget_trias_draw(uiWidgetTrias *tria, unsigned int pos)
|
||||
{
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glVertexPointer(2, GL_FLOAT, 0, tria->vec);
|
||||
glDrawElements(GL_TRIANGLES, tria->tot * 3, GL_UNSIGNED_INT, tria->index);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
immBegin(GL_TRIANGLES, tria->tot * 3);
|
||||
for (int i = 0; i < tria->tot; ++i)
|
||||
for (int j = 0; j < 3; ++j)
|
||||
immVertex2fv(pos, tria->vec[tria->index[i][j]]);
|
||||
immEnd();
|
||||
}
|
||||
|
||||
static void widget_draw_vertex_buffer(unsigned int pos, unsigned int col, int mode,
|
||||
const float quads_pos[WIDGET_SIZE_MAX][2],
|
||||
const unsigned char quads_col[WIDGET_SIZE_MAX][4],
|
||||
unsigned int totvert)
|
||||
{
|
||||
immBegin(mode, totvert);
|
||||
for (int i = 0; i < totvert; ++i) {
|
||||
if (quads_col)
|
||||
immAttrib4ubv(col, quads_col[i]);
|
||||
immVertex2fv(pos, quads_pos[i]);
|
||||
}
|
||||
immEnd();
|
||||
}
|
||||
|
||||
static void widget_menu_trias(uiWidgetTrias *tria, const rcti *rect)
|
||||
|
@ -639,21 +655,18 @@ static void widget_verts_to_triangle_strip_open(uiWidgetBase *wtb, const int tot
|
|||
}
|
||||
}
|
||||
|
||||
static void widgetbase_outline(uiWidgetBase *wtb)
|
||||
static void widgetbase_outline(uiWidgetBase *wtb, unsigned int pos)
|
||||
{
|
||||
float triangle_strip[WIDGET_SIZE_MAX * 2 + 2][2]; /* + 2 because the last pair is wrapped */
|
||||
widget_verts_to_triangle_strip(wtb, wtb->totvert, triangle_strip);
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glVertexPointer(2, GL_FLOAT, 0, triangle_strip);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, wtb->totvert * 2 + 2);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
widget_draw_vertex_buffer(pos, 0, GL_TRIANGLE_STRIP, triangle_strip, NULL, wtb->totvert * 2 + 2);
|
||||
}
|
||||
|
||||
static void widgetbase_draw(uiWidgetBase *wtb, uiWidgetColors *wcol)
|
||||
{
|
||||
int j, a;
|
||||
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
/* backdrop non AA */
|
||||
|
@ -663,78 +676,76 @@ static void widgetbase_draw(uiWidgetBase *wtb, uiWidgetColors *wcol)
|
|||
float inner_v_half[WIDGET_SIZE_MAX][2];
|
||||
float x_mid = 0.0f; /* used for dumb clamping of values */
|
||||
|
||||
/* dark checkers */
|
||||
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);
|
||||
unsigned int pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 2, KEEP_FLOAT);
|
||||
immBindBuiltinProgram(GPU_SHADER_2D_CHECKER);
|
||||
|
||||
/* light checkers */
|
||||
GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
|
||||
glColor4ub(UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT, 255);
|
||||
GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_CHECKER_8PX);
|
||||
/* checkers */
|
||||
immUniform4f("color1", UI_ALPHA_CHECKER_DARK / 255.0f, UI_ALPHA_CHECKER_DARK / 255.0f, UI_ALPHA_CHECKER_DARK / 255.0f, 1.0f);
|
||||
immUniform4f("color2", UI_ALPHA_CHECKER_LIGHT / 255.0f, UI_ALPHA_CHECKER_LIGHT / 255.0f, UI_ALPHA_CHECKER_LIGHT / 255.0f, 1.0f);
|
||||
immUniform1i("size", 8);
|
||||
|
||||
glVertexPointer(2, GL_FLOAT, 0, wtb->inner_v);
|
||||
glDrawArrays(GL_POLYGON, 0, wtb->totvert);
|
||||
widget_draw_vertex_buffer(pos, 0, GL_TRIANGLE_FAN, wtb->inner_v, NULL, wtb->totvert);
|
||||
|
||||
GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
|
||||
immUnbindProgram();
|
||||
|
||||
/* alpha fill */
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
|
||||
immUniformColor4ubv((unsigned char *)wcol->inner);
|
||||
|
||||
glColor4ubv((unsigned char *)wcol->inner);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
for (a = 0; a < wtb->totvert; a++) {
|
||||
x_mid += wtb->inner_v[a][0];
|
||||
}
|
||||
x_mid /= wtb->totvert;
|
||||
|
||||
glVertexPointer(2, GL_FLOAT, 0, wtb->inner_v);
|
||||
glDrawArrays(GL_POLYGON, 0, wtb->totvert);
|
||||
widget_draw_vertex_buffer(pos, 0, GL_TRIANGLE_FAN, wtb->inner_v, NULL, wtb->totvert);
|
||||
|
||||
/* 1/2 solid color */
|
||||
glColor4ub(wcol->inner[0], wcol->inner[1], wcol->inner[2], 255);
|
||||
immUniformColor4ub(wcol->inner[0], wcol->inner[1], wcol->inner[2], 255);
|
||||
|
||||
for (a = 0; a < wtb->totvert; a++) {
|
||||
inner_v_half[a][0] = MIN2(wtb->inner_v[a][0], x_mid);
|
||||
inner_v_half[a][1] = wtb->inner_v[a][1];
|
||||
}
|
||||
|
||||
glVertexPointer(2, GL_FLOAT, 0, inner_v_half);
|
||||
glDrawArrays(GL_POLYGON, 0, wtb->totvert);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
widget_draw_vertex_buffer(pos, 0, GL_TRIANGLE_FAN, inner_v_half, NULL, wtb->totvert);
|
||||
|
||||
immUnbindProgram();
|
||||
}
|
||||
else {
|
||||
/* simple fill */
|
||||
glColor4ubv((unsigned char *)wcol->inner);
|
||||
unsigned int pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 2, KEEP_FLOAT);
|
||||
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
|
||||
immUniformColor4ubv((unsigned char *)wcol->inner);
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glVertexPointer(2, GL_FLOAT, 0, wtb->inner_v);
|
||||
glDrawArrays(GL_POLYGON, 0, wtb->totvert);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
widget_draw_vertex_buffer(pos, 0, GL_TRIANGLE_FAN, wtb->inner_v, NULL, wtb->totvert);
|
||||
|
||||
immUnbindProgram();
|
||||
}
|
||||
}
|
||||
else {
|
||||
char col1[4], col2[4];
|
||||
unsigned char col_array[WIDGET_SIZE_MAX * 4];
|
||||
unsigned char *col_pt = col_array;
|
||||
|
||||
unsigned char col_array[WIDGET_SIZE_MAX][4];
|
||||
unsigned char *col_pt = &col_array[0][0];
|
||||
|
||||
VertexFormat *format = immVertexFormat();
|
||||
unsigned int pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
|
||||
unsigned int col = add_attrib(format, "color", GL_UNSIGNED_BYTE, 4, NORMALIZE_INT_TO_FLOAT);
|
||||
|
||||
immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR);
|
||||
|
||||
shadecolors4(col1, col2, wcol->inner, wcol->shadetop, wcol->shadedown);
|
||||
|
||||
for (a = 0; a < wtb->totvert; a++, col_pt += 4) {
|
||||
round_box_shade_col4_r(col_pt, col1, col2, wtb->inner_uv[a][wtb->draw_shadedir ? 1 : 0]);
|
||||
}
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
glVertexPointer(2, GL_FLOAT, 0, wtb->inner_v);
|
||||
glColorPointer(4, GL_UNSIGNED_BYTE, 0, col_array);
|
||||
glDrawArrays(GL_POLYGON, 0, wtb->totvert);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
widget_draw_vertex_buffer(pos, col, GL_TRIANGLE_FAN, wtb->inner_v, col_array, wtb->totvert);
|
||||
immUnbindProgram();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* for each AA step */
|
||||
if (wtb->draw_outline) {
|
||||
float triangle_strip[WIDGET_SIZE_MAX * 2 + 2][2]; /* + 2 because the last pair is wrapped */
|
||||
|
@ -753,52 +764,63 @@ static void widgetbase_draw(uiWidgetBase *wtb, uiWidgetColors *wcol)
|
|||
UI_GetThemeColor4ubv(TH_WIDGET_EMBOSS, emboss);
|
||||
}
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
unsigned int pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 2, KEEP_FLOAT);
|
||||
|
||||
gpuMatrixBegin3D_legacy();
|
||||
|
||||
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
|
||||
for (j = 0; j < WIDGET_AA_JITTER; j++) {
|
||||
glTranslate2fv(jit[j]);
|
||||
gpuTranslate3f(jit[j][0], jit[j][1], 0.0f);
|
||||
|
||||
/* outline */
|
||||
glColor4ubv(tcol);
|
||||
immUniformColor4ubv(tcol);
|
||||
|
||||
glVertexPointer(2, GL_FLOAT, 0, triangle_strip);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, wtb->totvert * 2 + 2);
|
||||
widget_draw_vertex_buffer(pos, 0, GL_TRIANGLE_STRIP, triangle_strip, NULL, wtb->totvert * 2 + 2);
|
||||
|
||||
/* emboss bottom shadow */
|
||||
if (wtb->draw_emboss) {
|
||||
if (emboss[3]) {
|
||||
glColor4ubv(emboss);
|
||||
glVertexPointer(2, GL_FLOAT, 0, triangle_strip_emboss);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, wtb->halfwayvert * 2);
|
||||
immUniformColor4ubv(emboss);
|
||||
widget_draw_vertex_buffer(pos, 0, GL_TRIANGLE_STRIP, triangle_strip_emboss, NULL, wtb->halfwayvert * 2);
|
||||
}
|
||||
}
|
||||
|
||||
glTranslatef(-jit[j][0], -jit[j][1], 0.0f);
|
||||
gpuTranslate3f(-jit[j][0], -jit[j][1], 0.0f);
|
||||
}
|
||||
immUnbindProgram();
|
||||
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
gpuMatrixEnd();
|
||||
}
|
||||
|
||||
|
||||
/* decoration */
|
||||
if (wtb->tria1.tot || wtb->tria2.tot) {
|
||||
const unsigned char tcol[4] = {wcol->item[0],
|
||||
wcol->item[1],
|
||||
wcol->item[2],
|
||||
(unsigned char)((float)wcol->item[3] / WIDGET_AA_JITTER)};
|
||||
glColor4ubv(tcol);
|
||||
|
||||
unsigned int pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 2, KEEP_FLOAT);
|
||||
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
|
||||
immUniformColor4ubv(tcol);
|
||||
|
||||
gpuMatrixBegin3D_legacy();
|
||||
|
||||
/* for each AA step */
|
||||
for (j = 0; j < WIDGET_AA_JITTER; j++) {
|
||||
glTranslate2fv(jit[j]);
|
||||
gpuTranslate3f(jit[j][0], jit[j][1], 0.0f);
|
||||
|
||||
if (wtb->tria1.tot)
|
||||
widget_trias_draw(&wtb->tria1);
|
||||
widget_trias_draw(&wtb->tria1, pos);
|
||||
|
||||
if (wtb->tria2.tot)
|
||||
widget_trias_draw(&wtb->tria2);
|
||||
widget_trias_draw(&wtb->tria2, pos);
|
||||
|
||||
glTranslatef(-jit[j][0], -jit[j][1], 0.0f);
|
||||
gpuTranslate3f(-jit[j][0], -jit[j][1], 0.0f);
|
||||
}
|
||||
|
||||
gpuMatrixEnd();
|
||||
|
||||
immUnbindProgram();
|
||||
}
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
|
@ -1372,11 +1394,16 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b
|
|||
|
||||
selwidth_draw = BLF_width(fstyle->uifont_id, drawstr + but->ofs, but->selend - but->ofs);
|
||||
|
||||
glColor4ubv((unsigned char *)wcol->item);
|
||||
glRecti(rect->xmin + selsta_draw,
|
||||
rect->ymin + 2,
|
||||
min_ii(rect->xmin + selwidth_draw, rect->xmax - 2),
|
||||
rect->ymax - 2);
|
||||
unsigned int pos = add_attrib(immVertexFormat(), "pos", GL_INT, 2, KEEP_INT);
|
||||
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
|
||||
|
||||
immUniformColor4ubv((unsigned char *)wcol->item);
|
||||
immRecti(pos, rect->xmin + selsta_draw,
|
||||
rect->ymin + 2,
|
||||
min_ii(rect->xmin + selwidth_draw, rect->xmax - 2),
|
||||
rect->ymax - 2);
|
||||
|
||||
immUnbindProgram();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1399,13 +1426,18 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b
|
|||
t = 0;
|
||||
}
|
||||
|
||||
glColor3f(0.2, 0.6, 0.9);
|
||||
unsigned int pos = add_attrib(immVertexFormat(), "pos", GL_INT, 2, KEEP_INT);
|
||||
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
|
||||
|
||||
immUniformColor3f(0.2f, 0.6f, 0.9f);
|
||||
|
||||
tx = rect->xmin + t + 2;
|
||||
ty = rect->ymin + 2;
|
||||
|
||||
/* draw cursor */
|
||||
glRecti(rect->xmin + t, ty, tx, rect->ymax - 2);
|
||||
immRecti(pos, rect->xmin + t, ty, tx, rect->ymax - 2);
|
||||
|
||||
immUnbindProgram();
|
||||
}
|
||||
|
||||
#ifdef WITH_INPUT_IME
|
||||
|
@ -2170,23 +2202,24 @@ static void widget_softshadow(const rcti *rect, int roundboxalign, const float r
|
|||
|
||||
/* we draw a number of increasing size alpha quad strips */
|
||||
alphastep = 3.0f * btheme->tui.menu_shadow_fac / radout;
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
unsigned int pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 2, KEEP_FLOAT);
|
||||
|
||||
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
|
||||
|
||||
for (step = 1; step <= (int)radout; step++) {
|
||||
float expfac = sqrtf(step / radout);
|
||||
|
||||
round_box_shadow_edges(wtb.outer_v, &rect1, radin, UI_CNR_ALL, (float)step);
|
||||
|
||||
glColor4f(0.0f, 0.0f, 0.0f, alphastep * (1.0f - expfac));
|
||||
immUniformColor4f(0.0f, 0.0f, 0.0f, alphastep * (1.0f - expfac));
|
||||
|
||||
widget_verts_to_triangle_strip(&wtb, totvert, triangle_strip);
|
||||
|
||||
glVertexPointer(2, GL_FLOAT, 0, triangle_strip);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, totvert * 2); /* add + 2 for getting a complete soft rect. Now it skips top edge to allow transparent menus */
|
||||
widget_draw_vertex_buffer(pos, 0, GL_TRIANGLE_STRIP, triangle_strip, NULL, totvert * 2);
|
||||
}
|
||||
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
immUnbindProgram();
|
||||
}
|
||||
|
||||
static void widget_menu_back(uiWidgetColors *wcol, rcti *rect, int flag, int direction)
|
||||
|
@ -2223,20 +2256,21 @@ static void widget_menu_back(uiWidgetColors *wcol, rcti *rect, int flag, int dir
|
|||
|
||||
static void ui_hsv_cursor(float x, float y)
|
||||
{
|
||||
glPushMatrix();
|
||||
glTranslatef(x, y, 0.0f);
|
||||
|
||||
glColor3f(1.0f, 1.0f, 1.0f);
|
||||
glutil_draw_filled_arc(0.0f, M_PI * 2.0, 3.0f * U.pixelsize, 8);
|
||||
unsigned int pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 2, KEEP_FLOAT);
|
||||
|
||||
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
|
||||
|
||||
immUniformColor3f(1.0f, 1.0f, 1.0f);
|
||||
imm_draw_filled_circle(pos, x, y, 3.0f * U.pixelsize, 8);
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glEnable(GL_LINE_SMOOTH);
|
||||
glColor3f(0.0f, 0.0f, 0.0f);
|
||||
glutil_draw_lined_arc(0.0f, M_PI * 2.0, 3.0f * U.pixelsize, 12);
|
||||
immUniformColor3f(0.0f, 0.0f, 0.0f);
|
||||
imm_draw_lined_circle(pos, x, y, 3.0f * U.pixelsize, 12);
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_LINE_SMOOTH);
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
immUnbindProgram();
|
||||
}
|
||||
|
||||
void ui_hsvcircle_vals_from_pos(float *val_rad, float *val_dist, const rcti *rect,
|
||||
|
@ -2354,11 +2388,11 @@ static void ui_draw_but_HSVCIRCLE(uiBut *but, uiWidgetColors *wcol, const rcti *
|
|||
immUniformColor3ubv((unsigned char *)wcol->outline);
|
||||
imm_draw_lined_circle(pos, centx, centy, radius, tot);
|
||||
|
||||
immUnbindProgram();
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_LINE_SMOOTH);
|
||||
|
||||
immUnbindProgram();
|
||||
|
||||
/* cursor */
|
||||
float xpos, ypos;
|
||||
ui_hsvcircle_pos_from_vals(but, rect, hsvo, &xpos, &ypos);
|
||||
|
@ -2371,7 +2405,8 @@ static void ui_draw_but_HSVCIRCLE(uiBut *but, uiWidgetColors *wcol, const rcti *
|
|||
void ui_draw_gradient(const rcti *rect, const float hsv[3], const int type, const float alpha)
|
||||
{
|
||||
/* allows for 4 steps (red->yellow) */
|
||||
const float color_step = 1.0f / 48.0f;
|
||||
const int steps = 48;
|
||||
const float color_step = 1.0f / steps;
|
||||
int a;
|
||||
float h = hsv[0], s = hsv[1], v = hsv[2];
|
||||
float dx, dy, sx1, sx2, sy;
|
||||
|
@ -2425,9 +2460,14 @@ void ui_draw_gradient(const rcti *rect, const float hsv[3], const int type, cons
|
|||
copy_v3_v3(col1[3], col1[2]);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
/* old below */
|
||||
VertexFormat *format = immVertexFormat();
|
||||
unsigned int pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
|
||||
unsigned int col = add_attrib(format, "color", GL_FLOAT, 4, KEEP_FLOAT);
|
||||
immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR);
|
||||
|
||||
immBegin(GL_TRIANGLES, steps * 3 * 6);
|
||||
for (dx = 0.0f; dx < 0.999f; dx += color_step) { /* 0.999 = prevent float inaccuracy for steps */
|
||||
const float dx_next = dx + color_step;
|
||||
|
||||
|
@ -2485,22 +2525,29 @@ void ui_draw_gradient(const rcti *rect, const float hsv[3], const int type, cons
|
|||
sy = rect->ymin;
|
||||
dy = (float)BLI_rcti_size_y(rect) / 3.0f;
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
for (a = 0; a < 3; a++, sy += dy) {
|
||||
glColor4f(col0[a][0], col0[a][1], col0[a][2], alpha);
|
||||
glVertex2f(sx1, sy);
|
||||
immAttrib4f(col, col0[a][0], col0[a][1], col0[a][2], alpha);
|
||||
immVertex2f(pos, sx1, sy);
|
||||
|
||||
glColor4f(col1[a][0], col1[a][1], col1[a][2], alpha);
|
||||
glVertex2f(sx2, sy);
|
||||
immAttrib4f(col, col1[a][0], col1[a][1], col1[a][2], alpha);
|
||||
immVertex2f(pos, sx2, sy);
|
||||
|
||||
glColor4f(col1[a + 1][0], col1[a + 1][1], col1[a + 1][2], alpha);
|
||||
glVertex2f(sx2, sy + dy);
|
||||
immAttrib4f(col, col1[a + 1][0], col1[a + 1][1], col1[a + 1][2], alpha);
|
||||
immVertex2f(pos, sx2, sy + dy);
|
||||
|
||||
immAttrib4f(col, col0[a][0], col0[a][1], col0[a][2], alpha);
|
||||
immVertex2f(pos, sx1, sy);
|
||||
|
||||
immAttrib4f(col, col1[a + 1][0], col1[a + 1][1], col1[a + 1][2], alpha);
|
||||
immVertex2f(pos, sx2, sy + dy);
|
||||
|
||||
glColor4f(col0[a + 1][0], col0[a + 1][1], col0[a + 1][2], alpha);
|
||||
glVertex2f(sx1, sy + dy);
|
||||
immAttrib4f(col, col0[a + 1][0], col0[a + 1][1], col0[a + 1][2], alpha);
|
||||
immVertex2f(pos, sx1, sy + dy);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
immEnd();
|
||||
|
||||
immUnbindProgram();
|
||||
}
|
||||
|
||||
bool ui_but_is_colorpicker_display_space(uiBut *but)
|
||||
|
@ -2576,8 +2623,11 @@ static void ui_draw_but_HSVCUBE(uiBut *but, const rcti *rect)
|
|||
ui_hsv_cursor(x, y);
|
||||
|
||||
/* outline */
|
||||
glColor3ub(0, 0, 0);
|
||||
fdrawbox((rect->xmin), (rect->ymin), (rect->xmax), (rect->ymax));
|
||||
unsigned int pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 2, KEEP_FLOAT);
|
||||
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
|
||||
immUniformColor3ub(0, 0, 0);
|
||||
imm_draw_line_box(pos, (rect->xmin), (rect->ymin), (rect->xmax), (rect->ymax));
|
||||
immUnbindProgram();
|
||||
}
|
||||
|
||||
/* vertical 'value' slider, using new widget code */
|
||||
|
@ -2645,12 +2695,17 @@ static void ui_draw_separator(const rcti *rect, uiWidgetColors *wcol)
|
|||
wcol->text[2],
|
||||
30
|
||||
};
|
||||
|
||||
|
||||
unsigned int pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 2, KEEP_FLOAT);
|
||||
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glColor4ubv(col);
|
||||
immUniformColor4ubv(col);
|
||||
glLineWidth(1.0f);
|
||||
sdrawline(rect->xmin, y, rect->xmax, y);
|
||||
imm_draw_line(pos, rect->xmin, y, rect->xmax, y);
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
immUnbindProgram();
|
||||
}
|
||||
|
||||
/* ************ button callbacks, draw ***************** */
|
||||
|
@ -2722,11 +2777,14 @@ bool ui_link_bezier_points(const rcti *rect, float coord_array[][2], int resol)
|
|||
}
|
||||
|
||||
#define LINK_RESOL 24
|
||||
void ui_draw_link_bezier(const rcti *rect)
|
||||
void ui_draw_link_bezier(const rcti *rect, const float color[4])
|
||||
{
|
||||
float coord_array[LINK_RESOL + 1][2];
|
||||
|
||||
if (ui_link_bezier_points(rect, coord_array, LINK_RESOL)) {
|
||||
unsigned int pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 2, KEEP_FLOAT);
|
||||
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
|
||||
|
||||
#if 0 /* unused */
|
||||
/* we can reuse the dist variable here to increment the GL curve eval amount*/
|
||||
const float dist = 1.0f / (float)LINK_RESOL;
|
||||
|
@ -2734,13 +2792,17 @@ void ui_draw_link_bezier(const rcti *rect)
|
|||
glEnable(GL_BLEND);
|
||||
glEnable(GL_LINE_SMOOTH);
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glVertexPointer(2, GL_FLOAT, 0, coord_array);
|
||||
glDrawArrays(GL_LINE_STRIP, 0, LINK_RESOL + 1);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
immUniformColor4fv(color);
|
||||
|
||||
immBegin(GL_LINE_STRIP, LINK_RESOL + 1);
|
||||
for (int i = 0; i <= LINK_RESOL; ++i)
|
||||
immVertex2fv(pos, coord_array[i]);
|
||||
immEnd();
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_LINE_SMOOTH);
|
||||
|
||||
immUnbindProgram();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2922,15 +2984,16 @@ static void widget_link(uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *rect, in
|
|||
|
||||
if (but->flag & UI_SELECT) {
|
||||
rcti rectlink;
|
||||
float color[4];
|
||||
|
||||
UI_ThemeColor(TH_TEXT_HI);
|
||||
UI_GetThemeColor4fv(TH_TEXT_HI, color);
|
||||
|
||||
rectlink.xmin = BLI_rcti_cent_x(rect);
|
||||
rectlink.ymin = BLI_rcti_cent_y(rect);
|
||||
rectlink.xmax = but->linkto[0];
|
||||
rectlink.ymax = but->linkto[1];
|
||||
|
||||
ui_draw_link_bezier(&rectlink);
|
||||
ui_draw_link_bezier(&rectlink, color);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3082,13 +3145,18 @@ static void widget_swatch(uiBut *but, uiWidgetColors *wcol, rcti *rect, int stat
|
|||
float bw = rgb_to_grayscale(col);
|
||||
|
||||
bw += (bw < 0.5f) ? 0.5f : -0.5f;
|
||||
|
||||
glColor4f(bw, bw, bw, 1.0);
|
||||
glBegin(GL_TRIANGLES);
|
||||
glVertex2f(rect->xmin + 0.1f * width, rect->ymin + 0.9f * height);
|
||||
glVertex2f(rect->xmin + 0.1f * width, rect->ymin + 0.5f * height);
|
||||
glVertex2f(rect->xmin + 0.5f * width, rect->ymin + 0.9f * height);
|
||||
glEnd();
|
||||
|
||||
unsigned int pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 2, KEEP_FLOAT);
|
||||
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
|
||||
|
||||
immUniformColor4f(bw, bw, bw, 1.0f);
|
||||
immBegin(GL_TRIANGLES, 3);
|
||||
immVertex2f(pos, rect->xmin + 0.1f * width, rect->ymin + 0.9f * height);
|
||||
immVertex2f(pos, rect->xmin + 0.1f * width, rect->ymin + 0.5f * height);
|
||||
immVertex2f(pos, rect->xmin + 0.5f * width, rect->ymin + 0.9f * height);
|
||||
immEnd();
|
||||
|
||||
immUnbindProgram();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3389,7 +3457,7 @@ static void widget_draw_extra_mask(const bContext *C, uiBut *but, uiWidgetType *
|
|||
uiWidgetBase wtb;
|
||||
const float rad = 0.25f * U.widget_unit;
|
||||
unsigned char col[4];
|
||||
|
||||
|
||||
/* state copy! */
|
||||
wt->wcol = *(wt->wcol_theme);
|
||||
|
||||
|
@ -3399,12 +3467,17 @@ static void widget_draw_extra_mask(const bContext *C, uiBut *but, uiWidgetType *
|
|||
/* note: drawextra can change rect +1 or -1, to match round errors of existing previews */
|
||||
but->block->drawextra(C, but->poin, but->block->drawextra_arg1, but->block->drawextra_arg2, rect);
|
||||
|
||||
unsigned int pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 2, KEEP_FLOAT);
|
||||
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
|
||||
|
||||
/* make mask to draw over image */
|
||||
UI_GetThemeColor3ubv(TH_BACK, col);
|
||||
glColor3ubv(col);
|
||||
|
||||
immUniformColor3ubv(col);
|
||||
|
||||
round_box__edges(&wtb, UI_CNR_ALL, rect, 0.0f, rad);
|
||||
widgetbase_outline(&wtb);
|
||||
widgetbase_outline(&wtb, pos);
|
||||
|
||||
immUnbindProgram();
|
||||
}
|
||||
|
||||
/* outline */
|
||||
|
@ -3945,33 +4018,21 @@ static void draw_disk_shaded(
|
|||
float y1, y2;
|
||||
float fac;
|
||||
unsigned char r_col[4];
|
||||
unsigned int pos, col;
|
||||
|
||||
glBegin(GL_TRIANGLE_STRIP);
|
||||
|
||||
s = sinf(start);
|
||||
c = cosf(start);
|
||||
|
||||
y1 = s * radius_int;
|
||||
y2 = s * radius_ext;
|
||||
|
||||
VertexFormat *format = immVertexFormat();
|
||||
pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
|
||||
if (shaded) {
|
||||
fac = (y1 + radius_ext) * radius_ext_scale;
|
||||
round_box_shade_col4_r(r_col, col1, col2, fac);
|
||||
|
||||
glColor4ubv(r_col);
|
||||
col = add_attrib(format, "color", GL_UNSIGNED_BYTE, 4, NORMALIZE_INT_TO_FLOAT);
|
||||
immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR);
|
||||
}
|
||||
else {
|
||||
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
|
||||
immUniformColor4ubv((unsigned char *)col1);
|
||||
}
|
||||
|
||||
glVertex2f(c * radius_int, s * radius_int);
|
||||
|
||||
if (shaded) {
|
||||
fac = (y2 + radius_ext) * radius_ext_scale;
|
||||
round_box_shade_col4_r(r_col, col1, col2, fac);
|
||||
|
||||
glColor4ubv(r_col);
|
||||
}
|
||||
glVertex2f(c * radius_ext, s * radius_ext);
|
||||
|
||||
for (i = 1; i < subd; i++) {
|
||||
immBegin(GL_TRIANGLE_STRIP, subd * 2);
|
||||
for (i = 0; i < subd; i++) {
|
||||
float a;
|
||||
|
||||
a = start + ((i) / (float)(subd - 1)) * angle;
|
||||
|
@ -3983,20 +4044,20 @@ static void draw_disk_shaded(
|
|||
if (shaded) {
|
||||
fac = (y1 + radius_ext) * radius_ext_scale;
|
||||
round_box_shade_col4_r(r_col, col1, col2, fac);
|
||||
|
||||
glColor4ubv(r_col);
|
||||
immAttrib4ubv(col, r_col);
|
||||
}
|
||||
glVertex2f(c * radius_int, s * radius_int);
|
||||
immVertex2f(pos, c * radius_int, s * radius_int);
|
||||
|
||||
if (shaded) {
|
||||
fac = (y2 + radius_ext) * radius_ext_scale;
|
||||
round_box_shade_col4_r(r_col, col1, col2, fac);
|
||||
|
||||
glColor4ubv(r_col);
|
||||
immAttrib4ubv(col, r_col);
|
||||
}
|
||||
glVertex2f(c * radius_ext, s * radius_ext);
|
||||
immVertex2f(pos, c * radius_ext, s * radius_ext);
|
||||
}
|
||||
glEnd();
|
||||
immEnd();
|
||||
|
||||
immUnbindProgram();
|
||||
}
|
||||
|
||||
void ui_draw_pie_center(uiBlock *block)
|
||||
|
@ -4015,8 +4076,9 @@ void ui_draw_pie_center(uiBlock *block)
|
|||
float angle = atan2f(pie_dir[1], pie_dir[0]);
|
||||
float range = (block->pie_data.flags & UI_PIE_DEGREES_RANGE_LARGE) ? M_PI_2 : M_PI_4;
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(cx, cy, 0.0f);
|
||||
gpuMatrixBegin3D_legacy();
|
||||
gpuPushMatrix();
|
||||
gpuTranslate3f(cx, cy, 0.0f);
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
if (btheme->tui.wcol_pie_menu.shaded) {
|
||||
|
@ -4025,8 +4087,7 @@ void ui_draw_pie_center(uiBlock *block)
|
|||
draw_disk_shaded(0.0f, (float)(M_PI * 2.0), pie_radius_internal, pie_radius_external, subd, col1, col2, true);
|
||||
}
|
||||
else {
|
||||
glColor4ubv((GLubyte *)btheme->tui.wcol_pie_menu.inner);
|
||||
draw_disk_shaded(0.0f, (float)(M_PI * 2.0), pie_radius_internal, pie_radius_external, subd, NULL, NULL, false);
|
||||
draw_disk_shaded(0.0f, (float)(M_PI * 2.0), pie_radius_internal, pie_radius_external, subd, btheme->tui.wcol_pie_menu.inner, NULL, false);
|
||||
}
|
||||
|
||||
if (!(block->pie_data.flags & UI_PIE_INVALID_DIR)) {
|
||||
|
@ -4036,25 +4097,35 @@ void ui_draw_pie_center(uiBlock *block)
|
|||
draw_disk_shaded(angle - range / 2.0f, range, pie_radius_internal, pie_radius_external, subd, col1, col2, true);
|
||||
}
|
||||
else {
|
||||
glColor4ubv((GLubyte *)btheme->tui.wcol_pie_menu.inner_sel);
|
||||
draw_disk_shaded(angle - range / 2.0f, range, pie_radius_internal, pie_radius_external, subd, NULL, NULL, false);
|
||||
draw_disk_shaded(angle - range / 2.0f, range, pie_radius_internal, pie_radius_external, subd, btheme->tui.wcol_pie_menu.inner, NULL, false);
|
||||
}
|
||||
}
|
||||
|
||||
glColor4ubv((GLubyte *)btheme->tui.wcol_pie_menu.outline);
|
||||
glutil_draw_lined_arc(0.0f, (float)M_PI * 2.0f, pie_radius_internal, subd);
|
||||
glutil_draw_lined_arc(0.0f, (float)M_PI * 2.0f, pie_radius_external, subd);
|
||||
VertexFormat *format = immVertexFormat();
|
||||
unsigned int pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
|
||||
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
|
||||
immUniformColor4ubv((unsigned char *)btheme->tui.wcol_pie_menu.outline);
|
||||
|
||||
imm_draw_lined_circle(pos, 0.0f, 0.0f, pie_radius_internal, subd);
|
||||
imm_draw_lined_circle(pos, 0.0f, 0.0f, pie_radius_external, subd);
|
||||
|
||||
immUnbindProgram();
|
||||
|
||||
if (U.pie_menu_confirm > 0 && !(block->pie_data.flags & (UI_PIE_INVALID_DIR | UI_PIE_CLICK_STYLE))) {
|
||||
float pie_confirm_radius = U.pixelsize * (pie_radius_internal + U.pie_menu_confirm);
|
||||
float pie_confirm_external = U.pixelsize * (pie_radius_internal + U.pie_menu_confirm + 7.0f);
|
||||
|
||||
glColor4ub(btheme->tui.wcol_pie_menu.text_sel[0], btheme->tui.wcol_pie_menu.text_sel[1], btheme->tui.wcol_pie_menu.text_sel[2], 64);
|
||||
draw_disk_shaded(angle - range / 2.0f, range, pie_confirm_radius, pie_confirm_external, subd, NULL, NULL, false);
|
||||
const char col[4] = {btheme->tui.wcol_pie_menu.text_sel[0],
|
||||
btheme->tui.wcol_pie_menu.text_sel[1],
|
||||
btheme->tui.wcol_pie_menu.text_sel[2],
|
||||
64};
|
||||
|
||||
draw_disk_shaded(angle - range / 2.0f, range, pie_confirm_radius, pie_confirm_external, subd, col, NULL, false);
|
||||
}
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
glPopMatrix();
|
||||
gpuPopMatrix();
|
||||
gpuMatrixEnd();
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue