Add zbrush like slider control
parent
9736aaf5e6
commit
ffeaeb0725
12
src/editor.c
12
src/editor.c
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
#define ED_SIDEBAR_WIDTH 400
|
#define ED_SIDEBAR_WIDTH 400
|
||||||
#define ED_SPACING 10
|
#define ED_SPACING 10
|
||||||
|
#define ED_MARGIN 20
|
||||||
|
|
||||||
#define ED_MENU_HEIGHT ((float)glwImLineHeight(win))
|
#define ED_MENU_HEIGHT ((float)glwImLineHeight(win))
|
||||||
|
|
||||||
|
@ -34,6 +35,9 @@
|
||||||
|
|
||||||
#define ED_BONE_COLOR 0xffff00
|
#define ED_BONE_COLOR 0xffff00
|
||||||
|
|
||||||
|
#define ED_MIN_BALL_RADIUS 0.1
|
||||||
|
#define ED_MAX_BALL_RADIUS 30
|
||||||
|
|
||||||
typedef struct editor {
|
typedef struct editor {
|
||||||
glwWin *win;
|
glwWin *win;
|
||||||
float cameraAngleX;
|
float cameraAngleX;
|
||||||
|
@ -54,6 +58,7 @@ typedef struct editor {
|
||||||
int moveMouseY;
|
int moveMouseY;
|
||||||
bmesh *bm;
|
bmesh *bm;
|
||||||
skeleton *skl;
|
skeleton *skl;
|
||||||
|
float ballRadius;
|
||||||
} editor;
|
} editor;
|
||||||
|
|
||||||
#include "../data/bmesh_test_2.h"
|
#include "../data/bmesh_test_2.h"
|
||||||
|
@ -145,6 +150,13 @@ static void display(glwWin *win) {
|
||||||
glwImTabBox(win, GEN_ID, ED_SPACING / 2, ED_TOPBAR_HEIGHT, ED_SIDEBAR_WIDTH,
|
glwImTabBox(win, GEN_ID, ED_SPACING / 2, ED_TOPBAR_HEIGHT, ED_SIDEBAR_WIDTH,
|
||||||
ed->height - ED_TOPBAR_HEIGHT - ED_SPACING / 2,
|
ed->height - ED_TOPBAR_HEIGHT - ED_SPACING / 2,
|
||||||
titles, icons, 0);
|
titles, icons, 0);
|
||||||
|
ed->ballRadius = glwImSlider(win, GEN_ID, glwImNextX(win) + ED_MARGIN,
|
||||||
|
glwImNextY(win) + ED_MARGIN,
|
||||||
|
ED_SIDEBAR_WIDTH - ED_MARGIN * 2,
|
||||||
|
ED_MIN_BALL_RADIUS, ED_MAX_BALL_RADIUS,
|
||||||
|
ed->ballRadius,
|
||||||
|
"Radius: %.4f",
|
||||||
|
ed->ballRadius);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
60
src/glw.c
60
src/glw.c
|
@ -2,6 +2,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include <CoreFoundation/CoreFoundation.h>
|
#include <CoreFoundation/CoreFoundation.h>
|
||||||
#include "glw_internal.h"
|
#include "glw_internal.h"
|
||||||
#include "glw_style.h"
|
#include "glw_style.h"
|
||||||
|
@ -102,8 +103,8 @@ void glwMouseEvent(glwWin *win, int button, int state, int x, int y) {
|
||||||
|
|
||||||
int glwPointTest(int x, int y, int left, int top, int width, int height,
|
int glwPointTest(int x, int y, int left, int top, int width, int height,
|
||||||
int allowOffset) {
|
int allowOffset) {
|
||||||
int right = left + width - 1 + allowOffset;
|
int right = left + width + allowOffset;
|
||||||
int bottom = top + height - 1 + allowOffset;
|
int bottom = top + height + 5 + allowOffset;
|
||||||
left -= allowOffset;
|
left -= allowOffset;
|
||||||
top -= allowOffset;
|
top -= allowOffset;
|
||||||
return x >= left && x <= right && y >= top && y <= bottom;
|
return x >= left && x <= right && y >= top && y <= bottom;
|
||||||
|
@ -903,3 +904,58 @@ int glwImMenu(glwWin *win, int id, int x, int y, int width, int height,
|
||||||
imGUI->nextY = y + height;
|
imGUI->nextY = y + height;
|
||||||
return sel;
|
return sel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void glwDrawGradientLine(int x, int y, int width, int height,
|
||||||
|
unsigned int beginColor, unsigned int endColor) {
|
||||||
|
glLineWidth(height);
|
||||||
|
glBegin(GL_LINES);
|
||||||
|
glColor3f(glwR(beginColor), glwG(beginColor), glwB(beginColor));
|
||||||
|
glVertex2f(x, y);
|
||||||
|
glColor3f(glwR(endColor), glwG(endColor), glwB(endColor));
|
||||||
|
glVertex2f(x + width, y);
|
||||||
|
glEnd();
|
||||||
|
glLineWidth(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
float glwImSlider(glwWin *win, int id, int x, int y, int width,
|
||||||
|
float min, float max, float cur, char *fmt, ...) {
|
||||||
|
glwImGui *imGUI = glwGetImGUI(win);
|
||||||
|
char text[100];
|
||||||
|
float leftSegLen = width * (cur - min) / max;
|
||||||
|
float thumLeft = x + leftSegLen - (GLW_SLIDER_THUMB_WIDTH / 2);
|
||||||
|
float thumTop = y + glwGetLineHeight(win) - (GLW_SLIDER_THUMB_HEIGHT / 2);
|
||||||
|
unsigned int topColor = 0;
|
||||||
|
unsigned int bottomColor = 0;
|
||||||
|
va_list args;
|
||||||
|
va_start(args, fmt);
|
||||||
|
vsnprintf(text, sizeof(text), fmt, args);
|
||||||
|
glwImGUIActiveIdCheck(imGUI, id, thumLeft, thumTop,
|
||||||
|
GLW_SLIDER_THUMB_WIDTH, GLW_SLIDER_THUMB_HEIGHT);
|
||||||
|
topColor = GLW_FILL_GRADIENT_COLOR_1_H;
|
||||||
|
bottomColor = GLW_FILL_GRADIENT_COLOR_2_H;
|
||||||
|
if (imGUI->activeId == id) {
|
||||||
|
float mouseFromLeft = (float)glwMouseX(win) - x;
|
||||||
|
glwSwapColor(topColor, bottomColor);
|
||||||
|
cur = min + (max - min) * mouseFromLeft / width;
|
||||||
|
}
|
||||||
|
if (cur < min) {
|
||||||
|
cur = min;
|
||||||
|
} else if (cur > max) {
|
||||||
|
cur = max;
|
||||||
|
}
|
||||||
|
glwDrawSystemText(win, x, y, text, GLW_SYSTEM_FONT_COLOR);
|
||||||
|
glwDrawGradientLine(x, y + glwGetLineHeight(win), leftSegLen,
|
||||||
|
GLW_SLIDER_HEIGHT,
|
||||||
|
GLW_TOOLBAR_BACKGROUND_COLOR, 0x4d4d4d);
|
||||||
|
glwDrawGradientLine(x + leftSegLen, y + glwGetLineHeight(win),
|
||||||
|
width - leftSegLen, GLW_SLIDER_HEIGHT,
|
||||||
|
0x4d4d4d, GLW_TOOLBAR_BACKGROUND_COLOR);
|
||||||
|
glwDrawRoundedRectGradientFill(thumLeft, thumTop,
|
||||||
|
GLW_SLIDER_THUMB_WIDTH, GLW_SLIDER_THUMB_HEIGHT,
|
||||||
|
GLW_SLIDER_CORNER_RADIUS,
|
||||||
|
topColor, bottomColor);
|
||||||
|
glwDrawRoundedRectBorder(thumLeft, thumTop,
|
||||||
|
GLW_SLIDER_THUMB_WIDTH, GLW_SLIDER_THUMB_HEIGHT,
|
||||||
|
GLW_SLIDER_CORNER_RADIUS, GLW_BORDER_COLOR_2);
|
||||||
|
return cur;
|
||||||
|
}
|
||||||
|
|
|
@ -67,6 +67,8 @@ int glwMouseX(glwWin *win);
|
||||||
int glwMouseY(glwWin *win);
|
int glwMouseY(glwWin *win);
|
||||||
int glwImMenu(glwWin *win, int id, int x, int y, int width, int height,
|
int glwImMenu(glwWin *win, int id, int x, int y, int width, int height,
|
||||||
char **titles, int sel);
|
char **titles, int sel);
|
||||||
|
float glwImSlider(glwWin *win, int id, int x, int y, int width,
|
||||||
|
float min, float max, float cur, char *fmt, ...);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,4 +40,10 @@
|
||||||
|
|
||||||
#define GLW_MENU_BACKGROUND_COLOR 0x181818
|
#define GLW_MENU_BACKGROUND_COLOR 0x181818
|
||||||
|
|
||||||
|
#define GLW_SLIDER_THUMB_WIDTH 20
|
||||||
|
#define GLW_SLIDER_THUMB_HEIGHT 12
|
||||||
|
#define GLW_SLIDER_HEIGHT 2
|
||||||
|
|
||||||
|
#define GLW_SLIDER_CORNER_RADIUS 3
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue