Skip to content

Commit

Permalink
pool mgr: add unit preview
Browse files Browse the repository at this point in the history
  • Loading branch information
carrotIndustries committed Jan 1, 2018
1 parent a6600e7 commit 9f8fa5b
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 2 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ SRC_POOL_MGR = \
widgets/entity_preview.cpp\
widgets/preview_canvas.cpp\
widgets/preview_base.cpp\
widgets/unit_preview.cpp\

SRC_PGM_TEST = \
pgm-test.cpp
Expand Down
21 changes: 19 additions & 2 deletions pool-mgr/pool_notebook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "pool-mgr-app.hpp"
#include "widgets/part_preview.hpp"
#include "widgets/entity_preview.hpp"
#include "widgets/unit_preview.hpp"
#include "widgets/preview_canvas.hpp"
#include <thread>

Expand Down Expand Up @@ -272,9 +273,25 @@ namespace horizon {
sep->show();
box->pack_start(*sep, false, false, 0);
box->pack_start(*br, true, true, 0);
box->show();

append_page(*box, "Units");
auto paned = Gtk::manage(new Gtk::Paned(Gtk::ORIENTATION_HORIZONTAL));
paned->add1(*box);

auto preview = Gtk::manage(new UnitPreview(pool));
preview->signal_goto().connect(sigc::mem_fun(this, &PoolNotebook::go_to));
br->signal_selected().connect([this, br, preview]{
auto sel = br->get_selected();
if(!sel) {
preview->load(nullptr);
return;
}
auto unit = pool.get_unit(sel);
preview->load(unit);
});
paned->add2(*preview);
paned->show_all();

append_page(*paned, "Units");
}
{
auto br = Gtk::manage(new PoolBrowserSymbol(&pool));
Expand Down
78 changes: 78 additions & 0 deletions widgets/unit_preview.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#include "unit_preview.hpp"
#include "pool/unit.hpp"
#include "pool/pool.hpp"
#include "canvas/canvas.hpp"
#include "util/util.hpp"
#include "util/sqlite.hpp"
#include "object_descr.hpp"
#include "preview_canvas.hpp"

namespace horizon {
UnitPreview::UnitPreview(class Pool &p): Gtk::Box(Gtk::ORIENTATION_VERTICAL, 0), pool(p) {

auto symbol_sel_box = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, 4));
symbol_sel_box->property_margin() = 8;
{
auto la = Gtk::manage(new Gtk::Label("Symbol"));
la->get_style_context()->add_class("dim-label");
symbol_sel_box->pack_start(*la, false, false, 0);
}
combo_symbol = Gtk::manage(new Gtk::ComboBoxText);
combo_symbol->signal_changed().connect(sigc::mem_fun(this, &UnitPreview::handle_symbol_sel));
symbol_sel_box->pack_start(*combo_symbol, true, true, 0);

{
auto bu = create_goto_button(ObjectType::SYMBOL, [this] {
return UUID(combo_symbol->get_active_id());
});
symbol_sel_box->pack_start(*bu, false, false, 0);
}

pack_start(*symbol_sel_box, false, false, 0);

{
auto sep = Gtk::manage(new Gtk::Separator(Gtk::ORIENTATION_HORIZONTAL));
sep->show();
pack_start(*sep, false, false, 0);
}

canvas_symbol = Gtk::manage(new PreviewCanvas(pool));
canvas_symbol->show();
pack_start(*canvas_symbol, true, true, 0);


load(nullptr);
}

void UnitPreview::load(const Unit *u) {
unit = u;

for(auto it: goto_buttons) {
it->set_sensitive(unit);
}
combo_symbol->remove_all();
if(!unit) {
return;
}

SQLite::Query q(pool.db, "SELECT uuid, name FROM symbols WHERE unit=? ORDER BY name");
q.bind(1, unit->uuid);
while(q.step()) {
UUID uu = q.get<std::string>(0);
std::string name = q.get<std::string>(1);
combo_symbol->append((std::string)uu, name);
}
combo_symbol->set_active(0);
}

void UnitPreview::handle_symbol_sel() {
canvas_symbol->clear();
if(!unit)
return;
if(combo_symbol->get_active_row_number() == -1)
return;

canvas_symbol->load(ObjectType::SYMBOL, UUID(combo_symbol->get_active_id()));
}

}
23 changes: 23 additions & 0 deletions widgets/unit_preview.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once
#include <gtkmm.h>
#include <set>
#include "common.hpp"
#include "uuid.hpp"
#include "preview_base.hpp"

namespace horizon {
class UnitPreview: public Gtk::Box, public PreviewBase {
public:
UnitPreview(class Pool &pool);

void load(const class Unit *unit);

private:
class Pool &pool;
const class Unit *unit = nullptr;
class PreviewCanvas *canvas_symbol = nullptr;
Gtk::ComboBoxText *combo_symbol = nullptr;

void handle_symbol_sel();
};
}

0 comments on commit 9f8fa5b

Please sign in to comment.