|
From: <ob...@us...> - 2007-10-06 14:43:29
|
Revision: 337
http://iaeditor.svn.sourceforge.net/iaeditor/?rev=337&view=rev
Author: obi666
Date: 2007-10-06 07:43:33 -0700 (Sat, 06 Oct 2007)
Log Message:
-----------
Cleaning in time-line control pixels<->units<->values conversions.
Modified Paths:
--------------
trunk/src/apps/editor/gui/gui_common.h
trunk/src/apps/editor/gui/widgets/iaSimulationPanel.cpp
trunk/src/apps/editor/gui/widgets/iaSimulationPanel.h
trunk/src/apps/editor/gui/widgets/iaTimeLineCtrl.cpp
trunk/src/apps/editor/gui/widgets/iaTimeLineCtrl.h
trunk/src/apps/editor/gui/widgets/iaTrackCtrl.cpp
Modified: trunk/src/apps/editor/gui/gui_common.h
===================================================================
--- trunk/src/apps/editor/gui/gui_common.h 2007-10-06 12:58:56 UTC (rev 336)
+++ trunk/src/apps/editor/gui/gui_common.h 2007-10-06 14:43:33 UTC (rev 337)
@@ -22,10 +22,6 @@
#include <wx/dnd.h>
#include "editor.h"
-#define TIMELINE_UNIT_POS 8 //position of first unit on timeline
-#define TIMELINE_UNIT_SCALE 100.0
-#define PROGRESS_2_UNITS(progress) (progress / TIMELINE_UNIT_SCALE) * TIMELINE_UNIT_POS
-#define UNITS_2_PROGRESS(units) units * TIMELINE_UNIT_SCALE / TIMELINE_UNIT_POS
#define BUTTON_SIZE 32
#define TIMELINE_OFFSET 7*BUTTON_SIZE
Modified: trunk/src/apps/editor/gui/widgets/iaSimulationPanel.cpp
===================================================================
--- trunk/src/apps/editor/gui/widgets/iaSimulationPanel.cpp 2007-10-06 12:58:56 UTC (rev 336)
+++ trunk/src/apps/editor/gui/widgets/iaSimulationPanel.cpp 2007-10-06 14:43:33 UTC (rev 337)
@@ -38,6 +38,8 @@
IMPLEMENT_DYNAMIC_CLASS(iaSimulationPanel, wxPanel)
+iaSimulationPanel *iaSimulationPanel::m_pInstance = 0;
+
iaSimulationPanel::iaSimulationPanel (iEditorCentralInfo *central_info, iaMainFrame* parent, wxWindowID id,
const wxPoint& pos, const wxSize& size, long style)
: wxPanel (parent, id, pos, size, style)
@@ -47,6 +49,7 @@
play_forward_pressed = false;
play_backward_pressed = false;
simulate_pressed = false;
+ m_pInstance = this;
SetMinSize (wxSize (BUTTON_SIZE, BUTTON_SIZE));
}
void iaSimulationPanel::OnSize (wxSizeEvent& event)
Modified: trunk/src/apps/editor/gui/widgets/iaSimulationPanel.h
===================================================================
--- trunk/src/apps/editor/gui/widgets/iaSimulationPanel.h 2007-10-06 12:58:56 UTC (rev 336)
+++ trunk/src/apps/editor/gui/widgets/iaSimulationPanel.h 2007-10-06 14:43:33 UTC (rev 337)
@@ -52,6 +52,7 @@
};
void CreateControls ();
+ iaTimeLineCtrl *GetTimeLineCtrl () {return time_line_ctrl;}
//events
void OnLastFrameClick (wxCommandEvent& event);
@@ -63,6 +64,9 @@
void OnStepBackwardClick (wxCommandEvent& event);
void OnSize (wxSizeEvent& event);
+ /// singleton instance access
+ static iaSimulationPanel* instance () {return m_pInstance;}
+
DECLARE_DYNAMIC_CLASS(iaSimulationPanel)
private:
@@ -71,6 +75,7 @@
iaSimulationTracksCtrl *tracks_ctrl;
iEditorCentralInfo *central_info;
iaMainFrame *parent;
+ static iaSimulationPanel *m_pInstance;
//Buttons
wxBitmapButton *item_bitmap_button_step_forward;
Modified: trunk/src/apps/editor/gui/widgets/iaTimeLineCtrl.cpp
===================================================================
--- trunk/src/apps/editor/gui/widgets/iaTimeLineCtrl.cpp 2007-10-06 12:58:56 UTC (rev 336)
+++ trunk/src/apps/editor/gui/widgets/iaTimeLineCtrl.cpp 2007-10-06 14:43:33 UTC (rev 337)
@@ -76,7 +76,7 @@
timeline_anim_ptr_pos = 0;
timeline_sim_ptr_pos = 0;
unit_size = 8;
- unit_value = 1;
+ unit_value = 100;
}
iaTimeLineCtrl::~iaTimeLineCtrl()
@@ -97,10 +97,6 @@
PrepareDC (pdc);
DrawToDC (&pdc);
}
-int iaTimeLineCtrl::ScaleProgress (csTicks progress)
-{
- return (progress / TIMELINE_UNIT_SCALE) * TIMELINE_UNIT_POS;
-}
void iaTimeLineCtrl::SimulationStarted ()
{
timeline_sim_ptr_pos = 0;
@@ -109,7 +105,7 @@
void iaTimeLineCtrl::SimulatorProgressChanged (csTicks progress)
{
int prev_pos = timeline_sim_ptr_pos;
- timeline_sim_ptr_pos = ScaleProgress (progress);
+ timeline_sim_ptr_pos = GetUnitPos (GetUnit (progress));
if (prev_pos == timeline_sim_ptr_pos)
return;
@@ -131,11 +127,11 @@
for (int i = 0; i < b_cnt; i++)
{
int curr_scale = i * 10;
- int curr_scale_pos = GetScalePos (curr_scale);
+ int curr_scale_pos = GetUnitPos (curr_scale);
memdc.DrawRectangle (curr_scale_pos, GetSize ().y - 18, 2, 18);
for (size_t i = 0; i < 10; i++)
{
- memdc.DrawRectangle (GetScalePos (curr_scale++), GetSize ().y - 5, 2, 5);
+ memdc.DrawRectangle (GetUnitPos (curr_scale++), GetSize ().y - 5, 2, 5);
}
}
memdc.DrawBitmap (timeline_ptr_bitmap, timeline_anim_ptr_pos,
@@ -149,16 +145,20 @@
for (int i = 0; i < b_cnt; i++)
{
wxString label;
- label.sprintf ("%d", GetScaleValue (i * 10));
- memdc.DrawText (label, GetScalePos (i * 10) - timeline_font->GetPointSize () * label.Length () / 2 -
+ label.sprintf ("%d", GetUnitValue (i * 10));
+ memdc.DrawText (label, GetUnitPos (i * 10) - timeline_font->GetPointSize () * label.Length () / 2 -
timeline_font->GetPointSize () / 4, 0);
}
memdc.SelectObject (wxNullBitmap);
dc->DrawBitmap (dummy_bitmap, 0, 0);
}
-int iaTimeLineCtrl::GetScalePos (int i)
+int iaTimeLineCtrl::GetPosValue (int pos)
{
+ return (pos - TIMELINE_START) / unit_size * unit_value;
+}
+int iaTimeLineCtrl::GetUnitPos (int i)
+{
return TIMELINE_START + i * unit_size;
}
void iaTimeLineCtrl::AnimationLockChanged (bool lock)
@@ -173,7 +173,7 @@
void iaTimeLineCtrl::AnimationProgressChanged (csTicks progress)
{
int prev_pos = timeline_anim_ptr_pos;
- timeline_anim_ptr_pos = ScaleProgress (progress);
+ timeline_anim_ptr_pos = GetUnitPos (GetUnit (progress));
if (prev_pos == timeline_anim_ptr_pos)
return;
wxClientDC cdc (this);
Modified: trunk/src/apps/editor/gui/widgets/iaTimeLineCtrl.h
===================================================================
--- trunk/src/apps/editor/gui/widgets/iaTimeLineCtrl.h 2007-10-06 12:58:56 UTC (rev 336)
+++ trunk/src/apps/editor/gui/widgets/iaTimeLineCtrl.h 2007-10-06 14:43:33 UTC (rev 337)
@@ -22,6 +22,7 @@
struct iEditorCentralInfo;
#include "ia-tool/iaBaseObjectListener.h"
+#include "iPcDynamicsSystem.h"
// When drag_count reaches 0, process drag message
@@ -60,11 +61,14 @@
// Events
void OnPaint (wxPaintEvent& event);
+ int GetProgressSize (int progress) {return GetUnit (progress) * unit_size;}
+ int GetPosValue (int pos);
+
protected:
- int ScaleProgress (csTicks progress);
- int GetScaleValue (int i) {return i * unit_value;}
- int GetScalePos (int i);
+ int GetUnitPos (int i);
+ int GetUnit (int value) {return value / unit_value;}
+ int GetUnitValue (int i) {return i * unit_value;}
iEditorCentralInfo *central_info;
wxFont *timeline_font;
Modified: trunk/src/apps/editor/gui/widgets/iaTrackCtrl.cpp
===================================================================
--- trunk/src/apps/editor/gui/widgets/iaTrackCtrl.cpp 2007-10-06 12:58:56 UTC (rev 336)
+++ trunk/src/apps/editor/gui/widgets/iaTrackCtrl.cpp 2007-10-06 14:43:33 UTC (rev 337)
@@ -43,6 +43,8 @@
#include <wx/dcgraph.h>
#include "../gui_common.h"
#include "iaTrackCtrl.h"
+#include "iaTimeLineCtrl.h"
+#include "iaSimulationPanel.h"
#include "iPcCharacter.h"
#include "iPcAnimation.h"
@@ -74,7 +76,6 @@
{
iaEventCtrl::central_info = central_info;
iaEventCtrl::track_event = track_event;
- SetSize(PROGRESS_2_UNITS(track_event->GetDuration ()), size.y);
}
iaEventCtrl::~iaEventCtrl()
@@ -83,8 +84,9 @@
void iaEventCtrl::OnSize (wxSizeEvent& event)
{
central_info->Get3dView ()->Lock (true);
- csTicks duration = UNITS_2_PROGRESS (event.GetSize ().x);
- csTicks start = UNITS_2_PROGRESS (GetPosition ().x);
+ iaTimeLineCtrl *timelineCtrl = iaSimulationPanel::instance ()->GetTimeLineCtrl ();
+ csTicks duration = timelineCtrl->GetPosValue (event.GetSize ().x);
+ csTicks start = timelineCtrl->GetPosValue (GetPosition ().x);
track_event->SetDuration (duration);
track_event->SetStart (start);
@@ -196,12 +198,14 @@
void iaTrackCtrl::PutObject (iEditorObject *obj, wxCoord x, wxCoord y)
{
central_info->Get3dView ()->Lock (true);
+ iaTimeLineCtrl *timeLineCtrl = iaSimulationPanel::instance ()->GetTimeLineCtrl ();
- csTicks start = UNITS_2_PROGRESS (x);
+ csTicks start = timeLineCtrl->GetPosValue (x);
iTrackEvent *event = track->PutOnTrack (obj);
event->SetStart (start);
iaEventCtrl *event_ctrl = new iaEventCtrl (central_info, event, this, -1,
- wxPoint (x, 0), wxSize (0, GetSize ().y));
+ wxPoint (x, 0), wxSize (timeLineCtrl->GetProgressSize (event->GetDuration ()), GetSize ().y));
+
switch (obj->GetObjectType ())
{
case IA_OBJECT_TYPE_ANIMATION:
@@ -274,7 +278,7 @@
void iaCharacterTracksCtrl::Expand ()
{
collapsed = false;
- SetSize (GetSize ().x, (1 + tracks.GetSize ()) * (size_t)track_size);
+ SetSize (GetSize ().x, (int) ((1 + tracks.GetSize ()) * track_size));
for (size_t i = 0; i < tracks.GetSize (); i++)
{
tracks[i]->Show (true);
@@ -283,10 +287,10 @@
void iaCharacterTracksCtrl::AddTrack (const wxColor& color, iTrack *track)
{
iaTrackCtrl *track_ctrl = new iaTrackCtrl (central_info, track,
- this, -1, wxPoint (0, (tracks.GetSize () + 1) * track_size), wxSize (GetSize ().x, track_size));
+ this, -1, wxPoint (0, (int) ((tracks.GetSize () + 1) * track_size)), wxSize (GetSize ().x, track_size));
track_ctrl->SetBackgroundColour (color);
tracks.Push (track_ctrl);
- SetSize (GetSize ().x, (tracks.GetSize () + 1) * track_size);
+ SetSize (GetSize ().x, (int) ((tracks.GetSize () + 1) * track_size));
}
bool iaCharacterTracksCtrl::CreateControls (int track_size)
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|