/* * GuiController.cpp * * Created on: Nov 26, 2016 * Author: tibi */ #include #include #include #include namespace farmlands { namespace components { GuiController::GuiController() : m_canvas() { } GuiController::~GuiController() { } model::Component* GuiController::clone() { return new GuiController(); } void GuiController::onInitialize() { m_context = &GameState::current().renderContext; // Set up canvas m_canvas.setSize(m_context->viewport.width, m_context->viewport.height); // Add a text element auto text = new gui::widgets::TextArea(); text->setText("Hello world!"); text->setSize(50, 5); text->setPosition(100, 10); text->setColor(0, 1, 0); text->setBackColor(0.5f, 0, 0, 0.5f); text->setTextSize(11); text->setHorizontalWrap(gui::widgets::TextHorizontalWrapping::Ellipsis); text->setVerticalWrap(gui::widgets::TextVerticalWrapping::Trim); text->setAlignment(gui::widgets::TextAlign::BottomRight); m_canvas.addChild(text); } bool GuiController::onEvent(SDL_Event& event) { bool handled = m_canvas.handleEvent(event); float currentW = m_canvas.child(0)->width(); float currentH = m_canvas.child(0)->height(); if (event.type == SDL_EventType::SDL_KEYDOWN && event.key.keysym.scancode == SDL_SCANCODE_HOME) { m_canvas.child(0)->setSize(currentW + 5, currentH); } if (event.type == SDL_EventType::SDL_KEYDOWN && event.key.keysym.scancode == SDL_SCANCODE_END) { m_canvas.child(0)->setSize(currentW - 5, currentH); } return handled; } void GuiController::onRender() { // Render m_canvas.render(m_context); } void GuiController::dump(unsigned level) { for (unsigned i = 0; i < level; i++) std::cout<<" "; std::cout << " .Component: DebugController\n"; } } /* namespace controller */ } /* namespace farmlands */