<commit_before>#include "guiwindow.h"

#include "barcolor.h"
#include "imagebackground.h"
#include "textbutton.h"
#include "group.h"
#include "multiframe.h"
#include "textitem.h"
#include "textboxdraw.h"
#include "inputnumberformatter.h"
#include "choosenbrofplayers.h"

#include "gamesprite.h"
#include "gamefont.h"

#include <mw/font.h>
#include <mw/sprite.h>
#include <mw/window.h>

#include <iostream>
#include <string>

namespace gui {

	GuiWindow::GuiWindow() : mw::Window(500,600,"MWetris","images/tetris.bmp") {
		playFrameIndex_ = multiFrame_.addFrameBack();
		highscoreFrameIndex_ = multiFrame_.addFrameBack();
		customFrameIndex_ = multiFrame_.addFrameBack();
		optionFrameIndex_ = multiFrame_.addFrameBack();

		auto background = std::make_shared<ImageBackground>(spriteBackground);
		multiFrame_.setBackground(background,0);
		multiFrame_.setBackground(background,playFrameIndex_);
		multiFrame_.setBackground(background,highscoreFrameIndex_);
		multiFrame_.setBackground(background,customFrameIndex_);
		multiFrame_.setBackground(background,optionFrameIndex_);

		hDistance_ = 30;

		initFrameMenu();
		initHighscoreFrame();
		initPlayFrame();
		initCustomPlayFrame();
		initOptionFrame();

		multiFrame_.setCurrentFrame(0);
		mw::Window::setUnicodeInputEnable(true);
		resize(500,600);

		pauseKey_ = SDLK_p;
		restartKey_ = SDLK_F2;
	}

	void GuiWindow::quit() {
		setQuiting(true);
	}

	ButtonPtr GuiWindow::createTextButton(std::string text, int size, std::function<void(GuiItem*)> onClick) {
		Color textColor(1.0,0.1,0.1);
		Color focus(0.8, 0.1, 0, 0.3);
		Color onHover(0.6, 0.1, 0.1);
		Color notHover(0.4, 0.0, 0.0,0.0);
		Color pushed(0.8, 0.0, 0, 0.7);
		ButtonPtr button(new TextButton(text, size, fontDefault,
			textColor,focus,onHover,notHover,pushed));
		button->addOnClickListener(onClick);
		return button;
	}

	TextBoxPtr GuiWindow::createTextBox(int size) {
		Color textColor(1.0,1.0,1.0);
		Color focus(0.8, 0.1, 0, 0.3);
		Color onHover(0.6, 0.1, 0.1);
		return TextBoxPtr(new TextBoxDraw(size, fontDefault, 30, textColor, focus, onHover));
	}

	void GuiWindow::initFrameMenu() {
		multiFrame_.setCurrentFrame(0);
		multiFrame_.add(std::make_shared<TextItem>("MWetris",fontDefault50,80,Color(0.9,0.2,0,0.9)),10,50,false,true);
		multiFrame_.add(std::make_shared<TextItem>("Made by <NAME>",fontDefault18,12,Color(0.9,0.2,0,0.9)),0,0,true,false);

		// Upper bar.		
		multiFrame_.addBar(std::make_shared<BarColor>(Bar::UP,hDistance_,Color(0.5,0,0,0.30)));

		// Text is outside due to invY which dont know where the top of the text begin.
		// The bottom is put where it is supposed to but the invers not.
		ButtonPtr b1 = createTextButton("Resume", hDistance_, [&](GuiItem*) {
			multiFrame_.setCurrentFrame(playFrameIndex_);
		});
		resumeButton_ = b1;
		resumeButton_->setVisible(false);

		// Menu.
		ButtonPtr b2 = createTextButton("Play", 35, [&](GuiItem*) {
			resumeButton_->setVisible(true);
			multiFrame_.setCurrentFrame(playFrameIndex_);
			restartGame();			
		});

		ButtonPtr b3 = createTextButton("Custom play", 35, [&](GuiItem*) {
			multiFrame_.setCurrentFrame(customFrameIndex_);
		});
		ButtonPtr b4 = createTextButton("Highscore", 35, [&](GuiItem*) {
			multiFrame_.setCurrentFrame(highscoreFrameIndex_);
		});
		ButtonPtr b5 = createTextButton("Options", 35, [&](GuiItem*) {
			multiFrame_.setCurrentFrame(optionFrameIndex_);
		});
		ButtonPtr b6 = createTextButton("Exit", 35, [&](GuiItem*) {
			quit();
		});
		b6->addSdlEventListener([&](GuiItem* item, const SDL_Event& sdlEvent) {
			switch (sdlEvent.type) {
			case SDL_KEYDOWN:
				SDLKey key = sdlEvent.key.keysym.sym;
				if (key == SDLK_ESCAPE) {
					quit();
					break;
				}
			}
		});

		int x = 10;
		int y = 150;
		int distance = 50;

		// In Bar.
		multiFrame_.add(b1,0,0,false,true);
<commit_msg>Fixed! Closing the window now makes it close.<commit_after>#include "guiwindow.h"

#include "barcolor.h"
#include "imagebackground.h"
#include "textbutton.h"
#include "group.h"
#include "multiframe.h"
#include "textitem.h"
#include "textboxdraw.h"
#include "inputnumberformatter.h"
#include "choosenbrofplayers.h"

#include "gamesprite.h"
#include "gamefont.h"

#include <mw/font.h>
#include <mw/sprite.h>
#include <mw/window.h>

#include <iostream>
#include <string>

namespace gui {

	GuiWindow::GuiWindow() : mw::Window(500,600,"MWetris","images/tetris.bmp") {
		playFrameIndex_ = multiFrame_.addFrameBack();
		highscoreFrameIndex_ = multiFrame_.addFrameBack();
		customFrameIndex_ = multiFrame_.addFrameBack();
		optionFrameIndex_ = multiFrame_.addFrameBack();

		auto background = std::make_shared<ImageBackground>(spriteBackground);
		multiFrame_.setBackground(background,0);
		multiFrame_.setBackground(background,playFrameIndex_);
		multiFrame_.setBackground(background,highscoreFrameIndex_);
		multiFrame_.setBackground(background,customFrameIndex_);
		multiFrame_.setBackground(background,optionFrameIndex_);

		hDistance_ = 30;

		initFrameMenu();
		initHighscoreFrame();
		initPlayFrame();
		initCustomPlayFrame();
		initOptionFrame();

		multiFrame_.setCurrentFrame(0);
		mw::Window::setUnicodeInputEnable(true);
		resize(500,600);

		pauseKey_ = SDLK_p;
		restartKey_ = SDLK_F2;
	}

	void GuiWindow::quit() {
		setQuiting(true);
	}

	ButtonPtr GuiWindow::createTextButton(std::string text, int size, std::function<void(GuiItem*)> onClick) {
		Color textColor(1.0,0.1,0.1);
		Color focus(0.8, 0.1, 0, 0.3);
		Color onHover(0.6, 0.1, 0.1);
		Color notHover(0.4, 0.0, 0.0,0.0);
		Color pushed(0.8, 0.0, 0, 0.7);
		ButtonPtr button(new TextButton(text, size, fontDefault,
			textColor,focus,onHover,notHover,pushed));
		button->addOnClickListener(onClick);
		return button;
	}

	TextBoxPtr GuiWindow::createTextBox(int size) {
		Color textColor(1.0,1.0,1.0);
		Color focus(0.8, 0.1, 0, 0.3);
		Color onHover(0.6, 0.1, 0.1);
		return TextBoxPtr(new TextBoxDraw(size, fontDefault, 30, textColor, focus, onHover));
	}

	void GuiWindow::initFrameMenu() {
		multiFrame_.setCurrentFrame(0);
		multiFrame_.add(std::make_shared<TextItem>("MWetris",fontDefault50,80,Color(0.9,0.2,0,0.9)),10,50,false,true);
		multiFrame_.add(std::make_shared<TextItem>("Made by <NAME>",fontDefault18,12,Color(0.9,0.2,0,0.9)),0,0,true,false);

		// Upper bar.		
		multiFrame_.addBar(std::make_shared<BarColor>(Bar::UP,hDistance_,Color(0.5,0,0,0.30)));

		// Text is outside due to invY which dont know where the top of the text begin.
		// The bottom is put where it is supposed to but the invers not.
		ButtonPtr b1 = createTextButton("Resume", hDistance_, [&](GuiItem*) {
			multiFrame_.setCurrentFrame(playFrameIndex_);
		});
		resumeButton_ = b1;
		resumeButton_->setVisible(false);

		// Menu.
		ButtonPtr b2 = createTextButton("Play", 35, [&](GuiItem*) {
			resumeButton_->setVisible(true);
			multiFrame_.setCurrentFrame(playFrameIndex_);
			restartGame();			
		});

		ButtonPtr b3 = createTextButton("Custom play", 35, [&](GuiItem*) {
			multiFrame_.setCurrentFrame(customFrameIndex_);
		});
		ButtonPtr b4 = createTextButton("Highscore", 35, [&](GuiItem*) {
			multiFrame_.setCurrentFrame(highscoreFrameIndex_);
		});
		ButtonPtr b5 = createTextButton("Options", 35, [&](GuiItem*) {
			multiFrame_.setCurrentFrame(optionFrameIndex_);
		});
		ButtonPtr b6 = createTextButton("Exit", 35, [&](GuiItem*) {
			quit();
		});
		b6->addSdlEventListener([&](GuiItem* item, const SDL_Event& sdlEvent) {
			switch (sdlEvent.type) {
			case SDL_QUIT:
				quit();
				break;
			case SDL_KEYDOWN:
				SDLKey key = sdlEvent.key.keysym.sym;
				if (key == SDLK_ESCAPE) {
					quit();
					break;
				}
			}
		});

		int x = 10;
		int y = 150;
		int distance = 50;

		// In Bar.
		multiFrame_.add(b1,0,0,false,true);

{'fraction_non_alphanumeric': 0.15549215406562053, 'fraction_numerical': 0.03527428349111659, 'mean_word_length': 5.209339774557166, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1400644', 'n_tokens_mistral': 3162, 'n_tokens_neox': 2775, 'n_words': 491}