File: OBUTTON.h

package info (click to toggle)
7kaa 2.15.6%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 131,312 kB
  • sloc: cpp: 134,790; asm: 3,523; ansic: 1,949; perl: 1,665; makefile: 1,181; sh: 126; pascal: 27
file content (148 lines) | stat: -rw-r--r-- 4,539 bytes parent folder | download | duplicates (3)
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
 * Seven Kingdoms: Ancient Adversaries
 *
 * Copyright 1997,1998 Enlight Software Ltd.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

//Filename    : OBUTTON.H
//Description : Header file of button object

#ifndef __OBUTTON_H
#define __OBUTTON_H

#ifndef __OVGABUF_H
#include <OVGABUF.h>
#endif

//------- Define constant ---------//

enum  { BUTTON_TEXT=1, BUTTON_BITMAP, BUTTON_UDF };

//----------- Define variable type -----------//

typedef void (*ButtonFP)(int,int,int,int);  // user defined function to be called

//-------------- Define class Button -------------//

class Font;

class Button
{
public:
	enum  { STR_BUF_LEN=40, HELP_CODE_LEN=8 };

	char  	  		is_pushed;
	char  	  		enable_flag;   // either 1(Yes) or 0(No)
	short 	  		x1,y1,x2,y2;   // some function will need to access the button's coordination for area detection

	char     	   init_flag;
	char     	   button_type;
	char				use_texture_flag;
	char			button_wait; // user pushed button and waiting for release
	uint32_t		button_wait_timeout;
	unsigned short button_key;     // button is pressed when user press this key

	char  	  		str_buf[STR_BUF_LEN+1];
	const void* 	  		body_ptr;      // can be a text pointer, bitmap pointer or a pointer to user defined function
	char  	  		elastic;
	Font* 	  		font_ptr;

	char				help_code[HELP_CODE_LEN+1];

public:
	Button();

	void use_texture()						 { use_texture_flag=1; }

	void reset()                         { init_flag=0; }
	void set_font(Font*);
	void set_key(unsigned keyCode)       { button_key = keyCode; }
	void create(int,int,int,int,int,const void*,char=1,char=0);
	void set_body(void*);
	void set_help_code(const char* helpCode);

	//-------- text button ------------//

	void create_text(int x1,int y1,int x2,int y2,const char* textPtr,char elastic=1,char defIsPushed=0)
		  { create( BUTTON_TEXT,x1,y1,x2,y2,textPtr,elastic,defIsPushed); }

	void paint_text(int x1,int y1,int x2,int y2,const char* textPtr,char elastic=1,char defIsPushed=0)
		  { create( BUTTON_TEXT,x1,y1,x2,y2,textPtr,elastic,defIsPushed); paint(); }

	void create_text(int x1,int y1,const char* textPtr,char elastic=1,char defIsPushed=0);

	void paint_text(int x1,int y1,const char* textPtr,char elastic=1,char defIsPushed=0);

	//-------- bitmap button -------------//

	void create_bitmap(int x1,int y1,int x2,int y2,char* iconPtr,char elastic=1,char defIsPushed=0)
		  { create( BUTTON_BITMAP,x1,y1,x2,y2,iconPtr,elastic,defIsPushed); }

	void paint_bitmap(int x1,int y1,int x2,int y2,char* iconPtr,char elastic=1,char defIsPushed=0)
		  { create( BUTTON_BITMAP,x1,y1,x2,y2,iconPtr,elastic,defIsPushed); paint(); }

	//-------- user-defined function button ---------//

	void create_udf(int x1,int y1,int x2,int y2,ButtonFP funcPtr,char elastic=1,char defIsPushed=0)
		  { create( BUTTON_UDF,x1,y1,x2,y2,(void*)funcPtr,elastic,defIsPushed); }

	void paint_udf(int x1,int y1,int x2,int y2,ButtonFP funcPtr,char elastic=1,char defIsPushed=0)
		  { create( BUTTON_UDF,x1,y1,x2,y2,(void*)funcPtr,elastic,defIsPushed); paint(); }

   //--------------------------------------//

   void paint(int= -1, int=1);

   int  detect(unsigned=0,unsigned=0,int=0,int=0);

   void hide(char);
	void hide();
   void show();

	void push()        { if(!is_pushed) paint(1); }
	void pop()         { if(is_pushed)  paint(0);  }

	void disable()     { if(enable_flag)  { enable_flag=0; paint(); } }
	void enable()      { if(!enable_flag) { enable_flag=1; paint(); } }

	void wait_press(int inactiveTimeOut=0);
};

//------- Define class ButtonGroup ----------------//

class ButtonGroup
{
public:
   int     button_num;
   int     button_pressed;
   Button* button_array;

public:
	ButtonGroup(int);
	~ButtonGroup();

   void paint(int= -1);
   int  detect();
   void push(int);

   Button& operator[](int);
   int     operator()()          { return button_pressed; }
};

//-------------------------------------------------//

#endif