Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2016-07-23 22:10:24 +0200
committerStijn Buys <ingar@osirion.org>2016-07-23 22:10:24 +0200
commit5de756948709c153894d6b13b5bbc62e722e4149 (patch)
tree24f92adc944b51616858f52e75d81c2522af930b /src
parent492a5aabefb1a25d6c497bb1c8e12201c6d36f1d (diff)
Made the map widgets catch mouse release events,
preventing events from trickling through to the HUD.
Diffstat (limited to 'src')
-rw-r--r--src/client/galaxymapwidget.cc44
-rw-r--r--src/client/galaxymapwidget.h5
-rw-r--r--src/client/mapwidget.cc85
-rw-r--r--src/client/mapwidget.h5
4 files changed, 103 insertions, 36 deletions
diff --git a/src/client/galaxymapwidget.cc b/src/client/galaxymapwidget.cc
index 47d1f79..25460b8 100644
--- a/src/client/galaxymapwidget.cc
+++ b/src/client/galaxymapwidget.cc
@@ -38,11 +38,16 @@ void GalaxyMapWidget::set_zone(core::Zone *zone)
bool GalaxyMapWidget::on_mousepress(const unsigned int button)
{
- if (button == SDL_BUTTON_LEFT) {
- if (hover()) {
- if (zone() && (zone()->id() == hover())) {
+ if (button == SDL_BUTTON_LEFT)
+ {
+ if (hover())
+ {
+ if (zone() && (zone()->id() == hover()))
+ {
emit(ui::Widget::EventDoubleClicked);
- } else {
+ }
+ else
+ {
set_zone(core::Zone::find(hover()));
emit(ui::Widget::EventClicked);
}
@@ -54,16 +59,28 @@ bool GalaxyMapWidget::on_mousepress(const unsigned int button)
}
+bool GalaxyMapWidget::on_mouserelease(const unsigned int button)
+{
+ if (button == SDL_BUTTON_LEFT)
+ {
+ return true;
+ }
+
+ return false;
+}
+
void GalaxyMapWidget::draw()
{
// size and global location of the map
const float map_size = math::min(width(), height());
math::Vector2f map_location(global_location());
- if (map_size < width()) {
+ if (map_size < width())
+ {
map_location[0] += (width() - map_size) * 0.5f;
}
- if (map_size < height()) {
+ if (map_size < height())
+ {
map_location[1] += (height() - map_size) * 0.5f;
}
@@ -78,7 +95,8 @@ void GalaxyMapWidget::draw()
gl::color(0, 0, 0.25f);
gl::begin(gl::Lines);
- for (float i = 0; i <= grid_size; i += 1.0f) {
+ for (float i = 0; i <= grid_size; i += 1.0f)
+ {
gl::vertex(map_location.x(), map_location.y() + map_size / grid_size * i);
gl::vertex(map_location.x() + map_size, map_location.y() + map_size / grid_size * i);
@@ -117,7 +135,8 @@ void GalaxyMapWidget::draw()
for (core::Zone::Registry::iterator it = core::Zone::registry().begin(); it != core::Zone::registry().end(); it++) {
zone = (*it).second;
- if (zone->has_flag(core::Zone::Hidden)) {
+ if (zone->has_flag(core::Zone::Hidden))
+ {
continue;
}
@@ -127,12 +146,15 @@ void GalaxyMapWidget::draw()
icon_location[0] += map_size / scale * zone->location().x();
icon_location[1] += map_size - map_size / scale * zone->location().y(); // flip vertically
- if (math::distancesquared(cursor, icon_location) < (r*r)) {
+ if (math::distancesquared(cursor, icon_location) < (r*r))
+ {
galaxymapwidget_hover_id = zone->id();
}
- if (zone == galaxymapwidget_zone) {
- if (core::application()->time() - floorf(core::application()->time()) < 0.5f) {
+ if (zone == galaxymapwidget_zone)
+ {
+ if (core::application()->time() - floorf(core::application()->time()) < 0.5f)
+ {
draw_icon = false;
}
}
diff --git a/src/client/galaxymapwidget.h b/src/client/galaxymapwidget.h
index a3cc01d..a48e070 100644
--- a/src/client/galaxymapwidget.h
+++ b/src/client/galaxymapwidget.h
@@ -45,6 +45,11 @@ protected:
* */
virtual bool on_mousepress(const unsigned int button);
+ /**
+ * @brief mouse button release event handler
+ * */
+ virtual bool on_mouserelease(const unsigned int button);
+
private:
float galaxymapwidget_zoom;
diff --git a/src/client/mapwidget.cc b/src/client/mapwidget.cc
index 54e109e..20bb979 100644
--- a/src/client/mapwidget.cc
+++ b/src/client/mapwidget.cc
@@ -47,11 +47,14 @@ void MapWidget::set_zone(core::Zone *zone)
bool MapWidget::on_mousepress(const unsigned int button)
{
- if (button == SDL_BUTTON_LEFT) {
- if (mapwidget_zone && hover()) {
+ if (button == SDL_BUTTON_LEFT)
+ {
+ if (mapwidget_zone && hover())
+ {
core::Entity *target = mapwidget_zone->find_entity(hover());
- if (targets::is_valid_map_target(target)) {
+ if (targets::is_valid_map_target(target))
+ {
set_target(target);
emit(ui::Widget::EventClicked);
}
@@ -63,6 +66,16 @@ bool MapWidget::on_mousepress(const unsigned int button)
}
+bool MapWidget::on_mouserelease(const unsigned int button)
+{
+ if (button == SDL_BUTTON_LEFT)
+ {
+ return true;
+ }
+
+ return false;
+}
+
void MapWidget::draw()
{
if (!mapwidget_zone)
@@ -72,10 +85,12 @@ void MapWidget::draw()
const float map_size = math::min(width(), height());
math::Vector2f map_location(global_location());
- if (map_size < width()) {
+ if (map_size < width())
+ {
map_location[0] += (width() - map_size) * 0.5f;
}
- if (map_size < height()) {
+ if (map_size < height())
+ {
map_location[1] += (height() - map_size) * 0.5f;
}
@@ -122,52 +137,63 @@ void MapWidget::draw()
gl::begin(gl::Quads);
- for (core::Zone::Content::iterator it = mapwidget_zone->content().begin(); it != mapwidget_zone->content().end(); it++) {
+ for (core::Zone::Content::iterator it = mapwidget_zone->content().begin(); it != mapwidget_zone->content().end(); it++)
+ {
core::Entity *entity = (*it);
bool draw_icon = false;
icon_location.assign(map_center);
- if (targets::is_valid_map_target(entity)) {
+ if (targets::is_valid_map_target(entity))
+ {
draw_icon = true;
icon_location[0] -= map_size / scale * entity->location().y();
icon_location[1] -= map_size / scale * entity->location().x();
- if (math::distancesquared(cursor, icon_location) < (r*r)) {
+ if (math::distancesquared(cursor, icon_location) < (r*r))
+ {
mapwidget_hover_id = entity->id();
}
- if (entity == mapwidget_target) {
- if (core::application()->time() - floorf(core::application()->time()) < 0.5f) {
+ if (entity == mapwidget_target)
+ {
+ if (core::application()->time() - floorf(core::application()->time()) < 0.5f)
+ {
draw_icon = false;
}
}
}
- if (draw_icon) {
+ if (draw_icon)
+ {
color.assign(entity->color());
color.a = 1.0f;
- if (entity->type() == core::Entity::Globe) {
+ if (entity->type() == core::Entity::Globe)
+ {
// FIXME this is copy paste from the renderer and can use a cleanup
core::EntityGlobe *globe = static_cast<core::EntityGlobe *>(entity);
- if (globe->has_flag(core::Entity::Bright)) {
+ if (globe->has_flag(core::Entity::Bright))
+ {
gl::end();
// load globe corona texture
- if (!globe->corona_id() && globe->coronaname().size()) {
+ if (!globe->corona_id() && globe->coronaname().size())
+ {
globe->set_corona_id(render::Textures::load("textures/" + globe->coronaname()));
- if (!globe->corona_id()) {
+ if (!globe->corona_id())
+ {
globe->set_coronaname("");
}
}
// draw corona
- if (globe->corona_id()) {
+ if (globe->corona_id())
+ {
texture_current = render::Textures::bind(globe->corona_id());
gl::begin(gl::Quads);
@@ -187,30 +213,37 @@ void MapWidget::draw()
}
// bind bright globe icon texture
- if (texture_current != texture_bright) {
+ if (texture_current != texture_bright)
+ {
texture_current = render::Textures::bind(texture_bright);
}
gl::begin(gl::Quads);
- } else {
-
+ }
+ else
+ {
// bind globe icon texture
- if (texture_current != texture_globe) {
+ if (texture_current != texture_globe)
+ {
gl::end();
texture_current = render::Textures::bind(texture_globe);
gl::begin(gl::Quads);
}
}
- } else {
- if (texture_current != texture_entity) {
+ }
+ else
+ {
+ if (texture_current != texture_entity)
+ {
gl::end();
texture_current = render::Textures::bind(texture_entity);
gl::begin(gl::Quads);
}
}
- if (entity == core::localplayer()->mission_target()) {
+ if (entity == core::localplayer()->mission_target())
+ {
color.assign(palette()->mission());
}
@@ -234,7 +267,8 @@ void MapWidget::draw()
// draw localcontrol icon
// TODO draw a ship icon
- if (core::localcontrol()->zone() == mapwidget_zone) {
+ if (core::localcontrol()->zone() == mapwidget_zone)
+ {
core::EntityControlable *controlable = core::localcontrol();
//if (core::localcontrol()->state() != core::Entity::Docked) {
@@ -242,7 +276,8 @@ void MapWidget::draw()
icon_location[0] -= map_size / scale * controlable->location().y();
icon_location[1] -= map_size / scale * controlable->location().x();
- if (core::application()->time() - floorf(core::application()->time()) < 0.5f) {
+ if (core::application()->time() - floorf(core::application()->time()) < 0.5f)
+ {
texture_current = render::Textures::bind(texture_entity);
gl::begin(gl::Quads);
diff --git a/src/client/mapwidget.h b/src/client/mapwidget.h
index 38485fd..26a6876 100644
--- a/src/client/mapwidget.h
+++ b/src/client/mapwidget.h
@@ -52,6 +52,11 @@ protected:
* */
virtual bool on_mousepress(const unsigned int button);
+ /**
+ * @brief mouse button release event handler
+ * */
+ virtual bool on_mouserelease(const unsigned int button);
+
private:
float mapwidget_zoom;