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
bartiver authored Mar 9, 2026
2 parents 288ba44 + c2943f2 commit e460d7a
Show file tree
Hide file tree
Showing 327 changed files with 2,244,773 additions and 10,820 deletions.
33 changes: 6 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,12 @@
# TDT4102 Resources repo

This repo is now stripped down, so wysiwyg (what you see is what you get).
REMEMBER: From immediately after the summer of 2022 this repo deprecates the following:
This repo contains the following:

- <https://gitlab.stud.idi.ntnu.no/tdt4102/ovinger/oving-0>
- <https://gitlab.stud.idi.ntnu.no/tdt4102/vs-code/TDT4102>
- <https://gitlab.stud.idi.ntnu.no/tdt4102/vs-code/examples>
- <https://gitlab.stud.idi.ntnu.no/tdt4102/infobank>
- <https://gitlab.stud.idi.ntnu.no/tdt4102/graph_lib>
- <https://gitlab.stud.idi.ntnu.no/tdt4102/ovinger/utdelt>
- Build configurations
- Our graphics library with dependencies
- Infobank with pdfs and small articles about certain topics
- Project templates
- Windows specific setup

as they are now files inside the repo instead of subprojects. DELETE these repos to avoid confusion.

## Setup

`git clone https://gitlab.stud.idi.ntnu.no/tdt4102/vs-code/resources` copies the repo to your computer in a subfolder of the folder where you run the command from.

Hot tip for windows users: In File Explorer (filutforsker) navigate to the chosen folder, and then type `cmd` in the navigation bar to open command prompt in the correct folder.

## Walkthrough: Adding articles to infobank

### Do the changes

Change any file in the repo. Make sure you are happy with it.

### Publishing

Just use git. If you don't know git, see mini-tutorial underneath.

`git add .` adds all files to staging area.
`git commit -m "<message about what you changed>` saves the changes.
`git push` publishes the changes. The extension will automatically detect that changes are made and pull them.
13 changes: 7 additions & 6 deletions configuration/.vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"${workspaceFolder}/**",
"${workspaceFolder}/subprojects/animationwindow/include/**",
"${workspaceFolder}/subprojects/sdl2_image_windows/include/**",
"${workspaceFolder}/subprojects/sdl2_mixer_windows/include/**",
"${workspaceFolder}/subprojects/sdl2_windows/include/**"
],
"defines": [
Expand All @@ -15,9 +16,9 @@
],
"cStandard": "c17",
"cppStandard": "c++20",
"compilerPath": "C:\\TDT4102-mingw64\\bin\\clang",
"compileCommands": "${workspaceFolder}/builddir/compile_commands.json",
"intelliSenseMode": "windows-clang-x64"
"compilerPath": "C:\\TDT4102-mingw64\\bin\\gcc",
"compileCommands": "${workspaceFolder}/build/compile_commands.json",
"intelliSenseMode": "windows-gcc-x64"
},
{
"name": "Mac",
Expand All @@ -32,7 +33,7 @@
],
"cStandard": "c17",
"cppStandard": "c++20",
"compileCommands": "builddir/compile_commands.json",
"compileCommands": "build/compile_commands.json",
"intelliSenseMode": "macos-clang-x64"
},
{
Expand All @@ -47,8 +48,8 @@
],
"cStandard": "c17",
"cppStandard": "c++20",
"compileCommands": "builddir/compile_commands.json",
"intelliSenseMode": "linux-clang-x64"
"compileCommands": "build/compile_commands.json",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
Expand Down
1 change: 0 additions & 1 deletion configuration/.vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"ms-vscode.cpptools",
"vadimcn.vscode-lldb",
"tomoki1207.pdf"
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
Expand Down
10 changes: 10 additions & 0 deletions configuration/.vscode/keybindings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{ "key": "ctrl+f5", "command": "workbench.action.tasks.runTask",
"args": "Run Program", "when": "isMac" },

{ "key": "ctrl+f5", "command": "workbench.action.tasks.runTask",
"args": "Run Program", "when": "isLinux" },

{ "key": "ctrl+f5", "command": "workbench.action.tasks.runTask",
"args": "Run Program", "when": "isWindows" }
]
38 changes: 25 additions & 13 deletions configuration/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
{
"configurations": [
{
"name": "Build and Run Debug",
"type": "lldb",
"request": "launch",
"program": "${workspaceFolder}/builddir/program",
"args": [],
"cwd": "${workspaceFolder}",
"preLaunchTask": "Build Executable",
"internalConsoleOptions": "neverOpen",
}
]
}
"configurations": [
{
"name": "Build and Run Debug (Windows/Linux)",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/program",
"cwd": "${workspaceFolder}",
"args": [],
"preLaunchTask": "Build Executable",
"internalConsoleOptions": "neverOpen"
},
{
"name": "Build and Run Debug (macOS)",
"type": "lldb",
"request": "launch",
"program": "${workspaceFolder}/build/program",
"cwd": "${workspaceFolder}",
"args": [],
"preLaunchTask": "Build Executable",
"internalConsoleOptions": "neverOpen"
},


]
}
14 changes: 13 additions & 1 deletion configuration/.vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "shell",
"label": "Build Executable",
"command": "meson",
"args": ["compile", "-Cbuilddir"],
"args": ["compile", "-Cbuild"],
"group": {
"kind": "build",
"isDefault": true
Expand All @@ -18,6 +18,18 @@
"showReuseMessage": true,
"clear": true
}
},
{
"type": "shell",
"label": "Run Program",
"dependsOn": "Build Executable",
"command": "${workspaceFolder}/build/program",
"options": { "cwd": "${workspaceFolder}" },
"linux": { "command": "${workspaceFolder}/build/program" },
"windows": { "command": "${workspaceFolder}\\build\\program.exe" },
"osx": { "command": "${workspaceFolder}/build/program" },
"problemMatcher": []
}

]
}
23 changes: 8 additions & 15 deletions configuration/gui/meson.build
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
project('GUI Project', 'cpp',
version : '0.1',
default_options : ['warning_level=2',
'cpp_std=c++20',
'cpp_std=c++23',
'c_std=c17',
'default_library=static'])

# Windows compilation has no pre-packaged SDL2 available, and compilation takes a while.
# If you want to compile from source, remove everything but the contents of the else clause.
if host_machine.system() == 'windows'
sdl2_dep = subproject('sdl2_windows').get_variable('sdl2_windows_dep')
else
sdl2_dep = dependency('sdl2')
endif

animationwindow_dep = dependency('animationwindow', fallback: ['animationwindow', 'animationwindow_dep'])
std_lib_facilities_dep = dependency('std_lib_facilities', fallback: ['std_lib_facilities', 'std_lib_facilities_dep'])

compiler_flags = ['-Wconversion', '-fdiagnostics-color=always', '-Werror=return-type', '-static']

if host_machine.system() == 'linux'
compiler_flags = ['-Wconversion', '-fdiagnostics-color=always', '-Werror=return-type']
src = ['main.cpp']

if host_machine.system() == 'windows'
ld_flags = ['-static', '-lstdc++exp']
else
compiler_flags = ['-Wconversion', '-fdiagnostics-color=always', '-Werror=return-type', '-fcolor-diagnostics', '-fansi-escape-codes']
ld_flags = []
endif

src = ['main.cpp']

exe = executable('program', src, dependencies : [animationwindow_dep, sdl2_dep, std_lib_facilities_dep], cpp_args : compiler_flags)
exe = executable('program', src, dependencies : [std_lib_facilities_dep, animationwindow_dep], cpp_args : compiler_flags, link_args: ld_flags)
16 changes: 9 additions & 7 deletions configuration/nogui/meson.build
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
project('CLI Project', 'cpp',
version : '0.1',
default_options : ['warning_level=2',
'cpp_std=c++20',
'cpp_std=c++23',
'c_std=c17',
'default_library=static'])

std_lib_facilities_dep = dependency('std_lib_facilities', fallback: ['std_lib_facilities', 'std_lib_facilities_dep'])

if host_machine.system() == 'linux'
compiler_flags = ['-Wconversion', '-fdiagnostics-color=always', '-Werror=return-type']
else
compiler_flags = ['-Wconversion', '-fdiagnostics-color=always', '-Werror=return-type', '-fcolor-diagnostics', '-fansi-escape-codes']
endif
compiler_flags = ['-Wconversion', '-fdiagnostics-color=always', '-Werror=return-type', '-static']

src = ['main.cpp']

exe = executable('program', src, dependencies : [std_lib_facilities_dep], cpp_args : compiler_flags)
if host_machine.system() == 'windows'
ld_flags = ['-static', '-lstdc++exp']
else
ld_flags = []
endif

exe = executable('program', src, dependencies : [std_lib_facilities_dep], cpp_args : compiler_flags, link_args: ld_flags)
6 changes: 3 additions & 3 deletions dependencies/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This is the simple graphics library made for TDT4102.

## Commands

`meson setup builddir` - Set up builddir
`meson compile -C builddir` - Temporarily cd into builddir and compile
`meson install -C builddir --destdir ${env:AppData}/tdt4102/animationwindow` - Install files into folder in appdata. Is useful for testing
`meson setup build` - Set up a build-directory
`meson compile -C build` - Temporarily cd into the build-directory and compile
`meson install -C build --destdir ${env:AppData}/tdt4102/animationwindow` - Install files into folder in appdata. Is useful for testing
Note that the `animationwindow.pc` generated is not relocateable. This will not be available as a feature until meson 0.63.0. Therefore we modify line 1 to be `prefix=${pcfiledir}/../..` manually.
Binary file added dependencies/song.mp3
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "Color.h"
#include "Font.h"
#include "Image.h"
#include "Audio.h"
#include "KeyboardKey.h"
#include "Point.h"
#include "Widget.h"
Expand Down Expand Up @@ -101,7 +102,7 @@ class AnimationWindow {
// They allow you to draw a variety of different shapes.
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);
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_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);
Expand Down Expand Up @@ -129,5 +130,8 @@ class AnimationWindow {
void setBackgroundColor(TDT4102::Color newBackgroundColor);

float get_delta_mouse_wheel() const;

//
void play_audio(TDT4102::Audio& audio, int loops = 0);
};
} // namespace TDT4102
29 changes: 29 additions & 0 deletions dependencies/subprojects/animationwindow/include/Audio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include <string>
#include <filesystem>
#include <SDL_mixer.h>

namespace TDT4102 {
struct Audio {
// Allow the audio to be read out and played despite being private
friend class AnimationWindow;

public:
explicit Audio();
explicit Audio(std::filesystem::path pathToAudioFile);
~Audio();


private:
Mix_Chunk *sfx = nullptr;
Mix_Music *mus = nullptr;
bool ready = false; // flag to load audio before playing
bool isMusic = false;

std::filesystem::path src = "non existent file";

void load();
void play(int loops = 0);
};
}
4 changes: 3 additions & 1 deletion dependencies/subprojects/animationwindow/include/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ namespace TDT4102 {
ImageState state = ImageState::Invalidated;

void load(SDL_Renderer* renderer);

void draw(SDL_Renderer* renderer, TDT4102::Point location,
int imageWidth = 0, int imageHeight = 0);
int imageWidth = 0, int imageHeight = 0,
double angleDegrees = 0, TDT4102::Point rotationOrigin = {0, 0});

/// Does conditional texture cleanup.
/// Unsets the associated texture pointer
Expand Down
11 changes: 9 additions & 2 deletions dependencies/subprojects/animationwindow/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ project('animationwindow', ['c', 'cpp'], version: '0.01', default_options: ['cpp
if host_machine.system() == 'windows'
sdl2_dep = subproject('sdl2_windows').get_variable('sdl2_windows_dep')
sdl2image_dep = subproject('sdl2_image_windows').get_variable('sdl2_image_windows_dep')
sdl2mixer_dep = subproject('sdl2_mixer_windows').get_variable('sdl2_mixer_windows_dep')
else
sdl2_dep = dependency('sdl2')
sdl2image_dep = dependency('sdl2_image')
sdl2mixer_dep = dependency('SDL2_mixer')
endif


Expand All @@ -23,13 +25,18 @@ build_files = [
'src/AnimationWindow.cpp',
'src/Color.cpp',
'src/Image.cpp',
'src/Audio.cpp',
'src/Widget.cpp']
incdir = include_directories('include')
animationwindow = static_library('animationwindow', build_files, include_directories: incdir, dependencies: [sdl2_dep, sdl2image_dep], install: true)
animationwindow = static_library('animationwindow', build_files, include_directories: incdir, dependencies: [sdl2_dep, sdl2image_dep, sdl2mixer_dep], install: true)
install_subdir('include', install_dir: '.')
install_subdir('src', install_dir: '.')

animationwindow_dep = declare_dependency(link_with: animationwindow, include_directories: incdir)
animationwindow_dep = declare_dependency(
link_with: animationwindow,
include_directories: incdir,
dependencies: [sdl2_dep, sdl2image_dep, sdl2mixer_dep]
)

import('pkgconfig').generate(animationwindow)

Expand Down
13 changes: 10 additions & 3 deletions dependencies/subprojects/animationwindow/src/AnimationWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static bool sdlHasBeenInitialised = false;
TDT4102::AnimationWindow::AnimationWindow(int x, int y, int width, int height, const std::string& title) {
// Initialise SDL if it has not already been
if (!sdlHasBeenInitialised) {
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
throw std::runtime_error("Failed to create an AnimationWindow: The SDL backend could not be initialised.\nError details: " + std::string(SDL_GetError()));
}
sdlHasBeenInitialised = true;
Expand All @@ -44,6 +44,8 @@ TDT4102::AnimationWindow::AnimationWindow(int x, int y, int width, int height, c
SDL_SetRenderDrawColor(rendererHandle, backgroundColor.redChannel, backgroundColor.greenChannel, backgroundColor.blueChannel, backgroundColor.alphaChannel);
SDL_RenderClear(rendererHandle);

SDL_SetRenderDrawBlendMode(rendererHandle, SDL_BLENDMODE_BLEND);

SDL_RendererInfo rendererInfo;
SDL_GetRendererInfo(rendererHandle, &rendererInfo);

Expand Down Expand Up @@ -253,8 +255,8 @@ void TDT4102::AnimationWindow::draw_rectangle(TDT4102::Point topLeftPoint, int w
}
}

void TDT4102::AnimationWindow::draw_image(TDT4102::Point topLeftPoint, TDT4102::Image& image, int imageWidth, int imageHeight) {
image.draw(rendererHandle, topLeftPoint, imageWidth, imageHeight);
void TDT4102::AnimationWindow::draw_image(TDT4102::Point topLeftPoint, TDT4102::Image& image, int imageWidth, int imageHeight, double rotationAngleDegrees, TDT4102::Point rotationOrigin) {
image.draw(rendererHandle, topLeftPoint, imageWidth, imageHeight, rotationAngleDegrees, rotationOrigin);
}

void TDT4102::AnimationWindow::draw_text(TDT4102::Point topLeftPoint, std::string textToShow, TDT4102::Color color, unsigned int fontSize, TDT4102::Font font) {
Expand Down Expand Up @@ -415,3 +417,8 @@ void TDT4102::AnimationWindow::setBackgroundColor(TDT4102::Color newBackgroundCo
SDL_SetRenderDrawColor(rendererHandle, backgroundColor.redChannel, backgroundColor.greenChannel, backgroundColor.blueChannel, backgroundColor.alphaChannel);
SDL_RenderClear(rendererHandle);
}

void TDT4102::AnimationWindow::play_audio(TDT4102::Audio& audio, int loops) {
audio.play(loops);
}

Loading

0 comments on commit e460d7a

Please sign in to comment.