File: tilereg.h

package info (click to toggle)
crawl 2%3A0.23.0-1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 55,948 kB
  • sloc: cpp: 303,973; ansic: 28,797; python: 4,074; perl: 3,247; makefile: 1,632; java: 792; sh: 327; objc: 250; xml: 32; cs: 15; sed: 9; lisp: 3
file content (106 lines) | stat: -rw-r--r-- 2,431 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#ifdef USE_TILE_LOCAL
#pragma once

class ImageManager;
struct MouseEvent;

class Region
{
public:
    Region();
    virtual ~Region();

    void resize(int mx, int my);
    void place(int sx, int sy, int margin);
    void place(int sx, int sy, int ex, int ey, int margin);
    void place(int sx, int sy);
    void resize_to_fit(int wx, int wy);

    // Returns true if the mouse position is over the region
    // If true, then cx and cy are set in the range [0..mx-1], [0..my-1]
    virtual bool mouse_pos(int mouse_x, int mouse_y, int &cx, int &cy);

    virtual bool inside(int px, int py);
    virtual bool update_tip_text(string &tip) { return false; }
    virtual bool update_alt_text(string &alt) { return false; }
    virtual int handle_mouse(MouseEvent &event) = 0;

    virtual void render() = 0;
    virtual void clear() = 0;

    const virtual int grid_width_to_pixels(int x) const;
    const virtual int grid_height_to_pixels(int y) const;

    // Geometry
    // <-----------------wx----------------------->
    // sx     ox                                ex
    // |margin| text/tile area            |margin|

    // Offset in pixels
    int ox;
    int oy;

    // Unit size
    int dx;
    int dy;

    // Region size in dx/dy
    int mx;
    int my;

    // Width of the region in pixels
    int wx;
    int wy;

    // Start position in pixels (top left)
    int sx;
    int sy;

    // End position in pixels (bottom right)
    int ex;
    int ey;

protected:
    virtual void recalculate();
    virtual void calculate_grid_size(int inner_x, int inner_y);
    virtual void on_resize() = 0;
    void set_transform(bool no_scaling = false);
};

class FontWrapper;

// A convenience class for holding all the data that TileRegion and
// derived classes need in their constructors.
class TileRegionInit
{
public:
    TileRegionInit(ImageManager *_im, FontWrapper *_font, int _tx, int _ty) :
        im(_im), tag_font(_font), tile_x(_tx), tile_y(_ty) { }
    TileRegionInit() { }

    ImageManager *im;
    FontWrapper *tag_font;
    int tile_x;
    int tile_y;
};

class TileRegion : public Region
{
public:
    TileRegion(const TileRegionInit &init);
    ~TileRegion();

protected:
    ImageManager *m_image;
    FontWrapper *m_tag_font;
    bool m_dirty;
};

// An abstract tiles-only region that takes control over all input.
class ControlRegion : public Region
{
public:
    virtual void run() = 0;
};

#endif