diff --git a/.gitignore b/.gitignore index 531a399..a38514d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ # cmake build directory build/ + +# clangd cache +.cache/ diff --git a/as1/CMakeLists.txt b/as1/CMakeLists.txt new file mode 100644 index 0000000..a53d650 --- /dev/null +++ b/as1/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.18) +project(as1 CXX) + +set(CMAKE_CXX_STANDARD 20) + +# adding this option to make clangd work +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +add_subdirectory(../raylib-cpp raylib) + +add_executable(as1 as1.cpp raygui.cpp) +target_link_libraries(as1 PUBLIC raylib raylib_cpp raygui) + +configure_file(../assets/audio/ping.wav audio/ping.wav COPYONLY) +configure_file(../assets/audio/price-of-freedom.mp3 audio/price-of-freedom.mp3 COPYONLY) diff --git a/as1/README.md b/as1/README.md new file mode 100644 index 0000000..e69de29 diff --git a/as1/VolumeControl.h b/as1/VolumeControl.h new file mode 100755 index 0000000..257e024 --- /dev/null +++ b/as1/VolumeControl.h @@ -0,0 +1,124 @@ +/******************************************************************************************* +* +* VolumeControl v1.0.0 - Tool Description +* +* MODULE USAGE: +* #define GUI_VOLUMECONTROL_IMPLEMENTATION +* #include "gui_VolumeControl.h" +* +* INIT: GuiVolumeControlState state = InitGuiVolumeControl(); +* DRAW: GuiVolumeControl(&state); +* +* LICENSE: Propietary License +* +* Copyright (c) 2022 Joshua Dahl. All Rights Reserved. +* +* Unauthorized copying of this file, via any medium is strictly prohibited +* This project is proprietary and confidential unless the owner allows +* usage in any other form by expresely written permission. +* +**********************************************************************************************/ + +#include "raylib.h" + +// WARNING: raygui implementation is expected to be defined before including this header +// #undef RAYGUI_IMPLEMENTATION +#include "raygui.h" + +#include // Required for: strcpy() + +#ifndef GUI_VOLUMECONTROL_H +#define GUI_VOLUMECONTROL_H + +typedef struct { + // Define anchors + Vector2 anchor01; // ANCHOR ID:1 + + // Define controls variables + float SFXSliderValue; // Slider: SFXSlider + float MusicSliderValue; // Slider: MusicSlider + float DialogueSliderValue; // Slider: DialogueSlider + + // Custom state variables (depend on development software) + // NOTE: This variables should be added manually if required + +} GuiVolumeControlState; + +#ifdef __cplusplus +extern "C" { // Prevents name mangling of functions +#endif + +//---------------------------------------------------------------------------------- +// Module Functions Declaration +//---------------------------------------------------------------------------------- +GuiVolumeControlState InitGuiVolumeControl(void); +void GuiVolumeControl(GuiVolumeControlState *state); +// static void PingButton(); // Button: PingButton logic + +#ifdef __cplusplus +} +#endif + +#endif // GUI_VOLUMECONTROL_H + +/*********************************************************************************** +* +* GUI_VOLUMECONTROL IMPLEMENTATION +* +************************************************************************************/ +#if defined(GUI_VOLUMECONTROL_IMPLEMENTATION) + +#include "raygui.h" + +//---------------------------------------------------------------------------------- +// Module Functions Definition +//---------------------------------------------------------------------------------- +GuiVolumeControlState InitGuiVolumeControl(void) { + GuiVolumeControlState state = { 0 }; + + // Init anchors + state.anchor01 = (Vector2){ 24, 24 }; // ANCHOR ID:1 + + // Initilize controls variables + state.SFXSliderValue = 0.0f; // Slider: SFXSlider + state.MusicSliderValue = 0.0f; // Slider: MusicSlider + state.DialogueSliderValue = 0.0f; // Slider: DialogueSlider + + // Custom variables initialization + + return state; +} + +// Button: PingButton logic +// static void PingButton() +// { +// // TODO: Implement in outer file! +// } + + +void GuiVolumeControl(GuiVolumeControlState *state) { + // Const text + const char *VolumeGroupText = "Volume Controls"; // GROUPBOX: VolumeGroup + const char *SFXGroupText = "SFXVolume"; // GROUPBOX: SFXGroup + const char *SFXSliderText = ""; // SLIDER: SFXSlider + const char *MusicGroupText = "MusicVolume"; // GROUPBOX: MusicGroup + const char *MusicSliderText = ""; // SLIDER: MusicSlider + const char *DialogueGroupText = "DialogueVolume"; // GROUPBOX: DialogueGroup + const char *DialogueSliderText = ""; // SLIDER: DialogueSlider + const char *PingButtonText = "Ping"; // BUTTON: PingButton + + // Draw controls + GuiGroupBox((Rectangle){ state->anchor01.x + 0, state->anchor01.y + 0, 256, 264 }, VolumeGroupText); + GuiGroupBox((Rectangle){ state->anchor01.x + 24, state->anchor01.y + 24, 208, 56 }, SFXGroupText); + GuiLabel((Rectangle){ 64, 64, 120, 24 }, TextFormat("%.0f%%", state->SFXSliderValue)); + state->SFXSliderValue = GuiSlider((Rectangle){ state->anchor01.x + 72, state->anchor01.y + 40, 144, 24 }, SFXSliderText, NULL, state->SFXSliderValue, 0, 100); + GuiGroupBox((Rectangle){ state->anchor01.x + 24, state->anchor01.y + 104, 208, 56 }, MusicGroupText); + GuiLabel((Rectangle){ 64, 144, 120, 24 }, TextFormat("%.0f%%", state->MusicSliderValue)); + state->MusicSliderValue = GuiSlider((Rectangle){ state->anchor01.x + 72, state->anchor01.y + 120, 144, 24 }, MusicSliderText, NULL, state->MusicSliderValue, 0, 100); + GuiGroupBox((Rectangle){ state->anchor01.x + 24, state->anchor01.y + 184, 208, 56 }, DialogueGroupText); + GuiLabel((Rectangle){ 64, 224, 120, 24 }, TextFormat("%.0f%%", state->DialogueSliderValue)); + state->DialogueSliderValue = GuiSlider((Rectangle){ state->anchor01.x + 72, state->anchor01.y + 200, 144, 24 }, DialogueSliderText, NULL, state->DialogueSliderValue, 0, 100); + if (GuiButton((Rectangle){ 24, 304, 256, 24 }, PingButtonText)) PingButton(); +} + +#endif // GUI_VOLUMECONTROL_IMPLEMENTATION diff --git a/as1/as1.cpp b/as1/as1.cpp new file mode 100644 index 0000000..a193df2 --- /dev/null +++ b/as1/as1.cpp @@ -0,0 +1,56 @@ +#include "AudioDevice.hpp" +#include "Color.hpp" +#include +#include + +void PingButton() { + std::cout << "Ping!" << std::endl; +} + +#define GUI_VOLUMECONTROL_IMPLEMENTATION +#include "VolumeControl.h" + +template +concept calls_with_no_arguments = requires(T a) { + { a() }; +}; + +template +void call_lambda(TFunction func) { + func(); +} + +int main() { + raylib::Window window(800, 600, "CS381 - Assignment 0"); + raylib::AudioDevice audio; + + auto guiState = InitGuiVolumeControl(); + + raylib::Sound ping("audio/ping.wav"); + raylib::Music music("audio/price-of-freedom.mp3"); + music.Play(); + + // play ping sound when button is pressed + auto lambdaPingButton = [&ping]() { + ping.Play(); + }; + + call_lambda(lambdaPingButton); + + InitGuiVolumeControl(); + + while (!window.ShouldClose()) { + window.BeginDrawing(); + + window.ClearBackground(raylib::Color::RayWhite()); + music.Update(); + music.SetVolume(guiState.MusicSliderValue / 100.0f); + GuiVolumeControl(&guiState); + + window.EndDrawing(); + } + + delete ping; + + return 0; +} diff --git a/as1/raygui.cpp b/as1/raygui.cpp new file mode 100644 index 0000000..1878467 --- /dev/null +++ b/as1/raygui.cpp @@ -0,0 +1,2 @@ +#define RAYGUI_IMPLEMENTATION +#include "raygui.h"