This commit is contained in:
IXtreme 2025-06-14 03:10:55 -04:00
commit c7e92a159b
39 changed files with 9740 additions and 0 deletions

61
Makefile Normal file
View file

@ -0,0 +1,61 @@
CC = gcc
CXX = g++
ASSET_PREFIX = assets/
SRC_DIR = src
OBJ_DIR = obj
BIN_DIR = bin
LIB_DIR = lib
CPPFLAGS = -O3 -Iinclude -Isrc/imgui -g -D ASSET_DIR=\"$(ASSET_PREFIX)\"
CFLAGS = -O3 -g -Iinclude -D ASSET_DIR=\"$(ASSET_PREFIX)\"
LDFLAGS = -O3 -g
#global LDLIBS
LDLIBS += -L lib/
#LDLIBS += -L lib_web/
LDLIBS += -limgui -l:libraylib.a -lraylib -lsdbus-c++ -lmagic -lcurl #only enable if dynamic mode
LD_STATIC_LIBS = -l:libraylib.a #only enable if static mode
EXTRA_DIRS = $(OBJ_DIR)/rlImGui
EXE = $(BIN_DIR)/main
C_SRC += $(wildcard $(SRC_DIR)/*.c) #GET LIST OF ALL C FILES
CPP_SRC += $(wildcard $(SRC_DIR)/*.cpp) #GET LIST OF ALL CPP FILES
CPP_SRC += $(wildcard $(SRC_DIR)/rlImGui/*.cpp) #GET LIST OF ALL CPP FILES
C_OBJ := $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(C_SRC)) #MAKE LIST OF ALL C OBJECT FILES THAT NEED TO BE BUILT
CPP_OBJ := $(patsubst $(SRC_DIR)/%.cpp, $(OBJ_DIR)/%.o, $(CPP_SRC)) #MAKE LIST OF ALL CPP OBJECT FILES THAT NEED TO BE BUILT
OBJ := $(C_OBJ) $(CPP_OBJ)
all: $(EXE)
$(EXE): $(OBJ) | $(BIN_DIR)
$(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $@
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
$(CC) $(CFLAGS) -c $< -o $@
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp | $(OBJ_DIR)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
$(BIN_DIR) $(OBJ_DIR): | $(EXTRA_DIRS)
mkdir -p $@
$(EXTRA_DIRS):
mkdir -p $@
clean:
@$(RM) -rv $(BIN_DIR) $(OBJ_DIR)
.PHONY: all clean

73
compile_commands.json Normal file
View file

@ -0,0 +1,73 @@
[
{
"arguments": [
"/sbin/g++",
"-O3",
"-Iinclude",
"-Isrc/imgui",
"-g",
"-D",
"ASSET_DIR=\"assets/\"",
"-c",
"-o",
"obj/rlImGui/rlImGui.o",
"src/rlImGui/rlImGui.cpp"
],
"directory": "/home/inventorx/projects/shooter",
"file": "/home/inventorx/projects/shooter/src/rlImGui/rlImGui.cpp",
"output": "/home/inventorx/projects/shooter/obj/rlImGui/rlImGui.o"
},
{
"arguments": [
"/sbin/g++",
"-O3",
"-Iinclude",
"-Isrc/imgui",
"-g",
"-D",
"ASSET_DIR=\"assets/\"",
"-c",
"-o",
"obj/main.o",
"src/main.cpp"
],
"directory": "/home/inventorx/projects/shooter",
"file": "/home/inventorx/projects/shooter/src/main.cpp",
"output": "/home/inventorx/projects/shooter/obj/main.o"
},
{
"arguments": [
"/sbin/gcc",
"-O3",
"-g",
"-Iinclude",
"-D",
"ASSET_DIR=\"assets/\"",
"-c",
"-o",
"obj/testc.o",
"src/testc.c"
],
"directory": "/home/inventorx/projects/shooter",
"file": "/home/inventorx/projects/shooter/src/testc.c",
"output": "/home/inventorx/projects/shooter/obj/testc.o"
},
{
"arguments": [
"/sbin/g++",
"-O3",
"-Iinclude",
"-Isrc/imgui",
"-g",
"-D",
"ASSET_DIR=\"assets/\"",
"-c",
"-o",
"obj/testcpp.o",
"src/testcpp.cpp"
],
"directory": "/home/inventorx/projects/shooter",
"file": "/home/inventorx/projects/shooter/src/testcpp.cpp",
"output": "/home/inventorx/projects/shooter/obj/testcpp.o"
}
]

1
include/raylib-cpp Submodule

@ -0,0 +1 @@
Subproject commit 8e01c1dd8fbbe12199fc1256c3bc801d5745ad48

BIN
lib/libraylib.a Normal file

Binary file not shown.

230
src/main.cpp Normal file
View file

@ -0,0 +1,230 @@
#include "raylib-cpp/include/Camera3D.hpp"
#include "raylib-cpp/include/Rectangle.hpp"
#include "raylib-cpp/include/RenderTexture.hpp"
#include "raylib-cpp/include/Vector3.hpp"
#include <cmath>
#include <cstdio>
#include <iostream>
#include <ostream>
#define IMGUI_DEFINE_MATH_OPERATORS
#include "imgui.h"
#include "imgui_stdlib.h"
#include "raylib.h"
#include "raymath.h"
#include "rlImGui/rlImGui.h"
#include "rlgl.h"
#include "testcpp.hpp"
#include <raylib-cpp/include/raylib-cpp.hpp>
#include <rlgl.h>
#include <sdbus-c++/sdbus-c++.h>
namespace rl = raylib;
extern "C" {
#include "testc.h"
}
class RayWindow {
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 RayWindowExample {
public:
RenderTexture ViewTexture;
bool Open = true;
bool Focused = false;
bool Resized = false;
ImVec2 PastSize;
RayWindowExample() {
ViewTexture = LoadRenderTexture(GetScreenWidth(), GetScreenWidth());
// ViewTexture = LoadRenderTexture(256, 256);
printf("window w,h: %d, %d \n", ViewTexture.texture.width, ViewTexture.texture.height);
PastSize = ImVec2{256, 256};
Resized = false;
}
~RayWindowExample() {
UnloadRenderTexture(ViewTexture);
}
void Show() {
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
ImGui::SetNextWindowSize(ImVec2(256, 275), ImGuiCond_FirstUseEver);
if (ImGui::Begin("Raylib in ImGUI", &Open, ImGuiWindowFlags_NoScrollbar)) {
Focused = ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows);
ImVec2 DaZone = ImGui::GetContentRegionAvail();
rlImGuiImageRenderTexture(&ViewTexture);
// rlImGuiImage(&ViewTexture.texture);
if (PastSize != DaZone) {
Resized = true;
} else {
Resized = false;
}
PastSize = DaZone;
}
ImGui::End();
ImGui::PopStyleVar();
}
void Update() {
if (!Open) {
return;
}
if (Resized) {
UnloadRenderTexture(ViewTexture);
ViewTexture = LoadRenderTexture(PastSize.x, PastSize.y);
}
BeginTextureMode(ViewTexture);
ClearBackground(SKYBLUE);
DrawCircle(0, 0, 35, RED);
// DrawPixel(0,0, BLUE);
// DrawRectangleLines(0,0,PastSize.x,PastSize.y, RED);
Rectangle rec = Rectangle{0, 0, PastSize.x, PastSize.y};
// DrawRectangleLinesEx(rec, 2, RED);
EndTextureMode();
}
};
std::ostream &operator<<(std::ostream &os, const Vector3 &obj) {
os << "x: " << obj.x << " y: " << obj.y << " z: " << obj.z;
return os;
}
std::ostream &operator<<(std::ostream &os, const Vector2 &obj) {
os << "x: " << obj.x << " y: " << obj.y;
return os;
}
struct Player {
raylib::Camera3D cam;
rl::Vector3 accel;
rl::Vector3 velocity;
rl::Vector3 pos;
rl::Vector3 target;
Player() : cam((Vector3){0, 0, 0}) {
target = (Vector3){0, 0, -10};
//
}
void KeyControl() {
rl::Vector3 forward = (rl::Vector3)target;
rl::Vector3 left = Vector3RotateByAxisAngle(forward, cam.GetUp(), M_PI_2);
if (IsKeyDown(KEY_W)) {
accel += forward;
}
if (IsKeyDown(KEY_S)) {
accel += -forward;
}
if (IsKeyDown(KEY_A)) {
accel += left;
}
if (IsKeyDown(KEY_D)) {
accel += -left;
}
target = Vector3RotateByAxisAngle(target, (Vector3){0, 1, 0},
-GetMouseDelta().x * 0.02 * DEG2RAD);
// std::cout << GetMouseDelta() << std::endl;
}
void UpdatePhysics() {
velocity += accel * GetFrameTime() * 0.5f;
pos += velocity * GetFrameTime();
velocity += accel * GetFrameTime() * 0.5f;
accel = Vector3Zero();
cam.SetPosition(pos);
cam.SetTarget(pos + target);
}
};
int main(int argc, char *argv[]) {
// Initialization
//--------------------------------------------------------------------------------------
int screenWidth = 800;
int screenHeight = 800;
// SetConfigFlags(FLAG_MSAA_4X_HINT | FLAG_WINDOW_RESIZABLE);
// SetConfigFlags(FLAG_MSAA_4X_HINT | FLAG_VSYNC_HINT | FLAG_WINDOW_RESIZABLE);
// SetConfigFlags(FLAG_MSAA_4X_HINT | FLAG_WINDOW_RESIZABLE);
raylib::Window window(screenWidth, screenHeight, "shooter",
FLAG_MSAA_4X_HINT | FLAG_WINDOW_RESIZABLE);
window.SetTargetFPS(244);
rlImGuiSetup(true);
DisableCursor();
ImGui::GetStyle().AntiAliasedLinesUseTex = false;
// SetWindowState(FLAG_WINDOW_UNDECORATED);
TestC();
TestCPPFunc();
raylib::RenderTexture outputTexture(screenWidth, screenHeight);
bool run = true;
bool showIMgui = false;
bool showDemoWindow = true;
Player user;
while (!window.ShouldClose()) // Detect window close button or ESC key, or a quit from the menu
{
if (IsWindowResized()) {
outputTexture = raylib::RenderTexture(window.GetWidth(), window.GetHeight());
}
// user.cam.Update((Vector3){
// (IsKeyDown(KEY_W) || IsKeyDown(KEY_UP))*0.1f - // Move forward-backward
// (IsKeyDown(KEY_S) || IsKeyDown(KEY_DOWN))*0.1f,
// (IsKeyDown(KEY_D) || IsKeyDown(KEY_RIGHT))*0.1f - // Move right-left
// (IsKeyDown(KEY_A) || IsKeyDown(KEY_LEFT))*0.1f,
// 0.0f // Move up-down
// },
// (Vector3){
// GetMouseDelta().x*0.05f, // Rotation: yaw
// GetMouseDelta().y*0.05f, // Rotation: pitch
// 0.0f // Rotation: roll
// },
// GetMouseWheelMove()*2.0f); // Move to target (zoom)
user.KeyControl();
user.UpdatePhysics();
outputTexture.BeginMode();
ClearBackground(BLACK);
user.cam.BeginMode();
DrawSphere((Vector3){0, 0, -300}, 20, RED);
user.cam.EndMode();
outputTexture.EndMode();
window.BeginDrawing();
DrawTexturePro(outputTexture.texture,
(Rectangle){0, 0, static_cast<float>(outputTexture.texture.width),
static_cast<float>(-outputTexture.texture.height)},
(Rectangle){0, 0, static_cast<float>(window.GetWidth()),
static_cast<float>(window.GetHeight())},
(Vector2){0, 0}, 0, WHITE);
window.EndDrawing();
//----------------------------------------------------------------------------------
}
rlImGuiShutdown();
// De-Initialization
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
return 0;
}

68
src/mpris_connection.hpp Normal file
View file

@ -0,0 +1,68 @@
#ifndef COURSE_H
#define COURSE_H
#include <sdbus-c++/Types.h>
#include <unordered_map>
#define IMGUI_DEFINE_MATH_OPERATORS
#include <imgui.h>
#include <memory>
#include <raylib.h>
#include <sdbus-c++/IConnection.h>
#include <sdbus-c++/IProxy.h>
#include <string>
#include "cpp/quantize/celebi.h"
class RayTexture {
public:
Texture tex{};
std::string path;
RayTexture();
explicit RayTexture(Image img);
RayTexture(const RayTexture& other);
RayTexture& operator=(const RayTexture& other);
~RayTexture();
};
class DiscObject {
public:
float prevouspos;
float pos;
float velo;
float accel;
float target;
bool active;
bool enabled;
DiscObject(float ia);
void UpdatePos(float dtime);
void UpdatePos(float pos, float dtime);
void AddAccel(float ac);
void Activate();
};
class MprisPlayer {
public:
std::unique_ptr<sdbus::IConnection> bus_connection;
std::unique_ptr<sdbus::IProxy> PlayerProxy;
sdbus::InterfaceName mp2;
sdbus::MethodName playpause;
RayTexture tex;
std::vector<Color> accent_colors;
std::string image_path_cache;
long imagecount;
explicit MprisPlayer(std::string servicename);
void PausePlay();
void Refresh();
void UpdateTexture();
void Next();
void Prev();
std::string identity;
std::string playstate;
std::string GetIdentity();
std::unordered_map<std::string, sdbus::Variant> current_metadata;
std::unordered_map<std::string, sdbus::Variant> GetCurrentMetadata();
Color GetPrimaryColor();
};
#endif

16
src/rlImGui/LICENSE Normal file
View file

@ -0,0 +1,16 @@
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.

75
src/rlImGui/README.md Normal file
View file

@ -0,0 +1,75 @@
# 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.
![image](https://user-images.githubusercontent.com/322174/136596910-da1b60ae-4a39-48f0-ae84-f568bc396870.png)
## 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.
![image](https://user-images.githubusercontent.com/322174/136596949-033ffe0a-2476-4030-988a-5bf5b6e2ade7.png)
# 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

View file

@ -0,0 +1,280 @@
/*******************************************************************************************
*
* raylib-extras [ImGui] example - asset browser
*
* 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) 2024 Jeffery Myers
*
********************************************************************************************/
#define _CRT_NONSTDC_NO_WARNINGS
#include "asset_browser.h"
#include "imgui_utils.h"
#include "imgui.h"
#include "imgui_internal.h"
#include "raylib.h"
#include "extras/IconsFontAwesome6.h"
#include <algorithm>
AssetBrowserPanel::AssetBrowserPanel()
{
AssetRoot = GetWorkingDirectory();
RebuildFolderTree();
SetCurrentFolder(&FolderRoot);
CurrentView = &ListView;
}
void AssetBrowserPanel::Show()
{
ShowHeader();
ImGuiTableFlags flags = ImGuiTableFlags_Resizable | ImGuiTableFlags_SizingStretchSame | ImGuiTableFlags_Borders;
if (ImGui::BeginTable("AssetBrowserTab", 2, flags, ImGui::GetContentRegionAvail()))
{
ImGui::TableSetupColumn("FolderView", ImGuiTableColumnFlags_None, 0.25f);
ImGui::TableSetupColumn("AssetView", ImGuiTableColumnFlags_None, 0.75f);
ImGui::TableNextRow();
ImGui::TableNextColumn();
if (ImGui::BeginChild("FolderList", ImGui::GetContentRegionAvail(),ImGuiChildFlags_None, ImGuiWindowFlags_None))
{
ShowFolderTree();
ImGui::EndChild();
}
ImGui::TableNextColumn();
ShowFilePane();
ImGui::EndTable();
}
}
void AssetBrowserPanel::RebuildFolderTree()
{
FolderRoot.Children.clear();
FolderRoot.FullPath = AssetRoot;
FolderRoot.Name = GetFileNameWithoutExt(AssetRoot.c_str());
FolderRoot.Parent = nullptr;
FolderRoot.Icon = ICON_FA_SERVER;
FolderRoot.ForceOpenNextFrame = true;
FolderRoot.PopulateChildren();
}
void AssetBrowserPanel::SetCurrentFolder(FolderInfo* folder)
{
if (CurrentFolderContents.Folder == folder)
return;
CurrentFolderContents.Folder = folder;
CurrentFolderContents.Files.clear();
if (folder == nullptr)
return;
FolderInfo* openFolder = folder;
while (openFolder != nullptr)
{
openFolder->ForceOpenNextFrame = true;
openFolder = openFolder->Parent;
}
auto files = LoadDirectoryFiles(CurrentFolderContents.Folder->FullPath.c_str());
for (unsigned int i = 0; i < files.count; i++)
{
if (DirectoryExists(files.paths[i]))
continue;
const char* name = GetFileName(files.paths[i]);
if (!name || *name == '.')
continue;
FileInfo& file = CurrentFolderContents.Files.emplace_back();
file.FullPath = files.paths[i];
file.Name = name;
file.Icon = GetFileIcon(name);
}
UnloadDirectoryFiles(files);
}
void AssetBrowserPanel::FolderInfo::PopulateChildren()
{
constexpr Color folderColor = { 255,255,145,255 };
auto folders = LoadDirectoryFiles(FullPath.c_str());
for (unsigned int i = 0; i < folders.count; i++)
{
if (DirectoryExists(folders.paths[i]))
{
const char* name = GetFileNameWithoutExt(folders.paths[i]);
if (!name || *name == '.')
continue;
FolderInfo& child = Children.emplace_back();
child.FullPath = folders.paths[i];
child.Name = name;
child.Parent = this;
child.Tint = folderColor;
child.Icon = ICON_FA_FOLDER;
child.PopulateChildren();
}
}
UnloadDirectoryFiles(folders);
}
bool AssetBrowserPanel::ShowFolderTreeNode(FolderInfo& info)
{
ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick;
if (info.Children.empty())
flags |= ImGuiTreeNodeFlags_Leaf;
if (CurrentFolderContents.Folder == &info)
flags |= ImGuiTreeNodeFlags_Selected;
if (info.ForceOpenNextFrame)
{
ImGui::SetNextItemOpen(true);
}
bool open = ImGui::TreeNodeEx(info.Name.c_str(), flags, "%s %s", info.Icon.c_str(), info.Name.c_str());
if (info.ForceOpenNextFrame && CurrentFolderContents.Folder == &info)
ImGui::ScrollToItem(ImGuiScrollFlags_KeepVisibleCenterY);
info.ForceOpenNextFrame = false;
if (ImGui::IsItemClicked())
SetCurrentFolder(&info);
if (open)
{
for (auto& node : info.Children)
ShowFolderTreeNode(node);
ImGui::TreePop();
}
return CurrentFolderContents.Folder == &info;
}
void AssetBrowserPanel::ShowHeader()
{
ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 1);
if (ImGui::BeginChild("Header", ImVec2{ ImGui::GetContentRegionAvail().x, ImGui::GetFrameHeight() }))
{
ImGui::Text("%s Root", ICON_FA_FOLDER_OPEN);
ImGui::SameLine();
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x * 0.33f);
ImGui::InputText("###Path", (char*)(CurrentFolderContents.Folder->FullPath.c_str() + AssetRoot.size()), CurrentFolderContents.Folder->FullPath.size(), ImGuiInputTextFlags_ReadOnly);
ImGui::EndChild();
}
ImGui::PopStyleVar();
}
void AssetBrowserPanel::ShowFolderTree()
{
ShowFolderTreeNode(FolderRoot);
}
void AssetBrowserPanel::ShowFilePane()
{
if (ImGui::BeginChild("FileList", ImGui::GetContentRegionAvail(), ImGuiChildFlags_None, ImGuiWindowFlags_None))
{
if (CurrentView)
{
auto *item = CurrentView->Show(CurrentFolderContents);
if (item)
{
AssetItemInfo* assetItem = static_cast<AssetItemInfo*>(item);
if (!assetItem->IsFile())
SetCurrentFolder(static_cast<FolderInfo*>(item));
}
}
ImGui::EndChild();
}
}
ViewableItem* AssetBrowserPanel::AssetContainer::Reset()
{
FileItr = Files.begin();
FolderItr = Folder->Children.begin();
if (FileItr != Files.end())
return &(*FileItr);
if (FolderItr != Folder->Children.end())
return &(*FolderItr);
return nullptr;
}
size_t AssetBrowserPanel::AssetContainer::Count()
{
return Files.size() + Folder->Children.size();
}
ViewableItem* AssetBrowserPanel::AssetContainer::Next()
{
if (FileItr != Files.end())
{
FileItr++;
if (FileItr != Files.end())
return &(*FileItr);
else
{
if (FolderItr != Folder->Children.end())
return &(*FolderItr);
else
return nullptr;
}
}
if (FolderItr != Folder->Children.end())
{
FolderItr++;
if (FolderItr != Folder->Children.end())
return &(*FolderItr);
}
return nullptr;
}
const char* AssetBrowserPanel::GetFileIcon(const char* filename)
{
const char* e = GetFileExtension(filename);
if (e == nullptr)
return ICON_FA_FILE;
std::string ext = e;
std::transform(ext.begin(), ext.end(), ext.begin(),
[](unsigned char c) { return std::tolower(c); } // correct
);
if (!ext.empty())
{
if (ext==".png")
return ICON_FA_FILE_IMAGE;
if (ext==".wav" || ext==".mp3" || ext==".oog")
return ICON_FA_FILE_AUDIO;
if (ext==".ttf" || ext==".otf" || ext==".fnt")
return ICON_FA_FONT;
if (ext==".txt" || ext==".md")
return ICON_FA_FILE_LINES;
if (ext==".lua" || ext==".c" || ext==".h" || ext==".cpp")
return ICON_FA_FILE_CODE;
}
return ICON_FA_FILE;
}

View file

@ -0,0 +1,95 @@
/*******************************************************************************************
*
* raylib-extras [ImGui] example - asset browser
*
* 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) 2024 Jeffery Myers
*
********************************************************************************************/
#pragma once
#include "item_view.h"
#include "raylib.h"
#include <string>
#include <vector>
#include <list>
class AssetBrowserPanel
{
public:
AssetBrowserPanel();
void Show();
private:
std::string AssetRoot;
class AssetItemInfo : public ViewableItem
{
protected:
bool File = false;
public:
AssetItemInfo(bool file) : File(file) {}
bool IsFile() const { return File; }
};
class FileInfo : public AssetItemInfo
{
public:
FileInfo() : AssetItemInfo(true) {}
std::string FullPath;
};
class FolderInfo : public AssetItemInfo
{
public:
FolderInfo() : AssetItemInfo(false) {}
std::string FullPath;
FolderInfo* Parent = nullptr;
std::list<FolderInfo> Children;
bool ForceOpenNextFrame = false;
void PopulateChildren();
};
FolderInfo FolderRoot;
class AssetContainer : public ViewableItemContainer
{
public:
ViewableItem* Reset() override;
size_t Count() override;
ViewableItem* Next() override;
FolderInfo* Folder = nullptr;
std::vector<FileInfo> Files;
std::vector<FileInfo>::iterator FileItr;
std::list<FolderInfo>::iterator FolderItr;
};
AssetContainer CurrentFolderContents;
ListItemView ListView;
ItemView* CurrentView = nullptr;
void RebuildFolderTree();
void SetCurrentFolder(FolderInfo* folder);
bool ShowFolderTreeNode(FolderInfo& folder);
void ShowFolderTree();
void ShowFilePane();
void ShowHeader();
const char* GetFileIcon(const char* filename);
};

View file

@ -0,0 +1,94 @@
/*******************************************************************************************
*
* raylib-extras [ImGui] example - asset browser
*
* 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) 2024 Jeffery Myers
*
********************************************************************************************/
#include "imgui_utils.h"
#include "imgui.h"
#include "imgui_internal.h"
namespace ImGuiUtils
{
bool IsSpace(char aCharacter)
{
// all space characters are values 32 or less (space is 32)
// so we can convert them to a bitmask and use a single condition
const int mask = (1 << (' ' - 1)) | (1 << ('\f' - 1)) | (1 << ('\n' - 1)) | (1 << ('\r' - 1)) | (1 << ('\t' - 1)) | (1 << ('\v' - 1));
return (mask & (1 << ((aCharacter && aCharacter <= 32) * (aCharacter - 1)))) != 0;
}
//-------------------------------------------------------------------------------------------------
// Todo: Add support for soft-hyphens when using word boundaries?
//-------------------------------------------------------------------------------------------------
void TextWithEllipsis(const char* string, float aMaxWidth, bool useWordBoundaries, float aSpacing)
{
char const* partStart = string;
char const* partEnd = string;
ImWchar elipsisChar = ImGui::GetFont()->EllipsisChar;
char elipsisText[8];
ImTextStrToUtf8(elipsisText, sizeof(elipsisText), &elipsisChar, (&elipsisChar) + 1);
if (aSpacing < 0.0f) aSpacing = ImGui::GetStyle().ItemSpacing.x;
float const ellipsisWidth = ImGui::CalcTextSize(elipsisText).x + aSpacing;
float width = 0;
bool addElipsis = false;
while (*partStart != 0 )
{
// Add space to next segment
while (IsSpace(*partEnd))
partEnd++;
if (useWordBoundaries)
{
// get next 'word' by looking for space after non-space
while (*partEnd != 0 && !IsSpace(*partEnd))
++partEnd;
}
else
{
if (*partEnd != 0)
++partEnd;
}
ImVec2 const wordSize = ImGui::CalcTextSize(partStart, partEnd);
// Clearly we have space for this word so just add it
if (wordSize.x + width + ellipsisWidth < aMaxWidth)
{
width += wordSize.x;
partStart = partEnd;
}
// If we're just at the end of the word and we just fit then we can commit here
else if (*partEnd == 0 && wordSize.x + width < aMaxWidth)
{
width += wordSize.x;
partStart = partEnd;
}
// we're done so add elipsis where the current segment starts
else
{
addElipsis = true;
break;
}
}
ImGui::TextUnformatted(string, partStart);
if (addElipsis)
{
ImGui::SameLine(0.0f, aSpacing);
ImGui::TextUnformatted(elipsisText);
}
}
}

View file

@ -0,0 +1,19 @@
/*******************************************************************************************
*
* raylib-extras [ImGui] example - asset browser
*
* 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) 2024 Jeffery Myers
*
********************************************************************************************/
#pragma once
#include <string>
namespace ImGuiUtils
{
void TextWithEllipsis(const char* string, float maxWidth, bool useWordBoundaries = false, float aSpacing = 0);
}

View file

@ -0,0 +1,47 @@
/*******************************************************************************************
*
* raylib-extras [ImGui] example - asset browser
*
* 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) 2024 Jeffery Myers
*
********************************************************************************************/
#pragma once
#include <string>
#include "raylib.h"
class ViewableItem
{
public:
virtual ~ViewableItem() = default;
std::string Name;
std::string Icon;
Color Tint = BLANK;
};
class ViewableItemContainer
{
public:
virtual ~ViewableItemContainer() = default;
virtual ViewableItem* Reset() = 0;
virtual size_t Count() = 0;
virtual ViewableItem* Next() = 0;
};
class ItemView
{
public:
virtual ~ItemView() = default;
virtual ViewableItem* Show(ViewableItemContainer& container) = 0;
};
class ListItemView : public ItemView
{
public:
ViewableItem* Show(ViewableItemContainer& container) override;
};

View file

@ -0,0 +1,53 @@
/*******************************************************************************************
*
* raylib-extras [ImGui] example - asset browser
*
* 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) 2024 Jeffery Myers
*
********************************************************************************************/
#include "item_view.h"
#include "imgui.h"
#include "imgui_utils.h"
#include "rlImGuiColors.h"
#include "raylib.h"
extern ImFont* IconFont;
ViewableItem* ListItemView::Show(ViewableItemContainer& container)
{
ViewableItem* item = container.Reset();
ViewableItem* selected = nullptr;
while (item)
{
float x = ImGui::GetCursorPosX();
const char* name = TextFormat("###%s", item->Name.c_str());
if (item->Tint.a > 0)
ImGui::TextColored(rlImGuiColors::Convert(item->Tint), " %s", item->Icon.c_str());
else
ImGui::Text(" %s", item->Icon.c_str());
ImGui::SameLine(0, 0);
ImGui::Text(" %s", item->Name.c_str());
ImGui::SameLine(0, 0);
ImGui::SetCursorPosX(x);
//ImGui::SetItemAllowOverlap();
ImGui::Selectable(name);
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(0))
{
selected = item;
}
item = container.Next();
}
return selected;
}

View file

@ -0,0 +1,96 @@
/*******************************************************************************************
*
* raylib-extras [ImGui] example - asset browser
*
* 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) 2024 Jeffery Myers
*
********************************************************************************************/
#include "raylib.h"
#include "raymath.h"
#include "imgui.h"
#include "rlImGui.h"
#include "rlImGuiColors.h"
#include "extras/FA6FreeSolidFontData.h"
#include "asset_browser.h"
#include <limits>
ImFont* IconFont = nullptr;
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 - Asset browser");
SetTargetFPS(144);
rlImGuiBeginInitImGui();
ImGui::StyleColorsDark();
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.GlyphMaxAdvanceX = std::numeric_limits<float>::max();
icons_config.RasterizerMultiply = 1.0f;
icons_config.OversampleH = 2;
icons_config.OversampleV = 1;
icons_config.GlyphRanges = icons_ranges;
ImGuiIO& io = ImGui::GetIO();
io.Fonts->AddFontFromMemoryCompressedTTF((void*)fa_solid_900_compressed_data, fa_solid_900_compressed_size, 12, &icons_config, icons_ranges);
icons_config.MergeMode = false;
IconFont = io.Fonts->AddFontFromMemoryCompressedTTF((void*)fa_solid_900_compressed_data, fa_solid_900_compressed_size, 72, &icons_config, icons_ranges);
rlImGuiEndInitImGui();
AssetBrowserPanel assetBrowser;
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
BeginDrawing();
ClearBackground(DARKGRAY);
rlImGuiBegin();
ImGui::SetNextWindowPos(ImVec2(0, 0));
ImGui::SetNextWindowSize(ImVec2(float(GetScreenWidth()), float(GetScreenHeight())));
if (ImGui::Begin("Frame", 0, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoSavedSettings))
{
assetBrowser.Show();
}
ImGui::End();
rlImGuiEnd();
EndDrawing();
//----------------------------------------------------------------------------------
}
rlImGuiShutdown();
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}

View file

@ -0,0 +1,105 @@
/*******************************************************************************************
*
* raylib-extras [ImGui] example - Docking example
*
* This is an example of using the ImGui docking features that are part of docking branch
* You must replace the default imgui with the code from the docking branch for this to work
* https://github.com/ocornut/imgui/tree/docking
*
* Copyright (c) 2024 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 | FLAG_WINDOW_RESIZABLE | FLAG_WINDOW_HIGHDPI);
InitWindow(screenWidth, screenHeight, "raylib-Extras [ImGui] example - Docking");
SetTargetFPS(144);
rlImGuiSetup(true);
bool run = true;
bool showDemoWindow = true;
// if the linked ImGui has docking, enable it.
// this will only be true if you use the docking branch of ImGui.
#ifdef IMGUI_HAS_DOCK
ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_DockingEnable;
#endif
// Main game loop
while (!WindowShouldClose() && run) // Detect window close button or ESC key, or a quit from the menu
{
BeginDrawing();
ClearBackground(DARKGRAY);
// draw something to the raylib window below the GUI.
DrawCircle(GetScreenWidth() / 2, GetScreenHeight() / 2, GetScreenHeight() * 0.45f, DARKGREEN);
// start ImGui content
rlImGuiBegin();
// if you want windows to dock to the viewport, call this.
#ifdef IMGUI_HAS_DOCK
ImGui::DockSpaceOverViewport(0, NULL, ImGuiDockNodeFlags_PassthruCentralNode); // set ImGuiDockNodeFlags_PassthruCentralNode so that we can see the raylib contents behind the dockspace
#endif
// show a simple menu bar
if (ImGui::BeginMainMenuBar())
{
if (ImGui::BeginMenu("File"))
{
if (ImGui::MenuItem("Quit"))
run = false;
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Window"))
{
if (ImGui::MenuItem("Demo Window", nullptr, showDemoWindow))
showDemoWindow = !showDemoWindow;
ImGui::EndMenu();
}
ImGui::EndMainMenuBar();
}
// show some windows
if (showDemoWindow)
ImGui::ShowDemoWindow(&showDemoWindow);
if (ImGui::Begin("Test Window"))
{
ImGui::TextUnformatted("Another window");
}
ImGui::End();
// end ImGui Content
rlImGuiEnd();
EndDrawing();
//----------------------------------------------------------------------------------
}
rlImGuiShutdown();
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}

View file

@ -0,0 +1,392 @@
/*******************************************************************************************
*
* 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::GetCursorScreenPos().x, ImGui::GetWindowPos().y + ImGui::GetCursorScreenPos().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;
}

View file

@ -0,0 +1,127 @@
// 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("resources/driusstraight.ttf", 18.0f, nullptr, io.Fonts->GetGlyphRangesJapanese());
IM_ASSERT(font != nullptr);
// required to be called to cache the font texture with raylib
ImGui_ImplRaylib_BuildFontAtlas();
// 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;
}

View file

@ -0,0 +1,59 @@
/*******************************************************************************************
*
* 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 | FLAG_WINDOW_RESIZABLE);
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

Some files were not shown because too many files have changed in this diff Show more