Mercurial > malikania
view libclient/malikania/client/state/login_state.cpp @ 144:67eac3fc099f
Client: add prototype of login state, #712
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 28 Sep 2017 13:01:45 +0200 |
parents | |
children | c8510782d40d |
line wrap: on
line source
/* * login_state.cpp -- login state * * Copyright (c) 2013-2017 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 "color.hpp" #include "client.hpp" #include "login_state.hpp" #include "theme.hpp" #include "unicode.hpp" #include "window.hpp" namespace mlk { namespace client { login_state::login_state(client& clt) { clt.window().start_edit(); } void login_state::handle_text(const text_event& ev) { if (index_ == 0) login_ += ev.text; else password_ += ev.text; } void login_state::update(client&) { } void login_state::handle_key_down(const key_event& ev) { switch (ev.key) { case key::tab: index_ ++; if (index_ == 2) index_ = 0; break; case key::backspace: if (index_ == 0) login_.pop_back(); else password_.pop_back(); break; case key::enter: // TODO: add lobby_state when done. break; default: break; } } void login_state::draw(client& clt) { auto& win = clt.window(); const auto& font = win.theme().font(); win.set_drawing_color(mlk::client::color(0xffffffff)); win.clear(); win.set_drawing_color(mlk::client::color(0xff000000)); win.draw_text("Please log in", font, {10, 10}); win.draw_text("login: ", font, {10, 50}); win.draw_text("password: ", font, {10, 70}); if (!login_.empty()) win.draw_text(unicode::to_utf8(login_), font, {70, 50}); if (!password_.empty()) win.draw_text(std::string(password_.length(), '*'), font, {70, 70}); win.present(); } } // !client } // !mlk