这是indexloc提供的服务,不要输入任何密码
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions assets/gui/button.docx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# struct subtexture
# one sprite, as part of a texture atlas.
#
# this struct stores information about positions and sizes
# of sprites included in the 'big texture'.
# int32_t,int32_t,int32_t,int32_t,int32_t,int32_t
# x,y,w,h,cx,cy

# normal
0,0,3,3,0,0
3,0,122,3,0,0
125,0,3,3,0,0

0,3,3,58,0,0
3,3,122,58,0,0
125,3,3,58,0,0

0,61,3,3,0,0
3,61,122,3,0,0
125,61,3,3,0,0

# pressed
0,64,3,3,0,0
3,64,122,3,0,0
125,64,3,3,0,0

0,67,3,58,0,0
3,67,122,58,0,0
125,67,3,58,0,0

0,125,3,3,0,0
3,125,122,3,0,0
125,125,3,3,0,0
Binary file added assets/gui/button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ add_subdirectory("console")
add_subdirectory("coord")
add_subdirectory("crossplatform")
add_subdirectory("datastructure")
add_subdirectory("gui")
add_subdirectory("log")
add_subdirectory("job")
add_subdirectory("keybinds")
Expand Down
8 changes: 5 additions & 3 deletions cpp/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,20 +374,22 @@ int64_t Engine::lastframe_duration_nsec() {
return this->fps_counter.nsec_lastframe;
}

void Engine::render_text(coord::window position, size_t size, const char *format, ...) {
Font &Engine::get_font(size_t size) {
auto it = this->fonts.find(size);
if (it == this->fonts.end()) {
throw util::Error(MSG(err) << "Unknown font size requested: " << size);
}

Font *font = it->second.get();
return *(it->second);
}

void Engine::render_text(coord::window position, size_t size, const char *format, ...) {
va_list vl;
va_start(vl, format);
std::string buf = util::vsformat(format, vl);
va_end(vl);

font->render_static(position.x, position.y, buf.c_str());
get_font(size).render_static(position.x, position.y, buf.c_str());
}

void Engine::move_phys_camera(float x, float y, float amount) {
Expand Down
5 changes: 5 additions & 0 deletions cpp/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ class Engine : public ResizeHandler {
*/
int64_t lastframe_duration_nsec();

/**
* find a Font instance
*/
Font &get_font(size_t size);

/**
* render text with the at a position with specified font size
*/
Expand Down
74 changes: 74 additions & 0 deletions cpp/game_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
#include "util/timer.h"
#include "util/externalprofiler.h"

#include "gui/container.h"
#include "gui/drawer.h"
#include "gui/label.h"
#include "gui/toplevel.h"
#include "gui/imagebutton.h"
#include "gui/imagecheckbox.h"
#include "gui/style.h"
#include "gui/formlayout.h"

namespace openage {

/** @file
Expand Down Expand Up @@ -354,6 +363,59 @@ GameMain::GameMain(Engine *engine)
bind_player_switch(keybinds::action_t::SWITCH_TO_PLAYER_8, 8);

engine->get_keybind_manager().register_context(&this->keybind_context);

// create GUI
gui_top_level.reset(new gui::TopLevel);
gui_top_level->set_layout(std::make_unique<gui::FormLayout>());

gui::Style style{&assetmanager};

gui_loading_message = gui_top_level->create<gui::Label>();
gui_loading_message->set_text("Loading gamedata...");
gui_loading_message->set_layout_data(gui::FormLayoutData::best_size(gui_loading_message)
.set_left(gui::FormAttachment::center())
.set_top(gui::FormAttachment::center()));

gui_framerate = gui_top_level->create<gui::Label>();
gui_framerate->set_text("⸘FPS here maybe‽");
gui_framerate->set_layout_data(gui::FormLayoutData::best_size(gui_framerate)
.set_left(gui::FormAttachment::right().offset_by(-100))
.set_bottom(gui::FormAttachment::bottom().offset_by(-30)));

auto gui_idle_villager = gui_top_level->add_control(style.create_image_button("converted/Data/interfac.drs/50788.slp.png", 12));
gui_idle_villager->set_layout_data(gui::FormLayoutData::best_size(gui_idle_villager)
.set_left(gui::FormAttachment::left().offset_by(5))
.set_bottom(gui::FormAttachment::bottom().offset_by(-5)));
gui_idle_villager->on_click([]{
log::log(MSG(info).fmt("Idle villager, anyone?"));
});

#if 0
auto gui_flare = gui_top_level->add_control(style.create_image_button("converted/Data/interfac.drs/50788.slp.png", 2));
gui_flare->set_right(gui::FormAttachment::left().offset_by(90)); // tmp
gui_flare->set_top(gui::FormAttachment::bottom().offset_by(-85)); // tmp
gui_flare->set_left(gui::FormAttachment::adjacent_to(gui_idle_villager).offset_by(10));
gui_flare->set_bottom(gui::FormAttachment::bottom().offset_by(-50));
gui_flare->on_click([]{
log::log(MSG(info).fmt("Send a flare!"));
});

auto gui_quit = gui_top_level->add_control(style.create_button());
gui_quit->set_left(gui::FormAttachment::right().offset_by(-42));
gui_quit->set_right(gui::FormAttachment::right().offset_by(-10));
gui_quit->set_top(gui::FormAttachment::top().offset_by(10));
gui_quit->set_bottom(gui::FormAttachment::top().offset_by(40));
gui_quit->get_label()->set_text("X");
gui_quit->on_click([engine]{
engine->stop();
});

auto gui_palalol = gui_top_level->add_control(style.create_image_button("converted/Data/interfac.drs/50730.slp.png", 2));
gui_palalol->set_left(gui::FormAttachment::left().offset_by(10));
gui_palalol->set_right(gui::FormAttachment::left().offset_by(50));
gui_palalol->set_top(gui::FormAttachment::center().offset_by(10));
gui_palalol->set_bottom(gui::FormAttachment::center().offset_by(50));
#endif
}

GameMain::~GameMain() {
Expand All @@ -368,6 +430,11 @@ GameMain::~GameMain() {

bool GameMain::on_input(SDL_Event *e) {
Engine &engine = Engine::get();

// first, see if the gui wants to process the event
if (gui_top_level->process_event(e)) {
return true;
}

switch (e->type) {

Expand Down Expand Up @@ -651,6 +718,13 @@ bool GameMain::on_drawhud() {
txt->sample(bpreview_pos.to_camhud(), engine->current_player);
}
}

// draw the mighty GUI over everything
gui::Drawer drawer{e.engine_coord_data->window_size.x, e.engine_coord_data->window_size.y};
gui_top_level->resize(e.engine_coord_data->window_size.x, e.engine_coord_data->window_size.y); // FIXME only resize when size actually changes
gui_top_level->update(0.0);
gui_top_level->draw(drawer);

return true;
}

Expand Down
5 changes: 5 additions & 0 deletions cpp/game_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "unit/unit_container.h"
#include "util/externalprofiler.h"
#include "gamedata/gamedata.gen.h"
#include "gui/forward.h"

namespace openage {

Expand Down Expand Up @@ -101,6 +102,10 @@ class GameMain :
Command get_action(const coord::phys3 &pos) const;

openage::Engine *engine;

std::unique_ptr<gui::TopLevel> gui_top_level;
gui::Label *gui_loading_message;
gui::Label *gui_framerate;
};

} //namespace openage
Expand Down
15 changes: 15 additions & 0 deletions cpp/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
add_sources(${PROJECT_NAME}
border.cpp
button.cpp
checkbox.cpp
container.cpp
control.cpp
drawer.cpp
formlayout.cpp
gridlayout.cpp
image.cpp
label.cpp
layout.cpp
style.cpp
toplevel.cpp
)
31 changes: 31 additions & 0 deletions cpp/gui/absolutelayout.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2015-2015 the openage authors. See copying.md for legal info.

#ifndef OPENAGE_GUI_ABSOLUTELAYOUT_H_
#define OPENAGE_GUI_ABSOLUTELAYOUT_H_

#include "layout.h"

namespace openage {
namespace gui {

class AbsoluteLayoutData : public LayoutData {
public:
void set_position(int x, int y, int w, int h) {
position = {{x, x + w, y, y + h}};
}
};

class AbsoluteLayout : public Layout {
protected:
virtual void layout(const std::vector<std::unique_ptr<Control>> &controls, int container_w, int container_h) {
(void)controls;
(void)container_w;
(void)container_h;
}
};

} // namespace gui
} // namespace openage

#endif

18 changes: 18 additions & 0 deletions cpp/gui/alignment.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2015-2015 the openage authors. See copying.md for legal info.

#ifndef OPENAGE_GUI_ALIGNMENT_H_
#define OPENAGE_GUI_ALIGNMENT_H_

namespace openage {
namespace gui {

enum class HorizontalAlignment {
LEFT,
CENTER,
RIGHT
};

} // namespace gui
} // namespace openage

#endif
59 changes: 59 additions & 0 deletions cpp/gui/border.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2015-2015 the openage authors. See copying.md for legal info.

#include "border.h"

#include "image.h"

namespace openage {
namespace gui {

Border::Border() {
for (auto &img : slices) {
img = create<Image>();
}
contents = create<Container>();
}

void Border::set_texture(const Texture *texture, int base_subid) {
for (size_t i = 0; i < slices.size(); ++i) {
slices[i]->set_texture(texture, base_subid + i);
}

#if 0
slices[0]->set_left(FormAttachment::left());
slices[3]->set_left(FormAttachment::left());
slices[6]->set_left(FormAttachment::left());

slices[2]->set_right(FormAttachment::right());
slices[5]->set_right(FormAttachment::right());
slices[8]->set_right(FormAttachment::right());

slices[0]->set_top(FormAttachment::top());
slices[1]->set_top(FormAttachment::top());
slices[2]->set_top(FormAttachment::top());

slices[6]->set_bottom(FormAttachment::bottom());
slices[7]->set_bottom(FormAttachment::bottom());
slices[8]->set_bottom(FormAttachment::bottom());

slices[1]->set_left(FormAttachment::adjacent_to(slices[0]));
slices[4]->set_left(FormAttachment::adjacent_to(slices[3]));
slices[7]->set_left(FormAttachment::adjacent_to(slices[6]));

slices[1]->set_right(FormAttachment::adjacent_to(slices[2]));
slices[4]->set_right(FormAttachment::adjacent_to(slices[5]));
slices[7]->set_right(FormAttachment::adjacent_to(slices[8]));

slices[3]->set_top(FormAttachment::adjacent_to(slices[0]));
slices[4]->set_top(FormAttachment::adjacent_to(slices[1]));
slices[5]->set_top(FormAttachment::adjacent_to(slices[2]));

slices[3]->set_bottom(FormAttachment::adjacent_to(slices[6]));
slices[4]->set_bottom(FormAttachment::adjacent_to(slices[7]));
slices[5]->set_bottom(FormAttachment::adjacent_to(slices[8]));
#endif
}

} // namespace gui
} // namespace openage

36 changes: 36 additions & 0 deletions cpp/gui/border.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2015-2015 the openage authors. See copying.md for legal info.

#ifndef OPENAGE_GUI_BORDER_H_
#define OPENAGE_GUI_BORDER_H_

#include "../texture.h"
#include "container.h"
#include "forward.h"

#include <array>

namespace openage {
namespace gui {

class Border : public ContainerBase {
public:
Border();

void set_texture(const Texture *texture, int base_subid);

Container *get_contents() {
return contents;
}

protected:
std::array<Image *, 9> slices;
Container *contents;
};

} // namespace gui
} // namespace openage

#endif



Loading