first commit
This commit is contained in:
commit
5dfb2b7270
43 changed files with 19712 additions and 0 deletions
101
Makefile
Normal file
101
Makefile
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
#STATIC/DYNAMIC
|
||||
#LIB_MODE = STATIC
|
||||
LIB_MODE = DYNAMIC
|
||||
# BUILD/DYN_LIBRARY
|
||||
#IMGUI_MODE = BUILD
|
||||
IMGUI_MODE = DYN_LIBRARY
|
||||
|
||||
CC = gcc
|
||||
CXX = g++
|
||||
|
||||
SRC_DIR = src
|
||||
OBJ_DIR = obj
|
||||
BIN_DIR = bin
|
||||
LIB_DIR = lib
|
||||
|
||||
STATIC_INCLUDE_DIR = include
|
||||
|
||||
CPPFLAGS = -Isrc/imgui -g -O3
|
||||
CFLAGS = -g -O3
|
||||
LDFLAGS = -g -O3
|
||||
#global LDLIBS
|
||||
LDLIBS += -L lib/
|
||||
#LDLIBS += -L lib_web/
|
||||
|
||||
LD_DYNAMIC_LIBS = -lraylib #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
|
||||
|
||||
|
||||
#WEBMODE
|
||||
#CC = emcc
|
||||
#CXX = em++
|
||||
#SET ALL TO STATIC, have web version of libraylib.a in libs
|
||||
#ensure glfw is enable
|
||||
#some tinkering may be requiresd to get this working, just make sure
|
||||
#raylib has ES3 on (need to mod make file)
|
||||
#LDFLAGS += -s TOTAL_MEMORY=268435456 -s USE_GLFW=3 -sMIN_WEBGL_VERSION=2 -s FULL_ES3 -s ASYNCIFY
|
||||
#EXE = $(BIN_DIR)/main.html
|
||||
|
||||
|
||||
|
||||
|
||||
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
|
||||
|
||||
ifeq ($(IMGUI_MODE), BUILD)
|
||||
CPP_SRC += $(wildcard $(SRC_DIR)/imgui/*.cpp) #GET LIST OF ALL CPP FILES
|
||||
EXTRA_DIRS += $(OBJ_DIR)/imgui
|
||||
endif
|
||||
|
||||
ifeq ($(IMGUI_MODE), DYN_LIBRARY)
|
||||
LDLIBS += -limgui
|
||||
endif
|
||||
|
||||
#IF DYNAMIC MODE
|
||||
ifeq ($(LIB_MODE), DYNAMIC)
|
||||
LDLIBS += $(LD_DYNAMIC_LIBS)
|
||||
endif
|
||||
|
||||
#IF STATIC MODE
|
||||
ifeq ($(LIB_MODE), STATIC)
|
||||
LDLIBS += $(LD_STATIC_LIBS)
|
||||
CPPFLAGS += -I$(STATIC_INCLUDE_DIR)
|
||||
endif
|
||||
|
||||
|
||||
|
||||
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
|
||||
|
||||
8
README.md
Normal file
8
README.md
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# PROJECT TEMPLATE
|
||||
|
||||
put static libs in lib dir. To ship raylib included with game, compile raylib into a ".a" file, then move that there.
|
||||
the src/imgui folder should contain the git repo of imgui. if the imgui setting in the makefile is set to BUILD, this will be used to provide imgui, otherwise it will try to dynload the library
|
||||
|
||||
|
||||
### also
|
||||
oh yeah, disable rlimgui or whatever detecting DPI if compiling for web, it kills performance
|
||||
0
include/PUT_HEADERS_HERE
Normal file
0
include/PUT_HEADERS_HERE
Normal file
1708
include/raylib.h
Normal file
1708
include/raylib.h
Normal file
File diff suppressed because it is too large
Load diff
2941
include/raymath.h
Normal file
2941
include/raymath.h
Normal file
File diff suppressed because it is too large
Load diff
5262
include/rlgl.h
Normal file
5262
include/rlgl.h
Normal file
File diff suppressed because it is too large
Load diff
0
lib/PUT_STATIC_LIBS_HERE
Normal file
0
lib/PUT_STATIC_LIBS_HERE
Normal file
88
src/course.cpp
Normal file
88
src/course.cpp
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
#include "course.hpp"
|
||||
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||
#include "imgui.h"
|
||||
#include "imgui/misc/cpp/imgui_stdlib.h"
|
||||
#include <optional>
|
||||
#include <unordered_map>
|
||||
|
||||
Course::Course(std::string in) {
|
||||
number = in;
|
||||
}
|
||||
|
||||
CourseWindow::CourseWindow(Course in_course) : course(in_course) {}
|
||||
|
||||
void CourseWindow::Show() {
|
||||
ImGui::SetNextWindowSize(ImVec2(256, 275), ImGuiCond_FirstUseEver);
|
||||
if (ImGui::Begin(course.number.c_str(), &Open)) {
|
||||
link_pressed = false;
|
||||
ImGui::Text("%s", course.name.c_str());
|
||||
ImGui::TextWrapped("%s", course.desc.c_str());
|
||||
ImGui::SeparatorText("Prereqs:");
|
||||
for (int i = 0; i < course.prereq.size(); i++) {
|
||||
if (i > 0) {
|
||||
ImGui::SeparatorText("and");
|
||||
}
|
||||
for (int j = 0; j < course.prereq[i].size(); j++) {
|
||||
bool temppressed = ImGui::Button(course.prereq[i][j].c_str());
|
||||
if (temppressed) {
|
||||
new_course_string = course.prereq[i][j].c_str();
|
||||
link_pressed = true;
|
||||
}
|
||||
if (course.prereq[i].size() > 1 && j < (course.prereq[i].size() - 1)) {
|
||||
ImGui::Text("Or");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (course.prereq.size() == 0) {
|
||||
ImGui::Text("None");
|
||||
}
|
||||
}
|
||||
window_pos = ImGui::GetWindowPos();
|
||||
window_size = ImGui::GetWindowSize();
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
CourseManager::CourseManager(std::unordered_map<std::string, Course> ac) : all_courses(ac) {}
|
||||
|
||||
void CourseManager::Draw() {
|
||||
|
||||
for (auto it = course_windows.begin(); it != course_windows.end(); ++it) {
|
||||
if (it->second.Open) {
|
||||
it->second.Show();
|
||||
for (int i = 0; i < it->second.course.prereq.size(); i++) {
|
||||
for (int j = 0; j < it->second.course.prereq[i].size(); j++) {
|
||||
if (course_windows.count(it->second.course.prereq[i][j])) {
|
||||
auto target = course_windows.find(it->second.course.prereq[i][j]);
|
||||
auto target_ref = target->second;
|
||||
auto us = it->second;
|
||||
ImVec2 center_us = ImVec2((us.window_pos.x + us.window_size.x * 0.5f),
|
||||
(us.window_pos.y + us.window_size.y * 0.5f));
|
||||
ImVec2 center_target =
|
||||
ImVec2((target_ref.window_pos.x + target_ref.window_size.x * 0.5f),
|
||||
(target_ref.window_pos.y + target_ref.window_size.y * 0.5f));
|
||||
if (target->second.Open) {
|
||||
ImGui::GetBackgroundDrawList()->AddLine(center_us, center_target,
|
||||
IM_COL32_WHITE, 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (it->second.link_pressed) {
|
||||
AddByNum(it->second.new_course_string);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CourseManager::AddByNum(std::string num) {
|
||||
if (course_windows.count(num) > 0) {
|
||||
auto course_it = course_windows.find(num);
|
||||
course_it->second.Open = true;
|
||||
}
|
||||
auto course_it = all_courses.find(num);
|
||||
if (course_it != all_courses.end()) {
|
||||
Course c = course_it->second;
|
||||
|
||||
course_windows.insert(std::make_pair(num, CourseWindow(c)));
|
||||
}
|
||||
}
|
||||
41
src/course.hpp
Normal file
41
src/course.hpp
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#ifndef COURSE_H
|
||||
#define COURSE_H
|
||||
|
||||
#include <imgui.h>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
class Course {
|
||||
public:
|
||||
std::string number;
|
||||
std::string name;
|
||||
std::string desc;
|
||||
std::vector<std::vector<std::string>> prereq;
|
||||
Course(std::string in);
|
||||
};
|
||||
|
||||
class CourseWindow {
|
||||
public:
|
||||
bool Open = true;
|
||||
bool Focused = false;
|
||||
std::string new_course_string;
|
||||
bool link_pressed = false;
|
||||
Course course;
|
||||
ImVec2 window_pos;
|
||||
ImVec2 window_size;
|
||||
CourseWindow(Course in_course);
|
||||
void Show();
|
||||
};
|
||||
|
||||
class CourseManager {
|
||||
public:
|
||||
std::unordered_map<std::string, CourseWindow> course_windows;
|
||||
std::unordered_map<std::string, Course> all_courses;
|
||||
CourseManager(std::unordered_map<std::string, Course> ac);
|
||||
void Draw(void);
|
||||
void AddByNum(std::string num);
|
||||
void DrawLines(void);
|
||||
};
|
||||
|
||||
#endif
|
||||
256
src/main.cpp
Normal file
256
src/main.cpp
Normal file
|
|
@ -0,0 +1,256 @@
|
|||
/*******************************************************************************************
|
||||
*
|
||||
* 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
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||
#include "course.hpp"
|
||||
#include "raylib.h"
|
||||
#include "raymath.h"
|
||||
#include <optional>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "imgui.h"
|
||||
#include "imgui/misc/cpp/imgui_stdlib.h"
|
||||
#include "rlImGui/rlImGui.h"
|
||||
|
||||
#include "testcpp.hpp"
|
||||
|
||||
#include "nlohmann/json.hpp"
|
||||
#include "stdio.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
extern "C" {
|
||||
#include "testc.h"
|
||||
}
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
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};
|
||||
};
|
||||
|
||||
void ApplyJsonToCourse(Course *c, json j) {
|
||||
c->name = j.at("name");
|
||||
// printf("Parsing: %s\n", c->name.c_str());
|
||||
if (j.at("desc").is_null()) {
|
||||
} else {
|
||||
c->desc = j.at("desc");
|
||||
}
|
||||
|
||||
if (j.at("prereqs_obj").at("reqs_list").is_null()) {
|
||||
} else {
|
||||
c->prereq = j.at("prereqs_obj").at("reqs_list");
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<Course> GetCourseFromNum(std::vector<Course> course, std::string num) {
|
||||
for (int i = 0; i < course.size(); i++) {
|
||||
if (course[i].number == num) {
|
||||
return course[i];
|
||||
}
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 1280;
|
||||
int screenHeight = 800;
|
||||
|
||||
// SetConfigFlags(FLAG_MSAA_4X_HINT | FLAG_WINDOW_RESIZABLE);
|
||||
SetConfigFlags(FLAG_MSAA_4X_HINT | FLAG_VSYNC_HINT | FLAG_WINDOW_RESIZABLE);
|
||||
InitWindow(screenWidth, screenHeight, "raylib-Extras [ImGui] example - Docking");
|
||||
SetTargetFPS(120);
|
||||
rlImGuiSetup(true);
|
||||
ImGui::GetStyle().AntiAliasedLinesUseTex = false;
|
||||
|
||||
TestC();
|
||||
TestCPPFunc();
|
||||
|
||||
bool run = true;
|
||||
|
||||
bool showDemoWindow = false;
|
||||
|
||||
// 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
|
||||
|
||||
std::ifstream f("spring2025.json");
|
||||
json course_info = json::parse(f);
|
||||
|
||||
// for (json::iterator it = course_info.begin(); it != course_info.end(); ++it) {
|
||||
// std::cout << *it << std::endl;
|
||||
// }
|
||||
|
||||
json list = course_info.at("courses");
|
||||
|
||||
std::unordered_map<std::string, Course> all_courses;
|
||||
|
||||
for (json::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
Course test = Course(it.key());
|
||||
ApplyJsonToCourse(&test, it.value());
|
||||
// printf("%s\n", test.name.c_str());
|
||||
all_courses.insert(std::make_pair(it.key(), test));
|
||||
}
|
||||
|
||||
CourseManager courseman(all_courses);
|
||||
|
||||
printf("The rot consumed the json course data!!\n");
|
||||
|
||||
std::vector<CourseWindow> course_windows;
|
||||
std::string new_course_text_box_string;
|
||||
// Main game loop
|
||||
while (!WindowShouldClose() &&
|
||||
run) // Detect window close button or ESC key, or a quit from the menu
|
||||
{
|
||||
|
||||
BeginDrawing();
|
||||
ClearBackground(DARKGRAY);
|
||||
|
||||
// start ImGui content
|
||||
rlImGuiBegin();
|
||||
|
||||
// if you want windows to dock to the viewport, call this.
|
||||
#ifdef IMGUI_HAS_DOCK
|
||||
ImGui::DockSpaceOverViewport();
|
||||
#endif
|
||||
|
||||
// show a simple menu bar
|
||||
if (ImGui::BeginMainMenuBar()) {
|
||||
if (ImGui::BeginMenu("File")) {
|
||||
#ifdef IMGUI_HAS_DOCK
|
||||
if (ImGui::MenuItem("Enable Docking")) {
|
||||
ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
||||
}
|
||||
if (ImGui::MenuItem("Disable Docking")) {
|
||||
ImGui::GetIO().ConfigFlags &= ~ImGuiConfigFlags_DockingEnable;
|
||||
}
|
||||
#endif
|
||||
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("Add Course To Display");
|
||||
ImGui::InputText("erm", &new_course_text_box_string);
|
||||
if (ImGui::Button("Pog!!!!!!")) {
|
||||
courseman.AddByNum(new_course_text_box_string);
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
courseman.Draw();
|
||||
|
||||
// end ImGui Content
|
||||
rlImGuiEnd();
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
rlImGuiShutdown();
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
16
src/rlImGui/LICENSE
Normal file
16
src/rlImGui/LICENSE
Normal 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
75
src/rlImGui/README.md
Normal 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.
|
||||

|
||||
|
||||
|
||||
## 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
|
||||
280
src/rlImGui/examples/asset_browser/asset_browser.cpp
Normal file
280
src/rlImGui/examples/asset_browser/asset_browser.cpp
Normal 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;
|
||||
}
|
||||
95
src/rlImGui/examples/asset_browser/asset_browser.h
Normal file
95
src/rlImGui/examples/asset_browser/asset_browser.h
Normal 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);
|
||||
};
|
||||
94
src/rlImGui/examples/asset_browser/imgui_utils.cpp
Normal file
94
src/rlImGui/examples/asset_browser/imgui_utils.cpp
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
19
src/rlImGui/examples/asset_browser/imgui_utils.h
Normal file
19
src/rlImGui/examples/asset_browser/imgui_utils.h
Normal 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);
|
||||
}
|
||||
47
src/rlImGui/examples/asset_browser/item_view.h
Normal file
47
src/rlImGui/examples/asset_browser/item_view.h
Normal 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;
|
||||
};
|
||||
53
src/rlImGui/examples/asset_browser/item_views.cpp
Normal file
53
src/rlImGui/examples/asset_browser/item_views.cpp
Normal 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;
|
||||
}
|
||||
96
src/rlImGui/examples/asset_browser/main.cpp
Normal file
96
src/rlImGui/examples/asset_browser/main.cpp
Normal 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;
|
||||
}
|
||||
105
src/rlImGui/examples/docking_example.cpp
Normal file
105
src/rlImGui/examples/docking_example.cpp
Normal 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;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue