diff --git a/configuration/.vscode/c_cpp_properties.json b/configuration/.vscode/c_cpp_properties.json index c7ab5a7d6cd093734948a446ccbc6d86bcaf7b88..94fda69aaed4e86b1c0c2f67890a4ff253ec2d6c 100644 --- a/configuration/.vscode/c_cpp_properties.json +++ b/configuration/.vscode/c_cpp_properties.json @@ -13,7 +13,7 @@ "UNICODE", "_UNICODE" ], - "cStandard": "c20", + "cStandard": "c17", "cppStandard": "c++20", "compilerPath": "C:\\TDT4102-mingw64\\bin\\clang", "compileCommands": "${workspaceFolder}/builddir/compile_commands.json", @@ -30,7 +30,7 @@ "UNICODE", "_UNICODE" ], - "cStandard": "c20", + "cStandard": "c17", "cppStandard": "c++20", "compileCommands": "builddir/compile_commands.json", "intelliSenseMode": "macos-clang-x64" @@ -45,11 +45,10 @@ "UNICODE", "_UNICODE" ], - "cStandard": "c20", + "cStandard": "c17", "cppStandard": "c++20", "compileCommands": "builddir/compile_commands.json", - "intelliSenseMode": "linux-clang-x64", - "compilerPath": "/usr/bin/g++" + "intelliSenseMode": "linux-clang-x64" } ], "version": 4 diff --git a/dependencies/subprojects/animationwindow/include/AnimationWindow.h b/dependencies/subprojects/animationwindow/include/AnimationWindow.h index 533b02797222976c6dfff07d382cf253f4bdaaf9..e0c56482f5d9b8dcba9decbcb3c81bee0416dfe6 100644 --- a/dependencies/subprojects/animationwindow/include/AnimationWindow.h +++ b/dependencies/subprojects/animationwindow/include/AnimationWindow.h @@ -121,5 +121,7 @@ class AnimationWindow { // Getters for the window dimensions int width(); int height(); + + void setBackgroundColor(TDT4102::Color newBackgroundColor); }; } // namespace TDT4102 diff --git a/dependencies/subprojects/animationwindow/include/internal/FontCache.h b/dependencies/subprojects/animationwindow/include/internal/FontCache.h index 8bcae3c02b9734b1ee1bbcfd27adf5a0e02ca6b0..761e075c60673d7861b67f8b5ae2de4b8722b048 100644 --- a/dependencies/subprojects/animationwindow/include/internal/FontCache.h +++ b/dependencies/subprojects/animationwindow/include/internal/FontCache.h @@ -23,20 +23,20 @@ namespace TDT4102::internal { }; static const std::unordered_map<TDT4102::Font, std::vector<std::string>> TTFFilenames { - {Font::arial, {"Arial.ttf", "arial.ttf", "LiberationSans.ttf", "LiberationSans-Regular.ttf"}}, - {Font::arial_bold, {"Arial_Bold.ttf", "arialb.ttf", "arialbd.ttf", "Arial Bold.ttf", "LiberationSans-Bold.ttf"}}, - {Font::arial_bold_italic, {"Arial_Bold_Italic.ttf", "arialbi.ttf", "Arial Bold Italic.ttf", "LiberationSans-BoldItalic.ttf"}}, - {Font::arial_italic, {"Arial_Italic.ttf", "ariali.ttf", "Arial Italic.ttf", "LiberationSans-Italic.ttf"}}, - - {Font::courier, {"Courier_New.ttf", "cour.ttf", "Courier New.ttf", "LiberationMono.ttf", "LiberationMono-Regular.ttf"}}, - {Font::courier_bold, {"Courier_New_Bold.ttf", "courbd.ttf", "Courier New Bold.ttf", "LiberationMono-Bold.ttf"}}, - {Font::courier_bold_italic, {"Courier_New_Bold_Italic.ttf", "courbi.ttf", "Courier New Bold Italic.ttf", "LiberationMono-BoldItalic.ttf"}}, - {Font::courier_italic, {"Courier_New_Italic.ttf", "couri.ttf", "Courier New Bold Italic.ttf", "LiberationMono-Italic.ttf"}}, - - {Font::times, {"Times_New_Roman.ttf", "times.ttf", "Times New Roman.ttf", "LiberationSerif.ttf", "LiberationSerif-Regular.ttf"}}, - {Font::times_bold, {"Times_New_Roman_Bold.ttf", "timesb.ttf", "timesbd.ttf", "Times New Roman Bold.ttf", "LiberationSerif-Bold.ttf"}}, - {Font::times_bold_italic, {"Times_New_Roman_Bold_Italic.ttf", "timesbi.ttf", "Times New Roman Bold Italic.ttf", "LiberationSerif-BoldItalic.ttf"}}, - {Font::times_italic, {"Times_New_Roman_Italic.ttf", "timesi.ttf", "Times New Roman Italic.ttf", "LiberationSerif-Italic.ttf"}} + {Font::arial, {"Arial.ttf", "arial.ttf", "LiberationSans.ttf", "LiberationSans-Regular.ttf", "DejaVuSans.ttf"}}, + {Font::arial_bold, {"Arial_Bold.ttf", "arialb.ttf", "arialbd.ttf", "Arial Bold.ttf", "LiberationSans-Bold.ttf", "DejaVuSans-Bold.ttf"}}, + {Font::arial_bold_italic, {"Arial_Bold_Italic.ttf", "arialbi.ttf", "Arial Bold Italic.ttf", "LiberationSans-BoldItalic.ttf", "DejaVuSans-BoldOblique.ttf"}}, + {Font::arial_italic, {"Arial_Italic.ttf", "ariali.ttf", "Arial Italic.ttf", "LiberationSans-Italic.ttf", "DejaVuSans-Oblique.ttf"}}, + + {Font::courier, {"Courier_New.ttf", "cour.ttf", "Courier New.ttf", "LiberationMono.ttf", "LiberationMono-Regular.ttf", "DejaVuSansMono.ttf"}}, + {Font::courier_bold, {"Courier_New_Bold.ttf", "courbd.ttf", "Courier New Bold.ttf", "LiberationMono-Bold.ttf", "DejaVuSansMono-Bold.ttf"}}, + {Font::courier_bold_italic, {"Courier_New_Bold_Italic.ttf", "courbi.ttf", "Courier New Bold Italic.ttf", "LiberationMono-BoldItalic.ttf", "DejaVuSansMono-BoldOblique.ttf"}}, + {Font::courier_italic, {"Courier_New_Italic.ttf", "couri.ttf", "Courier New Bold Italic.ttf", "LiberationMono-Italic.ttf", "DejaVuSansMono-Oblique.ttf"}}, + + {Font::times, {"Times_New_Roman.ttf", "times.ttf", "Times New Roman.ttf", "LiberationSerif.ttf", "LiberationSerif-Regular.ttf", "DejaVuSerif.ttf"}}, + {Font::times_bold, {"Times_New_Roman_Bold.ttf", "timesb.ttf", "timesbd.ttf", "Times New Roman Bold.ttf", "LiberationSerif-Bold.ttf", "DejaVuSerif-Bold.ttf"}}, + {Font::times_bold_italic, {"Times_New_Roman_Bold_Italic.ttf", "timesbi.ttf", "Times New Roman Bold Italic.ttf", "LiberationSerif-BoldItalic.ttf", "DejaVuSerif-BoldItalic.ttf"}}, + {Font::times_italic, {"Times_New_Roman_Italic.ttf", "timesi.ttf", "Times New Roman Italic.ttf", "LiberationSerif-Italic.ttf", "DejaVuSerif-Italic.ttf"}} }; class FontCache { diff --git a/dependencies/subprojects/animationwindow/src/AnimationWindow.cpp b/dependencies/subprojects/animationwindow/src/AnimationWindow.cpp index b1d3f50359beba7abe942fb54fa33fede72b664c..2013c1963668f610bb0c12b7def230ff28328747 100644 --- a/dependencies/subprojects/animationwindow/src/AnimationWindow.cpp +++ b/dependencies/subprojects/animationwindow/src/AnimationWindow.cpp @@ -41,7 +41,7 @@ TDT4102::AnimationWindow::AnimationWindow(int x, int y, int width, int height, c } // Default window background colour - SDL_SetRenderDrawColor(rendererHandle, 0xFF, 0xFF, 0xFF, 0xFF); + SDL_SetRenderDrawColor(rendererHandle, backgroundColour.redChannel, backgroundColour.greenChannel, backgroundColour.blueChannel, backgroundColour.alphaChannel); SDL_RenderClear(rendererHandle); SDL_RendererInfo rendererInfo; @@ -388,3 +388,7 @@ void TDT4102::AnimationWindow::startNuklearDraw(TDT4102::Point location, std::st void TDT4102::AnimationWindow::endNuklearDraw() { nk_end(context); } + +void TDT4102::AnimationWindow::setBackgroundColor(TDT4102::Color newBackgroundColor) { + backgroundColour = newBackgroundColor; +} diff --git a/dependencies/subprojects/sdl2_image_windows/meson.build b/dependencies/subprojects/sdl2_image_windows/meson.build index 2019035d5b642cbd47647b1dbc14f70b2c68304e..033e61f3a27191c27b1f7e5ba76631a77025f127 100644 --- a/dependencies/subprojects/sdl2_image_windows/meson.build +++ b/dependencies/subprojects/sdl2_image_windows/meson.build @@ -1,6 +1,15 @@ project('sdl2_image_windows', 'cpp') +fs = import('fs') + +new_dir = join_paths('C:/TDT4102-mingw64','SDL2','sdl2_image_lib') +old_dir = join_paths(meson.current_source_dir(), 'lib') +#Ensuring backwards compatability in transition when SDL2 can be both places +dir_to_use = fs.exists(new_dir) ? new_dir : old_dir + cxx = meson.get_compiler('cpp') sdl2_image_windows_dep = declare_dependency( - dependencies : [cxx.find_library('SDL2_image', dirs : join_paths(meson.current_source_dir(), 'lib'))], + dependencies : [cxx.find_library('SDL2_image', dirs : dir_to_use)], include_directories : include_directories(join_paths('include', 'SDL2'))) + + \ No newline at end of file diff --git a/dependencies/subprojects/sdl2_windows/meson.build b/dependencies/subprojects/sdl2_windows/meson.build index f24b47750c2c134f5a36ecf9eac138f5390ef42b..09d8f7699373532da43eefbc82bf794382669cfa 100644 --- a/dependencies/subprojects/sdl2_windows/meson.build +++ b/dependencies/subprojects/sdl2_windows/meson.build @@ -1,8 +1,16 @@ project('sdl2_windows', 'cpp') +fs = import('fs') + +new_dir = join_paths('C:/TDT4102-mingw64','SDL2','sdl2_lib') +old_dir = join_paths(meson.current_source_dir(), 'lib') +#Ensuring backwards compatability in transition when SDL2 can be both places +dir_to_use = fs.exists(new_dir) ? new_dir : old_dir + cxx = meson.get_compiler('cpp') sdl2_windows_dep = declare_dependency( - dependencies : [cxx.find_library('SDL2main', dirs : join_paths(meson.current_source_dir(), 'lib')), - cxx.find_library('SDL2', dirs : join_paths(meson.current_source_dir(), 'lib'))], + dependencies : [cxx.find_library('SDL2main', dirs : dir_to_use), + cxx.find_library('SDL2', dirs : dir_to_use)], link_args: ['-lmingw32'], include_directories : include_directories(join_paths('include', 'SDL2'))) + diff --git a/templates/_folder_Lectures/Lecture 14 - handout/Stopwatch.cpp b/templates/_folder_Lectures/Lecture 14 - handout/Stopwatch.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a4be1c713aee747fd38ae5ad501e6a18470ac223 --- /dev/null +++ b/templates/_folder_Lectures/Lecture 14 - handout/Stopwatch.cpp @@ -0,0 +1,12 @@ +#include "Stopwatch.h" + +void Stopwatch::start() { + startTime = std::chrono::steady_clock::now(); +} + +double Stopwatch::stop() { + std::chrono::time_point endTime = std::chrono::steady_clock::now(); + long durationInMicroseconds = std::chrono::duration_cast<std::chrono::microseconds>(endTime - startTime).count(); + double durationInSeconds = double(durationInMicroseconds)/1000000.0; + return durationInSeconds; +} \ No newline at end of file diff --git a/templates/_folder_Lectures/Lecture 14 - handout/Stopwatch.h b/templates/_folder_Lectures/Lecture 14 - handout/Stopwatch.h new file mode 100644 index 0000000000000000000000000000000000000000..307f3835665aae16d34019c05d3012e877da6200 --- /dev/null +++ b/templates/_folder_Lectures/Lecture 14 - handout/Stopwatch.h @@ -0,0 +1,20 @@ +#pragma once +#include <iostream> +#include <chrono> + +// This class abstracts some (somewhat) nasty code that is +// definitely outside the scope of this course. +// Its main purpose is to return the amount of time +// taken by the program in main.cpp + +// Calling start() starts the stopwatch +// Calling stop() stops it and returns the amount of time +// that has elapsed since start() was called in seconds + +class Stopwatch { + std::chrono::time_point<std::chrono::steady_clock> startTime; + +public: + void start(); + double stop(); +}; \ No newline at end of file diff --git a/templates/_folder_Lectures/O10 - handout/Box.cpp b/templates/_folder_Lectures/O10 - handout/Box.cpp new file mode 100644 index 0000000000000000000000000000000000000000..460efb173cf5f259aefc5dc7194bd15d62bf6a82 --- /dev/null +++ b/templates/_folder_Lectures/O10 - handout/Box.cpp @@ -0,0 +1,17 @@ +#include "Box.h" + + +void Box::open() { + //hvis boksen er lukket, skal den åpnes (settes til trykket på) + //labelen skal settes til open-labelen + //label color skal settes til rød + +} + +void Box::close() { + // Lukk boksen + //sette riktig label og farge +} + + + diff --git a/templates/_folder_Lectures/O10 - handout/Box.h b/templates/_folder_Lectures/O10 - handout/Box.h new file mode 100644 index 0000000000000000000000000000000000000000..4e29bb401cd8fdf9edb3e79d49a54c36d104c3bc --- /dev/null +++ b/templates/_folder_Lectures/O10 - handout/Box.h @@ -0,0 +1,21 @@ +#pragma once +#include "widgets/Button.h" +#include <map> + +enum class Cell { closed, open }; + +class Box : public TDT4102::Button { + Cell state = Cell::closed; //begynner default som lukket + std::map<Cell, std::string> cellToSymbol { + {Cell::closed, "Trykk her!"}, + {Cell::open, "Bø"} + }; + +public: + Box(int x, int y, int width, int height) : TDT4102::Button(TDT4102::Point{x, y}, width, height, "Trykk her!") {}; + + void open(); //funksjon som skal åpne boksen + void close(); //funksjon som skal lukke boksen + + Cell getState() const { return state; }; +}; diff --git a/templates/_folder_Lectures/O10 - handout/ClickWindow.cpp b/templates/_folder_Lectures/O10 - handout/ClickWindow.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ae4011706ca50a2722d43a508c00bac5d59e697e --- /dev/null +++ b/templates/_folder_Lectures/O10 - handout/ClickWindow.cpp @@ -0,0 +1,55 @@ +#include "ClickWindow.h" + +ClickWindow::ClickWindow(int x, int y, int width, int height, int clicks, const std::string &title) : + // Initialiser medlemsvariabler, bruker konstruktoren til AnimationWindow-klassen + AnimationWindow{x, y, width, height, title}, + clicks{clicks}, + remainingClicks{clicks} + //initialisere de ulike knappene +{ + //legge til callback på de ulike knappene og adde dem til vinduet + + //Hvis det er noen knapper vi ikke vil skal synes fra start, kan vi kalle .setVisible(false) på dem + + +} + + +void ClickWindow::decreasing() { + //denne funksjonen skal kalles når man venstreklikker og skal telle ned antall klikk fra click variabelen + //remainingClicks må minke med 1 hver gang denne funksjonen kalles + + //Hvis remainingClicks = 0, skal man få opp quit og restart-knapper + + + //Hvis remainingClicks er mindre enn begynnende antall klikk, men større enn null, skal knappen være grønn + + //Hvis remainingClicks er mindre enn null, skal knappen hver gang man trykker få en random farge + + //I alle tilfellene skal labelen til knappen oppdateres slik at det står remainingClicks +} + +void ClickWindow::increasing() { + //funksjonen kalles når man høyreklikker. Da skal remainingClicks øke med 1 for hver gang + //Hvis remainingClicks er større enn antall klikk vi begynte med, skal knappen bli rød + //Husk å oppdatere knappens label +} + +void ClickWindow::click() { + + if (this->is_left_mouse_button_down()) { + decreasing(); + } + else if(this->is_right_mouse_button_down()){ + increasing(); + } +} + +void ClickWindow::restart() { + + //Funksjonen som kalles når man trykker på restart-knappen + //skal gjenopprette remainingClicks til clicks + //skjule restart og quit-knappene + //label og color for knappen må også gjøres om til det man begynte med +} + diff --git a/templates/_folder_Lectures/O10 - handout/ClickWindow.h b/templates/_folder_Lectures/O10 - handout/ClickWindow.h new file mode 100644 index 0000000000000000000000000000000000000000..ef6ca0fb10046f972bb04c06f67c6e29305b0ef0 --- /dev/null +++ b/templates/_folder_Lectures/O10 - handout/ClickWindow.h @@ -0,0 +1,29 @@ +#pragma once +#include "AnimationWindow.h" +#include "widgets/TextInput.h" +#include "widgets/Button.h" +#include <random> + +class ClickWindow : public TDT4102::AnimationWindow { +public: + ClickWindow(int x, int y, int width, int height, int clicks, const std::string& title); + +private: + const int clicks; // Antall klikk + int remainingClicks; //Antall klikk igjen + + + void decreasing(); + void increasing(); + + //callback-funksjonene + void cb_quit() { this->close(); }; + void cb_restart() { this->restart(); } + void cb_click() { this->click(); }; + void restart(); + void click(); + + //Lage tre knapper (lukke, åpne, klikk) + + //Kan legge til en TDT4102::TextInput som skal gi en tilbakemelding til spilleren +}; diff --git a/templates/_folder_Lectures/O10 - handout/MultiplyingWindow.cpp b/templates/_folder_Lectures/O10 - handout/MultiplyingWindow.cpp new file mode 100644 index 0000000000000000000000000000000000000000..642fadc1078c77e62ba081c5374b511c5d1e6f68 --- /dev/null +++ b/templates/_folder_Lectures/O10 - handout/MultiplyingWindow.cpp @@ -0,0 +1,45 @@ +#include "MultiplyingWindow.h" + +MultiplyingWindow::MultiplyingWindow(int x, int y, int width, int height, int multipleNumber, const std::string &title) : + // Initialiser medlemsvariabler, bruker konstruktoren til AnimationWindow-klassen + AnimationWindow{x, y, width, height, title}, + multiple{multipleNumber}, + width{width}, + height{height} +{ + //Skal lage den første boksen som skal komme opp og legge den til i buttons-vektoren + //Vi må sette riktig label, legge til callback og adde den til vinduet +} + + +void MultiplyingWindow::multiplying() { + //når denne funksjonen kalles har det blitt trykt - skal lage flere knapper + //må huske å legge de til i buttons + //ønsker at de skal plasseres random i vinuet + + + //I tillegg må vi, hvis knappene er åpne, lukke dem og sette bredde/høyde til mindre + //hvis vi vil, kan vi gi dem en random farge + + +} + +void MultiplyingWindow::multiplyingRecursive(int count, int width, int height) { + +} + +void MultiplyingWindow::nothing() { + //når denne funksjonen kalles skal man åpne alle knappene i buttons-vektoren + +} + + +void MultiplyingWindow::click() { + + if (this->is_left_mouse_button_down()) { + multiplying(); + } else if (this->is_right_mouse_button_down()) { + nothing(); + } +} + diff --git a/templates/_folder_Lectures/O10 - handout/MultiplyingWindow.h b/templates/_folder_Lectures/O10 - handout/MultiplyingWindow.h new file mode 100644 index 0000000000000000000000000000000000000000..2e86413b4413242e2452b276c5719eb3625d1b36 --- /dev/null +++ b/templates/_folder_Lectures/O10 - handout/MultiplyingWindow.h @@ -0,0 +1,24 @@ +#pragma once +#include "AnimationWindow.h" +#include "Box.h" +#include <random> + + +class MultiplyingWindow : public TDT4102::AnimationWindow { +public: + MultiplyingWindow(int x, int y, int width, int height, int multipleNumber, const std::string& title); + +private: + const int multiple; //antall den skal multiplisere seg med + const int width; //bredden til vinduet + const int height; //høyden til vinduet + + std::vector<std::shared_ptr<Box>> buttons; //lagrer pekere til alle knappene i en vektor + + void multiplying(); + void multiplyingRecursive(int count, int width, int height); + void nothing(); + + void cb_click() { this->click(); }; //callback-funksjonen + void click(); +}; diff --git a/templates/_folder_Lectures/O10 - handout/main.cpp b/templates/_folder_Lectures/O10 - handout/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c928e1f52461be54ce1a3929ad5d776378bbd26a --- /dev/null +++ b/templates/_folder_Lectures/O10 - handout/main.cpp @@ -0,0 +1,18 @@ +#include "ClickWindow.h" +#include "MultiplyingWindow.h" +#include "Box.h" + +int main() { + + constexpr int width = 700; + constexpr int height = 700; + constexpr int clicks = 10; + constexpr int multiple = 5; + + TDT4102::Point startPoint{ 200, 300 }; + + // lag vindu og kall wait_for_close() + + + return 0; +}