Skip to content

Commit

Permalink
Merge branch 'main' into thaugdahl/image-additions
Browse files Browse the repository at this point in the history
  • Loading branch information
joakibhu authored Jul 13, 2026
2 parents e460d7a + b877adb commit 723c60e
Show file tree
Hide file tree
Showing 165 changed files with 10,137 additions and 78 deletions.
14 changes: 9 additions & 5 deletions configuration/.vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/subprojects/animationwindow/include/**",
"${workspaceFolder}/subprojects/std_lib_facilities/**",
"${workspaceFolder}/subprojects/sdl2_image_windows/include/**",
"${workspaceFolder}/subprojects/sdl2_mixer_windows/include/**",
"${workspaceFolder}/subprojects/sdl2_windows/include/**"
Expand All @@ -15,7 +16,7 @@
"_UNICODE"
],
"cStandard": "c17",
"cppStandard": "c++20",
"cppStandard": "c++23",
"compilerPath": "C:\\TDT4102-mingw64\\bin\\gcc",
"compileCommands": "${workspaceFolder}/build/compile_commands.json",
"intelliSenseMode": "windows-gcc-x64"
Expand All @@ -24,30 +25,33 @@
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/subprojects/animationwindow/include/**"
"${workspaceFolder}/subprojects/animationwindow/include/**",
"${workspaceFolder}/subprojects/std_lib_facilities/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"cStandard": "c17",
"cppStandard": "c++20",
"cppStandard": "c++23",
"compileCommands": "build/compile_commands.json",
"intelliSenseMode": "macos-clang-x64"
},
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
"${workspaceFolder}/**",
"${workspaceFolder}/subprojects/animationwindow/include/**",
"${workspaceFolder}/subprojects/std_lib_facilities/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"cStandard": "c17",
"cppStandard": "c++20",
"cppStandard": "c++23",
"compileCommands": "build/compile_commands.json",
"intelliSenseMode": "linux-gcc-x64"
}
Expand Down
19 changes: 18 additions & 1 deletion configuration/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,22 @@
"cmake.configureOnOpen": false,
"cmake.autoSelectActiveFolder": false,
"cmake.configureOnEdit": false,
"makefile.alwaysPreConfigure": false
"makefile.alwaysPreConfigure": false,
"C_Cpp.default.compileCommands": [
"${workspaceFolder}/build/compile_commands.json"
],
"C_Cpp.codeAnalysis.clangTidy.args": [
"-header-filter=^${workspaceFolder}/.*",
"--system-headers=false",
"--query-driver=/usr/bin/*, /usr/local/bin/*, C:/TDT4102-mingw64/bin/*",
],
"C_Cpp.codeAnalysis.clangTidy.enabled": true,
"C_Cpp.codeAnalysis.exclude":{
"subprojects/**": true,
"build/**": true
},
"C_Cpp.codeAnalysis.runAutomatically": true,
"C_Cpp.codeAnalysis.clangTidy.useBuildPath": true,
"C_Cpp.errorSquiggles": "enabledIfIncludesResolve",
"C_Cpp.intelliSenseEngine": "default"
}
2 changes: 1 addition & 1 deletion dependencies/meson.build
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
project('testproject', 'cpp',
version : '0.1',
default_options : ['warning_level=0',
'cpp_std=c++20',
'cpp_std=c++23',
'c_std=c17',
'default_library=static'])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ class AnimationWindow {
void draw_circle(TDT4102::Point centre, int radius, TDT4102::Color color = TDT4102::Color::dark_blue, TDT4102::Color borderColor = TDT4102::Color::transparent);
void draw_rectangle(TDT4102::Point topLeftPoint, int width, int height, TDT4102::Color color = TDT4102::Color::dark_green, TDT4102::Color borderColor = TDT4102::Color::transparent);
void draw_image(TDT4102::Point topLeftPoint, TDT4102::Image& image, int imageWidth = 0, int imageHeight = 0, double rotationAngleDegrees = 0, TDT4102::Point rotationOrigin = {0, 0});
void draw_text(TDT4102::Point bottomLeftPoint, std::string textToShow, TDT4102::Color color = TDT4102::Color::black, unsigned int fontSize = 20, TDT4102::Font font = TDT4102::Font::arial);
void draw_image_region(TDT4102::Point topLeftPoint, TDT4102::Image& image, int imageWidth = 0, int imageHeight = 0, TDT4102::Point sourceTopLeftPoint = {0, 0}, int sourceWidth = 0, int sourceHeight = 0, TDT4102::FlipImage flip = TDT4102::FlipImage::NONE);
void draw_text(TDT4102::Point topLeftPoint, std::string textToShow, TDT4102::Color color = TDT4102::Color::black, unsigned int fontSize = 20, TDT4102::Font font = TDT4102::Font::arial);
void draw_line(TDT4102::Point start, TDT4102::Point end, TDT4102::Color color = TDT4102::Color::black);
void draw_triangle(TDT4102::Point vertex0, TDT4102::Point vertex1, TDT4102::Point vertex2, TDT4102::Color color = TDT4102::Color::yellow);
void draw_quad(TDT4102::Point vertex0, TDT4102::Point vertex1, TDT4102::Point vertex2, TDT4102::Point vertex3, TDT4102::Color color = TDT4102::Color::cyan);
Expand Down
9 changes: 9 additions & 0 deletions dependencies/subprojects/animationwindow/include/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
namespace TDT4102 {

struct ImageCache;

enum class FlipImage {
NONE, HORIZONTAL, VERTICAL
};

struct Image {
// Allow the texture to be read out and drawn despite being private
Expand Down Expand Up @@ -89,5 +93,10 @@ namespace TDT4102 {
void reset();

static ImageCache cache;

void drawRegion(SDL_Renderer* renderer, TDT4102::Point location,
int imageWidth = 0, int imageHeight = 0,
TDT4102::Point sourceTopLeftPoint = {0, 0},
int sourceWidth = 0, int sourceHeight = 0, SDL_RendererFlip flip = SDL_FLIP_NONE);
};
}
2 changes: 1 addition & 1 deletion dependencies/subprojects/animationwindow/include/Widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace TDT4102 {

protected:
void fire();
virtual void update(nk_context* context) = 0;
virtual void update(nk_context* contex, bool& eventHandled) = 0;
explicit Widget(TDT4102::Point position, unsigned int width, unsigned int height);
public:
void setCallback(std::function<void(void)> callback);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace TDT4102 {
nk_color buttonColorBorder = nk_rgba(35, 35, 35,255);

protected:
void update(nk_context* context) override;
void update(nk_context* context, bool& eventHandled) override;
public:
explicit Button(TDT4102::Point location, unsigned int width, unsigned int height, std::string label);
void setLabel(std::string newLabel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace TDT4102 {
nk_color checkBoxColorActive = nk_rgba(150, 150, 150, 255);

protected:
void update(nk_context* context) override;
void update(nk_context* context, bool& eventHandled) override;
public:
explicit CheckBox(TDT4102::Point location, unsigned int width, unsigned int height, std::string label);
bool isSelected() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace TDT4102 {
std::vector<std::string> options;
unsigned int selectedIndex = 0;
protected:
void update(nk_context* context) override;
void update(nk_context* context, bool& eventHandled) override;
public:
explicit DropdownList(TDT4102::Point location, unsigned int width, unsigned int height, std::vector<std::string> &initialOptions);
std::string getSelectedValue() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace TDT4102 {
nk_color radioColorActive = nk_rgba(150, 150, 150, 255);

protected:
void update(nk_context* context) override;
void update(nk_context* contex, bool& eventHandled) override;
public:
explicit RadioButton(TDT4102::Point location, unsigned int width, unsigned int height, std::string label);
bool isSelected() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace TDT4102 {
nk_color sliderCursorColorActive = nk_rgba(180, 180, 180, 255);
nk_color sliderCursorColorHover = nk_rgba(180, 180, 180, 255);
protected:
void update(nk_context* context) override;
void update(nk_context* context, bool& eventHandled) override;
public:
explicit Slider(TDT4102::Point location, unsigned int width, unsigned int height, int min = 0, int max = 100, int initialValue = 0, int step = 1);
int getValue() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace TDT4102 {
nk_color boxColor = nk_rgba(50 , 50, 50, 255);
nk_color borderColor = nk_rgba(50, 50, 50, 255);
protected:
void update(nk_context* context) override;
void update(nk_context* context, bool& eventHandled) override;
public:
explicit TextBox(TDT4102::Point location, unsigned int width, unsigned int height, std::string initialText = "");
std::string getText() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace TDT4102 {
nk_color boxColorActive = nk_rgba(50 , 50, 50, 255);
nk_color borderColor = nk_rgba(50, 50, 50, 255);
protected:
void update(nk_context* context) override;
void update(nk_context* context, bool& eventHandled) override;
public:
explicit TextInput(TDT4102::Point location, unsigned int width, unsigned int height, std::string initialText = "");
std::string getText() const;
Expand Down
2 changes: 1 addition & 1 deletion dependencies/subprojects/animationwindow/meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project('animationwindow', ['c', 'cpp'], version: '0.01', default_options: ['cpp_std=c++20', 'c_std=c17', 'default_library=static', 'buildtype=debugoptimized'])
project('animationwindow', ['c', 'cpp'], version: '0.01', default_options: ['cpp_std=c++23', 'c_std=c17', 'default_library=static', 'buildtype=debugoptimized'])

if host_machine.system() == 'windows'
sdl2_dep = subproject('sdl2_windows').get_variable('sdl2_windows_dep')
Expand Down
21 changes: 19 additions & 2 deletions dependencies/subprojects/animationwindow/src/AnimationWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,12 @@ void TDT4102::AnimationWindow::show_frame() {
}

void TDT4102::AnimationWindow::update_gui() {
bool eventHandled = false;
for (Widget& widget : widgets) {
fontCache.setFont(context, Font::arial, 18);
if (widget.isVisible) {
startNuklearDraw(widget.position, widget.uniqueWidgetName, widget.width, widget.height);
widget.update(context);
widget.update(context, eventHandled);
endNuklearDraw();
}
}
Expand Down Expand Up @@ -259,6 +260,21 @@ void TDT4102::AnimationWindow::draw_image(TDT4102::Point topLeftPoint, TDT4102::
image.draw(rendererHandle, topLeftPoint, imageWidth, imageHeight, rotationAngleDegrees, rotationOrigin);
}

void TDT4102::AnimationWindow::draw_image_region(TDT4102::Point topLeftPoint, TDT4102::Image& image, int imageWidth, int imageHeight, TDT4102::Point sourceTopLeftPoint, int sourceWidth, int sourceHeight, TDT4102::FlipImage flip) {
SDL_RendererFlip sdl_flip = SDL_FLIP_NONE;
switch (flip){
case TDT4102::FlipImage::HORIZONTAL:
sdl_flip = SDL_FLIP_HORIZONTAL;
break;
case TDT4102::FlipImage::VERTICAL:
sdl_flip = SDL_FLIP_VERTICAL;
break;
default:
sdl_flip = SDL_FLIP_NONE;
}
image.drawRegion(rendererHandle, topLeftPoint, imageWidth, imageHeight, sourceTopLeftPoint, sourceWidth, sourceHeight, sdl_flip);
}

void TDT4102::AnimationWindow::draw_text(TDT4102::Point topLeftPoint, std::string textToShow, TDT4102::Color color, unsigned int fontSize, TDT4102::Font font) {
textWindowCounter++;
std::stringstream windowName;
Expand Down Expand Up @@ -384,13 +400,14 @@ void TDT4102::AnimationWindow::startNuklearDraw(TDT4102::Point location, std::st
// Compute a rectangle that spans the entire size of the window
// Some padding is needed to accomplish this.
const unsigned int drawAreaPadding = 20;
const unsigned int windowPaddingX = 2 * context->style.window.padding.x;

// If no draw size was specified, use as much space as available inside the window
struct nk_rect drawAreaSize;
if (width == 0 && height == 0) {
drawAreaSize = nk_rect(float(location.x), float(location.y), float(windowSize.x - location.x + drawAreaPadding), float(windowSize.y - location.y + drawAreaPadding));
} else {
drawAreaSize = nk_rect(float(location.x), float(location.y), float(width), float(height));
drawAreaSize = nk_rect(float(location.x), float(location.y), float(width + windowPaddingX), float(height));
}

// Ensuring that all GUI elements have a reasonable minimum height
Expand Down
23 changes: 23 additions & 0 deletions dependencies/subprojects/animationwindow/src/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,29 @@ void TDT4102::Image::draw(SDL_Renderer *renderer, TDT4102::Point location, int i
SDL_RenderCopyEx(renderer, texture, nullptr, &imageBounds, angleDegrees, &rotationOrigin_sdl, SDL_FLIP_NONE);
}

void TDT4102::Image::drawRegion(SDL_Renderer* renderer, TDT4102::Point location, int imageWidth, int imageHeight, TDT4102::Point sourceTopLeftPoint, int sourceWidth, int sourceHeight, SDL_RendererFlip flip) {
if(texture == nullptr) {
load(renderer);
}

SDL_Rect sourceBounds {sourceTopLeftPoint.x, sourceTopLeftPoint.y, width, height};

if(sourceWidth > 0 && sourceHeight > 0) {
sourceBounds.w = sourceWidth;
sourceBounds.h = sourceHeight;
}

SDL_Rect imageBounds {location.x, location.y, width, height};

if(imageWidth > 0 && imageHeight > 0) {
imageBounds.w = imageWidth;
imageBounds.h = imageHeight;
}

SDL_RenderCopyEx(renderer, texture, &sourceBounds, &imageBounds, 0.0, nullptr, flip);
}


TDT4102::Image::~Image() {
cleanupTexture();
cleanupSurface();
Expand Down
16 changes: 6 additions & 10 deletions dependencies/subprojects/animationwindow/src/widgets/Button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,8 @@ TDT4102::Button::Button(TDT4102::Point location, unsigned int width, unsigned in
TDT4102::Widget(location, width, height),
label{std::move(label)} {}

void TDT4102::Button::update(nk_context *context) {
void TDT4102::Button::update(nk_context *context, bool& eventHandled) {

bool rightMouseIsDown = nk_input_has_mouse_click_down_in_rect(&context->input, NK_BUTTON_RIGHT, context->current->layout->clip, true);
bool rightMouseIsBeingPressed = rightMouseIsDown && !lastRightMouseButtonState;
lastRightMouseButtonState = rightMouseIsDown;

bool leftMouseIsDown = nk_input_has_mouse_click_down_in_rect(&context->input, NK_BUTTON_LEFT, context->current->layout->clip, true);
bool leftMouseIsBeingPressed = leftMouseIsDown && !lastLeftMouseButtonState;
lastLeftMouseButtonState = leftMouseIsDown;
struct nk_style* s = &context->style;
nk_style_push_color(context, &s->button.text_normal, labelColor);
nk_style_push_color(context, &s->button.text_hover, labelColor);
Expand All @@ -22,8 +15,11 @@ void TDT4102::Button::update(nk_context *context) {
nk_style_push_style_item(context, &s->button.normal, nk_style_item_color(buttonColor));
nk_style_push_style_item(context, &s->button.hover, nk_style_item_color(buttonColorHover));
nk_style_push_style_item(context, &s->button.active, nk_style_item_color(buttonColorActive));
if (nk_button_label(context, label.c_str()) || rightMouseIsBeingPressed || leftMouseIsBeingPressed) {
fire();
if (nk_button_label(context, label.c_str())) {
if(!eventHandled) {
fire();
eventHandled = true;
}
}
nk_style_pop_color(context);
nk_style_pop_color(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ TDT4102::CheckBox::CheckBox(TDT4102::Point location, unsigned int width, unsigne
TDT4102::Widget(location, width, height),
label{std::move(label)} {}

void TDT4102::CheckBox::update(nk_context *context) {
void TDT4102::CheckBox::update(nk_context *context, bool& eventHandled) {
if (nk_input_has_mouse_click_down_in_rect(&context->input, NK_BUTTON_RIGHT, context->current->layout->clip, true)) {
isSelected_ = false;
}
Expand All @@ -23,7 +23,10 @@ void TDT4102::CheckBox::update(nk_context *context) {

if (nk_checkbox_label(context, label.data(), &isSelected_)) {
isSelected_ = true;
fire();
if(!eventHandled) {
fire();
eventHandled = true;
}
}

nk_style_pop_color(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ std::string TDT4102::DropdownList::getSelectedValue() const {
return options.at(selectedIndex);
}

void TDT4102::DropdownList::update(nk_context *context) {
void TDT4102::DropdownList::update(nk_context *context, bool& eventHandled) {
if (nk_combo_begin_label(context, options.at(selectedIndex).c_str(), nk_vec2(nk_widget_width(context), 200))) {
nk_layout_row_dynamic(context, 35, 1);
for(unsigned int i = 0; i < options.size(); i++) {
if (nk_combo_item_label(context, options.at(i).c_str(), NK_TEXT_LEFT)) {
// selection changed
selectedIndex = i;
fire();
if(!eventHandled) {
fire();
eventHandled = true;
}
}
}
nk_combo_end(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ TDT4102::RadioButton::RadioButton(TDT4102::Point location, unsigned int width, u
TDT4102::Widget(location, width, height),
label{std::move(label)} {}

void TDT4102::RadioButton::update(nk_context *context) {
void TDT4102::RadioButton::update(nk_context *context, bool& eventHandled) {
if (nk_input_has_mouse_click_down_in_rect(&context->input, NK_BUTTON_RIGHT, context->current->layout->clip, true)) {
isSelected_ = false;
}
Expand All @@ -23,7 +23,10 @@ void TDT4102::RadioButton::update(nk_context *context) {

if (nk_radio_label(context, label.data(), &isSelected_)) {
isSelected_ = true;
fire();
if(!eventHandled) {
fire();
eventHandled = true;
}
}

nk_style_pop_color(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ int TDT4102::Slider::getValue() const {
return value;
}

void TDT4102::Slider::update(nk_context *context) {
void TDT4102::Slider::update(nk_context *context, bool& eventHandled) {

struct nk_style* s = &context->style;
nk_style_push_color(context, &s->slider.bar_normal, sliderBarColor);
Expand All @@ -24,7 +24,10 @@ void TDT4102::Slider::update(nk_context *context) {
nk_style_push_style_item(context, &s->slider.cursor_active, nk_style_item_color(sliderCursorColorActive));

if (nk_slider_int(context, minValue, &value, maxValue, stepValue)) {
fire();
if(!eventHandled) {
fire();
eventHandled = true;
}
}

nk_style_pop_color(context);
Expand Down
Loading

0 comments on commit 723c60e

Please sign in to comment.