Browse Source

normalize point type and fix errors

Bastien Sevajol 3 years ago
parent
commit
e695904137
9 changed files with 148 additions and 110 deletions
  1. 8 8
      Cargo.lock
  2. 1 1
      Cargo.toml
  3. 3 1
      src/main.rs
  4. 12 1
      src/physics/mod.rs
  5. 0 11
      src/physics/position.rs
  6. 23 3
      src/physics/util.rs
  7. 8 6
      src/scene/item.rs
  8. 87 73
      src/scene/main.rs
  9. 6 6
      src/ui/mod.rs

+ 8 - 8
Cargo.lock View File

@@ -808,14 +808,6 @@ dependencies = [
808 808
 ]
809 809
 
810 810
 [[package]]
811
-name = "ggez_tests"
812
-version = "0.1.0"
813
-dependencies = [
814
- "ggez",
815
- "glam",
816
-]
817
-
818
-[[package]]
819 811
 name = "gif"
820 812
 version = "0.11.2"
821 813
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1697,6 +1689,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1697 1689
 checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3"
1698 1690
 
1699 1691
 [[package]]
1692
+name = "open_combat"
1693
+version = "0.1.0"
1694
+dependencies = [
1695
+ "ggez",
1696
+ "glam",
1697
+]
1698
+
1699
+[[package]]
1700 1700
 name = "ordered-float"
1701 1701
 version = "2.1.1"
1702 1702
 source = "registry+https://github.com/rust-lang/crates.io-index"

+ 1 - 1
Cargo.toml View File

@@ -1,5 +1,5 @@
1 1
 [package]
2
-name = "ggez_tests"
2
+name = "open_combat"
3 3
 version = "0.1.0"
4 4
 authors = ["Sevajol Bastien <contact@bux.fr>"]
5 5
 edition = "2018"

+ 3 - 1
src/main.rs View File

@@ -11,8 +11,10 @@ mod physics;
11 11
 mod scene;
12 12
 mod ui;
13 13
 
14
-// TODO: create a ScenePosition and a WindowPosition to be more explicit
15 14
 type Point2 = Vec2;
15
+type WindowPoint = Vec2;
16
+type Offset = Vec2;
17
+type ScenePoint = Vec2;
16 18
 type Vector2 = Vec2;
17 19
 
18 20
 const TARGET_FPS: u32 = 60; // execute update code 60x per seconds

+ 12 - 1
src/physics/mod.rs View File

@@ -1,4 +1,3 @@
1
-pub mod position;
2 1
 pub mod util;
3 2
 
4 3
 #[derive(Debug)]
@@ -10,3 +9,15 @@ pub enum PhysicEvent {
10 9
 pub enum MetaEvent {
11 10
     FeelExplosion,
12 11
 }
12
+
13
+#[derive(Eq, PartialEq, Hash)]
14
+pub struct GridPosition {
15
+    x: i32,
16
+    y: i32,
17
+}
18
+
19
+impl GridPosition {
20
+    pub fn new(x: i32, y: i32) -> Self {
21
+        Self { x, y }
22
+    }
23
+}

+ 0 - 11
src/physics/position.rs View File

@@ -1,11 +0,0 @@
1
-#[derive(Eq, PartialEq, Hash)]
2
-pub struct GridPosition {
3
-    x: i32,
4
-    y: i32,
5
-}
6
-
7
-impl GridPosition {
8
-    pub fn new(x: i32, y: i32) -> Self {
9
-        Self { x, y }
10
-    }
11
-}

+ 23 - 3
src/physics/util.rs View File

@@ -1,5 +1,5 @@
1
-use crate::physics::position::GridPosition;
2
-use crate::{Point2, Vector2, GRID_TILE_HEIGHT, GRID_TILE_WIDTH};
1
+use crate::physics::GridPosition;
2
+use crate::{ScenePoint, Vector2, WindowPoint, GRID_TILE_HEIGHT, GRID_TILE_WIDTH};
3 3
 
4 4
 pub fn vec_from_angle(angle: f32) -> Vector2 {
5 5
     let vx = angle.sin();
@@ -7,9 +7,29 @@ pub fn vec_from_angle(angle: f32) -> Vector2 {
7 7
     Vector2::new(vx, vy)
8 8
 }
9 9
 
10
-pub fn grid_position_from_position(position: &Point2) -> GridPosition {
10
+pub fn grid_position_from_scene_point(position: &ScenePoint) -> GridPosition {
11 11
     GridPosition::new(
12 12
         (position.x / GRID_TILE_WIDTH) as i32,
13 13
         (position.y / GRID_TILE_HEIGHT) as i32,
14 14
     )
15 15
 }
16
+
17
+pub fn scene_point_from_window_point(
18
+    window_point: &WindowPoint,
19
+    display_offset: &WindowPoint,
20
+) -> ScenePoint {
21
+    ScenePoint::new(
22
+        window_point.x - display_offset.x,
23
+        window_point.y - display_offset.y,
24
+    )
25
+}
26
+
27
+pub fn window_point_from_scene_point(
28
+    scene_point: &ScenePoint,
29
+    display_offset: &WindowPoint,
30
+) -> WindowPoint {
31
+    WindowPoint::new(
32
+        scene_point.x + display_offset.x,
33
+        scene_point.y + display_offset.y,
34
+    )
35
+}

+ 8 - 6
src/scene/item.rs View File

@@ -1,10 +1,12 @@
1 1
 use ggez::graphics;
2 2
 
3 3
 use crate::behavior::ItemBehavior;
4
-use crate::physics::position::GridPosition;
4
+use crate::physics::GridPosition;
5 5
 use crate::physics::{util, MetaEvent};
6 6
 use crate::scene::SpriteType;
7
-use crate::{Point2, SCENE_ITEMS_SPRITE_SHEET_HEIGHT, SCENE_ITEMS_SPRITE_SHEET_WIDTH};
7
+use crate::{
8
+    Offset, Point2, ScenePoint, SCENE_ITEMS_SPRITE_SHEET_HEIGHT, SCENE_ITEMS_SPRITE_SHEET_WIDTH,
9
+};
8 10
 
9 11
 pub struct SceneItemSpriteInfo {
10 12
     pub relative_start_y: f32,
@@ -55,7 +57,7 @@ pub enum SceneItemType {
55 57
 
56 58
 pub struct SceneItem {
57 59
     pub type_: SceneItemType,
58
-    pub position: Point2,
60
+    pub position: ScenePoint,
59 61
     pub grid_position: GridPosition,
60 62
     pub state: ItemState,
61 63
     pub meta_events: Vec<MetaEvent>,
@@ -63,11 +65,11 @@ pub struct SceneItem {
63 65
 }
64 66
 
65 67
 impl SceneItem {
66
-    pub fn new(type_: SceneItemType, position: Point2, state: ItemState) -> Self {
68
+    pub fn new(type_: SceneItemType, position: ScenePoint, state: ItemState) -> Self {
67 69
         Self {
68 70
             type_,
69 71
             position: position.clone(),
70
-            grid_position: util::grid_position_from_position(&position.clone()),
72
+            grid_position: util::grid_position_from_scene_point(&position.clone()),
71 73
             state,
72 74
             meta_events: vec![],
73 75
             current_frame: 0,
@@ -96,7 +98,7 @@ impl SceneItem {
96 98
                 sprite_info.relative_tile_height,
97 99
             ))
98 100
             .rotation(90.0f32.to_radians())
99
-            .offset(Point2::new(0.5, 0.5))
101
+            .offset(Offset::new(0.5, 0.5))
100 102
     }
101 103
 
102 104
     pub fn sprite_type(&self) -> SpriteType {

+ 87 - 73
src/scene/main.rs View File

@@ -7,15 +7,17 @@ use ggez::timer::check_update_time;
7 7
 use ggez::{event, graphics, input, Context, GameResult};
8 8
 
9 9
 use crate::behavior::ItemBehavior;
10
-use crate::physics::position::GridPosition;
10
+use crate::physics::util::scene_point_from_window_point;
11
+use crate::physics::util::window_point_from_scene_point;
12
+use crate::physics::GridPosition;
11 13
 use crate::physics::{util, MetaEvent, PhysicEvent};
12 14
 use crate::scene::item::{ItemState, SceneItem, SceneItemType};
13 15
 use crate::ui::scene_item_menu::SceneItemMenuItem;
14 16
 use crate::ui::{SceneItemPrepareOrder, UiItem, UiSpriteInfo, UserEvent};
15 17
 use crate::{
16
-    Point2, ANIMATE_EACH, DEFAULT_SELECTED_SQUARE_SIDE, DEFAULT_SELECTED_SQUARE_SIDE_HALF,
17
-    DISPLAY_OFFSET_BY, DISPLAY_OFFSET_BY_SPEED, MAX_FRAME_I, META_EACH, PHYSICS_EACH,
18
-    SCENE_ITEMS_CHANGE_ERR_MSG, SPRITE_EACH, TARGET_FPS,
18
+    Offset, ScenePoint, WindowPoint, ANIMATE_EACH, DEFAULT_SELECTED_SQUARE_SIDE,
19
+    DEFAULT_SELECTED_SQUARE_SIDE_HALF, DISPLAY_OFFSET_BY, DISPLAY_OFFSET_BY_SPEED, MAX_FRAME_I,
20
+    META_EACH, PHYSICS_EACH, SCENE_ITEMS_CHANGE_ERR_MSG, SPRITE_EACH, TARGET_FPS,
19 21
 };
20 22
 use ggez::input::keyboard::KeyCode;
21 23
 
@@ -24,7 +26,7 @@ pub struct MainState {
24 26
     frame_i: u32,
25 27
 
26 28
     // display
27
-    display_offset: Point2,
29
+    display_offset: Offset,
28 30
     sprite_sheet_batch: graphics::spritebatch::SpriteBatch,
29 31
     map_batch: graphics::spritebatch::SpriteBatch,
30 32
     ui_batch: graphics::spritebatch::SpriteBatch,
@@ -37,12 +39,12 @@ pub struct MainState {
37 39
     physics_events: Vec<PhysicEvent>,
38 40
 
39 41
     // user interactions
40
-    left_click_down: Option<Point2>,
41
-    right_click_down: Option<Point2>,
42
-    current_cursor_position: Point2,
42
+    left_click_down: Option<WindowPoint>,
43
+    right_click_down: Option<WindowPoint>,
44
+    current_cursor_position: WindowPoint,
43 45
     user_events: Vec<UserEvent>,
44
-    selected_scene_items: Vec<usize>,         // scene_item usize
45
-    scene_item_menu: Option<(usize, Point2)>, // scene_item usize, display_at
46
+    selected_scene_items: Vec<usize>,             // scene_item usize
47
+    scene_item_menu: Option<(usize, ScenePoint)>, // scene_item usize, display_at
46 48
     scene_item_prepare_order: Option<SceneItemPrepareOrder>,
47 49
 }
48 50
 
@@ -66,7 +68,7 @@ impl MainState {
66 68
 
67 69
                 scene_items.push(SceneItem::new(
68 70
                     SceneItemType::Soldier,
69
-                    Point2::new((x as f32 * 24.0) + 100.0, (y as f32 * 24.0) + 100.0),
71
+                    ScenePoint::new((x as f32 * 24.0) + 100.0, (y as f32 * 24.0) + 100.0),
70 72
                     ItemState::new(current_behavior),
71 73
                 ));
72 74
             }
@@ -74,7 +76,7 @@ impl MainState {
74 76
 
75 77
         let mut main_state = MainState {
76 78
             frame_i: 0,
77
-            display_offset: Point2::new(0.0, 0.0),
79
+            display_offset: Offset::new(0.0, 0.0),
78 80
             sprite_sheet_batch,
79 81
             map_batch,
80 82
             ui_batch,
@@ -83,7 +85,7 @@ impl MainState {
83 85
             physics_events: vec![],
84 86
             left_click_down: None,
85 87
             right_click_down: None,
86
-            current_cursor_position: Point2::new(0.0, 0.0),
88
+            current_cursor_position: WindowPoint::new(0.0, 0.0),
87 89
             user_events: vec![],
88 90
             selected_scene_items: vec![],
89 91
             scene_item_menu: None,
@@ -91,7 +93,7 @@ impl MainState {
91 93
         };
92 94
 
93 95
         for (i, scene_item) in main_state.scene_items.iter().enumerate() {
94
-            let grid_position = util::grid_position_from_position(&scene_item.position);
96
+            let grid_position = util::grid_position_from_scene_point(&scene_item.position);
95 97
             main_state
96 98
                 .scene_items_by_grid_position
97 99
                 .entry(grid_position)
@@ -125,14 +127,12 @@ impl MainState {
125 127
 
126 128
         while let Some(user_event) = self.user_events.pop() {
127 129
             match user_event {
128
-                UserEvent::Click(click_position) => {
129
-                    let scene_position = Point2::new(
130
-                        click_position.x - self.display_offset.x,
131
-                        click_position.y - self.display_offset.y,
132
-                    );
130
+                UserEvent::Click(window_click_point) => {
131
+                    let scene_position =
132
+                        scene_point_from_window_point(&window_click_point, &self.display_offset);
133 133
                     self.selected_scene_items.drain(..);
134 134
                     if let Some(scene_item_usize) =
135
-                        self.get_first_scene_item_for_position(&scene_position)
135
+                        self.get_first_scene_item_for_scene_point(&scene_position)
136 136
                     {
137 137
                         self.selected_scene_items.push(scene_item_usize);
138 138
                     }
@@ -143,20 +143,22 @@ impl MainState {
143 143
                     }
144 144
 
145 145
                     // FIXME BS NOW: interpreter sur quel element du menu on a click ...
146
-                    if let Some((scene_item_usize, menu_position)) = self.scene_item_menu {
146
+                    if let Some((scene_item_usize, scene_menu_point)) = self.scene_item_menu {
147
+                        let window_menu_point =
148
+                            window_point_from_scene_point(&scene_menu_point, &self.display_offset);
147 149
                         let menu_sprite_info = UiSpriteInfo::from_type(UiItem::SceneItemMenu);
148 150
                         let scene_item = self
149 151
                             .scene_items
150 152
                             .get(scene_item_usize)
151 153
                             .expect(SCENE_ITEMS_CHANGE_ERR_MSG);
152
-                        if click_position.x >= menu_position.x
153
-                            && click_position.x <= menu_position.x + menu_sprite_info.width
154
-                            && click_position.y >= menu_position.y
155
-                            && click_position.y <= menu_position.y + menu_sprite_info.height
154
+                        if window_click_point.x >= window_menu_point.x
155
+                            && window_click_point.x <= window_menu_point.x + menu_sprite_info.width
156
+                            && window_click_point.y >= window_menu_point.y
157
+                            && window_click_point.y <= window_menu_point.y + menu_sprite_info.height
156 158
                         {
157 159
                             if let Some(menu_item) = menu_sprite_info.which_item_clicked(
158
-                                menu_position,
159
-                                click_position,
160
+                                window_menu_point,
161
+                                window_click_point,
160 162
                                 scene_item,
161 163
                             ) {
162 164
                                 match menu_item {
@@ -172,29 +174,26 @@ impl MainState {
172 174
                         }
173 175
                     };
174 176
                 }
175
-                UserEvent::AreaSelection(from, to) => {
176
-                    let scene_from = Point2::new(
177
-                        from.x - self.display_offset.x,
178
-                        from.y - self.display_offset.y,
179
-                    );
180
-                    let scene_to =
181
-                        Point2::new(to.x - self.display_offset.x, to.y - self.display_offset.y);
177
+                UserEvent::AreaSelection(window_from, window_to) => {
178
+                    let scene_from =
179
+                        scene_point_from_window_point(&window_from, &self.display_offset);
180
+                    let scene_to = scene_point_from_window_point(&window_to, &self.display_offset);
182 181
                     self.selected_scene_items.drain(..);
183 182
                     self.selected_scene_items
184
-                        .extend(self.get_scene_items_for_area(&scene_from, &scene_to));
183
+                        .extend(self.get_scene_items_for_scene_area(&scene_from, &scene_to));
185 184
                 }
186
-                UserEvent::RightClick(position) => {
187
-                    // FIXME BS NOW: il y a des probleme de position avec le offset !
185
+                UserEvent::RightClick(window_position) => {
186
+                    let scene_point =
187
+                        scene_point_from_window_point(&window_position, &self.display_offset);
188 188
                     if let Some(scene_item_usize) =
189
-                        self.get_first_scene_item_for_position(&position)
189
+                        self.get_first_scene_item_for_scene_point(&scene_point)
190 190
                     {
191 191
                         if self.selected_scene_items.contains(&scene_item_usize) {
192 192
                             let scene_item = self
193 193
                                 .scene_items
194 194
                                 .get(scene_item_usize)
195 195
                                 .expect(SCENE_ITEMS_CHANGE_ERR_MSG);
196
-                            self.scene_item_menu =
197
-                                Some((scene_item_usize, scene_item.position.clone()))
196
+                            self.scene_item_menu = Some((scene_item_usize, scene_item.position))
198 197
                         }
199 198
                     }
200 199
                 }
@@ -211,7 +210,7 @@ impl MainState {
211 210
                     // TODO ici il faut calculer le déplacement réél (en fonction des ticks, etc ...)
212 211
                     scene_item.position.x += 1.0;
213 212
                     scene_item.grid_position =
214
-                        util::grid_position_from_position(&scene_item.position);
213
+                        util::grid_position_from_scene_point(&scene_item.position);
215 214
                 }
216 215
                 _ => {}
217 216
             }
@@ -273,21 +272,14 @@ impl MainState {
273 272
         }
274 273
     }
275 274
 
276
-    fn position_with_display_offset(&self, position: &Point2) -> Point2 {
277
-        Point2::new(
278
-            position.x + self.display_offset.x,
279
-            position.y + self.display_offset.y,
280
-        )
281
-    }
282
-
283
-    fn get_first_scene_item_for_position(&self, position: &Point2) -> Option<usize> {
275
+    fn get_first_scene_item_for_scene_point(&self, scene_position: &ScenePoint) -> Option<usize> {
284 276
         // TODO: if found multiple: select nearest
285 277
         for (i, scene_item) in self.scene_items.iter().enumerate() {
286 278
             let sprite_info = scene_item.sprite_info();
287
-            if scene_item.position.x >= position.x - sprite_info.tile_width
288
-                && scene_item.position.x <= position.x + sprite_info.tile_width
289
-                && scene_item.position.y >= position.y - sprite_info.tile_height
290
-                && scene_item.position.y <= position.y + sprite_info.tile_height
279
+            if scene_item.position.x >= scene_position.x - sprite_info.tile_width
280
+                && scene_item.position.x <= scene_position.x + sprite_info.tile_width
281
+                && scene_item.position.y >= scene_position.y - sprite_info.tile_height
282
+                && scene_item.position.y <= scene_position.y + sprite_info.tile_height
291 283
             {
292 284
                 return Some(i);
293 285
             }
@@ -296,7 +288,7 @@ impl MainState {
296 288
         None
297 289
     }
298 290
 
299
-    fn get_scene_items_for_area(&self, from: &Point2, to: &Point2) -> Vec<usize> {
291
+    fn get_scene_items_for_scene_area(&self, from: &ScenePoint, to: &ScenePoint) -> Vec<usize> {
300 292
         let mut selection = vec![];
301 293
 
302 294
         for (i, scene_item) in self.scene_items.iter().enumerate() {
@@ -408,18 +400,26 @@ impl event::EventHandler for MainState {
408 400
 
409 401
             scene_mesh_builder.circle(
410 402
                 DrawMode::fill(),
411
-                left_click_down,
403
+                window_point_from_scene_point(&left_click_down, &self.display_offset),
412 404
                 2.0,
413 405
                 2.0,
414 406
                 graphics::YELLOW,
415 407
             )?;
416 408
         }
417 409
 
418
-        if let Some((_, position)) = self.scene_item_menu {
410
+        scene_mesh_builder.circle(
411
+            DrawMode::fill(),
412
+            scene_point_from_window_point(&self.current_cursor_position, &self.display_offset),
413
+            2.0,
414
+            2.0,
415
+            graphics::BLUE,
416
+        )?;
417
+
418
+        if let Some((_, scene_point)) = self.scene_item_menu {
419 419
             self.ui_batch.add(
420 420
                 UiSpriteInfo::from_type(UiItem::SceneItemMenu)
421 421
                     .as_draw_param()
422
-                    .dest(position),
422
+                    .dest(scene_point),
423 423
             );
424 424
         }
425 425
 
@@ -431,7 +431,13 @@ impl event::EventHandler for MainState {
431 431
                         .get(*scene_item_usize)
432 432
                         .expect(SCENE_ITEMS_CHANGE_ERR_MSG);
433 433
                     scene_mesh_builder.line(
434
-                        &vec![scene_item.position.clone(), self.current_cursor_position],
434
+                        &vec![
435
+                            scene_item.position.clone(),
436
+                            scene_point_from_window_point(
437
+                                &self.current_cursor_position,
438
+                                &self.display_offset,
439
+                            ),
440
+                        ],
435 441
                         2.0,
436 442
                         graphics::WHITE,
437 443
                     )?;
@@ -442,33 +448,41 @@ impl event::EventHandler for MainState {
442 448
         self.map_batch.add(
443 449
             graphics::DrawParam::new()
444 450
                 .src(graphics::Rect::new(0.0, 0.0, 1.0, 1.0))
445
-                .dest(Point2::new(0.0, 0.0)),
451
+                .dest(ScenePoint::new(0.0, 0.0)),
446 452
         );
447 453
 
448 454
         let scene_mesh = scene_mesh_builder.build(ctx)?;
449 455
         graphics::draw(
450 456
             ctx,
451 457
             &self.map_batch,
452
-            graphics::DrawParam::new()
453
-                .dest(self.position_with_display_offset(&Point2::new(0.0, 0.0))),
458
+            graphics::DrawParam::new().dest(window_point_from_scene_point(
459
+                &ScenePoint::new(0.0, 0.0),
460
+                &self.display_offset,
461
+            )),
454 462
         )?;
455 463
         graphics::draw(
456 464
             ctx,
457 465
             &self.sprite_sheet_batch,
458
-            graphics::DrawParam::new()
459
-                .dest(self.position_with_display_offset(&Point2::new(0.0, 0.0))),
466
+            graphics::DrawParam::new().dest(window_point_from_scene_point(
467
+                &ScenePoint::new(0.0, 0.0),
468
+                &self.display_offset,
469
+            )),
460 470
         )?;
461 471
         graphics::draw(
462 472
             ctx,
463 473
             &scene_mesh,
464
-            graphics::DrawParam::new()
465
-                .dest(self.position_with_display_offset(&Point2::new(0.0, 0.0))),
474
+            graphics::DrawParam::new().dest(window_point_from_scene_point(
475
+                &ScenePoint::new(0.0, 0.0),
476
+                &self.display_offset,
477
+            )),
466 478
         )?;
467 479
         graphics::draw(
468 480
             ctx,
469 481
             &self.ui_batch,
470
-            graphics::DrawParam::new()
471
-                .dest(self.position_with_display_offset(&Point2::new(0.0, 0.0))),
482
+            graphics::DrawParam::new().dest(window_point_from_scene_point(
483
+                &ScenePoint::new(0.0, 0.0),
484
+                &self.display_offset,
485
+            )),
472 486
         )?;
473 487
 
474 488
         self.sprite_sheet_batch.clear();
@@ -483,10 +497,10 @@ impl event::EventHandler for MainState {
483 497
     fn mouse_button_down_event(&mut self, _ctx: &mut Context, button: MouseButton, x: f32, y: f32) {
484 498
         match button {
485 499
             MouseButton::Left => {
486
-                self.left_click_down = Some(Point2::new(x, y));
500
+                self.left_click_down = Some(WindowPoint::new(x, y));
487 501
             }
488 502
             MouseButton::Right => {
489
-                self.right_click_down = Some(Point2::new(x, y));
503
+                self.right_click_down = Some(WindowPoint::new(x, y));
490 504
             }
491 505
             MouseButton::Middle => {}
492 506
             MouseButton::Other(_) => {}
@@ -497,14 +511,14 @@ impl event::EventHandler for MainState {
497 511
         match button {
498 512
             MouseButton::Left => {
499 513
                 if let Some(left_click_down) = self.left_click_down {
500
-                    if left_click_down == Point2::new(x, y) {
514
+                    if left_click_down == WindowPoint::new(x, y) {
501 515
                         self.user_events.push(UserEvent::Click(left_click_down));
502 516
                     } else {
503
-                        let from = Point2::new(
517
+                        let from = WindowPoint::new(
504 518
                             cmp::min(left_click_down.x as i32, x as i32) as f32,
505 519
                             cmp::min(left_click_down.y as i32, y as i32) as f32,
506 520
                         );
507
-                        let to = Point2::new(
521
+                        let to = WindowPoint::new(
508 522
                             cmp::max(left_click_down.x as i32, x as i32) as f32,
509 523
                             cmp::max(left_click_down.y as i32, y as i32) as f32,
510 524
                         );
@@ -525,6 +539,6 @@ impl event::EventHandler for MainState {
525 539
     }
526 540
 
527 541
     fn mouse_motion_event(&mut self, _ctx: &mut Context, x: f32, y: f32, _dx: f32, _dy: f32) {
528
-        self.current_cursor_position = Point2::new(x, y);
542
+        self.current_cursor_position = WindowPoint::new(x, y);
529 543
     }
530 544
 }

+ 6 - 6
src/ui/mod.rs View File

@@ -2,7 +2,7 @@ use ggez::graphics;
2 2
 
3 3
 use crate::scene::item::SceneItem;
4 4
 use crate::ui::scene_item_menu::SceneItemMenuItem;
5
-use crate::{Point2, UI_SPRITE_SHEET_HEIGHT, UI_SPRITE_SHEET_WIDTH};
5
+use crate::{Point2, WindowPoint, UI_SPRITE_SHEET_HEIGHT, UI_SPRITE_SHEET_WIDTH};
6 6
 
7 7
 pub mod scene_item_menu;
8 8
 
@@ -44,8 +44,8 @@ impl UiSpriteInfo {
44 44
 
45 45
     pub fn which_item_clicked(
46 46
         &self,
47
-        menu_position: Point2,
48
-        click_position: Point2,
47
+        window_menu_point: WindowPoint,
48
+        window_click_point: WindowPoint,
49 49
         scene_item: &SceneItem,
50 50
     ) -> Option<SceneItemMenuItem> {
51 51
         Some(SceneItemMenuItem::Move)
@@ -54,9 +54,9 @@ impl UiSpriteInfo {
54 54
 
55 55
 #[derive(Debug)]
56 56
 pub enum UserEvent {
57
-    Click(Point2),                 // Window coordinates
58
-    RightClick(Point2),            // Window coordinates
59
-    AreaSelection(Point2, Point2), // Window coordinates
57
+    Click(WindowPoint),                      // Window coordinates
58
+    RightClick(WindowPoint),                 // Window coordinates
59
+    AreaSelection(WindowPoint, WindowPoint), // Window coordinates
60 60
 }
61 61
 
62 62
 pub enum SceneItemPrepareOrder {