While a bit hacky now using emgui (which is just declared outside the root dir to make it simple)
This commit is contained in:
parent
804aad808d
commit
36baa7e2fb
@ -1,103 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
typedef unsigned int uint;
|
||||
|
||||
#if defined(ROCKETGUI_WIN32)
|
||||
|
||||
#include <xmmintrin.h> // __m128
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#include <stdint.h>
|
||||
#else
|
||||
|
||||
typedef unsigned char uint8_t;
|
||||
typedef signed char int8_t;
|
||||
|
||||
typedef unsigned short uint16_t;
|
||||
typedef signed short int16_t;
|
||||
|
||||
typedef unsigned int uint32_t;
|
||||
typedef signed int int32_t;
|
||||
|
||||
typedef unsigned __int64 uint64_t;
|
||||
typedef signed __int64 int64_t;
|
||||
|
||||
typedef __m128 uint128_t;
|
||||
typedef __m128 int128_t;
|
||||
|
||||
typedef unsigned char bool;
|
||||
|
||||
#ifndef true
|
||||
#define true 1
|
||||
#endif
|
||||
|
||||
#ifndef false
|
||||
#define false 0
|
||||
#endif
|
||||
|
||||
#pragma warning(disable: 4100 4127 4201)
|
||||
#endif
|
||||
|
||||
#define ROCKETGUI_LIKELY(exp) exp
|
||||
#define ROCKETGUI_UNLIKELY(exp) exp
|
||||
#define ROCKETGUI_INLINE __forceinline
|
||||
#define ROCKETGUI_RESTRICT __restrict
|
||||
#define ROCKETGUI_ALIGN(x) __declspec(align(x))
|
||||
#define ROCKETGUI_UNCACHEDAC_PTR(x) x
|
||||
#define ROCKETGUI_UNCACHED_PTR(x) x
|
||||
#define ROCKETGUI_CACHED_PTR(x) x
|
||||
#define ROCKETGUI_ALIGNOF(t) __alignof(t)
|
||||
#define ROCKETGUI_BREAK __debugbreak()
|
||||
|
||||
#if defined(_WIN64)
|
||||
#define ROCKETGUI_X64
|
||||
#endif
|
||||
|
||||
#elif defined(ROCKETGUI_UNIX) || defined(ROCKETGUI_MACOSX)
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(__SSE__)
|
||||
#include <xmmintrin.h>
|
||||
|
||||
typedef __m128 uint128_t;
|
||||
typedef __m128 int128_t;
|
||||
#else
|
||||
#error No SSE support detected
|
||||
#endif
|
||||
|
||||
#define ROCKETGUI_LIKELY(exp) __builtin_expect(exp, 1)
|
||||
#define ROCKETGUI_UNLIKELY(exp) __builtin_expect(exp, 0)
|
||||
#define ROCKETGUI_INLINE inline
|
||||
#define ROCKETGUI_RESTRICT __restrict
|
||||
#define ROCKETGUI_ALIGN(x) __attribute__((aligned(x)))
|
||||
#define ROCKETGUI_UNCACHEDAC_PTR(x) x
|
||||
#define ROCKETGUI_UNCACHED_PTR(x) x
|
||||
#define ROCKETGUI_CACHED_PTR(x) x
|
||||
#define ROCKETGUI_ALIGNOF(t) __alignof__(t)
|
||||
#define ROCKETGUI_BREAK ((*(volatile uint32_t *)(0)) = 0x666)
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifndef true
|
||||
#define true 1
|
||||
#endif
|
||||
|
||||
#ifndef false
|
||||
#define false 0
|
||||
#endif
|
||||
|
||||
#if defined(__LP64__)
|
||||
#define ROCKETGUI_X64
|
||||
#endif
|
||||
|
||||
#else
|
||||
#error Platform not supported
|
||||
#endif
|
||||
|
||||
#define sizeof_array(array) (int)(sizeof(array) / sizeof(array[0]))
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#include "RocketGui.h"
|
||||
#include <string.h>
|
||||
#include <Emgui.h>
|
||||
|
||||
typedef struct RETrack
|
||||
{
|
||||
@ -17,12 +17,17 @@ typedef struct Editor
|
||||
int currentRow;
|
||||
} Editor;
|
||||
|
||||
static Editor s_editor;
|
||||
//static Editor s_editor;
|
||||
|
||||
void Editor_create()
|
||||
{
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Editor_init()
|
||||
{
|
||||
/*
|
||||
memset(&s_editor, 0, sizeof(Editor));
|
||||
|
||||
s_editor.tracks[0].name = strdup("DemoTrack");
|
||||
@ -35,14 +40,16 @@ void Editor_init()
|
||||
s_editor.windowHeight = 600;
|
||||
|
||||
RocketGui_init();
|
||||
*/
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Editor_guiUpdate()
|
||||
void Editor_update()
|
||||
{
|
||||
RocketGui_begin();
|
||||
Emgui_begin();
|
||||
|
||||
/*
|
||||
RocketGui_beginHorizontalStackPanelXY(2, 2);
|
||||
|
||||
if (RocketGui_button("PressMeNow!"))
|
||||
@ -59,7 +66,22 @@ void Editor_guiUpdate()
|
||||
RocketGui_textLabel("Test");
|
||||
|
||||
RocketGui_fill(0xff0203ff, 10, 10, 100, 100);
|
||||
*/
|
||||
|
||||
Emgui_end();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Editor_keyDown(int keyCode)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Editor_destroy()
|
||||
{
|
||||
|
||||
RocketGui_end();
|
||||
}
|
||||
|
||||
|
||||
8
ogl_editor/src/Editor.h
Normal file
8
ogl_editor/src/Editor.h
Normal file
@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
void Editor_create();
|
||||
void Editor_destroy();
|
||||
void Editor_init();
|
||||
void Editor_update();
|
||||
void Editor_keyDown(int keyCode);
|
||||
|
||||
@ -1,8 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
void GFXBackend_create();
|
||||
void GFXBackend_destroy();
|
||||
void GFXBackend_updateViewPort(int width, int height);
|
||||
void GFXBackend_setFont(void* data, int width, int height);
|
||||
void GFXBackend_drawControls(void* data, int count);
|
||||
|
||||
@ -1,237 +0,0 @@
|
||||
#include <OpenGL/OpenGL.h>
|
||||
#include <OpenGL/gl.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "Core/Types.h"
|
||||
#include "../RocketGui.h"
|
||||
#include "../GFXBackend.h"
|
||||
#include "../MicroknightFont.h"
|
||||
|
||||
unsigned int s_fontTexture;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void GFXBackend_create()
|
||||
{
|
||||
// set the background colour
|
||||
glClearColor(0.0, 0.0, 0.0, 1.0);
|
||||
glClearDepth(1.0);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void GFXBackend_setFont(void* font, int w, int h)
|
||||
{
|
||||
glGenTextures(1, &s_fontTexture);
|
||||
glBindTexture(GL_TEXTURE_2D, s_fontTexture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, font);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void GFXBackend_updateViewPort(int width, int height)
|
||||
{
|
||||
glViewport(0, 0, width, height);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(0, width, height, 0, 0, 1);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void GFXBackend_destroy()
|
||||
{
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void drawTextHorizontal(int x, int y, const char* text)
|
||||
{
|
||||
const int charOffset = 32;
|
||||
char c = *text++;
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
glBindTexture(GL_TEXTURE_2D, s_fontTexture);
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
while (c != 0)
|
||||
{
|
||||
int offset = c - charOffset;
|
||||
uint16_t font_x = s_microknightLayout[offset].x;
|
||||
uint16_t font_y = s_microknightLayout[offset].y;
|
||||
const float font_0 = ((float)font_x) / 128.0f;
|
||||
const float font_1 = ((float)font_y) / 128.0f;
|
||||
const float font_2 = ((float)font_x + 8) / 128.0f;
|
||||
const float font_3 = ((float)font_y + 8) / 128.0f;
|
||||
|
||||
glTexCoord2f(font_0, font_1);
|
||||
glVertex2i(x, y);
|
||||
glTexCoord2f(font_0, font_3);
|
||||
glVertex2i(x, y + 8);
|
||||
glTexCoord2f(font_2, font_3);
|
||||
glVertex2i(x + 8,y + 8);
|
||||
glTexCoord2f(font_2, font_1);
|
||||
glVertex2i(x + 8,y);
|
||||
|
||||
c = *text++;
|
||||
x += 8;
|
||||
}
|
||||
|
||||
glEnd();
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int GFXBackend_getTextPixelLength(const char* text)
|
||||
{
|
||||
// hardcoded for now
|
||||
return (strlen(text) - 1) * 9;
|
||||
}
|
||||
|
||||
void GFXBackend_drawLine(int x, int y, int xEnd, int yEnd)
|
||||
{
|
||||
glColor4f(0.5f, 0.5f, 0.5f, 0.5f);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glBegin(GL_LINES);
|
||||
glVertex2i(x, y);
|
||||
glVertex2i(xEnd, yEnd);
|
||||
glVertex2i(x + 1, y);
|
||||
glVertex2i(xEnd + 1, yEnd);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
struct RETrack;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int GFXBackend_drawTrack(int xPos, int yPos, struct RETrack* track)
|
||||
{
|
||||
/*
|
||||
int i, count;
|
||||
int trackWidth = GFXBackend_getTextPixelLength(track->name) + 4;
|
||||
|
||||
// at least 30 pixels in width
|
||||
|
||||
if (trackWidth < 30)
|
||||
trackWidth = 30;
|
||||
|
||||
glColor3f(1.0f, 1.0f, 1.0f);
|
||||
GFXBackend_drawTextHorizontal(xPos, yPos, track->name);
|
||||
|
||||
GFXBackend_drawLine(xPos + trackWidth, yPos, xPos + trackWidth, yPos + 800); // TODO: proper y-size according to window size
|
||||
|
||||
for (i = 2, count = 30; i < count; ++i)
|
||||
{
|
||||
drawRow(xPos, (i * 20));
|
||||
}
|
||||
|
||||
return trackWidth + 8;
|
||||
*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void OpenGL_drawPosition(int row, int xPos, int yPos, int height)
|
||||
{
|
||||
/*
|
||||
int i, count;
|
||||
|
||||
// so yeah, we can make this smarter
|
||||
// TODO: remove sprintf (may be ok)
|
||||
// TODO: Build one list of quads instead of glVertex crap
|
||||
|
||||
for (i = 0, count = (height - yPos); i < count; i += s_fontWidth)
|
||||
{
|
||||
char tempString[64];
|
||||
sprintf(tempString, "%08d", row);
|
||||
|
||||
if (row & 7)
|
||||
glColor4f(0.5f, 0.5f, 0.5f, 0.5f);
|
||||
else
|
||||
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
|
||||
OpenGL_drawTextHorizontal(xPos, yPos, tempString);
|
||||
row++;
|
||||
yPos += s_fontWidth;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void quad(int x, int y, int width, int height)
|
||||
{
|
||||
glVertex2i(x, y);
|
||||
glVertex2i(x, y + height);
|
||||
glVertex2i(x + width,y + height);
|
||||
glVertex2i(x + width,y);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void GFXBackend_drawControls(void* data, int controlCount)
|
||||
{
|
||||
RocketControlInfo* controls = (RocketControlInfo*)data;
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
for (uint i = 0; i < controlCount; ++i)
|
||||
{
|
||||
const RocketControlInfo* control = &controls[i];
|
||||
|
||||
switch (controls[i].type)
|
||||
{
|
||||
case DRAWTYPE_NONE :
|
||||
break;
|
||||
|
||||
case DRAWTYPE_SLIDER :
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
case DRAWTYPE_FILL :
|
||||
{
|
||||
uint32_t color = control->color;
|
||||
glBegin(GL_QUADS);
|
||||
glColor4f(((color >> 16) & 0xff) * 1.0f / 255.0f,
|
||||
((color >> 8) & 0xff) * 1.0f / 255.0f,
|
||||
((color >> 0) & 0xff) * 1.0f / 255.0f,
|
||||
((color >> 24) & 0xff) * 1.0f / 255.0f);
|
||||
quad(control->x, control->y, control->width, control->height);
|
||||
glEnd();
|
||||
break;
|
||||
}
|
||||
|
||||
case DRAWTYPE_TEXT :
|
||||
{
|
||||
drawTextHorizontal(control->x, control->y, control->text);
|
||||
break;
|
||||
}
|
||||
|
||||
case DRAWTYPE_IMAGE :
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
glFlush();
|
||||
}
|
||||
|
||||
@ -1,529 +0,0 @@
|
||||
#include "RocketGui.h"
|
||||
#include "MicroknightFont.h"
|
||||
#include "GFXBackend.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(ROCKETGUI_MACOSX)
|
||||
#include <sys/syslimits.h>
|
||||
#else
|
||||
// TODO: Include correct path
|
||||
#define PATH_MAX 1024
|
||||
#endif
|
||||
|
||||
///
|
||||
|
||||
enum
|
||||
{
|
||||
MAX_CONTROLS = 1024,
|
||||
MAX_IMAGES = 1024,
|
||||
};
|
||||
|
||||
RocketGuiState g_rocketGuiState;
|
||||
uint32_t s_controlId;
|
||||
|
||||
const int s_fontWidth = 9;
|
||||
const int s_fontHeight = 9;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum GuiPlacementState
|
||||
{
|
||||
PLACEMENTSTATE_NONE,
|
||||
PLACEMENTSTATE_HORIZONAL,
|
||||
PLACEMENTSTATE_VERTICAL,
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
typedef struct GuiPlacementInfo
|
||||
{
|
||||
enum GuiPlacementState state;
|
||||
int x;
|
||||
int y;
|
||||
|
||||
} GuiPlacementInfo;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static GuiPlacementInfo g_placementInfo;
|
||||
RocketControlInfo g_controls[MAX_CONTROLS];
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void RocketGui_beginHorizontalStackPanelXY(int x, int y)
|
||||
{
|
||||
g_placementInfo.state = PLACEMENTSTATE_HORIZONAL;
|
||||
g_placementInfo.x = x;
|
||||
g_placementInfo.y = y;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void RocketGui_beginVerticalStackPanelXY(int x, int y)
|
||||
{
|
||||
g_placementInfo.state = PLACEMENTSTATE_VERTICAL;
|
||||
g_placementInfo.x = x;
|
||||
g_placementInfo.y = y;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void RocketGui_begin()
|
||||
{
|
||||
s_controlId = 1;
|
||||
g_controls[0].type = DRAWTYPE_NONE;
|
||||
memset(&g_placementInfo, 0, sizeof(GuiPlacementInfo));
|
||||
}
|
||||
|
||||
/*
|
||||
struct LoadedImages
|
||||
{
|
||||
char filename[PATH_MAX][MAX_IMAGES];
|
||||
RocketImage image[MAX_IMAGES];
|
||||
uint32_t count;
|
||||
} g_loadedImages;
|
||||
*/
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static bool RocketGui_regionHit(const RocketControlInfo* control)
|
||||
{
|
||||
printf("mouse %d %d\n", g_rocketGuiState.mousex, g_rocketGuiState.mousey);
|
||||
printf("control %d %d %d %d\n", control->x, control->y, control->width, control->height);
|
||||
|
||||
if (g_rocketGuiState.mousex < control->x ||
|
||||
g_rocketGuiState.mousey < control->y ||
|
||||
g_rocketGuiState.mousex >= control->x + control->width ||
|
||||
g_rocketGuiState.mousey >= control->y + control->height)
|
||||
{
|
||||
printf("false\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("true\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void initFont()
|
||||
{
|
||||
uint32_t i;
|
||||
uint32_t* fontData;
|
||||
uint32_t* tempColorData = fontData = (uint32_t*)malloc(128 * 128 * sizeof(uint32_t));
|
||||
const uint8_t* data = s_microkinghtFontData;
|
||||
|
||||
// Build new texture
|
||||
|
||||
const uint32_t fontColor = 0x7fffffff;
|
||||
|
||||
for (i = 0; i < (128 * 128) / 8; ++i)
|
||||
{
|
||||
uint8_t color = *data++;
|
||||
*tempColorData++ = ((color >> 7) & 1) ? fontColor : 0;
|
||||
*tempColorData++ = ((color >> 6) & 1) ? fontColor : 0;
|
||||
*tempColorData++ = ((color >> 5) & 1) ? fontColor : 0;
|
||||
*tempColorData++ = ((color >> 4) & 1) ? fontColor : 0;
|
||||
*tempColorData++ = ((color >> 3) & 1) ? fontColor : 0;
|
||||
*tempColorData++ = ((color >> 2) & 1) ? fontColor : 0;
|
||||
*tempColorData++ = ((color >> 1) & 1) ? fontColor : 0;
|
||||
*tempColorData++ = ((color >> 0) & 1) ? fontColor : 0;
|
||||
}
|
||||
|
||||
GFXBackend_setFont(fontData, 128, 128);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void RocketGui_init()
|
||||
{
|
||||
initFont();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void RocketGui_reset()
|
||||
{
|
||||
//memset(&g_loadedImages, 0, sizeof(struct LoadedImages)); // not really needed but good when debugging
|
||||
g_rocketGuiState.mousex = -1;
|
||||
g_rocketGuiState.mousey = -1;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
static RocketImage* loadImage(const char* filename)
|
||||
{
|
||||
uint32_t i;
|
||||
uint32_t index = g_loadedImages.count;
|
||||
|
||||
HIPPO_ASSERT(filename);
|
||||
|
||||
// TODO: Hash filenames?
|
||||
|
||||
for (i = 0; i != index; ++i)
|
||||
{
|
||||
if (!strcmp(filename, g_loadedImages.filename[i]))
|
||||
return &g_loadedImages.image[i];
|
||||
}
|
||||
|
||||
// Load new image
|
||||
|
||||
if (!RocketImageLoader_loadFile(&g_loadedImages.image[index], filename))
|
||||
{
|
||||
printf("Unable to load %s\n", filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
strcpy(g_loadedImages.filename[index], filename); g_loadedImages.count++;
|
||||
|
||||
return &g_loadedImages.image[index];
|
||||
}
|
||||
*/
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void updatePlacement()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static bool RocketGui_regionHitSlider(const RocketControlInfo* control)
|
||||
{
|
||||
if (g_rocketGuiState.mousex < control->sliderThumbX ||
|
||||
g_rocketGuiState.mousey < control->sliderThumbY ||
|
||||
g_rocketGuiState.mousex >= control->sliderThumbX + control->sliderThumbWidth ||
|
||||
g_rocketGuiState.mousey >= control->sliderThumbY + control->sliderThumbHeight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void RocketGui_drawBorder(uint32_t color0, uint32_t color1, int x, int y, int w, int h)
|
||||
{
|
||||
RocketGui_fill(color0, x, y, 1, h);
|
||||
RocketGui_fill(color0, x, y, w, 1);
|
||||
RocketGui_fill(color1, x + w, y, 1, h);
|
||||
RocketGui_fill(color1, x, y + h, w, 1);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void RocketGui_fill(uint32_t color, int x, int y, int w, int h)
|
||||
{
|
||||
uint32_t controlId = 0;
|
||||
RocketControlInfo* control = 0;
|
||||
|
||||
// Setup the control
|
||||
controlId = s_controlId++;
|
||||
control = &g_controls[controlId];
|
||||
control->type = DRAWTYPE_FILL;
|
||||
control->x = x;
|
||||
control->y = y;
|
||||
control->width = w;
|
||||
control->height = h;
|
||||
control->color = color;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void RocketGui_textLabelXY(const char* text, int x, int y)
|
||||
{
|
||||
uint32_t controlId = 0;
|
||||
RocketControlInfo* control = 0;
|
||||
|
||||
// Setup the control
|
||||
controlId = s_controlId++;
|
||||
control = &g_controls[controlId];
|
||||
control->type = DRAWTYPE_TEXT;
|
||||
control->color = 0;
|
||||
control->x = x;
|
||||
control->y = y;
|
||||
control->text = (char*)text;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
float floatClamp(float value, float low, float high)
|
||||
{
|
||||
if (value < low)
|
||||
value = low;
|
||||
|
||||
if (value > high)
|
||||
value = high;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool RocketGui_slider(int x, int y, int w, int h, int start, int end, enum RocketSliderDirection dir, int itemSpace, int* value)
|
||||
{
|
||||
int thumbPosition = 0;
|
||||
uint32_t controlId = 0;
|
||||
float thumbSize = 0.0f, range;
|
||||
RocketControlInfo* control = 0;
|
||||
|
||||
// Setup the control
|
||||
controlId = s_controlId++;
|
||||
control = &g_controls[controlId];
|
||||
control->type = DRAWTYPE_SLIDER;
|
||||
control->x = x;
|
||||
control->y = y;
|
||||
control->width = w;
|
||||
control->height = h;
|
||||
|
||||
// considering how much stuff we have have in the slider we need to calculate how much space the scolling area actually
|
||||
// is so we can resize the thumb
|
||||
|
||||
range = end - start;
|
||||
|
||||
if (dir == SLIDERDIRECTION_VERTICAL)
|
||||
{
|
||||
float v = *value;
|
||||
int itemsHeight = (end - start) * itemSpace;
|
||||
int sliderHeigthArea = h - y;
|
||||
|
||||
if (itemsHeight <= 0)
|
||||
itemsHeight = 1;
|
||||
|
||||
thumbPosition = y + ((v / range) * h);
|
||||
|
||||
thumbSize = (float)sliderHeigthArea / (float)itemsHeight;
|
||||
thumbSize = /*floatClamp(thumbSize, 0.05, 1.0f)*/ 1.0f * sliderHeigthArea;
|
||||
|
||||
control->sliderThumbX = x + 1;
|
||||
control->sliderThumbY = thumbPosition + 1;
|
||||
control->sliderThumbWidth = w - 1;
|
||||
control->sliderThumbHeight = (int)thumbSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
// handle Horizontal here:
|
||||
}
|
||||
|
||||
if (RocketGui_regionHitSlider(control))
|
||||
{
|
||||
g_rocketGuiState.hotItem = controlId;
|
||||
if (g_rocketGuiState.activeItem == 0 && g_rocketGuiState.mouseDown)
|
||||
g_rocketGuiState.activeItem = controlId;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
|
||||
if (g_rocketGuiState.activeItem == controlId)
|
||||
{
|
||||
if (dir == SLIDERDIRECTION_VERTICAL)
|
||||
{
|
||||
float mouseYrelative;
|
||||
int mousePos = g_rocketGuiState.mousey - (y + control->sliderThumbHeight / 2);
|
||||
int mouseYlimit = control->height - control->sliderThumbHeight;
|
||||
if (mousePos < 0) mousePos = 0;
|
||||
if (mousePos > mouseYlimit) mousePos = mouseYlimit;
|
||||
|
||||
mouseYrelative = (float)mousePos / (float)control->height;
|
||||
control->sliderThumbY = (int)(y + mouseYrelative * h);
|
||||
*value = start + (range * mouseYrelative);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
RocketControlInfo* RocketGui_textLabel(const char* text)
|
||||
{
|
||||
uint32_t controlId = 0;
|
||||
RocketControlInfo* control = 0;
|
||||
|
||||
// Setup the control
|
||||
controlId = s_controlId++;
|
||||
control = &g_controls[controlId];
|
||||
control->type = DRAWTYPE_TEXT;
|
||||
control->x = g_placementInfo.x;
|
||||
control->y = g_placementInfo.y;
|
||||
control->width = strlen(text) * 9; // fix me
|
||||
control->height = 9; // fixme
|
||||
control->text = (char*)text;
|
||||
control->color = 0;
|
||||
|
||||
switch (g_placementInfo.state)
|
||||
{
|
||||
case PLACEMENTSTATE_NONE :
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
case PLACEMENTSTATE_HORIZONAL :
|
||||
{
|
||||
g_placementInfo.x += control->width;
|
||||
break;
|
||||
}
|
||||
|
||||
case PLACEMENTSTATE_VERTICAL :
|
||||
{
|
||||
g_placementInfo.y += 9; // TODO: Use correct size from font
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return control;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static uint32_t genericImageControl(const char* filename)
|
||||
{
|
||||
uint32_t controlId = 0;
|
||||
RocketControlInfo* control = 0;
|
||||
struct RocketImage* image = 0; //loadImage(filename);
|
||||
|
||||
if (!image)
|
||||
return ~0;
|
||||
|
||||
// Setup the control
|
||||
|
||||
controlId = s_controlId++;
|
||||
control = &g_controls[controlId];
|
||||
control->type = DRAWTYPE_IMAGE;
|
||||
control->x = g_placementInfo.x;
|
||||
control->y = g_placementInfo.y;
|
||||
//control->width = image->width;
|
||||
//control->height = image->height;
|
||||
control->imageData = image;
|
||||
|
||||
updatePlacement();
|
||||
|
||||
switch (g_placementInfo.state)
|
||||
{
|
||||
case PLACEMENTSTATE_NONE :
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
case PLACEMENTSTATE_HORIZONAL :
|
||||
{
|
||||
//g_placementInfo.x += image->width;
|
||||
break;
|
||||
}
|
||||
|
||||
case PLACEMENTSTATE_VERTICAL :
|
||||
{
|
||||
//g_placementInfo.y += image->height;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return controlId;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void RocketGui_staticImage(const char* filename)
|
||||
{
|
||||
genericImageControl(filename);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
static void highlightControl(RocketControlInfo* control)
|
||||
{
|
||||
RocketGui_fill(0xb0ffffff, control->x, control->y, control->width, control->height);
|
||||
}
|
||||
*/
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool RocketGui_buttonImage(const char* filename)
|
||||
{
|
||||
RocketControlInfo* control;
|
||||
uint32_t controlId = 0;
|
||||
|
||||
controlId = genericImageControl(filename);
|
||||
|
||||
if (controlId == ~0)
|
||||
return false;
|
||||
|
||||
control = &g_controls[controlId];
|
||||
|
||||
if (RocketGui_regionHit(control))
|
||||
{
|
||||
g_rocketGuiState.hotItem = controlId;
|
||||
if (g_rocketGuiState.activeItem == 0 && g_rocketGuiState.mouseDown)
|
||||
g_rocketGuiState.activeItem = controlId;
|
||||
|
||||
//highlightControl(control);
|
||||
}
|
||||
|
||||
if (g_rocketGuiState.mouseDown == 0 && g_rocketGuiState.hotItem == controlId && g_rocketGuiState.activeItem == controlId)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool RocketGui_button(const char* text)
|
||||
{
|
||||
RocketControlInfo* control;
|
||||
uint32_t controlId = 0;
|
||||
|
||||
control = RocketGui_textLabel(text);
|
||||
controlId = s_controlId - 1;
|
||||
|
||||
if (controlId == ~0)
|
||||
return false;
|
||||
|
||||
control = &g_controls[controlId];
|
||||
|
||||
if (RocketGui_regionHit(control))
|
||||
{
|
||||
g_rocketGuiState.hotItem = controlId;
|
||||
if (g_rocketGuiState.activeItem == 0 && g_rocketGuiState.mouseDown)
|
||||
g_rocketGuiState.activeItem = controlId;
|
||||
|
||||
//highlightControl(control);
|
||||
}
|
||||
|
||||
if (g_rocketGuiState.mouseDown == 0 && g_rocketGuiState.hotItem == controlId && g_rocketGuiState.activeItem == controlId)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void RocketGui_end()
|
||||
{
|
||||
if (g_rocketGuiState.mouseDown == 0)
|
||||
{
|
||||
g_rocketGuiState.activeItem = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (g_rocketGuiState.activeItem == 0)
|
||||
g_rocketGuiState.activeItem = -1;
|
||||
}
|
||||
|
||||
GFXBackend_drawControls(&g_controls, s_controlId);
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <Core/Types.h>
|
||||
#include <emgui/Types.h>
|
||||
|
||||
struct RocketImage;
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#import "RocketView.h"
|
||||
#include "../Editor.h"
|
||||
#include <emgui/emgui.h>
|
||||
#include <Emgui.h>
|
||||
#include <GFXBackend.h>
|
||||
|
||||
@implementation RocketView
|
||||
|
||||
@ -122,7 +123,7 @@
|
||||
Emgui_setMousePos((int)location.x, (int)originalFrame.size.height - (int)location.y);
|
||||
Emgui_setMouseLmb(1);
|
||||
|
||||
Editor_guiUpdate();
|
||||
Editor_update();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -136,7 +137,7 @@
|
||||
|
||||
-(void) dealloc
|
||||
{
|
||||
Example_destroy();
|
||||
Editor_destroy();
|
||||
EMGFXBackend_destroy();
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
38
units.lua
38
units.lua
@ -25,6 +25,38 @@ StaticLibrary {
|
||||
}
|
||||
|
||||
StaticLibrary {
|
||||
Name = "emgui",
|
||||
|
||||
Env = {
|
||||
CPPPATH = { ".", "../../emgui/src", "../../../../emgui/src" },
|
||||
PROGOPTS = {
|
||||
{ "/SUBSYSTEM:WINDOWS", "/DEBUG"; Config = { "win32-*-*", "win64-*-*" } },
|
||||
},
|
||||
|
||||
CPPDEFS = {
|
||||
{ "EMGUI_MACOSX", Config = "macosx-*-*" },
|
||||
{ "EMGUI_WINDOWS"; Config = { "win32-*-*", "win64-*-*" } },
|
||||
},
|
||||
|
||||
CCOPTS = {
|
||||
{ "-Werror", "-pedantic-errors", "-Wall"; Config = "macosx-clang-*" },
|
||||
},
|
||||
},
|
||||
|
||||
Sources = {
|
||||
FGlob {
|
||||
Dir = "../emgui/src",
|
||||
Extensions = { ".c" },
|
||||
Filters = {
|
||||
{ Pattern = "macosx"; Config = "macosx-*-*" },
|
||||
{ Pattern = "windows"; Config = { "win32-*-*", "win64-*-*" } },
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
StaticLibrary {
|
||||
Name = "sync",
|
||||
|
||||
Sources = {
|
||||
@ -40,13 +72,13 @@ Program {
|
||||
Name = "editor",
|
||||
|
||||
Env = {
|
||||
CPPPATH = { ".", "ogl_editor/src" },
|
||||
CPPPATH = { ".", "ogl_editor/src", "../emgui/src", "../../../../../emgui/src" },
|
||||
PROGOPTS = {
|
||||
{ "/SUBSYSTEM:WINDOWS", "/DEBUG"; Config = { "win32-*-*", "win64-*-*" } },
|
||||
},
|
||||
|
||||
CPPDEFS = {
|
||||
{ "ROCKETGUI_MACOSX", Config = "macosx-*-*" },
|
||||
{ "EMGUI_MACOSX", Config = "macosx-*-*" },
|
||||
{ "ROCKETGUI_WIN32"; Config = { "win32-*-*", "win64-*-*" } },
|
||||
},
|
||||
|
||||
@ -55,7 +87,7 @@ Program {
|
||||
},
|
||||
},
|
||||
|
||||
Depends = { "sync", "mxml" },
|
||||
Depends = { "sync", "mxml", "emgui" },
|
||||
|
||||
Frameworks = { "Cocoa", "OpenGL" },
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user