summaryrefslogtreecommitdiff
path: root/src/graphcoloring/mainmenu.cpp
blob: 3aed9c0c778c054c927ae333c7cb4649248b834c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2018 Leo Tenenbaum
// This file is part of GraphColoring.
//
// GraphColoring is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GraphColoring is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with GraphColoring.  If not, see <https://www.gnu.org/licenses/>.
////////////////////////////////////////////////////////////////////////////////

#include "mainmenu.hpp"

#include <iostream>

#include "gui/gui.hpp"
#include "graphcoloring.hpp"

namespace graphcoloring {

MainMenu::MainMenu(gui::Window* win, gui::Button::callback_t onstart)
	: window(win),
	  title_size(0, 0, TITLE_SIZE/1.5, TITLE_SIZE, win->GetSizePtr())
{
	gui::Button::callback_t quit = [this](){
		window->Quit();
	};

	gui::Size button_size = gui::Position(0,0,BUTTON_WIDTH,BUTTON_HEIGHT,
		win->GetSizePtr());

	std::shared_ptr<gui::Button> quitButton(new gui::Button(window, "Quit",
			gui::Position(), button_size, 0xFF0066FF));
	quitButton->SetCommand(quit);

	std::shared_ptr<gui::Button> startButton(new gui::Button(window, "Start",
			gui::Position(), button_size, 0x00FF66FF));
	startButton->SetCommand(onstart);

	std::vector<std::shared_ptr<gui::Button>> buttons = {
			startButton, quitButton
	};

	int title_height = title_size.Y();
	gui::Position menuPosition = window->GetPosition(0, title_height);
	gui::Size     menuSize     = window->GetPosition(0, -title_height, 1, 1);

	menu = std::make_unique<gui::Menu>(window, buttons, menuPosition, menuSize);

	window->SetRenderCallback([this](gui::Window*){Render();});
}

void MainMenu::Render()
{
	window->SetDrawColor(GraphColoring::BACKGROUND_COLOR);
	window->Clear();
	window->SetDrawColor(TITLE_COLOR);
	window->SetTextSize(std::min(title_size.X(), title_size.Y()));
	window->DrawText(GraphColoring::TITLE, window->GetPosition(0,10,0.5,0),
		gui::Alignment::CENTER, gui::Alignment::TOP);
	menu->Render();
}


} // namespace graphcoloring