Mercurial > malikania
view mlk-client/main.cpp @ 206:12873699ad8b
client: create variant instead of dispatcher
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 29 Nov 2018 14:04:58 +0100 |
parents | c973501abe36 |
children | 263122adef77 |
line wrap: on
line source
/* * main.cpp -- main client file * * Copyright (c) 2013-2018 David Demelier <markand@malikania.fr> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include <iostream> #include <chrono> #include <thread> #include <malikania/client/color.hpp> #include <malikania/client/button.hpp> #include <malikania/client/window.hpp> #include <malikania/client/sprite.hpp> #include <malikania/client/theme.hpp> #include <assets/ui.hpp> using namespace std::chrono_literals; int main(int, char**) { mlk::client::window win(1920/2, 1080/2, "Hello"); mlk::client::image image(std::string(ui, sizeof (ui))); mlk::client::sprite sprite(std::move(image), {16, 16}); for (;;) { while (auto ev = win.poll()) { if (std::holds_alternative<mlk::client::quit_event>(ev)) return 0; } win.clear(); win.set_drawing_color(mlk::client::color::from_hex(0xffffffff)); const auto width = 200; const auto height = 150; // top sprite.draw(win, 0, mlk::point{10, 10}); sprite.draw(win, 1, mlk::rectangle{10 + 16, 10, width, 16}); sprite.draw(win, 2, mlk::point{10 + 16 + width, 10}); // middle sprite.draw(win, 32, mlk::rectangle{10, 10 + 16, 16, height}); sprite.draw(win, 33, mlk::rectangle{10 + 16, 10 + 16, width, height}); sprite.draw(win, 34, mlk::rectangle{10 + 16 + width, 10 + 16, 16, height}); // bottom sprite.draw(win, 64, mlk::point{10, 10 + 16 + height}); sprite.draw(win, 65, mlk::rectangle{10 + 16, 10 + 16 + height, width, 16}); sprite.draw(win, 66, mlk::point{10 + 16 + width, 10 + 16 + height}); // input sprite.draw(win, 3, mlk::point{10 + 8, 10 + 8}); sprite.draw(win, 4, mlk::rectangle{10 + 8 + 16, 10 + 8, width - 16, 16}); sprite.draw(win, 5, mlk::point{10 + 8 + width, 10 + 8}); sprite.draw(win, 35, mlk::point{10 + 8, 10 + 8 + 16}); sprite.draw(win, 36, mlk::rectangle{10 + 8 + 16, 10 + 8 + 16, width - 16, 16}); sprite.draw(win, 37, mlk::point{10 + 8 + width, 10 + 8 + 16}); win.present(); std::this_thread::sleep_for(50ms); } return 0; }