# HG changeset patch # User David Demelier # Date 1506594975 -7200 # Node ID 473e1eb96363e458e1e86d78666e075bbe3f7a66 # Parent 2cce1729b6dada0cccff32ab0700c7710a47c9ef Client: add simple splashscreen_state, #712 diff -r 2cce1729b6da -r 473e1eb96363 client/CMakeLists.txt --- a/client/CMakeLists.txt Thu Sep 28 06:40:09 2017 +0200 +++ b/client/CMakeLists.txt Thu Sep 28 12:36:15 2017 +0200 @@ -23,8 +23,14 @@ ${mlk-client_SOURCE_DIR}/main.cpp ) +set( + ASSETS + ${mlk-client_SOURCE_DIR}/assets/kingthings_spike.ttf +) + malikania_define_executable( TARGET mlk-client SOURCES ${SOURCES} + ASSETS ${ASSETS} LIBRARIES libmlk-client-js ) diff -r 2cce1729b6da -r 473e1eb96363 client/assets/kingthings_spike.ttf Binary file client/assets/kingthings_spike.ttf has changed diff -r 2cce1729b6da -r 473e1eb96363 client/main.cpp --- a/client/main.cpp Thu Sep 28 06:40:09 2017 +0200 +++ b/client/main.cpp Thu Sep 28 12:36:15 2017 +0200 @@ -20,8 +20,19 @@ #include #include +#include #include +namespace res { + +namespace { + +#include + +} // !namespace + +} // !res + int main() { boost::asio::io_service service; @@ -29,6 +40,8 @@ mlk::client::connection conn(service); mlk::client::window w; mlk::client::client clt(service, conn, w); + mlk::client::font f(std::string(res::kingthings_spike, sizeof (res::kingthings_spike)), 64); + clt.set_state(std::make_unique(std::move(f), "Malikania Kingdom")); clt.run(); } diff -r 2cce1729b6da -r 473e1eb96363 libclient/CMakeLists.txt --- a/libclient/CMakeLists.txt Thu Sep 28 06:40:09 2017 +0200 +++ b/libclient/CMakeLists.txt Thu Sep 28 12:36:15 2017 +0200 @@ -40,6 +40,7 @@ ${libmlk-client_SOURCE_DIR}/malikania/client/rectangle.hpp ${libmlk-client_SOURCE_DIR}/malikania/client/sprite.hpp ${libmlk-client_SOURCE_DIR}/malikania/client/state.hpp + ${libmlk-client_SOURCE_DIR}/malikania/client/state/splashscreen_state.hpp ${libmlk-client_SOURCE_DIR}/malikania/client/theme.hpp ${libmlk-client_SOURCE_DIR}/malikania/client/unique_layout.hpp ${libmlk-client_SOURCE_DIR}/malikania/client/widget.hpp @@ -62,6 +63,7 @@ ${libmlk-client_SOURCE_DIR}/malikania/client/image.cpp ${libmlk-client_SOURCE_DIR}/malikania/client/label.cpp ${libmlk-client_SOURCE_DIR}/malikania/client/sprite.cpp + ${libmlk-client_SOURCE_DIR}/malikania/client/state/splashscreen_state.cpp ${libmlk-client_SOURCE_DIR}/malikania/client/theme.cpp ${libmlk-client_SOURCE_DIR}/malikania/client/unique_layout.cpp ${libmlk-client_SOURCE_DIR}/malikania/client/widget.cpp diff -r 2cce1729b6da -r 473e1eb96363 libclient/malikania/client/client.cpp --- a/libclient/malikania/client/client.cpp Thu Sep 28 06:40:09 2017 +0200 +++ b/libclient/malikania/client/client.cpp Thu Sep 28 12:36:15 2017 +0200 @@ -95,6 +95,11 @@ state_ = std::move(state_next_); window_.poll(*this); + + if (state_) { + state_->update(*this); + state_->draw(*this); + } } } // !client diff -r 2cce1729b6da -r 473e1eb96363 libclient/malikania/client/state/splashscreen_state.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libclient/malikania/client/state/splashscreen_state.cpp Thu Sep 28 12:36:15 2017 +0200 @@ -0,0 +1,51 @@ +/* + * splashscreen_state.cpp -- simple basic splashscreen + * + * Copyright (c) 2013-2017 David Demelier + * + * 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 "client.hpp" +#include "splashscreen_state.hpp" +#include "window.hpp" + +namespace mlk { + +namespace client { + +void splashscreen_state::update(client& clt) +{ + (void)clt; +} + +void splashscreen_state::draw(client& clt) +{ + // TODO: window.size(). + auto clip = font_.clip(text_); + auto size = mlk::size(640, 480); + auto& win = clt.window(); + + win.set_drawing_color(background_); + win.clear(); + win.set_drawing_color(foreground_); + win.draw_text(text_, font_, { + (size.width() - clip.width()) / 2, + (size.height() - clip.height()) / 2 + }); + win.present(); +} + +} // !client + +} // !mlk diff -r 2cce1729b6da -r 473e1eb96363 libclient/malikania/client/state/splashscreen_state.hpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libclient/malikania/client/state/splashscreen_state.hpp Thu Sep 28 12:36:15 2017 +0200 @@ -0,0 +1,179 @@ +/* + * splashscreen_state.hpp -- simple basic splashscreen + * + * Copyright (c) 2013-2017 David Demelier + * + * 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. + */ + +#ifndef MALIKANIA_CLIENT_SPLASHSCREEN_STATE_HPP +#define MALIKANIA_CLIENT_SPLASHSCREEN_STATE_HPP + +/** + * \file splashscreen_state.hpp + * \brief Simple basic splashscreen. + */ + +#include + +#include + +#include +#include +#include + +namespace mlk { + +namespace client { + +/** + * \brief Simple basic splashscreen. + */ +class splashscreen_state : public state { +private: + mlk::client::font font_; + mlk::client::color foreground_{0xff000000}; + mlk::client::color background_{0xffffffff}; + std::string text_; + std::uint16_t delay_{3000}; + boost::timer::cpu_timer timer_; + +public: + /** + * Construct the state. + * + * \param fn the font + * \param text the text to show + */ + inline splashscreen_state(mlk::client::font fn, std::string text) noexcept + : font_(std::move(fn)) + , text_(std::move(text)) + { + } + + /** + * Get the current font. + * + * \return the font + */ + inline const mlk::client::font& font() const noexcept + { + return font_; + } + + /** + * Set the font. + * + * \param fn the font + */ + inline void set_font(mlk::client::font fn) noexcept + { + font_ = std::move(fn); + } + + /** + * Get the text color. + * + * \return the color + */ + inline const color& foreground() const noexcept + { + return foreground_; + } + + /** + * Set the text color. + * + * \param c the color + */ + inline void set_foreground(color c) noexcept + { + foreground_ = std::move(c); + } + + /** + * Get the background color. + * + * \return the color + */ + inline const color& background() const noexcept + { + return background_; + } + + /** + * Set the background color. + * + * \param c the color + */ + inline void set_background(color c) noexcept + { + background_ = std::move(c); + } + + /** + * Get the text to show. + * + * \return the text + */ + inline const std::string& text() const noexcept + { + return text_; + } + + /** + * Set the text to show. + * + * \param text the text + */ + inline void set_text(std::string text) noexcept + { + text_ = std::move(text); + } + + /** + * Get the delay. + * + * \return the delay in milliseconds + */ + inline std::uint16_t delay() const noexcept + { + return delay_; + } + + /** + * Set the delay. + * + * \return the delay in milliseconds + */ + inline void set_delay(std::uint16_t delay) noexcept + { + delay_ = delay; + } + + /** + * \copydoc state::update + */ + void update(client& clt) override; + + /** + * \copydoc state::draw + */ + void draw(client& clt) override; +}; + +} // !client + +} // !mlk + +#endif // !MALIKANIA_CLIENT_SPLASHSCREEN_STATE_HPP