Skip to content
Snippets Groups Projects
Commit 8cce572b authored by Eila Aurora Huru Bergene's avatar Eila Aurora Huru Bergene
Browse files
parents 0dd2df8b b771f258
No related branches found
No related tags found
No related merge requests found
Showing
with 286 additions and 23 deletions
......@@ -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
......
......@@ -121,5 +121,7 @@ class AnimationWindow {
// Getters for the window dimensions
int width();
int height();
void setBackgroundColor(TDT4102::Color newBackgroundColor);
};
} // namespace TDT4102
......@@ -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 {
......
......@@ -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;
}
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
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')))
#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
#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
#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
}
#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; };
};
#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
}
#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
};
#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();
}
}
#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();
};
#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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment