[Bf-blender-cvs] [db5e89a] temp-ui-widget-refactor: Initial refactor of interface widget architecture
Julian Eisel
noreply at git.blender.org
Thu Jul 9 01:16:43 CEST 2015
Commit: db5e89ad5c020bffc3bcc074fd5284772c6b03a2
Author: Julian Eisel
Date: Thu Jul 9 00:50:37 2015 +0200
Branches: temp-ui-widget-refactor
https://developer.blender.org/rBdb5e89ad5c020bffc3bcc074fd5284772c6b03a2
Initial refactor of interface widget architecture
Initial refactor of interface widget architecture towards the following goals:
* Widget Draw Styles (see T45025 - heavily overlaps with this)
* Isolating widget code to make it more future proof
* Adding callback based widgets handling module (currently handled in interface_handler.c)
Adds the following folders/files:
interface/widgets/
interface/widgets/widgets.c
interface/widgets/widgets.h
interface/widgets/widgets_draw/
interface/widgets/widgets_draw/drawstyle_classic.c
interface/widgets/widgets_draw/widgets_draw.c
interface/widgets/widgets_draw/widgets_draw_intern.h
Not sure if editors/interface/ is the right place for this, but depends on some further decisions.
===================================================================
M source/blender/editors/interface/CMakeLists.txt
M source/blender/editors/interface/interface_widgets.c
A source/blender/editors/interface/widgets/widgets.c
A source/blender/editors/interface/widgets/widgets.h
A source/blender/editors/interface/widgets/widgets_draw/drawstyle_classic.c
A source/blender/editors/interface/widgets/widgets_draw/widgets_draw.c
A source/blender/editors/interface/widgets/widgets_draw/widgets_draw_intern.h
===================================================================
diff --git a/source/blender/editors/interface/CMakeLists.txt b/source/blender/editors/interface/CMakeLists.txt
index 972eca7..356c071 100644
--- a/source/blender/editors/interface/CMakeLists.txt
+++ b/source/blender/editors/interface/CMakeLists.txt
@@ -19,6 +19,8 @@
# ***** END GPL LICENSE BLOCK *****
set(INC
+ widgets
+ widgets/widgets_draw
../include
../../blenfont
../../blenkernel
@@ -55,8 +57,13 @@ set(SRC
resources.c
view2d.c
view2d_ops.c
+ widgets/widgets.c
+ widgets/widgets_draw/drawstyle_classic.c
+ widgets/widgets_draw/widgets_draw.c
interface_intern.h
+ widgets/widgets.h
+ widgets/widgets_draw/widgets_draw_intern.h
)
if(WITH_INTERNATIONAL)
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 253f461..659d0d7 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -55,6 +55,8 @@
#include "UI_interface.h"
#include "UI_interface_icons.h"
+#include "widgets.h"
+
#include "interface_intern.h"
#ifdef WITH_INPUT_IME
@@ -64,54 +66,10 @@
/* icons are 80% of height of button (16 pixels inside 20 height) */
#define ICON_SIZE_FROM_BUTRECT(rect) (0.8f * BLI_rcti_size_y(rect))
-/* ************** widget base functions ************** */
-/**
- * - in: roundbox codes for corner types and radius
- * - return: array of `[size][2][x, y]` points, the edges of the roundbox, + UV coords
- *
- * - draw black box with alpha 0 on exact button boundbox
- * - for every AA step:
- * - draw the inner part for a round filled box, with color blend codes or texture coords
- * - draw outline in outline color
- * - draw outer part, bottom half, extruded 1 pixel to bottom, for emboss shadow
- * - draw extra decorations
- * - draw background color box with alpha 1 on exact button boundbox
- */
-
-/* fill this struct with polygon info to draw AA'ed */
-/* it has outline, back, and two optional tria meshes */
-
-typedef struct uiWidgetTrias {
- unsigned int tot;
-
- float vec[16][2];
- const unsigned int (*index)[3];
-
-} uiWidgetTrias;
-
-/* max as used by round_box__edges */
-#define WIDGET_CURVE_RESOLU 9
-#define WIDGET_SIZE_MAX (WIDGET_CURVE_RESOLU * 4)
-
-typedef struct uiWidgetBase {
-
- int totvert, halfwayvert;
- float outer_v[WIDGET_SIZE_MAX][2];
- float inner_v[WIDGET_SIZE_MAX][2];
- float inner_uv[WIDGET_SIZE_MAX][2];
-
- bool draw_inner, draw_outline, draw_emboss, draw_shadedir;
-
- uiWidgetTrias tria1;
- uiWidgetTrias tria2;
-
-} uiWidgetBase;
-
/** uiWidgetType: for time being only for visual appearance,
* later, a handling callback can be added too
*/
typedef struct uiWidgetType {
-
/* pointer to theme color definition */
uiWidgetColors *wcol_theme;
uiWidgetStateColors *wcol_state;
@@ -119,6 +77,8 @@ typedef struct uiWidgetType {
/* converted colors for state */
uiWidgetColors wcol;
+ uiWidgetDrawType *draw_type;
+
void (*state)(struct uiWidgetType *, int state);
void (*draw)(uiWidgetColors *, rcti *, int state, int roundboxalign);
void (*custom)(uiBut *, uiWidgetColors *, rcti *, int state, int roundboxalign);
@@ -322,162 +282,6 @@ static int round_box_shadow_edges(float (*vert)[2], const rcti *rect, float rad,
return tot;
}
-/* this call has 1 extra arg to allow mask outline */
-static void round_box__edges(uiWidgetBase *wt, int roundboxalign, const rcti *rect, float rad, float radi)
-{
- float vec[WIDGET_CURVE_RESOLU][2], veci[WIDGET_CURVE_RESOLU][2];
- float minx = rect->xmin, miny = rect->ymin, maxx = rect->xmax, maxy = rect->ymax;
- float minxi = minx + U.pixelsize; /* boundbox inner */
- float maxxi = maxx - U.pixelsize;
- float minyi = miny + U.pixelsize;
- float maxyi = maxy - U.pixelsize;
- float facxi = (maxxi != minxi) ? 1.0f / (maxxi - minxi) : 0.0f; /* for uv, can divide by zero */
- float facyi = (maxyi != minyi) ? 1.0f / (maxyi - minyi) : 0.0f;
- int a, tot = 0, minsize;
- const int hnum = ((roundboxalign & (UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT)) == (UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT) ||
- (roundboxalign & (UI_CNR_BOTTOM_RIGHT | UI_CNR_BOTTOM_LEFT)) == (UI_CNR_BOTTOM_RIGHT | UI_CNR_BOTTOM_LEFT)) ? 1 : 2;
- const int vnum = ((roundboxalign & (UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT)) == (UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT) ||
- (roundboxalign & (UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT)) == (UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT)) ? 1 : 2;
-
- minsize = min_ii(BLI_rcti_size_x(rect) * hnum,
- BLI_rcti_size_y(rect) * vnum);
-
- if (2.0f * rad > minsize)
- rad = 0.5f * minsize;
-
- if (2.0f * (radi + 1.0f) > minsize)
- radi = 0.5f * minsize - U.pixelsize;
-
- /* mult */
- for (a = 0; a < WIDGET_CURVE_RESOLU; a++) {
- veci[a][0] = radi * cornervec[a][0];
- veci[a][1] = radi * cornervec[a][1];
- vec[a][0] = rad * cornervec[a][0];
- vec[a][1] = rad * cornervec[a][1];
- }
-
- /* corner left-bottom */
- if (roundboxalign & UI_CNR_BOTTOM_LEFT) {
-
- for (a = 0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
- wt->inner_v[tot][0] = minxi + veci[a][1];
- wt->inner_v[tot][1] = minyi + radi - veci[a][0];
-
- wt->outer_v[tot][0] = minx + vec[a][1];
- wt->outer_v[tot][1] = miny + rad - vec[a][0];
-
- wt->inner_uv[tot][0] = facxi * (wt->inner_v[tot][0] - minxi);
- wt->inner_uv[tot][1] = facyi * (wt->inner_v[tot][1] - minyi);
- }
- }
- else {
- wt->inner_v[tot][0] = minxi;
- wt->inner_v[tot][1] = minyi;
-
- wt->outer_v[tot][0] = minx;
- wt->outer_v[tot][1] = miny;
-
- wt->inner_uv[tot][0] = 0.0f;
- wt->inner_uv[tot][1] = 0.0f;
-
- tot++;
- }
-
- /* corner right-bottom */
- if (roundboxalign & UI_CNR_BOTTOM_RIGHT) {
-
- for (a = 0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
- wt->inner_v[tot][0] = maxxi - radi + veci[a][0];
- wt->inner_v[tot][1] = minyi + veci[a][1];
-
- wt->outer_v[tot][0] = maxx - rad + vec[a][0];
- wt->outer_v[tot][1] = miny + vec[a][1];
-
- wt->inner_uv[tot][0] = facxi * (wt->inner_v[tot][0] - minxi);
- wt->inner_uv[tot][1] = facyi * (wt->inner_v[tot][1] - minyi);
- }
- }
- else {
- wt->inner_v[tot][0] = maxxi;
- wt->inner_v[tot][1] = minyi;
-
- wt->outer_v[tot][0] = maxx;
- wt->outer_v[tot][1] = miny;
-
- wt->inner_uv[tot][0] = 1.0f;
- wt->inner_uv[tot][1] = 0.0f;
-
- tot++;
- }
-
- wt->halfwayvert = tot;
-
- /* corner right-top */
- if (roundboxalign & UI_CNR_TOP_RIGHT) {
-
- for (a = 0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
- wt->inner_v[tot][0] = maxxi - veci[a][1];
- wt->inner_v[tot][1] = maxyi - radi + veci[a][0];
-
- wt->outer_v[tot][0] = maxx - vec[a][1];
- wt->outer_v[tot][1] = maxy - rad + vec[a][0];
-
- wt->inner_uv[tot][0] = facxi * (wt->inner_v[tot][0] - minxi);
- wt->inner_uv[tot][1] = facyi * (wt->inner_v[tot][1] - minyi);
- }
- }
- else {
- wt->inner_v[tot][0] = maxxi;
- wt->inner_v[tot][1] = maxyi;
-
- wt->outer_v[tot][0] = maxx;
- wt->outer_v[tot][1] = maxy;
-
- wt->inner_uv[tot][0] = 1.0f;
- wt->inner_uv[tot][1] = 1.0f;
-
- tot++;
- }
-
- /* corner left-top */
- if (roundboxalign & UI_CNR_TOP_LEFT) {
-
- for (a = 0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
- wt->inner_v[tot][0] = minxi + radi - veci[a][0];
- wt->inner_v[tot][1] = maxyi - veci[a][1];
-
- wt->outer_v[tot][0] = minx + rad - vec[a][0];
- wt->outer_v[tot][1] = maxy - vec[a][1];
-
- wt->inner_uv[tot][0] = facxi * (wt->inner_v[tot][0] - minxi);
- wt->inner_uv[tot][1] = facyi * (wt->inner_v[tot][1] - minyi);
- }
-
- }
- else {
-
- wt->inner_v[tot][0] = minxi;
- wt->inner_v[tot][1] = maxyi;
-
- wt->outer_v[tot][0] = minx;
- wt->outer_v[tot][1] = maxy;
-
- wt->inner_uv[tot][0] = 0.0f;
- wt->inner_uv[tot][1] = 1.0f;
-
- tot++;
- }
-
- BLI_assert(tot <= WIDGET_SIZE_MAX);
-
- wt->totvert = tot;
-}
-
-static void round_box_edges(uiWidgetBase *wt, int roundboxalign, const rcti *rect, float rad)
-{
- round_box__edges(wt, roundboxalign, rect, rad, rad - U.pixelsize);
-}
-
/* based on button rect, return scaled array of triangles */
static void widget_draw_tria_ex(
@@ -535,14 +339,6 @@ 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)
-{
- 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);
-}
-
static void widget_menu_trias(uiWidgetTrias *tria, const rcti *rect)
{
float centx, centy, size;
@@ -618,17 +414,6 @@ static void widget_verts_to_triangle_strip(uiWidgetBase *wtb, const int totvert,
copy_v2_v2(triangle_strip[a * 2 + 1], wtb->inner_v[0]);
}
-static void widget_verts_to_triangle_strip_open(uiWidgetBase *wtb, const int totvert, float triangle_strip[WIDGET_SIZE_MAX * 2][2])
-{
- int a;
- for (a = 0; a < totvert; a++) {
- triangle_strip[a * 2][0] = wtb->outer_v[a][0];
- triangle_strip[a * 2][1] = wtb->outer_v[a][1];
- triangle_strip[a * 2 + 1][0] = wtb->outer_v[a][0];
- triangle_strip[a * 2 + 1][1] = wtb->outer_v[a][1] - 1.0f;
- }
-}
-
static void widgetbase_outline(uiWidgetBase *wtb)
{
float triangle_strip[WIDGET_SIZE_MAX * 2 + 2][2]; /* + 2 because the last pair is wrapped */
@@ -640,167 +425,6 @@ static void widgetbase_outline(uiWidgetBase *wtb)
glDisableClientState(GL_VERTEX_ARRAY);
}
-static void widgetbase_draw(uiWidgetBase *wtb, uiWidgetColors *wcol)
-{
- int j, a;
-
- glEnable(GL_BLEND);
-
- /* backdrop non AA */
- if (wtb->draw_inner) {
- if (wcol->shaded == 0) {
- if (wcol->alpha_check) {
- 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);
-
- /* light checkers */
- glEnable(GL_POLYGON_STIPPLE);
- glColor4ub(UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT, 255);
- glPolygonSt
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list