fix compile against newer giflib
[rofl0r-obeditor.git] / src / entity__MyAnimationZone.cpp
blob4b19cb27ba76f112122bad77d156439c5c137a0d
1 /*
2 * MyAnimationZone.cpp
4 * Created on: 7 nov. 2008
5 * Author: pat
6 */
8 #include "wx/wxprec.h"
9 #ifndef WX_PRECOMP
10 #include "wx/wx.h"
11 #endif
13 #include <wx/sound.h>
14 #include <wx/dcbuffer.h>
15 #include <wx/tooltip.h>
17 #include "images__MyPalette.h"
18 #include "entity__enums.h"
19 #include "entity__globals.h"
20 #include "entity__MyAnimationZone.h"
22 extern void PlaySound(char *file);
25 #define PI 3.14159265
26 #define JUMP_HALF_TIME 20
27 #define JUMP_ANIM_STEP 4
29 using namespace std;
31 //***************************************
32 //***************************************
33 //***************************************
34 //***************************************
36 wxColour ob_pink(255,0,255);
37 wxColour MyAnimationZone::orig_bg(0,0,0);
39 struct jump_step
41 int mv_h;
42 int delay;
45 struct jump_stair
47 float mv_x;
48 float mv_z;
49 int curr_step;
50 int nb_step;
51 jump_step *steps;
55 void clear_jump_stairs( jump_stair*& fr_jump_stairs, int& nb_stair )
57 if( fr_jump_stairs != NULL )
58 for( int i =0; i < nb_stair; i++ )
60 if( fr_jump_stairs[i].nb_step > 0 )
61 delete[] fr_jump_stairs[i].steps;
64 if( fr_jump_stairs != NULL )
65 delete[] fr_jump_stairs;
66 fr_jump_stairs = NULL;
67 nb_stair = 0;
71 //***************************************
72 //***************************************
73 //***************************************
75 MyAnimationZone::MyAnimationZone(wxWindow *parent)
76 : wxControl(parent, wxID_ANY
77 , wxDefaultPosition, wxDefaultSize
78 , wxVSCROLL| wxHSCROLL
81 SetBackgroundStyle( wxBG_STYLE_CUSTOM );
83 theBitmap = NULL;
84 m_flag = 0;
86 SetToolTip( wxString() );
87 theTip = GetToolTip();
88 theTip->SetDelay( 200 );
89 theTip->Enable( false );
91 fr_decal_Xs = NULL;
92 fr_decal_Ys = NULL;
93 fr_As = NULL;
94 fr_Zdecal = NULL;
95 fr_total_decal_Xs = NULL;
96 fr_total_decal_Ys = NULL;
97 fr_offset_Xs = NULL;
98 fr_offset_Ys = NULL;
99 fr_DM_decal_Xs = NULL;
100 fr_DM_decal_Ys = NULL;
101 fr_rotate_offset_Xs = NULL;
102 fr_rotate_offset_Ys = NULL;
103 original_img_w = NULL;
104 original_img_h = NULL;
105 current_img_w = NULL;
106 current_img_h = NULL;
107 fr_rotate_imgw = NULL;
108 fr_rotate_imgh = NULL;
109 fr_delays = NULL;
110 fr_jumph = NULL;
111 fr_jumpx = NULL;
112 fr_jumpz = NULL;
113 fr_jump_timer = NULL;
114 fr_jump_stairs = NULL;
115 nb_stair = 0;
117 // Bunch of var for animate the jump
118 is_in_jump = false;
119 jump_decal_x = jump_decal_z = jump_decal_alt = 0;
120 jump_alt_step = 0;
121 jump_last_delay = jump_time_counter = 0;
122 draw_jump_step = false;
124 TO_offx = 0;
125 TO_offy = 0;
126 TO_x = 0;
127 TO_a = 0;
128 TO_w = 0;
129 TO_h = 0;
131 mouse_draw = DRAW_NOTHING;
132 b_mouseD = false;
133 b_rightmouseD = false;
134 Clear();
135 dc = NULL;
137 SetBackgroundStyle( wxBG_STYLE_CUSTOM );
140 MyAnimationZone::~MyAnimationZone()
142 Clear();
145 //******************************************************
147 int MyAnimationZone::H()const
149 int _w, _h;
150 GetSize(&_w,&_h);
151 return _h;
154 int MyAnimationZone::W()const
156 int _w, _h;
157 GetSize(&_w,&_h);
158 return _w;
161 int MyAnimationZone::X()const
163 int mx,my;
164 GetPosition(&mx,&my);
165 return mx;
168 int MyAnimationZone::Y()const
170 int mx,my;
171 GetPosition(&mx,&my);
172 return my;
177 //******************************************************
179 void MyAnimationZone::SetSize(int _x, int _y, int _width, int _height, int _sizeFlags )
181 wxControl::SetSize(_x,_y,_width, _height,_sizeFlags);
184 //-------------------------------------------------------------------------------
185 void
186 MyAnimationZone::pGetClientSize( int* w,int* h)
188 GetClientSize( w,h);
189 #ifdef _WXGTK__
190 if( GetScrollRange(wxHORIZONTAL) > 0 )
191 h -= wxSystemSettings::GetMetric( wxSYS_HSCROLL_Y );
192 if( GetScrollRange(wxVERTICAL) > 0 )
193 w -= wxSystemSettings::GetMetric( wxSYS_HSCROLL_X );
194 #endif
197 //-------------------------------------------------------------------------------
198 void
199 MyAnimationZone::Zoom(float _factor, bool b_exact_factor, bool b_recalc_size )
201 if( _factor <= 0 || m_flag & M_ZOOMING )
202 return;
203 m_flag |= M_ZOOMING;
205 // Vars...
206 int w,h;
207 pGetClientSize( &w,&h);
209 // Get middle point in ob coords
210 int sp_x = (w/2+GetScrollPos(wxHORIZONTAL) ) / zoom_factor;
211 int sp_y = (h/2+GetScrollPos(wxVERTICAL ) ) / zoom_factor;
213 // Set the new zoom factor
214 if( b_exact_factor == true )
215 zoom_factor = _factor;
216 else
217 zoom_factor = zoom_factor*_factor;
219 // If so, recalc size
220 if( b_recalc_size == true );
221 ReCalcAnimSize();
223 // Recompute scrollbars pos
224 sp_x = sp_x*zoom_factor - w/2;
225 sp_y = sp_y*zoom_factor - h/2;
227 if( total_W*zoom_factor < w )
228 SetScrollbar( wxHORIZONTAL, 0,0,0);
229 else
230 SetScrollbar( wxHORIZONTAL, sp_x,w,total_W*zoom_factor);
232 if( total_H*zoom_factor < h )
233 SetScrollbar( wxVERTICAL, 0,0,0);
234 else
235 SetScrollbar( wxVERTICAL, sp_y,h,total_H*zoom_factor);
238 // Must rethink the stuff if scroll bar appears
239 int new_w,new_h;
240 pGetClientSize( &new_w,&new_h);
241 if( new_w != w || new_h != h )
243 m_flag &= ~M_ZOOMING;
244 Zoom( zoom_factor, true, false );
245 return;
248 // Repaint...
249 RePaint();
250 m_flag &= ~M_ZOOMING;
253 void MyAnimationZone::ResetZoom()
255 Zoom( 1, true );
259 //******************************************************
261 extern bool Is_AAirAnim();
263 void MyAnimationZone::_Recalculate_JumpStuffs()
265 // ****************************************************************************************
266 // Init some jump variables
268 ob_object *jumpframe_prop = curr_anim->GetSubObject( wxT("jumpframe") );
269 int jump_frame = -1;
270 int jump_speedh = 0;
271 int jump_speedx = 0;
272 int jump_speedz = 0;
273 jump_alt_step = 0;
275 if( jumpframe_prop != NULL && jumpframe_prop->GetToken(0) != wxString() )
277 jump_frame = StrToInt( jumpframe_prop->GetToken(0) );
278 jump_speedh = StrToInt( jumpframe_prop->GetToken(1) );
279 jump_alt_step = jump_speedh;
280 jump_speedx = StrToInt( jumpframe_prop->GetToken(2) );
281 jump_speedz = StrToInt( jumpframe_prop->GetToken(3) );
283 // Provide some default values for fall frames
284 else if( Is_AAirAnim() )
286 jump_frame = 0;
287 jump_speedh = 3;
288 if( curr_anim->GetToken(0).Left(4).Upper() == wxT("FALL") )
289 jump_speedx = -2;
290 else if( curr_anim->GetToken(0).Left(4).Upper() == wxT("JUMP") )
291 jump_speedx = 0;
294 ob_object *dropframe_prop = curr_anim->GetSubObject( wxT("dropframe") );
295 int drop_frame = -1;
296 if( dropframe_prop != NULL && dropframe_prop->GetToken(0) != wxString() )
297 drop_frame = StrToInt( dropframe_prop->GetToken(0) );
299 ob_object *landframe_prop = curr_anim->GetSubObject( wxT("landframe") );
300 int land_frame = -1;
301 if( landframe_prop != NULL && landframe_prop->GetToken(0) != wxString() )
302 land_frame = StrToInt( landframe_prop->GetToken(0) );
305 bool in_jump = false, in_drop = false, in_land = false;
306 int know_delay = 0;
307 int curr_jumph = 0;;
308 int jump_duration = 0;
309 int curr_alt = 0;
311 #define DGET_DELAY( _frame ) \
312 (_frame->delay!=NO_CLONED_VAL?_frame->delay:1)
314 //******************************************************************
315 // Calculate delays and a,x,z decals
316 for( int i = 0; i < curr_frames_count; i++ )
318 if( curr_frames[i]->jumpState > 0 && ! in_jump )
319 in_jump = true;
320 if( curr_frames[i]->dropState > 0 && ! in_drop )
321 in_drop = true;
322 if( curr_frames[i]->landState > 0 && ! in_land )
323 in_land = true;
325 know_delay = DGET_DELAY(curr_frames[i]);
326 if( know_delay <= 0 )
327 know_delay = 1;
329 curr_frames[i]->end_jump = false;
331 bool b_flipped = curr_frames[i]->flipState > 0;
333 //***********************************
334 // Special Case the drop frame
335 if( curr_frames[i]->dropState == 2 && curr_frames[i]->jumpState > 0 )
337 if( i == 0 )
339 wxMessageBox( wxT("Drop frame at position ZERO !!!"), wxT("ProPlem"), wxOK | wxICON_INFORMATION, this );
340 fr_delays[i] = know_delay;
341 fr_jumph[i] = 0;
342 fr_jumpx[i] = 0;
343 fr_jumpz[i] = 0;
344 continue;
347 // Must force the previous frame delay to have this frame to the apex
348 if( jump_duration < JUMP_HALF_TIME )
350 // simple case : juste force the previous delay so it be at the apex
351 fr_delays[i-1] = ( JUMP_HALF_TIME - jump_duration + fr_delays[i-1] );
352 fr_jumph[i] = fr_delays[i-1] * jump_speedh;
353 fr_jumpx[i] = fr_delays[i-1] * jump_speedx;
354 fr_jumpz[i] = fr_delays[i-1] * jump_speedz;
357 // Complicated case : the apex is passed
358 else
360 int over_time = jump_duration - JUMP_HALF_TIME;
362 int j;
363 for( j = i-1; j >= 0; j--)
365 over_time -= fr_delays[j];
367 // We got the last frame before the apex
368 if( over_time < 0 )
370 fr_delays[j] = - over_time;
371 break;
374 fr_jumph[i] = fr_delays[j] * jump_speedh;
375 fr_jumpx[i] = fr_delays[j] * jump_speedx;
376 fr_jumpz[i] = fr_delays[j] * jump_speedz;
378 // Set a delay of 0 to all the frame between
379 for( j = j + 1; j < i; j++ )
381 fr_delays[j] = 0;
382 fr_jumph[j] = 0;
383 fr_jumpx[j] = 0;
384 fr_jumpz[j] = 0;
388 // Set the drop frame data
389 fr_delays[i] = know_delay;
390 curr_jumph = jump_speedh * JUMP_HALF_TIME;
391 jump_duration = JUMP_HALF_TIME;
392 in_land = false;
395 //***********************************
396 // Special Case the land frame
397 else if( curr_frames[i]->landState == 2 && curr_frames[i]->jumpState > 0 )
399 // Must force the delay to have this frame (and all remaining previous) to the ground
401 //Simple case : just add some time to the land frame
402 if( jump_duration < 2 * JUMP_HALF_TIME )
404 if( i == 0 )
406 wxMessageBox( wxT("Land frame at position ZERO !!!"), wxT("ProPlem"), wxOK | wxICON_INFORMATION, this );
407 fr_delays[i] = know_delay;
408 fr_jumph[i] = 0;
409 fr_jumpx[i] = 0;
410 fr_jumpz[i] = 0;
411 continue;
413 // simple case : juste force the previous delay
414 fr_delays[i-1] = ( 2 * JUMP_HALF_TIME - jump_duration + fr_delays[i-1] );
416 // Set the drop frame data
417 if( fr_delays[i-1] <= JUMP_HALF_TIME )
418 fr_jumph[i] = - fr_delays[i-1] * jump_speedh;
419 else
421 int last_up_delay = fr_delays[i-1] - JUMP_HALF_TIME;
422 fr_jumph[i] = - (fr_delays[i-1] -2 * last_up_delay ) * jump_speedh;
424 fr_delays[i] = know_delay;
425 fr_jumpx[i] = fr_delays[i-1] * jump_speedx;
426 fr_jumpz[i] = fr_delays[i-1] * jump_speedz;
429 // Complicated case : the ground is passed
430 else
432 int over_time = jump_duration - 2 * JUMP_HALF_TIME;
434 int j;
435 for( j = i-1; j >= 0; j--)
437 over_time -= fr_delays[j];
439 // We got the last frame before the ground
440 if( over_time < 0 )
442 fr_delays[j] = - over_time;
443 break;
447 // Set the drop frame data
448 if( fr_delays[j] <= JUMP_HALF_TIME )
449 fr_jumph[i] = - fr_delays[j] * jump_speedh;
450 else
452 int last_up_delay = fr_delays[j] - JUMP_HALF_TIME;
453 fr_jumph[i] = - (fr_delays[j] -2 * last_up_delay ) * jump_speedh;
455 fr_delays[i] = know_delay;
456 fr_jumpx[i] = fr_delays[j] * jump_speedx;
457 fr_jumpz[i] = fr_delays[j] * jump_speedz;
459 // Set a delay of 0 to all the frame between
460 for( j = j + 1; j < i; j++ )
462 fr_delays[j] = 0;
463 fr_jumph[j] = 0;
464 fr_jumpx[j] = 0;
465 fr_jumpz[j] = 0;
469 curr_jumph = 0; //jump_speedh * JUMP_HALF_TIME;
470 jump_duration = 2 * JUMP_HALF_TIME;
471 curr_frames[i]->end_jump = true;
472 in_land = true;
475 // at the ground -> no jump influence
476 else if( in_land || ! in_jump )
478 fr_delays[i] = know_delay;
479 fr_jumph[i] = 0;
480 fr_jumpx[i] = 0;
481 fr_jumpz[i] = 0;
482 if( curr_frames[i]->jumpState != 2 )
483 curr_frames[i]->end_jump = true;
486 // go up case
487 else if( in_jump && ! in_drop )
489 // Special case : apex passed
490 if( jump_duration >= JUMP_HALF_TIME && jump_duration < 2 * JUMP_HALF_TIME )
492 fr_delays[i] = know_delay;
493 fr_jumpx[i] = 0;
494 fr_jumpz[i] = 0;
496 fr_jumph[i] = (JUMP_HALF_TIME - ( jump_duration - JUMP_HALF_TIME )) * jump_speedh;
497 if( i > 0 && curr_frames[i-1]->jumpState > 0)
499 int last_up_delay = fr_delays[i-1] - (jump_duration - JUMP_HALF_TIME);
500 fr_jumph[i] = - (fr_delays[i-1] -2 * last_up_delay ) * jump_speedh;
501 fr_jumpx[i] = fr_delays[i-1] * jump_speedx;
502 fr_jumpz[i] = fr_delays[i-1] * jump_speedz;
504 in_drop = true;
507 // Special case : apex passed and directly to ground
508 else if( jump_duration >= 2 * JUMP_HALF_TIME )
510 fr_delays[i] = know_delay;
511 fr_jumpx[i] = 0;
512 fr_jumpz[i] = 0;
513 fr_jumph[i] = 0;
515 // Gotta cut some delay and some alt to stay to ground
516 if( i > 0 && curr_frames[i-1]->jumpState > 0)
518 int over_time = jump_duration - 2 * JUMP_HALF_TIME;
519 fr_delays[i-1] -= over_time;
520 jump_duration -= over_time;
521 fr_jumph[i] = - curr_alt;
522 fr_jumpx[i] = fr_delays[i-1] * jump_speedx;
523 fr_jumpz[i] = fr_delays[i-1] * jump_speedz;
525 in_land = true;
526 curr_frames[i]->end_jump = true;
529 // Just moving up
530 else
532 fr_delays[i] = know_delay;
533 fr_jumpx[i] = 0;
534 fr_jumpz[i] = 0;
535 fr_jumph[i] = 0;
537 if( i > 0 && curr_frames[i-1]->jumpState > 0 )
539 fr_jumph[i] = fr_delays[i-1] * jump_speedh;
540 fr_jumpx[i] = fr_delays[i-1] * jump_speedx;
541 fr_jumpz[i] = fr_delays[i-1] * jump_speedz;
546 // go down case
547 else if( in_jump && in_drop )
549 // Special case : ground passed
550 if( jump_duration >= 2 * JUMP_HALF_TIME )
552 fr_delays[i] = know_delay;
553 fr_jumpx[i] = 0;
554 fr_jumpz[i] = 0;
555 fr_jumph[i] = 0;
557 // Gotta cut some alt
558 if( i > 0 && curr_frames[i-1]->jumpState > 0)
560 int over_time = jump_duration - 2 * JUMP_HALF_TIME;
561 jump_duration -= over_time;
562 fr_delays[i-1] -= over_time;
563 fr_jumph[i] = - fr_delays[i-1] * jump_speedh;
564 fr_jumpx[i] = fr_delays[i-1] * jump_speedx;
565 fr_jumpz[i] = fr_delays[i-1] * jump_speedz;
567 in_land = true;
568 curr_frames[i]->end_jump = true;
571 // just going down
572 else
574 fr_delays[i] = know_delay;
575 fr_jumpx[i] = 0;
576 fr_jumpz[i] = 0;
577 fr_jumph[i] = 0;
578 if( i > 0 && curr_frames[i-1]->jumpState > 0)
580 fr_jumph[i] = - fr_delays[i-1] * jump_speedh;
581 fr_jumpx[i] = fr_delays[i-1] * jump_speedx;
582 fr_jumpz[i] = fr_delays[i-1] * jump_speedz;
587 if( b_flipped )
588 fr_jumpx[i] = - fr_jumpx[i];
590 if( curr_frames[i]->jumpState > 0 )
592 jump_duration += fr_delays[i];
593 curr_alt += fr_jumph[i];
598 // Now we can calculate each delay from the start of the jump
599 fr_jump_timer[0] = 0;
600 for( int _i = 1; _i < curr_frames_count; _i++ )
602 if( curr_frames[_i]->jumpState == 2 )
603 fr_jump_timer[_i] = 0;
604 else if( curr_frames[_i]->jumpState > 0 )
605 fr_jump_timer[_i] = fr_jump_timer[_i-1] + fr_delays[_i-1];
606 else
607 fr_jump_timer[_i] = 0;
611 // Now we can calculate each jump step
612 for( int i = 0; i < curr_frames_count; i++ )
614 fr_jump_stairs[i].nb_step = 0;
615 fr_jump_stairs[i].curr_step = 0;
617 if( curr_frames[i]->end_jump )
618 continue;
620 // Number of jump need by this frame
621 int nb_step = floor( ((float) fr_delays[i] - (float) JUMP_ANIM_STEP )/ (float) JUMP_ANIM_STEP );
622 fr_jump_stairs[i].nb_step = nb_step;
623 if( nb_step <= 0 )
625 fr_jump_stairs[i].nb_step = 0;
626 continue;
629 fr_jump_stairs[i].steps = new jump_step[nb_step];
631 // Set the delays of each steps
632 for( int j = 0; j < nb_step - 1; j++)
633 fr_jump_stairs[i].steps[j].delay = JUMP_ANIM_STEP;
634 // And the last step
635 fr_jump_stairs[i].steps[nb_step - 1].delay = fr_delays[i] - JUMP_ANIM_STEP * nb_step;
637 // Setting the move_h of each step
638 int time_elapsed = fr_jump_timer[i] + JUMP_ANIM_STEP;
639 for( int j = 0; j < nb_step; j++)
641 // case, apex passed
642 if( (time_elapsed - JUMP_ANIM_STEP) <= JUMP_HALF_TIME
643 && time_elapsed > JUMP_HALF_TIME )
645 int _moveh = JUMP_ANIM_STEP * jump_speedh;
646 _moveh -= (time_elapsed - JUMP_HALF_TIME ) * jump_speedh * 2;
647 fr_jump_stairs[i].steps[j].mv_h = _moveh;
650 // Going up
651 else if( time_elapsed < JUMP_HALF_TIME )
652 fr_jump_stairs[i].steps[j].mv_h = JUMP_ANIM_STEP * jump_speedh;
654 // on the ground
655 else if( time_elapsed >= 2 * JUMP_HALF_TIME )
657 fr_jump_stairs[i].steps[j].mv_h = 0;
658 // Stop calculation, and stop the frame step to this one
659 fr_jump_stairs[i].nb_step = j+1;
660 fr_jump_stairs[i].steps[j].delay = fr_jump_timer[i] + fr_delays[i] - time_elapsed;
661 j = nb_step;
664 // Ground reached
665 else if( (time_elapsed + JUMP_ANIM_STEP) >= 2 * JUMP_HALF_TIME )
667 fr_jump_stairs[i].steps[j].mv_h = - (2*JUMP_HALF_TIME - time_elapsed ) * jump_speedh;
668 // Stop calculation, and stop the frame step to this one
669 fr_jump_stairs[i].nb_step = j+1;
670 fr_jump_stairs[i].steps[j].delay = fr_jump_timer[i] + fr_delays[i] - time_elapsed;
671 j = nb_step;
674 // Going down
675 else
676 fr_jump_stairs[i].steps[j].mv_h = - JUMP_ANIM_STEP * jump_speedh;
678 time_elapsed += JUMP_ANIM_STEP;
684 //******************************************************
686 void getRotationNewOffset( int off_x, int off_y, int _w, int _h, int angle,
687 float& new_offx, float& new_offy,float& new_w, float& new_h );
689 void MyAnimationZone::ReCalcAnimSize()
691 // Reinit size datas
692 if( fr_decal_Xs != NULL )
693 delete[] fr_decal_Xs;
694 fr_decal_Xs = NULL;
695 if( fr_decal_Ys != NULL )
696 delete[] fr_decal_Ys;
697 fr_decal_Ys = NULL;
698 if( fr_As != NULL )
699 delete[] fr_As;
700 fr_As = NULL;
701 if( fr_Zdecal != NULL )
702 delete[] fr_Zdecal;
703 fr_Zdecal = NULL;
705 if( fr_total_decal_Xs != NULL )
706 delete[] fr_total_decal_Xs;
707 fr_total_decal_Xs = NULL;
708 if( fr_total_decal_Ys != NULL )
709 delete[] fr_total_decal_Ys;
710 fr_total_decal_Ys = NULL;
712 if( fr_offset_Xs != NULL )
713 delete[] fr_offset_Xs;
714 fr_offset_Xs = NULL;
715 if( fr_offset_Ys != NULL )
716 delete[] fr_offset_Ys;
717 fr_offset_Ys = NULL;
718 if( fr_DM_decal_Xs != NULL )
719 delete[] fr_DM_decal_Xs;
720 fr_DM_decal_Xs = NULL;
721 if( fr_DM_decal_Ys != NULL )
722 delete[] fr_DM_decal_Ys;
723 fr_DM_decal_Ys = NULL;
724 if( fr_rotate_offset_Xs != NULL )
725 delete[] fr_rotate_offset_Xs;
726 fr_rotate_offset_Xs = NULL;
727 if( fr_rotate_offset_Ys != NULL )
728 delete[] fr_rotate_offset_Ys;
729 fr_rotate_offset_Ys = NULL;
730 if( original_img_w != NULL )
731 delete[] original_img_w;
732 original_img_w = NULL;
733 if( original_img_h != NULL )
734 delete[] original_img_h;
735 original_img_h = NULL;
736 if( current_img_w != NULL )
737 delete[] current_img_w;
738 current_img_w = NULL;
739 if( current_img_h != NULL )
740 delete[] current_img_h;
741 current_img_h = NULL;
742 if( fr_rotate_imgw != NULL )
743 delete[] fr_rotate_imgw;
744 fr_rotate_imgw = NULL;
745 if( fr_rotate_imgh != NULL )
746 delete[] fr_rotate_imgh;
747 fr_rotate_imgh = NULL;
748 if( fr_delays != NULL )
749 delete[] fr_delays;
750 fr_delays = NULL;
751 if( fr_jumph != NULL )
752 delete[] fr_jumph;
753 fr_jumph = NULL;
754 if( fr_jumpx != NULL )
755 delete[] fr_jumpx;
756 fr_jumpx = NULL;
757 if( fr_jumpz != NULL )
758 delete[] fr_jumpz;
759 fr_jumpz = NULL;
760 if( fr_jump_timer != NULL )
761 delete[] fr_jump_timer;
762 fr_jump_timer = NULL;
764 clear_jump_stairs( fr_jump_stairs, nb_stair );
766 if( curr_frames == NULL )
768 Clear();
769 return;
772 // reinit vars
773 fr_decal_Xs = new int[curr_frames_count];
774 fr_decal_Ys = new int[curr_frames_count];
775 fr_total_decal_Xs = new int[curr_frames_count];
776 fr_total_decal_Ys = new int[curr_frames_count];
777 fr_As = new int[curr_frames_count];
778 fr_Zdecal = new int[curr_frames_count];
779 fr_offset_Xs = new int[curr_frames_count];
780 fr_offset_Ys = new int[curr_frames_count];
781 fr_DM_decal_Xs = new int[curr_frames_count];
782 fr_DM_decal_Ys = new int[curr_frames_count];
783 fr_rotate_offset_Xs = new int[curr_frames_count];
784 fr_rotate_offset_Ys = new int[curr_frames_count];
785 original_img_w = new int[curr_frames_count];
786 original_img_h = new int[curr_frames_count];
787 current_img_w = new int[curr_frames_count];
788 current_img_h = new int[curr_frames_count];
789 fr_rotate_imgw = new int[curr_frames_count];
790 fr_rotate_imgh = new int[curr_frames_count];
791 fr_delays = new int[curr_frames_count];
792 fr_jumph = new int[curr_frames_count];
793 fr_jumpx = new int[curr_frames_count];
794 fr_jumpz = new int[curr_frames_count];
795 fr_jump_timer = new int[curr_frames_count];
796 fr_jump_stairs = new jump_stair[curr_frames_count];
797 nb_stair = curr_frames_count;
799 total_W = 0;
800 total_H = 0;
802 // The max depassage relative to the first frame left-top corner
803 float max_spilling_X = 0;
804 float max_spilling_Y = 0;
806 // Information on the previous frame
807 int prev_offset_X = 0;
808 int prev_offset_Y = 0;
809 int prev_total_decalx = 0;
810 int prev_total_decaly = 0;
812 min_decal_X = 0;
813 min_decal_Y = 0;
815 int prev_fr_time = 0;
818 // ****************************************************************************************
819 //********************************************
820 // first recalculate jumps datas
821 _Recalculate_JumpStuffs();
824 // ****************************************************************************************
825 // Init some jump datas
826 ob_object *jumpframe_prop = curr_anim->GetSubObject( wxT("jumpframe") );
827 int jump_speedx = 0;
828 int jump_speedz = 0;
830 if( jumpframe_prop != NULL && jumpframe_prop->GetToken(0) != wxString() )
832 jump_speedx = StrToInt( jumpframe_prop->GetToken(2) );
833 jump_speedz = StrToInt( jumpframe_prop->GetToken(3) );
835 else if( Is_AAirAnim() )
837 if( curr_anim->GetToken(0).Left(4).Upper() == wxT("FALL") )
838 jump_speedx = -2;
839 else if( curr_anim->GetToken(0).Left(4).Upper() == wxT("JUMP") )
840 jump_speedx = 0;
841 jump_speedz = 0;
845 // ****************************************************************************************
846 // getting the decal for each frame and the overall decal relative with the first frame
847 #define DGET_DMVAL(prop,k) \
848 (curr_frames[i]->prop[k]!=NO_CLONED_VAL?curr_frames[i]->prop[k]:0)
849 #define DGET_SVAL(prop) \
850 (curr_frames[i]->prop!=NO_CLONED_VAL?curr_frames[i]->prop:0)
852 for( int i = 0; i < curr_frames_count; i++ )
854 // Get size of the img of the frame
855 wxImage *fr_img = curr_frames[i]->GetImage();
857 if( fr_img == NULL )
858 fr_img = noImg;
859 float img_w = fr_img->GetWidth();
860 float img_h = fr_img->GetHeight();
861 original_img_w[i] = img_w;
862 original_img_h[i] = img_h;
864 int offsetX = DGET_DMVAL(offset,0);
865 int original_offsetX = offsetX;
866 int offsetY = DGET_DMVAL(offset,1);
867 int original_offsetY = offsetY;
868 int movex = DGET_SVAL(move);
869 int movea = DGET_SVAL(moveA);
870 int movez = DGET_SVAL(moveZ);
872 bool b_flipped = false;
873 if( curr_frames[i]->flipState > 0 )
875 movex = -movex;
876 fr_jumpx[i] = - fr_jumpx[i];
877 original_offsetX = img_w - offsetX;
878 offsetX = original_offsetX;
879 b_flipped = true;
882 // Apply drawmethod transformations
883 if( curr_frames[i]->GetSubObject( wxT("nodrawmethod") ) == NULL
884 && curr_frames[i]->GetSubObject( wxT("drawmethod")) != NULL )
886 // drawmethod datas
887 int _i = 0;
888 int _scaleX = DGET_DMVAL(drawMethod,_i);
889 _i++;
890 int _scaleY = DGET_DMVAL(drawMethod,_i);
891 _i++;
892 int _flipX = DGET_DMVAL(drawMethod,_i);
893 _i++;
894 int _flipY = DGET_DMVAL(drawMethod,_i);
895 _i += 5;
896 int _rotate = DGET_DMVAL(drawMethod,_i);
897 _i++;
898 bool _fliprotate = (DGET_DMVAL(drawMethod,_i) != 0);
900 // scale the offset
901 if( _scaleX != 0 )
903 float _dm_scaleX = ((float) _scaleX / (float) 256 );
904 offsetX *= _dm_scaleX;
905 img_w *= _dm_scaleX;
906 if( _dm_scaleX < 0 )
908 img_w = - img_w;
909 offsetX = img_w + offsetX;
912 if( _scaleY != 0 )
914 float _dm_scaleY = ((float) _scaleY / (float) 256 );
915 offsetY *= _dm_scaleY;
916 img_h *= _dm_scaleY;
917 if( _dm_scaleY < 0 )
919 img_h = - img_h;
920 offsetY = img_h + offsetY;
923 if( _flipX )
925 offsetX = img_w - offsetX;
927 if( _flipY )
929 offsetY = img_h - offsetY;
932 fr_rotate_imgw[i] = img_w;
933 fr_rotate_imgh[i] = img_h;
935 // Rotation stuff
936 if( _rotate != 0 )
938 if( b_flipped && _fliprotate )
939 _rotate = - _rotate;
940 fr_rotate_offset_Xs[i] = offsetX;
941 fr_rotate_offset_Ys[i] = offsetY;
942 float new_img_w, new_img_h, new_off_x,new_off_y;
943 getRotationNewOffset( offsetX, offsetY, ceil(img_w), ceil(img_h),
944 _rotate, new_off_x, new_off_y, new_img_w, new_img_h );
945 offsetX = new_off_x;
946 offsetY = new_off_y;
947 img_w = new_img_w;
948 img_h = new_img_h;
952 img_w = ceil(img_w);
953 img_h = ceil(img_h);
954 current_img_w[i] = img_w;
955 current_img_h[i] = img_h;
957 fr_offset_Xs[i] = offsetX;
958 fr_offset_Ys[i] = offsetY;
959 fr_DM_decal_Xs[i] = original_offsetX - offsetX;
960 fr_DM_decal_Ys[i] = original_offsetY - offsetY;
962 int tot_decal_x = 0, tot_decal_y = 0;
963 if( i > 0 )
965 int tot_movea = - movea;
966 int tot_movez = movez;
967 int tot_movex = movex;
969 // If not in a jump
970 if( curr_frames[i]->jumpState == 0 )
971 fr_As[i] = - movea + fr_As[i-1];
973 // In a jump, must compute the new altitude
974 else
976 // This one have no delay -> no implications
977 if( fr_delays[i] == 0 )
979 fr_As[i] = fr_As[i-1];
980 fr_decal_Xs[i] = 0;
981 fr_Zdecal[i] = 0;
982 tot_movea = 0;
983 tot_movez = 0;
984 tot_movex = 0;
985 fr_jump_stairs[i].mv_x = 0;
986 fr_jump_stairs[i].mv_z = 0;
988 else
990 fr_As[i] = - fr_jumph[i] + fr_As[i-1];
991 fr_decal_Xs[i] += fr_jumpx[i];
992 fr_Zdecal[i] -= fr_jumpz[i];
993 tot_movea = - fr_jumph[i];
994 tot_movez += fr_jumpz[i];
995 tot_movex += fr_jumpx[i];
996 fr_jump_stairs[i].mv_x = (float)movex / (float)fr_delays[i] + (float) jump_speedx;
997 fr_jump_stairs[i].mv_z = (float)movez / (float)fr_delays[i] + (float) jump_speedz;
1001 int decalx = prev_offset_X + tot_movex - offsetX;
1002 int decaly = prev_offset_Y + tot_movez + tot_movea - offsetY;
1003 tot_decal_x = decalx + prev_total_decalx;
1004 tot_decal_y = decaly + prev_total_decaly;
1006 fr_decal_Xs[i] = decalx;
1007 fr_decal_Ys[i] = decaly;
1008 fr_total_decal_Xs[i] = tot_decal_x;
1009 fr_total_decal_Ys[i] = tot_decal_y;
1011 fr_Zdecal[i] = -movez + fr_Zdecal[i-1];
1014 else
1016 fr_decal_Xs[i] = 0;
1017 fr_decal_Ys[i] = 0;
1018 fr_As[i] = 0;
1019 fr_Zdecal[i] = 0;
1020 fr_total_decal_Xs[i] = 0;
1021 fr_total_decal_Ys[i] = 0;
1023 // In a jump, must compute the new altitude
1024 if( curr_frames[i]->jumpState > 0 )
1026 fr_jump_stairs[i].mv_x = (float)movex / (float)fr_delays[i] + (float) jump_speedx;
1027 fr_jump_stairs[i].mv_z = (float)movez / (float)fr_delays[i] + (float) jump_speedz;
1031 if( tot_decal_x < min_decal_X )
1032 min_decal_X = tot_decal_x;
1033 if( tot_decal_y < min_decal_Y )
1034 min_decal_Y = tot_decal_y;
1036 int curr_spilling_X = tot_decal_x + img_w;
1037 int curr_spilling_Y = tot_decal_y + img_h;
1039 if( curr_spilling_X > max_spilling_X )
1040 max_spilling_X = curr_spilling_X;
1041 if( curr_spilling_Y > max_spilling_Y )
1042 max_spilling_Y = curr_spilling_Y;
1044 // in case of a jump, have to calc all overhead of every jump step
1045 if( curr_frames[i]->jumpState > 0 && ! curr_frames[i]->end_jump )
1047 int nb_step = fr_jump_stairs[i].nb_step;
1048 int x_decal = fr_jump_stairs[i].mv_x;
1049 int z_decal = fr_jump_stairs[i].mv_z;
1051 float step_tot_dec_x = 0;
1052 float step_tot_dec_y = 0;
1054 for( int j = 0; j < nb_step; j ++ )
1056 int mv_h = fr_jump_stairs[i].steps[j].mv_h;
1057 int delay = JUMP_ANIM_STEP;
1058 if( j>0 )
1059 delay = fr_jump_stairs[i].steps[j-1].delay;
1061 step_tot_dec_x += (float) delay * x_decal;
1062 step_tot_dec_y += (float) delay * (float) z_decal - (float) mv_h;
1064 // Update maxs
1065 if( tot_decal_x + step_tot_dec_x < min_decal_X )
1066 min_decal_X = tot_decal_x + step_tot_dec_x;
1067 if( tot_decal_y + step_tot_dec_y < min_decal_Y )
1068 min_decal_Y = tot_decal_y + step_tot_dec_y;
1070 if( curr_spilling_X + step_tot_dec_x> max_spilling_X )
1071 max_spilling_X = curr_spilling_X + step_tot_dec_x;
1072 if( curr_spilling_Y + step_tot_dec_y > max_spilling_Y )
1073 max_spilling_Y = curr_spilling_Y + step_tot_dec_y;
1077 prev_offset_X = offsetX;
1078 prev_offset_Y = offsetY;
1079 prev_total_decalx = tot_decal_x;
1080 prev_total_decaly = tot_decal_y;
1082 prev_fr_time = DGET_DELAY(curr_frames[i]);
1085 total_W = ceil( - min_decal_X + max_spilling_X);
1086 total_H = ceil( - min_decal_Y + max_spilling_Y );
1088 if( GetScrollRange(wxHORIZONTAL) != (total_W * zoom_factor)
1089 || GetScrollRange(wxVERTICAL ) != (total_H * zoom_factor)
1091 Zoom( zoom_factor, true, false );
1093 Refresh();
1097 //******************************************************
1098 enum { MYALL, MYRIGHT, MYLEFT };
1100 void MyAnimationZone::UpdateFrames()
1102 ReCalcAnimSize();
1103 RePaint();
1106 //******************************************************
1108 wxSize MyAnimationZone::DoGetBestSize() const
1110 return GetContainingSizer()->GetSize();
1114 void MyAnimationZone::Clear()
1116 if( theBitmap != NULL )
1117 delete theBitmap;
1118 theBitmap = NULL;
1120 if( fr_decal_Xs != NULL )
1121 delete[] fr_decal_Xs;
1122 fr_decal_Xs = NULL;
1124 if( fr_decal_Ys != NULL )
1125 delete[] fr_decal_Ys;
1126 fr_decal_Ys = NULL;
1128 if( fr_As != NULL )
1129 delete[] fr_As;
1130 fr_As = NULL;
1132 if( fr_total_decal_Xs != NULL )
1133 delete[] fr_total_decal_Xs;
1134 fr_total_decal_Xs = NULL;
1136 if( fr_total_decal_Ys != NULL )
1137 delete[] fr_total_decal_Ys;
1138 fr_total_decal_Ys = NULL;
1140 if( fr_rotate_offset_Xs != NULL )
1141 delete[] fr_rotate_offset_Xs;
1142 fr_rotate_offset_Xs = NULL;
1145 if( fr_rotate_offset_Ys != NULL )
1146 delete[] fr_rotate_offset_Ys;
1147 fr_rotate_offset_Ys = NULL;
1149 if( original_img_w != NULL )
1150 delete[] original_img_w;
1151 original_img_w = NULL;
1153 if( original_img_h != NULL )
1154 delete[] original_img_h;
1155 original_img_h = NULL;
1157 if( current_img_w != NULL )
1158 delete[] current_img_w;
1159 current_img_w = NULL;
1161 if( current_img_h != NULL )
1162 delete[] current_img_h;
1163 current_img_h = NULL;
1165 if( fr_rotate_imgw != NULL )
1166 delete[] fr_rotate_imgw;
1167 fr_rotate_imgw = NULL;
1169 if( fr_rotate_imgh != NULL )
1170 delete[] fr_rotate_imgh;
1171 fr_rotate_imgh = NULL;
1173 if( fr_delays != NULL )
1174 delete[] fr_delays;
1175 fr_delays = NULL;
1177 if( fr_jumph != NULL )
1178 delete[] fr_jumph;
1179 fr_jumph = NULL;
1181 if( fr_jumpx != NULL )
1182 delete[] fr_jumpx;
1183 fr_jumpx = NULL;
1185 if( fr_jumpz != NULL )
1186 delete[] fr_jumpz;
1187 fr_jumpz = NULL;
1189 if( fr_jump_timer != NULL )
1190 delete[] fr_jump_timer;
1191 fr_jump_timer = NULL;
1193 clear_jump_stairs( fr_jump_stairs, nb_stair );
1195 total_W = 0;
1196 total_H = 0;
1197 min_decal_X = 0;
1198 min_decal_Y = 0;
1200 m_flag &= ~M_PAINTING;
1202 Zoom( 3, true );
1204 Refresh();
1208 //******************************************************
1210 void MyAnimationZone::EvtMouseSomething(wxMouseEvent& event)
1212 // No mouse something with no frame avalaible
1213 if( curr_frames == NULL || curr_anim == NULL || fr_total_decal_Xs == NULL )
1214 return;
1216 int mx = event.m_x;
1217 int my = event.m_y;
1219 // Gather information about the frame currently drawn
1220 // Getting the indice of the frame
1221 int _ind = ind_active_frame;
1222 if( _ind < 0 )
1223 _ind = 0;
1224 if( _ind >= curr_frames_count )
1225 return;
1227 wxImage *fr_img = curr_frames[_ind]->GetImage();
1228 if( fr_img == NULL )
1229 fr_img = noImg;
1230 int img_w = (int)((float)fr_img->GetWidth() * zoom_factor);
1231 int img_h = (int)((float)fr_img->GetHeight() * zoom_factor );
1232 if( img_w <= 5 && img_h <= 5 )
1234 fr_img = noImg;
1235 img_w = (int)((float)fr_img->GetWidth() * zoom_factor);
1236 img_h = (int)((float)fr_img->GetHeight() * zoom_factor );
1239 // Gather Infos about the painting zone
1240 int _w,_h;
1241 GetSize( &_w, &_h);
1243 // decal_x = 0;
1244 // decal_y = 0;
1245 // if( (int)((float)total_W*zoom_factor) < _w )
1246 // decal_x = (_w - (int)((float)total_W*zoom_factor)) /2;
1247 // if( (int)((float)total_H*zoom_factor) < _h )
1248 // decal_y = (_h - (int)((float)total_H*zoom_factor)) /2;
1250 // Getting the decals for the current frame
1251 int dc_x = fr_total_decal_Xs[_ind];
1252 int dc_y = fr_total_decal_Ys[_ind];
1254 // Translate mouse coord to animation coord
1255 mx -= decal_x + (int)((float)(dc_x - min_decal_X)*zoom_factor);
1256 my -= decal_y + (int)((float)(dc_y - min_decal_Y)*zoom_factor);
1258 mx = (int)((float)mx / zoom_factor);
1259 my = (int)((float)my / zoom_factor);
1261 if( event.Moving() == true )
1263 // Put the tooltip
1264 wxString tip_txt=
1265 IntToStr(mx)
1266 + wxT(" , ")
1267 + IntToStr(my)
1269 theTip->SetTip( tip_txt );
1270 theTip->Enable(true);
1271 event.Skip();
1272 return;
1274 if( event.IsButton() == true )
1275 theTip->Enable(false);
1277 // Left click
1278 if( event.ButtonUp() )
1280 b_mouseD = false;
1281 // Simple click
1282 if( mouse_draw == DRAW_NOTHING || ( abs(r_x - mx) < 2 && abs(r_y - my) < 2 ))
1284 TO_x = mx - fr_offset_Xs[_ind];
1285 if( curr_frames[_ind]->flipState > 0 )
1286 TO_x = -TO_x;
1287 TO_x += + curr_frames[_ind]->move;
1288 TO_a = fr_offset_Ys[_ind] - my + curr_frames[_ind]->moveA;
1290 ReverseDMCoord( mx, my);
1291 ReverseFPCoord(mx);
1292 TO_offx = mx;
1293 TO_offy = my;
1295 TO_w = 0;
1296 TO_h = 0;
1297 mouse_draw = DRAW_AIM;
1298 OnSimpleClick(event);
1299 RePaint();
1300 return;
1302 else
1304 if( my < r_y)
1306 int t = r_y;
1307 r_y = my;
1308 my = t;
1310 if( mx < r_x )
1312 int t = r_x;
1313 r_x = mx;
1314 mx = t;
1317 r_w = mx - r_x;
1318 r_h = my - r_y;
1320 TO_x = 0;
1321 TO_a = 0;
1322 TO_w = r_w;
1323 TO_h = r_h;
1325 // More work with the offsets due To DM
1326 TO_offx = r_x;
1327 TO_offy = r_y;
1329 // Apply the Flipframe mod
1330 ReverseFPCoord(TO_offx,r_w);
1332 // Take the Offset decal due to the DM
1333 TO_offx += fr_DM_decal_Xs[_ind];
1334 TO_offy += fr_DM_decal_Ys[_ind];
1336 OnEndLeftDragging();
1337 RePaint();
1338 return;
1342 if( event.ButtonDown() || event.RightDown() )
1344 TO_offx = 0;
1345 TO_offy = 0;
1346 TO_x = 0;
1347 TO_a = 0;
1348 TO_w = 0;
1349 TO_h = 0;
1350 mouse_draw = DRAW_NOTHING;
1351 OnAnyButtonDown();
1354 if( event.ButtonDown() )
1356 b_mouseD = true;
1357 b_rightmouseD = false;
1358 r_x = mx;
1359 r_y = my;
1360 OnLeftButtonDown();
1361 RePaint();
1362 return;
1366 if( event.RightDown() )
1368 b_mouseD = false;
1369 b_rightmouseD = true;
1370 r_right_x = mx;
1371 r_right_y = my;
1372 RePaint();
1373 return;
1377 if( event.Dragging() && event.m_leftDown )
1379 if( ! b_mouseD )
1380 return;
1381 mouse_draw = DRAW_RECT;
1382 r_w = mx - r_x;
1383 r_h = my - r_y;
1384 OnDragging();
1385 RePaint();
1386 return;
1389 event.Skip();
1392 void MyAnimationZone::OnSimpleClick(wxMouseEvent& event)
1396 void MyAnimationZone::OnEndLeftDragging()
1400 void MyAnimationZone::OnAnyButtonDown()
1404 void MyAnimationZone::OnLeftButtonDown()
1408 void MyAnimationZone::OnDragging()
1413 //******************************************************
1415 void MyAnimationZone::ResetMouseDraw()
1417 TO_offx = 0;
1418 TO_offy = 0;
1419 TO_x = 0;
1420 TO_a = 0;
1421 TO_w = 0;
1422 TO_h = 0;
1423 mouse_draw = DRAW_NOTHING;
1424 RePaint();
1427 //******************************************************
1429 void MyAnimationZone::OnEraseBackground(wxEraseEvent& event)
1431 event.Skip();
1434 //******************************************************
1436 void MyAnimationZone::RePaint()
1438 Refresh();
1441 //******************************************************
1443 void MyAnimationZone::Draw_NoImg()
1445 int _w,_h;
1446 GetSize( &_w, &_h);
1447 if( _w > 0 && _h > 0 )
1449 theBitmap = new wxBitmap( noImg->Scale(_w/2, _h/2));
1450 dc->DrawBitmap( *theBitmap, _w/4, _h/4, true );
1454 //******************************************************
1456 void MyAnimationZone::myDrawLine( int _x0, int _y0, int _x1, int _y1 )
1458 dc->DrawLine( decal_x + (int)((float)(_x0 - min_decal_X)*zoom_factor),
1459 decal_y + (int)((float)(_y0 - min_decal_Y)*zoom_factor),
1460 decal_x + (int)((float)(_x1 - min_decal_X)*zoom_factor),
1461 decal_y + (int)((float)(_y1 - min_decal_Y)*zoom_factor) );
1464 void MyAnimationZone::myDrawRect( int _x, int _y, int _w, int _h, bool b_label_reserve )
1466 if( ! b_label_reserve )
1467 dc->DrawRectangle( decal_x + (int)((float)(_x - min_decal_X)*zoom_factor),
1468 decal_y + (int)((float)(_y - min_decal_Y)*zoom_factor),
1469 (int)((float)_w*zoom_factor),
1470 (int)((float)_h*zoom_factor) );
1471 else
1473 myDrawLine( _x + 5, _y, _x+_w, _y );
1474 myDrawLine( _x, _y + 5, _x, _y+_h );
1475 myDrawLine( _x+_w, _y, _x+_w, _y+_h );
1476 myDrawLine( _x, _y+_h, _x+_w,_y+_h );
1480 void MyAnimationZone::myDrawCircle( int _x,int _y, int rayon )
1482 dc->DrawCircle( decal_x +(int)((float)(_x - min_decal_X)*zoom_factor),
1483 decal_y +(int)((float)(_y - min_decal_Y)*zoom_factor),
1484 (int)((float)rayon * zoom_factor) );
1487 void MyAnimationZone::myDrawLabel( const wxString& text, int _x,int _y )
1489 int _w = text.Len()*5;
1490 int _h = 10;
1491 dc->SetTextBackground( wxNullColour );
1492 dc->SetTextForeground( dc->GetPen().GetColour() );
1493 dc->DrawText( text
1494 ,decal_x + (int)((float)(_x - min_decal_X -_w/2)*zoom_factor)
1495 ,decal_y + (int)((float)(_y - min_decal_Y -_h/3)*zoom_factor) );
1498 //******************************************************
1500 void MyAnimationZone::PaintBackground()
1502 brush.SetColour(orig_bg);
1503 dc->SetBrush(brush);
1504 pen.SetColour(orig_bg);
1505 dc->SetPen(pen);
1506 myDrawRect( min_decal_X, min_decal_Y, total_W, total_H );
1509 int MyAnimationZone::GetIndFrameToPaint()
1511 return ind_active_frame;
1514 //******************************************************
1516 void MyAnimationZone::OnPaint(wxPaintEvent& event)
1518 m_flag |= M_PAINTING;
1519 bool b_setdcNull = false;
1520 if( dc == NULL )
1522 dc = new wxAutoBufferedPaintDC( this );
1523 if( ! dc->IsOk() )
1525 delete dc;
1526 m_flag &= ~M_PAINTING;
1527 return;
1529 b_setdcNull = true;
1532 orig_bg= GetBackgroundColour();
1534 // RePaint All the background SETED
1535 int _w,_h;
1536 GetSize( &_w, &_h);
1538 brush.SetColour(orig_bg);
1539 if( !brush.IsOk() )
1541 if( b_setdcNull )
1543 delete dc;
1544 dc = NULL;
1546 return;
1548 // dc->SetBrush(brush);
1549 dc->SetBackground(orig_bg);
1550 dc->Clear();
1551 // dc->SetPen(pen);
1552 // dc->DrawRectangle( 0, 0, _w, _h );
1554 // Paint the frame
1555 if( curr_frames != NULL && curr_anim != NULL && fr_total_decal_Xs != NULL )
1557 ind_frPainted = GetIndFrameToPaint();
1558 if( ind_frPainted < 0 )
1559 ind_frPainted = 0;
1560 if( ind_frPainted >= curr_frames_count )
1562 Draw_NoImg();
1563 if( b_setdcNull )
1565 delete dc;
1566 dc = NULL;
1568 m_flag &= ~M_PAINTING;
1569 return;
1572 // Original image size
1573 int original_img_w;
1574 int original_img_h;
1576 // image size after draw method application
1577 int img_w;
1578 int img_h;
1580 // if the frame is a flipped one (with flipframe prop)
1581 flipped_fr = false;
1583 wxImage *orig_fr_img = curr_frames[ind_frPainted]->GetImage();
1584 wxImage fr_img;
1585 if( orig_fr_img == NULL )
1587 fr_img = *noImg;
1588 original_img_w = fr_img.GetWidth();
1589 original_img_h = fr_img.GetHeight();
1592 //*****************************************
1593 // apply transformations to the image
1594 //*****************************************
1595 if( orig_fr_img != NULL )
1597 fr_img = orig_fr_img->Copy();
1598 PreProcessImage( fr_img );
1599 original_img_w = fr_img.GetWidth();
1600 original_img_h = fr_img.GetHeight();
1602 //*****************************************
1603 // flipframe transformation
1604 if( curr_frames[ind_frPainted]->flipState > 0 )
1606 flipped_fr = true;
1607 fr_img = fr_img.Mirror();
1610 //*****************************************
1611 // draw image transformations
1612 if( curr_frames[ind_frPainted]->GetSubObject( wxT("nodrawmethod") ) == NULL
1613 && curr_frames[ind_frPainted]->GetSubObject( wxT("drawmethod")) != NULL )
1615 #define DGET_DMVAL2(k) \
1616 (curr_frames[ind_frPainted]->drawMethod[k]!=NO_CLONED_VAL?curr_frames[ind_frPainted]->drawMethod[k]:0)
1617 // draw image datas
1618 int _i = 0;
1619 int _scaleX = DGET_DMVAL2(_i);
1620 _i++;
1621 int _scaleY = DGET_DMVAL2(_i);
1622 _i++;
1623 bool _flipx = (DGET_DMVAL2(_i)!=0);
1624 _i++;
1625 bool _flipy = (DGET_DMVAL2(_i)!=0);
1626 _i++;
1627 // int _shiftx = curr_frames[ind_frPainted]->drawMethod[_i];
1628 _i++;
1629 // int _alpha = curr_frames[ind_frPainted]->drawMethod[_i]
1630 _i++;
1631 // int _remap = curr_frames[ind_frPainted]->drawMethod[_i]
1632 _i++;
1633 // int _fillcolor = curr_frames[ind_frPainted]->drawMethod[_i]
1634 _i++;
1635 int _rotate = DGET_DMVAL2(_i);
1636 _i++;
1637 bool _fliprotate=(DGET_DMVAL2(_i)!=0);
1639 // draw image FLIPS
1640 if( _flipx )
1641 fr_img = fr_img.Mirror( true );
1642 if( _flipy )
1643 fr_img = fr_img.Mirror( false );
1645 // draw image scaling
1646 if( _scaleX != 0 || _scaleY != 0)
1648 if( _scaleX == 0 ) _scaleX = 256;
1649 if( _scaleY == 0 ) _scaleY = 256;
1651 if( _scaleX < 0 )
1653 fr_img = fr_img.Mirror( true );
1654 _scaleX = - _scaleX;
1657 if( _scaleY < 0 )
1659 fr_img = fr_img.Mirror( false );
1660 _scaleY = - _scaleY;
1663 float dm_scalex = ((float) _scaleX / (float) 256 );
1664 float dm_scaley = ((float) _scaleY / (float) 256 );
1666 fr_img.Rescale( (int)((float) fr_img.GetWidth() * dm_scalex)
1667 ,(int)((float) fr_img.GetHeight()* dm_scaley ));
1670 // Rotate
1671 if( _rotate )
1673 if( flipped_fr && _fliprotate )
1674 _rotate = - _rotate;
1675 fr_img.SetMaskColour( 255, 0, 255 );
1676 fr_img = fr_img.Rotate( (float) (-_rotate) * (float) 2 * PI / (float) 360
1677 , wxPoint(fr_rotate_offset_Xs[ind_frPainted],fr_rotate_offset_Ys[ind_frPainted])
1678 , true );
1679 fr_img.SetMask(false);
1685 img_w = fr_img.GetWidth();
1686 img_h = fr_img.GetHeight();
1687 int real_img_w = (int)((float) img_w * zoom_factor);
1688 int real_img_h = (int)((float) img_h * zoom_factor );
1690 if( theBitmap != NULL )
1691 delete theBitmap;
1692 theBitmap = new wxBitmap( fr_img.Scale(real_img_w, real_img_h));
1695 // Gather Infos about the painting zone
1696 //Check if the anim size is lower than the client size
1697 if( (int)((float)total_W*zoom_factor) < _w )
1698 decal_x = (_w - (int)((float)total_W*zoom_factor)) /2;
1699 else
1700 decal_x = - GetScrollPos(wxHORIZONTAL);
1702 if( (int)((float)total_H*zoom_factor) < _h )
1703 decal_y = (_h - (int)((float)total_H*zoom_factor)) /2;
1704 else
1705 decal_y = - GetScrollPos(wxVERTICAL);
1708 // Paint the borders of the background
1709 brush.SetColour(*wxBLACK);
1710 dc->SetBrush(brush);
1711 pen.SetColour( *wxBLACK );
1712 dc->SetPen(pen);
1713 myDrawRect( min_decal_X - 2, min_decal_Y - 2, total_W + 4, total_H + 4 );
1715 m_flag &= ~M_REDRAW_ALL;
1717 // Paint the background
1718 PaintBackground();
1721 //******************************************
1722 // init Some variables
1723 prev_frame_rect_x = decal_x + (-min_decal_X + fr_total_decal_Xs[ind_frPainted]) * zoom_factor;
1724 prev_frame_rect_y = decal_y + (-min_decal_Y + fr_total_decal_Ys[ind_frPainted]) * zoom_factor;
1725 prev_frame_rect_w = theBitmap->GetWidth();
1726 prev_frame_rect_h = theBitmap->GetHeight();
1727 dc_x = fr_total_decal_Xs[ind_frPainted];
1728 dc_y = fr_total_decal_Ys[ind_frPainted];
1730 //******************************************
1731 // Draw the bitmap
1732 //******************************************
1733 if( ! draw_jump_step )
1734 dc->DrawBitmap( *theBitmap, prev_frame_rect_x, prev_frame_rect_y, true );
1735 else
1737 dc->DrawBitmap( *theBitmap,
1738 prev_frame_rect_x + jump_decal_x * zoom_factor,
1739 prev_frame_rect_y + (-jump_decal_alt+jump_decal_z) * zoom_factor,
1740 true );
1743 // curr_frames == NULL
1744 else
1746 Draw_NoImg();
1749 m_flag &= ~M_PAINTING;
1750 if( b_setdcNull )
1752 delete dc;
1753 dc = NULL;
1758 //******************************************************
1759 void
1760 MyAnimationZone::PreProcessImage( wxImage& fr_img )
1765 //******************************************************
1767 void MyAnimationZone::Refresh()
1769 m_flag |= M_REDRAW_ALL;
1770 wxControl::Refresh();
1773 //******************************************************
1775 void MyAnimationZone::EvtSize( wxSizeEvent& event )
1777 event.Skip();
1778 Zoom(zoom_factor, true, false );
1779 Refresh();
1783 //******************************************************
1785 void MyAnimationZone::EvtGetFocus(wxFocusEvent&)
1790 //******************************************************
1793 void _rotate_point( float& _x, float& _y, int _angle );
1795 void MyAnimationZone::ReverseFPCoord( int& _mx, int _mw )
1797 int ind = ind_active_frame;
1798 if( curr_frames[ind]->flipState > 0 )
1800 _mx = original_img_w[ind] - _mx;
1801 _mx = _mx - _mw;
1805 //******************************************************
1808 void MyAnimationZone::ReverseDMCoord( int& _mx, int& _my)
1810 int ind = ind_active_frame;
1811 if( curr_frames[ind]->GetSubObject( wxT("nodrawmethod") ) == NULL
1812 && curr_frames[ind]->GetSubObject( wxT("drawmethod")) != NULL )
1814 // draw image datas
1815 int _i = 0;
1816 int _scaleX = curr_frames[ind]->drawMethod[_i];
1817 _i++;
1818 int _scaleY = curr_frames[ind]->drawMethod[_i];
1819 _i++;
1820 bool _flipx = (curr_frames[ind]->drawMethod[_i]!=0);
1821 _i++;
1822 bool _flipy = (curr_frames[ind]->drawMethod[_i]!=0);
1823 _i+=4;
1824 // int _fillcolor = curr_frames[ind]->drawMethod[_i];
1825 _i++;
1826 int _rotate = curr_frames[ind]->drawMethod[_i];
1827 _i++;
1828 bool _fliprotate = (curr_frames[ind]->drawMethod[_i]!=0);
1831 // DeRotate
1832 if( _rotate != 0 )
1834 // Derotate current cursor vector
1835 float _x = -(fr_offset_Xs[ind] - _mx);
1836 float _y = fr_offset_Ys[ind] - _my;
1837 if( curr_frames[ind]->flipState > 0 && _fliprotate )
1838 _rotate = - _rotate;
1839 if( _x != 0 || _y != 0 )
1840 _rotate_point( _x, _y, - _rotate );
1842 // Rescale the "before rotation" vector to the original image size
1843 _mx = fr_rotate_offset_Xs[ind] + _x;
1844 _my = fr_rotate_offset_Ys[ind] - _y;
1847 // reverse flips
1848 if( _flipx )
1850 _mx = fr_rotate_imgw[ind] - _mx;
1852 if( _flipy )
1854 _my = fr_rotate_imgh[ind] - _my;
1856 if( _scaleX < 0 )
1858 _mx = fr_rotate_imgw[ind] - _mx;
1859 _scaleX = - _scaleX;
1861 if( _scaleY < 0 )
1863 _my = fr_rotate_imgh[ind] - _my;
1864 _scaleY = - _scaleY;
1867 // Descale
1868 if( _scaleX != 0 )
1870 float _factor = (float)256 / (float)_scaleX;
1871 _mx *= _factor;
1873 if( _scaleY != 0 )
1875 float _factor = (float)256 / (float)_scaleY;
1876 _my *= _factor;
1881 void _rotate_point( float& _x, float& _y, int _angle )
1883 float angle = (float) (-_angle) * (float)2 * (float)PI / (float) 360;
1884 float mod = sqrt( _x*_x + _y*_y );
1885 float alpha = acos( _x / mod );
1886 if( _y < 0 )
1887 alpha = -alpha;
1888 _x = cos( angle + alpha ) * mod;
1889 _y = sin( angle + alpha ) * mod;
1893 #define _MIN(x1,x2) ((x1 >x2) ? x2: x1)
1894 #define _MAX(x1,x2) ((x1 >x2) ? x1: x2)
1896 void getRotationNewOffset( int off_x, int off_y, int _w, int _h, int angle,
1897 float& new_offx, float& new_offy,float& new_w, float& new_h )
1899 float p0_x = - off_x;
1900 float p0_y = off_y;
1901 float p1_x = - off_x;
1902 float p1_y = off_y - _h;
1903 float p2_x = _w - off_x;
1904 float p2_y = off_y - _h;
1905 float p3_x = _w - off_x;
1906 float p3_y = off_y;
1907 _rotate_point( p0_x, p0_y, angle );
1908 _rotate_point( p1_x, p1_y, angle );
1909 _rotate_point( p2_x, p2_y, angle );
1910 _rotate_point( p3_x, p3_y, angle );
1911 float xmin = _MIN( _MIN( p0_x, p1_x) , _MIN(p2_x, p3_x));
1912 float ymin = _MIN( _MIN( p0_y, p1_y) , _MIN(p2_y, p3_y));
1914 float xmax = _MAX( _MAX( p0_x, p1_x) , _MAX(p2_x, p3_x));
1915 float ymax = _MAX( _MAX( p0_y, p1_y) , _MAX(p2_y, p3_y));
1917 new_w = ceil(xmax) - floor(xmin);
1918 new_h = ceil(ymax) - floor(ymin);
1919 new_offx = - xmin;
1920 new_offy = ymax;
1923 //---------------------------------------------------------------
1924 void
1925 MyAnimationZone::Evt_Scroll( wxScrollWinEvent& evt )
1927 SetScrollPos( evt.GetOrientation(), evt.GetPosition() );
1928 RePaint();
1932 //******************************************************
1933 //******************************************************
1934 //******************************************************
1937 BEGIN_EVENT_TABLE(MyAnimationZone, wxControl)
1938 EVT_ERASE_BACKGROUND(MyAnimationZone::OnEraseBackground)
1939 EVT_PAINT(MyAnimationZone::OnPaint)
1940 EVT_MOUSE_EVENTS(MyAnimationZone::EvtMouseSomething)
1941 EVT_SIZE(MyAnimationZone::EvtSize)
1942 EVT_SET_FOCUS(MyAnimationZone::EvtGetFocus)
1943 EVT_SCROLLWIN(MyAnimationZone::Evt_Scroll)
1944 END_EVENT_TABLE()
1947 //******************************************************
1948 //******************************************************
1949 //******************************************************
1951 MyAnimationCtrl::MyAnimationCtrl( wxWindow *_parent )
1952 : MyAnimationZone( _parent ), anim_timer(this,TIMER_ANIM)
1954 b_looping = false;
1955 b_playing = false;
1956 b_sound_on = true;
1957 inStopPlaying = false;
1958 curr_played = 0;
1959 first_to_play = 0;
1960 last_to_play = 0;
1963 //******************************************************
1965 MyAnimationCtrl::~MyAnimationCtrl()
1969 //******************************************************
1971 void MyAnimationCtrl::GetFramesToPlay()
1973 // Get the selected frames from the list of frames
1974 panel_Anims->wList_frames->GetSelectedFrames( first_to_play, last_to_play );
1977 //******************************************************
1979 void MyAnimationCtrl::UpdateFrames()
1981 // No update when playing
1982 if( b_playing )
1983 return;
1985 MyAnimationZone::UpdateFrames();
1986 UpdateNavigation();
1989 //******************************************************
1991 void MyAnimationCtrl::UpdateNavigation()
1993 // Update navigation buttons
1994 if( curr_frames == NULL )
1996 panel_Anims->EnableNavigation( MYALL, false );
1997 Refresh();
1998 return;
2001 int ind = ind_active_frame;
2002 if( curr_frames_count == 1 )
2003 panel_Anims->EnableNavigation( MYALL, false );
2004 else if( ind >= curr_frames_count -1 )
2005 panel_Anims->EnableNavigation( MYRIGHT, false );
2006 else if( ind <= 0 )
2007 panel_Anims->EnableNavigation( MYLEFT, false );
2008 else if( ind > 0 && ind <= curr_frames_count )
2009 panel_Anims->EnableNavigation( MYALL, true );
2012 //******************************************************
2014 void MyAnimationCtrl::StartPlaying()
2016 if( b_playing )
2018 curr_played = first_to_play;
2019 return;
2021 else if( curr_frames_count <= 0 )
2022 return;
2024 else
2026 panel_Anims->butt_Play->SetBitmapLabel( wxBitmap( wxImage( GetRessourceFile_String(wxT("stop.png")))));
2027 b_playing = true;
2028 panel_Anims->wList_frames->GetSelectedFrames(first_to_play, last_to_play);
2029 curr_played = first_to_play -1;
2031 // Save the current selection of the list of frames
2032 panel_Anims->wList_frames->GetSelection( sv_ind_active, sv_ind_first, sv_ind_last );
2035 wxTimerEvent event;
2036 EvtTimer(event);
2040 void MyAnimationCtrl::StopPlaying()
2042 if( inStopPlaying )
2043 return;
2044 inStopPlaying = true;
2046 if( b_playing )
2048 panel_Anims->butt_Play->SetBitmapLabel( wxBitmap( wxImage( GetRessourceFile_String(wxT("aktion.png")))));
2050 // restore framelist selection
2051 panel_Anims->wList_frames->RestoreSelection( sv_ind_active, sv_ind_first, sv_ind_last );
2053 b_playing = false;
2055 // Reset jump vars
2056 is_in_jump = false;
2057 jump_last_delay = jump_time_counter = 0;
2058 draw_jump_step = false;
2061 anim_timer.Stop();
2062 UpdateNavigation();
2063 Refresh();
2064 inStopPlaying = false;
2068 //******************************************************
2070 void MyAnimationCtrl::Clear()
2072 MyAnimationZone::Clear();
2073 b_playing = false;
2074 inStopPlaying = false;
2077 //******************************************************
2079 void MyAnimationCtrl::EvtMouseSomething(wxMouseEvent& event)
2081 // No such things during animation
2082 if( b_playing )
2083 return;
2085 MyAnimationZone::EvtMouseSomething(event);
2088 //******************************************************
2090 void MyAnimationCtrl::OnSimpleClick(wxMouseEvent& event)
2092 panel_Anims->toBBox->Disable();
2093 panel_Anims->toAtt->Disable();
2094 panel_Anims->toOffset->Enable();
2095 panel_Anims->toXA->Enable();
2098 void MyAnimationCtrl::OnEndLeftDragging()
2100 panel_Anims->toBBox->Enable();
2101 panel_Anims->toAtt->Enable();
2102 panel_Anims->toOffset->Disable();
2103 panel_Anims->toXA->Disable();
2106 void MyAnimationCtrl::OnAnyButtonDown()
2108 panel_Anims->toBBox->Disable();
2109 panel_Anims->toAtt->Disable();
2110 panel_Anims->toOffset->Disable();
2111 panel_Anims->toXA->Disable();
2114 void MyAnimationCtrl::OnLeftButtonDown()
2118 void MyAnimationCtrl::ResetMouseDraw()
2120 panel_Anims->toBBox->Disable();
2121 panel_Anims->toAtt->Disable();
2122 panel_Anims->toOffset->Disable();
2123 panel_Anims->toXA->Disable();
2124 MyAnimationZone::ResetMouseDraw();
2127 void MyAnimationCtrl::EvtGetFocus(wxFocusEvent&)
2129 // repass the focus to the list of frames
2130 panel_Anims->wList_frames->SetFocus();
2133 //******************************************************
2135 void MyAnimationCtrl::EvtTimer(wxTimerEvent& event)
2137 draw_jump_step = false;
2138 if( is_in_jump )
2140 if( curr_played < curr_frames_count &&
2141 fr_jump_stairs[curr_played].curr_step < fr_jump_stairs[curr_played].nb_step )
2143 int curr_step = fr_jump_stairs[curr_played].curr_step;
2144 int curr_delay = JUMP_ANIM_STEP;
2145 curr_delay = fr_jump_stairs[curr_played].steps[curr_step].delay;
2146 jump_decal_alt += fr_jump_stairs[curr_played].steps[curr_step].mv_h;
2147 jump_decal_x += fr_jump_stairs[curr_played].mv_x * (float) curr_delay;
2148 jump_decal_z += fr_jump_stairs[curr_played].mv_z * (float) curr_delay;
2150 anim_timer.Start(10 * curr_delay );
2152 fr_jump_stairs[curr_played].curr_step++;
2154 // draw the frame
2155 draw_jump_step = true;
2157 RePaint();
2158 return;
2160 else
2161 fr_jump_stairs[curr_played].curr_step = 0;
2164 int k = 0;
2165 while( k <= curr_frames_count )
2167 curr_played++;
2168 if( curr_played > last_to_play )
2170 if( b_looping == false )
2172 StopPlaying();
2173 return;
2175 else
2176 curr_played = first_to_play;
2178 if( fr_delays[curr_played] > 0 )
2179 break;
2180 k++;
2183 if( k > curr_frames_count || curr_played < 0 || curr_played >= curr_frames_count )
2185 StopPlaying();
2186 return;
2189 // End of a jump
2190 if( curr_frames[curr_played]->end_jump )
2191 is_in_jump = false;
2193 // Frame of a jump
2194 else if( curr_frames[curr_played]->jumpState > 0 )
2196 // Start of a jump
2197 if( ! is_in_jump )
2199 is_in_jump = true;
2200 jump_time_counter = fr_jump_timer[curr_played];
2203 // Reset some frame jump datas
2204 jump_decal_x = jump_decal_z = jump_decal_alt = 0;
2206 panel_Anims->wList_frames->SetSelected( curr_played, false, false );
2208 // Set the timer
2209 jump_last_delay = fr_delays[curr_played];
2211 // the anim delay is lower than a jump animation step
2212 if( jump_last_delay >= JUMP_ANIM_STEP )
2213 jump_last_delay = JUMP_ANIM_STEP;
2214 anim_timer.Start(10 * jump_last_delay);
2216 // Play the sound
2217 PlayFrameSound();
2219 RePaint();
2220 return;
2223 // draw the frame
2224 PlayUpdate();
2227 //******************************************************
2229 void MyAnimationCtrl::PlayUpdate()
2231 if( curr_frames == NULL )
2232 return;
2234 // Set the curr_played frame
2235 panel_Anims->wList_frames->SetSelected( curr_played, false, false );
2237 // Set the timer
2238 int delay = fr_delays[curr_played];
2239 if( delay < 2 ) delay = 2;
2240 anim_timer.Start(delay*10);
2242 // draw the frame
2243 RePaint();
2245 // Play the sound
2246 PlayFrameSound();
2250 //******************************************************
2252 void MyAnimationCtrl::PlayFrameSound()
2254 ob_frame *frame_to_show = curr_frames[curr_played];
2255 if( frame_to_show != NULL && b_sound_on)
2257 wxFileName file_snd = GetObFile(frame_to_show->GetSubObject_Token(wxT("sound")));
2258 if( file_snd.FileExists() )
2260 PlaySound( (char*) file_snd.GetFullPath().c_str() );
2266 //******************************************************
2268 void MyAnimationCtrl::PaintBackground()
2270 if( ! b_playing )
2272 brush.SetColour(orig_bg);
2273 pen.SetColour(orig_bg);
2275 else
2277 brush.SetColour(ob_pink);
2278 pen.SetColour(ob_pink);
2280 dc->SetBrush(brush);
2281 dc->SetPen(pen);
2282 myDrawRect( min_decal_X, min_decal_Y, total_W, total_H );
2285 //******************************************************
2287 void MyAnimationCtrl::OnPaint(wxPaintEvent& event)
2289 dc = new wxAutoBufferedPaintDC( this );
2290 MyAnimationZone::OnPaint( event );
2292 m_flag |= M_PAINTING;
2293 if( curr_frames != NULL && curr_anim != NULL && fr_total_decal_Xs != NULL )
2295 //******************************************
2296 // Draw the ground lines
2297 //******************************************
2299 // The original ground line
2300 pen.SetColour( wxColour(0,0,0));
2301 pen.SetWidth( 2 );
2302 dc->SetPen( pen );
2303 int _firstframe_ground_y = fr_total_decal_Ys[0] + fr_offset_Ys[0];
2304 myDrawLine( min_decal_X, _firstframe_ground_y, total_W, _firstframe_ground_y );
2306 // The current ground line
2307 pen.SetColour( wxColour(255,255,0));
2308 pen.SetWidth( 2 );
2309 dc->SetPen( pen );
2310 int curr_ground_y = dc_y + fr_offset_Ys[ind_frPainted] - fr_As[ind_frPainted];
2311 if( curr_ground_y != _firstframe_ground_y )
2312 myDrawLine( min_decal_X,curr_ground_y , total_W, curr_ground_y );
2315 //******************************************
2316 // In case of not playing the animation, draw the beat-box and all the stuffs
2317 //******************************************
2320 if( !b_playing )
2322 // Draw the Offset cross
2323 pen.SetColour( wxColour(0,0,0));
2324 pen.SetWidth( 3 );
2325 dc->SetPen( pen );
2326 int cross_w = 7;
2327 myDrawLine( dc_x + fr_offset_Xs[ind_frPainted] - cross_w, dc_y + fr_offset_Ys[ind_frPainted],
2328 dc_x + fr_offset_Xs[ind_frPainted] + cross_w, dc_y + fr_offset_Ys[ind_frPainted] );
2329 myDrawLine( dc_x + fr_offset_Xs[ind_frPainted], dc_y + fr_offset_Ys[ind_frPainted] - cross_w,
2330 dc_x + fr_offset_Xs[ind_frPainted], dc_y + fr_offset_Ys[ind_frPainted] + cross_w );
2332 // Draw the Altitude
2333 if( fr_As[ind_frPainted] < 0 )
2335 pen.SetColour( wxColour(255,255,0));
2336 pen.SetWidth( 3 );
2337 dc->SetPen( pen );
2338 myDrawLine( dc_x+fr_offset_Xs[ind_frPainted], dc_y+fr_offset_Ys[ind_frPainted],
2339 dc_x+fr_offset_Xs[ind_frPainted], dc_y+fr_offset_Ys[ind_frPainted] - fr_As[ind_frPainted] );
2340 myDrawLine( dc_x+fr_offset_Xs[ind_frPainted]-3, dc_y+fr_offset_Ys[ind_frPainted] + 3,
2341 dc_x+fr_offset_Xs[ind_frPainted], dc_y+fr_offset_Ys[ind_frPainted] );
2342 myDrawLine( dc_x+fr_offset_Xs[ind_frPainted]+3, dc_y+fr_offset_Ys[ind_frPainted] + 3,
2343 dc_x+fr_offset_Xs[ind_frPainted], dc_y+fr_offset_Ys[ind_frPainted] );
2344 myDrawLine( dc_x+fr_offset_Xs[ind_frPainted]-2, dc_y+fr_offset_Ys[ind_frPainted] - fr_As[ind_frPainted],
2345 dc_x+fr_offset_Xs[ind_frPainted]+2, dc_y+fr_offset_Ys[ind_frPainted] - fr_As[ind_frPainted] );
2348 // Draw the beat-box
2349 int bbox_x = curr_frames[ind_frPainted]->bBox[0];
2350 int bbox_y = curr_frames[ind_frPainted]->bBox[1];
2351 int bbox_w = curr_frames[ind_frPainted]->bBox[2];
2352 int bbox_h = curr_frames[ind_frPainted]->bBox[3];
2354 if( bbox_x != 0 || bbox_y != 0 || bbox_w != 0 || bbox_h != 0 )
2356 if( flipped_fr )
2358 bbox_x = original_img_w[ind_frPainted] - bbox_x - bbox_w;
2360 pen.SetColour( panel_Anims->bbox_color->GetColor() );
2361 pen.SetWidth( 2 );
2362 dc->SetPen( pen );
2363 dc->SetBrush(*wxTRANSPARENT_BRUSH);
2364 myDrawRect( dc_x+ bbox_x - fr_DM_decal_Xs[ind_frPainted],
2365 dc_y+ bbox_y - fr_DM_decal_Ys[ind_frPainted],
2366 bbox_w, bbox_h, true );
2367 myDrawLabel( wxT("BB"), dc_x+bbox_x-fr_DM_decal_Xs[ind_frPainted], dc_y+bbox_y-fr_DM_decal_Ys[ind_frPainted]);
2370 // Draw the attack-boxes
2371 pen.SetWidth( 2 );
2372 pen.SetColour( panel_Anims->att_color->GetColor() );
2373 dc->SetPen( pen );
2375 wxString att_name = curr_frames[ind_frPainted]->attName;
2376 int att_x = curr_frames[ind_frPainted]->attBox[0];
2377 int att_y = curr_frames[ind_frPainted]->attBox[1];
2378 int att_w = curr_frames[ind_frPainted]->attBox[2];
2379 int att_h = curr_frames[ind_frPainted]->attBox[3];
2381 if( att_x != 0 || att_y != 0 || att_w != 0 || att_h != 0 )
2383 if( flipped_fr )
2385 att_x = original_img_w[ind_frPainted] - att_x - att_w;
2387 dc->SetBrush(*wxTRANSPARENT_BRUSH);
2388 myDrawRect( dc_x + att_x - fr_DM_decal_Xs[ind_frPainted]
2389 , dc_y + att_y - fr_DM_decal_Ys[ind_frPainted]
2390 , att_w
2391 , att_h, true );
2392 if( att_name.Left(6) == wxT("attack") )
2393 att_name = wxT("att") + att_name.Right(att_name.Len()-6);
2395 myDrawLabel( att_name,
2396 dc_x + att_x - fr_DM_decal_Xs[ind_frPainted],
2397 dc_y + att_y - fr_DM_decal_Ys[ind_frPainted]
2402 // Paint the mouse draw
2403 pen.SetColour( wxColour(0,255,0));
2404 dc->SetPen( pen );
2405 dc->SetBrush(*wxTRANSPARENT_BRUSH);
2406 if( mouse_draw == DRAW_AIM )
2408 myDrawCircle( dc_x+r_x, dc_y+r_y, 5 );
2409 myDrawLine( dc_x+r_x -2, dc_y+r_y, dc_x+r_x +2, dc_y+r_y );
2410 myDrawLine( dc_x+r_x , dc_y+r_y-2, dc_x+r_x , dc_y+r_y+2 );
2412 else if( mouse_draw == DRAW_RECT )
2414 myDrawRect( dc_x+r_x, dc_y+r_y, r_w, r_h );
2418 delete dc;
2419 dc = NULL;
2420 m_flag &= ~M_PAINTING;
2424 //******************************************************
2426 int MyAnimationCtrl::GetIndFrameToPaint()
2428 if( ! b_playing )
2429 return ind_active_frame;
2430 else
2431 return curr_played;
2435 //******************************************************
2436 //******************************************************
2437 //******************************************************
2438 //******************************************************
2439 BEGIN_EVENT_TABLE(MyAnimationCtrl, MyAnimationZone)
2440 EVT_PAINT(MyAnimationCtrl::OnPaint)
2441 EVT_SET_FOCUS(MyAnimationCtrl::EvtGetFocus)
2442 EVT_TIMER(TIMER_ANIM, MyAnimationCtrl::EvtTimer)
2443 END_EVENT_TABLE()
2447 //******************************************************
2448 //******************************************************
2449 //******************************************************
2450 //******************************************************
2452 MyRemapViewerCtrl::MyRemapViewerCtrl(wxWindow *_parent)
2453 :MyAnimationZone( _parent )
2455 #ifdef OSLINUX
2456 wxImage img_pip_plus( GetRessourceFile( wxT("cursor_pipette_plus.png") ).GetFullPath() );
2457 wxImage img_pip_simple( wxImage( GetRessourceFile( wxT("cursor_pipette_simple.png") ).GetFullPath() ) );
2458 #endif
2459 #ifdef OSWINDOW
2460 wxImage img_pip_plus( GetRessourceFile( wxT("cursor_pipette_plus-win.png") ).GetFullPath() );
2461 wxImage img_pip_simple( wxImage( GetRessourceFile( wxT("cursor_pipette_simple-win.png") ).GetFullPath() ) );
2462 #endif
2463 img_pip_plus.SetMask();
2464 img_pip_simple.SetMask();
2466 cursor_pipette_plus = wxCursor( img_pip_plus );
2467 cursor_pipette_simple= wxCursor( img_pip_simple );
2469 mouse_icon_state = 0;
2473 //******************************************************
2475 MyRemapViewerCtrl::~MyRemapViewerCtrl()
2477 if( dc != NULL )
2478 delete dc;
2482 //******************************************************
2484 void MyRemapViewerCtrl::PreProcessImage( wxImage& fr_img )
2486 if( panel_Remaps->paletteCtrl == NULL || ! panel_Remaps->paletteCtrl->b_init )
2487 return;
2489 int palette_count = panel_Remaps->paletteCtrl->thePalette->GetColoursCount();
2490 if( palette_count <= 0 )
2491 return;
2493 unsigned char o_r[palette_count], o_g[palette_count], o_b[palette_count];
2494 unsigned char n_r[palette_count], n_g[palette_count], n_b[palette_count];
2496 if( ! panel_Remaps->paletteCtrl->mode8bit )
2498 for( int i = 0; i < palette_count; i++)
2500 // Get the original colour
2501 panel_Remaps->paletteCtrl->thePalette->GetRGB( i, &o_r[i], &o_g[i], &o_b[i] );
2503 // Get the mapped colour
2504 panel_Remaps->paletteCtrl->paletteElements[i]->GetRGB( &n_r[i], &n_g[i], &n_b[i] );
2508 else
2510 for( int i = 0; i < palette_count; i++)
2512 // Get the original colour
2513 panel_Remaps->paletteCtrl->thePalette->GetRGB( i, &o_r[i], &o_g[i], &o_b[i] );
2515 // Get the mapped colour
2516 if( panel_Remaps->paletteCtrl->paletteElements[i]->mappedTo >= 0 )
2518 int ind_remap = panel_Remaps->paletteCtrl->paletteElements[i]->mappedTo;
2519 panel_Remaps->paletteCtrl->paletteElements[ind_remap]->GetRGB( &n_r[i], &n_g[i], &n_b[i] );
2521 else
2522 panel_Remaps->paletteCtrl->paletteElements[i]->GetRGB( &n_r[i], &n_g[i], &n_b[i] );
2527 // Do the mapping
2528 int nb_pixs = fr_img.GetWidth() * fr_img.GetHeight();
2529 unsigned char *_pixs = fr_img.GetData( );
2531 for( int i = 0; i < nb_pixs; i++ )
2533 unsigned char _r = _pixs[i*3];
2534 unsigned char _g = _pixs[i*3+1];
2535 unsigned char _b = _pixs[i*3+2];
2537 for (int j=0; j < palette_count; j++ )
2539 // No map for this colour
2540 if( n_r[j] == o_r[j] && n_g[j] == o_g[j] && n_b[j] == o_b[j] )
2541 continue;
2543 // Mapping found
2544 if( _r == o_r[j] && _g == o_g[j] && _b == o_b[j] )
2546 _pixs[i*3] = n_r[j];
2547 _pixs[i*3+1] = n_g[j];
2548 _pixs[i*3+2] = n_b[j];
2549 break;
2556 //******************************************************
2558 void MyRemapViewerCtrl::OnSimpleClick(wxMouseEvent& event)
2560 if( panel_Remaps->paletteCtrl == NULL || curr_frames == NULL || ind_active_frame < 0 )
2561 return;
2563 if( curr_frames[ind_active_frame]->GetImage() == noImg )
2564 return;
2566 //Get the index of the color under the mouse
2567 int ind = curr_frames[ind_active_frame]->Get_ColorIndex(TO_offx, TO_offy );
2569 if( ind < 0 )
2570 return;
2572 int add_mode = (event.m_controlDown?1:0)+(event.m_shiftDown?2:0);
2573 panel_Remaps->paletteCtrl->SelectColour( ind , add_mode);
2577 //******************************************************
2579 void MyRemapViewerCtrl::OnPaint(wxPaintEvent& event)
2581 dc = new wxAutoBufferedPaintDC( this );
2582 MyAnimationZone::OnPaint( event );
2583 delete dc;
2584 dc = NULL;
2587 //******************************************************
2588 void
2589 MyRemapViewerCtrl::EvtMouseMove(wxMouseEvent& event)
2591 MyAnimationZone::EvtMouseSomething( event );
2593 if( event.ControlDown() && mouse_icon_state <= 1 )
2595 // Set the mouse icon with a pipette plus
2596 wxSetCursor( cursor_pipette_plus );
2598 else if( mouse_icon_state != 1 )
2600 // Set the mouse icon with a simple pipette
2601 wxSetCursor( cursor_pipette_simple );
2603 event.Skip();
2607 //******************************************************
2609 void MyRemapViewerCtrl::EvtMouseEnter(wxMouseEvent& event)
2611 mouse_icon_state = 0;
2612 // Set the cursor
2613 EvtMouseMove(event);
2617 //******************************************************
2619 void MyRemapViewerCtrl::EvtMouseLeave(wxMouseEvent& event)
2621 // Restore the previous cursor
2622 wxSetCursor( wxNullCursor );
2626 //******************************************************
2627 //******************************************************
2628 //******************************************************
2629 BEGIN_EVENT_TABLE(MyRemapViewerCtrl, MyAnimationZone)
2630 EVT_PAINT(MyRemapViewerCtrl::OnPaint)
2631 EVT_MOTION(MyRemapViewerCtrl::EvtMouseMove)
2632 EVT_ENTER_WINDOW(MyRemapViewerCtrl::EvtMouseEnter)
2633 EVT_LEAVE_WINDOW(MyRemapViewerCtrl::EvtMouseLeave)
2634 END_EVENT_TABLE()
2637 //******************************************************
2638 //******************************************************
2639 //******************************************************
2640 //******************************************************
2642 MyPlatformViewerCtrl::MyPlatformViewerCtrl(wxWindow *_parent)
2643 :MyAnimationZone( _parent )
2645 #ifdef OSLINUX
2646 wxImage img_move( GetRessourceFile( wxT("cursor_move.png") ).GetFullPath() );
2647 #endif
2648 #ifdef OSWINDOW
2649 wxImage img_move( GetRessourceFile( wxT("cursor_move-win.png") ).GetFullPath() );
2650 #endif
2652 img_move.SetMaskColour( 130, 130, 130);
2653 img_move.SetMask();
2655 cursor_move = wxCursor( img_move );
2656 elt_dragged = PLAT_NONE;
2660 //******************************************************
2662 MyPlatformViewerCtrl::~MyPlatformViewerCtrl()
2667 //************************************************************************************
2669 void MyPlatformViewerCtrl::OnLeftButtonDown()
2671 //Check if it's near a draggable point
2672 int poff_x = StrToInt( panel_Platform->txtctrl_off_x->GetValue() );
2673 int poff_y = StrToInt( panel_Platform->txtctrl_off_y->GetValue() );
2674 int plr = StrToInt( panel_Platform->txtctrl_l_r->GetValue() );
2675 int pdl = StrToInt( panel_Platform->txtctrl_d_l->GetValue() );
2676 int pupr = StrToInt( panel_Platform->txtctrl_up_r->GetValue() );
2677 int pupl = StrToInt( panel_Platform->txtctrl_up_l->GetValue() );
2678 int pdepth = StrToInt( panel_Platform->txtctrl_depth->GetValue() );
2679 int palt = StrToInt( panel_Platform->txtctrl_alt->GetValue() );
2681 wxPoint d( poff_x, poff_y );
2682 wxPoint dl( d.x + pdl , d.y );
2683 wxPoint dr( d.x + plr , d.y );
2684 wxPoint u( d.x , d.y - palt);
2685 wxPoint ul( u.x +pupl , u.y );
2686 wxPoint ur( u.x +pupr , u.y );
2687 wxPoint depth_decal( pdepth * 0.5, pdepth * 0.866 );
2688 wxPoint dr_d( dr.x + depth_decal.x , dr.y - depth_decal.y);
2691 int max_dist = 3;
2693 if( abs(ul.x - r_x ) <= max_dist && abs( ul.y - r_y ) <= max_dist )
2695 r_x = StrToInt( panel_Platform->txtctrl_off_x->GetValue() );
2696 elt_dragged = PLAT_LU;
2698 else if( abs(ur.x - r_x ) <= max_dist && abs( ur.y - r_y ) <= max_dist )
2700 r_x = StrToInt( panel_Platform->txtctrl_off_x->GetValue() );
2701 elt_dragged = PLAT_RU;
2703 else if( abs(u.x - r_x ) <= max_dist && abs( u.y - r_y ) <= max_dist )
2705 r_y = StrToInt( panel_Platform->txtctrl_off_y->GetValue() );
2706 elt_dragged = PLAT_U;
2708 else if( abs(dr_d.x - r_x ) <= max_dist && abs( dr_d.y - r_y ) <= max_dist )
2710 r_x = StrToInt( panel_Platform->txtctrl_l_r->GetValue() ) + StrToInt( panel_Platform->txtctrl_off_x->GetValue() );
2711 elt_dragged = PLAT_DEPTH;
2713 else if( abs(dl.x - r_x ) <= max_dist && abs( dl.y - r_y ) <= max_dist )
2715 r_x = StrToInt( panel_Platform->txtctrl_off_x->GetValue() );
2716 elt_dragged = PLAT_LD;
2718 else if( abs(dr.x - r_x ) <= max_dist && abs( dr.y - r_y ) <= max_dist )
2720 r_x = StrToInt( panel_Platform->txtctrl_off_x->GetValue() );
2721 elt_dragged = PLAT_RD;
2723 else if( abs(d.x - r_x ) <= max_dist && abs(d.y - r_y ) <= max_dist )
2724 elt_dragged = PLAT_D;
2726 else
2727 elt_dragged = PLAT_NONE;
2729 if( elt_dragged != PLAT_NONE )
2731 SetCursor( cursor_move );
2733 else
2734 SetCursor( wxNullCursor );
2738 //************************************************************************************
2740 void MyPlatformViewerCtrl::OnEndLeftDragging()
2742 elt_dragged = PLAT_NONE;
2743 SetCursor( wxNullCursor );
2745 // Make the save into the ob_object
2746 panel_Platform->Update_entity_platform();
2750 //************************************************************************************
2752 void MyPlatformViewerCtrl::OnDragging()
2754 if( elt_dragged == PLAT_NONE )
2756 SetCursor( wxNullCursor );
2757 return;
2760 switch( elt_dragged )
2762 case PLAT_LD:
2764 panel_Platform->txtctrl_d_l->SetValue(IntToStr( r_w));
2765 break;
2767 case PLAT_RD:
2769 panel_Platform->txtctrl_l_r->SetValue(IntToStr(r_w));
2770 break;
2772 case PLAT_LU:
2774 panel_Platform->txtctrl_up_l->SetValue(IntToStr(r_w));
2775 break;
2777 case PLAT_RU:
2779 panel_Platform->txtctrl_up_r->SetValue(IntToStr(r_w));
2780 break;
2782 case PLAT_DEPTH:
2784 panel_Platform->txtctrl_depth->SetValue(IntToStr((int)(r_w * 2)));
2785 break;
2787 case PLAT_U:
2789 panel_Platform->txtctrl_alt->SetValue(IntToStr(-r_h));
2790 break;
2792 case PLAT_D:
2794 panel_Platform->txtctrl_off_x->SetValue(IntToStr(r_x+r_w));
2795 panel_Platform->txtctrl_off_y->SetValue(IntToStr(r_y+r_h));
2796 break;
2799 Refresh();
2803 //************************************************************************************
2805 void MyPlatformViewerCtrl::OnSimpleClick(wxMouseEvent& event)
2807 elt_dragged = PLAT_NONE;
2808 SetCursor( wxNullCursor );
2811 //************************************************************************************
2813 void MyPlatformViewerCtrl::OnPaint(wxPaintEvent& event)
2815 dc = new wxAutoBufferedPaintDC( this );
2816 MyAnimationZone::OnPaint( event );
2818 // If a platform is setted
2819 if( panel_Platform->chckbx_noplatform->GetValue() == false )
2821 brush.SetColour(panel_Platform->plat_color->GetColor() );
2822 dc->SetBrush(brush);
2823 pen.SetColour(panel_Platform->plat_color->GetColor());
2824 dc->SetPen(pen);
2826 int poff_x = StrToInt( panel_Platform->txtctrl_off_x->GetValue() );
2827 int poff_y = StrToInt( panel_Platform->txtctrl_off_y->GetValue() );
2828 int plr = StrToInt( panel_Platform->txtctrl_l_r->GetValue() );
2829 int pdl = StrToInt( panel_Platform->txtctrl_d_l->GetValue() );
2830 int pupr = StrToInt( panel_Platform->txtctrl_up_r->GetValue() );
2831 int pupl = StrToInt( panel_Platform->txtctrl_up_l->GetValue() );
2832 int pdepth = StrToInt( panel_Platform->txtctrl_depth->GetValue() );
2833 int palt = StrToInt( panel_Platform->txtctrl_alt->GetValue() );
2835 wxPoint d( dc_x + poff_x, dc_y + poff_y );
2836 wxPoint dl( d.x + pdl , d.y );
2837 wxPoint dr( d.x + plr , d.y );
2838 wxPoint u( d.x , d.y - palt);
2839 wxPoint ul( u.x +pupl , u.y );
2840 wxPoint ur( u.x +pupr , u.y );
2841 wxPoint depth_decal( pdepth * 0.5, pdepth * 0.866 );
2842 wxPoint ul_d( ul.x + depth_decal.x , ul.y - depth_decal.y);
2843 wxPoint ur_d( ur.x + depth_decal.x , ur.y - depth_decal.y);
2844 wxPoint dr_d( dr.x + depth_decal.x , dr.y - depth_decal.y);
2846 // First draw the Draggable Points
2847 int point_rayon = 2;
2848 myDrawCircle( dl.x,dl.y, point_rayon );
2849 myDrawCircle( d.x,d.y, point_rayon );
2850 myDrawCircle( dr.x,dr.y, point_rayon );
2851 myDrawCircle( ul.x,ul.y, point_rayon );
2852 myDrawCircle( u.x,u.y, point_rayon );
2853 myDrawCircle( ur.x,ur.y, point_rayon );
2854 myDrawCircle( dr_d.x,dr_d.y, point_rayon );
2856 // Now draw all these awfull lines
2857 myDrawLine( dl.x , dl.y, d.x , d.y );
2858 myDrawLine( d.x , dl.y, dr.x , d.y);
2859 myDrawLine( ul.x , ul.y, u.x , u.y );
2860 myDrawLine( u.x , u.y , ur.x , ur.y );
2861 myDrawLine( dl.x, dl.y , ul.x, ul.y );
2862 myDrawLine( dr.x, dr.y , ur.x, ur.y );
2863 myDrawLine( ul.x, ul.y , ul_d.x, ul_d.y );
2864 myDrawLine( ur.x, ur.y , ur_d.x, ur_d.y );
2865 myDrawLine( dr.x, dr.y , dr_d.x, dr_d.y );
2866 myDrawLine( ul_d.x, ul_d.y , ur_d.x, ur_d.y );
2867 myDrawLine( ur_d.x, ur_d.y , dr_d.x, dr_d.y );
2871 delete dc;
2875 //******************************************************
2876 //******************************************************
2877 //******************************************************
2878 BEGIN_EVENT_TABLE(MyPlatformViewerCtrl, MyAnimationZone)
2879 EVT_PAINT(MyPlatformViewerCtrl::OnPaint)
2880 END_EVENT_TABLE()