Example #1
0
  bool UIPanel::checkbox(const char * str, bool checked, bool enabled)
  {
    _state.widgetId++;
    uint32_t id = _state.widgetId;

    float x = _state.widgetX;
    float y = _state.widgetY; // + BUTTON_HEIGHT;
    float w = _state.widgetW;
    float h = BUTTON_HEIGHT;
    _state.widgetY += BUTTON_HEIGHT + DEFAULT_SPACING;

    bool over = enabled && inRect(_state, x, y, w, h);
    bool result = buttonLogic(_state, id, over);

    const float cx = x + BUTTON_HEIGHT * 0.5f - CHECK_SIZE * 0.5f;
    const float cy = y + BUTTON_HEIGHT * 0.5f - CHECK_SIZE * 0.5f;

    addRoundedRectangle(_faceMesh->geometry, Vector2(cx - 3.0f, cy - 3.0f), Vector2(CHECK_SIZE + 6.0f, CHECK_SIZE + 6.0f), 4.0f, Color(0.5, 0.5, 0.5, isActive(_state, id) ? 0.75 : 0.35));

    if (checked)
    {
      if (enabled)
        addRoundedRectangle(_faceMesh->geometry, Vector2(cx, cy), Vector2(CHECK_SIZE, CHECK_SIZE), CHECK_SIZE * 0.5f - 1.0f, Color(1, 1, 1, isActive(_state, id) ? 1 : 0.8));
      else
        addRoundedRectangle(_faceMesh->geometry, Vector2(cx, cy), Vector2(CHECK_SIZE, CHECK_SIZE), CHECK_SIZE * 0.5f - 1.0f, Color(0.5, 0.5, 0.5, 0.8));
    }

    if (enabled)
      font->buildTextGeometry(str, Vector2(x + BUTTON_HEIGHT, y + BUTTON_HEIGHT * 0.5f + TEXT_HEIGHT * 0.5f), _fontMesh->geometry, isHot(_state, id) ? Color(1, 0.75, 0, 1) : Color(1, 1, 1, 0.8));
    else
      font->buildTextGeometry(str, Vector2(x + BUTTON_HEIGHT, y + BUTTON_HEIGHT * 0.5f + TEXT_HEIGHT * 0.5f), _fontMesh->geometry, Color(0.5, 0.5, 0.5, 0.8));

    return result;
  }
Example #2
0
bool imguiCheck(const char* text, bool checked, bool enabled)
{
	g_state.widgetId++;
	unsigned int id = (g_state.areaId<<16) | g_state.widgetId;
	
	int x = g_state.widgetX;
	int y = g_state.widgetY - BUTTON_HEIGHT;
	int w = g_state.widgetW;
	int h = BUTTON_HEIGHT;
	g_state.widgetY -= BUTTON_HEIGHT + DEFAULT_SPACING;

	bool over = enabled && inRect(x, y, w, h);
	bool res = buttonLogic(id, over);
	
	const int cx = x+BUTTON_HEIGHT/2-CHECK_SIZE/2;
	const int cy = y+BUTTON_HEIGHT/2-CHECK_SIZE/2;
	addGfxCmdRoundedRect((float)cx-3, (float)cy-3, (float)CHECK_SIZE+6, (float)CHECK_SIZE+6, 4, imguiRGBA(128,128,128, isActive(id)?196:96));
	if (checked)
	{
		if (enabled)
			addGfxCmdRoundedRect((float)cx, (float)cy, (float)CHECK_SIZE, (float)CHECK_SIZE, (float)CHECK_SIZE/2-1, imguiRGBA(255,255,255,isActive(id)?255:200));
		else
			addGfxCmdRoundedRect((float)cx, (float)cy, (float)CHECK_SIZE, (float)CHECK_SIZE, (float)CHECK_SIZE/2-1, imguiRGBA(128,128,128,200));
	}

	if (enabled)
		addGfxCmdText(x+BUTTON_HEIGHT, y+BUTTON_HEIGHT/2-TEXT_HEIGHT/2, IMGUI_ALIGN_LEFT, text, isHot(id) ? imguiRGBA(255,196,0,255) : imguiRGBA(255,255,255,200));
	else
		addGfxCmdText(x+BUTTON_HEIGHT, y+BUTTON_HEIGHT/2-TEXT_HEIGHT/2, IMGUI_ALIGN_LEFT, text, imguiRGBA(128,128,128,200));

	return res;
}
Example #3
0
  bool UIPanel::button(const char * str, bool enabled)
  {
    _state.widgetId++;
    uint32_t id = _state.widgetId;

    const float x = _state.widgetX;
    const float y = _state.widgetY;
    const float w = _state.widgetW;
    const float h = BUTTON_HEIGHT;
    _state.widgetY += BUTTON_HEIGHT + DEFAULT_SPACING;

    bool over = enabled && inRect(_state, x, y, w, h);
    bool result = buttonLogic(_state, id, over);

    addRoundedRectangle(_faceMesh->geometry, Vector2(x, y), Vector2(w, h), BUTTON_HEIGHT * 0.5f - 1.0f, Color(0.5, 0.5, 0.5, isActive(_state, id) ? 0.75 : 0.35));

    const float textLength = font->textLength(str);
    const float textX = x + BUTTON_HEIGHT * 0.5f + (w - BUTTON_HEIGHT) * 0.5f - textLength * 0.5f;

    if (enabled)
      font->buildTextGeometry(str, Vector2(textX, y + BUTTON_HEIGHT * 0.5f + TEXT_HEIGHT * 0.5f), _fontMesh->geometry, isHot(_state, id) ? Color(1, 0.75, 0, 1) : Color(1, 1, 1, 0.8));
    else
      font->buildTextGeometry(str, Vector2(textX, y + BUTTON_HEIGHT * 0.5f + TEXT_HEIGHT * 0.5f), _fontMesh->geometry, isHot(_state, id) ? Color(1, 0.75, 0, 1) : Color(0.5, 0.5, 0.5, 0.8));

    return result;
  }
Example #4
0
bool imguiCollapse(const char* text, const char* subtext, bool checked, bool enabled)
{
	g_state.widgetId++;
	unsigned int id = (g_state.areaId<<16) | g_state.widgetId;
	
	int x = g_state.widgetX;
	int y = g_state.widgetY - BUTTON_HEIGHT;
	int w = g_state.widgetW;
	int h = BUTTON_HEIGHT;
	g_state.widgetY -= BUTTON_HEIGHT; // + DEFAULT_SPACING;

	const int cx = x+BUTTON_HEIGHT/2-CHECK_SIZE/2;
	const int cy = y+BUTTON_HEIGHT/2-CHECK_SIZE/2;

	bool over = enabled && inRect(x, y, w, h);
	bool res = buttonLogic(id, over);
	
	if (checked)
		addGfxCmdTriangle(cx, cy, CHECK_SIZE, CHECK_SIZE, 2, imguiRGBA(255,255,255,isActive(id)?255:200));
	else
		addGfxCmdTriangle(cx, cy, CHECK_SIZE, CHECK_SIZE, 1, imguiRGBA(255,255,255,isActive(id)?255:200));

	if (enabled)
		addGfxCmdText(x+BUTTON_HEIGHT, y+BUTTON_HEIGHT/2-TEXT_HEIGHT/2, IMGUI_ALIGN_LEFT, text, isHot(id) ? imguiRGBA(255,196,0,255) : imguiRGBA(255,255,255,200));
	else
		addGfxCmdText(x+BUTTON_HEIGHT, y+BUTTON_HEIGHT/2-TEXT_HEIGHT/2, IMGUI_ALIGN_LEFT, text, imguiRGBA(128,128,128,200));

	if (subtext)
		addGfxCmdText(x+w-BUTTON_HEIGHT/2, y+BUTTON_HEIGHT/2-TEXT_HEIGHT/2, IMGUI_ALIGN_RIGHT, subtext, imguiRGBA(255,255,255,128));
	
	return res;
}
/************************************************************************

	Function:		display

	Description:	Draws initial static openGL. Sets up buttons, menu,
	drawing of letters, calls mouse functionality, runs all animations.

*************************************************************************/
void display(void)
{

	// Clear the screen and redraw updated stuff
	glClear(GL_COLOR_BUFFER_BIT);

	// Draw bonus in background if button pressed
	// The bonus is psychadelic sqaures that are multicolor, pulsing in the
	// background
	drawBonus();

	// Morphs the letter if button pressed, else stays as N
	morphLetter();

	// Draw the background for the menu
	drawMenu();

	// This draws the buttons
	// Always draw base buttons and shadows, but draw over if one is pressed
	drawButtons();

	// Checks if mouse is pressed and records the position
	mouseCheck();

	// Performs button operations depending on mouse position
	buttonLogic();

	// Draw text for buttons
	drawButtonText();

	// Use swap buffers for double buffering
	glutSwapBuffers();
}
Example #6
0
bool imguiButton(const char* text, bool enabled)
{
	g_state.widgetId++;
	unsigned int id = (g_state.areaId<<16) | g_state.widgetId;
	
	int x = g_state.widgetX;
	int y = g_state.widgetY - BUTTON_HEIGHT;
	int w = g_state.widgetW;
	int h = BUTTON_HEIGHT;
	g_state.widgetY -= BUTTON_HEIGHT + DEFAULT_SPACING;

	bool over = enabled && inRect(x, y, w, h);
	bool res = buttonLogic(id, over);

	addGfxCmdRoundedRect((float)x, (float)y, (float)w, (float)h, (float)BUTTON_HEIGHT/2-1, imguiRGBA(128,128,128, isActive(id)?196:96));
	if (enabled)
		addGfxCmdText(x+BUTTON_HEIGHT/2, y+BUTTON_HEIGHT/2-TEXT_HEIGHT/2, IMGUI_ALIGN_LEFT, text, isHot(id) ? imguiRGBA(255,196,0,255) : imguiRGBA(255,255,255,200));
	else
		addGfxCmdText(x+BUTTON_HEIGHT/2, y+BUTTON_HEIGHT/2-TEXT_HEIGHT/2, IMGUI_ALIGN_LEFT, text, imguiRGBA(128,128,128,200));

	return res;
}
Example #7
0
bool imguiItem(const char* text, bool enabled)
{
	s_state.widgetId++;
	unsigned int id = (s_state.areaId << 16) | s_state.widgetId;

	int x = s_state.widgetX;
	int y = s_state.widgetY - BUTTON_HEIGHT;
	int w = s_state.widgetW;
	int h = BUTTON_HEIGHT;
	s_state.widgetY -= BUTTON_HEIGHT + DEFAULT_SPACING;

	bool over = enabled && inRect(x, y, w, h);
	bool res = buttonLogic(id, over);

	if (isHot(id))
		AddGfxCmdRoundedRect((float)x, (float)y, (float)w, (float)h, 2.0f, SetRGBA(255, 196, 0, isActive(id) ? 196 : 96));

	if (enabled)
		AddGfxCmdText(x + BUTTON_HEIGHT / 2, y + BUTTON_HEIGHT / 2 - TEXT_HEIGHT / 2, TEXT_ALIGN_LEFT, text, SetRGBA(255, 255, 255, 200));
	else
		AddGfxCmdText(x + BUTTON_HEIGHT / 2, y + BUTTON_HEIGHT / 2 - TEXT_HEIGHT / 2, TEXT_ALIGN_LEFT, text, SetRGBA(128, 128, 128, 200));

	return res;
}
Example #8
0
  bool UIPanel::slider(const char * text, float * value, float valueMin, float valueMax, float valueInc, bool enabled)
  {
    _state.widgetId++;
    uint32_t id = _state.widgetId;

    const float x = _state.widgetX;
    const float y = _state.widgetY;
    const float w = _state.widgetW;
    const float h = SLIDER_HEIGHT;
    _state.widgetY += SLIDER_HEIGHT + DEFAULT_SPACING;

    addRoundedRectangle(_faceMesh->geometry, Vector2(x, y), Vector2(w, h), 4.0f, Color(0, 0, 0, 0.5));

    const float range = w - SLIDER_MARKER_WIDTH;

    float u = (*value - valueMin) / (valueMax - valueMin);
    if (u < 0.0f) u = 0.0f;
    if (u > 1.0f) u = 1.0f;
    float m = u * range;

    bool over = enabled && inRect(_state, x + m, y, SLIDER_MARKER_WIDTH, SLIDER_HEIGHT);
    bool result = buttonLogic(_state, id, over);
    bool valueChanged = false;

    if (isActive(_state, id))
    {
      if (_state.wentActive)
      {
        _state.mouseDrag.x = _state.mousePos.x;
        _state.dragOrigin = u;
      }

      if (_state.mouseDrag.x != _state.mousePos.x)
      {
        u = _state.dragOrigin + (float)(_state.mousePos.x - _state.mouseDrag.x) / (float)range;
        if (u < 0) u = 0;
        if (u > 1) u = 1;
        *value = valueMin + u * (valueMax - valueMin);
        *value = std::floor(*value / valueInc + 0.5f) * valueInc;
        m = u * range;
        valueChanged = true;
      }
    }

    if (isActive(_state, id))
      addRoundedRectangle(_faceMesh->geometry, Vector2(x + m, y), Vector2(SLIDER_MARKER_WIDTH, SLIDER_HEIGHT), 4.0f, Color(1, 1, 1, 1));
    else
      addRoundedRectangle(_faceMesh->geometry, Vector2(x + m, y), Vector2(SLIDER_MARKER_WIDTH, SLIDER_HEIGHT), 4.0f, isHot(_state, id) ? Color(1, 0.75, 0, 1) : Color(1, 1, 1, 0.25));

    char valueStr[16];
    sprintf(valueStr, "%d%%", (int)std::ceil((*value - valueMin) / (valueMax - valueMin) * 100.0));
    const float valueLength = font->textLength(valueStr);

    Color fontColor = isHot(_state, id) ? Color(1, 0.75, 0, 1) : Color(1, 1, 1, 0.8);

    if (!enabled)
      fontColor = Color(0.5, 0.5, 0.5, 0.8);

    font->buildTextGeometry(text, Vector2(x + SLIDER_HEIGHT * 0.5f, y + SLIDER_HEIGHT * 0.5f + TEXT_HEIGHT * 0.5f), _fontMesh->geometry, fontColor);
    font->buildTextGeometry(valueStr, Vector2(x + w - valueLength - SLIDER_HEIGHT * 0.5f, y + SLIDER_HEIGHT * 0.5f + TEXT_HEIGHT * 0.5f), _fontMesh->geometry, fontColor);

    return result || valueChanged;
  }
Example #9
0
bool imguiSlider(const char* text, float* val, float vmin, float vmax, float vinc, bool enabled)
{
	g_state.widgetId++;
	unsigned int id = (g_state.areaId<<16) | g_state.widgetId;
	
	int x = g_state.widgetX;
	int y = g_state.widgetY - BUTTON_HEIGHT;
	int w = g_state.widgetW;
	int h = SLIDER_HEIGHT;
	g_state.widgetY -= SLIDER_HEIGHT + DEFAULT_SPACING;

	addGfxCmdRoundedRect((float)x, (float)y, (float)w, (float)h, 4.0f, imguiRGBA(0,0,0,128));

	const int range = w - SLIDER_MARKER_WIDTH;

	float u = (*val - vmin) / (vmax-vmin);
	if (u < 0) u = 0;
	if (u > 1) u = 1;
	int m = (int)(u * range);

	bool over = enabled && inRect(x+m, y, SLIDER_MARKER_WIDTH, SLIDER_HEIGHT);
	bool res = buttonLogic(id, over);
	bool valChanged = false;

	if (isActive(id))
	{
		if (g_state.wentActive)
		{
			g_state.dragX = g_state.mx;
			g_state.dragOrig = u;
		}
		if (g_state.dragX != g_state.mx)
		{
			u = g_state.dragOrig + (float)(g_state.mx - g_state.dragX) / (float)range;
			if (u < 0) u = 0;
			if (u > 1) u = 1;
			*val = vmin + u*(vmax-vmin);
			*val = floorf(*val/vinc+0.5f)*vinc; // Snap to vinc
			m = (int)(u * range);
			valChanged = true;
		}
	}

	if (isActive(id))
		addGfxCmdRoundedRect((float)(x+m), (float)y, (float)SLIDER_MARKER_WIDTH, (float)SLIDER_HEIGHT, 4.0f, imguiRGBA(255,255,255,255));
	else
		addGfxCmdRoundedRect((float)(x+m), (float)y, (float)SLIDER_MARKER_WIDTH, (float)SLIDER_HEIGHT, 4.0f, isHot(id) ? imguiRGBA(255,196,0,128) : imguiRGBA(255,255,255,64));

	// TODO: fix this, take a look at 'nicenum'.
	int digits = (int)(ceilf(log10f(vinc)));
	char fmt[16];
	snprintf(fmt, 16, "%%.%df", digits >= 0 ? 0 : -digits);
	char msg[128];
	snprintf(msg, 128, fmt, *val);
	
	if (enabled)
	{
		addGfxCmdText(x+SLIDER_HEIGHT/2, y+SLIDER_HEIGHT/2-TEXT_HEIGHT/2, IMGUI_ALIGN_LEFT, text, isHot(id) ? imguiRGBA(255,196,0,255) : imguiRGBA(255,255,255,200));
		addGfxCmdText(x+w-SLIDER_HEIGHT/2, y+SLIDER_HEIGHT/2-TEXT_HEIGHT/2, IMGUI_ALIGN_RIGHT, msg, isHot(id) ? imguiRGBA(255,196,0,255) : imguiRGBA(255,255,255,200));
	}
	else
	{
		addGfxCmdText(x+SLIDER_HEIGHT/2, y+SLIDER_HEIGHT/2-TEXT_HEIGHT/2, IMGUI_ALIGN_LEFT, text, imguiRGBA(128,128,128,200));
		addGfxCmdText(x+w-SLIDER_HEIGHT/2, y+SLIDER_HEIGHT/2-TEXT_HEIGHT/2, IMGUI_ALIGN_RIGHT, msg, imguiRGBA(128,128,128,200));
	}

	return res || valChanged;
}
Example #10
0
void imguiEndScrollArea()
{
	// Disable scissoring.
	addGfxCmdScissor(-1,-1,-1,-1);

	// Draw scroll bar
	int x = g_scrollRight+SCROLL_AREA_PADDING/2;
	int y = g_scrollBottom;
	int w = SCROLL_AREA_PADDING*2;
	int h = g_scrollTop - g_scrollBottom;

	int stop = g_scrollAreaTop;
	int sbot = g_state.widgetY;
	int sh = stop - sbot; // The scrollable area height.

	float barHeight = (float)h/(float)sh;
	
	if (barHeight < 1)
	{
		float barY = (float)(y - sbot)/(float)sh;
		if (barY < 0) barY = 0;
		if (barY > 1) barY = 1;
		
		// Handle scroll bar logic.
		unsigned int hid = g_scrollId;
		int hx = x;
		int hy = y + (int)(barY*h);
		int hw = w;
		int hh = (int)(barHeight*h);
		
		const int range = h - (hh-1);
		bool over = inRect(hx, hy, hw, hh);
		buttonLogic(hid, over);
		if (isActive(hid))
		{
			float u = (float)(hy-y) / (float)range;
			if (g_state.wentActive)
			{
				g_state.dragY = g_state.my;
				g_state.dragOrig = u;
			}
			if (g_state.dragY != g_state.my)
			{
				u = g_state.dragOrig + (g_state.my - g_state.dragY) / (float)range;
				if (u < 0) u = 0;
				if (u > 1) u = 1;
				*g_scrollVal = (int)((1-u) * (sh - h));
			}
		}
		
		// BG
		addGfxCmdRoundedRect((float)x, (float)y, (float)w, (float)h, (float)w/2-1, imguiRGBA(0,0,0,196));
		// Bar
		if (isActive(hid))
			addGfxCmdRoundedRect((float)hx, (float)hy, (float)hw, (float)hh, (float)w/2-1, imguiRGBA(255,196,0,196));
		else
			addGfxCmdRoundedRect((float)hx, (float)hy, (float)hw, (float)hh, (float)w/2-1, isHot(hid) ? imguiRGBA(255,196,0,96) : imguiRGBA(255,255,255,64));

		// Handle mouse scrolling.
		if (g_insideScrollArea) // && !anyActive())
		{
			if (g_state.scroll)
			{
				*g_scrollVal += 20*g_state.scroll;
				if (*g_scrollVal < 0) *g_scrollVal = 0;
				if (*g_scrollVal > (sh - h)) *g_scrollVal = (sh - h);
			}
		}
	}
	g_state.insideCurrentScroll = false;
}
Example #11
0
bool imguiSlider(const char* text, int* val, int vmin, int vmax, int vinc, bool enabled)
{
	s_state.widgetId++;
	unsigned int id = (s_state.areaId << 16) | s_state.widgetId;

	int x = s_state.widgetX;
	int y = s_state.widgetY - BUTTON_HEIGHT;
	int w = s_state.widgetW;
	int h = SLIDER_HEIGHT;
	s_state.widgetY -= SLIDER_HEIGHT + DEFAULT_SPACING;

	AddGfxCmdRoundedRect((float)x, (float)y, (float)w, (float)h, 4.0f, SetRGBA(0, 0, 0, 128));

	const int range = w - SLIDER_MARKER_WIDTH;

	float u = (*val - vmin) / float(vmax - vmin);
	if (u < 0) u = 0;
	if (u > 1) u = 1;
	int m = (int)(u * range);

	bool over = enabled && inRect(x + m, y, SLIDER_MARKER_WIDTH, SLIDER_HEIGHT);
	bool res = buttonLogic(id, over);
	bool valChanged = false;

	if (isActive(id))
	{
		if (s_state.wentActive)
		{
			s_state.dragX = s_state.mx;
			s_state.dragOrig = u;
		}
		if (s_state.dragX != s_state.mx)
		{
			u = s_state.dragOrig + (float)(s_state.mx - s_state.dragX) / (float)range;
			if (u < 0) u = 0;
			if (u > 1) u = 1;
			*val = int(vmin + u*(vmax - vmin));
			*val = int(floorf(*val / float(vinc) + 0.5f))*vinc; // Snap to vinc
			m = (int)(u * range);
			valChanged = true;
		}
	}

	if (isActive(id))
		AddGfxCmdRoundedRect((float)(x + m), (float)y, (float)SLIDER_MARKER_WIDTH, (float)SLIDER_HEIGHT, 4.0f, SetRGBA(255, 255, 255, 255));
	else
		AddGfxCmdRoundedRect((float)(x + m), (float)y, (float)SLIDER_MARKER_WIDTH, (float)SLIDER_HEIGHT, 4.0f, isHot(id) ? SetRGBA(255, 196, 0, 128) : SetRGBA(255, 255, 255, 64));

	char msg[128];
	snprintf(msg, 128, "%d", *val);

	if (enabled)
	{
		AddGfxCmdText(x + SLIDER_HEIGHT / 2, y + SLIDER_HEIGHT / 2 - TEXT_HEIGHT / 2, TEXT_ALIGN_LEFT, text, isHot(id) ? SetRGBA(255, 196, 0, 255) : SetRGBA(255, 255, 255, 200));
		AddGfxCmdText(x + w - SLIDER_HEIGHT / 2, y + SLIDER_HEIGHT / 2 - TEXT_HEIGHT / 2, TEXT_ALIGN_RIGHT, msg, isHot(id) ? SetRGBA(255, 196, 0, 255) : SetRGBA(255, 255, 255, 200));
	}
	else
	{
		AddGfxCmdText(x + SLIDER_HEIGHT / 2, y + SLIDER_HEIGHT / 2 - TEXT_HEIGHT / 2, TEXT_ALIGN_LEFT, text, SetRGBA(128, 128, 128, 200));
		AddGfxCmdText(x + w - SLIDER_HEIGHT / 2, y + SLIDER_HEIGHT / 2 - TEXT_HEIGHT / 2, TEXT_ALIGN_RIGHT, msg, SetRGBA(128, 128, 128, 200));
	}

	return res || valChanged;
}