File: | home/HaikuArchives/ArtPaint/addons/AddOns/Twirl/Twirl.cpp |
Warning: | line 121, column 8 Value stored to 'target_bpr' during its initialization is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* |
2 | * Copyright 2003, Heikki Suhonen |
3 | * Distributed under the terms of the MIT License. |
4 | * |
5 | * Authors: |
6 | * Heikki Suhonen <heikki.suhonen@gmail.com> |
7 | * |
8 | */ |
9 | #include <Bitmap.h> |
10 | #include <Catalog.h> |
11 | #include <math.h> |
12 | #include <LayoutBuilder.h> |
13 | #include <Slider.h> |
14 | #include <StatusBar.h> |
15 | #include <Window.h> |
16 | |
17 | #define PI3.14159265358979323846 M_PI3.14159265358979323846 |
18 | |
19 | #include "AddOns.h" |
20 | #include "ManipulatorInformer.h" |
21 | #include "Twirl.h" |
22 | #include "PixelOperations.h" |
23 | #include "Selection.h" |
24 | |
25 | #undef B_TRANSLATION_CONTEXT"AddOns_Twirl" |
26 | #define B_TRANSLATION_CONTEXT"AddOns_Twirl" "AddOns_Twirl" |
27 | |
28 | |
29 | #ifdef __cplusplus201402L |
30 | extern "C" { |
31 | #endif |
32 | char name[255] = B_TRANSLATE_MARK("Twirl" B_UTF8_ELLIPSIS)("Twirl" "\xE2\x80\xA6"); |
33 | char menu_help_string[255] = B_TRANSLATE_MARK("Twirls the active layer.")("Twirls the active layer."); |
34 | int32 add_on_api_version = ADD_ON_API_VERSION; |
35 | add_on_types add_on_type = DISTORT_ADD_ON; |
36 | #ifdef __cplusplus201402L |
37 | } |
38 | #endif |
39 | |
40 | |
41 | Manipulator* instantiate_add_on(BBitmap *bm,ManipulatorInformer *i) |
42 | { |
43 | delete i; |
44 | return new TwirlManipulator(bm); |
45 | } |
46 | |
47 | |
48 | TwirlManipulator::TwirlManipulator(BBitmap *bm) |
49 | : WindowGUIManipulator() |
50 | { |
51 | last_calculated_resolution = 8; |
52 | lowest_available_quality = 8; |
53 | preview_bitmap = NULL__null; |
54 | copy_of_the_preview_bitmap = NULL__null; |
55 | config_view = NULL__null; |
56 | |
57 | sin_table = new float[720]; |
58 | cos_table = new float[720]; |
59 | for (int32 i=0;i<720;i++) { |
60 | sin_table[i] = sin((float)i/720.0*2*PI3.14159265358979323846); |
61 | cos_table[i] = cos((float)i/720.0*2*PI3.14159265358979323846); |
62 | } |
63 | |
64 | SetPreviewBitmap(bm); |
65 | } |
66 | |
67 | |
68 | TwirlManipulator::~TwirlManipulator() |
69 | { |
70 | delete[] sin_table; |
71 | delete[] cos_table; |
72 | |
73 | delete copy_of_the_preview_bitmap; |
74 | |
75 | if (config_view != NULL__null) { |
76 | config_view->RemoveSelf(); |
77 | delete config_view; |
78 | } |
79 | } |
80 | |
81 | |
82 | void TwirlManipulator::MouseDown(BPoint point,uint32,BView*,bool first_click) |
83 | { |
84 | if (first_click) |
85 | previous_settings = settings; |
86 | |
87 | settings.center = point; |
88 | if (config_view != NULL__null) |
89 | config_view->ChangeSettings(&settings); |
90 | } |
91 | |
92 | |
93 | BBitmap* TwirlManipulator::ManipulateBitmap(ManipulatorSettings *set,BBitmap *original,Selection *selection,BStatusBar *status_bar) |
94 | { |
95 | TwirlManipulatorSettings *new_settings = dynamic_cast<TwirlManipulatorSettings*>(set); |
96 | |
97 | if (new_settings == NULL__null) |
98 | return NULL__null; |
99 | |
100 | if (original == NULL__null) |
101 | return NULL__null; |
102 | |
103 | BBitmap *source_bitmap; |
104 | BBitmap *target_bitmap; |
105 | BBitmap *new_bitmap; |
106 | |
107 | if (original == preview_bitmap) { |
108 | target_bitmap = original; |
109 | source_bitmap = copy_of_the_preview_bitmap; |
110 | } |
111 | else { |
112 | target_bitmap = original; |
113 | new_bitmap = DuplicateBitmap(original,0); |
114 | source_bitmap = new_bitmap; |
115 | } |
116 | |
117 | |
118 | uint32 *source_bits = (uint32*)source_bitmap->Bits(); |
119 | uint32 *target_bits = (uint32*)target_bitmap->Bits(); |
120 | int32 source_bpr = source_bitmap->BytesPerRow()/4; |
121 | int32 target_bpr = target_bitmap->BytesPerRow()/4; |
Value stored to 'target_bpr' during its initialization is never read | |
122 | |
123 | |
124 | float start_y = 0; |
125 | float end_y = target_bitmap->Bounds().bottom; |
126 | float real_x; |
127 | float real_y; |
128 | float distance; |
129 | float center_distance_from_edges = new_settings->twirl_radius; |
130 | float cx = new_settings->center.x; |
131 | float cy = new_settings->center.y; |
132 | float k = new_settings->twirl_amount/(float)MAX_TWIRL_AMOUNT720; |
133 | float dx; |
134 | float dy; |
135 | int32 top = 0; |
136 | int32 bottom = target_bitmap->Bounds().bottom; |
137 | |
138 | BMessage progress_message = BMessage(B_UPDATE_STATUS_BAR); |
139 | progress_message.AddFloat("delta",0.0); |
140 | |
141 | union { |
142 | uint8 bytes[4]; |
143 | uint32 word; |
144 | } background; |
145 | |
146 | background.bytes[0] = 0xFF; |
147 | background.bytes[1] = 0xFF; |
148 | background.bytes[2] = 0xFF; |
149 | background.bytes[3] = 0x00; |
150 | |
151 | |
152 | if (selection->IsEmpty()) { |
153 | uint32 p1,p2,p3,p4; |
154 | for (float y=start_y;y<=end_y;y++) { |
155 | for (float x=0;x<source_bpr;x++) { |
156 | real_x = x-cx; |
157 | real_y = y-cy; |
158 | uint32 target_value = 0x00000000; |
159 | distance = sqrt(real_x*real_x+real_y*real_y); |
160 | |
161 | if (distance <= center_distance_from_edges) { |
162 | float omega = (center_distance_from_edges-distance)/center_distance_from_edges*k*2*PI3.14159265358979323846; |
163 | dx = (cos(omega)*real_x-sin(omega)*real_y)-real_x; |
164 | dy = (sin(omega)*real_x+cos(omega)*real_y)-real_y; |
165 | } |
166 | else { |
167 | dx = 0; |
168 | dy = 0; |
169 | } |
170 | int32 ceil_y = ceil(y+dy); |
171 | int32 floor_y = ceil_y -1; |
172 | int32 floor_x = floor(x+dx); |
173 | int32 ceil_x = floor_x+1; |
174 | |
175 | float v = ceil_y-(y+dy); |
176 | float u = (x+dx)-floor_x; |
177 | if ((ceil_y <= bottom) && (ceil_y>=top)) { |
178 | if ((floor_x >= 0) && (floor_x <source_bpr)) { |
179 | p1 = *(source_bits + ceil_y*source_bpr + floor_x); |
180 | } |
181 | else |
182 | p1 = background.word; |
183 | |
184 | if ((ceil_x >= 0) && (ceil_x <source_bpr)) { |
185 | p2 = *(source_bits + ceil_y*source_bpr + ceil_x); |
186 | } |
187 | else |
188 | p2 = background.word; |
189 | } |
190 | else { |
191 | p1 = background.word; |
192 | p2 = background.word; |
193 | } |
194 | if ((floor_y <= bottom) && (floor_y>=top)) { |
195 | if ((floor_x >= 0) && (floor_x <source_bpr)) { |
196 | p3 = *(source_bits + floor_y*source_bpr + floor_x); |
197 | } |
198 | else |
199 | p3 = background.word; |
200 | |
201 | if ((ceil_x >= 0) && (ceil_x <source_bpr)) { |
202 | p4 = *(source_bits + floor_y*source_bpr + ceil_x); |
203 | } |
204 | else |
205 | p4 = background.word; |
206 | } |
207 | else { |
208 | p3 = background.word; |
209 | p4 = background.word; |
210 | } |
211 | *target_bits++ = bilinear_interpolation(p1,p2,p3,p4,u,v); |
212 | } |
213 | // Send a progress-message if required |
214 | if ((status_bar != NULL__null) && ((int32)y%10 == 0)) { |
215 | progress_message.ReplaceFloat("delta",100.0/(float)(end_y-start_y)*10.0); |
216 | status_bar->Window()->PostMessage(&progress_message,status_bar); |
217 | } |
218 | } |
219 | } |
220 | else { |
221 | uint32 p1,p2,p3,p4; |
222 | for (float y=start_y;y<=end_y;y++) { |
223 | for (float x=0;x<source_bpr;x++) { |
224 | if (selection->ContainsPoint(x,y)) { |
225 | real_x = x-cx; |
226 | real_y = y-cy; |
227 | uint32 target_value = 0x00000000; |
228 | distance = sqrt(real_x*real_x+real_y*real_y); |
229 | |
230 | if (distance <= center_distance_from_edges) { |
231 | float omega = (center_distance_from_edges-distance)/center_distance_from_edges*k*2*PI3.14159265358979323846; |
232 | dx = (cos(omega)*real_x-sin(omega)*real_y)-real_x; |
233 | dy = (sin(omega)*real_x+cos(omega)*real_y)-real_y; |
234 | } |
235 | else { |
236 | dx = 0; |
237 | dy = 0; |
238 | } |
239 | float y_mix_upper = ceil(y+dy)-(y+dy); |
240 | float x_mix_right = (x+dx)- floor(x+dx); |
241 | if ((ceil(y+dy) <= bottom) && (ceil(y+dy)>=top)) { |
242 | if ((floor(x+dx) >= 0) && (floor(x+dx) <source_bpr)) { |
243 | p1 = *(source_bits + (int32)ceil(y+dy)*source_bpr + (int32)floor(x+dx)); |
244 | } |
245 | else |
246 | p1 = background.word; |
247 | |
248 | if ((ceil(x+dx) >= 0) && (ceil(x+dx) <source_bpr)) { |
249 | p2 = *(source_bits + (int32)ceil(y+dy)*source_bpr + (int32)ceil(x+dx)); |
250 | } |
251 | else |
252 | p2 = background.word; |
253 | } |
254 | else { |
255 | p1 = background.word; |
256 | p2 = background.word; |
257 | } |
258 | if ((floor(y+dy) <= bottom) && (floor(y+dy)>=top)) { |
259 | if ((floor(x+dx) >= 0) && (floor(x+dx) <source_bpr)) { |
260 | p3 = *(source_bits + (int32)floor(y+dy)*source_bpr + (int32)floor(x+dx)); |
261 | } |
262 | else |
263 | p3 = background.word; |
264 | |
265 | if ((ceil(x+dx) >= 0) && (ceil(x+dx) <source_bpr)) { |
266 | p4 = *(source_bits + (int32)floor(y+dy)*source_bpr + (int32)ceil(x+dx)); |
267 | } |
268 | else |
269 | p4 = background.word; |
270 | } |
271 | else { |
272 | p3 = background.word; |
273 | p4 = background.word; |
274 | } |
275 | |
276 | *target_bits++ = combine_4_pixels(p1,p2,p3,p4,(1-y_mix_upper)*(1-x_mix_right),(1-y_mix_upper)*(x_mix_right),(y_mix_upper)*(1-x_mix_right),(y_mix_upper)*(x_mix_right)); |
277 | } |
278 | else |
279 | *target_bits++ = *(source_bits + (int32)x + (int32)y*source_bpr); |
280 | } |
281 | // Send a progress-message if required |
282 | if ((status_bar != NULL__null) && ((int32)y%10 == 0)) { |
283 | progress_message.ReplaceFloat("delta",100.0/(float)(end_y-start_y)*10.0); |
284 | status_bar->Window()->PostMessage(&progress_message,status_bar); |
285 | } |
286 | } |
287 | } |
288 | |
289 | return original; |
290 | } |
291 | |
292 | |
293 | int32 TwirlManipulator::PreviewBitmap(Selection *selection,bool full_quality,BRegion *updated_region) |
294 | { |
295 | if ((settings == previous_settings) == FALSE0) { |
296 | previous_settings = settings; |
297 | last_calculated_resolution = lowest_available_quality; |
298 | } |
299 | else { |
300 | last_calculated_resolution = max_c(highest_available_quality,floor(last_calculated_resolution/2.0))((highest_available_quality)>(floor(last_calculated_resolution /2.0))?(highest_available_quality):(floor(last_calculated_resolution /2.0))); |
301 | } |
302 | if (full_quality == TRUE1) |
303 | last_calculated_resolution = min_c(last_calculated_resolution,1)((last_calculated_resolution)>(1)?(1):(last_calculated_resolution )); |
304 | |
305 | |
306 | uint32 *source_bits = (uint32*)copy_of_the_preview_bitmap->Bits(); |
307 | uint32 *target_bits = (uint32*)preview_bitmap->Bits(); |
308 | int32 source_bpr = copy_of_the_preview_bitmap->BytesPerRow()/4; |
309 | int32 target_bpr = preview_bitmap->BytesPerRow()/4; |
310 | |
311 | int32 start_y = 0; |
312 | int32 end_y = preview_bitmap->Bounds().bottom; |
313 | |
314 | union { |
315 | uint8 bytes[4]; |
316 | uint32 word; |
317 | } background; |
318 | |
319 | background.bytes[0] = 0xFF; |
320 | background.bytes[1] = 0xFF; |
321 | background.bytes[2] = 0xFF; |
322 | background.bytes[3] = 0x00; |
323 | |
324 | |
325 | if (last_calculated_resolution > 0) { |
326 | int32 real_x; |
327 | int32 real_y; |
328 | int32 distance; |
329 | int32 center_distance_from_edges = settings.twirl_radius; |
330 | int32 cx = settings.center.x; |
331 | int32 cy = settings.center.y; |
332 | float k = settings.twirl_amount/(float)MAX_TWIRL_AMOUNT720; |
333 | int32 dx; |
334 | int32 dy; |
335 | float two_180_per_pi = 360.0/PI3.14159265358979323846; |
336 | int32 top = 0; |
337 | int32 bottom = preview_bitmap->Bounds().bottom; |
338 | float multiplier = 1.0 / (float)center_distance_from_edges*k*2.0*PI3.14159265358979323846; |
339 | |
340 | if (selection->IsEmpty() == TRUE1) { |
341 | for (int32 y=start_y;y<=end_y;y += last_calculated_resolution) { |
342 | for (int32 x=0;x<source_bpr;x += last_calculated_resolution) { |
343 | real_x = x-cx; |
344 | real_y = y-cy; |
345 | #ifdef __POWERPC__ |
346 | distance = 1.0/reciprocal_of_square_root(real_x*real_x + real_y*real_y); |
347 | #else |
348 | // distance = fsqrt(real_x*real_x + real_y*real_y); |
349 | distance = sqrt(real_x*real_x + real_y*real_y); |
350 | #endif |
351 | if (distance <= center_distance_from_edges) { |
352 | float omega = (center_distance_from_edges-distance)*multiplier; |
353 | omega = (omega<0?2*PI3.14159265358979323846+omega:omega); |
354 | int32 cos_angle = (int32)(omega*two_180_per_pi)%720; |
355 | int32 sin_angle = (int32)(omega*two_180_per_pi)%720; |
356 | dx = (cos_table[cos_angle]*real_x-sin_table[sin_angle]*real_y)-real_x; |
357 | dy = (sin_table[sin_angle]*real_x+cos_table[cos_angle]*real_y)-real_y; |
358 | |
359 | } |
360 | else { |
361 | dx = 0; |
362 | dy = 0; |
363 | } |
364 | |
365 | // This if is quite slow. |
366 | if (((y+dy) <= bottom) && ((y+dy)>=top) && ((x+dx) >= 0) && ((x+dx)<target_bpr)) { |
367 | *(target_bits + (int32)x + (int32)y*target_bpr) = *(source_bits + (int32)(x+dx) + (int32)(y+dy)*source_bpr); |
368 | } |
369 | else { |
370 | *(target_bits + (int32)x + (int32)y*target_bpr) = background.word; |
371 | } |
372 | } |
373 | } |
374 | } |
375 | else { |
376 | for (int32 y=start_y;y<=end_y;y += last_calculated_resolution) { |
377 | for (int32 x=0;x<source_bpr;x += last_calculated_resolution) { |
378 | real_x = x-cx; |
379 | real_y = y-cy; |
380 | #ifdef __POWERPC__ |
381 | distance = 1.0/reciprocal_of_square_root(real_x*real_x + real_y*real_y); |
382 | #else |
383 | // distance = fsqrt(real_x*real_x + real_y*real_y); |
384 | distance = sqrt(real_x*real_x + real_y*real_y); |
385 | #endif |
386 | if ((distance <= center_distance_from_edges) && (selection->ContainsPoint(x,y))) { |
387 | float omega = (center_distance_from_edges-distance)*multiplier; |
388 | omega = (omega<0?2*PI3.14159265358979323846+omega:omega); |
389 | int32 cos_angle = (int32)(omega*two_180_per_pi)%720; |
390 | int32 sin_angle = (int32)(omega*two_180_per_pi)%720; |
391 | dx = (cos_table[cos_angle]*real_x-sin_table[sin_angle]*real_y)-real_x; |
392 | dy = (sin_table[sin_angle]*real_x+cos_table[cos_angle]*real_y)-real_y; |
393 | |
394 | } |
395 | else { |
396 | dx = 0; |
397 | dy = 0; |
398 | } |
399 | |
400 | // This if is quite slow. |
401 | if (((y+dy) <= bottom) && ((y+dy)>=top) && ((x+dx) >= 0) && ((x+dx)<target_bpr)) { |
402 | *(target_bits + (int32)x + (int32)y*target_bpr) = *(source_bits + (int32)(x+dx) + (int32)(y+dy)*source_bpr); |
403 | } |
404 | else { |
405 | *(target_bits + (int32)x + (int32)y*target_bpr) = background.word; |
406 | } |
407 | } |
408 | } |
409 | } |
410 | } |
411 | updated_region->Set(preview_bitmap->Bounds()); |
412 | return last_calculated_resolution; |
413 | } |
414 | |
415 | void TwirlManipulator::SetPreviewBitmap(BBitmap *bm) |
416 | { |
417 | if (preview_bitmap != bm) { |
418 | delete copy_of_the_preview_bitmap; |
419 | if (bm != NULL__null) { |
420 | if (preview_bitmap == NULL__null) { |
421 | settings.center.x = bm->Bounds().right/2; |
422 | settings.center.y = bm->Bounds().bottom/2; |
423 | } |
424 | preview_bitmap = bm; |
425 | copy_of_the_preview_bitmap = DuplicateBitmap(bm,0); |
426 | } |
427 | else { |
428 | preview_bitmap = NULL__null; |
429 | copy_of_the_preview_bitmap = NULL__null; |
430 | } |
431 | if (config_view != NULL__null) { |
432 | config_view->ChangeSettings(&settings); |
433 | } |
434 | } |
435 | |
436 | if (preview_bitmap != NULL__null) { |
437 | double speed = GetSystemClockSpeed() / 10000; |
438 | |
439 | BRect bounds = preview_bitmap->Bounds(); |
440 | float num_pixels = (bounds.Width()+1) * (bounds.Height() + 1); |
441 | lowest_available_quality = 1; |
442 | while ((2*num_pixels/lowest_available_quality/lowest_available_quality) > speed) |
443 | lowest_available_quality *= 2; |
444 | |
445 | lowest_available_quality = min_c(lowest_available_quality,16)((lowest_available_quality)>(16)?(16):(lowest_available_quality )); |
446 | highest_available_quality = max_c(lowest_available_quality/2,1)((lowest_available_quality/2)>(1)?(lowest_available_quality /2):(1)); |
447 | } |
448 | else { |
449 | lowest_available_quality = 1; |
450 | highest_available_quality = 1; |
451 | } |
452 | last_calculated_resolution = lowest_available_quality; |
453 | } |
454 | |
455 | |
456 | void TwirlManipulator::Reset(Selection*) |
457 | { |
458 | if (preview_bitmap != NULL__null) { |
459 | uint32 *source_bits = (uint32*)copy_of_the_preview_bitmap->Bits(); |
460 | uint32 *target_bits = (uint32*)preview_bitmap->Bits(); |
461 | |
462 | int32 bits_length = preview_bitmap->BitsLength()/4; |
463 | |
464 | for (int32 i=0;i<bits_length;i++) |
465 | *target_bits++ = *source_bits++; |
466 | } |
467 | } |
468 | |
469 | |
470 | BView* TwirlManipulator::MakeConfigurationView(const BMessenger& target) |
471 | { |
472 | config_view = new TwirlManipulatorView(BRect(0,0,0,0),this,target); |
473 | config_view->ChangeSettings(&settings); |
474 | |
475 | return config_view; |
476 | } |
477 | |
478 | const char* TwirlManipulator::ReturnHelpString() |
479 | { |
480 | return B_TRANSLATE("Click to set the twirl center. Use sliders to adjust twirl.")BLocaleRoster::Default()->GetCatalog()->GetString(("Click to set the twirl center. Use sliders to adjust twirl." ), "AddOns_Twirl"); |
481 | } |
482 | |
483 | const char* TwirlManipulator::ReturnName() |
484 | { |
485 | return B_TRANSLATE("Twirl")BLocaleRoster::Default()->GetCatalog()->GetString(("Twirl" ), "AddOns_Twirl"); |
486 | } |
487 | |
488 | ManipulatorSettings* TwirlManipulator::ReturnSettings() |
489 | { |
490 | return new TwirlManipulatorSettings(settings); |
491 | } |
492 | |
493 | void TwirlManipulator::ChangeSettings(ManipulatorSettings *s) |
494 | { |
495 | TwirlManipulatorSettings *new_settings = dynamic_cast<TwirlManipulatorSettings*>(s); |
496 | |
497 | if (new_settings != NULL__null) { |
498 | previous_settings = settings; |
499 | settings = *new_settings; |
500 | } |
501 | } |
502 | |
503 | |
504 | TwirlManipulatorView::TwirlManipulatorView(BRect rect,TwirlManipulator *manip, |
505 | const BMessenger& t) |
506 | : WindowGUIManipulatorView() |
507 | { |
508 | manipulator = manip; |
509 | target = new BMessenger(t); |
510 | preview_started = FALSE0; |
511 | |
512 | twirl_radius_slider = new BSlider("twirl_radius_slider", |
513 | B_TRANSLATE("Size:")BLocaleRoster::Default()->GetCatalog()->GetString(("Size:" ), "AddOns_Twirl"), new BMessage(TWIRL_RADIUS_CHANGED'Tlec'), 10, 1000, |
514 | B_HORIZONTAL, B_TRIANGLE_THUMB); |
515 | twirl_radius_slider->SetLimitLabels(B_TRANSLATE("Small")BLocaleRoster::Default()->GetCatalog()->GetString(("Small" ), "AddOns_Twirl"),B_TRANSLATE("Big")BLocaleRoster::Default()->GetCatalog()->GetString(("Big" ), "AddOns_Twirl")); |
516 | twirl_radius_slider->SetModificationMessage(new BMessage(TWIRL_RADIUS_ADJUSTING_STARTED'Tras')); |
517 | twirl_radius_slider->SetHashMarks(B_HASH_MARKS_BOTTOM); |
518 | twirl_radius_slider->SetHashMarkCount(11); |
519 | |
520 | twirl_amount_slider = new BSlider("twirl_amount_slider", |
521 | B_TRANSLATE("Direction and amount:")BLocaleRoster::Default()->GetCatalog()->GetString(("Direction and amount:" ), "AddOns_Twirl"), new BMessage(TWIRL_AMOUNT_CHANGED'Tamc'), MIN_TWIRL_AMOUNT-720, |
522 | MAX_TWIRL_AMOUNT720, B_HORIZONTAL, B_TRIANGLE_THUMB); |
523 | twirl_amount_slider->SetLimitLabels(B_TRANSLATE("Left")BLocaleRoster::Default()->GetCatalog()->GetString(("Left" ), "AddOns_Twirl"), B_TRANSLATE("Right")BLocaleRoster::Default()->GetCatalog()->GetString(("Right" ), "AddOns_Twirl")); |
524 | twirl_amount_slider->SetModificationMessage(new BMessage(TWIRL_AMOUNT_ADJUSTING_STARTED'Taas')); |
525 | twirl_amount_slider->SetHashMarks(B_HASH_MARKS_BOTTOM); |
526 | twirl_amount_slider->SetHashMarkCount(11); |
527 | |
528 | BLayoutBuilder::Group<>(this, B_VERTICAL, B_USE_ITEM_SPACING) |
529 | .Add(twirl_radius_slider) |
530 | .Add(twirl_amount_slider) |
531 | .SetInsets(B_USE_SMALL_INSETS) |
532 | .End(); |
533 | } |
534 | |
535 | |
536 | TwirlManipulatorView::~TwirlManipulatorView() |
537 | { |
538 | delete target; |
539 | } |
540 | |
541 | void TwirlManipulatorView::AttachedToWindow() |
542 | { |
543 | WindowGUIManipulatorView::AttachedToWindow(); |
544 | |
545 | twirl_radius_slider->SetTarget(BMessenger(this)); |
546 | twirl_amount_slider->SetTarget(BMessenger(this)); |
547 | } |
548 | |
549 | |
550 | void TwirlManipulatorView::AllAttached() |
551 | { |
552 | twirl_radius_slider->SetValue(settings.twirl_radius); |
553 | twirl_amount_slider->SetValue(settings.twirl_amount); |
554 | } |
555 | |
556 | |
557 | void TwirlManipulatorView::MessageReceived(BMessage *message) |
558 | { |
559 | switch (message->what) { |
560 | case TWIRL_RADIUS_ADJUSTING_STARTED'Tras': |
561 | if (preview_started == FALSE0) { |
562 | preview_started = TRUE1; |
563 | target->SendMessage(HS_MANIPULATOR_ADJUSTING_STARTED'Mast'); |
564 | } |
565 | settings.twirl_radius = twirl_radius_slider->Value(); |
566 | manipulator->ChangeSettings(&settings); |
567 | break; |
568 | |
569 | case TWIRL_RADIUS_CHANGED'Tlec': |
570 | preview_started = FALSE0; |
571 | settings.twirl_radius = twirl_radius_slider->Value(); |
572 | manipulator->ChangeSettings(&settings); |
573 | target->SendMessage(HS_MANIPULATOR_ADJUSTING_FINISHED'Mafi'); |
574 | break; |
575 | |
576 | case TWIRL_AMOUNT_ADJUSTING_STARTED'Taas': |
577 | if (preview_started == FALSE0) { |
578 | preview_started = TRUE1; |
579 | target->SendMessage(HS_MANIPULATOR_ADJUSTING_STARTED'Mast'); |
580 | } |
581 | settings.twirl_amount = twirl_amount_slider->Value(); |
582 | manipulator->ChangeSettings(&settings); |
583 | break; |
584 | |
585 | case TWIRL_AMOUNT_CHANGED'Tamc': |
586 | preview_started = FALSE0; |
587 | settings.twirl_amount = twirl_amount_slider->Value(); |
588 | manipulator->ChangeSettings(&settings); |
589 | target->SendMessage(HS_MANIPULATOR_ADJUSTING_FINISHED'Mafi'); |
590 | break; |
591 | |
592 | default: |
593 | WindowGUIManipulatorView::MessageReceived(message); |
594 | break; |
595 | } |
596 | } |
597 | |
598 | |
599 | void TwirlManipulatorView::ChangeSettings(TwirlManipulatorSettings *s) |
600 | { |
601 | settings = *s; |
602 | BWindow *window = Window(); |
603 | |
604 | if (window != NULL__null) { |
605 | window->Lock(); |
606 | |
607 | twirl_radius_slider->SetValue(settings.twirl_radius); |
608 | twirl_amount_slider->SetValue(settings.twirl_amount); |
609 | |
610 | window->Unlock(); |
611 | } |
612 | } |