4 * Created on: 7 nov. 2008
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
);
26 #define JUMP_HALF_TIME 20
27 #define JUMP_ANIM_STEP 4
31 //***************************************
32 //***************************************
33 //***************************************
34 //***************************************
36 wxColour
ob_pink(255,0,255);
37 wxColour
MyAnimationZone::orig_bg(0,0,0);
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
;
71 //***************************************
72 //***************************************
73 //***************************************
75 MyAnimationZone::MyAnimationZone(wxWindow
*parent
)
76 : wxControl(parent
, wxID_ANY
77 , wxDefaultPosition
, wxDefaultSize
78 , wxVSCROLL
| wxHSCROLL
81 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
86 SetToolTip( wxString() );
87 theTip
= GetToolTip();
88 theTip
->SetDelay( 200 );
89 theTip
->Enable( false );
95 fr_total_decal_Xs
= NULL
;
96 fr_total_decal_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
;
113 fr_jump_timer
= NULL
;
114 fr_jump_stairs
= NULL
;
117 // Bunch of var for animate the jump
119 jump_decal_x
= jump_decal_z
= jump_decal_alt
= 0;
121 jump_last_delay
= jump_time_counter
= 0;
122 draw_jump_step
= false;
131 mouse_draw
= DRAW_NOTHING
;
133 b_rightmouseD
= false;
137 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
140 MyAnimationZone::~MyAnimationZone()
145 //******************************************************
147 int MyAnimationZone::H()const
154 int MyAnimationZone::W()const
161 int MyAnimationZone::X()const
164 GetPosition(&mx
,&my
);
168 int MyAnimationZone::Y()const
171 GetPosition(&mx
,&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 //-------------------------------------------------------------------------------
186 MyAnimationZone::pGetClientSize( int* w
,int* h
)
190 if( GetScrollRange(wxHORIZONTAL
) > 0 )
191 h
-= wxSystemSettings::GetMetric( wxSYS_HSCROLL_Y
);
192 if( GetScrollRange(wxVERTICAL
) > 0 )
193 w
-= wxSystemSettings::GetMetric( wxSYS_HSCROLL_X
);
197 //-------------------------------------------------------------------------------
199 MyAnimationZone::Zoom(float _factor
, bool b_exact_factor
, bool b_recalc_size
)
201 if( _factor
<= 0 || m_flag
& M_ZOOMING
)
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
;
217 zoom_factor
= zoom_factor
*_factor
;
219 // If so, recalc size
220 if( b_recalc_size
== true );
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);
230 SetScrollbar( wxHORIZONTAL
, sp_x
,w
,total_W
*zoom_factor
);
232 if( total_H
*zoom_factor
< h
)
233 SetScrollbar( wxVERTICAL
, 0,0,0);
235 SetScrollbar( wxVERTICAL
, sp_y
,h
,total_H
*zoom_factor
);
238 // Must rethink the stuff if scroll bar appears
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 );
250 m_flag
&= ~M_ZOOMING
;
253 void MyAnimationZone::ResetZoom()
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") );
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() )
288 if( curr_anim
->GetToken(0).Left(4).Upper() == wxT("FALL") )
290 else if( curr_anim
->GetToken(0).Left(4).Upper() == wxT("JUMP") )
294 ob_object
*dropframe_prop
= curr_anim
->GetSubObject( wxT("dropframe") );
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") );
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;
308 int jump_duration
= 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
)
320 if( curr_frames
[i
]->dropState
> 0 && ! in_drop
)
322 if( curr_frames
[i
]->landState
> 0 && ! in_land
)
325 know_delay
= DGET_DELAY(curr_frames
[i
]);
326 if( know_delay
<= 0 )
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 )
339 wxMessageBox( wxT("Drop frame at position ZERO !!!"), wxT("ProPlem"), wxOK
| wxICON_INFORMATION
, this );
340 fr_delays
[i
] = know_delay
;
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
360 int over_time
= jump_duration
- JUMP_HALF_TIME
;
363 for( j
= i
-1; j
>= 0; j
--)
365 over_time
-= fr_delays
[j
];
367 // We got the last frame before the apex
370 fr_delays
[j
] = - over_time
;
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
++ )
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
;
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
)
406 wxMessageBox( wxT("Land frame at position ZERO !!!"), wxT("ProPlem"), wxOK
| wxICON_INFORMATION
, this );
407 fr_delays
[i
] = know_delay
;
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
;
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
432 int over_time
= jump_duration
- 2 * JUMP_HALF_TIME
;
435 for( j
= i
-1; j
>= 0; j
--)
437 over_time
-= fr_delays
[j
];
439 // We got the last frame before the ground
442 fr_delays
[j
] = - over_time
;
447 // Set the drop frame data
448 if( fr_delays
[j
] <= JUMP_HALF_TIME
)
449 fr_jumph
[i
] = - fr_delays
[j
] * jump_speedh
;
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
++ )
469 curr_jumph
= 0; //jump_speedh * JUMP_HALF_TIME;
470 jump_duration
= 2 * JUMP_HALF_TIME
;
471 curr_frames
[i
]->end_jump
= true;
475 // at the ground -> no jump influence
476 else if( in_land
|| ! in_jump
)
478 fr_delays
[i
] = know_delay
;
482 if( curr_frames
[i
]->jumpState
!= 2 )
483 curr_frames
[i
]->end_jump
= true;
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
;
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
;
507 // Special case : apex passed and directly to ground
508 else if( jump_duration
>= 2 * JUMP_HALF_TIME
)
510 fr_delays
[i
] = know_delay
;
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
;
526 curr_frames
[i
]->end_jump
= true;
532 fr_delays
[i
] = know_delay
;
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
;
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
;
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
;
568 curr_frames
[i
]->end_jump
= true;
574 fr_delays
[i
] = know_delay
;
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
;
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];
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
)
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
;
625 fr_jump_stairs
[i
].nb_step
= 0;
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
;
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
++)
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
;
651 else if( time_elapsed
< JUMP_HALF_TIME
)
652 fr_jump_stairs
[i
].steps
[j
].mv_h
= JUMP_ANIM_STEP
* jump_speedh
;
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
;
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
;
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()
692 if( fr_decal_Xs
!= NULL
)
693 delete[] fr_decal_Xs
;
695 if( fr_decal_Ys
!= NULL
)
696 delete[] fr_decal_Ys
;
701 if( 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
;
715 if( fr_offset_Ys
!= NULL
)
716 delete[] fr_offset_Ys
;
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
)
751 if( fr_jumph
!= NULL
)
754 if( fr_jumpx
!= NULL
)
757 if( 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
)
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
;
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;
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") );
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") )
839 else if( curr_anim
->GetToken(0).Left(4).Upper() == wxT("JUMP") )
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();
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 )
876 fr_jumpx
[i
] = - fr_jumpx
[i
];
877 original_offsetX
= img_w
- offsetX
;
878 offsetX
= original_offsetX
;
882 // Apply drawmethod transformations
883 if( curr_frames
[i
]->GetSubObject( wxT("nodrawmethod") ) == NULL
884 && curr_frames
[i
]->GetSubObject( wxT("drawmethod")) != NULL
)
888 int _scaleX
= DGET_DMVAL(drawMethod
,_i
);
890 int _scaleY
= DGET_DMVAL(drawMethod
,_i
);
892 int _flipX
= DGET_DMVAL(drawMethod
,_i
);
894 int _flipY
= DGET_DMVAL(drawMethod
,_i
);
896 int _rotate
= DGET_DMVAL(drawMethod
,_i
);
898 bool _fliprotate
= (DGET_DMVAL(drawMethod
,_i
) != 0);
903 float _dm_scaleX
= ((float) _scaleX
/ (float) 256 );
904 offsetX
*= _dm_scaleX
;
909 offsetX
= img_w
+ offsetX
;
914 float _dm_scaleY
= ((float) _scaleY
/ (float) 256 );
915 offsetY
*= _dm_scaleY
;
920 offsetY
= img_h
+ offsetY
;
925 offsetX
= img_w
- offsetX
;
929 offsetY
= img_h
- offsetY
;
932 fr_rotate_imgw
[i
] = img_w
;
933 fr_rotate_imgh
[i
] = img_h
;
938 if( b_flipped
&& _fliprotate
)
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
);
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;
965 int tot_movea
= - movea
;
966 int tot_movez
= movez
;
967 int tot_movex
= movex
;
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
976 // This one have no delay -> no implications
977 if( fr_delays
[i
] == 0 )
979 fr_As
[i
] = fr_As
[i
-1];
985 fr_jump_stairs
[i
].mv_x
= 0;
986 fr_jump_stairs
[i
].mv_z
= 0;
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];
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
;
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
;
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 );
1097 //******************************************************
1098 enum { MYALL
, MYRIGHT
, MYLEFT
};
1100 void MyAnimationZone::UpdateFrames()
1106 //******************************************************
1108 wxSize
MyAnimationZone::DoGetBestSize() const
1110 return GetContainingSizer()->GetSize();
1114 void MyAnimationZone::Clear()
1116 if( theBitmap
!= NULL
)
1120 if( fr_decal_Xs
!= NULL
)
1121 delete[] fr_decal_Xs
;
1124 if( fr_decal_Ys
!= NULL
)
1125 delete[] fr_decal_Ys
;
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
)
1177 if( fr_jumph
!= NULL
)
1181 if( fr_jumpx
!= NULL
)
1185 if( 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
);
1200 m_flag
&= ~M_PAINTING
;
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
)
1219 // Gather information about the frame currently drawn
1220 // Getting the indice of the frame
1221 int _ind
= ind_active_frame
;
1224 if( _ind
>= curr_frames_count
)
1227 wxImage
*fr_img
= curr_frames
[_ind
]->GetImage();
1228 if( fr_img
== NULL
)
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 )
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
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 )
1269 theTip
->SetTip( tip_txt
);
1270 theTip
->Enable(true);
1274 if( event
.IsButton() == true )
1275 theTip
->Enable(false);
1278 if( event
.ButtonUp() )
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 )
1287 TO_x
+= + curr_frames
[_ind
]->move
;
1288 TO_a
= fr_offset_Ys
[_ind
] - my
+ curr_frames
[_ind
]->moveA
;
1290 ReverseDMCoord( mx
, my
);
1297 mouse_draw
= DRAW_AIM
;
1298 OnSimpleClick(event
);
1325 // More work with the offsets due To DM
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();
1342 if( event
.ButtonDown() || event
.RightDown() )
1350 mouse_draw
= DRAW_NOTHING
;
1354 if( event
.ButtonDown() )
1357 b_rightmouseD
= false;
1366 if( event.RightDown() )
1369 b_rightmouseD = true;
1377 if( event
.Dragging() && event
.m_leftDown
)
1381 mouse_draw
= DRAW_RECT
;
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()
1423 mouse_draw
= DRAW_NOTHING
;
1427 //******************************************************
1429 void MyAnimationZone::OnEraseBackground(wxEraseEvent
& event
)
1434 //******************************************************
1436 void MyAnimationZone::RePaint()
1441 //******************************************************
1443 void MyAnimationZone::Draw_NoImg()
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
) );
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;
1491 dc
->SetTextBackground( wxNullColour
);
1492 dc
->SetTextForeground( dc
->GetPen().GetColour() );
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
);
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;
1522 dc
= new wxAutoBufferedPaintDC( this );
1526 m_flag
&= ~M_PAINTING
;
1532 orig_bg
= GetBackgroundColour();
1534 // RePaint All the background SETED
1538 brush
.SetColour(orig_bg
);
1548 // dc->SetBrush(brush);
1549 dc
->SetBackground(orig_bg
);
1552 // dc->DrawRectangle( 0, 0, _w, _h );
1555 if( curr_frames
!= NULL
&& curr_anim
!= NULL
&& fr_total_decal_Xs
!= NULL
)
1557 ind_frPainted
= GetIndFrameToPaint();
1558 if( ind_frPainted
< 0 )
1560 if( ind_frPainted
>= curr_frames_count
)
1568 m_flag
&= ~M_PAINTING
;
1572 // Original image size
1576 // image size after draw method application
1580 // if the frame is a flipped one (with flipframe prop)
1583 wxImage
*orig_fr_img
= curr_frames
[ind_frPainted
]->GetImage();
1585 if( orig_fr_img
== NULL
)
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 )
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)
1619 int _scaleX
= DGET_DMVAL2(_i
);
1621 int _scaleY
= DGET_DMVAL2(_i
);
1623 bool _flipx
= (DGET_DMVAL2(_i
)!=0);
1625 bool _flipy
= (DGET_DMVAL2(_i
)!=0);
1627 // int _shiftx = curr_frames[ind_frPainted]->drawMethod[_i];
1629 // int _alpha = curr_frames[ind_frPainted]->drawMethod[_i]
1631 // int _remap = curr_frames[ind_frPainted]->drawMethod[_i]
1633 // int _fillcolor = curr_frames[ind_frPainted]->drawMethod[_i]
1635 int _rotate
= DGET_DMVAL2(_i
);
1637 bool _fliprotate
=(DGET_DMVAL2(_i
)!=0);
1641 fr_img
= fr_img
.Mirror( true );
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;
1653 fr_img
= fr_img
.Mirror( true );
1654 _scaleX
= - _scaleX
;
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
));
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
])
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
)
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;
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;
1705 decal_y
= - GetScrollPos(wxVERTICAL
);
1708 // Paint the borders of the background
1709 brush
.SetColour(*wxBLACK
);
1710 dc
->SetBrush(brush
);
1711 pen
.SetColour( *wxBLACK
);
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
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 //******************************************
1732 //******************************************
1733 if( ! draw_jump_step
)
1734 dc
->DrawBitmap( *theBitmap
, prev_frame_rect_x
, prev_frame_rect_y
, true );
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
,
1743 // curr_frames == NULL
1749 m_flag
&= ~M_PAINTING
;
1758 //******************************************************
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
)
1778 Zoom(zoom_factor
, true, false );
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
;
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
)
1816 int _scaleX
= curr_frames
[ind
]->drawMethod
[_i
];
1818 int _scaleY
= curr_frames
[ind
]->drawMethod
[_i
];
1820 bool _flipx
= (curr_frames
[ind
]->drawMethod
[_i
]!=0);
1822 bool _flipy
= (curr_frames
[ind
]->drawMethod
[_i
]!=0);
1824 // int _fillcolor = curr_frames[ind]->drawMethod[_i];
1826 int _rotate
= curr_frames
[ind
]->drawMethod
[_i
];
1828 bool _fliprotate
= (curr_frames
[ind
]->drawMethod
[_i
]!=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
;
1850 _mx
= fr_rotate_imgw
[ind
] - _mx
;
1854 _my
= fr_rotate_imgh
[ind
] - _my
;
1858 _mx
= fr_rotate_imgw
[ind
] - _mx
;
1859 _scaleX
= - _scaleX
;
1863 _my
= fr_rotate_imgh
[ind
] - _my
;
1864 _scaleY
= - _scaleY
;
1870 float _factor
= (float)256 / (float)_scaleX
;
1875 float _factor
= (float)256 / (float)_scaleY
;
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
);
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
;
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
;
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
);
1923 //---------------------------------------------------------------
1925 MyAnimationZone::Evt_Scroll( wxScrollWinEvent
& evt
)
1927 SetScrollPos( evt
.GetOrientation(), evt
.GetPosition() );
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
)
1947 //******************************************************
1948 //******************************************************
1949 //******************************************************
1951 MyAnimationCtrl::MyAnimationCtrl( wxWindow
*_parent
)
1952 : MyAnimationZone( _parent
), anim_timer(this,TIMER_ANIM
)
1957 inStopPlaying
= false;
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
1985 MyAnimationZone::UpdateFrames();
1989 //******************************************************
1991 void MyAnimationCtrl::UpdateNavigation()
1993 // Update navigation buttons
1994 if( curr_frames
== NULL
)
1996 panel_Anims
->EnableNavigation( MYALL
, false );
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 );
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()
2018 curr_played
= first_to_play
;
2021 else if( curr_frames_count
<= 0 )
2026 panel_Anims
->butt_Play
->SetBitmapLabel( wxBitmap( wxImage( GetRessourceFile_String(wxT("stop.png")))));
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
);
2040 void MyAnimationCtrl::StopPlaying()
2044 inStopPlaying
= true;
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
);
2057 jump_last_delay
= jump_time_counter
= 0;
2058 draw_jump_step
= false;
2064 inStopPlaying
= false;
2068 //******************************************************
2070 void MyAnimationCtrl::Clear()
2072 MyAnimationZone::Clear();
2074 inStopPlaying
= false;
2077 //******************************************************
2079 void MyAnimationCtrl::EvtMouseSomething(wxMouseEvent
& event
)
2081 // No such things during animation
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;
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
++;
2155 draw_jump_step
= true;
2161 fr_jump_stairs
[curr_played
].curr_step
= 0;
2165 while( k
<= curr_frames_count
)
2168 if( curr_played
> last_to_play
)
2170 if( b_looping
== false )
2176 curr_played
= first_to_play
;
2178 if( fr_delays
[curr_played
] > 0 )
2183 if( k
> curr_frames_count
|| curr_played
< 0 || curr_played
>= curr_frames_count
)
2190 if( curr_frames
[curr_played
]->end_jump
)
2194 else if( curr_frames
[curr_played
]->jumpState
> 0 )
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 );
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
);
2227 //******************************************************
2229 void MyAnimationCtrl::PlayUpdate()
2231 if( curr_frames
== NULL
)
2234 // Set the curr_played frame
2235 panel_Anims
->wList_frames
->SetSelected( curr_played
, false, false );
2238 int delay
= fr_delays
[curr_played
];
2239 if( delay
< 2 ) delay
= 2;
2240 anim_timer
.Start(delay
*10);
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()
2272 brush
.SetColour(orig_bg
);
2273 pen
.SetColour(orig_bg
);
2277 brush
.SetColour(ob_pink
);
2278 pen
.SetColour(ob_pink
);
2280 dc
->SetBrush(brush
);
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));
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));
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 //******************************************
2322 // Draw the Offset cross
2323 pen
.SetColour( wxColour(0,0,0));
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));
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 )
2358 bbox_x
= original_img_w
[ind_frPainted
] - bbox_x
- bbox_w
;
2360 pen
.SetColour( panel_Anims
->bbox_color
->GetColor() );
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
2372 pen
.SetColour( panel_Anims
->att_color
->GetColor() );
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 )
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
]
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));
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
);
2420 m_flag
&= ~M_PAINTING
;
2424 //******************************************************
2426 int MyAnimationCtrl::GetIndFrameToPaint()
2429 return ind_active_frame
;
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
)
2447 //******************************************************
2448 //******************************************************
2449 //******************************************************
2450 //******************************************************
2452 MyRemapViewerCtrl::MyRemapViewerCtrl(wxWindow
*_parent
)
2453 :MyAnimationZone( _parent
)
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() ) );
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() ) );
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()
2482 //******************************************************
2484 void MyRemapViewerCtrl::PreProcessImage( wxImage
& fr_img
)
2486 if( panel_Remaps
->paletteCtrl
== NULL
|| ! panel_Remaps
->paletteCtrl
->b_init
)
2489 int palette_count
= panel_Remaps
->paletteCtrl
->thePalette
->GetColoursCount();
2490 if( palette_count
<= 0 )
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
] );
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
] );
2522 panel_Remaps
->paletteCtrl
->paletteElements
[i
]->GetRGB( &n_r
[i
], &n_g
[i
], &n_b
[i
] );
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
] )
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
];
2556 //******************************************************
2558 void MyRemapViewerCtrl::OnSimpleClick(wxMouseEvent
& event
)
2560 if( panel_Remaps
->paletteCtrl
== NULL
|| curr_frames
== NULL
|| ind_active_frame
< 0 )
2563 if( curr_frames
[ind_active_frame
]->GetImage() == noImg
)
2566 //Get the index of the color under the mouse
2567 int ind
= curr_frames
[ind_active_frame
]->Get_ColorIndex(TO_offx
, TO_offy
);
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
);
2587 //******************************************************
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
);
2607 //******************************************************
2609 void MyRemapViewerCtrl::EvtMouseEnter(wxMouseEvent
& event
)
2611 mouse_icon_state
= 0;
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
)
2637 //******************************************************
2638 //******************************************************
2639 //******************************************************
2640 //******************************************************
2642 MyPlatformViewerCtrl::MyPlatformViewerCtrl(wxWindow
*_parent
)
2643 :MyAnimationZone( _parent
)
2646 wxImage
img_move( GetRessourceFile( wxT("cursor_move.png") ).GetFullPath() );
2649 wxImage
img_move( GetRessourceFile( wxT("cursor_move-win.png") ).GetFullPath() );
2652 img_move
.SetMaskColour( 130, 130, 130);
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
);
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
;
2727 elt_dragged
= PLAT_NONE
;
2729 if( elt_dragged
!= PLAT_NONE
)
2731 SetCursor( cursor_move
);
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
);
2760 switch( elt_dragged
)
2764 panel_Platform
->txtctrl_d_l
->SetValue(IntToStr( r_w
));
2769 panel_Platform
->txtctrl_l_r
->SetValue(IntToStr(r_w
));
2774 panel_Platform
->txtctrl_up_l
->SetValue(IntToStr(r_w
));
2779 panel_Platform
->txtctrl_up_r
->SetValue(IntToStr(r_w
));
2784 panel_Platform
->txtctrl_depth
->SetValue(IntToStr((int)(r_w
* 2)));
2789 panel_Platform
->txtctrl_alt
->SetValue(IntToStr(-r_h
));
2794 panel_Platform
->txtctrl_off_x
->SetValue(IntToStr(r_x
+r_w
));
2795 panel_Platform
->txtctrl_off_y
->SetValue(IntToStr(r_y
+r_h
));
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());
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
);
2875 //******************************************************
2876 //******************************************************
2877 //******************************************************
2878 BEGIN_EVENT_TABLE(MyPlatformViewerCtrl
, MyAnimationZone
)
2879 EVT_PAINT(MyPlatformViewerCtrl::OnPaint
)