[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Wesnoth-cvs-commits] wesnoth/src display.cpp display.hpp
From: |
Guillaume Melquiond |
Subject: |
[Wesnoth-cvs-commits] wesnoth/src display.cpp display.hpp |
Date: |
Thu, 07 Oct 2004 14:49:56 -0400 |
CVSROOT: /cvsroot/wesnoth
Module name: wesnoth
Branch:
Changes by: Guillaume Melquiond <address@hidden> 04/10/07 18:43:00
Modified files:
src : display.cpp display.hpp
Log message:
Applied mark7's hex detection patch (#3416).
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/display.cpp.diff?tr1=1.266&tr2=1.267&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/display.hpp.diff?tr1=1.83&tr2=1.84&r1=text&r2=text
Patches:
Index: wesnoth/src/display.cpp
diff -u wesnoth/src/display.cpp:1.266 wesnoth/src/display.cpp:1.267
--- wesnoth/src/display.cpp:1.266 Thu Oct 7 01:47:33 2004
+++ wesnoth/src/display.cpp Thu Oct 7 18:42:59 2004
@@ -1,4 +1,4 @@
-/* $Id: display.cpp,v 1.266 2004/10/07 01:47:33 Sirp Exp $ */
+/* $Id: display.cpp,v 1.267 2004/10/07 18:42:59 silene Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -239,12 +239,48 @@
xclick -= rect.x;
yclick -= rect.y;
- const int tile_width = hex_width();
+ return pixel_position_to_hex(xpos_ + xclick, ypos_ + yclick);
+}
- const int xtile = (xpos_ + xclick)/tile_width;
- const int ytile = (ypos_ + yclick - (is_odd(xtile) ? zoom_/2 :
0))/zoom_; //(yclick + is_odd(xtile) ? -yclick/2 : 0)/zoom_;
+gamemap::location display::pixel_position_to_hex(int x, int y)
+{
+ const int tesselation_x_size = hex_size() * 3 / 2;
+ const int tesselation_y_size = hex_size();
+ const int x_base = x / tesselation_x_size * 2;
+ const int x_mod = x % tesselation_x_size;
+ const int y_base = y / tesselation_y_size;
+ const int y_mod = y % tesselation_y_size;
+
+ int x_modifier;
+ int y_modifier;
+
+ if (y_mod < tesselation_y_size / 2) {
+ if ((x_mod * 2 + y_mod) < (hex_size() / 2)) {
+ x_modifier = -1;
+ y_modifier = -1;
+ } else if ((x_mod * 2 - y_mod) < (hex_size() * 3 / 2)) {
+ x_modifier = 0;
+ y_modifier = 0;
+ } else {
+ x_modifier = 1;
+ y_modifier = -1;
+ }
+
+ } else {
+ if ((x_mod * 2 - (y_mod - hex_size() / 2)) < 0) {
+ x_modifier = -1;
+ y_modifier = 0;
+ } else if ((x_mod * 2 + (y_mod - hex_size() / 2)) < hex_size()
* 2) {
+ x_modifier = 0;
+ y_modifier = 0;
+ } else {
+ x_modifier = 1;
+ y_modifier = 0;
+ }
+ }
- return gamemap::location(xtile,ytile);
+ return gamemap::location(x_base + x_modifier,
+ y_base + y_modifier);
}
int display::get_location_x(const gamemap::location& loc) const
Index: wesnoth/src/display.hpp
diff -u wesnoth/src/display.hpp:1.83 wesnoth/src/display.hpp:1.84
--- wesnoth/src/display.hpp:1.83 Sat Sep 11 21:22:57 2004
+++ wesnoth/src/display.hpp Thu Oct 7 18:42:59 2004
@@ -1,4 +1,4 @@
-/* $Id: display.hpp,v 1.83 2004/09/11 21:22:57 gruikya Exp $ */
+/* $Id: display.hpp,v 1.84 2004/10/07 18:42:59 silene Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -135,11 +135,16 @@
//over
void highlight_hex(gamemap::location hex);
- //given x,y co-ordinates of a pixel, will return the location of the
- //hex that this pixel corresponds to. Returns an invalid location is
- //the mouse isn't over any valid location.
+ //given x,y co-ordinates of an onscreen pixel, will return the
+ //location of the hex that this pixel corresponds to. Returns an
+ //invalid location is the mouse isn't over any valid location.
gamemap::location hex_clicked_on(int x, int y);
-
+
+ //given x,y co-ordinates of a pixel on the map, will return the
+ //location of the hex that this pixel corresponds to. Returns an
+ //invalid location is the mouse isn't over any valid location.
+ gamemap::location pixel_position_to_hex(int x, int y);
+
//given x,y co-ordinates of the mouse, will return the location of the
//hex in the minimap that the mouse is currently over, or an invalid
//location if the mouse isn't over the minimap.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Wesnoth-cvs-commits] wesnoth/src display.cpp display.hpp,
Guillaume Melquiond <=