MCPcopy Create free account
hub / github.com/GarageGames/Torque3D / ptSetFrameRanges

Method ptSetFrameRanges

Engine/source/gui/controls/guiAnimBitmapCtrl.cpp:143–210  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

141}
142
143bool guiAnimBitmapCtrl::ptSetFrameRanges(void *object, const char *index, const char *data)
144{
145 guiAnimBitmapCtrl *pData = static_cast<guiAnimBitmapCtrl*>(object);
146
147 // Here we parse mAnimTexFramesString into byte-size frame numbers in mAnimTexFrames.
148 // Each frame token must be separated by whitespace.
149 // A frame token must be a positive integer frame number or a range of frame numbers
150 // separated with a '-'.
151 // The range separator, '-', cannot have any whitspace around it.
152 // Ranges can be specified to move through the frames in reverse as well as forward.
153 // Frame numbers exceeding the number of tiles will wrap.
154 // example:
155 // "0-16 20 19 18 17 31-21"
156
157 S32 n_tiles = pData->mAnimTexTiling.x * pData->mAnimTexTiling.y - 1;
158
159 pData->mAnimTexFrames.clear();
160
161 if (!data || !data[0])
162 {
163 for (S32 i = 0; i <= n_tiles; i++)
164 pData->mAnimTexFrames.push_back(i);
165 pData->mNumFrames = pData->mAnimTexFrames.size() - 1;
166 if (pData->mCurFrameIndex > pData->mNumFrames)
167 pData->mCurFrameIndex = pData->mNumFrames;
168 return true;
169 }
170 char* tokCopy = new char[dStrlen(data) + 1];
171 dStrcpy(tokCopy, data);
172
173 char* currTok = dStrtok(tokCopy, " \t");
174 while (currTok != NULL)
175 {
176 char* minus = dStrchr(currTok, '-');
177 if (minus)
178 {
179 // add a range of frames
180 *minus = '\0';
181 S32 range_a = dAtoi(currTok);
182 S32 range_b = dAtoi(minus + 1);
183 if (range_b < range_a)
184 {
185 // reverse frame range
186 for (S32 i = range_a; i >= range_b; i--)
187 pData->mAnimTexFrames.push_back(i);
188 }
189 else
190 {
191 // forward frame range
192 for (S32 i = range_a; i <= range_b; i++)
193 pData->mAnimTexFrames.push_back(i);
194 }
195 }
196 else
197 {
198 // add one frame
199 pData->mAnimTexFrames.push_back(dAtoi(currTok));
200 }

Callers

nothing calls this directly

Calls 8

dStrcpyFunction · 0.85
dStrtokFunction · 0.85
dStrlenFunction · 0.50
dStrchrFunction · 0.50
dAtoiFunction · 0.50
clearMethod · 0.45
push_backMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected