mirror of
https://github.com/aap/librw.git
synced 2026-04-16 19:39:02 +01:00
little cleanup and mousewheel support for skeleton
This commit is contained in:
@@ -182,7 +182,7 @@ mousebtn(GLFWwindow *window, int button, int action, int mods)
|
||||
{
|
||||
static int buttons = 0;
|
||||
sk::MouseState ms;
|
||||
|
||||
|
||||
switch(button){
|
||||
case GLFW_MOUSE_BUTTON_LEFT:
|
||||
if(action == GLFW_PRESS)
|
||||
@@ -208,6 +208,14 @@ mousebtn(GLFWwindow *window, int button, int action, int mods)
|
||||
EventHandler(MOUSEBTN, &ms);
|
||||
}
|
||||
|
||||
static void
|
||||
mousewheel(GLFWwindow *window, double x, double y)
|
||||
{
|
||||
sk::MouseState ms;
|
||||
ms.wheelDelta = y;
|
||||
EventHandler(MOUSEWHEEL, &ms);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
@@ -231,6 +239,7 @@ main(int argc, char *argv[])
|
||||
glfwSetWindowSizeCallback(window, resize);
|
||||
glfwSetCursorPosCallback(window, mousemove);
|
||||
glfwSetMouseButtonCallback(window, mousebtn);
|
||||
glfwSetScrollCallback(window, mousewheel);
|
||||
|
||||
float lastTime = glfwGetTime()*1000;
|
||||
while(!sk::globals.quit && !glfwWindowShouldClose(window)){
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#define WITH_D3D
|
||||
#include <rw.h>
|
||||
#include <skeleton.h>
|
||||
#include <assert.h>
|
||||
@@ -11,6 +12,35 @@ static rw::Texture *g_FontTexture;
|
||||
static Im2DVertex *g_vertbuf;
|
||||
static int g_vertbufSize;
|
||||
|
||||
// TODO: scissor from librw itself
|
||||
static void
|
||||
SetClip(const ImVec4 &clip)
|
||||
{
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
float x1 = clip.x; float y1 = clip.y;
|
||||
float x2 = clip.z; float y2 = clip.w;
|
||||
#ifdef RW_OPENGL
|
||||
glScissor(x1, io.DisplaySize.y-y2, x2-x1, y2-y1);
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
#endif
|
||||
#ifdef RW_D3D9
|
||||
rw::d3d::d3ddevice->SetRenderState(D3DRS_SCISSORTESTENABLE, 1);
|
||||
RECT r = { (LONG)x1, (LONG)y1, (LONG)x2, (LONG)y2 };
|
||||
rw::d3d::d3ddevice->SetScissorRect(&r);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
DisableClip(void)
|
||||
{
|
||||
#ifdef RW_OPENGL
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
#endif
|
||||
#ifdef RW_D3D9
|
||||
rw::d3d::d3ddevice->SetRenderState(D3DRS_SCISSORTESTENABLE, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
ImGui_ImplRW_RenderDrawLists(ImDrawData* draw_data)
|
||||
{
|
||||
@@ -88,9 +118,12 @@ ImGui_ImplRW_RenderDrawLists(ImDrawData* draw_data)
|
||||
rw::SetRenderState(rw::TEXTUREFILTER, tex->getFilter());
|
||||
}else
|
||||
rw::SetRenderStatePtr(rw::TEXTURERASTER, nil);
|
||||
|
||||
SetClip(pcmd->ClipRect);
|
||||
rw::im2d::RenderIndexedPrimitive(rw::PRIMTYPETRILIST,
|
||||
g_vertbuf+vtx_offset, cmd_list->VtxBuffer.Size,
|
||||
cmd_list->IdxBuffer.Data+idx_offset, pcmd->ElemCount);
|
||||
DisableClip();
|
||||
}
|
||||
idx_offset += pcmd->ElemCount;
|
||||
}
|
||||
@@ -141,7 +174,7 @@ ImGui_ImplRW_CreateFontsTexture()
|
||||
g_FontTexture = rw::Texture::create(rw::Raster::createFromImage(image));
|
||||
g_FontTexture->setFilter(rw::Texture::LINEAR);
|
||||
image->destroy();
|
||||
|
||||
|
||||
// Store our identifier
|
||||
io.Fonts->TexID = (void*)g_FontTexture;
|
||||
|
||||
@@ -151,8 +184,6 @@ ImGui_ImplRW_CreateFontsTexture()
|
||||
bool
|
||||
ImGui_ImplRW_CreateDeviceObjects()
|
||||
{
|
||||
// if(!g_pd3dDevice)
|
||||
// return false;
|
||||
if(!ImGui_ImplRW_CreateFontsTexture())
|
||||
return false;
|
||||
return true;
|
||||
@@ -285,10 +316,10 @@ ImGuiEventHandler(sk::Event e, void *param)
|
||||
|
||||
switch(e){
|
||||
case KEYDOWN:
|
||||
io.AddKeyEvent(SkKeyToImGuiKey(*(int*)param), true);
|
||||
io.AddKeyEvent(SkKeyToImGuiKey(*(int*)param), true);
|
||||
return EVENTPROCESSED;
|
||||
case KEYUP:
|
||||
io.AddKeyEvent(SkKeyToImGuiKey(*(int*)param), false);
|
||||
io.AddKeyEvent(SkKeyToImGuiKey(*(int*)param), false);
|
||||
return EVENTPROCESSED;
|
||||
case CHARINPUT:
|
||||
c = (uint)(uintptr)param;
|
||||
@@ -305,6 +336,10 @@ ImGuiEventHandler(sk::Event e, void *param)
|
||||
io.MouseDown[2] = !!(ms->buttons & 2);
|
||||
io.MouseDown[1] = !!(ms->buttons & 4);
|
||||
return EVENTPROCESSED;
|
||||
case MOUSEWHEEL:
|
||||
ms = (MouseState*)param;
|
||||
io.MouseWheel += ms->wheelDelta;
|
||||
return EVENTPROCESSED;
|
||||
}
|
||||
return EVENTPROCESSED;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ InitRW(void)
|
||||
n = Engine::getNumSubSystems();
|
||||
for(i = 0; i < n; i++)
|
||||
if(Engine::getSubSystemInfo(&info, i))
|
||||
printf("subsystem: %s\n", info.name);
|
||||
;//printf("subsystem: %s\n", info.name);
|
||||
Engine::setSubSystem(n-1);
|
||||
|
||||
int want = -1;
|
||||
@@ -34,7 +34,7 @@ InitRW(void)
|
||||
// if(mode.width == 640 && mode.height == 480 && mode.depth == 32)
|
||||
if(mode.width == 1920 && mode.height == 1080 && mode.depth == 32)
|
||||
want = i;
|
||||
printf("mode: %dx%dx%d %d\n", mode.width, mode.height, mode.depth, mode.flags);
|
||||
//printf("mode: %dx%dx%d %d\n", mode.width, mode.height, mode.depth, mode.flags);
|
||||
}
|
||||
// if(want >= 0) Engine::setVideoMode(want);
|
||||
Engine::getVideoModeInfo(&mode, Engine::getCurrentVideoMode());
|
||||
|
||||
@@ -72,6 +72,7 @@ enum Event
|
||||
CHARINPUT,
|
||||
MOUSEMOVE,
|
||||
MOUSEBTN,
|
||||
MOUSEWHEEL,
|
||||
RESIZE,
|
||||
IDLE,
|
||||
QUIT
|
||||
@@ -91,6 +92,7 @@ struct MouseState
|
||||
{
|
||||
int posx, posy;
|
||||
int buttons; // bits 0-2 are left, middle, right button down
|
||||
float wheelDelta;
|
||||
};
|
||||
|
||||
struct Args
|
||||
|
||||
@@ -135,6 +135,10 @@ WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
ms.buttons = buttons;
|
||||
EventHandler(MOUSEBTN, &ms);
|
||||
break;
|
||||
case WM_MOUSEWHEEL:
|
||||
ms.wheelDelta = (float)GET_WHEEL_DELTA_WPARAM(wParam) / (float)WHEEL_DELTA;
|
||||
EventHandler(MOUSEWHEEL, &ms);
|
||||
break;
|
||||
|
||||
case WM_SIZE:
|
||||
rw::Rect r;
|
||||
|
||||
@@ -1596,7 +1596,7 @@ startSDL2(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("OpenGL version: %s\n", glGetString(GL_VERSION));
|
||||
// printf("OpenGL version: %s\n", glGetString(GL_VERSION));
|
||||
|
||||
glGlobals.window = win;
|
||||
glGlobals.glcontext = ctx;
|
||||
@@ -1763,7 +1763,7 @@ startSDL3(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("OpenGL version: %s\n", glGetString(GL_VERSION));
|
||||
// printf("OpenGL version: %s\n", glGetString(GL_VERSION));
|
||||
|
||||
glGlobals.window = win;
|
||||
glGlobals.glcontext = ctx;
|
||||
@@ -1929,7 +1929,7 @@ startGLFW(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("OpenGL version: %s\n", glGetString(GL_VERSION));
|
||||
// printf("OpenGL version: %s\n", glGetString(GL_VERSION));
|
||||
|
||||
glGlobals.window = win;
|
||||
*glGlobals.pWindow = win;
|
||||
|
||||
Reference in New Issue
Block a user