diff --git a/src/editor.c b/src/editor.c index ccf6efa1..c99f095a 100644 --- a/src/editor.c +++ b/src/editor.c @@ -23,6 +23,7 @@ #define ED_SIDEBAR_WIDTH 400 #define ED_SPACING 10 +#define ED_MARGIN 20 #define ED_MENU_HEIGHT ((float)glwImLineHeight(win)) @@ -34,6 +35,9 @@ #define ED_BONE_COLOR 0xffff00 +#define ED_MIN_BALL_RADIUS 0.1 +#define ED_MAX_BALL_RADIUS 30 + typedef struct editor { glwWin *win; float cameraAngleX; @@ -54,6 +58,7 @@ typedef struct editor { int moveMouseY; bmesh *bm; skeleton *skl; + float ballRadius; } editor; #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, ed->height - ED_TOPBAR_HEIGHT - ED_SPACING / 2, 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); } { diff --git a/src/glw.c b/src/glw.c index efcde223..dcb5f939 100644 --- a/src/glw.c +++ b/src/glw.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include "glw_internal.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 allowOffset) { - int right = left + width - 1 + allowOffset; - int bottom = top + height - 1 + allowOffset; + int right = left + width + allowOffset; + int bottom = top + height + 5 + allowOffset; left -= allowOffset; top -= allowOffset; 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; 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; +} diff --git a/src/glw.h b/src/glw.h index 4d10d1ba..f094ef19 100644 --- a/src/glw.h +++ b/src/glw.h @@ -67,6 +67,8 @@ int glwMouseX(glwWin *win); int glwMouseY(glwWin *win); int glwImMenu(glwWin *win, int id, int x, int y, int width, int height, 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 } diff --git a/src/glw_style.h b/src/glw_style.h index 3877a1b7..8cce5d00 100644 --- a/src/glw_style.h +++ b/src/glw_style.h @@ -40,4 +40,10 @@ #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