mirror of
https://github.com/Drezil/imgui.git
synced 2024-12-18 14:16:36 +00:00
Example: Marmalade: shallow tweaks and cleanups to match ImGui coding style (#375)
This commit is contained in:
parent
81927b073e
commit
2b3fb5c0f7
@ -1,6 +1,9 @@
|
|||||||
// ImGui Marmalade binding with IwGx
|
// ImGui Marmalade binding with IwGx
|
||||||
// Copyright (C) 2015 by Giovanni Zito
|
// Copyright (C) 2015 by Giovanni Zito
|
||||||
// This file is part of ImGui
|
// This file is part of ImGui
|
||||||
|
// You can copy and use unmodified imgui_impl_* files in your project.
|
||||||
|
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown().
|
||||||
|
// See main.cpp for an example of using this.
|
||||||
// https://github.com/ocornut/imgui
|
// https://github.com/ocornut/imgui
|
||||||
|
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
@ -16,8 +19,8 @@
|
|||||||
static double g_Time = 0.0f;
|
static double g_Time = 0.0f;
|
||||||
static bool g_MousePressed[3] = { false, false, false };
|
static bool g_MousePressed[3] = { false, false, false };
|
||||||
static float g_MouseWheel = 0.0f;
|
static float g_MouseWheel = 0.0f;
|
||||||
static CIwTexture* g_FontTexture = 0;
|
static CIwTexture* g_FontTexture = NULL;
|
||||||
static char* g_ClipboardText = 0 ;
|
static char* g_ClipboardText = NULL;
|
||||||
static bool g_osdKeyboardEnabled = false;
|
static bool g_osdKeyboardEnabled = false;
|
||||||
|
|
||||||
// use this setting to scale the interface - e.g. on device you could use 2 or 3 scale factor
|
// use this setting to scale the interface - e.g. on device you could use 2 or 3 scale factor
|
||||||
@ -41,8 +44,9 @@ void ImGui_Marmalade_RenderDrawLists(ImDrawData* draw_data)
|
|||||||
CIwFVec2* pUVStream = IW_GX_ALLOC(CIwFVec2, nVert);
|
CIwFVec2* pUVStream = IW_GX_ALLOC(CIwFVec2, nVert);
|
||||||
CIwColour* pColStream = IW_GX_ALLOC(CIwColour, nVert);
|
CIwColour* pColStream = IW_GX_ALLOC(CIwColour, nVert);
|
||||||
|
|
||||||
for( int i=0; i < nVert; i++ ) {
|
for( int i=0; i < nVert; i++ )
|
||||||
// todo - optimize multiplication on gpu using vertex shader
|
{
|
||||||
|
// TODO: optimize multiplication on gpu using vertex shader
|
||||||
pVertStream[i].x = cmd_list->VtxBuffer[i].pos.x * g_scale.x;
|
pVertStream[i].x = cmd_list->VtxBuffer[i].pos.x * g_scale.x;
|
||||||
pVertStream[i].y = cmd_list->VtxBuffer[i].pos.y * g_scale.y;
|
pVertStream[i].y = cmd_list->VtxBuffer[i].pos.y * g_scale.y;
|
||||||
pUVStream[i].x = cmd_list->VtxBuffer[i].uv.x;
|
pUVStream[i].x = cmd_list->VtxBuffer[i].uv.x;
|
||||||
@ -73,7 +77,6 @@ void ImGui_Marmalade_RenderDrawLists(ImDrawData* draw_data)
|
|||||||
pCurrentMaterial->SetAlphaTestMode(CIwMaterial::ALPHATEST_DISABLED);
|
pCurrentMaterial->SetAlphaTestMode(CIwMaterial::ALPHATEST_DISABLED);
|
||||||
pCurrentMaterial->SetTexture((CIwTexture*)pcmd->TextureId);
|
pCurrentMaterial->SetTexture((CIwTexture*)pcmd->TextureId);
|
||||||
IwGxSetMaterial(pCurrentMaterial);
|
IwGxSetMaterial(pCurrentMaterial);
|
||||||
|
|
||||||
IwGxDrawPrims(IW_GX_TRI_LIST, (uint16*)idx_buffer, pcmd->ElemCount);
|
IwGxDrawPrims(IW_GX_TRI_LIST, (uint16*)idx_buffer, pcmd->ElemCount);
|
||||||
}
|
}
|
||||||
idx_buffer += pcmd->ElemCount;
|
idx_buffer += pcmd->ElemCount;
|
||||||
@ -81,18 +84,20 @@ void ImGui_Marmalade_RenderDrawLists(ImDrawData* draw_data)
|
|||||||
IwGxFlush();
|
IwGxFlush();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO restore modified state (i.e. mvp matrix)
|
// TODO: restore modified state (i.e. mvp matrix)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static const char* ImGui_Marmalade_GetClipboardText()
|
static const char* ImGui_Marmalade_GetClipboardText()
|
||||||
{
|
{
|
||||||
if(s3eClipboardAvailable()) {
|
if (s3eClipboardAvailable())
|
||||||
|
{
|
||||||
int size = s3eClipboardGetText(NULL, 0);
|
int size = s3eClipboardGetText(NULL, 0);
|
||||||
if( size > 0 ) {
|
if (size > 0)
|
||||||
if(g_ClipboardText) {
|
{
|
||||||
|
if (g_ClipboardText)
|
||||||
|
{
|
||||||
delete[] g_ClipboardText;
|
delete[] g_ClipboardText;
|
||||||
g_ClipboardText = 0 ;
|
g_ClipboardText = NULL;
|
||||||
}
|
}
|
||||||
g_ClipboardText = new char[size];
|
g_ClipboardText = new char[size];
|
||||||
g_ClipboardText[0] = '\0';
|
g_ClipboardText[0] = '\0';
|
||||||
@ -105,54 +110,42 @@ static const char* ImGui_Marmalade_GetClipboardText()
|
|||||||
|
|
||||||
static void ImGui_Marmalade_SetClipboardText(const char* text)
|
static void ImGui_Marmalade_SetClipboardText(const char* text)
|
||||||
{
|
{
|
||||||
if( s3eClipboardAvailable() ) {
|
if (s3eClipboardAvailable())
|
||||||
s3eClipboardSetText(text);
|
s3eClipboardSetText(text);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
int32 ImGui_Marmalade_PointerButtonEventCallback(void* SystemData, void* pUserData)
|
int32 ImGui_Marmalade_PointerButtonEventCallback(void* SystemData, void* pUserData)
|
||||||
{
|
{
|
||||||
// pEvent->m_Button is of type s3ePointerButton and indicates which mouse
|
// pEvent->m_Button is of type s3ePointerButton and indicates which mouse
|
||||||
// button was pressed. For touchscreens this should always have the value
|
// button was pressed. For touchscreen this should always have the value
|
||||||
// S3E_POINTER_BUTTON_SELECT
|
// S3E_POINTER_BUTTON_SELECT
|
||||||
s3ePointerEvent* pEvent = (s3ePointerEvent*)SystemData;
|
s3ePointerEvent* pEvent = (s3ePointerEvent*)SystemData;
|
||||||
|
|
||||||
if(pEvent->m_Pressed==1) {
|
if (pEvent->m_Pressed == 1)
|
||||||
if(pEvent->m_Button == S3E_POINTER_BUTTON_LEFTMOUSE) {
|
{
|
||||||
|
if (pEvent->m_Button == S3E_POINTER_BUTTON_LEFTMOUSE)
|
||||||
g_MousePressed[0] = true;
|
g_MousePressed[0] = true;
|
||||||
}
|
if (pEvent->m_Button == S3E_POINTER_BUTTON_RIGHTMOUSE)
|
||||||
if(pEvent->m_Button == S3E_POINTER_BUTTON_RIGHTMOUSE) {
|
|
||||||
g_MousePressed[1] = true;
|
g_MousePressed[1] = true;
|
||||||
}
|
if (pEvent->m_Button == S3E_POINTER_BUTTON_MIDDLEMOUSE)
|
||||||
if(pEvent->m_Button == S3E_POINTER_BUTTON_MIDDLEMOUSE) {
|
|
||||||
g_MousePressed[2] = true;
|
g_MousePressed[2] = true;
|
||||||
}
|
if (pEvent->m_Button == S3E_POINTER_BUTTON_MOUSEWHEELUP)
|
||||||
if(pEvent->m_Button == S3E_POINTER_BUTTON_MOUSEWHEELUP) {
|
|
||||||
g_MouseWheel += pEvent->m_y;
|
g_MouseWheel += pEvent->m_y;
|
||||||
}
|
if (pEvent->m_Button == S3E_POINTER_BUTTON_MOUSEWHEELDOWN)
|
||||||
if(pEvent->m_Button == S3E_POINTER_BUTTON_MOUSEWHEELDOWN) {
|
|
||||||
g_MouseWheel += pEvent->m_y;
|
g_MouseWheel += pEvent->m_y;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//void ImGui_Marmalade_ScrollCallback(double /*xoffset*/,double yoffset)
|
|
||||||
//{
|
|
||||||
// g_MouseWheel += (float)yoffset; // Use fractional mouse wheel, 1.0 unit 5 lines.
|
|
||||||
//}
|
|
||||||
|
|
||||||
int32 ImGui_Marmalade_KeyCallback(void* SystemData, void* userData)
|
int32 ImGui_Marmalade_KeyCallback(void* SystemData, void* userData)
|
||||||
{
|
{
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
s3eKeyboardEvent* e = (s3eKeyboardEvent*)SystemData;
|
s3eKeyboardEvent* e = (s3eKeyboardEvent*)SystemData;
|
||||||
if( e->m_Pressed == 1 ) {
|
if (e->m_Pressed == 1)
|
||||||
io.KeysDown[e->m_Key] = true;
|
io.KeysDown[e->m_Key] = true;
|
||||||
}
|
if (e->m_Pressed == 0)
|
||||||
if(e->m_Pressed == 0) {
|
|
||||||
io.KeysDown[e->m_Key] = false;
|
io.KeysDown[e->m_Key] = false;
|
||||||
}
|
|
||||||
|
|
||||||
io.KeyCtrl = s3eKeyboardGetState(s3eKeyLeftControl) == S3E_KEY_STATE_DOWN || s3eKeyboardGetState(s3eKeyRightControl) == S3E_KEY_STATE_DOWN;
|
io.KeyCtrl = s3eKeyboardGetState(s3eKeyLeftControl) == S3E_KEY_STATE_DOWN || s3eKeyboardGetState(s3eKeyRightControl) == S3E_KEY_STATE_DOWN;
|
||||||
io.KeyShift = s3eKeyboardGetState(s3eKeyLeftShift) == S3E_KEY_STATE_DOWN || s3eKeyboardGetState(s3eKeyRightShift) == S3E_KEY_STATE_DOWN;
|
io.KeyShift = s3eKeyboardGetState(s3eKeyLeftShift) == S3E_KEY_STATE_DOWN || s3eKeyboardGetState(s3eKeyRightShift) == S3E_KEY_STATE_DOWN;
|
||||||
@ -164,11 +157,9 @@ int32 ImGui_Marmalade_KeyCallback(void* SystemData, void* userData)
|
|||||||
int32 ImGui_Marmalade_CharCallback(void* SystemData, void* userData)
|
int32 ImGui_Marmalade_CharCallback(void* SystemData, void* userData)
|
||||||
{
|
{
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
||||||
s3eKeyboardCharEvent* e = (s3eKeyboardCharEvent*)SystemData;
|
s3eKeyboardCharEvent* e = (s3eKeyboardCharEvent*)SystemData;
|
||||||
if( (e->m_Char > 0 && e->m_Char < 0x10000) ) {
|
if ((e->m_Char > 0 && e->m_Char < 0x10000))
|
||||||
io.AddInputCharacter((unsigned short)e->m_Char);
|
io.AddInputCharacter((unsigned short)e->m_Char);
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -207,16 +198,17 @@ bool ImGui_Marmalade_CreateDeviceObjects()
|
|||||||
|
|
||||||
void ImGui_Marmalade_InvalidateDeviceObjects()
|
void ImGui_Marmalade_InvalidateDeviceObjects()
|
||||||
{
|
{
|
||||||
if(g_ClipboardText) {
|
if (g_ClipboardText)
|
||||||
|
{
|
||||||
delete[] g_ClipboardText;
|
delete[] g_ClipboardText;
|
||||||
g_ClipboardText = 0 ;
|
g_ClipboardText = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_FontTexture)
|
if (g_FontTexture)
|
||||||
{
|
{
|
||||||
delete g_FontTexture;
|
delete g_FontTexture;
|
||||||
ImGui::GetIO().Fonts->TexID = 0;
|
ImGui::GetIO().Fonts->TexID = 0;
|
||||||
g_FontTexture = 0;
|
g_FontTexture = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,9 +260,8 @@ void ImGui_Marmalade_Shutdown()
|
|||||||
|
|
||||||
void ImGui_Marmalade_NewFrame()
|
void ImGui_Marmalade_NewFrame()
|
||||||
{
|
{
|
||||||
if (!g_FontTexture) {
|
if (!g_FontTexture)
|
||||||
ImGui_Marmalade_CreateDeviceObjects();
|
ImGui_Marmalade_CreateDeviceObjects();
|
||||||
}
|
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
||||||
@ -290,7 +281,8 @@ void ImGui_Marmalade_NewFrame()
|
|||||||
mouse_y = s3ePointerGetY();
|
mouse_y = s3ePointerGetY();
|
||||||
io.MousePos = ImVec2((float)mouse_x/g_scale.x, (float)mouse_y/g_scale.y); // Mouse position in screen coordinates (set to -1,-1 if no mouse / on another screen, etc.)
|
io.MousePos = ImVec2((float)mouse_x/g_scale.x, (float)mouse_y/g_scale.y); // Mouse position in screen coordinates (set to -1,-1 if no mouse / on another screen, etc.)
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
io.MouseDown[i] = g_MousePressed[i] || s3ePointerGetState((s3ePointerButton)i) != S3E_POINTER_STATE_UP; // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame.
|
io.MouseDown[i] = g_MousePressed[i] || s3ePointerGetState((s3ePointerButton)i) != S3E_POINTER_STATE_UP; // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame.
|
||||||
g_MousePressed[i] = false;
|
g_MousePressed[i] = false;
|
||||||
}
|
}
|
||||||
@ -298,21 +290,27 @@ void ImGui_Marmalade_NewFrame()
|
|||||||
io.MouseWheel = g_MouseWheel;
|
io.MouseWheel = g_MouseWheel;
|
||||||
g_MouseWheel = 0.0f;
|
g_MouseWheel = 0.0f;
|
||||||
|
|
||||||
// Hide OS mouse cursor if ImGui is drawing it
|
// TODO: Hide OS mouse cursor if ImGui is drawing it
|
||||||
// s3ePointerSetInt(S3E_POINTER_HIDE_CURSOR,(io.MouseDrawCursor ? 0 : 1));
|
// s3ePointerSetInt(S3E_POINTER_HIDE_CURSOR,(io.MouseDrawCursor ? 0 : 1));
|
||||||
|
|
||||||
// Start the frame
|
// Start the frame
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
// show/hide OSD keyboard
|
// Show/hide OSD keyboard
|
||||||
if( io.WantTextInput ) { // some text input widget is active?
|
if (io.WantTextInput)
|
||||||
if( !g_osdKeyboardEnabled ) {
|
{
|
||||||
|
// Some text input widget is active?
|
||||||
|
if (!g_osdKeyboardEnabled)
|
||||||
|
{
|
||||||
g_osdKeyboardEnabled = true;
|
g_osdKeyboardEnabled = true;
|
||||||
s3eKeyboardSetInt(S3E_KEYBOARD_GET_CHAR, 1); // show OSD keyboard
|
s3eKeyboardSetInt(S3E_KEYBOARD_GET_CHAR, 1); // show OSD keyboard
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else { // no text input widget is active
|
else
|
||||||
if(g_osdKeyboardEnabled) {
|
{
|
||||||
|
// No text input widget is active
|
||||||
|
if (g_osdKeyboardEnabled)
|
||||||
|
{
|
||||||
g_osdKeyboardEnabled = false;
|
g_osdKeyboardEnabled = false;
|
||||||
s3eKeyboardSetInt(S3E_KEYBOARD_GET_CHAR, 0); // hide OSD keyboard
|
s3eKeyboardSetInt(S3E_KEYBOARD_GET_CHAR, 0); // hide OSD keyboard
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
// ImGui Marmalade binding with IwGx
|
// ImGui Marmalade binding with IwGx
|
||||||
// Copyright (C) 2015 by Giovanni Zito
|
// Copyright (C) 2015 by Giovanni Zito
|
||||||
// This file is part of ImGui
|
// This file is part of ImGui
|
||||||
|
// You can copy and use unmodified imgui_impl_* files in your project.
|
||||||
|
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown().
|
||||||
|
// See main.cpp for an example of using this.
|
||||||
// https://github.com/ocornut/imgui
|
// https://github.com/ocornut/imgui
|
||||||
|
|
||||||
IMGUI_API bool ImGui_Marmalade_Init(bool install_callbacks);
|
IMGUI_API bool ImGui_Marmalade_Init(bool install_callbacks);
|
||||||
@ -14,6 +17,5 @@ IMGUI_API bool ImGui_Marmalade_CreateDeviceObjects();
|
|||||||
// callbacks (installed by default if you enable 'install_callbacks' during initialization)
|
// callbacks (installed by default if you enable 'install_callbacks' during initialization)
|
||||||
// You can also handle inputs yourself and use those as a reference.
|
// You can also handle inputs yourself and use those as a reference.
|
||||||
IMGUI_API int32 ImGui_Marmalade_PointerButtonEventCallback(void* SystemData, void* pUserData);
|
IMGUI_API int32 ImGui_Marmalade_PointerButtonEventCallback(void* SystemData, void* pUserData);
|
||||||
//IMGUI_API void ImGui_Marmalade_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
|
|
||||||
IMGUI_API int32 ImGui_Marmalade_KeyCallback(void* SystemData, void* userData);
|
IMGUI_API int32 ImGui_Marmalade_KeyCallback(void* SystemData, void* userData);
|
||||||
IMGUI_API int32 ImGui_Marmalade_CharCallback(void* SystemData, void* userData);
|
IMGUI_API int32 ImGui_Marmalade_CharCallback(void* SystemData, void* userData);
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
#include <s3ePointer.h>
|
#include <s3ePointer.h>
|
||||||
#include <IwGx.h>
|
#include <IwGx.h>
|
||||||
|
|
||||||
|
|
||||||
int main(int, char**)
|
int main(int, char**)
|
||||||
{
|
{
|
||||||
// Setup ImGui binding
|
// Setup ImGui binding
|
||||||
|
Loading…
Reference in New Issue
Block a user