memoserv/src/nana/widget/psx_mc_grid.cpp

107 lines
2.8 KiB
C++

/* Copyright 2020, Michele Santullo
* This file is part of memoserv.
*
* Memoserv is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Memoserv is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Memoserv. If not, see <http://www.gnu.org/licenses/>.
*/
#include "widget/psx_mc_grid.hpp"
#include <utility>
#include <iostream>
namespace duck::widget {
#if !defined(NDEBUG)
bool PSXMCGrid::s_dark_bg_colour = false;
#endif
namespace drawerbase::psxmcgrid {
class Trigger::Measurer : public nana::dev::widget_content_measurer_interface {
public:
Measurer(Trigger* t)
: m_trigger{ t }
{}
std::optional<nana::size> measure(graph_reference, unsigned, bool) const override {
return nana::size{51 * 3, 51 * 5};
}
nana::size extension() const override {
return {20, 20};
}
private:
Trigger* m_trigger;
};
Trigger::Trigger() :
m_measurer(std::make_unique<Measurer>(this))
{
}
Trigger::~Trigger() noexcept = default;
void Trigger::attached (nana::widget& widget, nana::paint::graphics& graph) {
m_widget = &widget;
nana::API::dev::enable_space_click(widget, true);
nana::window wd = widget;
nana::API::tabstop(wd);
nana::API::dev::set_measurer(widget, m_measurer.get());
}
void Trigger::detached() {
m_widget = nullptr;
}
} //namespace drawerbase::psxmcgrid
//PSXMCGrid::PSXMCGrid (const std::string& caption) :
// PSXMCGrid(0, caption)
//{
//}
PSXMCGrid::PSXMCGrid (nana::window wd, const std::string& caption) :
//nana::panel<true>(wd, true),
m_panel(wd, true),
m_grid(m_panel, 3, true),
m_title(m_panel, caption)
{
std::cout << "PSXMCGrid::PSXMCGrid(wd, \"" + caption + "\");\n";
this->create(wd, nana::rectangle{}, true);
//this->transparent(false);
//this->size(m_grid.size());
m_place.bind(m_panel);
m_place.div("vert <mctitle fit margin=5> <mcgrid fit margin=5>");
m_place["mctitle"] << m_title;
m_place["mcgrid"] << m_grid;
m_place.collocate();
}
void PSXMCGrid::bgcolor(const nana::color& color) {
m_grid.bgcolor(color);
nana::widget_object<nana::category::widget_tag, drawerbase::psxmcgrid::Trigger>::bgcolor(color);
#if !defined(NDEBUG)
//if (s_dark_bg_colour)
// nana::panel<true>::bgcolor(nana::colors::black);
//else
// nana::panel<true>::bgcolor(nana::colors::white);
s_dark_bg_colour = not s_dark_bg_colour;
#else
nana::panel<true>::bgcolor(color);
#endif
}
void PSXMCGrid::emplace_back (AnimationWithSize&& anim) {
m_grid.emplace_back(std::move(anim));
}
} //namespace duck::widget