diff options
author | Robert Vollmert <rvollmert@gmx.net> | 2010-09-05 08:56:03 +0200 |
---|---|---|
committer | Robert Vollmert <rvollmert@gmx.net> | 2010-09-05 10:12:56 +0200 |
commit | f07c2355e9784425d99a62335927de80be00fff4 (patch) | |
tree | 79f0060acde0f035c832e0073e2b83af06dfc20f /crawl-ref/source/viewgeom.h | |
parent | d8051c6f31ef3369827b6eaa4a6ccaaa72a8086e (diff) | |
download | crawl-ref-f07c2355e9784425d99a62335927de80be00fff4.tar.gz crawl-ref-f07c2355e9784425d99a62335927de80be00fff4.zip |
View coordinates now relative to viewport, not screen.
Also name some bounds checking functions less terribly and move to
viewgeom, and add new screen<->grid transforms.
Fixes issue #2215 (Fedhas targeting with messages_at_top) and is
likely to reduce the chance of future breakage with messages_at_top.
Also likely to introduce bugs.
Diffstat (limited to 'crawl-ref/source/viewgeom.h')
-rw-r--r-- | crawl-ref/source/viewgeom.h | 62 |
1 files changed, 45 insertions, 17 deletions
diff --git a/crawl-ref/source/viewgeom.h b/crawl-ref/source/viewgeom.h index 8d7644731a..839898ef12 100644 --- a/crawl-ref/source/viewgeom.h +++ b/crawl-ref/source/viewgeom.h @@ -74,19 +74,14 @@ public: // Recalculate vlos1 and vlos2. void calc_vlos(); - inline coord_def view_centre() const - { - return viewp + viewhalfsz; - } - inline coord_def view2grid(const coord_def &pos) const { - return (pos - view_centre() + vgrdc); + return (pos - viewhalfsz + vgrdc); } inline coord_def grid2view(const coord_def &pos) const { - return (pos - vgrdc + view_centre()); + return (pos - vgrdc + viewhalfsz); } inline coord_def view2show(const coord_def &pos) const @@ -109,33 +104,56 @@ public: return (view2grid(show2view(pos))); } + inline coord_def screen2view(const coord_def& pos) const + { + return (pos - viewp); + } + + inline coord_def view2screen(const coord_def& pos) const + { + return (pos + viewp); + } + + inline coord_def screen2grid(const coord_def& pos) const + { + return view2grid(screen2view(pos)); + } + + inline coord_def grid2screen(const coord_def& pos) const + { + return view2screen(grid2view(pos)); + } + coord_def glosc() const { return (glos1 + glos2) / 2; } - bool in_grid_los(const coord_def &c) const + bool in_los_bounds_g(const coord_def &c) const { return (c.x >= glos1.x && c.x <= glos2.x && c.y >= glos1.y && c.y <= glos2.y); } - bool in_view_los(const coord_def &c) const + bool in_los_bounds_v(const coord_def &c) const + { + return in_los_bounds_g(view2grid(c)); + } + + bool in_viewport_v(const coord_def &c) const { - return (c.x >= vlos1.x && c.x <= vlos2.x - && c.y >= vlos1.y && c.y <= vlos2.y); + return (c.x >= 0 && c.y >= 0 + && c.x < viewsz.x && c.y < viewsz.y); } - bool in_view_viewport(const coord_def &c) const + bool in_viewport_s(const coord_def &c) const { - return (c.x >= viewp.x && c.y >= viewp.y - && c.x < viewp.x + viewsz.x - && c.y < viewp.y + viewsz.y); + return in_viewport_v(screen2view(c)); } - bool in_grid_viewport(const coord_def &c) const + bool in_viewport_g(const coord_def &c) const { - return in_view_viewport(grid2view(c)); + return in_viewport_v(grid2view(c)); } }; @@ -171,4 +189,14 @@ inline coord_def show2grid(const coord_def &pos) return crawl_view.show2grid(pos); } +inline bool in_los_bounds_v(const coord_def& pos) +{ + return crawl_view.in_los_bounds_v(pos); +} + +inline bool in_los_bounds_g(const coord_def& pos) +{ + return crawl_view.in_los_bounds_g(pos); +} + #endif |