1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "ags/engine/ac/global_button.h"
24 #include "ags/shared/ac/common.h"
25 #include "ags/engine/ac/button.h"
26 #include "ags/shared/ac/game_setup_struct.h"
27 #include "ags/engine/ac/string.h"
28 #include "ags/shared/gui/gui_main.h"
29 #include "ags/shared/gui/gui_button.h"
30 
31 namespace AGS3 {
32 
33 using namespace AGS::Shared;
34 
35 
36 
SetButtonText(int guin,int objn,const char * newtx)37 void SetButtonText(int guin, int objn, const char *newtx) {
38 	VALIDATE_STRING(newtx);
39 	if ((guin < 0) | (guin >= _GP(game).numgui))
40 		quit("!SetButtonText: invalid GUI number");
41 	if ((objn < 0) | (objn >= _GP(guis)[guin].GetControlCount()))
42 		quit("!SetButtonText: invalid object number");
43 	if (_GP(guis)[guin].GetControlType(objn) != kGUIButton)
44 		quit("!SetButtonText: specified control is not a button");
45 
46 	GUIButton *guil = (GUIButton *)_GP(guis)[guin].GetControl(objn);
47 	Button_SetText(guil, newtx);
48 }
49 
50 
AnimateButton(int guin,int objn,int view,int loop,int speed,int repeat)51 void AnimateButton(int guin, int objn, int view, int loop, int speed, int repeat) {
52 	if ((guin < 0) | (guin >= _GP(game).numgui)) quit("!AnimateButton: invalid GUI number");
53 	if ((objn < 0) | (objn >= _GP(guis)[guin].GetControlCount())) quit("!AnimateButton: invalid object number");
54 	if (_GP(guis)[guin].GetControlType(objn) != kGUIButton)
55 		quit("!AnimateButton: specified control is not a button");
56 
57 	Button_Animate((GUIButton *)_GP(guis)[guin].GetControl(objn), view, loop, speed, repeat);
58 }
59 
60 
GetButtonPic(int guin,int objn,int ptype)61 int GetButtonPic(int guin, int objn, int ptype) {
62 	if ((guin < 0) | (guin >= _GP(game).numgui)) quit("!GetButtonPic: invalid GUI number");
63 	if ((objn < 0) | (objn >= _GP(guis)[guin].GetControlCount())) quit("!GetButtonPic: invalid object number");
64 	if (_GP(guis)[guin].GetControlType(objn) != kGUIButton)
65 		quit("!GetButtonPic: specified control is not a button");
66 	if ((ptype < 0) | (ptype > 3)) quit("!GetButtonPic: invalid pic type");
67 
68 	GUIButton *guil = (GUIButton *)_GP(guis)[guin].GetControl(objn);
69 
70 	if (ptype == 0) {
71 		// currently displayed pic
72 		if (guil->CurrentImage < 0)
73 			return guil->Image;
74 		return guil->CurrentImage;
75 	} else if (ptype == 1) {
76 		// nomal pic
77 		return guil->Image;
78 	} else if (ptype == 2) {
79 		// mouseover pic
80 		return guil->MouseOverImage;
81 	} else { // pushed pic
82 		return guil->PushedImage;
83 	}
84 
85 	quit("internal error in getbuttonpic");
86 }
87 
SetButtonPic(int guin,int objn,int ptype,int slotn)88 void SetButtonPic(int guin, int objn, int ptype, int slotn) {
89 	if ((guin < 0) | (guin >= _GP(game).numgui)) quit("!SetButtonPic: invalid GUI number");
90 	if ((objn < 0) | (objn >= _GP(guis)[guin].GetControlCount())) quit("!SetButtonPic: invalid object number");
91 	if (_GP(guis)[guin].GetControlType(objn) != kGUIButton)
92 		quit("!SetButtonPic: specified control is not a button");
93 	if ((ptype < 1) | (ptype > 3)) quit("!SetButtonPic: invalid pic type");
94 
95 	GUIButton *guil = (GUIButton *)_GP(guis)[guin].GetControl(objn);
96 	if (ptype == 1) {
97 		Button_SetNormalGraphic(guil, slotn);
98 	} else if (ptype == 2) {
99 		// mouseover pic
100 		Button_SetMouseOverGraphic(guil, slotn);
101 	} else { // pushed pic
102 		Button_SetPushedGraphic(guil, slotn);
103 	}
104 }
105 
106 } // namespace AGS3
107