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/slider.h"
24 #include "ags/shared/ac/common.h"
25 #include "ags/shared/debugging/out.h"
26 #include "ags/engine/script/script_api.h"
27 #include "ags/engine/script/script_runtime.h"
28 #include "ags/globals.h"
29 
30 namespace AGS3 {
31 
32 // *** SLIDER FUNCTIONS
33 
Slider_SetMax(GUISlider * guisl,int valn)34 void Slider_SetMax(GUISlider *guisl, int valn) {
35 
36 	if (valn != guisl->MaxValue) {
37 		guisl->MaxValue = valn;
38 
39 		if (guisl->Value > guisl->MaxValue)
40 			guisl->Value = guisl->MaxValue;
41 		if (guisl->MinValue > guisl->MaxValue)
42 			quit("!Slider.Max: minimum cannot be greater than maximum");
43 
44 		guisl->NotifyParentChanged();
45 	}
46 
47 }
48 
Slider_GetMax(GUISlider * guisl)49 int Slider_GetMax(GUISlider *guisl) {
50 	return guisl->MaxValue;
51 }
52 
Slider_SetMin(GUISlider * guisl,int valn)53 void Slider_SetMin(GUISlider *guisl, int valn) {
54 
55 	if (valn != guisl->MinValue) {
56 		guisl->MinValue = valn;
57 
58 		if (guisl->Value < guisl->MinValue)
59 			guisl->Value = guisl->MinValue;
60 		if (guisl->MinValue > guisl->MaxValue)
61 			quit("!Slider.Min: minimum cannot be greater than maximum");
62 
63 		guisl->NotifyParentChanged();
64 	}
65 
66 }
67 
Slider_GetMin(GUISlider * guisl)68 int Slider_GetMin(GUISlider *guisl) {
69 	return guisl->MinValue;
70 }
71 
Slider_SetValue(GUISlider * guisl,int valn)72 void Slider_SetValue(GUISlider *guisl, int valn) {
73 	if (valn > guisl->MaxValue) valn = guisl->MaxValue;
74 	if (valn < guisl->MinValue) valn = guisl->MinValue;
75 
76 	if (valn != guisl->Value) {
77 		guisl->Value = valn;
78 		guisl->NotifyParentChanged();
79 	}
80 }
81 
Slider_GetValue(GUISlider * guisl)82 int Slider_GetValue(GUISlider *guisl) {
83 	return guisl->Value;
84 }
85 
Slider_GetBackgroundGraphic(GUISlider * guisl)86 int Slider_GetBackgroundGraphic(GUISlider *guisl) {
87 	return (guisl->BgImage > 0) ? guisl->BgImage : 0;
88 }
89 
Slider_SetBackgroundGraphic(GUISlider * guisl,int newImage)90 void Slider_SetBackgroundGraphic(GUISlider *guisl, int newImage) {
91 	if (newImage != guisl->BgImage) {
92 		guisl->BgImage = newImage;
93 		guisl->NotifyParentChanged();
94 	}
95 }
96 
Slider_GetHandleGraphic(GUISlider * guisl)97 int Slider_GetHandleGraphic(GUISlider *guisl) {
98 	return (guisl->HandleImage > 0) ? guisl->HandleImage : 0;
99 }
100 
Slider_SetHandleGraphic(GUISlider * guisl,int newImage)101 void Slider_SetHandleGraphic(GUISlider *guisl, int newImage) {
102 	if (newImage != guisl->HandleImage) {
103 		guisl->HandleImage = newImage;
104 		guisl->NotifyParentChanged();
105 	}
106 }
107 
Slider_GetHandleOffset(GUISlider * guisl)108 int Slider_GetHandleOffset(GUISlider *guisl) {
109 	return guisl->HandleOffset;
110 }
111 
Slider_SetHandleOffset(GUISlider * guisl,int newOffset)112 void Slider_SetHandleOffset(GUISlider *guisl, int newOffset) {
113 	if (newOffset != guisl->HandleOffset) {
114 		guisl->HandleOffset = newOffset;
115 		guisl->NotifyParentChanged();
116 	}
117 }
118 
119 //=============================================================================
120 //
121 // Script API Functions
122 //
123 //=============================================================================
124 
125 // int (GUISlider *guisl)
Sc_Slider_GetBackgroundGraphic(void * self,const RuntimeScriptValue * params,int32_t param_count)126 RuntimeScriptValue Sc_Slider_GetBackgroundGraphic(void *self, const RuntimeScriptValue *params, int32_t param_count) {
127 	API_OBJCALL_INT(GUISlider, Slider_GetBackgroundGraphic);
128 }
129 
130 // void (GUISlider *guisl, int newImage)
Sc_Slider_SetBackgroundGraphic(void * self,const RuntimeScriptValue * params,int32_t param_count)131 RuntimeScriptValue Sc_Slider_SetBackgroundGraphic(void *self, const RuntimeScriptValue *params, int32_t param_count) {
132 	API_OBJCALL_VOID_PINT(GUISlider, Slider_SetBackgroundGraphic);
133 }
134 
135 // int (GUISlider *guisl)
Sc_Slider_GetHandleGraphic(void * self,const RuntimeScriptValue * params,int32_t param_count)136 RuntimeScriptValue Sc_Slider_GetHandleGraphic(void *self, const RuntimeScriptValue *params, int32_t param_count) {
137 	API_OBJCALL_INT(GUISlider, Slider_GetHandleGraphic);
138 }
139 
140 // void (GUISlider *guisl, int newImage)
Sc_Slider_SetHandleGraphic(void * self,const RuntimeScriptValue * params,int32_t param_count)141 RuntimeScriptValue Sc_Slider_SetHandleGraphic(void *self, const RuntimeScriptValue *params, int32_t param_count) {
142 	API_OBJCALL_VOID_PINT(GUISlider, Slider_SetHandleGraphic);
143 }
144 
145 // int (GUISlider *guisl)
Sc_Slider_GetHandleOffset(void * self,const RuntimeScriptValue * params,int32_t param_count)146 RuntimeScriptValue Sc_Slider_GetHandleOffset(void *self, const RuntimeScriptValue *params, int32_t param_count) {
147 	API_OBJCALL_INT(GUISlider, Slider_GetHandleOffset);
148 }
149 
150 // void (GUISlider *guisl, int newOffset)
Sc_Slider_SetHandleOffset(void * self,const RuntimeScriptValue * params,int32_t param_count)151 RuntimeScriptValue Sc_Slider_SetHandleOffset(void *self, const RuntimeScriptValue *params, int32_t param_count) {
152 	API_OBJCALL_VOID_PINT(GUISlider, Slider_SetHandleOffset);
153 }
154 
155 // int (GUISlider *guisl)
Sc_Slider_GetMax(void * self,const RuntimeScriptValue * params,int32_t param_count)156 RuntimeScriptValue Sc_Slider_GetMax(void *self, const RuntimeScriptValue *params, int32_t param_count) {
157 	API_OBJCALL_INT(GUISlider, Slider_GetMax);
158 }
159 
160 // void (GUISlider *guisl, int valn)
Sc_Slider_SetMax(void * self,const RuntimeScriptValue * params,int32_t param_count)161 RuntimeScriptValue Sc_Slider_SetMax(void *self, const RuntimeScriptValue *params, int32_t param_count) {
162 	API_OBJCALL_VOID_PINT(GUISlider, Slider_SetMax);
163 }
164 
165 // int (GUISlider *guisl)
Sc_Slider_GetMin(void * self,const RuntimeScriptValue * params,int32_t param_count)166 RuntimeScriptValue Sc_Slider_GetMin(void *self, const RuntimeScriptValue *params, int32_t param_count) {
167 	API_OBJCALL_INT(GUISlider, Slider_GetMin);
168 }
169 
170 // void (GUISlider *guisl, int valn)
Sc_Slider_SetMin(void * self,const RuntimeScriptValue * params,int32_t param_count)171 RuntimeScriptValue Sc_Slider_SetMin(void *self, const RuntimeScriptValue *params, int32_t param_count) {
172 	API_OBJCALL_VOID_PINT(GUISlider, Slider_SetMin);
173 }
174 
175 // int (GUISlider *guisl)
Sc_Slider_GetValue(void * self,const RuntimeScriptValue * params,int32_t param_count)176 RuntimeScriptValue Sc_Slider_GetValue(void *self, const RuntimeScriptValue *params, int32_t param_count) {
177 	API_OBJCALL_INT(GUISlider, Slider_GetValue);
178 }
179 
180 // void Slider_SetValue(GUISlider *guisl, int valn)
Sc_Slider_SetValue(void * self,const RuntimeScriptValue * params,int32_t param_count)181 RuntimeScriptValue Sc_Slider_SetValue(void *self, const RuntimeScriptValue *params, int32_t param_count) {
182 	API_OBJCALL_VOID_PINT(GUISlider, Slider_SetValue);
183 }
184 
185 
RegisterSliderAPI()186 void RegisterSliderAPI() {
187 	ccAddExternalObjectFunction("Slider::get_BackgroundGraphic", Sc_Slider_GetBackgroundGraphic);
188 	ccAddExternalObjectFunction("Slider::set_BackgroundGraphic", Sc_Slider_SetBackgroundGraphic);
189 	ccAddExternalObjectFunction("Slider::get_HandleGraphic", Sc_Slider_GetHandleGraphic);
190 	ccAddExternalObjectFunction("Slider::set_HandleGraphic", Sc_Slider_SetHandleGraphic);
191 	ccAddExternalObjectFunction("Slider::get_HandleOffset", Sc_Slider_GetHandleOffset);
192 	ccAddExternalObjectFunction("Slider::set_HandleOffset", Sc_Slider_SetHandleOffset);
193 	ccAddExternalObjectFunction("Slider::get_Max", Sc_Slider_GetMax);
194 	ccAddExternalObjectFunction("Slider::set_Max", Sc_Slider_SetMax);
195 	ccAddExternalObjectFunction("Slider::get_Min", Sc_Slider_GetMin);
196 	ccAddExternalObjectFunction("Slider::set_Min", Sc_Slider_SetMin);
197 	ccAddExternalObjectFunction("Slider::get_Value", Sc_Slider_GetValue);
198 	ccAddExternalObjectFunction("Slider::set_Value", Sc_Slider_SetValue);
199 }
200 
201 } // namespace AGS3
202