-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstylus.h
132 lines (105 loc) · 3.85 KB
/
stylus.h
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
* PROPRIETARY INFORMATION. This software is proprietary to POWDER
* Development, and is not to be reproduced, transmitted, or disclosed
* in any way without written permission.
*
* Produced by: Jeff Lait
*
* POWDER Development
*
* NAME: stylus.h ( POWDER Library, C++ )
*
* COMMENTS:
*/
#ifndef __stylus__
#define __stylus__
#include <mygba.h>
class MOB;
enum STYLUSREGIONS
{
REGION_NONE = 0,
// The increasingly inaccurately named bottom buttons.
REGION_BOTTOMBUTTON = 1,
REGION_MAPTILES = 2,
REGION_INVENTORY = 4,
REGION_SLOTS = 8,
REGION_MENU = 16,
REGION_DISPLAYTEXT = 32,
REGION_TENDIR = 64,
REGION_FOURDIR = 128,
REGION_KEYBOARD = 256,
REGION_SIDEBUTTON = 512,
};
// Create this object at the start of a method that will query the
// stylus to ensure stylus processing is activated & cleared as
// expected.
class STYLUSLOCK
{
public:
explicit STYLUSLOCK(int regions = 0);
virtual ~STYLUSLOCK();
// You can only call this once and only if no region was specified
// in the constructor.
void setRegion(int regions);
// This is an *inclusive* range!
// Specified relative to GBA.
// Specified in *tile* coordinates - ie, everything is multiplied
// by 8.
// -1 means not to clip.
void setRange(int left, int top, int right, int bottom);
bool snap(int &x, int &y);
// Returns true if inside user specified range.
bool inRange(int x, int y);
// Processes the stylus, possibly drawing the sprite overlay if
// needed.
void update();
// Clears any pending stylus buttons
void clear();
// Waits for a proper stylus press on an inventory item, returning it.
bool selectinventoryitem(int &cx, int &cy);
// Waits for a proper click on an itemslot.
bool selectinventoryslot(int &slot);
// Queries for a menu choice in the given range.
bool selectmenu(int &menu, int x, int y, bool &inbounds);
// Performs any drag requests, updating the action strip accordingly
bool performDrags(int menuy, int startoflist, int endoflist,
const u8 *menu,
u8 *actionstrip);
// Perform inventory drags. We are returned the start & end slots
// if we return true.
// This doesn't use "locking" but rather soft touch.
// That sentence doesn't make any sense, does it?
// This is like stylus_queryinventory in that it is independent
// of normal menu options.
bool performInventoryDrag(int &sx, int &sy, int &ex, int &ey, MOB *owner, bool &dirty);
// Returns true if a click occured in the bottom
// row of buttons, each 16x16 and starting on y=160.
// buttonsel is which button was pressed.
// Nothing is consumed if the click is outside this range.
bool getbottombutton(int &buttonsel);
// Returns true if proper press. dy is set to +/-1 or 0.
bool getdisplaytext(int &dy);
// Sets the ten dir options, sets cancel if a valid click outside.
bool gettendir(int &dx, int &dy, int &dz, bool &cancel);
// Sets the ten dir options, sets cancel if a valid click outside.
bool getfourdir(int &dx, int &dy, bool &cancel);
// Returns which character tile was hit.
bool getchartile(int &cx, int &cy);
// Returns true if a click has occured.
// Cancel will be true if it was a cancel select
// mx & my will store the map coordinates of where the click occured.
bool getmaptile(int &mx, int &my, bool &cancel);
private:
STYLUSLOCK *myParent;
int myRegion;
int myLeft, myRight, myTop, myBottom;
// Flags controlling our current state.
bool myWaitForDown;
bool myStarted, myValid, myButton, myBadSnap;
bool myDragging;
int myStartX, myStartY;
int myLastDragX, myLastDragY;
};
// Sets cx/cy to inventory item if stylus is currently over them.
bool stylus_queryinventoryitem(int &cx, int &cy);
#endif