Initial Commit (does NOT build)
This commit is contained in:
commit
6b404b2d20
16
.gitignore
vendored
Normal file
16
.gitignore
vendored
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
# Ignore build directories
|
||||||
|
build/
|
||||||
|
cmake-build-debug/
|
||||||
|
cmake-build-release/
|
||||||
|
cmake-build-relminsize/
|
||||||
|
|
||||||
|
# Ignore cache files
|
||||||
|
.cache/
|
||||||
|
|
||||||
|
# Ignore LSP file
|
||||||
|
compile_commands.json
|
||||||
|
|
||||||
|
# Ignore IDE Files
|
||||||
|
.vs/
|
||||||
|
.jb/
|
||||||
|
.idea/
|
95
CMakeLists.txt
Normal file
95
CMakeLists.txt
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.24)
|
||||||
|
project(RaylibDmx) # Project Name: RaylibDmx
|
||||||
|
|
||||||
|
# nvim/fleet users (ONLY WORKS WITH MINGW/NINJA BUILDERS)
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
|
# Dependencies
|
||||||
|
## - Raylib
|
||||||
|
## - rlImGui
|
||||||
|
#### - ImGui
|
||||||
|
|
||||||
|
# Use FetchContent to download and build raylib
|
||||||
|
# This is a faster alternative to using a git repo, since this just downloads the source
|
||||||
|
# while the git repo pull takes a lot longer. Not sure why, other repos don't seem to have this issue
|
||||||
|
|
||||||
|
# If you would like to use git instead, use this:
|
||||||
|
# - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
#FetchContent_Declare(
|
||||||
|
# raylib
|
||||||
|
# GIT_REPOSITORY "https://github.com/raysan5/raylib.git"
|
||||||
|
# GIT_TAG "master"
|
||||||
|
# GIT_SHALLOW TRUE
|
||||||
|
# GIT_PROGRESS TRUE
|
||||||
|
#)
|
||||||
|
# - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
||||||
|
include(FetchContent)
|
||||||
|
set(FETCHCONTENT_QUIET FALSE)
|
||||||
|
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) # don't build the supplied examples
|
||||||
|
set(BUILD_GAMES OFF CACHE BOOL "" FORCE) # don't build the supplied example games
|
||||||
|
|
||||||
|
FetchContent_Declare(
|
||||||
|
raylib
|
||||||
|
URL https://github.com/raysan5/raylib/archive/refs/tags/4.5.0.tar.gz
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(raylib)
|
||||||
|
|
||||||
|
# Raylib conf
|
||||||
|
set(raylib_VERBOSE 1) # Not 100% sure if this does anything...
|
||||||
|
|
||||||
|
# Download and build Dear ImGui
|
||||||
|
FetchContent_Declare(
|
||||||
|
imgui
|
||||||
|
GIT_REPOSITORY https://github.com/ocornut/imgui.git
|
||||||
|
GIT_SHALLOW TRUE
|
||||||
|
GIT_TAG v1.89.4
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(imgui)
|
||||||
|
|
||||||
|
# Download and build rlImGui
|
||||||
|
FetchContent_Declare(
|
||||||
|
rlImGui
|
||||||
|
GIT_REPOSITORY https://github.com/raylib-extras/rlImGui.git
|
||||||
|
GIT_TAG main
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(rlImGui)
|
||||||
|
|
||||||
|
# Add rlImGui library
|
||||||
|
add_library(rlImGui STATIC
|
||||||
|
${rlImGui_SOURCE_DIR}/rlImGui.cpp
|
||||||
|
${rlImGui_SOURCE_DIR}/imgui_impl_raylib.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
# Include directories for rlImGui
|
||||||
|
target_include_directories(rlImGui PRIVATE
|
||||||
|
${imgui_SOURCE_DIR}
|
||||||
|
${raylib_SOURCE_DIR}/src
|
||||||
|
${rlImGui_SOURCE_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Link rlImGui with Raylib
|
||||||
|
target_link_libraries(rlImGui PRIVATE raylib)
|
||||||
|
|
||||||
|
# add source code
|
||||||
|
file(GLOB_RECURSE PROJECT_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/src/*.cpp") # Define PROJECT_SOURCES as a list of all source files
|
||||||
|
set(PROJECT_INCLUDE "${CMAKE_CURRENT_LIST_DIR}/src")
|
||||||
|
|
||||||
|
# exe
|
||||||
|
add_executable(${PROJECT_NAME})
|
||||||
|
target_sources(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCES})
|
||||||
|
target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_INCLUDE})
|
||||||
|
target_link_libraries(${PROJECT_NAME} PRIVATE raylib rlImGui)
|
||||||
|
|
||||||
|
# Web Configurations
|
||||||
|
if (${PLATFORM} STREQUAL "Web")
|
||||||
|
# Tell Emscripten to build an example.html file.
|
||||||
|
set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".html")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Checks if OSX and links appropriate frameworks (Only required on MacOS)
|
||||||
|
if (APPLE)
|
||||||
|
target_link_libraries(${PROJECT_NAME} "-framework IOKit")
|
||||||
|
target_link_libraries(${PROJECT_NAME} "-framework Cocoa")
|
||||||
|
target_link_libraries(${PROJECT_NAME} "-framework OpenGL")
|
||||||
|
endif()
|
44
README.md
Normal file
44
README.md
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
# DMX Raylib
|
||||||
|
Trying to get my DMX Lightshow app working with raylib (and imgui)
|
||||||
|
|
||||||
|
## Deps:
|
||||||
|
[https://cmake.org/](cmake)
|
||||||
|
A c++ compiler [https://www.mingw-w64.org/](mingw)
|
||||||
|
|
||||||
|
## Cloning
|
||||||
|
Clone the repo with git:
|
||||||
|
```bash
|
||||||
|
git clone https://thisrepo.com:8080/dmxshowraylib/dmxshowraylib.git
|
||||||
|
```
|
||||||
|
Or you can choose the *Download zip* option
|
||||||
|
|
||||||
|
Then, extract / navigate to the downlaoded directory.
|
||||||
|
Create a build folder:
|
||||||
|
```bash
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
```
|
||||||
|
|
||||||
|
Use a generator to generate the build files. (Using ninja in this example)
|
||||||
|
```
|
||||||
|
cmake -G "Ninja" ..
|
||||||
|
```
|
||||||
|
|
||||||
|
Let this run, then build the project using:
|
||||||
|
```
|
||||||
|
cmake --build . -- -j
|
||||||
|
```
|
||||||
|
(The -j flag uses all cores to build faster)
|
||||||
|
|
||||||
|
You can also build a Visual Studio solution file. This is usually the default if you don't specify a generator to cmake:
|
||||||
|
```bash
|
||||||
|
cmake ..
|
||||||
|
```
|
||||||
|
|
||||||
|
This should create a project `.sln` file you can open with Visual Studio. Then, just hit F5!
|
||||||
|
|
||||||
|
|
||||||
|
### Libraries used:
|
||||||
|
[https://github.com/raysan5/raylib](Raylib) Amazing library
|
||||||
|
[https://github.com/raylib-extras/rlImGui](rlImGui) ImGui with Raylib Backend
|
||||||
|
[https://github.com/ocornut/imgui](ImGui) Little tooling
|
33
src/main.cpp
Normal file
33
src/main.cpp
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#include "raylib.h"
|
||||||
|
#include "panel.h"
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
const int screenWidth = 1920;
|
||||||
|
const int screenHeight = 1080;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "DMX Raylib UI");
|
||||||
|
SetTargetFPS(60);
|
||||||
|
|
||||||
|
// Create the timeline and properties panels
|
||||||
|
Panel timelinePanel = {{0, 0, screenWidth * 0.75f, screenHeight * 0.6f}, "Timeline", LIGHTGRAY, DARKGRAY, true};
|
||||||
|
Panel propertiesPanel = {{screenWidth * 0.75f, 0, screenWidth * 0.25f, screenHeight}, "Properties", LIGHTGRAY, DARKGRAY, true};
|
||||||
|
|
||||||
|
while (!WindowShouldClose()) {
|
||||||
|
// Update panels
|
||||||
|
timelinePanel.Update();
|
||||||
|
propertiesPanel.Update();
|
||||||
|
|
||||||
|
BeginDrawing();
|
||||||
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
|
// Draw panels
|
||||||
|
if (timelinePanel.isVisible) timelinePanel.Draw();
|
||||||
|
if (propertiesPanel.isVisible) propertiesPanel.Draw();
|
||||||
|
|
||||||
|
DrawFPS(3, screenHeight - 20);
|
||||||
|
EndDrawing();
|
||||||
|
}
|
||||||
|
|
||||||
|
CloseWindow();
|
||||||
|
return 0;
|
||||||
|
}
|
21
src/panel.cpp
Normal file
21
src/panel.cpp
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
//
|
||||||
|
// Created by illyum on 8/15/2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "panel.h"
|
||||||
|
|
||||||
|
void Panel::Draw() {
|
||||||
|
// Draw panel background
|
||||||
|
DrawRectangleRec(bounds, backgroundColor);
|
||||||
|
|
||||||
|
// Draw panel header
|
||||||
|
DrawRectangle(bounds.x, bounds.y, bounds.width, 30, headerColor);
|
||||||
|
DrawText(title.c_str(), bounds.x + 10, bounds.y + 5, 20, WHITE);
|
||||||
|
|
||||||
|
// Draw content (placeholder)
|
||||||
|
DrawText("Content goes here", bounds.x + 10, bounds.y + 40, 20, GRAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Panel::Update() {
|
||||||
|
// This method can be expanded to handle resizing, interactions, etc.
|
||||||
|
}
|
27
src/panel.h
Normal file
27
src/panel.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
//
|
||||||
|
// Created by illyum on 8/15/2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef PANEL_H
|
||||||
|
#define PANEL_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
|
struct Panel {
|
||||||
|
Rectangle bounds;
|
||||||
|
std::string title;
|
||||||
|
Color backgroundColor;
|
||||||
|
Color headerColor;
|
||||||
|
bool isVisible;
|
||||||
|
|
||||||
|
// Panel content can be expanded later
|
||||||
|
void Draw();
|
||||||
|
void Update();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //PANEL_H
|
53
src/ui.cpp
Normal file
53
src/ui.cpp
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
//
|
||||||
|
// Created by illyum on 8/15/2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "ui.h"
|
||||||
|
|
||||||
|
void Button::Draw() {
|
||||||
|
Color currentColor = isHovered ? hoverColor : color;
|
||||||
|
DrawRectangleRec(bounds, currentColor);
|
||||||
|
DrawText(text, bounds.x + 10, bounds.y + 10, 20, textColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Button::Update() {
|
||||||
|
Vector2 mousePoint = GetMousePosition();
|
||||||
|
isHovered = CheckCollisionPointRec(mousePoint, bounds);
|
||||||
|
isClicked = isHovered && IsMouseButtonPressed(MOUSE_LEFT_BUTTON);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Slider::Draw() {
|
||||||
|
DrawRectangleRec(bounds, color);
|
||||||
|
float knobX = bounds.x + (value - minValue) / (maxValue - minValue) * bounds.width;
|
||||||
|
DrawRectangle(knobX - 5, bounds.y - 5, 10, bounds.height + 10, knobColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Slider::Update() {
|
||||||
|
static bool isDragging = false;
|
||||||
|
|
||||||
|
Vector2 mousePoint = GetMousePosition();
|
||||||
|
if (CheckCollisionPointRec(mousePoint, bounds) && IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) {
|
||||||
|
isDragging = true;
|
||||||
|
}
|
||||||
|
if (isDragging) {
|
||||||
|
float newValue = minValue + (mousePoint.x - bounds.x) / bounds.width * (maxValue - minValue);
|
||||||
|
value = Clamp(newValue, minValue, maxValue);
|
||||||
|
|
||||||
|
if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) {
|
||||||
|
isDragging = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// This will make the slider stop updating when the mouse leave's the bounds of the slider
|
||||||
|
// Vector2 mousePoint = GetMousePosition();
|
||||||
|
// if (CheckCollisionPointRec(mousePoint, bounds) && IsMouseButtonDown(MOUSE_LEFT_BUTTON)) {
|
||||||
|
// float newValue = minValue + (mousePoint.x - bounds.x) / bounds.width * (maxValue - minValue);
|
||||||
|
// value = Clamp(newValue, minValue, maxValue);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
float Clamp(float value, float min, float max) {
|
||||||
|
if (value < min) return min;
|
||||||
|
if (value > max) return max;
|
||||||
|
return value;
|
||||||
|
}
|
39
src/ui.h
Normal file
39
src/ui.h
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
//
|
||||||
|
// Created by illyum on 8/15/2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef UI_H
|
||||||
|
#define UI_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
|
||||||
|
|
||||||
|
struct Button {
|
||||||
|
Rectangle bounds;
|
||||||
|
const char* text;
|
||||||
|
Color color;
|
||||||
|
Color hoverColor;
|
||||||
|
Color textColor;
|
||||||
|
bool isHovered;
|
||||||
|
bool isClicked;
|
||||||
|
|
||||||
|
void Draw();
|
||||||
|
void Update();
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Slider {
|
||||||
|
Rectangle bounds;
|
||||||
|
float value;
|
||||||
|
float minValue;
|
||||||
|
float maxValue;
|
||||||
|
Color color;
|
||||||
|
Color knobColor;
|
||||||
|
|
||||||
|
void Draw();
|
||||||
|
void Update();
|
||||||
|
};
|
||||||
|
|
||||||
|
float Clamp(float value, float min, float max);
|
||||||
|
|
||||||
|
#endif //UI_H
|
Loading…
x
Reference in New Issue
Block a user