mirror of
https://gitlab.com/shinovon/re3-symbian.git
synced 2026-05-23 01:57:21 +03:00
Initial commit
This commit is contained in:
commit
77cdaaf97e
827 changed files with 418745 additions and 0 deletions
80
vendor/librw/skeleton/CMakeLists.txt
vendored
Normal file
80
vendor/librw/skeleton/CMakeLists.txt
vendored
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
add_library(librw_skeleton
|
||||
glfw.cpp
|
||||
sdl2.cpp
|
||||
skeleton.cpp
|
||||
skeleton.h
|
||||
win.cpp
|
||||
|
||||
imgui/imgui_impl_rw.cpp
|
||||
imgui/imgui_impl_rw.h
|
||||
|
||||
imgui/imconfig.h
|
||||
imgui/imgui.cpp
|
||||
imgui/imgui.h
|
||||
imgui/imgui_demo.cpp
|
||||
imgui/imgui_draw.cpp
|
||||
imgui/imgui_internal.h
|
||||
imgui/imgui_tables.cpp
|
||||
imgui/imgui_widgets.cpp
|
||||
imgui/imstb_rectpack.h
|
||||
imgui/imstb_textedit.h
|
||||
imgui/imstb_truetype.h
|
||||
|
||||
imgui/ImGuizmo.cpp
|
||||
imgui/ImGuizmo.h
|
||||
)
|
||||
add_library(librw::skeleton ALIAS librw_skeleton)
|
||||
|
||||
set_target_properties(librw_skeleton
|
||||
PROPERTIES
|
||||
PREFIX ""
|
||||
EXPORT_NAME skeleton
|
||||
CXX_STANDARD 11
|
||||
)
|
||||
|
||||
target_link_libraries(librw_skeleton
|
||||
PRIVATE
|
||||
librw
|
||||
)
|
||||
|
||||
target_include_directories(librw_skeleton
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
||||
$<INSTALL_INTERFACE:${LIBRW_INSTALL_INCLUDEDIR}/skeleton>
|
||||
)
|
||||
|
||||
if(LIBRW_INSTALL)
|
||||
install(
|
||||
FILES
|
||||
skeleton.h
|
||||
DESTINATION "${LIBRW_INSTALL_INCLUDEDIR}/skeleton"
|
||||
)
|
||||
|
||||
install(
|
||||
FILES
|
||||
imgui/imconfig.h
|
||||
imgui/imgui.h
|
||||
imgui/imgui_impl_rw.h
|
||||
imgui/imgui_internal.h
|
||||
imgui/ImGuizmo.h
|
||||
imgui/imstb_rectpack.h
|
||||
imgui/imstb_textedit.h
|
||||
imgui/imstb_truetype.h
|
||||
DESTINATION "${LIBRW_INSTALL_INCLUDEDIR}/skeleton/imgui"
|
||||
)
|
||||
|
||||
install(
|
||||
FILES
|
||||
imgui/LICENSE_imgui.txt
|
||||
imgui/LICENSE_imguizmo.txt
|
||||
DESTINATION "${CMAKE_INSTALL_DOCDIR}"
|
||||
)
|
||||
|
||||
install(
|
||||
TARGETS librw_skeleton
|
||||
EXPORT librw-targets
|
||||
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
|
||||
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||
)
|
||||
endif()
|
||||
262
vendor/librw/skeleton/glfw.cpp
vendored
Normal file
262
vendor/librw/skeleton/glfw.cpp
vendored
Normal file
|
|
@ -0,0 +1,262 @@
|
|||
#ifndef LIBRW_SDL2
|
||||
|
||||
#include <rw.h>
|
||||
#include "skeleton.h"
|
||||
|
||||
using namespace sk;
|
||||
using namespace rw;
|
||||
|
||||
#ifdef RW_OPENGL
|
||||
|
||||
GLFWwindow *window;
|
||||
int keymap[GLFW_KEY_LAST+1];
|
||||
|
||||
static void
|
||||
initkeymap(void)
|
||||
{
|
||||
int i;
|
||||
for(i = 0; i < GLFW_KEY_LAST+1; i++)
|
||||
keymap[i] = KEY_NULL;
|
||||
keymap[GLFW_KEY_SPACE] = ' ';
|
||||
keymap[GLFW_KEY_APOSTROPHE] = '\'';
|
||||
keymap[GLFW_KEY_COMMA] = ',';
|
||||
keymap[GLFW_KEY_MINUS] = '-';
|
||||
keymap[GLFW_KEY_PERIOD] = '.';
|
||||
keymap[GLFW_KEY_SLASH] = '/';
|
||||
keymap[GLFW_KEY_0] = '0';
|
||||
keymap[GLFW_KEY_1] = '1';
|
||||
keymap[GLFW_KEY_2] = '2';
|
||||
keymap[GLFW_KEY_3] = '3';
|
||||
keymap[GLFW_KEY_4] = '4';
|
||||
keymap[GLFW_KEY_5] = '5';
|
||||
keymap[GLFW_KEY_6] = '6';
|
||||
keymap[GLFW_KEY_7] = '7';
|
||||
keymap[GLFW_KEY_8] = '8';
|
||||
keymap[GLFW_KEY_9] = '9';
|
||||
keymap[GLFW_KEY_SEMICOLON] = ';';
|
||||
keymap[GLFW_KEY_EQUAL] = '=';
|
||||
keymap[GLFW_KEY_A] = 'A';
|
||||
keymap[GLFW_KEY_B] = 'B';
|
||||
keymap[GLFW_KEY_C] = 'C';
|
||||
keymap[GLFW_KEY_D] = 'D';
|
||||
keymap[GLFW_KEY_E] = 'E';
|
||||
keymap[GLFW_KEY_F] = 'F';
|
||||
keymap[GLFW_KEY_G] = 'G';
|
||||
keymap[GLFW_KEY_H] = 'H';
|
||||
keymap[GLFW_KEY_I] = 'I';
|
||||
keymap[GLFW_KEY_J] = 'J';
|
||||
keymap[GLFW_KEY_K] = 'K';
|
||||
keymap[GLFW_KEY_L] = 'L';
|
||||
keymap[GLFW_KEY_M] = 'M';
|
||||
keymap[GLFW_KEY_N] = 'N';
|
||||
keymap[GLFW_KEY_O] = 'O';
|
||||
keymap[GLFW_KEY_P] = 'P';
|
||||
keymap[GLFW_KEY_Q] = 'Q';
|
||||
keymap[GLFW_KEY_R] = 'R';
|
||||
keymap[GLFW_KEY_S] = 'S';
|
||||
keymap[GLFW_KEY_T] = 'T';
|
||||
keymap[GLFW_KEY_U] = 'U';
|
||||
keymap[GLFW_KEY_V] = 'V';
|
||||
keymap[GLFW_KEY_W] = 'W';
|
||||
keymap[GLFW_KEY_X] = 'X';
|
||||
keymap[GLFW_KEY_Y] = 'Y';
|
||||
keymap[GLFW_KEY_Z] = 'Z';
|
||||
keymap[GLFW_KEY_LEFT_BRACKET] = '[';
|
||||
keymap[GLFW_KEY_BACKSLASH] = '\\';
|
||||
keymap[GLFW_KEY_RIGHT_BRACKET] = ']';
|
||||
keymap[GLFW_KEY_GRAVE_ACCENT] = '`';
|
||||
keymap[GLFW_KEY_ESCAPE] = KEY_ESC;
|
||||
keymap[GLFW_KEY_ENTER] = KEY_ENTER;
|
||||
keymap[GLFW_KEY_TAB] = KEY_TAB;
|
||||
keymap[GLFW_KEY_BACKSPACE] = KEY_BACKSP;
|
||||
keymap[GLFW_KEY_INSERT] = KEY_INS;
|
||||
keymap[GLFW_KEY_DELETE] = KEY_DEL;
|
||||
keymap[GLFW_KEY_RIGHT] = KEY_RIGHT;
|
||||
keymap[GLFW_KEY_LEFT] = KEY_LEFT;
|
||||
keymap[GLFW_KEY_DOWN] = KEY_DOWN;
|
||||
keymap[GLFW_KEY_UP] = KEY_UP;
|
||||
keymap[GLFW_KEY_PAGE_UP] = KEY_PGUP;
|
||||
keymap[GLFW_KEY_PAGE_DOWN] = KEY_PGDN;
|
||||
keymap[GLFW_KEY_HOME] = KEY_HOME;
|
||||
keymap[GLFW_KEY_END] = KEY_END;
|
||||
keymap[GLFW_KEY_CAPS_LOCK] = KEY_CAPSLK;
|
||||
keymap[GLFW_KEY_SCROLL_LOCK] = KEY_NULL;
|
||||
keymap[GLFW_KEY_NUM_LOCK] = KEY_NULL;
|
||||
keymap[GLFW_KEY_PRINT_SCREEN] = KEY_NULL;
|
||||
keymap[GLFW_KEY_PAUSE] = KEY_NULL;
|
||||
|
||||
keymap[GLFW_KEY_F1] = KEY_F1;
|
||||
keymap[GLFW_KEY_F2] = KEY_F2;
|
||||
keymap[GLFW_KEY_F3] = KEY_F3;
|
||||
keymap[GLFW_KEY_F4] = KEY_F4;
|
||||
keymap[GLFW_KEY_F5] = KEY_F5;
|
||||
keymap[GLFW_KEY_F6] = KEY_F6;
|
||||
keymap[GLFW_KEY_F7] = KEY_F7;
|
||||
keymap[GLFW_KEY_F8] = KEY_F8;
|
||||
keymap[GLFW_KEY_F9] = KEY_F9;
|
||||
keymap[GLFW_KEY_F10] = KEY_F10;
|
||||
keymap[GLFW_KEY_F11] = KEY_F11;
|
||||
keymap[GLFW_KEY_F12] = KEY_F12;
|
||||
keymap[GLFW_KEY_F13] = KEY_NULL;
|
||||
keymap[GLFW_KEY_F14] = KEY_NULL;
|
||||
keymap[GLFW_KEY_F15] = KEY_NULL;
|
||||
keymap[GLFW_KEY_F16] = KEY_NULL;
|
||||
keymap[GLFW_KEY_F17] = KEY_NULL;
|
||||
keymap[GLFW_KEY_F18] = KEY_NULL;
|
||||
keymap[GLFW_KEY_F19] = KEY_NULL;
|
||||
keymap[GLFW_KEY_F20] = KEY_NULL;
|
||||
keymap[GLFW_KEY_F21] = KEY_NULL;
|
||||
keymap[GLFW_KEY_F22] = KEY_NULL;
|
||||
keymap[GLFW_KEY_F23] = KEY_NULL;
|
||||
keymap[GLFW_KEY_F24] = KEY_NULL;
|
||||
keymap[GLFW_KEY_F25] = KEY_NULL;
|
||||
keymap[GLFW_KEY_KP_0] = KEY_NULL;
|
||||
keymap[GLFW_KEY_KP_1] = KEY_NULL;
|
||||
keymap[GLFW_KEY_KP_2] = KEY_NULL;
|
||||
keymap[GLFW_KEY_KP_3] = KEY_NULL;
|
||||
keymap[GLFW_KEY_KP_4] = KEY_NULL;
|
||||
keymap[GLFW_KEY_KP_5] = KEY_NULL;
|
||||
keymap[GLFW_KEY_KP_6] = KEY_NULL;
|
||||
keymap[GLFW_KEY_KP_7] = KEY_NULL;
|
||||
keymap[GLFW_KEY_KP_8] = KEY_NULL;
|
||||
keymap[GLFW_KEY_KP_9] = KEY_NULL;
|
||||
keymap[GLFW_KEY_KP_DECIMAL] = KEY_NULL;
|
||||
keymap[GLFW_KEY_KP_DIVIDE] = KEY_NULL;
|
||||
keymap[GLFW_KEY_KP_MULTIPLY] = KEY_NULL;
|
||||
keymap[GLFW_KEY_KP_SUBTRACT] = KEY_NULL;
|
||||
keymap[GLFW_KEY_KP_ADD] = KEY_NULL;
|
||||
keymap[GLFW_KEY_KP_ENTER] = KEY_NULL;
|
||||
keymap[GLFW_KEY_KP_EQUAL] = KEY_NULL;
|
||||
keymap[GLFW_KEY_LEFT_SHIFT] = KEY_LSHIFT;
|
||||
keymap[GLFW_KEY_LEFT_CONTROL] = KEY_LCTRL;
|
||||
keymap[GLFW_KEY_LEFT_ALT] = KEY_LALT;
|
||||
keymap[GLFW_KEY_LEFT_SUPER] = KEY_NULL;
|
||||
keymap[GLFW_KEY_RIGHT_SHIFT] = KEY_RSHIFT;
|
||||
keymap[GLFW_KEY_RIGHT_CONTROL] = KEY_RCTRL;
|
||||
keymap[GLFW_KEY_RIGHT_ALT] = KEY_RALT;
|
||||
keymap[GLFW_KEY_RIGHT_SUPER] = KEY_NULL;
|
||||
keymap[GLFW_KEY_MENU] = KEY_NULL;
|
||||
}
|
||||
|
||||
static void KeyUp(int key) { EventHandler(KEYUP, &key); }
|
||||
static void KeyDown(int key) { EventHandler(KEYDOWN, &key); }
|
||||
|
||||
static void
|
||||
keypress(GLFWwindow *window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if(key >= 0 && key <= GLFW_KEY_LAST){
|
||||
if(action == GLFW_RELEASE) KeyUp(keymap[key]);
|
||||
else if(action == GLFW_PRESS) KeyDown(keymap[key]);
|
||||
else if(action == GLFW_REPEAT) KeyDown(keymap[key]);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
charinput(GLFWwindow *window, unsigned int c)
|
||||
{
|
||||
EventHandler(CHARINPUT, (void*)(uintptr)c);
|
||||
}
|
||||
|
||||
static void
|
||||
resize(GLFWwindow *window, int w, int h)
|
||||
{
|
||||
rw::Rect r;
|
||||
r.x = 0;
|
||||
r.y = 0;
|
||||
r.w = w;
|
||||
r.h = h;
|
||||
EventHandler(RESIZE, &r);
|
||||
}
|
||||
|
||||
static void
|
||||
mousemove(GLFWwindow *window, double x, double y)
|
||||
{
|
||||
sk::MouseState ms;
|
||||
ms.posx = x;
|
||||
ms.posy = y;
|
||||
EventHandler(MOUSEMOVE, &ms);
|
||||
}
|
||||
|
||||
static void
|
||||
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)
|
||||
buttons |= 1;
|
||||
else
|
||||
buttons &= ~1;
|
||||
break;
|
||||
case GLFW_MOUSE_BUTTON_MIDDLE:
|
||||
if(action == GLFW_PRESS)
|
||||
buttons |= 2;
|
||||
else
|
||||
buttons &= ~2;
|
||||
break;
|
||||
case GLFW_MOUSE_BUTTON_RIGHT:
|
||||
if(action == GLFW_PRESS)
|
||||
buttons |= 4;
|
||||
else
|
||||
buttons &= ~4;
|
||||
break;
|
||||
}
|
||||
|
||||
ms.buttons = buttons;
|
||||
EventHandler(MOUSEBTN, &ms);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
args.argc = argc;
|
||||
args.argv = argv;
|
||||
|
||||
if(EventHandler(INITIALIZE, nil) == EVENTERROR)
|
||||
return 0;
|
||||
|
||||
engineOpenParams.width = sk::globals.width;
|
||||
engineOpenParams.height = sk::globals.height;
|
||||
engineOpenParams.windowtitle = sk::globals.windowtitle;
|
||||
engineOpenParams.window = &window;
|
||||
|
||||
if(EventHandler(RWINITIALIZE, nil) == EVENTERROR)
|
||||
return 0;
|
||||
|
||||
initkeymap();
|
||||
glfwSetKeyCallback(window, keypress);
|
||||
glfwSetCharCallback(window, charinput);
|
||||
glfwSetWindowSizeCallback(window, resize);
|
||||
glfwSetCursorPosCallback(window, mousemove);
|
||||
glfwSetMouseButtonCallback(window, mousebtn);
|
||||
|
||||
float lastTime = glfwGetTime()*1000;
|
||||
while(!sk::globals.quit && !glfwWindowShouldClose(window)){
|
||||
float currTime = glfwGetTime()*1000;
|
||||
float timeDelta = (currTime - lastTime)*0.001f;
|
||||
glfwPollEvents();
|
||||
|
||||
EventHandler(IDLE, &timeDelta);
|
||||
|
||||
lastTime = currTime;
|
||||
}
|
||||
|
||||
EventHandler(RWTERMINATE, nil);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace sk {
|
||||
|
||||
void
|
||||
SetMousePosition(int x, int y)
|
||||
{
|
||||
glfwSetCursorPos(*engineOpenParams.window, (double)x, (double)y);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
2724
vendor/librw/skeleton/imgui/ImGuizmo.cpp
vendored
Normal file
2724
vendor/librw/skeleton/imgui/ImGuizmo.cpp
vendored
Normal file
File diff suppressed because it is too large
Load diff
213
vendor/librw/skeleton/imgui/ImGuizmo.h
vendored
Normal file
213
vendor/librw/skeleton/imgui/ImGuizmo.h
vendored
Normal file
|
|
@ -0,0 +1,213 @@
|
|||
// https://github.com/CedricGuillemet/ImGuizmo
|
||||
// v 1.61 WIP
|
||||
//
|
||||
// The MIT License(MIT)
|
||||
//
|
||||
// Copyright(c) 2021 Cedric Guillemet
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files(the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions :
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -------------------------------------------------------------------------------------------
|
||||
// History :
|
||||
// 2019/11/03 View gizmo
|
||||
// 2016/09/11 Behind camera culling. Scaling Delta matrix not multiplied by source matrix scales. local/world rotation and translation fixed. Display message is incorrect (X: ... Y:...) in local mode.
|
||||
// 2016/09/09 Hatched negative axis. Snapping. Documentation update.
|
||||
// 2016/09/04 Axis switch and translation plan autohiding. Scale transform stability improved
|
||||
// 2016/09/01 Mogwai changed to Manipulate. Draw debug cube. Fixed inverted scale. Mixing scale and translation/rotation gives bad results.
|
||||
// 2016/08/31 First version
|
||||
//
|
||||
// -------------------------------------------------------------------------------------------
|
||||
// Future (no order):
|
||||
//
|
||||
// - Multi view
|
||||
// - display rotation/translation/scale infos in local/world space and not only local
|
||||
// - finish local/world matrix application
|
||||
// - OPERATION as bitmask
|
||||
//
|
||||
// -------------------------------------------------------------------------------------------
|
||||
// Example
|
||||
#if 0
|
||||
void EditTransform(const Camera& camera, matrix_t& matrix)
|
||||
{
|
||||
static ImGuizmo::OPERATION mCurrentGizmoOperation(ImGuizmo::ROTATE);
|
||||
static ImGuizmo::MODE mCurrentGizmoMode(ImGuizmo::WORLD);
|
||||
if (ImGui::IsKeyPressed(90))
|
||||
mCurrentGizmoOperation = ImGuizmo::TRANSLATE;
|
||||
if (ImGui::IsKeyPressed(69))
|
||||
mCurrentGizmoOperation = ImGuizmo::ROTATE;
|
||||
if (ImGui::IsKeyPressed(82)) // r Key
|
||||
mCurrentGizmoOperation = ImGuizmo::SCALE;
|
||||
if (ImGui::RadioButton("Translate", mCurrentGizmoOperation == ImGuizmo::TRANSLATE))
|
||||
mCurrentGizmoOperation = ImGuizmo::TRANSLATE;
|
||||
ImGui::SameLine();
|
||||
if (ImGui::RadioButton("Rotate", mCurrentGizmoOperation == ImGuizmo::ROTATE))
|
||||
mCurrentGizmoOperation = ImGuizmo::ROTATE;
|
||||
ImGui::SameLine();
|
||||
if (ImGui::RadioButton("Scale", mCurrentGizmoOperation == ImGuizmo::SCALE))
|
||||
mCurrentGizmoOperation = ImGuizmo::SCALE;
|
||||
float matrixTranslation[3], matrixRotation[3], matrixScale[3];
|
||||
ImGuizmo::DecomposeMatrixToComponents(matrix.m16, matrixTranslation, matrixRotation, matrixScale);
|
||||
ImGui::InputFloat3("Tr", matrixTranslation, 3);
|
||||
ImGui::InputFloat3("Rt", matrixRotation, 3);
|
||||
ImGui::InputFloat3("Sc", matrixScale, 3);
|
||||
ImGuizmo::RecomposeMatrixFromComponents(matrixTranslation, matrixRotation, matrixScale, matrix.m16);
|
||||
|
||||
if (mCurrentGizmoOperation != ImGuizmo::SCALE)
|
||||
{
|
||||
if (ImGui::RadioButton("Local", mCurrentGizmoMode == ImGuizmo::LOCAL))
|
||||
mCurrentGizmoMode = ImGuizmo::LOCAL;
|
||||
ImGui::SameLine();
|
||||
if (ImGui::RadioButton("World", mCurrentGizmoMode == ImGuizmo::WORLD))
|
||||
mCurrentGizmoMode = ImGuizmo::WORLD;
|
||||
}
|
||||
static bool useSnap(false);
|
||||
if (ImGui::IsKeyPressed(83))
|
||||
useSnap = !useSnap;
|
||||
ImGui::Checkbox("", &useSnap);
|
||||
ImGui::SameLine();
|
||||
vec_t snap;
|
||||
switch (mCurrentGizmoOperation)
|
||||
{
|
||||
case ImGuizmo::TRANSLATE:
|
||||
snap = config.mSnapTranslation;
|
||||
ImGui::InputFloat3("Snap", &snap.x);
|
||||
break;
|
||||
case ImGuizmo::ROTATE:
|
||||
snap = config.mSnapRotation;
|
||||
ImGui::InputFloat("Angle Snap", &snap.x);
|
||||
break;
|
||||
case ImGuizmo::SCALE:
|
||||
snap = config.mSnapScale;
|
||||
ImGui::InputFloat("Scale Snap", &snap.x);
|
||||
break;
|
||||
}
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImGuizmo::SetRect(0, 0, io.DisplaySize.x, io.DisplaySize.y);
|
||||
ImGuizmo::Manipulate(camera.mView.m16, camera.mProjection.m16, mCurrentGizmoOperation, mCurrentGizmoMode, matrix.m16, NULL, useSnap ? &snap.x : NULL);
|
||||
}
|
||||
#endif
|
||||
#pragma once
|
||||
|
||||
#ifdef USE_IMGUI_API
|
||||
#include "imconfig.h"
|
||||
#endif
|
||||
#ifndef IMGUI_API
|
||||
#define IMGUI_API
|
||||
#endif
|
||||
|
||||
namespace ImGuizmo
|
||||
{
|
||||
// call inside your own window and before Manipulate() in order to draw gizmo to that window.
|
||||
// Or pass a specific ImDrawList to draw to (e.g. ImGui::GetForegroundDrawList()).
|
||||
IMGUI_API void SetDrawlist(ImDrawList* drawlist = nullptr);
|
||||
|
||||
// call BeginFrame right after ImGui_XXXX_NewFrame();
|
||||
IMGUI_API void BeginFrame();
|
||||
|
||||
// this is necessary because when imguizmo is compiled into a dll, and imgui into another
|
||||
// globals are not shared between them.
|
||||
// More details at https://stackoverflow.com/questions/19373061/what-happens-to-global-and-static-variables-in-a-shared-library-when-it-is-dynam
|
||||
// expose method to set imgui context
|
||||
IMGUI_API void SetImGuiContext(ImGuiContext* ctx);
|
||||
|
||||
// return true if mouse cursor is over any gizmo control (axis, plan or screen component)
|
||||
IMGUI_API bool IsOver();
|
||||
|
||||
// return true if mouse IsOver or if the gizmo is in moving state
|
||||
IMGUI_API bool IsUsing();
|
||||
|
||||
// enable/disable the gizmo. Stay in the state until next call to Enable.
|
||||
// gizmo is rendered with gray half transparent color when disabled
|
||||
IMGUI_API void Enable(bool enable);
|
||||
|
||||
// helper functions for manualy editing translation/rotation/scale with an input float
|
||||
// translation, rotation and scale float points to 3 floats each
|
||||
// Angles are in degrees (more suitable for human editing)
|
||||
// example:
|
||||
// float matrixTranslation[3], matrixRotation[3], matrixScale[3];
|
||||
// ImGuizmo::DecomposeMatrixToComponents(gizmoMatrix.m16, matrixTranslation, matrixRotation, matrixScale);
|
||||
// ImGui::InputFloat3("Tr", matrixTranslation, 3);
|
||||
// ImGui::InputFloat3("Rt", matrixRotation, 3);
|
||||
// ImGui::InputFloat3("Sc", matrixScale, 3);
|
||||
// ImGuizmo::RecomposeMatrixFromComponents(matrixTranslation, matrixRotation, matrixScale, gizmoMatrix.m16);
|
||||
//
|
||||
// These functions have some numerical stability issues for now. Use with caution.
|
||||
IMGUI_API void DecomposeMatrixToComponents(const float* matrix, float* translation, float* rotation, float* scale);
|
||||
IMGUI_API void RecomposeMatrixFromComponents(const float* translation, const float* rotation, const float* scale, float* matrix);
|
||||
|
||||
IMGUI_API void SetRect(float x, float y, float width, float height);
|
||||
// default is false
|
||||
IMGUI_API void SetOrthographic(bool isOrthographic);
|
||||
|
||||
// Render a cube with face color corresponding to face normal. Usefull for debug/tests
|
||||
IMGUI_API void DrawCubes(const float* view, const float* projection, const float* matrices, int matrixCount);
|
||||
IMGUI_API void DrawGrid(const float* view, const float* projection, const float* matrix, const float gridSize);
|
||||
|
||||
// call it when you want a gizmo
|
||||
// Needs view and projection matrices.
|
||||
// matrix parameter is the source matrix (where will be gizmo be drawn) and might be transformed by the function. Return deltaMatrix is optional
|
||||
// translation is applied in world space
|
||||
enum OPERATION
|
||||
{
|
||||
TRANSLATE_X = (1u << 0),
|
||||
TRANSLATE_Y = (1u << 1),
|
||||
TRANSLATE_Z = (1u << 2),
|
||||
ROTATE_X = (1u << 3),
|
||||
ROTATE_Y = (1u << 4),
|
||||
ROTATE_Z = (1u << 5),
|
||||
ROTATE_SCREEN = (1u << 6),
|
||||
SCALE_X = (1u << 7),
|
||||
SCALE_Y = (1u << 8),
|
||||
SCALE_Z = (1u << 9),
|
||||
BOUNDS = (1u << 10),
|
||||
TRANSLATE = TRANSLATE_X | TRANSLATE_Y | TRANSLATE_Z,
|
||||
ROTATE = ROTATE_X | ROTATE_Y | ROTATE_Z | ROTATE_SCREEN,
|
||||
SCALE = SCALE_X | SCALE_Y | SCALE_Z
|
||||
};
|
||||
|
||||
inline OPERATION operator|(OPERATION lhs, OPERATION rhs)
|
||||
{
|
||||
return static_cast<OPERATION>(static_cast<int>(lhs) | static_cast<int>(rhs));
|
||||
}
|
||||
|
||||
enum MODE
|
||||
{
|
||||
LOCAL,
|
||||
WORLD
|
||||
};
|
||||
|
||||
IMGUI_API bool Manipulate(const float* view, const float* projection, OPERATION operation, MODE mode, float* matrix, float* deltaMatrix = NULL, const float* snap = NULL, const float* localBounds = NULL, const float* boundsSnap = NULL);
|
||||
//
|
||||
// Please note that this cubeview is patented by Autodesk : https://patents.google.com/patent/US7782319B2/en
|
||||
// It seems to be a defensive patent in the US. I don't think it will bring troubles using it as
|
||||
// other software are using the same mechanics. But just in case, you are now warned!
|
||||
//
|
||||
IMGUI_API void ViewManipulate(float* view, float length, ImVec2 position, ImVec2 size, ImU32 backgroundColor);
|
||||
|
||||
IMGUI_API void SetID(int id);
|
||||
|
||||
// return true if the cursor is over the operation's gizmo
|
||||
IMGUI_API bool IsOver(OPERATION op);
|
||||
IMGUI_API void SetGizmoSizeClipSpace(float value);
|
||||
|
||||
// Allow axis to flip
|
||||
// When true (default), the guizmo axis flip for better visibility
|
||||
// When false, they always stay along the positive world/local axis
|
||||
IMGUI_API void AllowAxisFlip(bool value);
|
||||
}
|
||||
21
vendor/librw/skeleton/imgui/LICENSE_imgui.txt
vendored
Normal file
21
vendor/librw/skeleton/imgui/LICENSE_imgui.txt
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014-2021 Omar Cornut
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
21
vendor/librw/skeleton/imgui/LICENSE_imguizmo.txt
vendored
Normal file
21
vendor/librw/skeleton/imgui/LICENSE_imguizmo.txt
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Cedric Guillemet
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
121
vendor/librw/skeleton/imgui/imconfig.h
vendored
Normal file
121
vendor/librw/skeleton/imgui/imconfig.h
vendored
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// COMPILE-TIME OPTIONS FOR DEAR IMGUI
|
||||
// Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure.
|
||||
// You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions.
|
||||
//-----------------------------------------------------------------------------
|
||||
// A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/rebased branch with your modifications to it)
|
||||
// B) or '#define IMGUI_USER_CONFIG "my_imgui_config.h"' in your project and then add directives in your own file without touching this template.
|
||||
//-----------------------------------------------------------------------------
|
||||
// You need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include the imgui*.cpp
|
||||
// files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on data structures.
|
||||
// Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts.
|
||||
// Call IMGUI_CHECKVERSION() from your .cpp files to verify that the data structures your files are using are matching the ones imgui.cpp is using.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
//---- Define assertion handler. Defaults to calling assert().
|
||||
// If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement.
|
||||
//#define IM_ASSERT(_EXPR) MyAssert(_EXPR)
|
||||
//#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts
|
||||
|
||||
//---- Define attributes of all API symbols declarations, e.g. for DLL under Windows
|
||||
// Using Dear ImGui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility.
|
||||
// DLL users: heaps and globals are not shared across DLL boundaries! You will need to call SetCurrentContext() + SetAllocatorFunctions()
|
||||
// for each static/DLL boundary you are calling from. Read "Context and Memory Allocators" section of imgui.cpp for more details.
|
||||
//#define IMGUI_API __declspec( dllexport )
|
||||
//#define IMGUI_API __declspec( dllimport )
|
||||
|
||||
//---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names.
|
||||
//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||
|
||||
//---- Disable all of Dear ImGui or don't implement standard windows.
|
||||
// It is very strongly recommended to NOT disable the demo windows during development. Please read comments in imgui_demo.cpp.
|
||||
//#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty.
|
||||
//#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty. Not recommended.
|
||||
//#define IMGUI_DISABLE_METRICS_WINDOW // Disable metrics/debugger window: ShowMetricsWindow() will be empty.
|
||||
|
||||
//---- Don't implement some functions to reduce linkage requirements.
|
||||
//#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. (user32.lib/.a, kernel32.lib/.a)
|
||||
//#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] Don't implement default IME handler. Won't use and link with ImmGetContext/ImmSetCompositionWindow. (imm32.lib/.a)
|
||||
//#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, ime).
|
||||
//#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default).
|
||||
//#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf)
|
||||
//#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself.
|
||||
//#define IMGUI_DISABLE_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle at all (replace them with dummies)
|
||||
//#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function.
|
||||
//#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions().
|
||||
|
||||
//---- Include imgui_user.h at the end of imgui.h as a convenience
|
||||
//#define IMGUI_INCLUDE_IMGUI_USER_H
|
||||
|
||||
//---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another)
|
||||
//#define IMGUI_USE_BGRA_PACKED_COLOR
|
||||
|
||||
//---- Use 32-bit for ImWchar (default is 16-bit) to support unicode planes 1-16. (e.g. point beyond 0xFFFF like emoticons, dingbats, symbols, shapes, ancient languages, etc...)
|
||||
//#define IMGUI_USE_WCHAR32
|
||||
|
||||
//---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version
|
||||
// By default the embedded implementations are declared static and not available outside of Dear ImGui sources files.
|
||||
//#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h"
|
||||
//#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h"
|
||||
//#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
|
||||
//#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION
|
||||
|
||||
//---- Use stb_printf's faster implementation of vsnprintf instead of the one from libc (unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined)
|
||||
// Requires 'stb_sprintf.h' to be available in the include path. Compatibility checks of arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by STB sprintf.
|
||||
// #define IMGUI_USE_STB_SPRINTF
|
||||
|
||||
//---- Use FreeType to build and rasterize the font atlas (instead of stb_truetype which is embedded by default in Dear ImGui)
|
||||
// Requires FreeType headers to be available in the include path. Requires program to be compiled with 'misc/freetype/imgui_freetype.cpp' (in this repository) + the FreeType library (not provided).
|
||||
// On Windows you may use vcpkg with 'vcpkg install freetype' + 'vcpkg integrate install'.
|
||||
//#define IMGUI_ENABLE_FREETYPE
|
||||
|
||||
//---- Use stb_truetype to build and rasterize the font atlas (default)
|
||||
// The only purpose of this define is if you want force compilation of the stb_truetype backend ALONG with the FreeType backend.
|
||||
//#define IMGUI_ENABLE_STB_TRUETYPE
|
||||
|
||||
//---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4.
|
||||
// This will be inlined as part of ImVec2 and ImVec4 class declarations.
|
||||
/*
|
||||
#define IM_VEC2_CLASS_EXTRA \
|
||||
ImVec2(const MyVec2& f) { x = f.x; y = f.y; } \
|
||||
operator MyVec2() const { return MyVec2(x,y); }
|
||||
|
||||
#define IM_VEC4_CLASS_EXTRA \
|
||||
ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \
|
||||
operator MyVec4() const { return MyVec4(x,y,z,w); }
|
||||
*/
|
||||
|
||||
//---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices.
|
||||
// Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices).
|
||||
// Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer.
|
||||
// Read about ImGuiBackendFlags_RendererHasVtxOffset for details.
|
||||
//#define ImDrawIdx unsigned int
|
||||
|
||||
//---- Override ImDrawCallback signature (will need to modify renderer backends accordingly)
|
||||
//struct ImDrawList;
|
||||
//struct ImDrawCmd;
|
||||
//typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data);
|
||||
//#define ImDrawCallback MyImDrawCallback
|
||||
|
||||
//---- Debug Tools: Macro to break in Debugger
|
||||
// (use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.)
|
||||
//#define IM_DEBUG_BREAK IM_ASSERT(0)
|
||||
//#define IM_DEBUG_BREAK __debugbreak()
|
||||
|
||||
//---- Debug Tools: Have the Item Picker break in the ItemAdd() function instead of ItemHoverable(),
|
||||
// (which comes earlier in the code, will catch a few extra items, allow picking items other than Hovered one.)
|
||||
// This adds a small runtime cost which is why it is not enabled by default.
|
||||
//#define IMGUI_DEBUG_TOOL_ITEM_PICKER_EX
|
||||
|
||||
//---- Debug Tools: Enable slower asserts
|
||||
//#define IMGUI_DEBUG_PARANOID
|
||||
|
||||
//---- Tip: You can add extra functions within the ImGui:: namespace, here or in your own headers files.
|
||||
/*
|
||||
namespace ImGui
|
||||
{
|
||||
void MyFunction(const char* name, const MyMatrix44& v);
|
||||
}
|
||||
*/
|
||||
11589
vendor/librw/skeleton/imgui/imgui.cpp
vendored
Normal file
11589
vendor/librw/skeleton/imgui/imgui.cpp
vendored
Normal file
File diff suppressed because it is too large
Load diff
2852
vendor/librw/skeleton/imgui/imgui.h
vendored
Normal file
2852
vendor/librw/skeleton/imgui/imgui.h
vendored
Normal file
File diff suppressed because it is too large
Load diff
7725
vendor/librw/skeleton/imgui/imgui_demo.cpp
vendored
Normal file
7725
vendor/librw/skeleton/imgui/imgui_demo.cpp
vendored
Normal file
File diff suppressed because it is too large
Load diff
4152
vendor/librw/skeleton/imgui/imgui_draw.cpp
vendored
Normal file
4152
vendor/librw/skeleton/imgui/imgui_draw.cpp
vendored
Normal file
File diff suppressed because it is too large
Load diff
240
vendor/librw/skeleton/imgui/imgui_impl_rw.cpp
vendored
Normal file
240
vendor/librw/skeleton/imgui/imgui_impl_rw.cpp
vendored
Normal file
|
|
@ -0,0 +1,240 @@
|
|||
#include <rw.h>
|
||||
#include <skeleton.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "imgui/imgui.h"
|
||||
#include "imgui_impl_rw.h"
|
||||
|
||||
using namespace rw::RWDEVICE;
|
||||
|
||||
static rw::Texture *g_FontTexture;
|
||||
static Im2DVertex *g_vertbuf;
|
||||
static int g_vertbufSize;
|
||||
|
||||
void
|
||||
ImGui_ImplRW_RenderDrawLists(ImDrawData* draw_data)
|
||||
{
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
|
||||
// minimized
|
||||
if (io.DisplaySize.x <= 0.0f || io.DisplaySize.y <= 0.0f)
|
||||
return;
|
||||
|
||||
if(g_vertbuf == nil || g_vertbufSize < draw_data->TotalVtxCount){
|
||||
if(g_vertbuf){
|
||||
rwFree(g_vertbuf);
|
||||
g_vertbuf = nil;
|
||||
}
|
||||
g_vertbufSize = draw_data->TotalVtxCount + 5000;
|
||||
g_vertbuf = rwNewT(Im2DVertex, g_vertbufSize, 0);
|
||||
}
|
||||
|
||||
float xoff = 0.0f;
|
||||
float yoff = 0.0f;
|
||||
#ifdef RWHALFPIXEL
|
||||
xoff = -0.5;
|
||||
yoff = 0.5;
|
||||
#endif
|
||||
|
||||
rw::Camera *cam = (rw::Camera*)rw::engine->currentCamera;
|
||||
Im2DVertex *vtx_dst = g_vertbuf;
|
||||
float recipZ = 1.0f/cam->nearPlane;
|
||||
for(int n = 0; n < draw_data->CmdListsCount; n++){
|
||||
const ImDrawList *cmd_list = draw_data->CmdLists[n];
|
||||
const ImDrawVert *vtx_src = cmd_list->VtxBuffer.Data;
|
||||
for(int i = 0; i < cmd_list->VtxBuffer.Size; i++){
|
||||
vtx_dst[i].setScreenX(vtx_src[i].pos.x + xoff);
|
||||
vtx_dst[i].setScreenY(vtx_src[i].pos.y + yoff);
|
||||
vtx_dst[i].setScreenZ(rw::im2d::GetNearZ());
|
||||
vtx_dst[i].setCameraZ(cam->nearPlane);
|
||||
vtx_dst[i].setRecipCameraZ(recipZ);
|
||||
vtx_dst[i].setColor(vtx_src[i].col&0xFF, vtx_src[i].col>>8 & 0xFF, vtx_src[i].col>>16 & 0xFF, vtx_src[i].col>>24 & 0xFF);
|
||||
vtx_dst[i].setU(vtx_src[i].uv.x, recipZ);
|
||||
vtx_dst[i].setV(vtx_src[i].uv.y, recipZ);
|
||||
}
|
||||
vtx_dst += cmd_list->VtxBuffer.Size;
|
||||
}
|
||||
|
||||
int vertexAlpha = rw::GetRenderState(rw::VERTEXALPHA);
|
||||
int srcBlend = rw::GetRenderState(rw::SRCBLEND);
|
||||
int dstBlend = rw::GetRenderState(rw::DESTBLEND);
|
||||
int ztest = rw::GetRenderState(rw::ZTESTENABLE);
|
||||
void *tex = rw::GetRenderStatePtr(rw::TEXTURERASTER);
|
||||
int addrU = rw::GetRenderState(rw::TEXTUREADDRESSU);
|
||||
int addrV = rw::GetRenderState(rw::TEXTUREADDRESSV);
|
||||
int filter = rw::GetRenderState(rw::TEXTUREFILTER);
|
||||
int cullmode = rw::GetRenderState(rw::CULLMODE);
|
||||
|
||||
rw::SetRenderState(rw::VERTEXALPHA, 1);
|
||||
rw::SetRenderState(rw::SRCBLEND, rw::BLENDSRCALPHA);
|
||||
rw::SetRenderState(rw::DESTBLEND, rw::BLENDINVSRCALPHA);
|
||||
rw::SetRenderState(rw::ZTESTENABLE, 0);
|
||||
rw::SetRenderState(rw::CULLMODE, rw::CULLNONE);
|
||||
|
||||
int vtx_offset = 0;
|
||||
for(int n = 0; n < draw_data->CmdListsCount; n++){
|
||||
const ImDrawList *cmd_list = draw_data->CmdLists[n];
|
||||
int idx_offset = 0;
|
||||
for(int i = 0; i < cmd_list->CmdBuffer.Size; i++){
|
||||
const ImDrawCmd *pcmd = &cmd_list->CmdBuffer[i];
|
||||
if(pcmd->UserCallback)
|
||||
pcmd->UserCallback(cmd_list, pcmd);
|
||||
else{
|
||||
rw::Texture *tex = (rw::Texture*)pcmd->TextureId;
|
||||
if(tex && tex->raster){
|
||||
rw::SetRenderStatePtr(rw::TEXTURERASTER, tex->raster);
|
||||
rw::SetRenderState(rw::TEXTUREADDRESSU, tex->getAddressU());
|
||||
rw::SetRenderState(rw::TEXTUREADDRESSV, tex->getAddressV());
|
||||
rw::SetRenderState(rw::TEXTUREFILTER, tex->getFilter());
|
||||
}else
|
||||
rw::SetRenderStatePtr(rw::TEXTURERASTER, nil);
|
||||
rw::im2d::RenderIndexedPrimitive(rw::PRIMTYPETRILIST,
|
||||
g_vertbuf+vtx_offset, cmd_list->VtxBuffer.Size,
|
||||
cmd_list->IdxBuffer.Data+idx_offset, pcmd->ElemCount);
|
||||
}
|
||||
idx_offset += pcmd->ElemCount;
|
||||
}
|
||||
vtx_offset += cmd_list->VtxBuffer.Size;
|
||||
}
|
||||
|
||||
rw::SetRenderState(rw::VERTEXALPHA,vertexAlpha);
|
||||
rw::SetRenderState(rw::SRCBLEND, srcBlend);
|
||||
rw::SetRenderState(rw::DESTBLEND, dstBlend);
|
||||
rw::SetRenderState(rw::ZTESTENABLE, ztest);
|
||||
rw::SetRenderStatePtr(rw::TEXTURERASTER, tex);
|
||||
rw::SetRenderState(rw::TEXTUREADDRESSU, addrU);
|
||||
rw::SetRenderState(rw::TEXTUREADDRESSV, addrV);
|
||||
rw::SetRenderState(rw::TEXTUREFILTER, filter);
|
||||
rw::SetRenderState(rw::CULLMODE, cullmode);
|
||||
}
|
||||
|
||||
bool
|
||||
ImGui_ImplRW_Init(void)
|
||||
{
|
||||
using namespace sk;
|
||||
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
|
||||
io.KeyMap[ImGuiKey_Tab] = KEY_TAB;
|
||||
io.KeyMap[ImGuiKey_LeftArrow] = KEY_LEFT;
|
||||
io.KeyMap[ImGuiKey_RightArrow] = KEY_RIGHT;
|
||||
io.KeyMap[ImGuiKey_UpArrow] = KEY_UP;
|
||||
io.KeyMap[ImGuiKey_DownArrow] = KEY_DOWN;
|
||||
io.KeyMap[ImGuiKey_PageUp] = KEY_PGUP;
|
||||
io.KeyMap[ImGuiKey_PageDown] = KEY_PGDN;
|
||||
io.KeyMap[ImGuiKey_Home] = KEY_HOME;
|
||||
io.KeyMap[ImGuiKey_End] = KEY_END;
|
||||
io.KeyMap[ImGuiKey_Delete] = KEY_DEL;
|
||||
io.KeyMap[ImGuiKey_Backspace] = KEY_BACKSP;
|
||||
io.KeyMap[ImGuiKey_Enter] = KEY_ENTER;
|
||||
io.KeyMap[ImGuiKey_Escape] = KEY_ESC;
|
||||
io.KeyMap[ImGuiKey_A] = 'A';
|
||||
io.KeyMap[ImGuiKey_C] = 'C';
|
||||
io.KeyMap[ImGuiKey_V] = 'V';
|
||||
io.KeyMap[ImGuiKey_X] = 'X';
|
||||
io.KeyMap[ImGuiKey_Y] = 'Y';
|
||||
io.KeyMap[ImGuiKey_Z] = 'Z';
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
ImGui_ImplRW_Shutdown(void)
|
||||
{
|
||||
}
|
||||
|
||||
static bool
|
||||
ImGui_ImplRW_CreateFontsTexture()
|
||||
{
|
||||
// Build texture atlas
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
unsigned char *pixels;
|
||||
int width, height;
|
||||
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height, nil);
|
||||
|
||||
rw::Image *image;
|
||||
image = rw::Image::create(width, height, 32);
|
||||
image->allocate();
|
||||
for(int y = 0; y < height; y++)
|
||||
memcpy(image->pixels + image->stride*y, pixels + width*4* y, width*4);
|
||||
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;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ImGui_ImplRW_CreateDeviceObjects()
|
||||
{
|
||||
// if(!g_pd3dDevice)
|
||||
// return false;
|
||||
if(!ImGui_ImplRW_CreateFontsTexture())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
ImGui_ImplRW_NewFrame(float timeDelta)
|
||||
{
|
||||
if(!g_FontTexture)
|
||||
ImGui_ImplRW_CreateDeviceObjects();
|
||||
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
|
||||
io.DisplaySize = ImVec2(sk::globals.width, sk::globals.height);
|
||||
io.DeltaTime = timeDelta;
|
||||
|
||||
io.KeyCtrl = io.KeysDown[sk::KEY_LCTRL] || io.KeysDown[sk::KEY_RCTRL];
|
||||
io.KeyShift = io.KeysDown[sk::KEY_LSHIFT] || io.KeysDown[sk::KEY_RSHIFT];
|
||||
io.KeyAlt = io.KeysDown[sk::KEY_LALT] || io.KeysDown[sk::KEY_RALT];
|
||||
io.KeySuper = false;
|
||||
|
||||
if(io.WantSetMousePos)
|
||||
sk::SetMousePosition(io.MousePos.x, io.MousePos.y);
|
||||
|
||||
ImGui::NewFrame();
|
||||
}
|
||||
|
||||
sk::EventStatus
|
||||
ImGuiEventHandler(sk::Event e, void *param)
|
||||
{
|
||||
using namespace sk;
|
||||
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
MouseState *ms;
|
||||
uint c;
|
||||
|
||||
switch(e){
|
||||
case KEYDOWN:
|
||||
c = *(int*)param;
|
||||
if(c < 256)
|
||||
io.KeysDown[c] = 1;
|
||||
return EVENTPROCESSED;
|
||||
case KEYUP:
|
||||
c = *(int*)param;
|
||||
if(c < 256)
|
||||
io.KeysDown[c] = 0;
|
||||
return EVENTPROCESSED;
|
||||
case CHARINPUT:
|
||||
c = (uint)(uintptr)param;
|
||||
io.AddInputCharacter((unsigned short)c);
|
||||
return EVENTPROCESSED;
|
||||
case MOUSEMOVE:
|
||||
ms = (MouseState*)param;
|
||||
io.MousePos.x = ms->posx;
|
||||
io.MousePos.y = ms->posy;
|
||||
return EVENTPROCESSED;
|
||||
case MOUSEBTN:
|
||||
ms = (MouseState*)param;
|
||||
io.MouseDown[0] = !!(ms->buttons & 1);
|
||||
io.MouseDown[2] = !!(ms->buttons & 2);
|
||||
io.MouseDown[1] = !!(ms->buttons & 4);
|
||||
return EVENTPROCESSED;
|
||||
}
|
||||
return EVENTPROCESSED;
|
||||
}
|
||||
5
vendor/librw/skeleton/imgui/imgui_impl_rw.h
vendored
Normal file
5
vendor/librw/skeleton/imgui/imgui_impl_rw.h
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
IMGUI_API bool ImGui_ImplRW_Init(void);
|
||||
IMGUI_API void ImGui_ImplRW_Shutdown(void);
|
||||
IMGUI_API void ImGui_ImplRW_NewFrame(float timeDelta);
|
||||
sk::EventStatus ImGuiEventHandler(sk::Event e, void *param);
|
||||
void ImGui_ImplRW_RenderDrawLists(ImDrawData* draw_data);
|
||||
2688
vendor/librw/skeleton/imgui/imgui_internal.h
vendored
Normal file
2688
vendor/librw/skeleton/imgui/imgui_internal.h
vendored
Normal file
File diff suppressed because it is too large
Load diff
4028
vendor/librw/skeleton/imgui/imgui_tables.cpp
vendored
Normal file
4028
vendor/librw/skeleton/imgui/imgui_tables.cpp
vendored
Normal file
File diff suppressed because it is too large
Load diff
8056
vendor/librw/skeleton/imgui/imgui_widgets.cpp
vendored
Normal file
8056
vendor/librw/skeleton/imgui/imgui_widgets.cpp
vendored
Normal file
File diff suppressed because it is too large
Load diff
639
vendor/librw/skeleton/imgui/imstb_rectpack.h
vendored
Normal file
639
vendor/librw/skeleton/imgui/imstb_rectpack.h
vendored
Normal file
|
|
@ -0,0 +1,639 @@
|
|||
// [DEAR IMGUI]
|
||||
// This is a slightly modified version of stb_rect_pack.h 1.00.
|
||||
// Those changes would need to be pushed into nothings/stb:
|
||||
// - Added STBRP__CDECL
|
||||
// Grep for [DEAR IMGUI] to find the changes.
|
||||
|
||||
// stb_rect_pack.h - v1.00 - public domain - rectangle packing
|
||||
// Sean Barrett 2014
|
||||
//
|
||||
// Useful for e.g. packing rectangular textures into an atlas.
|
||||
// Does not do rotation.
|
||||
//
|
||||
// Not necessarily the awesomest packing method, but better than
|
||||
// the totally naive one in stb_truetype (which is primarily what
|
||||
// this is meant to replace).
|
||||
//
|
||||
// Has only had a few tests run, may have issues.
|
||||
//
|
||||
// More docs to come.
|
||||
//
|
||||
// No memory allocations; uses qsort() and assert() from stdlib.
|
||||
// Can override those by defining STBRP_SORT and STBRP_ASSERT.
|
||||
//
|
||||
// This library currently uses the Skyline Bottom-Left algorithm.
|
||||
//
|
||||
// Please note: better rectangle packers are welcome! Please
|
||||
// implement them to the same API, but with a different init
|
||||
// function.
|
||||
//
|
||||
// Credits
|
||||
//
|
||||
// Library
|
||||
// Sean Barrett
|
||||
// Minor features
|
||||
// Martins Mozeiko
|
||||
// github:IntellectualKitty
|
||||
//
|
||||
// Bugfixes / warning fixes
|
||||
// Jeremy Jaussaud
|
||||
// Fabian Giesen
|
||||
//
|
||||
// Version history:
|
||||
//
|
||||
// 1.00 (2019-02-25) avoid small space waste; gracefully fail too-wide rectangles
|
||||
// 0.99 (2019-02-07) warning fixes
|
||||
// 0.11 (2017-03-03) return packing success/fail result
|
||||
// 0.10 (2016-10-25) remove cast-away-const to avoid warnings
|
||||
// 0.09 (2016-08-27) fix compiler warnings
|
||||
// 0.08 (2015-09-13) really fix bug with empty rects (w=0 or h=0)
|
||||
// 0.07 (2015-09-13) fix bug with empty rects (w=0 or h=0)
|
||||
// 0.06 (2015-04-15) added STBRP_SORT to allow replacing qsort
|
||||
// 0.05: added STBRP_ASSERT to allow replacing assert
|
||||
// 0.04: fixed minor bug in STBRP_LARGE_RECTS support
|
||||
// 0.01: initial release
|
||||
//
|
||||
// LICENSE
|
||||
//
|
||||
// See end of file for license information.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// INCLUDE SECTION
|
||||
//
|
||||
|
||||
#ifndef STB_INCLUDE_STB_RECT_PACK_H
|
||||
#define STB_INCLUDE_STB_RECT_PACK_H
|
||||
|
||||
#define STB_RECT_PACK_VERSION 1
|
||||
|
||||
#ifdef STBRP_STATIC
|
||||
#define STBRP_DEF static
|
||||
#else
|
||||
#define STBRP_DEF extern
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct stbrp_context stbrp_context;
|
||||
typedef struct stbrp_node stbrp_node;
|
||||
typedef struct stbrp_rect stbrp_rect;
|
||||
|
||||
#ifdef STBRP_LARGE_RECTS
|
||||
typedef int stbrp_coord;
|
||||
#else
|
||||
typedef unsigned short stbrp_coord;
|
||||
#endif
|
||||
|
||||
STBRP_DEF int stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects);
|
||||
// Assign packed locations to rectangles. The rectangles are of type
|
||||
// 'stbrp_rect' defined below, stored in the array 'rects', and there
|
||||
// are 'num_rects' many of them.
|
||||
//
|
||||
// Rectangles which are successfully packed have the 'was_packed' flag
|
||||
// set to a non-zero value and 'x' and 'y' store the minimum location
|
||||
// on each axis (i.e. bottom-left in cartesian coordinates, top-left
|
||||
// if you imagine y increasing downwards). Rectangles which do not fit
|
||||
// have the 'was_packed' flag set to 0.
|
||||
//
|
||||
// You should not try to access the 'rects' array from another thread
|
||||
// while this function is running, as the function temporarily reorders
|
||||
// the array while it executes.
|
||||
//
|
||||
// To pack into another rectangle, you need to call stbrp_init_target
|
||||
// again. To continue packing into the same rectangle, you can call
|
||||
// this function again. Calling this multiple times with multiple rect
|
||||
// arrays will probably produce worse packing results than calling it
|
||||
// a single time with the full rectangle array, but the option is
|
||||
// available.
|
||||
//
|
||||
// The function returns 1 if all of the rectangles were successfully
|
||||
// packed and 0 otherwise.
|
||||
|
||||
struct stbrp_rect
|
||||
{
|
||||
// reserved for your use:
|
||||
int id;
|
||||
|
||||
// input:
|
||||
stbrp_coord w, h;
|
||||
|
||||
// output:
|
||||
stbrp_coord x, y;
|
||||
int was_packed; // non-zero if valid packing
|
||||
|
||||
}; // 16 bytes, nominally
|
||||
|
||||
|
||||
STBRP_DEF void stbrp_init_target (stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes);
|
||||
// Initialize a rectangle packer to:
|
||||
// pack a rectangle that is 'width' by 'height' in dimensions
|
||||
// using temporary storage provided by the array 'nodes', which is 'num_nodes' long
|
||||
//
|
||||
// You must call this function every time you start packing into a new target.
|
||||
//
|
||||
// There is no "shutdown" function. The 'nodes' memory must stay valid for
|
||||
// the following stbrp_pack_rects() call (or calls), but can be freed after
|
||||
// the call (or calls) finish.
|
||||
//
|
||||
// Note: to guarantee best results, either:
|
||||
// 1. make sure 'num_nodes' >= 'width'
|
||||
// or 2. call stbrp_allow_out_of_mem() defined below with 'allow_out_of_mem = 1'
|
||||
//
|
||||
// If you don't do either of the above things, widths will be quantized to multiples
|
||||
// of small integers to guarantee the algorithm doesn't run out of temporary storage.
|
||||
//
|
||||
// If you do #2, then the non-quantized algorithm will be used, but the algorithm
|
||||
// may run out of temporary storage and be unable to pack some rectangles.
|
||||
|
||||
STBRP_DEF void stbrp_setup_allow_out_of_mem (stbrp_context *context, int allow_out_of_mem);
|
||||
// Optionally call this function after init but before doing any packing to
|
||||
// change the handling of the out-of-temp-memory scenario, described above.
|
||||
// If you call init again, this will be reset to the default (false).
|
||||
|
||||
|
||||
STBRP_DEF void stbrp_setup_heuristic (stbrp_context *context, int heuristic);
|
||||
// Optionally select which packing heuristic the library should use. Different
|
||||
// heuristics will produce better/worse results for different data sets.
|
||||
// If you call init again, this will be reset to the default.
|
||||
|
||||
enum
|
||||
{
|
||||
STBRP_HEURISTIC_Skyline_default=0,
|
||||
STBRP_HEURISTIC_Skyline_BL_sortHeight = STBRP_HEURISTIC_Skyline_default,
|
||||
STBRP_HEURISTIC_Skyline_BF_sortHeight
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// the details of the following structures don't matter to you, but they must
|
||||
// be visible so you can handle the memory allocations for them
|
||||
|
||||
struct stbrp_node
|
||||
{
|
||||
stbrp_coord x,y;
|
||||
stbrp_node *next;
|
||||
};
|
||||
|
||||
struct stbrp_context
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
int align;
|
||||
int init_mode;
|
||||
int heuristic;
|
||||
int num_nodes;
|
||||
stbrp_node *active_head;
|
||||
stbrp_node *free_head;
|
||||
stbrp_node extra[2]; // we allocate two extra nodes so optimal user-node-count is 'width' not 'width+2'
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPLEMENTATION SECTION
|
||||
//
|
||||
|
||||
#ifdef STB_RECT_PACK_IMPLEMENTATION
|
||||
#ifndef STBRP_SORT
|
||||
#include <stdlib.h>
|
||||
#define STBRP_SORT qsort
|
||||
#endif
|
||||
|
||||
#ifndef STBRP_ASSERT
|
||||
#include <assert.h>
|
||||
#define STBRP_ASSERT assert
|
||||
#endif
|
||||
|
||||
// [DEAR IMGUI] Added STBRP__CDECL
|
||||
#ifdef _MSC_VER
|
||||
#define STBRP__NOTUSED(v) (void)(v)
|
||||
#define STBRP__CDECL __cdecl
|
||||
#else
|
||||
#define STBRP__NOTUSED(v) (void)sizeof(v)
|
||||
#define STBRP__CDECL
|
||||
#endif
|
||||
|
||||
enum
|
||||
{
|
||||
STBRP__INIT_skyline = 1
|
||||
};
|
||||
|
||||
STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic)
|
||||
{
|
||||
switch (context->init_mode) {
|
||||
case STBRP__INIT_skyline:
|
||||
STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight || heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight);
|
||||
context->heuristic = heuristic;
|
||||
break;
|
||||
default:
|
||||
STBRP_ASSERT(0);
|
||||
}
|
||||
}
|
||||
|
||||
STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_out_of_mem)
|
||||
{
|
||||
if (allow_out_of_mem)
|
||||
// if it's ok to run out of memory, then don't bother aligning them;
|
||||
// this gives better packing, but may fail due to OOM (even though
|
||||
// the rectangles easily fit). @TODO a smarter approach would be to only
|
||||
// quantize once we've hit OOM, then we could get rid of this parameter.
|
||||
context->align = 1;
|
||||
else {
|
||||
// if it's not ok to run out of memory, then quantize the widths
|
||||
// so that num_nodes is always enough nodes.
|
||||
//
|
||||
// I.e. num_nodes * align >= width
|
||||
// align >= width / num_nodes
|
||||
// align = ceil(width/num_nodes)
|
||||
|
||||
context->align = (context->width + context->num_nodes-1) / context->num_nodes;
|
||||
}
|
||||
}
|
||||
|
||||
STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes)
|
||||
{
|
||||
int i;
|
||||
#ifndef STBRP_LARGE_RECTS
|
||||
STBRP_ASSERT(width <= 0xffff && height <= 0xffff);
|
||||
#endif
|
||||
|
||||
for (i=0; i < num_nodes-1; ++i)
|
||||
nodes[i].next = &nodes[i+1];
|
||||
nodes[i].next = NULL;
|
||||
context->init_mode = STBRP__INIT_skyline;
|
||||
context->heuristic = STBRP_HEURISTIC_Skyline_default;
|
||||
context->free_head = &nodes[0];
|
||||
context->active_head = &context->extra[0];
|
||||
context->width = width;
|
||||
context->height = height;
|
||||
context->num_nodes = num_nodes;
|
||||
stbrp_setup_allow_out_of_mem(context, 0);
|
||||
|
||||
// node 0 is the full width, node 1 is the sentinel (lets us not store width explicitly)
|
||||
context->extra[0].x = 0;
|
||||
context->extra[0].y = 0;
|
||||
context->extra[0].next = &context->extra[1];
|
||||
context->extra[1].x = (stbrp_coord) width;
|
||||
#ifdef STBRP_LARGE_RECTS
|
||||
context->extra[1].y = (1<<30);
|
||||
#else
|
||||
context->extra[1].y = 65535;
|
||||
#endif
|
||||
context->extra[1].next = NULL;
|
||||
}
|
||||
|
||||
// find minimum y position if it starts at x1
|
||||
static int stbrp__skyline_find_min_y(stbrp_context *c, stbrp_node *first, int x0, int width, int *pwaste)
|
||||
{
|
||||
stbrp_node *node = first;
|
||||
int x1 = x0 + width;
|
||||
int min_y, visited_width, waste_area;
|
||||
|
||||
STBRP__NOTUSED(c);
|
||||
|
||||
STBRP_ASSERT(first->x <= x0);
|
||||
|
||||
#if 0
|
||||
// skip in case we're past the node
|
||||
while (node->next->x <= x0)
|
||||
++node;
|
||||
#else
|
||||
STBRP_ASSERT(node->next->x > x0); // we ended up handling this in the caller for efficiency
|
||||
#endif
|
||||
|
||||
STBRP_ASSERT(node->x <= x0);
|
||||
|
||||
min_y = 0;
|
||||
waste_area = 0;
|
||||
visited_width = 0;
|
||||
while (node->x < x1) {
|
||||
if (node->y > min_y) {
|
||||
// raise min_y higher.
|
||||
// we've accounted for all waste up to min_y,
|
||||
// but we'll now add more waste for everything we've visted
|
||||
waste_area += visited_width * (node->y - min_y);
|
||||
min_y = node->y;
|
||||
// the first time through, visited_width might be reduced
|
||||
if (node->x < x0)
|
||||
visited_width += node->next->x - x0;
|
||||
else
|
||||
visited_width += node->next->x - node->x;
|
||||
} else {
|
||||
// add waste area
|
||||
int under_width = node->next->x - node->x;
|
||||
if (under_width + visited_width > width)
|
||||
under_width = width - visited_width;
|
||||
waste_area += under_width * (min_y - node->y);
|
||||
visited_width += under_width;
|
||||
}
|
||||
node = node->next;
|
||||
}
|
||||
|
||||
*pwaste = waste_area;
|
||||
return min_y;
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int x,y;
|
||||
stbrp_node **prev_link;
|
||||
} stbrp__findresult;
|
||||
|
||||
static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int width, int height)
|
||||
{
|
||||
int best_waste = (1<<30), best_x, best_y = (1 << 30);
|
||||
stbrp__findresult fr;
|
||||
stbrp_node **prev, *node, *tail, **best = NULL;
|
||||
|
||||
// align to multiple of c->align
|
||||
width = (width + c->align - 1);
|
||||
width -= width % c->align;
|
||||
STBRP_ASSERT(width % c->align == 0);
|
||||
|
||||
// if it can't possibly fit, bail immediately
|
||||
if (width > c->width || height > c->height) {
|
||||
fr.prev_link = NULL;
|
||||
fr.x = fr.y = 0;
|
||||
return fr;
|
||||
}
|
||||
|
||||
node = c->active_head;
|
||||
prev = &c->active_head;
|
||||
while (node->x + width <= c->width) {
|
||||
int y,waste;
|
||||
y = stbrp__skyline_find_min_y(c, node, node->x, width, &waste);
|
||||
if (c->heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight) { // actually just want to test BL
|
||||
// bottom left
|
||||
if (y < best_y) {
|
||||
best_y = y;
|
||||
best = prev;
|
||||
}
|
||||
} else {
|
||||
// best-fit
|
||||
if (y + height <= c->height) {
|
||||
// can only use it if it first vertically
|
||||
if (y < best_y || (y == best_y && waste < best_waste)) {
|
||||
best_y = y;
|
||||
best_waste = waste;
|
||||
best = prev;
|
||||
}
|
||||
}
|
||||
}
|
||||
prev = &node->next;
|
||||
node = node->next;
|
||||
}
|
||||
|
||||
best_x = (best == NULL) ? 0 : (*best)->x;
|
||||
|
||||
// if doing best-fit (BF), we also have to try aligning right edge to each node position
|
||||
//
|
||||
// e.g, if fitting
|
||||
//
|
||||
// ____________________
|
||||
// |____________________|
|
||||
//
|
||||
// into
|
||||
//
|
||||
// | |
|
||||
// | ____________|
|
||||
// |____________|
|
||||
//
|
||||
// then right-aligned reduces waste, but bottom-left BL is always chooses left-aligned
|
||||
//
|
||||
// This makes BF take about 2x the time
|
||||
|
||||
if (c->heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight) {
|
||||
tail = c->active_head;
|
||||
node = c->active_head;
|
||||
prev = &c->active_head;
|
||||
// find first node that's admissible
|
||||
while (tail->x < width)
|
||||
tail = tail->next;
|
||||
while (tail) {
|
||||
int xpos = tail->x - width;
|
||||
int y,waste;
|
||||
STBRP_ASSERT(xpos >= 0);
|
||||
// find the left position that matches this
|
||||
while (node->next->x <= xpos) {
|
||||
prev = &node->next;
|
||||
node = node->next;
|
||||
}
|
||||
STBRP_ASSERT(node->next->x > xpos && node->x <= xpos);
|
||||
y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste);
|
||||
if (y + height <= c->height) {
|
||||
if (y <= best_y) {
|
||||
if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
|
||||
best_x = xpos;
|
||||
STBRP_ASSERT(y <= best_y);
|
||||
best_y = y;
|
||||
best_waste = waste;
|
||||
best = prev;
|
||||
}
|
||||
}
|
||||
}
|
||||
tail = tail->next;
|
||||
}
|
||||
}
|
||||
|
||||
fr.prev_link = best;
|
||||
fr.x = best_x;
|
||||
fr.y = best_y;
|
||||
return fr;
|
||||
}
|
||||
|
||||
static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, int width, int height)
|
||||
{
|
||||
// find best position according to heuristic
|
||||
stbrp__findresult res = stbrp__skyline_find_best_pos(context, width, height);
|
||||
stbrp_node *node, *cur;
|
||||
|
||||
// bail if:
|
||||
// 1. it failed
|
||||
// 2. the best node doesn't fit (we don't always check this)
|
||||
// 3. we're out of memory
|
||||
if (res.prev_link == NULL || res.y + height > context->height || context->free_head == NULL) {
|
||||
res.prev_link = NULL;
|
||||
return res;
|
||||
}
|
||||
|
||||
// on success, create new node
|
||||
node = context->free_head;
|
||||
node->x = (stbrp_coord) res.x;
|
||||
node->y = (stbrp_coord) (res.y + height);
|
||||
|
||||
context->free_head = node->next;
|
||||
|
||||
// insert the new node into the right starting point, and
|
||||
// let 'cur' point to the remaining nodes needing to be
|
||||
// stiched back in
|
||||
|
||||
cur = *res.prev_link;
|
||||
if (cur->x < res.x) {
|
||||
// preserve the existing one, so start testing with the next one
|
||||
stbrp_node *next = cur->next;
|
||||
cur->next = node;
|
||||
cur = next;
|
||||
} else {
|
||||
*res.prev_link = node;
|
||||
}
|
||||
|
||||
// from here, traverse cur and free the nodes, until we get to one
|
||||
// that shouldn't be freed
|
||||
while (cur->next && cur->next->x <= res.x + width) {
|
||||
stbrp_node *next = cur->next;
|
||||
// move the current node to the free list
|
||||
cur->next = context->free_head;
|
||||
context->free_head = cur;
|
||||
cur = next;
|
||||
}
|
||||
|
||||
// stitch the list back in
|
||||
node->next = cur;
|
||||
|
||||
if (cur->x < res.x + width)
|
||||
cur->x = (stbrp_coord) (res.x + width);
|
||||
|
||||
#ifdef _DEBUG
|
||||
cur = context->active_head;
|
||||
while (cur->x < context->width) {
|
||||
STBRP_ASSERT(cur->x < cur->next->x);
|
||||
cur = cur->next;
|
||||
}
|
||||
STBRP_ASSERT(cur->next == NULL);
|
||||
|
||||
{
|
||||
int count=0;
|
||||
cur = context->active_head;
|
||||
while (cur) {
|
||||
cur = cur->next;
|
||||
++count;
|
||||
}
|
||||
cur = context->free_head;
|
||||
while (cur) {
|
||||
cur = cur->next;
|
||||
++count;
|
||||
}
|
||||
STBRP_ASSERT(count == context->num_nodes+2);
|
||||
}
|
||||
#endif
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
// [DEAR IMGUI] Added STBRP__CDECL
|
||||
static int STBRP__CDECL rect_height_compare(const void *a, const void *b)
|
||||
{
|
||||
const stbrp_rect *p = (const stbrp_rect *) a;
|
||||
const stbrp_rect *q = (const stbrp_rect *) b;
|
||||
if (p->h > q->h)
|
||||
return -1;
|
||||
if (p->h < q->h)
|
||||
return 1;
|
||||
return (p->w > q->w) ? -1 : (p->w < q->w);
|
||||
}
|
||||
|
||||
// [DEAR IMGUI] Added STBRP__CDECL
|
||||
static int STBRP__CDECL rect_original_order(const void *a, const void *b)
|
||||
{
|
||||
const stbrp_rect *p = (const stbrp_rect *) a;
|
||||
const stbrp_rect *q = (const stbrp_rect *) b;
|
||||
return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
|
||||
}
|
||||
|
||||
#ifdef STBRP_LARGE_RECTS
|
||||
#define STBRP__MAXVAL 0xffffffff
|
||||
#else
|
||||
#define STBRP__MAXVAL 0xffff
|
||||
#endif
|
||||
|
||||
STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects)
|
||||
{
|
||||
int i, all_rects_packed = 1;
|
||||
|
||||
// we use the 'was_packed' field internally to allow sorting/unsorting
|
||||
for (i=0; i < num_rects; ++i) {
|
||||
rects[i].was_packed = i;
|
||||
}
|
||||
|
||||
// sort according to heuristic
|
||||
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_height_compare);
|
||||
|
||||
for (i=0; i < num_rects; ++i) {
|
||||
if (rects[i].w == 0 || rects[i].h == 0) {
|
||||
rects[i].x = rects[i].y = 0; // empty rect needs no space
|
||||
} else {
|
||||
stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h);
|
||||
if (fr.prev_link) {
|
||||
rects[i].x = (stbrp_coord) fr.x;
|
||||
rects[i].y = (stbrp_coord) fr.y;
|
||||
} else {
|
||||
rects[i].x = rects[i].y = STBRP__MAXVAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// unsort
|
||||
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order);
|
||||
|
||||
// set was_packed flags and all_rects_packed status
|
||||
for (i=0; i < num_rects; ++i) {
|
||||
rects[i].was_packed = !(rects[i].x == STBRP__MAXVAL && rects[i].y == STBRP__MAXVAL);
|
||||
if (!rects[i].was_packed)
|
||||
all_rects_packed = 0;
|
||||
}
|
||||
|
||||
// return the all_rects_packed status
|
||||
return all_rects_packed;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
This software is available under 2 licenses -- choose whichever you prefer.
|
||||
------------------------------------------------------------------------------
|
||||
ALTERNATIVE A - MIT License
|
||||
Copyright (c) 2017 Sean Barrett
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
------------------------------------------------------------------------------
|
||||
ALTERNATIVE B - Public Domain (www.unlicense.org)
|
||||
This is free and unencumbered software released into the public domain.
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
|
||||
software, either in source code form or as a compiled binary, for any purpose,
|
||||
commercial or non-commercial, and by any means.
|
||||
In jurisdictions that recognize copyright laws, the author or authors of this
|
||||
software dedicate any and all copyright interest in the software to the public
|
||||
domain. We make this dedication for the benefit of the public at large and to
|
||||
the detriment of our heirs and successors. We intend this dedication to be an
|
||||
overt act of relinquishment in perpetuity of all present and future rights to
|
||||
this software under copyright law.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
1447
vendor/librw/skeleton/imgui/imstb_textedit.h
vendored
Normal file
1447
vendor/librw/skeleton/imgui/imstb_textedit.h
vendored
Normal file
File diff suppressed because it is too large
Load diff
4903
vendor/librw/skeleton/imgui/imstb_truetype.h
vendored
Normal file
4903
vendor/librw/skeleton/imgui/imstb_truetype.h
vendored
Normal file
File diff suppressed because it is too large
Load diff
326
vendor/librw/skeleton/sdl2.cpp
vendored
Normal file
326
vendor/librw/skeleton/sdl2.cpp
vendored
Normal file
|
|
@ -0,0 +1,326 @@
|
|||
#ifdef LIBRW_SDL2
|
||||
|
||||
#include <rw.h>
|
||||
#include "skeleton.h"
|
||||
|
||||
using namespace sk;
|
||||
using namespace rw;
|
||||
|
||||
#ifdef RW_OPENGL
|
||||
|
||||
SDL_Window *window;
|
||||
|
||||
static int keyCodeToSkKey(SDL_Keycode keycode) {
|
||||
switch (keycode) {
|
||||
case SDLK_SPACE: return ' ';
|
||||
case SDLK_QUOTE: return '\'';
|
||||
case SDLK_COMMA: return ',';
|
||||
case SDLK_MINUS: return '-';
|
||||
case SDLK_PERIOD: return '.';
|
||||
case SDLK_SLASH: return '/';
|
||||
|
||||
case SDLK_0: return '0';
|
||||
case SDLK_1: return '1';
|
||||
case SDLK_2: return '2';
|
||||
case SDLK_3: return '3';
|
||||
case SDLK_4: return '4';
|
||||
case SDLK_5: return '5';
|
||||
case SDLK_6: return '6';
|
||||
case SDLK_7: return '7';
|
||||
case SDLK_8: return '8';
|
||||
case SDLK_9: return '9';
|
||||
|
||||
case SDLK_SEMICOLON: return ';';
|
||||
case SDLK_EQUALS: return '=';
|
||||
|
||||
case SDLK_a: return 'A';
|
||||
case SDLK_b: return 'B';
|
||||
case SDLK_c: return 'C';
|
||||
case SDLK_d: return 'D';
|
||||
case SDLK_e: return 'E';
|
||||
case SDLK_f: return 'F';
|
||||
case SDLK_g: return 'G';
|
||||
case SDLK_h: return 'H';
|
||||
case SDLK_i: return 'I';
|
||||
case SDLK_j: return 'J';
|
||||
case SDLK_k: return 'K';
|
||||
case SDLK_l: return 'L';
|
||||
case SDLK_m: return 'M';
|
||||
case SDLK_n: return 'N';
|
||||
case SDLK_o: return 'O';
|
||||
case SDLK_p: return 'P';
|
||||
case SDLK_q: return 'Q';
|
||||
case SDLK_r: return 'R';
|
||||
case SDLK_s: return 'S';
|
||||
case SDLK_t: return 'T';
|
||||
case SDLK_u: return 'U';
|
||||
case SDLK_v: return 'V';
|
||||
case SDLK_w: return 'W';
|
||||
case SDLK_x: return 'X';
|
||||
case SDLK_y: return 'Y';
|
||||
case SDLK_z: return 'Z';
|
||||
|
||||
case SDLK_LEFTBRACKET: return '[';
|
||||
case SDLK_BACKSLASH: return '\\';
|
||||
case SDLK_RIGHTBRACKET: return ']';
|
||||
case SDLK_BACKQUOTE: return '`';
|
||||
case SDLK_ESCAPE: return KEY_ESC;
|
||||
case SDLK_RETURN: return KEY_ENTER;
|
||||
case SDLK_TAB: return KEY_TAB;
|
||||
case SDLK_BACKSPACE: return KEY_BACKSP;
|
||||
case SDLK_INSERT: return KEY_INS;
|
||||
case SDLK_DELETE: return KEY_DEL;
|
||||
case SDLK_RIGHT: return KEY_RIGHT;
|
||||
case SDLK_LEFT: return KEY_LEFT;
|
||||
case SDLK_DOWN: return KEY_DOWN;
|
||||
case SDLK_UP: return KEY_UP;
|
||||
case SDLK_PAGEUP: return KEY_PGUP;
|
||||
case SDLK_PAGEDOWN: return KEY_PGDN;
|
||||
case SDLK_HOME: return KEY_HOME;
|
||||
case SDLK_END: return KEY_END;
|
||||
case SDLK_CAPSLOCK: return KEY_CAPSLK;
|
||||
case SDLK_SCROLLLOCK: return KEY_NULL;
|
||||
case SDLK_NUMLOCKCLEAR: return KEY_NULL;
|
||||
case SDLK_PRINTSCREEN: return KEY_NULL;
|
||||
case SDLK_PAUSE: return KEY_NULL;
|
||||
|
||||
case SDLK_F1: return KEY_F1;
|
||||
case SDLK_F2: return KEY_F2;
|
||||
case SDLK_F3: return KEY_F3;
|
||||
case SDLK_F4: return KEY_F4;
|
||||
case SDLK_F5: return KEY_F5;
|
||||
case SDLK_F6: return KEY_F6;
|
||||
case SDLK_F7: return KEY_F7;
|
||||
case SDLK_F8: return KEY_F8;
|
||||
case SDLK_F9: return KEY_F9;
|
||||
case SDLK_F10: return KEY_F10;
|
||||
case SDLK_F11: return KEY_F11;
|
||||
case SDLK_F12: return KEY_F12;
|
||||
case SDLK_F13: return KEY_NULL;
|
||||
case SDLK_F14: return KEY_NULL;
|
||||
case SDLK_F15: return KEY_NULL;
|
||||
case SDLK_F16: return KEY_NULL;
|
||||
case SDLK_F17: return KEY_NULL;
|
||||
case SDLK_F18: return KEY_NULL;
|
||||
case SDLK_F19: return KEY_NULL;
|
||||
case SDLK_F20: return KEY_NULL;
|
||||
case SDLK_F21: return KEY_NULL;
|
||||
case SDLK_F22: return KEY_NULL;
|
||||
case SDLK_F23: return KEY_NULL;
|
||||
case SDLK_F24: return KEY_NULL;
|
||||
|
||||
case SDLK_KP_0: return KEY_NULL;
|
||||
case SDLK_KP_1: return KEY_NULL;
|
||||
case SDLK_KP_2: return KEY_NULL;
|
||||
case SDLK_KP_3: return KEY_NULL;
|
||||
case SDLK_KP_4: return KEY_NULL;
|
||||
case SDLK_KP_5: return KEY_NULL;
|
||||
case SDLK_KP_6: return KEY_NULL;
|
||||
case SDLK_KP_7: return KEY_NULL;
|
||||
case SDLK_KP_8: return KEY_NULL;
|
||||
case SDLK_KP_9: return KEY_NULL;
|
||||
case SDLK_KP_DECIMAL: return KEY_NULL;
|
||||
case SDLK_KP_DIVIDE: return KEY_NULL;
|
||||
case SDLK_KP_MULTIPLY: return KEY_NULL;
|
||||
case SDLK_KP_MINUS: return KEY_NULL;
|
||||
case SDLK_KP_PLUS: return KEY_NULL;
|
||||
case SDLK_KP_ENTER: return KEY_NULL;
|
||||
case SDLK_KP_EQUALS: return KEY_NULL;
|
||||
|
||||
case SDLK_LSHIFT: return KEY_LSHIFT;
|
||||
case SDLK_LCTRL: return KEY_LCTRL;
|
||||
case SDLK_LALT: return KEY_LALT;
|
||||
case SDLK_LGUI: return KEY_NULL;
|
||||
case SDLK_RSHIFT: return KEY_RSHIFT;
|
||||
case SDLK_RCTRL: return KEY_RCTRL;
|
||||
case SDLK_RALT: return KEY_RALT;
|
||||
case SDLK_RGUI: return KEY_NULL;
|
||||
case SDLK_MENU: return KEY_NULL;
|
||||
}
|
||||
return KEY_NULL;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void
|
||||
keypress(SDL_Window *window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if(key >= 0 && key <= GLFW_KEY_LAST){
|
||||
if(action == GLFW_RELEASE) KeyUp(keymap[key]);
|
||||
else if(action == GLFW_PRESS) KeyDown(keymap[key]);
|
||||
else if(action == GLFW_REPEAT) KeyDown(keymap[key]);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
charinput(GLFWwindow *window, unsigned int c)
|
||||
{
|
||||
EventHandler(CHARINPUT, (void*)(uintptr)c);
|
||||
}
|
||||
|
||||
static void
|
||||
resize(GLFWwindow *window, int w, int h)
|
||||
{
|
||||
rw::Rect r;
|
||||
r.x = 0;
|
||||
r.y = 0;
|
||||
r.w = w;
|
||||
r.h = h;
|
||||
EventHandler(RESIZE, &r);
|
||||
}
|
||||
|
||||
static void
|
||||
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)
|
||||
buttons |= 1;
|
||||
else
|
||||
buttons &= ~1;
|
||||
break;
|
||||
case GLFW_MOUSE_BUTTON_MIDDLE:
|
||||
if(action == GLFW_PRESS)
|
||||
buttons |= 2;
|
||||
else
|
||||
buttons &= ~2;
|
||||
break;
|
||||
case GLFW_MOUSE_BUTTON_RIGHT:
|
||||
if(action == GLFW_PRESS)
|
||||
buttons |= 4;
|
||||
else
|
||||
buttons &= ~4;
|
||||
break;
|
||||
}
|
||||
|
||||
sk::MouseState ms;
|
||||
ms.buttons = buttons;
|
||||
EventHandler(MOUSEBTN, &ms);
|
||||
}
|
||||
#endif
|
||||
|
||||
enum mousebutton {
|
||||
BUTTON_LEFT = 0x1,
|
||||
BUTTON_MIDDLE = 0x2,
|
||||
BUTTON_RIGHT = 0x4,
|
||||
};
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
args.argc = argc;
|
||||
args.argv = argv;
|
||||
|
||||
if(EventHandler(INITIALIZE, nil) == EVENTERROR)
|
||||
return 0;
|
||||
|
||||
engineOpenParams.width = sk::globals.width;
|
||||
engineOpenParams.height = sk::globals.height;
|
||||
engineOpenParams.windowtitle = sk::globals.windowtitle;
|
||||
engineOpenParams.window = &window;
|
||||
|
||||
if(EventHandler(RWINITIALIZE, nil) == EVENTERROR)
|
||||
return 0;
|
||||
|
||||
float lastTime = SDL_GetTicks();
|
||||
SDL_Event event;
|
||||
int mouseButtons = 0;
|
||||
|
||||
SDL_StartTextInput();
|
||||
|
||||
while(!sk::globals.quit){
|
||||
while(SDL_PollEvent(&event)){
|
||||
switch(event.type){
|
||||
case SDL_QUIT:
|
||||
sk::globals.quit = true;
|
||||
break;
|
||||
case SDL_WINDOWEVENT:
|
||||
switch (event.window.event) {
|
||||
case SDL_WINDOWEVENT_RESIZED: {
|
||||
rw::Rect r;
|
||||
SDL_GetWindowPosition(window, &r.x, &r.y);
|
||||
r.w = event.window.data1;
|
||||
r.h = event.window.data2;
|
||||
EventHandler(RESIZE, &r);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_KEYUP: {
|
||||
int c = keyCodeToSkKey(event.key.keysym.sym);
|
||||
EventHandler(KEYUP, &c);
|
||||
break;
|
||||
}
|
||||
case SDL_KEYDOWN: {
|
||||
int c = keyCodeToSkKey(event.key.keysym.sym);
|
||||
EventHandler(KEYDOWN, &c);
|
||||
break;
|
||||
}
|
||||
case SDL_TEXTINPUT: {
|
||||
char *c = event.text.text;
|
||||
while (int ci = *c) {
|
||||
EventHandler(CHARINPUT, (void*)(uintptr)ci);
|
||||
++c;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SDL_MOUSEMOTION: {
|
||||
sk::MouseState ms;
|
||||
ms.posx = event.motion.x;
|
||||
ms.posy = event.motion.y;
|
||||
EventHandler(MOUSEMOVE, &ms);
|
||||
break;
|
||||
}
|
||||
case SDL_MOUSEBUTTONDOWN: {
|
||||
switch (event.button.button) {
|
||||
case SDL_BUTTON_LEFT: mouseButtons |= BUTTON_LEFT; break;
|
||||
case SDL_BUTTON_MIDDLE: mouseButtons |= BUTTON_MIDDLE; break;
|
||||
case SDL_BUTTON_RIGHT: mouseButtons |= BUTTON_RIGHT; break;
|
||||
}
|
||||
sk::MouseState ms;
|
||||
ms.buttons = mouseButtons;
|
||||
EventHandler(MOUSEBTN, &ms);
|
||||
break;
|
||||
}
|
||||
case SDL_MOUSEBUTTONUP: {
|
||||
switch (event.button.button) {
|
||||
case SDL_BUTTON_LEFT: mouseButtons &= ~BUTTON_LEFT; break;
|
||||
case SDL_BUTTON_MIDDLE: mouseButtons &= ~BUTTON_MIDDLE; break;
|
||||
case SDL_BUTTON_RIGHT: mouseButtons &= ~BUTTON_RIGHT; break;
|
||||
}
|
||||
sk::MouseState ms;
|
||||
ms.buttons = mouseButtons;
|
||||
EventHandler(MOUSEBTN, &ms);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
float currTime = SDL_GetTicks();
|
||||
float timeDelta = (currTime - lastTime) * 0.001f;
|
||||
|
||||
EventHandler(IDLE, &timeDelta);
|
||||
|
||||
lastTime = currTime;
|
||||
}
|
||||
|
||||
SDL_StopTextInput();
|
||||
|
||||
EventHandler(RWTERMINATE, nil);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace sk {
|
||||
|
||||
void
|
||||
SetMousePosition(int x, int y)
|
||||
{
|
||||
SDL_WarpMouseInWindow(*engineOpenParams.window, x, y);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
192
vendor/librw/skeleton/skeleton.cpp
vendored
Normal file
192
vendor/librw/skeleton/skeleton.cpp
vendored
Normal file
|
|
@ -0,0 +1,192 @@
|
|||
#include <rw.h>
|
||||
#include "skeleton.h"
|
||||
|
||||
|
||||
namespace sk {
|
||||
|
||||
Globals globals;
|
||||
Args args;
|
||||
|
||||
|
||||
bool
|
||||
InitRW(void)
|
||||
{
|
||||
if(!rw::Engine::init())
|
||||
return false;
|
||||
if(AppEventHandler(sk::PLUGINATTACH, nil) == EVENTERROR)
|
||||
return false;
|
||||
if(!rw::Engine::open(&engineOpenParams))
|
||||
return false;
|
||||
|
||||
SubSystemInfo info;
|
||||
int i, n;
|
||||
n = Engine::getNumSubSystems();
|
||||
for(i = 0; i < n; i++)
|
||||
if(Engine::getSubSystemInfo(&info, i))
|
||||
printf("subsystem: %s\n", info.name);
|
||||
Engine::setSubSystem(n-1);
|
||||
|
||||
int want = -1;
|
||||
VideoMode mode;
|
||||
n = Engine::getNumVideoModes();
|
||||
for(i = 0; i < n; i++)
|
||||
if(Engine::getVideoModeInfo(&mode, i)){
|
||||
// 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);
|
||||
}
|
||||
// if(want >= 0) Engine::setVideoMode(want);
|
||||
Engine::getVideoModeInfo(&mode, Engine::getCurrentVideoMode());
|
||||
|
||||
if(mode.flags & VIDEOMODEEXCLUSIVE){
|
||||
globals.width = mode.width;
|
||||
globals.height = mode.height;
|
||||
}
|
||||
|
||||
if(!rw::Engine::start())
|
||||
return false;
|
||||
|
||||
rw::Charset::open();
|
||||
|
||||
rw::Image::setSearchPath("./");
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
TerminateRW(void)
|
||||
{
|
||||
rw::Charset::close();
|
||||
|
||||
// TODO: delete all tex dicts
|
||||
rw::Engine::stop();
|
||||
rw::Engine::close();
|
||||
rw::Engine::term();
|
||||
}
|
||||
|
||||
Camera*
|
||||
CameraCreate(int32 width, int32 height, bool32 z)
|
||||
{
|
||||
Camera *cam;
|
||||
cam = Camera::create();
|
||||
cam->setFrame(Frame::create());
|
||||
cam->frameBuffer = Raster::create(width, height, 0, Raster::CAMERA);
|
||||
cam->zBuffer = Raster::create(width, height, 0, Raster::ZBUFFER);
|
||||
return cam;
|
||||
}
|
||||
|
||||
void
|
||||
CameraDestroy(rw::Camera *cam)
|
||||
{
|
||||
if(cam->frameBuffer){
|
||||
cam->frameBuffer->destroy();
|
||||
cam->frameBuffer = nil;
|
||||
}
|
||||
if(cam->zBuffer){
|
||||
cam->zBuffer->destroy();
|
||||
cam->zBuffer = nil;
|
||||
}
|
||||
rw::Frame *frame = cam->getFrame();
|
||||
if(frame){
|
||||
cam->setFrame(nil);
|
||||
frame->destroy();
|
||||
}
|
||||
cam->destroy();
|
||||
}
|
||||
|
||||
void
|
||||
CameraSize(Camera *cam, Rect *r, float viewWindow, float aspectRatio)
|
||||
{
|
||||
if(cam->frameBuffer){
|
||||
cam->frameBuffer->destroy();
|
||||
cam->frameBuffer = nil;
|
||||
}
|
||||
if(cam->zBuffer){
|
||||
cam->zBuffer->destroy();
|
||||
cam->zBuffer = nil;
|
||||
}
|
||||
cam->frameBuffer = Raster::create(r->w, r->h, 0, Raster::CAMERA);
|
||||
cam->zBuffer = Raster::create(r->w, r->h, 0, Raster::ZBUFFER);
|
||||
|
||||
if(viewWindow != 0.0f){
|
||||
rw::V2d vw;
|
||||
// TODO: aspect ratio when fullscreen
|
||||
if(r->w > r->h){
|
||||
vw.x = viewWindow;
|
||||
vw.y = viewWindow / ((float)r->w/r->h);
|
||||
}else{
|
||||
vw.x = viewWindow / ((float)r->h/r->w);
|
||||
vw.y = viewWindow;
|
||||
}
|
||||
cam->setViewWindow(&vw);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CameraMove(Camera *cam, V3d *delta)
|
||||
{
|
||||
rw::V3d offset;
|
||||
rw::V3d::transformVectors(&offset, delta, 1, &cam->getFrame()->matrix);
|
||||
cam->getFrame()->translate(&offset);
|
||||
}
|
||||
|
||||
void
|
||||
CameraPan(Camera *cam, V3d *pos, float angle)
|
||||
{
|
||||
rw::Frame *frame = cam->getFrame();
|
||||
rw::V3d trans = pos ? *pos : frame->matrix.pos;
|
||||
rw::V3d negTrans = rw::scale(trans, -1.0f);
|
||||
frame->translate(&negTrans);
|
||||
frame->rotate(&frame->matrix.up, angle);
|
||||
frame->translate(&trans);
|
||||
}
|
||||
|
||||
void
|
||||
CameraTilt(Camera *cam, V3d *pos, float angle)
|
||||
{
|
||||
rw::Frame *frame = cam->getFrame();
|
||||
rw::V3d trans = pos ? *pos : frame->matrix.pos;
|
||||
rw::V3d negTrans = rw::scale(trans, -1.0f);
|
||||
frame->translate(&negTrans);
|
||||
frame->rotate(&frame->matrix.right, angle);
|
||||
frame->translate(&trans);
|
||||
}
|
||||
|
||||
void
|
||||
CameraRotate(Camera *cam, V3d *pos, float angle)
|
||||
{
|
||||
rw::Frame *frame = cam->getFrame();
|
||||
rw::V3d trans = pos ? *pos : frame->matrix.pos;
|
||||
rw::V3d negTrans = rw::scale(trans, -1.0f);
|
||||
frame->translate(&negTrans);
|
||||
frame->rotate(&frame->matrix.at, angle);
|
||||
frame->translate(&negTrans);
|
||||
}
|
||||
|
||||
EventStatus
|
||||
EventHandler(Event e, void *param)
|
||||
{
|
||||
EventStatus s;
|
||||
if (e == INITIALIZE) {
|
||||
ImGui::CreateContext();
|
||||
}
|
||||
|
||||
s = AppEventHandler(e, param);
|
||||
if(e == QUIT){
|
||||
globals.quit = 1;
|
||||
return EVENTPROCESSED;
|
||||
}
|
||||
if(s == EVENTNOTPROCESSED)
|
||||
switch(e){
|
||||
case RWINITIALIZE:
|
||||
return InitRW() ? EVENTPROCESSED : EVENTERROR;
|
||||
case RWTERMINATE:
|
||||
TerminateRW();
|
||||
return EVENTPROCESSED;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
}
|
||||
120
vendor/librw/skeleton/skeleton.h
vendored
Normal file
120
vendor/librw/skeleton/skeleton.h
vendored
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
extern rw::EngineOpenParams engineOpenParams;
|
||||
|
||||
namespace sk {
|
||||
|
||||
using namespace rw;
|
||||
|
||||
// same as RW skeleton
|
||||
enum Key
|
||||
{
|
||||
// ascii...
|
||||
|
||||
KEY_ESC = 128,
|
||||
|
||||
KEY_F1 = 129,
|
||||
KEY_F2 = 130,
|
||||
KEY_F3 = 131,
|
||||
KEY_F4 = 132,
|
||||
KEY_F5 = 133,
|
||||
KEY_F6 = 134,
|
||||
KEY_F7 = 135,
|
||||
KEY_F8 = 136,
|
||||
KEY_F9 = 137,
|
||||
KEY_F10 = 138,
|
||||
KEY_F11 = 139,
|
||||
KEY_F12 = 140,
|
||||
|
||||
KEY_INS = 141,
|
||||
KEY_DEL = 142,
|
||||
KEY_HOME = 143,
|
||||
KEY_END = 144,
|
||||
KEY_PGUP = 145,
|
||||
KEY_PGDN = 146,
|
||||
|
||||
KEY_UP = 147,
|
||||
KEY_DOWN = 148,
|
||||
KEY_LEFT = 149,
|
||||
KEY_RIGHT = 150,
|
||||
|
||||
// some stuff ommitted
|
||||
|
||||
KEY_BACKSP = 168,
|
||||
KEY_TAB = 169,
|
||||
KEY_CAPSLK = 170,
|
||||
KEY_ENTER = 171,
|
||||
KEY_LSHIFT = 172,
|
||||
KEY_RSHIFT = 173,
|
||||
KEY_LCTRL = 174,
|
||||
KEY_RCTRL = 175,
|
||||
KEY_LALT = 176,
|
||||
KEY_RALT = 177,
|
||||
|
||||
KEY_NULL, // unused
|
||||
KEY_NUMKEYS,
|
||||
};
|
||||
|
||||
enum EventStatus
|
||||
{
|
||||
EVENTERROR,
|
||||
EVENTPROCESSED,
|
||||
EVENTNOTPROCESSED
|
||||
};
|
||||
|
||||
enum Event
|
||||
{
|
||||
INITIALIZE,
|
||||
RWINITIALIZE,
|
||||
RWTERMINATE,
|
||||
SELECTDEVICE,
|
||||
PLUGINATTACH,
|
||||
KEYDOWN,
|
||||
KEYUP,
|
||||
CHARINPUT,
|
||||
MOUSEMOVE,
|
||||
MOUSEBTN,
|
||||
RESIZE,
|
||||
IDLE,
|
||||
QUIT
|
||||
};
|
||||
|
||||
struct Globals
|
||||
{
|
||||
const char *windowtitle;
|
||||
int32 width;
|
||||
int32 height;
|
||||
bool32 quit;
|
||||
};
|
||||
extern Globals globals;
|
||||
|
||||
// Argument to mouse events
|
||||
struct MouseState
|
||||
{
|
||||
int posx, posy;
|
||||
int buttons; // bits 0-2 are left, middle, right button down
|
||||
};
|
||||
|
||||
struct Args
|
||||
{
|
||||
int argc;
|
||||
char **argv;
|
||||
};
|
||||
extern Args args;
|
||||
|
||||
bool InitRW(void);
|
||||
void TerminateRW(void);
|
||||
Camera *CameraCreate(int32 width, int32 height, bool32 z);
|
||||
void CameraDestroy(rw::Camera *cam);
|
||||
void CameraSize(Camera *cam, Rect *r, float viewWindow = 0.0f, float aspectRatio = 0.0f);
|
||||
void CameraMove(Camera *cam, V3d *delta);
|
||||
void CameraPan(Camera *cam, V3d *pos, float angle);
|
||||
void CameraTilt(Camera *cam, V3d *pos, float angle);
|
||||
void CameraRotate(Camera *cam, V3d *pos, float angle);
|
||||
void SetMousePosition(int x, int y);
|
||||
EventStatus EventHandler(Event e, void *param);
|
||||
|
||||
}
|
||||
|
||||
sk::EventStatus AppEventHandler(sk::Event e, void *param);
|
||||
|
||||
#include "imgui/imgui.h"
|
||||
#include "imgui/imgui_impl_rw.h"
|
||||
315
vendor/librw/skeleton/win.cpp
vendored
Normal file
315
vendor/librw/skeleton/win.cpp
vendored
Normal file
|
|
@ -0,0 +1,315 @@
|
|||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <rw.h>
|
||||
#include "skeleton.h"
|
||||
|
||||
using namespace sk;
|
||||
using namespace rw;
|
||||
|
||||
#ifdef RW_D3D9
|
||||
|
||||
#ifndef VK_OEM_NEC_EQUAL
|
||||
#define VK_OEM_NEC_EQUAL 0x92
|
||||
#endif
|
||||
|
||||
static int keymap[256];
|
||||
static void
|
||||
initkeymap(void)
|
||||
{
|
||||
int i;
|
||||
for(i = 0; i < 256; i++)
|
||||
keymap[i] = KEY_NULL;
|
||||
keymap[VK_SPACE] = ' ';
|
||||
keymap[VK_OEM_7] = '\'';
|
||||
keymap[VK_OEM_COMMA] = ',';
|
||||
keymap[VK_OEM_MINUS] = '-';
|
||||
keymap[VK_OEM_PERIOD] = '.';
|
||||
keymap[VK_OEM_2] = '/';
|
||||
for(i = '0'; i <= '9'; i++)
|
||||
keymap[i] = i;
|
||||
keymap[VK_OEM_1] = ';';
|
||||
keymap[VK_OEM_NEC_EQUAL] = '=';
|
||||
for(i = 'A'; i <= 'Z'; i++)
|
||||
keymap[i] = i;
|
||||
keymap[VK_OEM_4] = '[';
|
||||
keymap[VK_OEM_5] = '\\';
|
||||
keymap[VK_OEM_6] = ']';
|
||||
keymap[VK_OEM_3] = '`';
|
||||
keymap[VK_ESCAPE] = KEY_ESC;
|
||||
keymap[VK_RETURN] = KEY_ENTER;
|
||||
keymap[VK_TAB] = KEY_TAB;
|
||||
keymap[VK_BACK] = KEY_BACKSP;
|
||||
keymap[VK_INSERT] = KEY_INS;
|
||||
keymap[VK_DELETE] = KEY_DEL;
|
||||
keymap[VK_RIGHT] = KEY_RIGHT;
|
||||
keymap[VK_LEFT] = KEY_LEFT;
|
||||
keymap[VK_DOWN] = KEY_DOWN;
|
||||
keymap[VK_UP] = KEY_UP;
|
||||
keymap[VK_PRIOR] = KEY_PGUP;
|
||||
keymap[VK_NEXT] = KEY_PGDN;
|
||||
keymap[VK_HOME] = KEY_HOME;
|
||||
keymap[VK_END] = KEY_END;
|
||||
keymap[VK_MODECHANGE] = KEY_CAPSLK;
|
||||
for(i = VK_F1; i <= VK_F24; i++)
|
||||
keymap[i] = i-VK_F1+KEY_F1;
|
||||
keymap[VK_LSHIFT] = KEY_LSHIFT;
|
||||
keymap[VK_LCONTROL] = KEY_LCTRL;
|
||||
keymap[VK_LMENU] = KEY_LALT;
|
||||
keymap[VK_RSHIFT] = KEY_RSHIFT;
|
||||
keymap[VK_RCONTROL] = KEY_RCTRL;
|
||||
keymap[VK_RMENU] = KEY_RALT;
|
||||
}
|
||||
bool running;
|
||||
|
||||
static void KeyUp(int key) { EventHandler(KEYUP, &key); }
|
||||
static void KeyDown(int key) { EventHandler(KEYDOWN, &key); }
|
||||
|
||||
LRESULT CALLBACK
|
||||
WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
static int resizing = 0;
|
||||
static int buttons = 0;
|
||||
POINTS p;
|
||||
|
||||
MouseState ms;
|
||||
switch(msg){
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
|
||||
case WM_SYSKEYDOWN:
|
||||
case WM_KEYDOWN:
|
||||
if(wParam == VK_MENU){
|
||||
if(GetKeyState(VK_LMENU) & 0x8000) KeyDown(keymap[VK_LMENU]);
|
||||
if(GetKeyState(VK_RMENU) & 0x8000) KeyDown(keymap[VK_RMENU]);
|
||||
}else if(wParam == VK_CONTROL){
|
||||
if(GetKeyState(VK_LCONTROL) & 0x8000) KeyDown(keymap[VK_LCONTROL]);
|
||||
if(GetKeyState(VK_RCONTROL) & 0x8000) KeyDown(keymap[VK_RCONTROL]);
|
||||
}else if(wParam == VK_SHIFT){
|
||||
if(GetKeyState(VK_LSHIFT) & 0x8000) KeyDown(keymap[VK_LSHIFT]);
|
||||
if(GetKeyState(VK_RSHIFT) & 0x8000) KeyDown(keymap[VK_RSHIFT]);
|
||||
}else
|
||||
KeyDown(keymap[wParam]);
|
||||
break;
|
||||
|
||||
case WM_SYSKEYUP:
|
||||
case WM_KEYUP:
|
||||
if(wParam == VK_MENU){
|
||||
if((GetKeyState(VK_LMENU) & 0x8000) == 0) KeyUp(keymap[VK_LMENU]);
|
||||
if((GetKeyState(VK_RMENU) & 0x8000) == 0) KeyUp(keymap[VK_RMENU]);
|
||||
}else if(wParam == VK_CONTROL){
|
||||
if((GetKeyState(VK_LCONTROL) & 0x8000) == 0) KeyUp(keymap[VK_LCONTROL]);
|
||||
if((GetKeyState(VK_RCONTROL) & 0x8000) == 0) KeyUp(keymap[VK_RCONTROL]);
|
||||
}else if(wParam == VK_SHIFT){
|
||||
if((GetKeyState(VK_LSHIFT) & 0x8000) == 0) KeyUp(keymap[VK_LSHIFT]);
|
||||
if((GetKeyState(VK_RSHIFT) & 0x8000) == 0) KeyUp(keymap[VK_RSHIFT]);
|
||||
}else
|
||||
KeyUp(keymap[wParam]);
|
||||
break;
|
||||
|
||||
case WM_CHAR:
|
||||
if(wParam > 0 && wParam < 0x10000)
|
||||
EventHandler(CHARINPUT, (void*)wParam);
|
||||
break;
|
||||
|
||||
case WM_MOUSEMOVE:
|
||||
p = MAKEPOINTS(lParam);
|
||||
ms.posx = p.x;
|
||||
ms.posy = p.y;
|
||||
EventHandler(MOUSEMOVE, &ms);
|
||||
break;
|
||||
|
||||
case WM_LBUTTONDOWN:
|
||||
buttons |= 1; goto mbtn;
|
||||
case WM_LBUTTONUP:
|
||||
buttons &= ~1; goto mbtn;
|
||||
case WM_MBUTTONDOWN:
|
||||
buttons |= 2; goto mbtn;
|
||||
case WM_MBUTTONUP:
|
||||
buttons &= ~2; goto mbtn;
|
||||
case WM_RBUTTONDOWN:
|
||||
buttons |= 4; goto mbtn;
|
||||
case WM_RBUTTONUP:
|
||||
buttons &= ~4;
|
||||
mbtn:
|
||||
ms.buttons = buttons;
|
||||
EventHandler(MOUSEBTN, &ms);
|
||||
break;
|
||||
|
||||
case WM_SIZE:
|
||||
rw::Rect r;
|
||||
r.x = 0;
|
||||
r.y = 0;
|
||||
r.w = LOWORD(lParam);
|
||||
r.h = HIWORD(lParam);
|
||||
EventHandler(RESIZE, &r);
|
||||
break;
|
||||
|
||||
case WM_CLOSE:
|
||||
DestroyWindow(hwnd);
|
||||
break;
|
||||
|
||||
case WM_SYSCOMMAND:
|
||||
if ((wParam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu
|
||||
return 0;
|
||||
break;
|
||||
|
||||
case WM_QUIT:
|
||||
running = false;
|
||||
break;
|
||||
}
|
||||
return DefWindowProc(hwnd, msg, wParam, lParam);
|
||||
}
|
||||
|
||||
HWND
|
||||
MakeWindow(HINSTANCE instance, int width, int height, const char *title)
|
||||
{
|
||||
WNDCLASS wc;
|
||||
wc.style = CS_HREDRAW | CS_VREDRAW;
|
||||
wc.lpfnWndProc = WndProc;
|
||||
wc.cbClsExtra = 0;
|
||||
wc.cbWndExtra = 0;
|
||||
wc.hInstance = instance;
|
||||
wc.hIcon = LoadIcon(0, IDI_APPLICATION);
|
||||
wc.hCursor = LoadCursor(0, IDC_ARROW);
|
||||
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
|
||||
wc.lpszMenuName = 0;
|
||||
wc.lpszClassName = "librwD3D9";
|
||||
if(!RegisterClass(&wc)){
|
||||
MessageBox(0, "RegisterClass() - FAILED", 0, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int offx = 100;
|
||||
int offy = 100;
|
||||
RECT rect;
|
||||
rect.left = 0;
|
||||
rect.top = 0;
|
||||
rect.right = width;
|
||||
rect.bottom = height;
|
||||
DWORD style = WS_OVERLAPPEDWINDOW;
|
||||
AdjustWindowRect(&rect, style, FALSE);
|
||||
rect.right += -rect.left;
|
||||
rect.bottom += -rect.top;
|
||||
HWND win;
|
||||
win = CreateWindow("librwD3D9", title, style,
|
||||
offx, offy, rect.right, rect.bottom, 0, 0, instance, 0);
|
||||
if(!win){
|
||||
MessageBox(0, "CreateWindow() - FAILED", 0, 0);
|
||||
return 0;
|
||||
}
|
||||
ShowWindow(win, SW_SHOW);
|
||||
UpdateWindow(win);
|
||||
return win;
|
||||
}
|
||||
|
||||
void
|
||||
pollEvents(void)
|
||||
{
|
||||
MSG msg;
|
||||
while(PeekMessage(&msg, 0, 0, 0, PM_REMOVE)){
|
||||
if(msg.message == WM_QUIT){
|
||||
running = false;
|
||||
break;
|
||||
}else{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int WINAPI
|
||||
WinMain(HINSTANCE instance, HINSTANCE,
|
||||
PSTR cmdLine, int showCmd)
|
||||
{
|
||||
/*
|
||||
AllocConsole();
|
||||
freopen("CONIN$", "r", stdin);
|
||||
freopen("CONOUT$", "w", stdout);
|
||||
freopen("CONOUT$", "w", stderr);
|
||||
*/
|
||||
|
||||
INT64 ticks;
|
||||
INT64 ticksPerSecond;
|
||||
if(!QueryPerformanceFrequency((LARGE_INTEGER*)&ticksPerSecond))
|
||||
return 0;
|
||||
if(!QueryPerformanceCounter((LARGE_INTEGER*)&ticks))
|
||||
return 0;
|
||||
|
||||
#if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)
|
||||
args.argc = _argc;
|
||||
args.argv = _argv;
|
||||
#else
|
||||
args.argc = __argc;
|
||||
args.argv = __argv;
|
||||
#endif
|
||||
|
||||
if(EventHandler(INITIALIZE, nil) == EVENTERROR)
|
||||
return 0;
|
||||
|
||||
HWND win = MakeWindow(instance,
|
||||
sk::globals.width, sk::globals.height,
|
||||
sk::globals.windowtitle);
|
||||
if(win == 0){
|
||||
MessageBox(0, "MakeWindow() - FAILED", 0, 0);
|
||||
return 0;
|
||||
}
|
||||
engineOpenParams.window = win;
|
||||
initkeymap();
|
||||
|
||||
if(EventHandler(RWINITIALIZE, nil) == EVENTERROR)
|
||||
return 0;
|
||||
|
||||
INT64 lastTicks;
|
||||
QueryPerformanceCounter((LARGE_INTEGER *)&lastTicks);
|
||||
running = true;
|
||||
while((pollEvents(), running) && !globals.quit){
|
||||
QueryPerformanceCounter((LARGE_INTEGER *)&ticks);
|
||||
float timeDelta = (float)(ticks - lastTicks)/ticksPerSecond;
|
||||
|
||||
EventHandler(IDLE, &timeDelta);
|
||||
|
||||
lastTicks = ticks;
|
||||
}
|
||||
|
||||
EventHandler(RWTERMINATE, nil);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace sk {
|
||||
|
||||
void
|
||||
SetMousePosition(int x, int y)
|
||||
{
|
||||
POINT pos = { x, y };
|
||||
ClientToScreen(engineOpenParams.window, &pos);
|
||||
SetCursorPos(pos.x, pos.y);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef RW_OPENGL
|
||||
int main(int argc, char *argv[]);
|
||||
|
||||
int WINAPI
|
||||
WinMain(HINSTANCE instance, HINSTANCE,
|
||||
PSTR cmdLine, int showCmd)
|
||||
{
|
||||
/*
|
||||
AllocConsole();
|
||||
freopen("CONIN$", "r", stdin);
|
||||
freopen("CONOUT$", "w", stdout);
|
||||
freopen("CONOUT$", "w", stderr);
|
||||
*/
|
||||
|
||||
#if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)
|
||||
return main(_argc, _argv);
|
||||
#else
|
||||
return main(__argc, __argv);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue