Experiment writing a grid widget. WiP.
This commit is contained in:
parent
73baf26696
commit
1c8f07d51d
5 changed files with 151 additions and 29 deletions
BIN
michele_epsxe000.mcr
Normal file
BIN
michele_epsxe000.mcr
Normal file
Binary file not shown.
|
@ -5,6 +5,7 @@ add_executable(${PROJECT_NAME}
|
||||||
memorycard.cpp
|
memorycard.cpp
|
||||||
block.cpp
|
block.cpp
|
||||||
icon_fetch.cpp
|
icon_fetch.cpp
|
||||||
|
grid.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(${PROJECT_NAME}
|
target_link_libraries(${PROJECT_NAME}
|
||||||
|
|
70
src/gui/grid.cpp
Normal file
70
src/gui/grid.cpp
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
#include "grid.hpp"
|
||||||
|
#include "memorycard.hpp"
|
||||||
|
#include "block.hpp"
|
||||||
|
#include "icon_fetch.hpp"
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
namespace implem {
|
||||||
|
void draw_icons (
|
||||||
|
int icon_size,
|
||||||
|
const MemoryCard& mc,
|
||||||
|
std::array<nana::animation, 15>& icons,
|
||||||
|
nana::widget& wid
|
||||||
|
) {
|
||||||
|
assert(icon_size);
|
||||||
|
|
||||||
|
for (int z = 0; z < icons.size(); ++z) {
|
||||||
|
nana::frameset fset;
|
||||||
|
for (const auto& frame : icon_fetch(mc[z])) {
|
||||||
|
nana::paint::image img;
|
||||||
|
img.open(frame.data(), frame.size());
|
||||||
|
fset.push_back(img);
|
||||||
|
}
|
||||||
|
|
||||||
|
const int x = (16 + 2) * (z % 3);
|
||||||
|
const int y = (16 + 2) * (z / 3);
|
||||||
|
|
||||||
|
nana::animation& ani = icons[z];
|
||||||
|
ani.fps(3);
|
||||||
|
ani.push_back(fset);
|
||||||
|
ani.output(wid, nana::point(x, y));
|
||||||
|
ani.looped(true);
|
||||||
|
ani.play();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} //namespace implem
|
||||||
|
|
||||||
|
grid_drawer_trigger::grid_drawer_trigger() = default;
|
||||||
|
|
||||||
|
void grid_drawer_trigger::attached (
|
||||||
|
nana::widget& widget,
|
||||||
|
nana::paint::graphics& graph
|
||||||
|
) {
|
||||||
|
using nana::effects::edge_nimbus;
|
||||||
|
using nana::API::dev::enable_space_click;
|
||||||
|
using nana::API::tabstop;
|
||||||
|
using nana::API::effects_edge_nimbus;
|
||||||
|
using nana::API::dev::set_measurer;
|
||||||
|
|
||||||
|
m_graph = &graph;
|
||||||
|
m_widget = &widget;
|
||||||
|
|
||||||
|
nana::window wd = widget;
|
||||||
|
|
||||||
|
enable_space_click(widget, true);
|
||||||
|
tabstop(wd);
|
||||||
|
effects_edge_nimbus(wd, edge_nimbus::active);
|
||||||
|
effects_edge_nimbus(wd, edge_nimbus::over);
|
||||||
|
}
|
||||||
|
|
||||||
|
void grid_drawer_trigger::set_memorycard (const MemoryCard* mc) {
|
||||||
|
m_memorycard = mc;
|
||||||
|
}
|
||||||
|
|
||||||
|
void grid_drawer_trigger::_m_draw_background (
|
||||||
|
nana::paint::graphics&,
|
||||||
|
bool is_mouse_down
|
||||||
|
) {
|
||||||
|
assert(m_memorycard);
|
||||||
|
implem::draw_icons(16, *m_memorycard, m_icons, *m_widget);
|
||||||
|
}
|
69
src/gui/grid.hpp
Normal file
69
src/gui/grid.hpp
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "nana/gui/widgets/widget.hpp"
|
||||||
|
#include "nana/gui/animation.hpp"
|
||||||
|
#include <array>
|
||||||
|
|
||||||
|
class MemoryCard;
|
||||||
|
|
||||||
|
namespace implem {
|
||||||
|
//void draw_icons (
|
||||||
|
// int icon_size,
|
||||||
|
// const MemoryCard& mc,
|
||||||
|
// std::array<nana::animation, 15>& icons,
|
||||||
|
// nana::widget& wid
|
||||||
|
//);
|
||||||
|
} //namespace implem
|
||||||
|
|
||||||
|
class grid_drawer_trigger : public nana::drawer_trigger {
|
||||||
|
public:
|
||||||
|
grid_drawer_trigger();
|
||||||
|
void set_memorycard (const MemoryCard* mc);
|
||||||
|
|
||||||
|
private:
|
||||||
|
virtual void attached(nana::widget&, nana::paint::graphics&) override;
|
||||||
|
|
||||||
|
//void _m_draw_title (nana::paint::graphics&, bool is_mouse_down, bool is_focus);
|
||||||
|
void _m_draw_background (nana::paint::graphics&, bool is_mouse_down);
|
||||||
|
//void _m_draw_border (nana::paint::graphics&, bool is_mouse_down);
|
||||||
|
|
||||||
|
std::array<nana::animation, 15> m_icons;
|
||||||
|
nana::widget* m_widget{nullptr};
|
||||||
|
nana::paint::graphics* m_graph{nullptr};
|
||||||
|
const MemoryCard* m_memorycard{nullptr};
|
||||||
|
bool m_is_ms_down{false};
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename DrawerTrigger>
|
||||||
|
class basic_grid : public nana::widget_object<nana::category::widget_tag, DrawerTrigger> {
|
||||||
|
public:
|
||||||
|
basic_grid() = default;
|
||||||
|
basic_grid (nana::widget& widget, unsigned int icon_size, const MemoryCard* mc);
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_icon_size{0};
|
||||||
|
const MemoryCard* m_memorycard{nullptr};
|
||||||
|
};
|
||||||
|
|
||||||
|
using grid = basic_grid<grid_drawer_trigger>;
|
||||||
|
|
||||||
|
template <typename DrawerTrigger>
|
||||||
|
basic_grid<DrawerTrigger>::basic_grid (
|
||||||
|
nana::widget& widget,
|
||||||
|
unsigned int icon_size,
|
||||||
|
const MemoryCard* mc
|
||||||
|
) :
|
||||||
|
m_icon_size(icon_size),
|
||||||
|
m_memorycard(mc)
|
||||||
|
{
|
||||||
|
this->create(
|
||||||
|
widget.handle(),
|
||||||
|
nana::rectangle{
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
(icon_size + 2) * 3 - 2,
|
||||||
|
(icon_size + 2) * 5 - 2
|
||||||
|
}
|
||||||
|
);
|
||||||
|
this->get_drawer_trigger().set_memorycard(m_memorycard);
|
||||||
|
}
|
|
@ -1,45 +1,27 @@
|
||||||
#include "nana/gui.hpp"
|
#include "nana/gui.hpp"
|
||||||
#include "nana/gui/animation.hpp"
|
|
||||||
#include "nana/gui/widgets/panel.hpp"
|
|
||||||
#include "memorycard.hpp"
|
#include "memorycard.hpp"
|
||||||
#include "block.hpp"
|
#include "grid.hpp"
|
||||||
#include "icon_fetch.hpp"
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstdint>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <array>
|
|
||||||
#include <vector>
|
|
||||||
#include <climits>
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
nana::form frm;
|
nana::form frm;
|
||||||
|
|
||||||
|
const MemoryCard mc(std::ifstream("/home/michele/dev/code/cpp/memoserv/michele_epsxe000.mcr", std::ios::binary));
|
||||||
|
grid grid1{frm, 16, &mc};
|
||||||
|
#if !defined(NDEBUG)
|
||||||
|
grid1.bgcolor(nana::colors::azure);
|
||||||
|
#endif
|
||||||
|
|
||||||
std::cout << "Hello world\n";
|
std::cout << "Hello world\n";
|
||||||
|
frm.div("vert<>< <weight=5%><grid1><weight=5%><> ><>");
|
||||||
|
frm["grid1"] << grid1;
|
||||||
|
frm.collocate();
|
||||||
frm.show();
|
frm.show();
|
||||||
|
|
||||||
const MemoryCard mc(std::ifstream("/home/michele/emu/psx/WipEout 3 - Special Edition (Europe) (En,Fr,De,Es,It).srm", std::ios::binary));
|
//const MemoryCard mc(std::ifstream("/home/michele/emu/psx/WipEout 3 - Special Edition (Europe) (En,Fr,De,Es,It).srm", std::ios::binary));
|
||||||
//MemoryCard mc(std::ifstream("/run/media/michele/roms/michele_epsxe000.mcr", std::ios::binary));
|
|
||||||
//MemoryCard mc(std::ifstream("/home/michele/emu/psx/Rapid Racer (Europe) (En,Fr,De,Es,It).srm", std::ios::binary));
|
//MemoryCard mc(std::ifstream("/home/michele/emu/psx/Rapid Racer (Europe) (En,Fr,De,Es,It).srm", std::ios::binary));
|
||||||
|
|
||||||
std::array<nana::animation, 15> icons { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 };
|
|
||||||
for (int z = 0; z < 15; ++z) {
|
|
||||||
nana::frameset fset;
|
|
||||||
for (const auto& frame : icon_fetch(mc[z])) {
|
|
||||||
nana::paint::image img;
|
|
||||||
img.open(frame.data(), frame.size());
|
|
||||||
fset.push_back(img);
|
|
||||||
}
|
|
||||||
|
|
||||||
const int x = 5 + 18 * (z % 3);
|
|
||||||
const int y = 5 + 18 * (z / 3);
|
|
||||||
|
|
||||||
nana::animation& ani = icons[z];
|
|
||||||
ani.push_back(fset);
|
|
||||||
ani.output(frm, nana::point(x, y));
|
|
||||||
ani.looped(true);
|
|
||||||
ani.play();
|
|
||||||
}
|
|
||||||
|
|
||||||
nana::exec();
|
nana::exec();
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Add table
Reference in a new issue