Convert rlImGui to C
This commit is contained in:
372
engine/libs/rlImGui/.gitignore
vendored
372
engine/libs/rlImGui/.gitignore
vendored
@@ -1,372 +0,0 @@
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
##
|
||||
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||
|
||||
# User-specific files
|
||||
*.rsuser
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Mono auto generated files
|
||||
mono_crash.*
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
[Aa][Rr][Mm]/
|
||||
[Aa][Rr][Mm]64/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
[Ll]ogs/
|
||||
|
||||
# Visual Studio 2015/2017 cache/options directory
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
#wwwroot/
|
||||
|
||||
# Visual Studio 2017 auto generated files
|
||||
Generated\ Files/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
# NUnit
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
nunit-*.xml
|
||||
|
||||
# Build Results of an ATL Project
|
||||
[Dd]ebugPS/
|
||||
[Rr]eleasePS/
|
||||
dlldata.c
|
||||
|
||||
# Benchmark Results
|
||||
BenchmarkDotNet.Artifacts/
|
||||
|
||||
# .NET Core
|
||||
project.lock.json
|
||||
project.fragment.lock.json
|
||||
artifacts/
|
||||
|
||||
# StyleCop
|
||||
StyleCopReport.xml
|
||||
|
||||
# Files built by Visual Studio
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_h.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.iobj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.ipdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*_wpftmp.csproj
|
||||
*.log
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.svclog
|
||||
*.scc
|
||||
|
||||
# Chutzpah Test files
|
||||
_Chutzpah*
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opendb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
*.sap
|
||||
|
||||
# Visual Studio Trace Files
|
||||
*.e2e
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
$tf/
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
*.DotSettings.user
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# AxoCover is a Code Coverage Tool
|
||||
.axoCover/*
|
||||
!.axoCover/settings.json
|
||||
|
||||
# Visual Studio code coverage results
|
||||
*.coverage
|
||||
*.coveragexml
|
||||
|
||||
# NCrunch
|
||||
_NCrunch_*
|
||||
.*crunch*.local.xml
|
||||
nCrunchTemp_*
|
||||
|
||||
# MightyMoose
|
||||
*.mm.*
|
||||
AutoTest.Net/
|
||||
|
||||
# Web workbench (sass)
|
||||
.sass-cache/
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.[Pp]ublish.xml
|
||||
*.azurePubxml
|
||||
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||
# but database connection strings (with potential passwords) will be unencrypted
|
||||
*.pubxml
|
||||
*.publishproj
|
||||
|
||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||
# in these scripts will be unencrypted
|
||||
PublishScripts/
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
# NuGet Symbol Packages
|
||||
*.snupkg
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/[Pp]ackages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
!**/[Pp]ackages/build/
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
#!**/[Pp]ackages/repositories.config
|
||||
# NuGet v3's project.json files produces more ignorable files
|
||||
*.nuget.props
|
||||
*.nuget.targets
|
||||
|
||||
# Microsoft Azure Build Output
|
||||
csx/
|
||||
*.build.csdef
|
||||
|
||||
# Microsoft Azure Emulator
|
||||
ecf/
|
||||
rcf/
|
||||
|
||||
# Windows Store app package directories and files
|
||||
AppPackages/
|
||||
BundleArtifacts/
|
||||
Package.StoreAssociation.xml
|
||||
_pkginfo.txt
|
||||
*.appx
|
||||
*.appxbundle
|
||||
*.appxupload
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
*.[Cc]ache
|
||||
# but keep track of directories ending in .cache
|
||||
!?*.[Cc]ache/
|
||||
|
||||
# Others
|
||||
ClientBin/
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.jfm
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
orleans.codegen.cs
|
||||
|
||||
# Including strong name files can present a security risk
|
||||
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||
#*.snk
|
||||
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||
#bower_components/
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
ServiceFabricBackup/
|
||||
*.rptproj.bak
|
||||
|
||||
# SQL Server files
|
||||
*.mdf
|
||||
*.ldf
|
||||
*.ndf
|
||||
|
||||
# Business Intelligence projects
|
||||
*.rdl.data
|
||||
*.bim.layout
|
||||
*.bim_*.settings
|
||||
*.rptproj.rsuser
|
||||
*- [Bb]ackup.rdl
|
||||
*- [Bb]ackup ([0-9]).rdl
|
||||
*- [Bb]ackup ([0-9][0-9]).rdl
|
||||
|
||||
# Microsoft Fakes
|
||||
FakesAssemblies/
|
||||
|
||||
# GhostDoc plugin setting file
|
||||
*.GhostDoc.xml
|
||||
|
||||
# Node.js Tools for Visual Studio
|
||||
.ntvs_analysis.dat
|
||||
node_modules/
|
||||
|
||||
# Visual Studio 6 build log
|
||||
*.plg
|
||||
|
||||
# Visual Studio 6 workspace options file
|
||||
*.opt
|
||||
|
||||
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||
*.vbw
|
||||
|
||||
# Visual Studio LightSwitch build output
|
||||
**/*.HTMLClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/ModelManifest.xml
|
||||
**/*.Server/GeneratedArtifacts
|
||||
**/*.Server/ModelManifest.xml
|
||||
_Pvt_Extensions
|
||||
|
||||
# Paket dependency manager
|
||||
.paket/paket.exe
|
||||
paket-files/
|
||||
|
||||
# FAKE - F# Make
|
||||
.fake/
|
||||
|
||||
# CodeRush personal settings
|
||||
.cr/personal
|
||||
|
||||
# Python Tools for Visual Studio (PTVS)
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
# Cake - Uncomment if you are using it
|
||||
# tools/**
|
||||
# !tools/packages.config
|
||||
|
||||
# Tabs Studio
|
||||
*.tss
|
||||
|
||||
# Telerik's JustMock configuration file
|
||||
*.jmconfig
|
||||
|
||||
# BizTalk build output
|
||||
*.btp.cs
|
||||
*.btm.cs
|
||||
*.odx.cs
|
||||
*.xsd.cs
|
||||
|
||||
# OpenCover UI analysis results
|
||||
OpenCover/
|
||||
|
||||
# Azure Stream Analytics local run output
|
||||
ASALocalRun/
|
||||
|
||||
# MSBuild Binary and Structured Log
|
||||
*.binlog
|
||||
|
||||
# NVidia Nsight GPU debugger configuration file
|
||||
*.nvuser
|
||||
|
||||
# MFractors (Xamarin productivity tool) working folder
|
||||
.mfractor/
|
||||
|
||||
# Local History for Visual Studio
|
||||
.localhistory/
|
||||
|
||||
# BeatPulse healthcheck temp database
|
||||
healthchecksdb
|
||||
|
||||
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
||||
MigrationBackup/
|
||||
|
||||
# Ionide (cross platform F# VS Code tools) working folder
|
||||
.ionide/
|
||||
/build/ImGuiSample.vcxproj
|
||||
/build/ImGuiSample.vcxproj.filters
|
||||
/build/editor.vcxproj
|
||||
/build/editor.vcxproj.filters
|
||||
/build/imgui.ini
|
||||
/build/raylib.vcxproj
|
||||
/build/raylib.vcxproj.filters
|
||||
/build/rlImGui.vcxproj
|
||||
/build/rlImGui.vcxproj.filters
|
||||
/build/simple.vcxproj
|
||||
/build/simple.vcxproj.filters
|
||||
/examples/editor.vcxproj
|
||||
/examples/editor.vcxproj.filters
|
||||
/examples/simple.vcxproj
|
||||
/examples/simple.vcxproj.filters
|
||||
/premake5.exe
|
||||
/rlImGui.sln
|
||||
*.ini
|
||||
raylib-master
|
||||
_build
|
||||
Catalog
|
||||
imgui-master
|
||||
@@ -1,9 +1,9 @@
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
project(rlImGui)
|
||||
|
||||
set (CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
|
||||
add_library(rlImGui STATIC rlImGui.cpp)
|
||||
add_library(rlImGui STATIC rlImGui.c)
|
||||
|
||||
set(rlImGuiHeaders
|
||||
imgui_impl_raylib.h
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
Copyright (c) 2020-2021 Jeffery Myers
|
||||
|
||||
This software is provided "as-is", without any express or implied warranty. In no event
|
||||
will the authors be held liable for any damages arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose, including commercial
|
||||
applications, and to alter it and redistribute it freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you
|
||||
wrote the original software. If you use this software in a product, an acknowledgment
|
||||
in the product documentation would be appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented
|
||||
as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
@@ -1,75 +0,0 @@
|
||||
# rlImGui
|
||||
<img align="left" src="https://github.com/raysan5/raylib/raw/master/logo/raylib_logo_animation.gif" width="64">
|
||||
A Raylib integration with DearImGui
|
||||
|
||||
rlImgui provides a backend for [Dear ImGui](https://github.com/ocornut/imgui) using [Raylib](https://www.raylib.com/).
|
||||
|
||||
# Building
|
||||
rlImGui is setup to use premake to generate a static library and examples for Visual Studio 2019. Premake can also be used to generate makefiles for linux. rlImGui can be used as a static library, or by direclty including the files into your game project.
|
||||
|
||||
If you wish to use premake, you will need to download the Premake5 executable for your platform from. https://premake.github.io/download
|
||||
|
||||
# Setup
|
||||
|
||||
Using rlImGui in your code is very easy. Once you have included the library, or source files for rlImGui and ImGui in your project, simply do the following.
|
||||
```
|
||||
#include "rlImGui.h" // include the API header
|
||||
|
||||
// before your game loop
|
||||
rlImGuiSetup(true); // sets up ImGui with ether a dark or light default theme
|
||||
|
||||
// inside your game loop, between BeginDrawing() and EndDrawing()
|
||||
rlImGuiBegin(); // starts the ImGui content mode. Make all ImGui calls after this
|
||||
|
||||
rlImGuiEnd(); // ends the ImGui content mode. Make all ImGui calls before this
|
||||
|
||||
// after your game loop is over, before you close the window
|
||||
|
||||
rlImGuiShutdown(); // cleans up ImGui
|
||||
```
|
||||
|
||||
# Examples
|
||||
There are two example programs in the examples folder.
|
||||
|
||||
## Simple
|
||||
This is the most simple use of ImGui in raylib, it just shows the ImGui demo window.
|
||||

|
||||
|
||||
|
||||
## Editor
|
||||
This is a more complex example of ImGui, showing how to use raylib 2d and 3d cameras to draw into ImGui windows using render textures.
|
||||

|
||||
|
||||
# Extras
|
||||
|
||||
## rlImGuiColors.h
|
||||
This file has a converter to change Raylib colors into ImGui Colors
|
||||
|
||||
## Font Awesome Icons
|
||||
Support for Font Awesome 6 https://fontawesome.com/ is built into rlImGui and enabled by default. You can simply
|
||||
#include "extras/IconsFontAwesome6.h"
|
||||
To use the ICON_FA macros for any icon in the free set.
|
||||
|
||||
If you wish to disable font awesome support you can #define NO_FONT_AWESOME
|
||||
|
||||
|
||||
# Images
|
||||
Raylib textures can be drawn in ImGui using the following functions
|
||||
```
|
||||
void rlImGuiImage(const Texture *image);
|
||||
void rlImGuiImageSize(const Texture *image, int width, int height);
|
||||
void rlImGuiImageSizeV(const Texture* image, Vector2 size);
|
||||
void rlImGuiImageRect(const Texture* image, int destWidth, int destHeight, Rectangle sourceRect);
|
||||
void rlImGuiImageRenderTexture(const RenderTexture* image);
|
||||
void rlImGuiImageRenderTextureFit(const RenderTexture* image, bool center);
|
||||
|
||||
bool rlImGuiImageButton(const Texture *image);
|
||||
bool rlImGuiImageButtonSize(const char* name, const Texture* image, struct ImVec2 size);
|
||||
```
|
||||
|
||||
# C vs C++
|
||||
ImGui is a C++ library, so rlImGui uses C++ to create the backend and integration with Raylib.
|
||||
The rlImGui.h API only uses features that are common to C and C++, so rlImGui can be built as a static library and used by pure C code. Users of ImGui who wish to use pure C must use an ImGui wrapper, such as [https://github.com/cimgui/cimgui].
|
||||
|
||||
# Low level API
|
||||
If you would like more controll over the ImGui Backend, you can use the low level API that is found in imgui_impl_raylib.h. This is API follows the patterns of other ImGui backends and does not do automatic context management. An example of it's use can be found in imgui_style_example.cpp
|
||||
@@ -1,392 +0,0 @@
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib-extras [ImGui] example - editor
|
||||
*
|
||||
* This is a more complex ImGui Integration
|
||||
* It shows how to build windows on top of 2d and 3d views using a render texture
|
||||
*
|
||||
* Copyright (c) 2021 Jeffery Myers
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
#include "raylib.h"
|
||||
#include "raymath.h"
|
||||
|
||||
#include "imgui.h"
|
||||
#include "rlImGui.h"
|
||||
#include "rlImGuiColors.h"
|
||||
|
||||
bool Quit = false;
|
||||
|
||||
bool ImGuiDemoOpen = false;
|
||||
|
||||
class DocumentWindow
|
||||
{
|
||||
public:
|
||||
bool Open = false;
|
||||
|
||||
RenderTexture ViewTexture;
|
||||
|
||||
virtual void Setup() = 0;
|
||||
virtual void Shutdown() = 0;
|
||||
virtual void Show() = 0;
|
||||
virtual void Update() = 0;
|
||||
|
||||
bool Focused = false;
|
||||
|
||||
Rectangle ContentRect = { 0 };
|
||||
};
|
||||
|
||||
class ImageViewerWindow : public DocumentWindow
|
||||
{
|
||||
public:
|
||||
|
||||
void Setup() override
|
||||
{
|
||||
Camera.zoom = 1;
|
||||
Camera.target.x = 0;
|
||||
Camera.target.y = 0;
|
||||
Camera.rotation = 0;
|
||||
Camera.offset.x = GetScreenWidth() / 2.0f;
|
||||
Camera.offset.y = GetScreenHeight() / 2.0f;
|
||||
|
||||
ViewTexture = LoadRenderTexture(GetScreenWidth(), GetScreenHeight());
|
||||
ImageTexture = LoadTexture("resources/parrots.png");
|
||||
|
||||
UpdateRenderTexture();
|
||||
}
|
||||
|
||||
void Show() override
|
||||
{
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
|
||||
ImGui::SetNextWindowSizeConstraints(ImVec2(400, 400), ImVec2((float)GetScreenWidth(), (float)GetScreenHeight()));
|
||||
|
||||
Focused = false;
|
||||
|
||||
if (ImGui::Begin("Image Viewer", &Open, ImGuiWindowFlags_NoScrollbar))
|
||||
{
|
||||
// save off the screen space content rectangle
|
||||
ContentRect = { ImGui::GetWindowPos().x + ImGui::GetWindowContentRegionMin().x, ImGui::GetWindowPos().y + ImGui::GetWindowContentRegionMin().y, ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y };
|
||||
|
||||
Focused = ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows);
|
||||
|
||||
ImVec2 size = ImGui::GetContentRegionAvail();
|
||||
|
||||
// center the scratch pad in the view
|
||||
Rectangle viewRect = { 0 };
|
||||
viewRect.x = ViewTexture.texture.width / 2 - size.x / 2;
|
||||
viewRect.y = ViewTexture.texture.height / 2 - size.y / 2;
|
||||
viewRect.width = size.x;
|
||||
viewRect.height = -size.y;
|
||||
|
||||
if (ImGui::BeginChild("Toolbar", ImVec2(ImGui::GetContentRegionAvail().x, 25)))
|
||||
{
|
||||
ImGui::SetCursorPosX(2);
|
||||
ImGui::SetCursorPosY(3);
|
||||
|
||||
if (ImGui::Button("None"))
|
||||
{
|
||||
CurrentToolMode = ToolMode::None;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
|
||||
if (ImGui::Button("Move"))
|
||||
{
|
||||
CurrentToolMode = ToolMode::Move;
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
switch (CurrentToolMode)
|
||||
{
|
||||
case ToolMode::None:
|
||||
ImGui::TextUnformatted("No Tool");
|
||||
break;
|
||||
case ToolMode::Move:
|
||||
ImGui::TextUnformatted("Move Tool");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::TextUnformatted(TextFormat("camera target X%f Y%f", Camera.target.x, Camera.target.y));
|
||||
ImGui::EndChild();
|
||||
}
|
||||
|
||||
rlImGuiImageRect(&ViewTexture.texture, (int)size.x, (int)size.y, viewRect);
|
||||
}
|
||||
ImGui::End();
|
||||
ImGui::PopStyleVar();
|
||||
}
|
||||
|
||||
void Update() override
|
||||
{
|
||||
if (!Open)
|
||||
return;
|
||||
|
||||
if (IsWindowResized())
|
||||
{
|
||||
UnloadRenderTexture(ViewTexture);
|
||||
ViewTexture = LoadRenderTexture(GetScreenWidth(), GetScreenHeight());
|
||||
|
||||
Camera.offset.x = GetScreenWidth() / 2.0f;
|
||||
Camera.offset.y = GetScreenHeight() / 2.0f;
|
||||
}
|
||||
|
||||
Vector2 mousePos = GetMousePosition();
|
||||
|
||||
if (Focused)
|
||||
{
|
||||
if (CurrentToolMode == ToolMode::Move)
|
||||
{
|
||||
// only do this tool when the mouse is in the content area of the window
|
||||
if (IsMouseButtonDown(0) && CheckCollisionPointRec(mousePos, ContentRect))
|
||||
{
|
||||
if (!Dragging)
|
||||
{
|
||||
LastMousePos = mousePos;
|
||||
LastTarget = Camera.target;
|
||||
}
|
||||
Dragging = true;
|
||||
Vector2 mouseDelta = Vector2Subtract(LastMousePos, mousePos);
|
||||
|
||||
mouseDelta.x /= Camera.zoom;
|
||||
mouseDelta.y /= Camera.zoom;
|
||||
Camera.target = Vector2Add(LastTarget, mouseDelta);
|
||||
|
||||
DirtyScene = true;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Dragging = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Dragging = false;
|
||||
}
|
||||
|
||||
if (DirtyScene)
|
||||
{
|
||||
DirtyScene = false;
|
||||
UpdateRenderTexture();
|
||||
}
|
||||
}
|
||||
|
||||
Texture ImageTexture;
|
||||
Camera2D Camera = { 0 };
|
||||
|
||||
Vector2 LastMousePos = { 0 };
|
||||
Vector2 LastTarget = { 0 };
|
||||
bool Dragging = false;
|
||||
|
||||
bool DirtyScene = false;
|
||||
|
||||
enum class ToolMode
|
||||
{
|
||||
None,
|
||||
Move,
|
||||
};
|
||||
|
||||
ToolMode CurrentToolMode = ToolMode::None;
|
||||
|
||||
void UpdateRenderTexture()
|
||||
{
|
||||
BeginTextureMode(ViewTexture);
|
||||
ClearBackground(BLUE);
|
||||
|
||||
// camera with our view offset with a world origin of 0,0
|
||||
BeginMode2D(Camera);
|
||||
|
||||
// center the image at 0,0
|
||||
DrawTexture(ImageTexture, ImageTexture.width / -2, ImageTexture.height / -2, WHITE);
|
||||
|
||||
EndMode2D();
|
||||
EndTextureMode();
|
||||
}
|
||||
|
||||
void Shutdown() override
|
||||
{
|
||||
UnloadRenderTexture(ViewTexture);
|
||||
UnloadTexture(ImageTexture);
|
||||
}
|
||||
};
|
||||
|
||||
class SceneViewWindow : public DocumentWindow
|
||||
{
|
||||
public:
|
||||
Camera3D Camera = { 0 };
|
||||
|
||||
void Setup() override
|
||||
{
|
||||
ViewTexture = LoadRenderTexture(GetScreenWidth(), GetScreenHeight());
|
||||
|
||||
Camera.fovy = 45;
|
||||
Camera.up.y = 1;
|
||||
Camera.position.y = 3;
|
||||
Camera.position.z = -25;
|
||||
|
||||
Image img = GenImageChecked(256, 256, 32, 32, DARKGRAY, WHITE);
|
||||
GridTexture = LoadTextureFromImage(img);
|
||||
UnloadImage(img);
|
||||
GenTextureMipmaps(&GridTexture);
|
||||
SetTextureFilter(GridTexture, TEXTURE_FILTER_ANISOTROPIC_16X);
|
||||
SetTextureWrap(GridTexture, TEXTURE_WRAP_CLAMP);
|
||||
}
|
||||
|
||||
void Shutdown() override
|
||||
{
|
||||
UnloadRenderTexture(ViewTexture);
|
||||
UnloadTexture(GridTexture);
|
||||
}
|
||||
|
||||
void Show() override
|
||||
{
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
|
||||
ImGui::SetNextWindowSizeConstraints(ImVec2(400, 400), ImVec2((float)GetScreenWidth(), (float)GetScreenHeight()));
|
||||
|
||||
if (ImGui::Begin("3D View", &Open, ImGuiWindowFlags_NoScrollbar))
|
||||
{
|
||||
Focused = ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows);
|
||||
// draw the view
|
||||
rlImGuiImageRenderTextureFit(&ViewTexture, true);
|
||||
}
|
||||
ImGui::End();
|
||||
ImGui::PopStyleVar();
|
||||
}
|
||||
|
||||
void Update() override
|
||||
{
|
||||
if (!Open)
|
||||
return;
|
||||
|
||||
if (IsWindowResized())
|
||||
{
|
||||
UnloadRenderTexture(ViewTexture);
|
||||
ViewTexture = LoadRenderTexture(GetScreenWidth(), GetScreenHeight());
|
||||
}
|
||||
|
||||
float period = 10;
|
||||
float magnitude = 25;
|
||||
|
||||
Camera.position.x = (float)(sinf((float)GetTime() / period) * magnitude);
|
||||
|
||||
BeginTextureMode(ViewTexture);
|
||||
ClearBackground(SKYBLUE);
|
||||
|
||||
BeginMode3D(Camera);
|
||||
|
||||
// grid of cube trees on a plane to make a "world"
|
||||
DrawPlane(Vector3{ 0, 0, 0 }, Vector2{ 50, 50 }, BEIGE); // simple world plane
|
||||
float spacing = 4;
|
||||
int count = 5;
|
||||
|
||||
for (float x = -count * spacing; x <= count * spacing; x += spacing)
|
||||
{
|
||||
for (float z = -count * spacing; z <= count * spacing; z += spacing)
|
||||
{
|
||||
Vector3 pos = { x, 0.5f, z };
|
||||
|
||||
Vector3 min = { x - 0.5f,0,z - 0.5f };
|
||||
Vector3 max = { x + 0.5f,1,z + 0.5f };
|
||||
|
||||
DrawCube(Vector3{ x, 1.5f, z }, 1, 1, 1, GREEN);
|
||||
DrawCube(Vector3{ x, 0.5f, z }, 0.25f, 1, 0.25f, BROWN);
|
||||
}
|
||||
}
|
||||
|
||||
EndMode3D();
|
||||
EndTextureMode();
|
||||
}
|
||||
|
||||
Texture2D GridTexture = { 0 };
|
||||
};
|
||||
|
||||
|
||||
ImageViewerWindow ImageViewer;
|
||||
SceneViewWindow SceneView;
|
||||
|
||||
void DoMainMenu()
|
||||
{
|
||||
if (ImGui::BeginMainMenuBar())
|
||||
{
|
||||
if (ImGui::BeginMenu("File"))
|
||||
{
|
||||
if (ImGui::MenuItem("Exit"))
|
||||
Quit = true;
|
||||
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
if (ImGui::BeginMenu("Window"))
|
||||
{
|
||||
ImGui::MenuItem("ImGui Demo", nullptr, &ImGuiDemoOpen);
|
||||
ImGui::MenuItem("Image Viewer", nullptr, &ImageViewer.Open);
|
||||
ImGui::MenuItem("3D View", nullptr, &SceneView.Open);
|
||||
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
ImGui::EndMainMenuBar();
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 1900;
|
||||
int screenHeight = 900;
|
||||
|
||||
SetConfigFlags(FLAG_MSAA_4X_HINT | FLAG_VSYNC_HINT);
|
||||
InitWindow(screenWidth, screenHeight, "raylib-Extras [ImGui] example - ImGui Demo");
|
||||
SetTargetFPS(144);
|
||||
rlImGuiSetup(true);
|
||||
ImGui::GetIO().ConfigWindowsMoveFromTitleBarOnly = true;
|
||||
|
||||
ImageViewer.Setup();
|
||||
ImageViewer.Open = true;
|
||||
|
||||
SceneView.Setup();
|
||||
SceneView.Open = true;
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose() && !Quit) // Detect window close button or ESC key
|
||||
{
|
||||
ImageViewer.Update();
|
||||
SceneView.Update();
|
||||
|
||||
BeginDrawing();
|
||||
ClearBackground(DARKGRAY);
|
||||
|
||||
rlImGuiBegin();
|
||||
DoMainMenu();
|
||||
|
||||
if (ImGuiDemoOpen)
|
||||
ImGui::ShowDemoWindow(&ImGuiDemoOpen);
|
||||
|
||||
if (ImageViewer.Open)
|
||||
ImageViewer.Show();
|
||||
|
||||
if (SceneView.Open)
|
||||
SceneView.Show();
|
||||
|
||||
rlImGuiEnd();
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
rlImGuiShutdown();
|
||||
|
||||
ImageViewer.Shutdown();
|
||||
SceneView.Shutdown();
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,124 +0,0 @@
|
||||
// Dear ImGui: standalone example application for Raylib with OpenGL
|
||||
// (Raylib is a simple learning library for game development)
|
||||
|
||||
// Learn about Dear ImGui:
|
||||
// - FAQ https://dearimgui.com/faq
|
||||
// - Getting Started https://dearimgui.com/getting-started
|
||||
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
|
||||
// - Introduction, links and more at the top of imgui.cpp
|
||||
|
||||
#include "imgui.h"
|
||||
#include "imgui_impl_raylib.h"
|
||||
#include "raylib.h"
|
||||
|
||||
// Main code
|
||||
int main(int, char**)
|
||||
{
|
||||
// Setup raylib window
|
||||
SetConfigFlags(FLAG_WINDOW_RESIZABLE | FLAG_WINDOW_HIGHDPI);
|
||||
InitWindow(1280, 720, "Dear ImGui Raylib(OpenGL) example");
|
||||
|
||||
// Setup Dear ImGui context
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
|
||||
|
||||
// Setup Dear ImGui style
|
||||
ImGui::StyleColorsDark();
|
||||
//ImGui::StyleColorsLight();
|
||||
|
||||
// Setup Platform/Renderer backends
|
||||
ImGui_ImplRaylib_Init();
|
||||
|
||||
// Load Fonts
|
||||
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
||||
// - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
|
||||
// - If the file cannot be loaded, the function will return a nullptr. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
|
||||
// - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call.
|
||||
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering.
|
||||
// - Read 'docs/FONTS.md' for more instructions and details.
|
||||
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
||||
//io.Fonts->AddFontDefault();
|
||||
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf", 18.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f);
|
||||
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, nullptr, io.Fonts->GetGlyphRangesJapanese());
|
||||
//IM_ASSERT(font != nullptr);
|
||||
|
||||
// Our state
|
||||
bool show_demo_window = true;
|
||||
bool show_another_window = false;
|
||||
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
|
||||
|
||||
// Main loop
|
||||
bool done = false;
|
||||
while (!done)
|
||||
{
|
||||
// Poll and handle events (inputs, window resize, etc.)
|
||||
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
||||
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
|
||||
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
|
||||
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
||||
ImGui_ImplRaylib_ProcessEvents();
|
||||
|
||||
// Start the Dear ImGui frame
|
||||
ImGui_ImplRaylib_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
|
||||
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
||||
if (show_demo_window)
|
||||
ImGui::ShowDemoWindow(&show_demo_window);
|
||||
|
||||
// 2. Show a simple window that we create ourselves. We use a Begin/End pair to create a named window.
|
||||
{
|
||||
static float f = 0.0f;
|
||||
static int counter = 0;
|
||||
|
||||
ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it.
|
||||
|
||||
ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too)
|
||||
ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state
|
||||
ImGui::Checkbox("Another Window", &show_another_window);
|
||||
|
||||
ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
|
||||
ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color
|
||||
|
||||
if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated)
|
||||
counter++;
|
||||
ImGui::SameLine();
|
||||
ImGui::Text("counter = %d", counter);
|
||||
|
||||
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
// 3. Show another simple window.
|
||||
if (show_another_window)
|
||||
{
|
||||
ImGui::Begin("Another Window", &show_another_window); // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked)
|
||||
ImGui::Text("Hello from another window!");
|
||||
if (ImGui::Button("Close Me"))
|
||||
show_another_window = false;
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
|
||||
// Rendering
|
||||
ImGui::Render();
|
||||
BeginDrawing();
|
||||
ClearBackground(Color{ (unsigned char)(clear_color.x * 255), (unsigned char)(clear_color.y * 255),(unsigned char)(clear_color.z * 255),(unsigned char)(clear_color.w * 255) });
|
||||
ImGui_ImplRaylib_RenderDrawData(ImGui::GetDrawData());
|
||||
EndDrawing();
|
||||
|
||||
done = WindowShouldClose();
|
||||
}
|
||||
// Cleanup
|
||||
ImGui_ImplRaylib_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
|
||||
CloseWindow();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib-extras [ImGui] example - Simple Integration
|
||||
*
|
||||
* This is a simple ImGui Integration
|
||||
* It is done using C++ but with C style code
|
||||
* It can be done in C as well if you use the C ImGui wrapper
|
||||
* https://github.com/cimgui/cimgui
|
||||
*
|
||||
* Copyright (c) 2021 Jeffery Myers
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
#include "raylib.h"
|
||||
#include "raymath.h"
|
||||
|
||||
#include "imgui.h"
|
||||
#include "rlImGui.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 1280;
|
||||
int screenHeight = 800;
|
||||
|
||||
SetConfigFlags(FLAG_MSAA_4X_HINT | FLAG_VSYNC_HINT);
|
||||
InitWindow(screenWidth, screenHeight, "raylib-Extras [ImGui] example - simple ImGui Demo");
|
||||
SetTargetFPS(144);
|
||||
rlImGuiSetup(true);
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
BeginDrawing();
|
||||
ClearBackground(DARKGRAY);
|
||||
|
||||
// start ImGui Conent
|
||||
rlImGuiBegin();
|
||||
|
||||
// show ImGui Content
|
||||
bool open = true;
|
||||
ImGui::ShowDemoWindow(&open);
|
||||
|
||||
// end ImGui Content
|
||||
rlImGuiEnd();
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
rlImGuiShutdown();
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,34 +0,0 @@
|
||||
Font Awesome Free License
|
||||
-------------------------
|
||||
|
||||
Font Awesome Free is free, open source, and GPL friendly. You can use it for
|
||||
commercial projects, open source projects, or really almost whatever you want.
|
||||
Full Font Awesome Free license: https://fontawesome.com/license/free.
|
||||
|
||||
# Icons: CC BY 4.0 License (https://creativecommons.org/licenses/by/4.0/)
|
||||
In the Font Awesome Free download, the CC BY 4.0 license applies to all icons
|
||||
packaged as SVG and JS file types.
|
||||
|
||||
# Fonts: SIL OFL 1.1 License (https://scripts.sil.org/OFL)
|
||||
In the Font Awesome Free download, the SIL OFL license applies to all icons
|
||||
packaged as web and desktop font files.
|
||||
|
||||
# Code: MIT License (https://opensource.org/licenses/MIT)
|
||||
In the Font Awesome Free download, the MIT license applies to all non-font and
|
||||
non-icon files.
|
||||
|
||||
# Attribution
|
||||
Attribution is required by MIT, SIL OFL, and CC BY licenses. Downloaded Font
|
||||
Awesome Free files already contain embedded comments with sufficient
|
||||
attribution, so you shouldn't need to do anything additional when using these
|
||||
files normally.
|
||||
|
||||
We've kept attribution comments terse, so we ask that you do not actively work
|
||||
to remove them from files, especially code. They're a great way for folks to
|
||||
learn about Font Awesome.
|
||||
|
||||
# Brand Icons
|
||||
All brand icons are trademarks of their respective owners. The use of these
|
||||
trademarks does not indicate endorsement of the trademark holder by Font
|
||||
Awesome, nor vice versa. **Please do not use brand logos for any purpose except
|
||||
to represent the company, product, or service to which they refer.**
|
||||
|
||||
@@ -41,13 +41,14 @@
|
||||
// - Introduction, links and more at the top of imgui.cpp
|
||||
|
||||
#pragma once
|
||||
#include "imgui.h" // IMGUI_IMPL_API
|
||||
#define CIMGUI_DEFINE_ENUMS_AND_STRUCTS
|
||||
#include "cimgui.h" // IMGUI_IMPL_API
|
||||
#ifndef IMGUI_DISABLE
|
||||
|
||||
IMGUI_IMPL_API bool ImGui_ImplRaylib_Init();
|
||||
IMGUI_IMPL_API void ImGui_ImplRaylib_Shutdown();
|
||||
IMGUI_IMPL_API void ImGui_ImplRaylib_NewFrame();
|
||||
IMGUI_IMPL_API void ImGui_ImplRaylib_RenderDrawData(ImDrawData* draw_data);
|
||||
IMGUI_IMPL_API bool ImGui_ImplRaylib_ProcessEvents();
|
||||
bool ImGui_ImplRaylib_Init();
|
||||
void ImGui_ImplRaylib_Shutdown();
|
||||
void ImGui_ImplRaylib_NewFrame();
|
||||
void ImGui_ImplRaylib_RenderDrawData(ImDrawData* draw_data);
|
||||
bool ImGui_ImplRaylib_ProcessEvents();
|
||||
|
||||
#endif // #ifndef IMGUI_DISABLE
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
premake5.exe vs2022
|
||||
pause
|
||||
@@ -1,2 +0,0 @@
|
||||
premake5.exe gmake2
|
||||
pause
|
||||
Binary file not shown.
@@ -1,173 +0,0 @@
|
||||
newoption
|
||||
{
|
||||
trigger = "graphics",
|
||||
value = "OPENGL_VERSION",
|
||||
description = "version of OpenGL to build raylib against",
|
||||
allowed = {
|
||||
{ "opengl11", "OpenGL 1.1"},
|
||||
{ "opengl21", "OpenGL 2.1"},
|
||||
{ "opengl33", "OpenGL 3.3"},
|
||||
{ "opengl43", "OpenGL 4.3"}
|
||||
},
|
||||
default = "opengl33"
|
||||
}
|
||||
|
||||
function define_C()
|
||||
language "C"
|
||||
end
|
||||
|
||||
function define_Cpp()
|
||||
language "C++"
|
||||
end
|
||||
|
||||
function string.starts(String,Start)
|
||||
return string.sub(String,1,string.len(Start))==Start
|
||||
end
|
||||
|
||||
function link_to(lib)
|
||||
links (lib)
|
||||
includedirs ("../"..lib.."/include", "../"..lib.."/" )
|
||||
end
|
||||
|
||||
function download_progress(total, current)
|
||||
local ratio = current / total;
|
||||
ratio = math.min(math.max(ratio, 0), 1);
|
||||
local percent = math.floor(ratio * 100);
|
||||
print("Download progress (" .. percent .. "%/100%)")
|
||||
end
|
||||
|
||||
function check_raylib()
|
||||
if(os.isdir("raylib") == false and os.isdir("raylib-master") == false) then
|
||||
if(not os.isfile("raylib-master.zip")) then
|
||||
print("Raylib not found, downloading from github")
|
||||
local result_str, response_code = http.download("https://github.com/raysan5/raylib/archive/refs/heads/master.zip", "raylib-master.zip", {
|
||||
progress = download_progress,
|
||||
headers = { "From: Premake", "Referer: Premake" }
|
||||
})
|
||||
end
|
||||
print("Unzipping to " .. os.getcwd())
|
||||
zip.extract("raylib-master.zip", os.getcwd())
|
||||
os.remove("raylib-master.zip")
|
||||
end
|
||||
end
|
||||
|
||||
function check_imgui()
|
||||
if(os.isdir("imgui") == false and os.isdir("imgui-master") == false) then
|
||||
if(not os.isfile("imgui-master.zip")) then
|
||||
print("imgui not found, downloading from github")
|
||||
local result_str, response_code = http.download("https://github.com/ocornut/imgui/archive/refs/heads/master.zip", "imgui-master.zip", {
|
||||
progress = download_progress,
|
||||
headers = { "From: Premake", "Referer: Premake" }
|
||||
})
|
||||
end
|
||||
print("Unzipping to " .. os.getcwd())
|
||||
zip.extract("imgui-master.zip", os.getcwd())
|
||||
os.remove("imgui-master.zip")
|
||||
end
|
||||
end
|
||||
|
||||
workspace "rlImGui"
|
||||
configurations { "Debug", "Release" }
|
||||
platforms { "x64"}
|
||||
defaultplatform "x64"
|
||||
|
||||
filter "configurations:Debug"
|
||||
defines { "DEBUG" }
|
||||
symbols "On"
|
||||
|
||||
filter "configurations:Release"
|
||||
defines { "NDEBUG" }
|
||||
optimize "On"
|
||||
|
||||
filter { "platforms:x64" }
|
||||
architecture "x86_64"
|
||||
|
||||
targetdir "bin/%{cfg.buildcfg}/"
|
||||
|
||||
|
||||
cdialect "C99"
|
||||
cppdialect "C++11"
|
||||
check_raylib()
|
||||
check_imgui()
|
||||
|
||||
include ("raylib_premake5.lua")
|
||||
|
||||
project "rlImGui"
|
||||
kind "StaticLib"
|
||||
location "_build"
|
||||
targetdir "_bin/%{cfg.buildcfg}"
|
||||
language "C++"
|
||||
|
||||
include_raylib()
|
||||
includedirs { "rlImGui", "imgui", "imgui-master"}
|
||||
vpaths
|
||||
{
|
||||
["Header Files"] = { "*.h"},
|
||||
["Source Files"] = {"*.cpp"},
|
||||
["ImGui Files"] = { "imgui/*.h","imgui/*.cpp", "imgui-master/*.h","imgui-master/*.cpp" },
|
||||
}
|
||||
files {"imgui-master/*.h", "imgui-master/*.cpp", "imgui/*.h", "imgui/*.cpp", "*.cpp", "*.h", "extras/**.h"}
|
||||
|
||||
defines {"IMGUI_DISABLE_OBSOLETE_FUNCTIONS","IMGUI_DISABLE_OBSOLETE_KEYIO"}
|
||||
|
||||
group "Examples"
|
||||
project "simple"
|
||||
kind "ConsoleApp"
|
||||
language "C++"
|
||||
location "_build"
|
||||
targetdir "_bin/%{cfg.buildcfg}"
|
||||
|
||||
vpaths
|
||||
{
|
||||
["Header Files"] = { "examples/**.h"},
|
||||
["Source Files"] = {"examples/**.cpp", "examples/**.c"},
|
||||
}
|
||||
files {"examples/simple.cpp"}
|
||||
link_raylib()
|
||||
links {"rlImGui"}
|
||||
includedirs {"./", "imgui", "imgui-master" }
|
||||
|
||||
filter "action:vs*"
|
||||
debugdir "$(SolutionDir)"
|
||||
|
||||
|
||||
project "editor"
|
||||
kind "ConsoleApp"
|
||||
language "C++"
|
||||
location "_build"
|
||||
targetdir "_bin/%{cfg.buildcfg}"
|
||||
|
||||
|
||||
vpaths
|
||||
{
|
||||
["Header Files"] = { "examples/**.h"},
|
||||
["Source Files"] = {"examples/**.cpp", "examples/**.c"},
|
||||
}
|
||||
files {"examples/editor.cpp"}
|
||||
link_raylib()
|
||||
links {"rlImGui"}
|
||||
includedirs {"./", "imgui", "imgui-master" }
|
||||
|
||||
filter "action:vs*"
|
||||
debugdir "$(SolutionDir)"
|
||||
|
||||
|
||||
project "imgui_style_example"
|
||||
kind "ConsoleApp"
|
||||
language "C++"
|
||||
location "_build"
|
||||
targetdir "_bin/%{cfg.buildcfg}"
|
||||
|
||||
vpaths
|
||||
{
|
||||
["Header Files"] = { "examples/**.h"},
|
||||
["Source Files"] = {"examples/**.cpp", "examples/**.c"},
|
||||
}
|
||||
files {"examples/imgui_style_example.cpp"}
|
||||
link_raylib()
|
||||
links {"rlImGui"}
|
||||
includedirs {"./", "imgui", "imgui-master" }
|
||||
|
||||
filter "action:vs*"
|
||||
debugdir "$(SolutionDir)"
|
||||
|
||||
Binary file not shown.
@@ -1,114 +0,0 @@
|
||||
|
||||
function platform_defines()
|
||||
defines{"PLATFORM_DESKTOP"}
|
||||
|
||||
filter {"options:graphics=opengl43"}
|
||||
defines{"GRAPHICS_API_OPENGL_43"}
|
||||
|
||||
filter {"options:graphics=opengl33"}
|
||||
defines{"GRAPHICS_API_OPENGL_33"}
|
||||
|
||||
filter {"options:graphics=opengl21"}
|
||||
defines{"GRAPHICS_API_OPENGL_21"}
|
||||
|
||||
filter {"options:graphics=opengl11"}
|
||||
defines{"GRAPHICS_API_OPENGL_11"}
|
||||
|
||||
filter {"system:macosx"}
|
||||
disablewarnings {"deprecated-declarations"}
|
||||
|
||||
filter {"system:linux"}
|
||||
defines {"_GNU_SOURCE"}
|
||||
-- This is necessary, otherwise compilation will fail since
|
||||
-- there is no CLOCK_MONOTOMIC. raylib claims to have a workaround
|
||||
-- to compile under c99 without -D_GNU_SOURCE, but it didn't seem
|
||||
-- to work. raylib's Makefile also adds this flag, probably why it went
|
||||
-- unnoticed for so long.
|
||||
-- It compiles under c11 without -D_GNU_SOURCE, because c11 requires
|
||||
-- to have CLOCK_MONOTOMIC
|
||||
-- See: https://github.com/raysan5/raylib/issues/2729
|
||||
|
||||
filter{}
|
||||
end
|
||||
|
||||
function get_raylib_dir()
|
||||
if (os.isdir("raylib-master")) then
|
||||
return "raylib-master"
|
||||
end
|
||||
if (os.isdir("../raylib-master")) then
|
||||
return "raylib-master"
|
||||
end
|
||||
return "raylib"
|
||||
end
|
||||
|
||||
function link_raylib()
|
||||
links {"raylib"}
|
||||
|
||||
raylib_dir = get_raylib_dir();
|
||||
includedirs {raylib_dir .. "/src" }
|
||||
includedirs {raylib_dir .."/src/external" }
|
||||
includedirs {raylib_dir .."/src/external/glfw/include" }
|
||||
platform_defines()
|
||||
filter "action:vs*"
|
||||
defines{"_WINSOCK_DEPRECATED_NO_WARNINGS", "_CRT_SECURE_NO_WARNINGS"}
|
||||
dependson {"raylib"}
|
||||
links {"raylib.lib"}
|
||||
characterset ("MBCS")
|
||||
|
||||
filter "system:windows"
|
||||
defines{"_WIN32"}
|
||||
links {"winmm", "kernel32", "opengl32", "gdi32"}
|
||||
libdirs {"_bin/%{cfg.buildcfg}"}
|
||||
|
||||
filter "system:linux"
|
||||
links {"pthread", "GL", "m", "dl", "rt", "X11"}
|
||||
|
||||
filter "system:macosx"
|
||||
links {"OpenGL.framework", "Cocoa.framework", "IOKit.framework", "CoreFoundation.framework", "CoreAudio.framework", "CoreVideo.framework"}
|
||||
|
||||
filter{}
|
||||
end
|
||||
|
||||
function include_raylib()
|
||||
raylib_dir = get_raylib_dir();
|
||||
includedirs {raylib_dir .."/src" }
|
||||
includedirs {raylib_dir .."/src/external" }
|
||||
includedirs {raylib_dir .."/src/external/glfw/include" }
|
||||
platform_defines()
|
||||
|
||||
filter "action:vs*"
|
||||
defines{"_WINSOCK_DEPRECATED_NO_WARNINGS", "_CRT_SECURE_NO_WARNINGS"}
|
||||
|
||||
filter{}
|
||||
end
|
||||
|
||||
project "raylib"
|
||||
kind "StaticLib"
|
||||
|
||||
platform_defines()
|
||||
|
||||
location "_build"
|
||||
language "C"
|
||||
targetdir "_bin/%{cfg.buildcfg}"
|
||||
|
||||
filter "action:vs*"
|
||||
defines{"_WINSOCK_DEPRECATED_NO_WARNINGS", "_CRT_SECURE_NO_WARNINGS"}
|
||||
characterset ("MBCS")
|
||||
|
||||
filter{}
|
||||
|
||||
raylib_dir = get_raylib_dir();
|
||||
print ("Using raylib dir " .. raylib_dir);
|
||||
includedirs {raylib_dir .. "/src", raylib_dir .. "/src/external/glfw/include" }
|
||||
vpaths
|
||||
{
|
||||
["Header Files"] = { raylib_dir .. "/src/**.h"},
|
||||
["Source Files/*"] = { raylib_dir .. "/src/**.c"},
|
||||
}
|
||||
files {raylib_dir .. "/src/*.h", raylib_dir .. "/src/*.c"}
|
||||
removefiles {raylib_dir .. "/src/rcore_*.c"}
|
||||
|
||||
filter { "system:macosx", "files:" .. raylib_dir .. "/src/rglfw.c" }
|
||||
compileas "Objective-C"
|
||||
|
||||
filter{}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 288 KiB |
699
engine/libs/rlImGui/rlImGui.c
Normal file
699
engine/libs/rlImGui/rlImGui.c
Normal file
@@ -0,0 +1,699 @@
|
||||
/**********************************************************************************************
|
||||
*
|
||||
* raylibExtras * Utilities and Shared Components for Raylib
|
||||
*
|
||||
* rlImGui * basic ImGui integration
|
||||
*
|
||||
* LICENSE: ZLIB
|
||||
*
|
||||
* Copyright (c) 2020 Jeffery Myers
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
**********************************************************************************************/
|
||||
#include "rlImGui.h"
|
||||
|
||||
#include "imgui_impl_raylib.h"
|
||||
|
||||
#include "raylib.h"
|
||||
#include "rlgl.h"
|
||||
|
||||
#ifdef PLATFORM_DESKTOP
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
#include <memory.h>
|
||||
|
||||
#define NO_FONT_AWESOME
|
||||
#ifndef NO_FONT_AWESOME
|
||||
#include "extras/FA6FreeSolidFontData.h"
|
||||
#endif
|
||||
|
||||
static ImGuiMouseCursor CurrentMouseCursor = ImGuiMouseCursor_COUNT;
|
||||
static MouseCursor MouseCursorMap[ImGuiMouseCursor_COUNT];
|
||||
|
||||
ImGuiContext *GlobalContext = NULL;
|
||||
|
||||
#define KEY_MAP_SIZE 512
|
||||
static ImGuiKey RaylibKeyMap[KEY_MAP_SIZE] = {};
|
||||
static bool RaylibKeyMapReady = false;
|
||||
|
||||
static bool LastFrameFocused = false;
|
||||
|
||||
static bool LastControlPressed = false;
|
||||
static bool LastShiftPressed = false;
|
||||
static bool LastAltPressed = false;
|
||||
static bool LastSuperPressed = false;
|
||||
|
||||
bool rlImGuiIsControlDown() { return IsKeyDown(KEY_RIGHT_CONTROL) || IsKeyDown(KEY_LEFT_CONTROL); }
|
||||
|
||||
bool rlImGuiIsShiftDown() { return IsKeyDown(KEY_RIGHT_SHIFT) || IsKeyDown(KEY_LEFT_SHIFT); }
|
||||
|
||||
bool rlImGuiIsAltDown() { return IsKeyDown(KEY_RIGHT_ALT) || IsKeyDown(KEY_LEFT_ALT); }
|
||||
|
||||
bool rlImGuiIsSuperDown() { return IsKeyDown(KEY_RIGHT_SUPER) || IsKeyDown(KEY_LEFT_SUPER); }
|
||||
|
||||
void ReloadFonts() {
|
||||
ImGuiIO *io = igGetIO();
|
||||
unsigned char *pixels = NULL;
|
||||
|
||||
int width;
|
||||
int height;
|
||||
ImFontAtlas_GetTexDataAsRGBA32(io->Fonts, &pixels, &width, &height, NULL);
|
||||
Image image = GenImageColor(width, height, BLANK);
|
||||
memcpy(image.data, pixels, width * height * 4);
|
||||
|
||||
Texture2D *fontTexture = (Texture2D *) io->Fonts->TexID;
|
||||
if (fontTexture && fontTexture->id != 0) {
|
||||
UnloadTexture(*fontTexture);
|
||||
MemFree(fontTexture);
|
||||
}
|
||||
|
||||
fontTexture = (Texture2D *) MemAlloc(sizeof(Texture2D));
|
||||
*fontTexture = LoadTextureFromImage(image);
|
||||
UnloadImage(image);
|
||||
io->Fonts->TexID = fontTexture;
|
||||
}
|
||||
|
||||
static const char *GetClipTextCallback(void *) {
|
||||
return GetClipboardText();
|
||||
}
|
||||
|
||||
static void SetClipTextCallback(void *, const char *text) {
|
||||
SetClipboardText(text);
|
||||
}
|
||||
|
||||
static void ImGuiNewFrame(float deltaTime) {
|
||||
ImGuiIO *io = igGetIO();
|
||||
|
||||
if (IsWindowFullscreen()) {
|
||||
int monitor = GetCurrentMonitor();
|
||||
io->DisplaySize.x = (float) (GetMonitorWidth(monitor));
|
||||
io->DisplaySize.y = (float) (GetMonitorHeight(monitor));
|
||||
} else {
|
||||
io->DisplaySize.x = (float) (GetScreenWidth());
|
||||
io->DisplaySize.y = (float) (GetScreenHeight());
|
||||
}
|
||||
|
||||
int width = (int) (io->DisplaySize.x), height = (int) (io->DisplaySize.y);
|
||||
#ifdef PLATFORM_DESKTOP
|
||||
glfwGetFramebufferSize(glfwGetCurrentContext(), &width, &height);
|
||||
#endif
|
||||
if (width > 0 && height > 0) {
|
||||
io->DisplayFramebufferScale = (ImVec2) {width / io->DisplaySize.x, height / io->DisplaySize.y};
|
||||
} else {
|
||||
io->DisplayFramebufferScale = (ImVec2) {1.0f, 1.0f};
|
||||
}
|
||||
|
||||
io->DeltaTime = deltaTime;
|
||||
|
||||
if (io->WantSetMousePos) {
|
||||
SetMousePosition((int) io->MousePos.x, (int) io->MousePos.y);
|
||||
} else {
|
||||
ImGuiIO_AddMousePosEvent(io, (float) GetMouseX(), (float) GetMouseY());
|
||||
}
|
||||
|
||||
#define setMouseEvent(rayMouse, imGuiMouse) \
|
||||
do { \
|
||||
int rMouse = rayMouse; \
|
||||
int iMouse = imGuiMouse; \
|
||||
if (IsMouseButtonPressed(rMouse)) \
|
||||
ImGuiIO_AddMouseButtonEvent(io, iMouse, true); \
|
||||
else if (IsMouseButtonReleased(rMouse)) \
|
||||
ImGuiIO_AddMouseButtonEvent(io, iMouse, false); \
|
||||
} while(0)
|
||||
|
||||
setMouseEvent(MOUSE_BUTTON_LEFT, ImGuiMouseButton_Left);
|
||||
setMouseEvent(MOUSE_BUTTON_RIGHT, ImGuiMouseButton_Right);
|
||||
setMouseEvent(MOUSE_BUTTON_MIDDLE, ImGuiMouseButton_Middle);
|
||||
setMouseEvent(MOUSE_BUTTON_FORWARD, ImGuiMouseButton_Middle + 1);
|
||||
setMouseEvent(MOUSE_BUTTON_BACK, ImGuiMouseButton_Middle + 2);
|
||||
#undef setMouseEvent
|
||||
|
||||
{
|
||||
Vector2 mouseWheel = GetMouseWheelMoveV();
|
||||
ImGuiIO_AddMouseWheelEvent(io, mouseWheel.x, mouseWheel.y);
|
||||
}
|
||||
|
||||
if ((io->ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange) == 0) {
|
||||
ImGuiMouseCursor imgui_cursor = igGetMouseCursor();
|
||||
if (imgui_cursor != CurrentMouseCursor || io->MouseDrawCursor) {
|
||||
CurrentMouseCursor = imgui_cursor;
|
||||
if (io->MouseDrawCursor || imgui_cursor == ImGuiMouseCursor_None) {
|
||||
HideCursor();
|
||||
} else {
|
||||
ShowCursor();
|
||||
|
||||
if (!(io->ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange)) {
|
||||
SetMouseCursor(
|
||||
(imgui_cursor > -1 && imgui_cursor < ImGuiMouseCursor_COUNT) ? MouseCursorMap[imgui_cursor]
|
||||
: MOUSE_CURSOR_DEFAULT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void ImGuiTriangleVert(ImDrawVert *idx_vert) {
|
||||
Color *c;
|
||||
c = (Color *) &idx_vert->col;
|
||||
rlColor4ub(c->r, c->g, c->b, c->a);
|
||||
rlTexCoord2f(idx_vert->uv.x, idx_vert->uv.y);
|
||||
rlVertex2f(idx_vert->pos.x, idx_vert->pos.y);
|
||||
}
|
||||
|
||||
static void ImGuiRenderTriangles(unsigned int count, int indexStart, const ImVector_ImDrawIdx *indexBuffer,
|
||||
const ImVector_ImDrawVert *vertBuffer, void *texturePtr) {
|
||||
if (count < 3)
|
||||
return;
|
||||
|
||||
Texture *texture = (Texture *) texturePtr;
|
||||
|
||||
unsigned int textureId = (texture == NULL) ? 0 : texture->id;
|
||||
|
||||
rlBegin(RL_TRIANGLES);
|
||||
rlSetTexture(textureId);
|
||||
|
||||
for (unsigned int i = 0; i <= (count - 3); i += 3) {
|
||||
if (rlCheckRenderBatchLimit(3)) {
|
||||
rlBegin(RL_TRIANGLES);
|
||||
rlSetTexture(textureId);
|
||||
}
|
||||
|
||||
ImDrawIdx indexA = indexBuffer->Data[indexStart + i];
|
||||
ImDrawIdx indexB = indexBuffer->Data[indexStart + i + 1];
|
||||
ImDrawIdx indexC = indexBuffer->Data[indexStart + i + 2];
|
||||
|
||||
ImDrawVert vertexA = vertBuffer->Data[indexA];
|
||||
ImDrawVert vertexB = vertBuffer->Data[indexB];
|
||||
ImDrawVert vertexC = vertBuffer->Data[indexC];
|
||||
|
||||
ImGuiTriangleVert(&vertexA);
|
||||
ImGuiTriangleVert(&vertexB);
|
||||
ImGuiTriangleVert(&vertexC);
|
||||
}
|
||||
|
||||
rlEnd();
|
||||
|
||||
}
|
||||
|
||||
static void EnableScissor(float x, float y, float width, float height) {
|
||||
rlEnableScissorTest();
|
||||
ImGuiIO *io = igGetIO();
|
||||
rlScissor((int) (x * io->DisplayFramebufferScale.x),
|
||||
(int) ((GetScreenHeight() - (int) (y + height)) * io->DisplayFramebufferScale.y),
|
||||
(int) (width * io->DisplayFramebufferScale.x),
|
||||
(int) (height * io->DisplayFramebufferScale.y));
|
||||
}
|
||||
|
||||
static void SetupMouseCursors() {
|
||||
MouseCursorMap[ImGuiMouseCursor_Arrow] = MOUSE_CURSOR_ARROW;
|
||||
MouseCursorMap[ImGuiMouseCursor_TextInput] = MOUSE_CURSOR_IBEAM;
|
||||
MouseCursorMap[ImGuiMouseCursor_Hand] = MOUSE_CURSOR_POINTING_HAND;
|
||||
MouseCursorMap[ImGuiMouseCursor_ResizeAll] = MOUSE_CURSOR_RESIZE_ALL;
|
||||
MouseCursorMap[ImGuiMouseCursor_ResizeEW] = MOUSE_CURSOR_RESIZE_EW;
|
||||
MouseCursorMap[ImGuiMouseCursor_ResizeNESW] = MOUSE_CURSOR_RESIZE_NESW;
|
||||
MouseCursorMap[ImGuiMouseCursor_ResizeNS] = MOUSE_CURSOR_RESIZE_NS;
|
||||
MouseCursorMap[ImGuiMouseCursor_ResizeNWSE] = MOUSE_CURSOR_RESIZE_NWSE;
|
||||
MouseCursorMap[ImGuiMouseCursor_NotAllowed] = MOUSE_CURSOR_NOT_ALLOWED;
|
||||
}
|
||||
|
||||
void SetupFontAwesome() {
|
||||
#ifndef NO_FONT_AWESOME
|
||||
static const ImWchar icons_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 };
|
||||
ImFontConfig icons_config;
|
||||
icons_config.MergeMode = true;
|
||||
icons_config.PixelSnapH = true;
|
||||
icons_config.FontDataOwnedByAtlas = false;
|
||||
|
||||
icons_config.GlyphRanges = icons_ranges;
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
io->Fonts->AddFontFromMemoryCompressedTTF((void*)fa_solid_900_compressed_data, fa_solid_900_compressed_size, FONT_AWESOME_ICON_SIZE, &icons_config, icons_ranges);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void SetupBackend() {
|
||||
ImGuiIO *io = igGetIO();
|
||||
io->BackendPlatformName = "imgui_impl_raylib";
|
||||
|
||||
io->BackendFlags |= ImGuiBackendFlags_HasMouseCursors;
|
||||
|
||||
io->MousePos = (ImVec2) {0, 0};
|
||||
|
||||
io->SetClipboardTextFn = SetClipTextCallback;
|
||||
io->GetClipboardTextFn = GetClipTextCallback;
|
||||
|
||||
io->ClipboardUserData = NULL;
|
||||
}
|
||||
|
||||
void rlImGuiEndInitImGui() {
|
||||
igSetCurrentContext(GlobalContext);
|
||||
|
||||
SetupFontAwesome();
|
||||
|
||||
SetupMouseCursors();
|
||||
|
||||
SetupBackend();
|
||||
|
||||
ReloadFonts();
|
||||
}
|
||||
|
||||
static void SetupKeymap() {
|
||||
if (RaylibKeyMapReady)
|
||||
return;
|
||||
RaylibKeyMapReady = true;
|
||||
|
||||
// build up a map of raylib keys to ImGuiKeys
|
||||
RaylibKeyMap[KEY_APOSTROPHE] = ImGuiKey_Apostrophe;
|
||||
RaylibKeyMap[KEY_COMMA] = ImGuiKey_Comma;
|
||||
RaylibKeyMap[KEY_MINUS] = ImGuiKey_Minus;
|
||||
RaylibKeyMap[KEY_PERIOD] = ImGuiKey_Period;
|
||||
RaylibKeyMap[KEY_SLASH] = ImGuiKey_Slash;
|
||||
RaylibKeyMap[KEY_ZERO] = ImGuiKey_0;
|
||||
RaylibKeyMap[KEY_ONE] = ImGuiKey_1;
|
||||
RaylibKeyMap[KEY_TWO] = ImGuiKey_2;
|
||||
RaylibKeyMap[KEY_THREE] = ImGuiKey_3;
|
||||
RaylibKeyMap[KEY_FOUR] = ImGuiKey_4;
|
||||
RaylibKeyMap[KEY_FIVE] = ImGuiKey_5;
|
||||
RaylibKeyMap[KEY_SIX] = ImGuiKey_6;
|
||||
RaylibKeyMap[KEY_SEVEN] = ImGuiKey_7;
|
||||
RaylibKeyMap[KEY_EIGHT] = ImGuiKey_8;
|
||||
RaylibKeyMap[KEY_NINE] = ImGuiKey_9;
|
||||
RaylibKeyMap[KEY_SEMICOLON] = ImGuiKey_Semicolon;
|
||||
RaylibKeyMap[KEY_EQUAL] = ImGuiKey_Equal;
|
||||
RaylibKeyMap[KEY_A] = ImGuiKey_A;
|
||||
RaylibKeyMap[KEY_B] = ImGuiKey_B;
|
||||
RaylibKeyMap[KEY_C] = ImGuiKey_C;
|
||||
RaylibKeyMap[KEY_D] = ImGuiKey_D;
|
||||
RaylibKeyMap[KEY_E] = ImGuiKey_E;
|
||||
RaylibKeyMap[KEY_F] = ImGuiKey_F;
|
||||
RaylibKeyMap[KEY_G] = ImGuiKey_G;
|
||||
RaylibKeyMap[KEY_H] = ImGuiKey_H;
|
||||
RaylibKeyMap[KEY_I] = ImGuiKey_I;
|
||||
RaylibKeyMap[KEY_J] = ImGuiKey_J;
|
||||
RaylibKeyMap[KEY_K] = ImGuiKey_K;
|
||||
RaylibKeyMap[KEY_L] = ImGuiKey_L;
|
||||
RaylibKeyMap[KEY_M] = ImGuiKey_M;
|
||||
RaylibKeyMap[KEY_N] = ImGuiKey_N;
|
||||
RaylibKeyMap[KEY_O] = ImGuiKey_O;
|
||||
RaylibKeyMap[KEY_P] = ImGuiKey_P;
|
||||
RaylibKeyMap[KEY_Q] = ImGuiKey_Q;
|
||||
RaylibKeyMap[KEY_R] = ImGuiKey_R;
|
||||
RaylibKeyMap[KEY_S] = ImGuiKey_S;
|
||||
RaylibKeyMap[KEY_T] = ImGuiKey_T;
|
||||
RaylibKeyMap[KEY_U] = ImGuiKey_U;
|
||||
RaylibKeyMap[KEY_V] = ImGuiKey_V;
|
||||
RaylibKeyMap[KEY_W] = ImGuiKey_W;
|
||||
RaylibKeyMap[KEY_X] = ImGuiKey_X;
|
||||
RaylibKeyMap[KEY_Y] = ImGuiKey_Y;
|
||||
RaylibKeyMap[KEY_Z] = ImGuiKey_Z;
|
||||
RaylibKeyMap[KEY_SPACE] = ImGuiKey_Space;
|
||||
RaylibKeyMap[KEY_ESCAPE] = ImGuiKey_Escape;
|
||||
RaylibKeyMap[KEY_ENTER] = ImGuiKey_Enter;
|
||||
RaylibKeyMap[KEY_TAB] = ImGuiKey_Tab;
|
||||
RaylibKeyMap[KEY_BACKSPACE] = ImGuiKey_Backspace;
|
||||
RaylibKeyMap[KEY_INSERT] = ImGuiKey_Insert;
|
||||
RaylibKeyMap[KEY_DELETE] = ImGuiKey_Delete;
|
||||
RaylibKeyMap[KEY_RIGHT] = ImGuiKey_RightArrow;
|
||||
RaylibKeyMap[KEY_LEFT] = ImGuiKey_LeftArrow;
|
||||
RaylibKeyMap[KEY_DOWN] = ImGuiKey_DownArrow;
|
||||
RaylibKeyMap[KEY_UP] = ImGuiKey_UpArrow;
|
||||
RaylibKeyMap[KEY_PAGE_UP] = ImGuiKey_PageUp;
|
||||
RaylibKeyMap[KEY_PAGE_DOWN] = ImGuiKey_PageDown;
|
||||
RaylibKeyMap[KEY_HOME] = ImGuiKey_Home;
|
||||
RaylibKeyMap[KEY_END] = ImGuiKey_End;
|
||||
RaylibKeyMap[KEY_CAPS_LOCK] = ImGuiKey_CapsLock;
|
||||
RaylibKeyMap[KEY_SCROLL_LOCK] = ImGuiKey_ScrollLock;
|
||||
RaylibKeyMap[KEY_NUM_LOCK] = ImGuiKey_NumLock;
|
||||
RaylibKeyMap[KEY_PRINT_SCREEN] = ImGuiKey_PrintScreen;
|
||||
RaylibKeyMap[KEY_PAUSE] = ImGuiKey_Pause;
|
||||
RaylibKeyMap[KEY_F1] = ImGuiKey_F1;
|
||||
RaylibKeyMap[KEY_F2] = ImGuiKey_F2;
|
||||
RaylibKeyMap[KEY_F3] = ImGuiKey_F3;
|
||||
RaylibKeyMap[KEY_F4] = ImGuiKey_F4;
|
||||
RaylibKeyMap[KEY_F5] = ImGuiKey_F5;
|
||||
RaylibKeyMap[KEY_F6] = ImGuiKey_F6;
|
||||
RaylibKeyMap[KEY_F7] = ImGuiKey_F7;
|
||||
RaylibKeyMap[KEY_F8] = ImGuiKey_F8;
|
||||
RaylibKeyMap[KEY_F9] = ImGuiKey_F9;
|
||||
RaylibKeyMap[KEY_F10] = ImGuiKey_F10;
|
||||
RaylibKeyMap[KEY_F11] = ImGuiKey_F11;
|
||||
RaylibKeyMap[KEY_F12] = ImGuiKey_F12;
|
||||
RaylibKeyMap[KEY_LEFT_SHIFT] = ImGuiKey_LeftShift;
|
||||
RaylibKeyMap[KEY_LEFT_CONTROL] = ImGuiKey_LeftCtrl;
|
||||
RaylibKeyMap[KEY_LEFT_ALT] = ImGuiKey_LeftAlt;
|
||||
RaylibKeyMap[KEY_LEFT_SUPER] = ImGuiKey_LeftSuper;
|
||||
RaylibKeyMap[KEY_RIGHT_SHIFT] = ImGuiKey_RightShift;
|
||||
RaylibKeyMap[KEY_RIGHT_CONTROL] = ImGuiKey_RightCtrl;
|
||||
RaylibKeyMap[KEY_RIGHT_ALT] = ImGuiKey_RightAlt;
|
||||
RaylibKeyMap[KEY_RIGHT_SUPER] = ImGuiKey_RightSuper;
|
||||
RaylibKeyMap[KEY_KB_MENU] = ImGuiKey_Menu;
|
||||
RaylibKeyMap[KEY_LEFT_BRACKET] = ImGuiKey_LeftBracket;
|
||||
RaylibKeyMap[KEY_BACKSLASH] = ImGuiKey_Backslash;
|
||||
RaylibKeyMap[KEY_RIGHT_BRACKET] = ImGuiKey_RightBracket;
|
||||
RaylibKeyMap[KEY_GRAVE] = ImGuiKey_GraveAccent;
|
||||
RaylibKeyMap[KEY_KP_0] = ImGuiKey_Keypad0;
|
||||
RaylibKeyMap[KEY_KP_1] = ImGuiKey_Keypad1;
|
||||
RaylibKeyMap[KEY_KP_2] = ImGuiKey_Keypad2;
|
||||
RaylibKeyMap[KEY_KP_3] = ImGuiKey_Keypad3;
|
||||
RaylibKeyMap[KEY_KP_4] = ImGuiKey_Keypad4;
|
||||
RaylibKeyMap[KEY_KP_5] = ImGuiKey_Keypad5;
|
||||
RaylibKeyMap[KEY_KP_6] = ImGuiKey_Keypad6;
|
||||
RaylibKeyMap[KEY_KP_7] = ImGuiKey_Keypad7;
|
||||
RaylibKeyMap[KEY_KP_8] = ImGuiKey_Keypad8;
|
||||
RaylibKeyMap[KEY_KP_9] = ImGuiKey_Keypad9;
|
||||
RaylibKeyMap[KEY_KP_DECIMAL] = ImGuiKey_KeypadDecimal;
|
||||
RaylibKeyMap[KEY_KP_DIVIDE] = ImGuiKey_KeypadDivide;
|
||||
RaylibKeyMap[KEY_KP_MULTIPLY] = ImGuiKey_KeypadMultiply;
|
||||
RaylibKeyMap[KEY_KP_SUBTRACT] = ImGuiKey_KeypadSubtract;
|
||||
RaylibKeyMap[KEY_KP_ADD] = ImGuiKey_KeypadAdd;
|
||||
RaylibKeyMap[KEY_KP_ENTER] = ImGuiKey_KeypadEnter;
|
||||
RaylibKeyMap[KEY_KP_EQUAL] = ImGuiKey_KeypadEqual;
|
||||
}
|
||||
|
||||
static void SetupGlobals() {
|
||||
LastFrameFocused = IsWindowFocused();
|
||||
LastControlPressed = false;
|
||||
LastShiftPressed = false;
|
||||
LastAltPressed = false;
|
||||
LastSuperPressed = false;
|
||||
|
||||
}
|
||||
|
||||
void rlImGuiBeginInitImGui() {
|
||||
SetupGlobals();
|
||||
GlobalContext = igCreateContext(NULL);
|
||||
SetupKeymap();
|
||||
|
||||
ImGuiIO *io = igGetIO();
|
||||
ImFontAtlas_AddFontDefault(io->Fonts, NULL);
|
||||
}
|
||||
|
||||
void rlImGuiSetup(bool dark) {
|
||||
rlImGuiBeginInitImGui();
|
||||
|
||||
if (dark)
|
||||
igStyleColorsDark(NULL);
|
||||
else
|
||||
igStyleColorsLight(NULL);
|
||||
|
||||
rlImGuiEndInitImGui();
|
||||
}
|
||||
|
||||
void rlImGuiReloadFonts() {
|
||||
igSetCurrentContext(GlobalContext);
|
||||
|
||||
ReloadFonts();
|
||||
}
|
||||
|
||||
void rlImGuiBegin() {
|
||||
igSetCurrentContext(GlobalContext);
|
||||
rlImGuiBeginDelta(GetFrameTime());
|
||||
}
|
||||
|
||||
void rlImGuiBeginDelta(float deltaTime) {
|
||||
igSetCurrentContext(GlobalContext);
|
||||
ImGuiNewFrame(deltaTime);
|
||||
ImGui_ImplRaylib_ProcessEvents();
|
||||
igNewFrame();
|
||||
}
|
||||
|
||||
void rlImGuiEnd() {
|
||||
igSetCurrentContext(GlobalContext);
|
||||
igRender();
|
||||
ImGui_ImplRaylib_RenderDrawData(igGetDrawData());
|
||||
}
|
||||
|
||||
void rlImGuiShutdown() {
|
||||
igSetCurrentContext(GlobalContext);
|
||||
ImGui_ImplRaylib_Shutdown();
|
||||
|
||||
igDestroyContext(NULL);
|
||||
}
|
||||
|
||||
static ImVec2 defaultUV0 = {0, 0};
|
||||
static ImVec2 defaultUV1 = {1, 1};
|
||||
static ImVec4 defaultBgCol = {0, 0, 0, 0};
|
||||
static ImVec4 defaultTintCol = {1, 1, 1, 1};
|
||||
|
||||
void rlImGuiImage(const Texture *image) {
|
||||
if (!image)
|
||||
return;
|
||||
if (GlobalContext)
|
||||
igSetCurrentContext(GlobalContext);
|
||||
igImage((ImTextureID) image, (ImVec2) {(float) (image->width), (float) (image->height)},
|
||||
defaultUV0, defaultUV1, defaultTintCol, defaultBgCol
|
||||
);
|
||||
}
|
||||
|
||||
bool rlImGuiImageButton(const char *name, const Texture *image) {
|
||||
if (!image)
|
||||
return false;
|
||||
if (GlobalContext)
|
||||
igSetCurrentContext(GlobalContext);
|
||||
return igImageButton(name, (ImTextureID) image, (ImVec2) {(float) (image->width), (float) (image->height)},
|
||||
defaultUV0, defaultUV1, defaultBgCol, defaultTintCol
|
||||
);
|
||||
}
|
||||
|
||||
bool rlImGuiImageButtonSize(const char *name, const Texture *image, ImVec2 size) {
|
||||
if (!image)
|
||||
return false;
|
||||
if (GlobalContext)
|
||||
igSetCurrentContext(GlobalContext);
|
||||
return igImageButton(name, (ImTextureID) image, size,
|
||||
defaultUV0, defaultUV1, defaultBgCol, defaultTintCol
|
||||
);
|
||||
}
|
||||
|
||||
void rlImGuiImageSize(const Texture *image, int width, int height) {
|
||||
if (!image)
|
||||
return;
|
||||
if (GlobalContext)
|
||||
igSetCurrentContext(GlobalContext);
|
||||
igImage((ImTextureID) image, (ImVec2) {(float) (width), (float) (height)},
|
||||
defaultUV0, defaultUV1, defaultTintCol, defaultBgCol
|
||||
);
|
||||
}
|
||||
|
||||
void rlImGuiImageSizeV(const Texture *image, Vector2 size) {
|
||||
if (!image)
|
||||
return;
|
||||
if (GlobalContext)
|
||||
igSetCurrentContext(GlobalContext);
|
||||
igImage((ImTextureID) image, (ImVec2) {size.x, size.y},
|
||||
defaultUV0, defaultUV1, defaultTintCol, defaultBgCol
|
||||
);
|
||||
}
|
||||
|
||||
void rlImGuiImageRect(const Texture *image, int destWidth, int destHeight, Rectangle sourceRect) {
|
||||
if (!image)
|
||||
return;
|
||||
if (GlobalContext)
|
||||
igSetCurrentContext(GlobalContext);
|
||||
ImVec2 uv0;
|
||||
ImVec2 uv1;
|
||||
|
||||
if (sourceRect.width < 0) {
|
||||
uv0.x = -((float) sourceRect.x / image->width);
|
||||
uv1.x = (uv0.x - (float) (fabs(sourceRect.width) / image->width));
|
||||
} else {
|
||||
uv0.x = (float) sourceRect.x / image->width;
|
||||
uv1.x = uv0.x + (float) (sourceRect.width / image->width);
|
||||
}
|
||||
|
||||
if (sourceRect.height < 0) {
|
||||
uv0.y = -((float) sourceRect.y / image->height);
|
||||
uv1.y = (uv0.y - (float) (fabs(sourceRect.height) / image->height));
|
||||
} else {
|
||||
uv0.y = (float) sourceRect.y / image->height;
|
||||
uv1.y = uv0.y + (float) (sourceRect.height / image->height);
|
||||
}
|
||||
|
||||
igImage((ImTextureID) image, (ImVec2) {
|
||||
(float) (destWidth),
|
||||
(float) (destHeight)}, uv0, uv1, defaultTintCol, defaultBgCol);
|
||||
}
|
||||
|
||||
void rlImGuiImageRenderTexture(const RenderTexture *image) {
|
||||
if (!image)
|
||||
return;
|
||||
if (GlobalContext)
|
||||
igSetCurrentContext(GlobalContext);
|
||||
rlImGuiImageRect(&image->texture, image->texture.width, image->texture.height, (Rectangle) {
|
||||
0, 0, (float) (image->texture.width), -(float) (image->texture.height)
|
||||
});
|
||||
}
|
||||
|
||||
void rlImGuiImageRenderTextureFit(const RenderTexture *image, bool center) {
|
||||
if (!image)
|
||||
return;
|
||||
if (GlobalContext)
|
||||
igSetCurrentContext(GlobalContext);
|
||||
|
||||
ImVec2 area;
|
||||
igGetContentRegionAvail(&area);
|
||||
|
||||
float scale = area.x / image->texture.width;
|
||||
|
||||
float y = image->texture.height * scale;
|
||||
if (y > area.y) {
|
||||
scale = area.y / image->texture.height;
|
||||
}
|
||||
|
||||
int sizeX = (int) (image->texture.width * scale);
|
||||
int sizeY = (int) (image->texture.height * scale);
|
||||
|
||||
if (center) {
|
||||
igSetCursorPosX(0);
|
||||
igSetCursorPosX(area.x / 2 - sizeX / 2);
|
||||
igSetCursorPosY(igGetCursorPosY() + (area.y / 2 - sizeY / 2));
|
||||
}
|
||||
|
||||
rlImGuiImageRect(&image->texture, sizeX, sizeY, (Rectangle) {
|
||||
0, 0, (float) (image->texture.width), -(float) (image->texture.height)
|
||||
});
|
||||
}
|
||||
|
||||
// raw ImGui backend API
|
||||
bool ImGui_ImplRaylib_Init() {
|
||||
SetupGlobals();
|
||||
|
||||
SetupKeymap();
|
||||
|
||||
ImGuiIO *io = igGetIO();
|
||||
ImFontAtlas_AddFontDefault(io->Fonts, NULL);
|
||||
|
||||
SetupFontAwesome();
|
||||
|
||||
SetupMouseCursors();
|
||||
|
||||
SetupBackend();
|
||||
|
||||
ReloadFonts();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ImGui_ImplRaylib_Shutdown() {
|
||||
ImGuiIO *io = igGetIO();
|
||||
|
||||
Texture2D *fontTexture = (Texture2D *) io->Fonts->TexID;
|
||||
|
||||
if (fontTexture && fontTexture->id != 0)
|
||||
UnloadTexture(*fontTexture);
|
||||
|
||||
io->Fonts->TexID = 0;
|
||||
}
|
||||
|
||||
void ImGui_ImplRaylib_NewFrame() {
|
||||
ImGuiNewFrame(GetFrameTime());
|
||||
}
|
||||
|
||||
void ImGui_ImplRaylib_RenderDrawData(ImDrawData *draw_data) {
|
||||
rlDrawRenderBatchActive();
|
||||
rlDisableBackfaceCulling();
|
||||
|
||||
for (int l = 0; l < draw_data->CmdListsCount; ++l) {
|
||||
const ImDrawList *commandList = draw_data->CmdLists.Data[l];
|
||||
const ImDrawVert *vtxBuffer = commandList->VtxBuffer.Data;
|
||||
const ImDrawIdx *idxBuffer = commandList->IdxBuffer.Data;
|
||||
|
||||
for (int cmd_i = 0; cmd_i < commandList->CmdBuffer.Size; cmd_i++) {
|
||||
const ImDrawCmd cmd = commandList->CmdBuffer.Data[cmd_i];
|
||||
EnableScissor(cmd.ClipRect.x - draw_data->DisplayPos.x, cmd.ClipRect.y - draw_data->DisplayPos.y,
|
||||
cmd.ClipRect.z - (cmd.ClipRect.x - draw_data->DisplayPos.x),
|
||||
cmd.ClipRect.w - (cmd.ClipRect.y - draw_data->DisplayPos.y));
|
||||
if (cmd.UserCallback != NULL) {
|
||||
cmd.UserCallback(commandList, &cmd);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
ImGuiRenderTriangles(cmd.ElemCount, cmd.IdxOffset, &commandList->IdxBuffer, &commandList->VtxBuffer,
|
||||
cmd.TextureId);
|
||||
rlDrawRenderBatchActive();
|
||||
}
|
||||
}
|
||||
|
||||
rlSetTexture(0);
|
||||
rlDisableScissorTest();
|
||||
rlEnableBackfaceCulling();
|
||||
}
|
||||
|
||||
bool ImGui_ImplRaylib_ProcessEvents() {
|
||||
ImGuiIO *io = igGetIO();
|
||||
|
||||
bool focused = IsWindowFocused();
|
||||
if (focused != LastFrameFocused)
|
||||
ImGuiIO_AddFocusEvent(io, focused);
|
||||
LastFrameFocused = focused;
|
||||
|
||||
// handle the modifyer key events so that shortcuts work
|
||||
bool ctrlDown = rlImGuiIsControlDown();
|
||||
if (ctrlDown != LastControlPressed)
|
||||
ImGuiIO_AddKeyEvent(io, ImGuiMod_Ctrl, ctrlDown);
|
||||
LastControlPressed = ctrlDown;
|
||||
|
||||
bool shiftDown = rlImGuiIsShiftDown();
|
||||
if (shiftDown != LastShiftPressed)
|
||||
ImGuiIO_AddKeyEvent(io, ImGuiMod_Shift, shiftDown);
|
||||
LastShiftPressed = shiftDown;
|
||||
|
||||
bool altDown = rlImGuiIsAltDown();
|
||||
if (altDown != LastAltPressed)
|
||||
ImGuiIO_AddKeyEvent(io, ImGuiMod_Alt, altDown);
|
||||
LastAltPressed = altDown;
|
||||
|
||||
bool superDown = rlImGuiIsSuperDown();
|
||||
if (superDown != LastSuperPressed)
|
||||
ImGuiIO_AddKeyEvent(io, ImGuiMod_Super, superDown);
|
||||
LastSuperPressed = superDown;
|
||||
|
||||
// get the pressed keys, they are in event order
|
||||
int keyId = GetKeyPressed();
|
||||
while (keyId != 0) {
|
||||
ImGuiKey keyItr = RaylibKeyMap[(KeyboardKey)(keyId)];
|
||||
if (keyItr != 0)
|
||||
ImGuiIO_AddKeyEvent(io, keyItr, true);
|
||||
keyId = GetKeyPressed();
|
||||
}
|
||||
|
||||
// look for any keys that were down last frame and see if they were down and are released
|
||||
for (int i = 0; i < KEY_MAP_SIZE; i++) {
|
||||
if (RaylibKeyMap[i] == 0) continue;
|
||||
if (IsKeyReleased(i))
|
||||
ImGuiIO_AddKeyEvent(io, RaylibKeyMap[i], false);
|
||||
}
|
||||
|
||||
// add the text input in order
|
||||
unsigned int pressed = GetCharPressed();
|
||||
while (pressed != 0) {
|
||||
ImGuiIO_AddInputCharacter(io, pressed);
|
||||
pressed = GetCharPressed();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,717 +0,0 @@
|
||||
/**********************************************************************************************
|
||||
*
|
||||
* raylibExtras * Utilities and Shared Components for Raylib
|
||||
*
|
||||
* rlImGui * basic ImGui integration
|
||||
*
|
||||
* LICENSE: ZLIB
|
||||
*
|
||||
* Copyright (c) 2020 Jeffery Myers
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
**********************************************************************************************/
|
||||
#include "rlImGui.h"
|
||||
|
||||
#include "imgui_impl_raylib.h"
|
||||
|
||||
#include "raylib.h"
|
||||
#include "rlgl.h"
|
||||
|
||||
#ifdef PLATFORM_DESKTOP
|
||||
#include <GLFW/glfw3.h>
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
#include <map>
|
||||
|
||||
#ifndef NO_FONT_AWESOME
|
||||
#include "extras/FA6FreeSolidFontData.h"
|
||||
#endif
|
||||
|
||||
static ImGuiMouseCursor CurrentMouseCursor = ImGuiMouseCursor_COUNT;
|
||||
static MouseCursor MouseCursorMap[ImGuiMouseCursor_COUNT];
|
||||
|
||||
ImGuiContext* GlobalContext = nullptr;
|
||||
|
||||
static std::map<KeyboardKey, ImGuiKey> RaylibKeyMap;
|
||||
|
||||
static bool LastFrameFocused = false;
|
||||
|
||||
static bool LastControlPressed = false;
|
||||
static bool LastShiftPressed = false;
|
||||
static bool LastAltPressed = false;
|
||||
static bool LastSuperPressed = false;
|
||||
|
||||
bool rlImGuiIsControlDown() { return IsKeyDown(KEY_RIGHT_CONTROL) || IsKeyDown(KEY_LEFT_CONTROL); }
|
||||
bool rlImGuiIsShiftDown() { return IsKeyDown(KEY_RIGHT_SHIFT) || IsKeyDown(KEY_LEFT_SHIFT); }
|
||||
bool rlImGuiIsAltDown() { return IsKeyDown(KEY_RIGHT_ALT) || IsKeyDown(KEY_LEFT_ALT); }
|
||||
bool rlImGuiIsSuperDown() { return IsKeyDown(KEY_RIGHT_SUPER) || IsKeyDown(KEY_LEFT_SUPER); }
|
||||
|
||||
void ReloadFonts()
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
unsigned char* pixels = nullptr;
|
||||
|
||||
int width;
|
||||
int height;
|
||||
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height, nullptr);
|
||||
Image image = GenImageColor(width, height, BLANK);
|
||||
memcpy(image.data, pixels, width * height * 4);
|
||||
|
||||
Texture2D* fontTexture = (Texture2D*)io.Fonts->TexID;
|
||||
if (fontTexture && fontTexture->id != 0)
|
||||
{
|
||||
UnloadTexture(*fontTexture);
|
||||
MemFree(fontTexture);
|
||||
}
|
||||
|
||||
fontTexture = (Texture2D*)MemAlloc(sizeof(Texture2D));
|
||||
*fontTexture = LoadTextureFromImage(image);
|
||||
UnloadImage(image);
|
||||
io.Fonts->TexID = fontTexture;
|
||||
}
|
||||
|
||||
static const char* GetClipTextCallback(void*)
|
||||
{
|
||||
return GetClipboardText();
|
||||
}
|
||||
|
||||
static void SetClipTextCallback(void*, const char* text)
|
||||
{
|
||||
SetClipboardText(text);
|
||||
}
|
||||
|
||||
static void ImGuiNewFrame(float deltaTime)
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
if (IsWindowFullscreen())
|
||||
{
|
||||
int monitor = GetCurrentMonitor();
|
||||
io.DisplaySize.x = float(GetMonitorWidth(monitor));
|
||||
io.DisplaySize.y = float(GetMonitorHeight(monitor));
|
||||
}
|
||||
else
|
||||
{
|
||||
io.DisplaySize.x = float(GetScreenWidth());
|
||||
io.DisplaySize.y = float(GetScreenHeight());
|
||||
}
|
||||
|
||||
int width = int(io.DisplaySize.x), height = int(io.DisplaySize.y);
|
||||
#ifdef PLATFORM_DESKTOP
|
||||
glfwGetFramebufferSize(glfwGetCurrentContext(), &width, &height);
|
||||
#endif
|
||||
if (width > 0 && height > 0)
|
||||
{
|
||||
io.DisplayFramebufferScale = ImVec2(width / io.DisplaySize.x, height / io.DisplaySize.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
io.DisplayFramebufferScale = ImVec2(1.0f, 1.0f);
|
||||
}
|
||||
|
||||
io.DeltaTime = deltaTime;
|
||||
|
||||
if (io.WantSetMousePos)
|
||||
{
|
||||
SetMousePosition((int)io.MousePos.x, (int)io.MousePos.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
io.AddMousePosEvent((float)GetMouseX(), (float)GetMouseY());
|
||||
}
|
||||
|
||||
auto setMouseEvent = [&io](int rayMouse, int imGuiMouse)
|
||||
{
|
||||
if (IsMouseButtonPressed(rayMouse))
|
||||
io.AddMouseButtonEvent(imGuiMouse, true);
|
||||
else if (IsMouseButtonReleased(rayMouse))
|
||||
io.AddMouseButtonEvent(imGuiMouse, false);
|
||||
};
|
||||
|
||||
setMouseEvent(MOUSE_BUTTON_LEFT, ImGuiMouseButton_Left);
|
||||
setMouseEvent(MOUSE_BUTTON_RIGHT, ImGuiMouseButton_Right);
|
||||
setMouseEvent(MOUSE_BUTTON_MIDDLE, ImGuiMouseButton_Middle);
|
||||
setMouseEvent(MOUSE_BUTTON_FORWARD, ImGuiMouseButton_Middle+1);
|
||||
setMouseEvent(MOUSE_BUTTON_BACK, ImGuiMouseButton_Middle+2);
|
||||
|
||||
{
|
||||
Vector2 mouseWheel = GetMouseWheelMoveV();
|
||||
io.AddMouseWheelEvent(mouseWheel.x, mouseWheel.y);
|
||||
}
|
||||
|
||||
if ((io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange) == 0)
|
||||
{
|
||||
ImGuiMouseCursor imgui_cursor = ImGui::GetMouseCursor();
|
||||
if (imgui_cursor != CurrentMouseCursor || io.MouseDrawCursor)
|
||||
{
|
||||
CurrentMouseCursor = imgui_cursor;
|
||||
if (io.MouseDrawCursor || imgui_cursor == ImGuiMouseCursor_None)
|
||||
{
|
||||
HideCursor();
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowCursor();
|
||||
|
||||
if (!(io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange))
|
||||
{
|
||||
SetMouseCursor((imgui_cursor > -1 && imgui_cursor < ImGuiMouseCursor_COUNT) ? MouseCursorMap[imgui_cursor] : MOUSE_CURSOR_DEFAULT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void ImGuiTriangleVert(ImDrawVert& idx_vert)
|
||||
{
|
||||
Color* c;
|
||||
c = (Color*)&idx_vert.col;
|
||||
rlColor4ub(c->r, c->g, c->b, c->a);
|
||||
rlTexCoord2f(idx_vert.uv.x, idx_vert.uv.y);
|
||||
rlVertex2f(idx_vert.pos.x, idx_vert.pos.y);
|
||||
}
|
||||
|
||||
static void ImGuiRenderTriangles(unsigned int count, int indexStart, const ImVector<ImDrawIdx>& indexBuffer, const ImVector<ImDrawVert>& vertBuffer, void* texturePtr)
|
||||
{
|
||||
if (count < 3)
|
||||
return;
|
||||
|
||||
Texture* texture = (Texture*)texturePtr;
|
||||
|
||||
unsigned int textureId = (texture == nullptr) ? 0 : texture->id;
|
||||
|
||||
rlBegin(RL_TRIANGLES);
|
||||
rlSetTexture(textureId);
|
||||
|
||||
for (unsigned int i = 0; i <= (count - 3); i += 3)
|
||||
{
|
||||
if (rlCheckRenderBatchLimit(3))
|
||||
{
|
||||
rlBegin(RL_TRIANGLES);
|
||||
rlSetTexture(textureId);
|
||||
}
|
||||
|
||||
ImDrawIdx indexA = indexBuffer[indexStart + i];
|
||||
ImDrawIdx indexB = indexBuffer[indexStart + i + 1];
|
||||
ImDrawIdx indexC = indexBuffer[indexStart + i + 2];
|
||||
|
||||
ImDrawVert vertexA = vertBuffer[indexA];
|
||||
ImDrawVert vertexB = vertBuffer[indexB];
|
||||
ImDrawVert vertexC = vertBuffer[indexC];
|
||||
|
||||
ImGuiTriangleVert(vertexA);
|
||||
ImGuiTriangleVert(vertexB);
|
||||
ImGuiTriangleVert(vertexC);
|
||||
}
|
||||
rlEnd();
|
||||
}
|
||||
|
||||
static void EnableScissor(float x, float y, float width, float height)
|
||||
{
|
||||
rlEnableScissorTest();
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
rlScissor((int)(x * io.DisplayFramebufferScale.x),
|
||||
int((GetScreenHeight() - (int)(y + height)) * io.DisplayFramebufferScale.y),
|
||||
(int)(width * io.DisplayFramebufferScale.x),
|
||||
(int)(height * io.DisplayFramebufferScale.y));
|
||||
}
|
||||
|
||||
static void SetupMouseCursors()
|
||||
{
|
||||
MouseCursorMap[ImGuiMouseCursor_Arrow] = MOUSE_CURSOR_ARROW;
|
||||
MouseCursorMap[ImGuiMouseCursor_TextInput] = MOUSE_CURSOR_IBEAM;
|
||||
MouseCursorMap[ImGuiMouseCursor_Hand] = MOUSE_CURSOR_POINTING_HAND;
|
||||
MouseCursorMap[ImGuiMouseCursor_ResizeAll] = MOUSE_CURSOR_RESIZE_ALL;
|
||||
MouseCursorMap[ImGuiMouseCursor_ResizeEW] = MOUSE_CURSOR_RESIZE_EW;
|
||||
MouseCursorMap[ImGuiMouseCursor_ResizeNESW] = MOUSE_CURSOR_RESIZE_NESW;
|
||||
MouseCursorMap[ImGuiMouseCursor_ResizeNS] = MOUSE_CURSOR_RESIZE_NS;
|
||||
MouseCursorMap[ImGuiMouseCursor_ResizeNWSE] = MOUSE_CURSOR_RESIZE_NWSE;
|
||||
MouseCursorMap[ImGuiMouseCursor_NotAllowed] = MOUSE_CURSOR_NOT_ALLOWED;
|
||||
}
|
||||
|
||||
void SetupFontAwesome()
|
||||
{
|
||||
#ifndef NO_FONT_AWESOME
|
||||
static const ImWchar icons_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 };
|
||||
ImFontConfig icons_config;
|
||||
icons_config.MergeMode = true;
|
||||
icons_config.PixelSnapH = true;
|
||||
icons_config.FontDataOwnedByAtlas = false;
|
||||
|
||||
icons_config.GlyphRanges = icons_ranges;
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
io.Fonts->AddFontFromMemoryCompressedTTF((void*)fa_solid_900_compressed_data, fa_solid_900_compressed_size, FONT_AWESOME_ICON_SIZE, &icons_config, icons_ranges);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void SetupBackend()
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.BackendPlatformName = "imgui_impl_raylib";
|
||||
|
||||
io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors;
|
||||
|
||||
io.MousePos = ImVec2(0, 0);
|
||||
|
||||
io.SetClipboardTextFn = SetClipTextCallback;
|
||||
io.GetClipboardTextFn = GetClipTextCallback;
|
||||
|
||||
io.ClipboardUserData = nullptr;
|
||||
}
|
||||
|
||||
void rlImGuiEndInitImGui()
|
||||
{
|
||||
ImGui::SetCurrentContext(GlobalContext);
|
||||
|
||||
SetupFontAwesome();
|
||||
|
||||
SetupMouseCursors();
|
||||
|
||||
SetupBackend();
|
||||
|
||||
ReloadFonts();
|
||||
}
|
||||
|
||||
static void SetupKeymap()
|
||||
{
|
||||
if (!RaylibKeyMap.empty())
|
||||
return;
|
||||
|
||||
// build up a map of raylib keys to ImGuiKeys
|
||||
RaylibKeyMap[KEY_APOSTROPHE] = ImGuiKey_Apostrophe;
|
||||
RaylibKeyMap[KEY_COMMA] = ImGuiKey_Comma;
|
||||
RaylibKeyMap[KEY_MINUS] = ImGuiKey_Minus;
|
||||
RaylibKeyMap[KEY_PERIOD] = ImGuiKey_Period;
|
||||
RaylibKeyMap[KEY_SLASH] = ImGuiKey_Slash;
|
||||
RaylibKeyMap[KEY_ZERO] = ImGuiKey_0;
|
||||
RaylibKeyMap[KEY_ONE] = ImGuiKey_1;
|
||||
RaylibKeyMap[KEY_TWO] = ImGuiKey_2;
|
||||
RaylibKeyMap[KEY_THREE] = ImGuiKey_3;
|
||||
RaylibKeyMap[KEY_FOUR] = ImGuiKey_4;
|
||||
RaylibKeyMap[KEY_FIVE] = ImGuiKey_5;
|
||||
RaylibKeyMap[KEY_SIX] = ImGuiKey_6;
|
||||
RaylibKeyMap[KEY_SEVEN] = ImGuiKey_7;
|
||||
RaylibKeyMap[KEY_EIGHT] = ImGuiKey_8;
|
||||
RaylibKeyMap[KEY_NINE] = ImGuiKey_9;
|
||||
RaylibKeyMap[KEY_SEMICOLON] = ImGuiKey_Semicolon;
|
||||
RaylibKeyMap[KEY_EQUAL] = ImGuiKey_Equal;
|
||||
RaylibKeyMap[KEY_A] = ImGuiKey_A;
|
||||
RaylibKeyMap[KEY_B] = ImGuiKey_B;
|
||||
RaylibKeyMap[KEY_C] = ImGuiKey_C;
|
||||
RaylibKeyMap[KEY_D] = ImGuiKey_D;
|
||||
RaylibKeyMap[KEY_E] = ImGuiKey_E;
|
||||
RaylibKeyMap[KEY_F] = ImGuiKey_F;
|
||||
RaylibKeyMap[KEY_G] = ImGuiKey_G;
|
||||
RaylibKeyMap[KEY_H] = ImGuiKey_H;
|
||||
RaylibKeyMap[KEY_I] = ImGuiKey_I;
|
||||
RaylibKeyMap[KEY_J] = ImGuiKey_J;
|
||||
RaylibKeyMap[KEY_K] = ImGuiKey_K;
|
||||
RaylibKeyMap[KEY_L] = ImGuiKey_L;
|
||||
RaylibKeyMap[KEY_M] = ImGuiKey_M;
|
||||
RaylibKeyMap[KEY_N] = ImGuiKey_N;
|
||||
RaylibKeyMap[KEY_O] = ImGuiKey_O;
|
||||
RaylibKeyMap[KEY_P] = ImGuiKey_P;
|
||||
RaylibKeyMap[KEY_Q] = ImGuiKey_Q;
|
||||
RaylibKeyMap[KEY_R] = ImGuiKey_R;
|
||||
RaylibKeyMap[KEY_S] = ImGuiKey_S;
|
||||
RaylibKeyMap[KEY_T] = ImGuiKey_T;
|
||||
RaylibKeyMap[KEY_U] = ImGuiKey_U;
|
||||
RaylibKeyMap[KEY_V] = ImGuiKey_V;
|
||||
RaylibKeyMap[KEY_W] = ImGuiKey_W;
|
||||
RaylibKeyMap[KEY_X] = ImGuiKey_X;
|
||||
RaylibKeyMap[KEY_Y] = ImGuiKey_Y;
|
||||
RaylibKeyMap[KEY_Z] = ImGuiKey_Z;
|
||||
RaylibKeyMap[KEY_SPACE] = ImGuiKey_Space;
|
||||
RaylibKeyMap[KEY_ESCAPE] = ImGuiKey_Escape;
|
||||
RaylibKeyMap[KEY_ENTER] = ImGuiKey_Enter;
|
||||
RaylibKeyMap[KEY_TAB] = ImGuiKey_Tab;
|
||||
RaylibKeyMap[KEY_BACKSPACE] = ImGuiKey_Backspace;
|
||||
RaylibKeyMap[KEY_INSERT] = ImGuiKey_Insert;
|
||||
RaylibKeyMap[KEY_DELETE] = ImGuiKey_Delete;
|
||||
RaylibKeyMap[KEY_RIGHT] = ImGuiKey_RightArrow;
|
||||
RaylibKeyMap[KEY_LEFT] = ImGuiKey_LeftArrow;
|
||||
RaylibKeyMap[KEY_DOWN] = ImGuiKey_DownArrow;
|
||||
RaylibKeyMap[KEY_UP] = ImGuiKey_UpArrow;
|
||||
RaylibKeyMap[KEY_PAGE_UP] = ImGuiKey_PageUp;
|
||||
RaylibKeyMap[KEY_PAGE_DOWN] = ImGuiKey_PageDown;
|
||||
RaylibKeyMap[KEY_HOME] = ImGuiKey_Home;
|
||||
RaylibKeyMap[KEY_END] = ImGuiKey_End;
|
||||
RaylibKeyMap[KEY_CAPS_LOCK] = ImGuiKey_CapsLock;
|
||||
RaylibKeyMap[KEY_SCROLL_LOCK] = ImGuiKey_ScrollLock;
|
||||
RaylibKeyMap[KEY_NUM_LOCK] = ImGuiKey_NumLock;
|
||||
RaylibKeyMap[KEY_PRINT_SCREEN] = ImGuiKey_PrintScreen;
|
||||
RaylibKeyMap[KEY_PAUSE] = ImGuiKey_Pause;
|
||||
RaylibKeyMap[KEY_F1] = ImGuiKey_F1;
|
||||
RaylibKeyMap[KEY_F2] = ImGuiKey_F2;
|
||||
RaylibKeyMap[KEY_F3] = ImGuiKey_F3;
|
||||
RaylibKeyMap[KEY_F4] = ImGuiKey_F4;
|
||||
RaylibKeyMap[KEY_F5] = ImGuiKey_F5;
|
||||
RaylibKeyMap[KEY_F6] = ImGuiKey_F6;
|
||||
RaylibKeyMap[KEY_F7] = ImGuiKey_F7;
|
||||
RaylibKeyMap[KEY_F8] = ImGuiKey_F8;
|
||||
RaylibKeyMap[KEY_F9] = ImGuiKey_F9;
|
||||
RaylibKeyMap[KEY_F10] = ImGuiKey_F10;
|
||||
RaylibKeyMap[KEY_F11] = ImGuiKey_F11;
|
||||
RaylibKeyMap[KEY_F12] = ImGuiKey_F12;
|
||||
RaylibKeyMap[KEY_LEFT_SHIFT] = ImGuiKey_LeftShift;
|
||||
RaylibKeyMap[KEY_LEFT_CONTROL] = ImGuiKey_LeftCtrl;
|
||||
RaylibKeyMap[KEY_LEFT_ALT] = ImGuiKey_LeftAlt;
|
||||
RaylibKeyMap[KEY_LEFT_SUPER] = ImGuiKey_LeftSuper;
|
||||
RaylibKeyMap[KEY_RIGHT_SHIFT] = ImGuiKey_RightShift;
|
||||
RaylibKeyMap[KEY_RIGHT_CONTROL] = ImGuiKey_RightCtrl;
|
||||
RaylibKeyMap[KEY_RIGHT_ALT] = ImGuiKey_RightAlt;
|
||||
RaylibKeyMap[KEY_RIGHT_SUPER] = ImGuiKey_RightSuper;
|
||||
RaylibKeyMap[KEY_KB_MENU] = ImGuiKey_Menu;
|
||||
RaylibKeyMap[KEY_LEFT_BRACKET] = ImGuiKey_LeftBracket;
|
||||
RaylibKeyMap[KEY_BACKSLASH] = ImGuiKey_Backslash;
|
||||
RaylibKeyMap[KEY_RIGHT_BRACKET] = ImGuiKey_RightBracket;
|
||||
RaylibKeyMap[KEY_GRAVE] = ImGuiKey_GraveAccent;
|
||||
RaylibKeyMap[KEY_KP_0] = ImGuiKey_Keypad0;
|
||||
RaylibKeyMap[KEY_KP_1] = ImGuiKey_Keypad1;
|
||||
RaylibKeyMap[KEY_KP_2] = ImGuiKey_Keypad2;
|
||||
RaylibKeyMap[KEY_KP_3] = ImGuiKey_Keypad3;
|
||||
RaylibKeyMap[KEY_KP_4] = ImGuiKey_Keypad4;
|
||||
RaylibKeyMap[KEY_KP_5] = ImGuiKey_Keypad5;
|
||||
RaylibKeyMap[KEY_KP_6] = ImGuiKey_Keypad6;
|
||||
RaylibKeyMap[KEY_KP_7] = ImGuiKey_Keypad7;
|
||||
RaylibKeyMap[KEY_KP_8] = ImGuiKey_Keypad8;
|
||||
RaylibKeyMap[KEY_KP_9] = ImGuiKey_Keypad9;
|
||||
RaylibKeyMap[KEY_KP_DECIMAL] = ImGuiKey_KeypadDecimal;
|
||||
RaylibKeyMap[KEY_KP_DIVIDE] = ImGuiKey_KeypadDivide;
|
||||
RaylibKeyMap[KEY_KP_MULTIPLY] = ImGuiKey_KeypadMultiply;
|
||||
RaylibKeyMap[KEY_KP_SUBTRACT] = ImGuiKey_KeypadSubtract;
|
||||
RaylibKeyMap[KEY_KP_ADD] = ImGuiKey_KeypadAdd;
|
||||
RaylibKeyMap[KEY_KP_ENTER] = ImGuiKey_KeypadEnter;
|
||||
RaylibKeyMap[KEY_KP_EQUAL] = ImGuiKey_KeypadEqual;
|
||||
}
|
||||
|
||||
static void SetupGlobals()
|
||||
{
|
||||
LastFrameFocused = IsWindowFocused();
|
||||
LastControlPressed = false;
|
||||
LastShiftPressed = false;
|
||||
LastAltPressed = false;
|
||||
LastSuperPressed = false;
|
||||
|
||||
}
|
||||
|
||||
void rlImGuiBeginInitImGui()
|
||||
{
|
||||
SetupGlobals();
|
||||
GlobalContext = ImGui::CreateContext(nullptr);
|
||||
SetupKeymap();
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.Fonts->AddFontDefault();
|
||||
}
|
||||
|
||||
void rlImGuiSetup(bool dark)
|
||||
{
|
||||
rlImGuiBeginInitImGui();
|
||||
|
||||
if (dark)
|
||||
ImGui::StyleColorsDark();
|
||||
else
|
||||
ImGui::StyleColorsLight();
|
||||
|
||||
rlImGuiEndInitImGui();
|
||||
}
|
||||
|
||||
void rlImGuiReloadFonts()
|
||||
{
|
||||
ImGui::SetCurrentContext(GlobalContext);
|
||||
|
||||
ReloadFonts();
|
||||
}
|
||||
|
||||
void rlImGuiBegin()
|
||||
{
|
||||
ImGui::SetCurrentContext(GlobalContext);
|
||||
rlImGuiBeginDelta(GetFrameTime());
|
||||
}
|
||||
|
||||
void rlImGuiBeginDelta(float deltaTime)
|
||||
{
|
||||
ImGui::SetCurrentContext(GlobalContext);
|
||||
ImGuiNewFrame(deltaTime);
|
||||
ImGui_ImplRaylib_ProcessEvents();
|
||||
ImGui::NewFrame();
|
||||
}
|
||||
|
||||
void rlImGuiEnd()
|
||||
{
|
||||
ImGui::SetCurrentContext(GlobalContext);
|
||||
ImGui::Render();
|
||||
ImGui_ImplRaylib_RenderDrawData(ImGui::GetDrawData());
|
||||
}
|
||||
|
||||
void rlImGuiShutdown()
|
||||
{
|
||||
ImGui::SetCurrentContext(GlobalContext);
|
||||
ImGui_ImplRaylib_Shutdown();
|
||||
|
||||
ImGui::DestroyContext();
|
||||
}
|
||||
|
||||
void rlImGuiImage(const Texture* image)
|
||||
{
|
||||
if (!image)
|
||||
return;
|
||||
if (GlobalContext)
|
||||
ImGui::SetCurrentContext(GlobalContext);
|
||||
ImGui::Image((ImTextureID)image, ImVec2(float(image->width), float(image->height)));
|
||||
}
|
||||
|
||||
bool rlImGuiImageButton(const char* name, const Texture* image)
|
||||
{
|
||||
if (!image)
|
||||
return false;
|
||||
if (GlobalContext)
|
||||
ImGui::SetCurrentContext(GlobalContext);
|
||||
return ImGui::ImageButton(name, (ImTextureID)image, ImVec2(float(image->width), float(image->height)));
|
||||
}
|
||||
|
||||
bool rlImGuiImageButtonSize(const char* name, const Texture* image, ImVec2 size)
|
||||
{
|
||||
if (!image)
|
||||
return false;
|
||||
if (GlobalContext)
|
||||
ImGui::SetCurrentContext(GlobalContext);
|
||||
return ImGui::ImageButton(name, (ImTextureID)image, size);
|
||||
}
|
||||
|
||||
void rlImGuiImageSize(const Texture* image, int width, int height)
|
||||
{
|
||||
if (!image)
|
||||
return;
|
||||
if (GlobalContext)
|
||||
ImGui::SetCurrentContext(GlobalContext);
|
||||
ImGui::Image((ImTextureID)image, ImVec2(float(width), float(height)));
|
||||
}
|
||||
|
||||
void rlImGuiImageSizeV(const Texture* image, Vector2 size)
|
||||
{
|
||||
if (!image)
|
||||
return;
|
||||
if (GlobalContext)
|
||||
ImGui::SetCurrentContext(GlobalContext);
|
||||
ImGui::Image((ImTextureID)image, ImVec2(size.x, size.y));
|
||||
}
|
||||
|
||||
void rlImGuiImageRect(const Texture* image, int destWidth, int destHeight, Rectangle sourceRect)
|
||||
{
|
||||
if (!image)
|
||||
return;
|
||||
if (GlobalContext)
|
||||
ImGui::SetCurrentContext(GlobalContext);
|
||||
ImVec2 uv0;
|
||||
ImVec2 uv1;
|
||||
|
||||
if (sourceRect.width < 0)
|
||||
{
|
||||
uv0.x = -((float)sourceRect.x / image->width);
|
||||
uv1.x = (uv0.x - (float)(fabs(sourceRect.width) / image->width));
|
||||
}
|
||||
else
|
||||
{
|
||||
uv0.x = (float)sourceRect.x / image->width;
|
||||
uv1.x = uv0.x + (float)(sourceRect.width / image->width);
|
||||
}
|
||||
|
||||
if (sourceRect.height < 0)
|
||||
{
|
||||
uv0.y = -((float)sourceRect.y / image->height);
|
||||
uv1.y = (uv0.y - (float)(fabs(sourceRect.height) / image->height));
|
||||
}
|
||||
else
|
||||
{
|
||||
uv0.y = (float)sourceRect.y / image->height;
|
||||
uv1.y = uv0.y + (float)(sourceRect.height / image->height);
|
||||
}
|
||||
|
||||
ImGui::Image((ImTextureID)image, ImVec2(float(destWidth), float(destHeight)), uv0, uv1);
|
||||
}
|
||||
|
||||
void rlImGuiImageRenderTexture(const RenderTexture* image)
|
||||
{
|
||||
if (!image)
|
||||
return;
|
||||
if (GlobalContext)
|
||||
ImGui::SetCurrentContext(GlobalContext);
|
||||
rlImGuiImageRect(&image->texture, image->texture.width, image->texture.height, Rectangle{ 0,0, float(image->texture.width), -float(image->texture.height) });
|
||||
}
|
||||
|
||||
void rlImGuiImageRenderTextureFit(const RenderTexture* image, bool center)
|
||||
{
|
||||
if (!image)
|
||||
return;
|
||||
if (GlobalContext)
|
||||
ImGui::SetCurrentContext(GlobalContext);
|
||||
|
||||
ImVec2 area = ImGui::GetContentRegionAvail();
|
||||
|
||||
float scale = area.x / image->texture.width;
|
||||
|
||||
float y = image->texture.height * scale;
|
||||
if (y > area.y)
|
||||
{
|
||||
scale = area.y / image->texture.height;
|
||||
}
|
||||
|
||||
int sizeX = int(image->texture.width * scale);
|
||||
int sizeY = int(image->texture.height * scale);
|
||||
|
||||
if (center)
|
||||
{
|
||||
ImGui::SetCursorPosX(0);
|
||||
ImGui::SetCursorPosX(area.x/2 - sizeX/2);
|
||||
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + (area.y / 2 - sizeY / 2));
|
||||
}
|
||||
|
||||
rlImGuiImageRect(&image->texture, sizeX, sizeY, Rectangle{ 0,0, float(image->texture.width), -float(image->texture.height) });
|
||||
}
|
||||
|
||||
// raw ImGui backend API
|
||||
bool ImGui_ImplRaylib_Init()
|
||||
{
|
||||
SetupGlobals();
|
||||
|
||||
SetupKeymap();
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.Fonts->AddFontDefault();
|
||||
|
||||
SetupFontAwesome();
|
||||
|
||||
SetupMouseCursors();
|
||||
|
||||
SetupBackend();
|
||||
|
||||
ReloadFonts();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ImGui_ImplRaylib_Shutdown()
|
||||
{
|
||||
ImGuiIO& io =ImGui::GetIO();
|
||||
Texture2D* fontTexture = (Texture2D*)io.Fonts->TexID;
|
||||
|
||||
if (fontTexture && fontTexture->id != 0)
|
||||
UnloadTexture(*fontTexture);
|
||||
|
||||
io.Fonts->TexID = 0;
|
||||
}
|
||||
|
||||
void ImGui_ImplRaylib_NewFrame()
|
||||
{
|
||||
ImGuiNewFrame(GetFrameTime());
|
||||
}
|
||||
|
||||
void ImGui_ImplRaylib_RenderDrawData(ImDrawData* draw_data)
|
||||
{
|
||||
rlDrawRenderBatchActive();
|
||||
rlDisableBackfaceCulling();
|
||||
|
||||
for (int l = 0; l < draw_data->CmdListsCount; ++l)
|
||||
{
|
||||
const ImDrawList* commandList = draw_data->CmdLists[l];
|
||||
|
||||
for (const auto& cmd : commandList->CmdBuffer)
|
||||
{
|
||||
EnableScissor(cmd.ClipRect.x - draw_data->DisplayPos.x, cmd.ClipRect.y - draw_data->DisplayPos.y, cmd.ClipRect.z - (cmd.ClipRect.x - draw_data->DisplayPos.x), cmd.ClipRect.w - (cmd.ClipRect.y - draw_data->DisplayPos.y));
|
||||
if (cmd.UserCallback != nullptr)
|
||||
{
|
||||
cmd.UserCallback(commandList, &cmd);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
ImGuiRenderTriangles(cmd.ElemCount, cmd.IdxOffset, commandList->IdxBuffer, commandList->VtxBuffer, cmd.TextureId);
|
||||
rlDrawRenderBatchActive();
|
||||
}
|
||||
}
|
||||
|
||||
rlSetTexture(0);
|
||||
rlDisableScissorTest();
|
||||
rlEnableBackfaceCulling();
|
||||
}
|
||||
|
||||
bool ImGui_ImplRaylib_ProcessEvents()
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
bool focused = IsWindowFocused();
|
||||
if (focused != LastFrameFocused)
|
||||
io.AddFocusEvent(focused);
|
||||
LastFrameFocused = focused;
|
||||
|
||||
// handle the modifyer key events so that shortcuts work
|
||||
bool ctrlDown = rlImGuiIsControlDown();
|
||||
if (ctrlDown != LastControlPressed)
|
||||
io.AddKeyEvent(ImGuiMod_Ctrl, ctrlDown);
|
||||
LastControlPressed = ctrlDown;
|
||||
|
||||
bool shiftDown = rlImGuiIsShiftDown();
|
||||
if (shiftDown != LastShiftPressed)
|
||||
io.AddKeyEvent(ImGuiMod_Shift, shiftDown);
|
||||
LastShiftPressed = shiftDown;
|
||||
|
||||
bool altDown = rlImGuiIsAltDown();
|
||||
if (altDown != LastAltPressed)
|
||||
io.AddKeyEvent(ImGuiMod_Alt, altDown);
|
||||
LastAltPressed = altDown;
|
||||
|
||||
bool superDown = rlImGuiIsSuperDown();
|
||||
if (superDown != LastSuperPressed)
|
||||
io.AddKeyEvent(ImGuiMod_Super, superDown);
|
||||
LastSuperPressed = superDown;
|
||||
|
||||
// get the pressed keys, they are in event order
|
||||
int keyId = GetKeyPressed();
|
||||
while (keyId != 0)
|
||||
{
|
||||
auto keyItr = RaylibKeyMap.find(KeyboardKey(keyId));
|
||||
if (keyItr != RaylibKeyMap.end())
|
||||
io.AddKeyEvent(keyItr->second, true);
|
||||
keyId = GetKeyPressed();
|
||||
}
|
||||
|
||||
// look for any keys that were down last frame and see if they were down and are released
|
||||
for (const auto keyItr : RaylibKeyMap)
|
||||
{
|
||||
if (IsKeyReleased(keyItr.first))
|
||||
io.AddKeyEvent(keyItr.second, false);
|
||||
}
|
||||
|
||||
// add the text input in order
|
||||
unsigned int pressed = GetCharPressed();
|
||||
while (pressed != 0)
|
||||
{
|
||||
io.AddInputCharacter(pressed);
|
||||
pressed = GetCharPressed();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -31,7 +31,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "raylib.h"
|
||||
#define CIMGUI_DEFINE_ENUMS_AND_STRUCTS
|
||||
#include "cimgui.h"
|
||||
|
||||
#define NO_FONT_AWESOME
|
||||
#ifndef NO_FONT_AWESOME
|
||||
#include "extras/IconsFontAwesome6.h"
|
||||
#define FONT_AWESOME_ICON_SIZE 11
|
||||
@@ -169,7 +172,7 @@ bool rlImGuiImageButton(const char* name, const Texture* image);
|
||||
/// <param name="image">The texture to draw</param>
|
||||
/// <param name="size">The size of the button/param>
|
||||
/// <returns>True if the button was clicked</returns>
|
||||
bool rlImGuiImageButtonSize(const char* name, const Texture* image, struct ImVec2 size);
|
||||
bool rlImGuiImageButtonSize(const char* name, const Texture* image, ImVec2 size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user