00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "xrb_engine2_worldviewwidget.hpp"
00012
00013 #include "xrb_engine2_world.hpp"
00014 #include "xrb_engine2_worldview.hpp"
00015
00016 namespace Xrb
00017 {
00018
00019 Engine2::WorldViewWidget::WorldViewWidget (
00020 ContainerWidget *const parent,
00021 std::string const &name)
00022 :
00023 Widget(parent, name)
00024 {
00025 ASSERT1(parent != NULL);
00026
00027 m_transform = FloatSimpleTransform2::ms_identity;
00028 m_is_transform_scaling_based_upon_widget_radius = false;
00029
00030 m_draw_focus_frame = true;
00031 m_accepts_focus = true;
00032
00033 m_world_view = NULL;
00034
00035
00036 ComputeTransform();
00037
00038 SetBackground(NULL);
00039 }
00040
00041 Engine2::WorldViewWidget::~WorldViewWidget ()
00042 {
00043 if (m_world_view != NULL)
00044 {
00045 m_world_view->DetachFromWorld();
00046 ASSERT1(m_world_view->GetWorld() == NULL);
00047 }
00048 Delete(m_world_view);
00049 }
00050
00051 void Engine2::WorldViewWidget::SetWorldView (Engine2::WorldView *const world_view)
00052 {
00053
00054 if (m_world_view == world_view)
00055 return;
00056
00057 if (m_world_view != NULL)
00058 {
00059 m_world_view->DetachFromWorld();
00060 ASSERT1(m_world_view->GetWorld() == NULL);
00061 }
00062 Delete(m_world_view);
00063 m_world_view = world_view;
00064 SetIsTransformScalingBasedUponWidgetRadius(m_world_view->IsTransformScalingBasedUponWidgetRadius());
00065 }
00066
00067 void Engine2::WorldViewWidget::SetIsTransformScalingBasedUponWidgetRadius (bool const is_transform_scaling_based_upon_widget_radius)
00068 {
00069 if (m_is_transform_scaling_based_upon_widget_radius != is_transform_scaling_based_upon_widget_radius)
00070 {
00071 m_is_transform_scaling_based_upon_widget_radius = is_transform_scaling_based_upon_widget_radius;
00072 if (m_world_view != NULL)
00073 m_world_view->SetIsTransformScalingBasedUponWidgetRadius(m_is_transform_scaling_based_upon_widget_radius);
00074 ComputeTransform();
00075 }
00076 }
00077
00078 void Engine2::WorldViewWidget::Draw (RenderContext const &render_context) const
00079 {
00080
00081 if (m_world_view != NULL)
00082 m_world_view->Draw(render_context);
00083
00084
00085
00086 Widget::Draw(render_context);
00087
00088
00089 DrawFocusFrame(render_context);
00090 }
00091
00092 void Engine2::WorldViewWidget::HandleFrame ()
00093 {
00094
00095 if (m_world_view != NULL)
00096 m_world_view->ProcessFrame(FrameTime());
00097 }
00098
00099 void Engine2::WorldViewWidget::MoveBy (ScreenCoordVector2 const &delta)
00100 {
00101 Widget::MoveBy(delta);
00102 ComputeTransform();
00103 }
00104
00105 ScreenCoordVector2 Engine2::WorldViewWidget::Resize (ScreenCoordVector2 const &size)
00106 {
00107 Widget::Resize(size);
00108 ComputeTransform();
00109 return Size();
00110 }
00111
00112 bool Engine2::WorldViewWidget::ProcessKeyEvent (EventKey const *const e)
00113 {
00114 if (m_world_view != NULL)
00115 return m_world_view->ProcessKeyEvent(e);
00116 else
00117 return false;
00118 }
00119
00120 bool Engine2::WorldViewWidget::ProcessMouseButtonEvent (EventMouseButton const *const e)
00121 {
00122 if (m_world_view != NULL)
00123 return m_world_view->ProcessMouseButtonEvent(e);
00124 else
00125 return false;
00126 }
00127
00128 bool Engine2::WorldViewWidget::ProcessMouseWheelEvent (EventMouseWheel const *const e)
00129 {
00130 if (m_world_view != NULL)
00131 return m_world_view->ProcessMouseWheelEvent(e);
00132 else
00133 return false;
00134 }
00135
00136 bool Engine2::WorldViewWidget::ProcessMouseMotionEvent (EventMouseMotion const *const e)
00137 {
00138 if (m_world_view != NULL)
00139 return m_world_view->ProcessMouseMotionEvent(e);
00140 else
00141 return false;
00142 }
00143
00144 void Engine2::WorldViewWidget::HandleFocus ()
00145 {
00146 if (m_world_view != NULL)
00147 m_world_view->HandleFocus();
00148 }
00149
00150 void Engine2::WorldViewWidget::HandleUnfocus ()
00151 {
00152 if (m_world_view != NULL)
00153 m_world_view->HandleUnfocus();
00154 }
00155
00156 void Engine2::WorldViewWidget::DrawFocusFrame (RenderContext const &render_context) const
00157 {
00158
00159 if (!m_draw_focus_frame)
00160 return;
00161
00162
00163 }
00164
00165 void Engine2::WorldViewWidget::ComputeTransform ()
00166 {
00167
00168 m_transform = FloatSimpleTransform2::ms_identity;
00169
00170
00171
00172 if (m_is_transform_scaling_based_upon_widget_radius)
00173 m_transform.Scale(0.5f * Size().StaticCast<Float>().Length());
00174 else
00175 m_transform.Scale(0.5f * static_cast<Float>(Min(Width(), Height())));
00176
00177
00178 m_transform.Translate(ScreenRect().Center().StaticCast<Float>());
00179 }
00180
00181 }