Add new color theme.

master
Jeremy Hu 2017-02-12 23:28:45 +09:30
parent 0a426f981b
commit 9736aaf5e6
4 changed files with 185 additions and 77 deletions

View File

@ -19,15 +19,18 @@
#define ED_MODE_EDIT 0
#define ED_MODE_ANIMATION 1
#define ED_BACKGROUND_COLOR 0x141414
#define ED_BACKGROUND_COLOR 0x141414 //0x111111
#define ED_SIDEBAR_WIDTH 400
#define ED_SPACING 10
#define ED_TOPBAR_HEIGHT 100
#define ED_TOOLBAR_HEIGHT (glwImLineHeight(win) * 1.2)
#define ED_MENU_HEIGHT ((float)glwImLineHeight(win))
#define ED_GL_BACKGROUND_COLOR GLW_BACKGROUND_COLOR
#define ED_TOPBAR_HEIGHT (ED_MENU_HEIGHT + ED_SPACING + glwImLineHeight(win) + ED_SPACING)
#define ED_TOOLBAR_HEIGHT ((float)glwImLineHeight(win) * 1.2)
#define ED_GL_BACKGROUND_COLOR 0x242424
#define ED_GL_BORDER_SIZE 7
#define ED_BONE_COLOR 0xffff00
@ -36,7 +39,7 @@ typedef struct editor {
float cameraAngleX;
float cameraAngleY;
float cameraDistance;
int newImId;
int selectedMenu;
int showBoneChecked;
int showBallChecked;
int showMeshChecked;
@ -103,12 +106,41 @@ static void display(glwWin *win) {
glLoadIdentity();
{
char *list[] = {"Open..", "New..", "Save As..", 0};
glwImButtonGroup(win, GEN_ID, 100, 30, 300, list, -1);
char *titles[] = {"File", "Window", "Help", 0};
ed->selectedMenu = glwImMenu(win, GEN_ID, 0, 0, ed->width,
glwImLineHeight(win), titles, ed->selectedMenu);
}
{
char *titles[] = {"Tool", 0};
char *titles[] = {"New..", "Open..", "Save As..", "Save", 0};
int icons[] = {ICON_FILE, 0, 0, 0, 0};
glwImButtonGroup(win, GEN_ID, ED_SPACING / 2,
ED_TOPBAR_HEIGHT - ED_SPACING - glwImLineHeight(win), titles, icons, 3);
}
{
char *titles[] = {"Add Ball", 0};
int icons[] = {ICON_PLUS, 0};
glwImButtonGroup(win, GEN_ID, glwImNextX(win) + ED_SPACING,
glwImNextY(win), titles, icons, 0);
}
{
char *titles[] = {"Del Ball", "Del All", 0};
int icons[] = {ICON_TRASH, 0, 0};
glwImButtonGroup(win, GEN_ID, glwImNextX(win) + ED_SPACING,
glwImNextY(win), titles, icons, -1);
}
{
char *titles[] = {"Start", "Pause", "Stop", 0};
int icons[] = {ICON_PLAY, ICON_PAUSE, ICON_STOP, 0};
glwImButtonGroup(win, GEN_ID, glwImNextX(win) + ED_SPACING,
glwImNextY(win), titles, icons, -1);
}
{
char *titles[] = {"Property", 0};
int icons[] = {ICON_TOOL, 0};
glwImTabBox(win, GEN_ID, ED_SPACING / 2, ED_TOPBAR_HEIGHT, ED_SIDEBAR_WIDTH,
ed->height - ED_TOPBAR_HEIGHT - ED_SPACING / 2,
@ -120,34 +152,36 @@ static void display(glwWin *win) {
int y = ED_TOPBAR_HEIGHT;
int width = ed->width - ED_SIDEBAR_WIDTH - ED_SPACING / 2 - ED_SPACING - ED_SPACING / 2;
int height = ed->height - ED_TOPBAR_HEIGHT - ED_SPACING / 2;
char *titles[] = {"Skeleton", "Animation", "Config", 0};
int icons[] = {ICON_MONITOR, ICON_PENCIL, ICON_EYE, 0};
char *titles[] = {"Model", 0};
int icons[] = {ICON_MONITOR, 0};
ed->mode = glwImTabBox(win, GEN_ID,
x, y, width, height,
titles, icons, ed->mode);
if (ED_MODE_EDIT == ed->mode) {
int toolBarY = glwImNextY(win) - 1;
int glWinY = toolBarY + ED_TOOLBAR_HEIGHT;
int toolBarContentY = toolBarY +
(ED_TOOLBAR_HEIGHT - glwImLineHeight(win));
glwImToolBar(win, GEN_ID, x, toolBarY, width, ED_TOOLBAR_HEIGHT);
ed->showBallChecked = glwImCheck(win, GEN_ID, x + ED_SPACING + ED_SPACING,
toolBarY + (ED_TOOLBAR_HEIGHT - glwImLineHeight(win)) / 2 + 2,
toolBarContentY,
"Ball",
ed->showBallChecked);
ed->showBoneChecked = glwImCheck(win, GEN_ID,
glwImNextX(win) + ED_SPACING,
toolBarY + (ED_TOOLBAR_HEIGHT - glwImLineHeight(win)) / 2 + 2,
toolBarContentY,
"Bone",
ed->showBoneChecked);
ed->showMeshChecked = glwImCheck(win, GEN_ID,
glwImNextX(win) + ED_SPACING,
toolBarY + (ED_TOOLBAR_HEIGHT - glwImLineHeight(win)) / 2 + 2,
toolBarContentY,
"Mesh",
ed->showMeshChecked);
ed->renderLeft = x + 1;
ed->renderTop = glWinY;
ed->renderWidth = width - 3;
ed->renderHeight = height - ED_TOOLBAR_HEIGHT;
ed->renderLeft = x + 1 + ED_GL_BORDER_SIZE;
ed->renderTop = glWinY + ED_GL_BORDER_SIZE;
ed->renderWidth = width - 3 - ED_GL_BORDER_SIZE * 2;
ed->renderHeight = height - (glWinY - y) - 3 - ED_GL_BORDER_SIZE * 2;
if (0 == ed->skl) {
ed->skl = skeletonCreate();
@ -179,17 +213,19 @@ static void display(glwWin *win) {
bmeshGenerate(ed->bm);
}
glEnable(GL_SCISSOR_TEST);
glScissor(ed->renderLeft, ED_SPACING / 2 + 1,
ed->renderWidth, ed->renderHeight);
glPushMatrix();
glTranslatef(ed->renderLeft, ed->renderTop, 0);
/*
glColor3f(glwR(ED_GL_BACKGROUND_COLOR),
glwG(ED_GL_BACKGROUND_COLOR),
glwB(ED_GL_BACKGROUND_COLOR));
glRecti(0, 0, ed->renderWidth, ed->renderHeight);*/
glRecti(ed->renderLeft,
ed->renderTop,
ed->renderLeft + ed->renderWidth,
ed->renderTop + ed->renderHeight);
glEnable(GL_SCISSOR_TEST);
glScissor(ed->renderLeft, ed->height - (ed->renderTop + ed->renderHeight),
ed->renderWidth, ed->renderHeight);
glPushMatrix();
glTranslatef(ed->renderLeft, ed->renderTop, 0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
@ -302,6 +338,7 @@ int main(int argc, char *argv[]) {
ed.cameraAngleY = -312;
ed.cameraDistance = 14.4;
ed.showMeshChecked = 1;
ed.selectedMenu = -1;
ed.win = glwCreateWindow(0, 0, 600, 480);
glwSetUserData(ed.win, &ed);

154
src/glw.c
View File

@ -12,6 +12,12 @@
#define M_PI 3.14159265
#endif
#define glwSwapColor(color1, color2) do {\
unsigned int tmp = color1;\
color1 = color2;\
color2 = tmp;\
} while (0)
void glwDrawSystemText(glwWin *win, int x, int y, char *text,
unsigned int color) {
int vleft, vwidth;
@ -478,26 +484,37 @@ void glwDrawRoundedRectGradientFill(float x, float y, float width, float height,
glEnd();
}
void glwDrawButtonBackground(float x, float y, float width, float height,
glwCtrlState state) {
static void glwDrawGradientBackground(float x, float y, float width, float height,
glwCtrlState state, int sunken) {
unsigned int topColor = 0;
unsigned int bottomColor = 0;
switch (state)
{
case GLW_CTRL_STATE_PRESS:
glwDrawRoundedRectGradientFill(x, y, width, height,
GLW_BUTTON_CORNER_RADIUS,
GLW_FILL_GRADIENT_COLOR_1_H, GLW_FILL_GRADIENT_COLOR_2_H);
topColor = GLW_FILL_GRADIENT_COLOR_1_H;
bottomColor = GLW_FILL_GRADIENT_COLOR_2_H;
break;
case GLW_CTRL_STATE_NORMAL:
default:
glwDrawRoundedRectGradientFill(x, y, width, height,
GLW_BUTTON_CORNER_RADIUS,
GLW_FILL_GRADIENT_COLOR_1, GLW_FILL_GRADIENT_COLOR_2);
topColor = GLW_FILL_GRADIENT_COLOR_1;
bottomColor = GLW_FILL_GRADIENT_COLOR_2;
break;
}
if (sunken) {
glwSwapColor(topColor, bottomColor);
}
glwDrawRoundedRectGradientFill(x, y, width, height,
GLW_BUTTON_CORNER_RADIUS,
topColor, bottomColor);
glwDrawRoundedRectBorder(x, y, width, height,
GLW_BUTTON_CORNER_RADIUS, GLW_BORDER_COLOR_2);
}
void glwDrawButtonBackground(float x, float y, float width, float height,
glwCtrlState state) {
glwDrawGradientBackground(x, y, width, height, state, 0);
}
glwSize glwMeasureSystemText(glwWin *win, char *text) {
glwSystemFontTexture *systemFontTexture = glwGetSystemFontTexture(win);
glwSize size = {0, systemFontTexture->originSize.height};
@ -528,7 +545,7 @@ static void glwImGUIActiveIdCheck(glwImGui *imGUI, int id, int x, int y,
}
}
int glwImButton(glwWin *win, int id, int x, int y, char *text) {
int glwImButton(glwWin *win, int id, int x, int y, char *text, int icon) {
glwImGui *imGUI = glwGetImGUI(win);
glwSize textSize = glwMeasureSystemText(win, text);
int width = textSize.width * (1 + GLW_HOR_AUTO_MARGIN * 2);
@ -544,6 +561,30 @@ int glwImButton(glwWin *win, int id, int x, int y, char *text) {
return imGUI->activeId == id;
}
static glwSize glwMeasureLabel(glwWin *win, char *text, int icon) {
glwSize size = glwMeasureSystemText(win, text);
int padding = glwGetLineHeight(win) / 2;
size.width += padding + padding + padding;
return size;
}
static void glwDrawLabel(glwWin *win, int x, int y, char *text, int icon,
unsigned int color) {
int lineHeight = glwGetLineHeight(win);
int padding = glwGetLineHeight(win) / 2;
if (icon) {
int iconIdx = icon - 1;
glwDrawSystemIcon(win, x + padding,
y + lineHeight * GLW_VER_AUTO_MARGIN, icon, color);
glwDrawSystemText(win, x + padding +
iconTable[iconIdx][ICON_ITEM_ORIGINAL_WIDTH] + padding / 2,
y + lineHeight * GLW_VER_AUTO_MARGIN, text, color);
} else {
glwDrawSystemText(win, x + padding,
y + lineHeight * GLW_VER_AUTO_MARGIN, text, color);
}
}
int glwImDropdownBox(glwWin *win, int id, int x, int y, char *text) {
glwImGui *imGUI = glwGetImGUI(win);
glwSize textSize = glwMeasureSystemText(win, text);
@ -569,14 +610,16 @@ int glwImCheck(glwWin *win, int id, int x, int y, char *text, int checked) {
glwImGui *imGUI = glwGetImGUI(win);
glwSize textSize = glwMeasureSystemText(win, text);
int height = textSize.height;
int boxWidth = height;
int boxWidth = height * 0.8;
int boxHeight = boxWidth;
int width = boxWidth + textSize.height * (1 + GLW_HOR_AUTO_MARGIN * 2) +
textSize.width;
int oldActiveId = imGUI->activeId;
glwImGUIActiveIdCheck(imGUI, id, x, y, width, height);
glwDrawButtonBackground(x, y, boxWidth, height,
glwDrawGradientBackground(x, y + (height - boxHeight) / 2,
boxWidth, boxHeight,
(imGUI->activeId == id || checked) ?
GLW_CTRL_STATE_PRESS : GLW_CTRL_STATE_NORMAL);
GLW_CTRL_STATE_PRESS : GLW_CTRL_STATE_NORMAL, 1);
glwDrawSystemText(win, x + textSize.height * GLW_HOR_AUTO_MARGIN + boxWidth,
y, text, GLW_SYSTEM_FONT_COLOR);
if (checked) {
@ -594,8 +637,8 @@ static int glwCalcListMaxWidth(glwWin *win, char **titles, int *icons,
int maxItemWidth = 0;
for (i = 0; titles[i]; ++i) {
glwSize textSize = glwMeasureSystemText(win, titles[i]);
itemWidth = textSize.width * (1 + GLW_HOR_AUTO_MARGIN * 2);
glwSize textSize = glwMeasureLabel(win, titles[i], icons ? icons[i] : 0);
itemWidth = textSize.width;
if (icons && icons[i]) {
itemWidth += iconTable[icons[i]][ICON_ITEM_ORIGINAL_WIDTH];
}
@ -610,15 +653,11 @@ static int glwCalcListMaxWidth(glwWin *win, char **titles, int *icons,
}
}
if (maxItemWidth < GLW_MIN_TAB_WIDTH) {
maxItemWidth = GLW_MIN_TAB_WIDTH;
}
return maxItemWidth;
}
int glwImButtonGroup(glwWin *win, int id, int x, int y, int parentWidth,
char **list, int sel) {
int glwImButtonGroup(glwWin *win, int id, int x, int y, char **titles,
int *icons, int sel) {
glwImGui *imGUI = glwGetImGUI(win);
int width = 0;
int height = 0;
@ -627,16 +666,16 @@ int glwImButtonGroup(glwWin *win, int id, int x, int y, int parentWidth,
int listLen = 0;
int offset;
int maxItemWidth = 0;
maxItemWidth = glwCalcListMaxWidth(win, list, 0, &height, &listLen);
unsigned int topColor = 0;
unsigned int bottomColor = 0;
maxItemWidth = glwCalcListMaxWidth(win, titles, icons, &height, &listLen);
width = maxItemWidth * listLen;
left = listLen > 1 ? x + (parentWidth - width) / 2 :
x + maxItemWidth * GLW_HOR_AUTO_MARGIN;
left = x;
glwImGUIActiveIdCheck(imGUI, id, left, y, width, height);
glwDrawRoundedRectGradientFill(left, y, width, height,
GLW_BUTTON_CORNER_RADIUS,
GLW_FILL_GRADIENT_COLOR_1, GLW_FILL_GRADIENT_COLOR_2);
for (i = 0, offset = left; list[i]; ++i) {
glwSize textSize = glwMeasureSystemText(win, list[i]);
for (i = 0, offset = left; titles[i]; ++i) {
if (imGUI->activeId == id) {
int hit = glwPointTest(imGUI->mouseX, imGUI->mouseY, offset, y,
maxItemWidth, height, 0);
@ -645,33 +684,38 @@ int glwImButtonGroup(glwWin *win, int id, int x, int y, int parentWidth,
}
}
if (sel == i) {
topColor = GLW_FILL_GRADIENT_COLOR_1_H;
bottomColor = GLW_FILL_GRADIENT_COLOR_2_H;
if (imGUI->activeId == id) {
glwSwapColor(topColor, bottomColor);
}
if (1 == listLen) {
glwDrawRoundedRectGradientFill(left, y, width, height,
GLW_BUTTON_CORNER_RADIUS,
GLW_FILL_GRADIENT_COLOR_1_H, GLW_FILL_GRADIENT_COLOR_2_H);
topColor, bottomColor);
} else {
if (0 == i) {
glwDrawLeftRoundedRectGradientFill(offset, y,
maxItemWidth, height,
GLW_BUTTON_CORNER_RADIUS,
GLW_FILL_GRADIENT_COLOR_1_H, GLW_FILL_GRADIENT_COLOR_2_H);
topColor, bottomColor);
} else if (listLen - 1 == i) {
glwDrawRightRoundedRectGradientFill(offset, y,
maxItemWidth, height,
GLW_BUTTON_CORNER_RADIUS,
GLW_FILL_GRADIENT_COLOR_1_H, GLW_FILL_GRADIENT_COLOR_2_H);
topColor, bottomColor);
} else {
glwDrawRectGradientFill(offset, y,
maxItemWidth, height,
GLW_FILL_GRADIENT_COLOR_1_H, GLW_FILL_GRADIENT_COLOR_2_H);
topColor, bottomColor);
}
}
}
if (0 != i) {
glwDrawVLine(offset, y, 1, height, GLW_BORDER_COLOR_2);
}
glwDrawSystemText(win, offset + (maxItemWidth - textSize.width) / 2,
y + height * 0.1, list[i], GLW_SYSTEM_FONT_COLOR);
glwDrawLabel(win, offset, y, titles[i], icons ? icons[i] : 0,
GLW_SYSTEM_FONT_COLOR);
offset += maxItemWidth;
}
imGUI->nextX = offset;
@ -692,6 +736,9 @@ int glwImTabBox(glwWin *win, int id, int x, int y, int width, int height,
int offset;
int maxItemWidth = 0;
maxItemWidth = glwCalcListMaxWidth(win, titles, icons, &tabHeight, &listLen);
if (maxItemWidth < GLW_MIN_TAB_WIDTH) {
maxItemWidth = GLW_MIN_TAB_WIDTH;
}
tabWidth = maxItemWidth * listLen;
left = x;
imGUI->nextX = x;
@ -707,7 +754,6 @@ int glwImTabBox(glwWin *win, int id, int x, int y, int width, int height,
glwDrawVLine(x + width - 1, y + tabHeight, 1, height - tabHeight,
GLW_BORDER_COLOR_1);
for (i = 0, offset = left; titles[i]; ++i) {
glwSize textSize = glwMeasureSystemText(win, titles[i]);
if (imGUI->activeId == id) {
int hit = glwPointTest(imGUI->mouseX, imGUI->mouseY, offset, y,
maxItemWidth, tabHeight, 0);
@ -724,17 +770,8 @@ int glwImTabBox(glwWin *win, int id, int x, int y, int width, int height,
GLW_BUTTON_CORNER_RADIUS,
GLW_TAB_FILL_GRADIENT_COLOR_1, GLW_TAB_FILL_GRADIENT_COLOR_2);
}
if (icons && icons[i]) {
int iconIdx = icons[i] - 1;
glwDrawSystemIcon(win, offset + textSize.height / 2,
y + tabHeight * GLW_VER_AUTO_MARGIN, icons[i], GLW_SYSTEM_FONT_COLOR);
glwDrawSystemText(win, offset + textSize.height / 2 +
iconTable[iconIdx][ICON_ITEM_ORIGINAL_WIDTH] + textSize.height / 2,
y + tabHeight * GLW_VER_AUTO_MARGIN, titles[i], GLW_SYSTEM_FONT_COLOR);
} else {
glwDrawSystemText(win, offset + (maxItemWidth - textSize.width) / 2,
y + tabHeight * GLW_VER_AUTO_MARGIN, titles[i], GLW_SYSTEM_FONT_COLOR);
}
glwDrawLabel(win, offset, y, titles[i], icons ? icons[i] : 0,
GLW_SYSTEM_FONT_COLOR);
offset += maxItemWidth;
}
return sel;
@ -836,4 +873,33 @@ int glwMouseY(glwWin *win) {
return ctx->y;
}
int glwImMenu(glwWin *win, int id, int x, int y, int width, int height,
char **titles, int sel) {
glwImGui *imGUI = glwGetImGUI(win);
int left = 0;
int i;
int listLen = 0;
int offset;
int maxItemWidth = 0;
maxItemWidth = glwCalcListMaxWidth(win, titles, 0, &height, &listLen);
left = x + glwGetLineHeight(win) / 2;
glwImGUIActiveIdCheck(imGUI, id, left, y, width, height);
glwDrawRectGradientFill(x, y, width, height,
GLW_MENU_BACKGROUND_COLOR, GLW_MENU_BACKGROUND_COLOR);
for (i = 0, offset = left; titles[i]; ++i) {
if (imGUI->activeId == id) {
int hit = glwPointTest(imGUI->mouseX, imGUI->mouseY, offset, y,
maxItemWidth, height, 0);
if (hit) {
sel = i;
}
}
glwDrawLabel(win, offset, y, titles[i], 0, sel == i ?
GLW_SYSTEM_FONT_COLOR_H : GLW_SYSTEM_FONT_COLOR);
offset += maxItemWidth;
}
glwDrawHLine(x, y + height - 1, width, 1, GLW_BORDER_COLOR_1);
imGUI->nextX = x;
imGUI->nextY = y + height;
return sel;
}

View File

@ -48,11 +48,11 @@ void glwWheelFunc(glwWin *win, void(*func)(glwWin *win, float delta));
#define glwR(rgb) ((float)(((rgb) >> 16) & 0xff) / 255)
#define glwG(rgb) ((float)(((rgb) >> 8) & 0xff) / 255)
#define glwB(rgb) ((float)(((rgb)) & 0xff) / 255)
int glwImButton(glwWin *win, int id, int x, int y, char *text);
int glwImButton(glwWin *win, int id, int x, int y, char *text, int icon);
int glwImCheck(glwWin *win, int id, int x, int y, char *text, int checked);
int glwImDropdownBox(glwWin *win, int id, int x, int y, char *text);
int glwImButtonGroup(glwWin *win, int id, int x, int y, int parentWidth,
char **list, int sel);
int glwImButtonGroup(glwWin *win, int id, int x, int y, char **titles,
int *icons, int sel);
int glwImPanel(glwWin *win, int id, int x, int y, int width, int height);
int glwImTabBox(glwWin *win, int id, int x, int y, int width, int height,
char **titles, int *icons, int sel);
@ -65,6 +65,8 @@ int glwPointTest(int x, int y, int left, int top, int width, int height,
int allowOffset);
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);
#ifdef __cplusplus
}

View File

@ -5,21 +5,22 @@
#define GLW_SYSTEM_FONT_WEIGHT 10
#define GLW_SYSTEM_FONT_SIZE 20
#define GLW_SYSTEM_FONT_COLOR 0xb9b9b9
#define GLW_SYSTEM_FONT_COLOR_H 0xffffff
#define GLW_SMALL_ROUNDED_CORNER_SLICES 5
#define GLW_BORDER_COLOR_1 0x000000
#define GLW_BORDER_COLOR_2 0x000000
#define GLW_FILL_GRADIENT_COLOR_1 0x424242
#define GLW_FILL_GRADIENT_COLOR_2 0x242424
#define GLW_FILL_GRADIENT_COLOR_1 0x2f2f2f //0x424242
#define GLW_FILL_GRADIENT_COLOR_2 0x1f1f1f //0x111111 //0x242424
#define GLW_FILL_GRADIENT_COLOR_1_H 0x3795fa
#define GLW_FILL_GRADIENT_COLOR_2_H 0x242424
#define GLW_FILL_GRADIENT_COLOR_1_H 0xf77100
#define GLW_FILL_GRADIENT_COLOR_2_H 0x713300
#define GLW_BUTTON_CORNER_RADIUS 5
#define GLW_CHECK_COLOR 0x000000
#define GLW_CHECK_COLOR GLW_BORDER_COLOR_2
#define GLW_TAB_FILL_GRADIENT_COLOR_1 GLW_FILL_GRADIENT_COLOR_1
#define GLW_TAB_FILL_GRADIENT_COLOR_2 GLW_FILL_GRADIENT_COLOR_2
@ -37,4 +38,6 @@
#define GLW_MIN_TAB_WIDTH 120
#define GLW_MENU_BACKGROUND_COLOR 0x181818
#endif