Mercurial > malikania
view mlk-client/main.cpp @ 214:e2574aa8301d
client: add basic input text, closes #910
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sun, 01 Sep 2019 06:53:48 +0200 |
parents | 61580ff3138a |
children |
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 <chrono> #include <iostream> #include <thread> #include <malikania/client/color.hpp> #include <malikania/client/window.hpp> #include <malikania/client/painter.hpp> #include <malikania/client/input.hpp> #include <malikania/client/image.hpp> #include <malikania/client/pixmap_theme.hpp> #include <malikania/rectangle.hpp> namespace assets { #include <assets/b.hpp> #include <assets/center.hpp> #include <assets/bl.hpp> #include <assets/br.hpp> #include <assets/l.hpp> #include <assets/r.hpp> #include <assets/t.hpp> #include <assets/tl.hpp> #include <assets/tr.hpp> } // !assets using namespace std::chrono_literals; int main(int argc, char** argv) { mlk::client::window win{1920, 1080}; mlk::client::pixmap_theme mytheme({}); mlk::client::theme::set_default(mytheme); mlk::client::painter painter{win}; mlk::client::input input; input.set_position({100, 150}); input.set_size({300, 64}); input.focus(); using mlk::client::pixmap_theme; using mlk::client::image; pixmap_theme::images images; images.emplace(pixmap_theme::component::input_bottom, std::string(assets::b, sizeof (assets::b))); images.emplace(pixmap_theme::component::input_bottom_left, std::string(assets::bl, sizeof (assets::bl))); images.emplace(pixmap_theme::component::input_bottom_right, std::string(assets::br, sizeof (assets::br))); images.emplace(pixmap_theme::component::input_center, std::string(assets::center, sizeof (assets::center))); images.emplace(pixmap_theme::component::input_left, std::string(assets::l, sizeof (assets::l))); images.emplace(pixmap_theme::component::input_right, std::string(assets::r, sizeof (assets::r))); images.emplace(pixmap_theme::component::input_top, std::string(assets::t, sizeof (assets::t))); images.emplace(pixmap_theme::component::input_top_left, std::string(assets::tl, sizeof (assets::tl))); images.emplace(pixmap_theme::component::input_top_right, std::string(assets::tr, sizeof (assets::tr))); mytheme.set_images(std::move(images)); for (;;) { while (auto ev = win.poll()) { if (std::get_if<mlk::client::quit_event>(&ev)) return 0; input.handle(ev); } painter.set_drawing_color({255, 255, 255, 255}); painter.clear(); input.draw(painter); painter.present(); } }