nux-1.16.0
|
00001 /* 00002 * Copyright 2010 Inalogic® Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License, as 00006 * published by the Free Software Foundation; either version 2.1 or 3.0 00007 * of the License. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranties of 00011 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the applicable version of the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of both the GNU Lesser General Public 00016 * License along with this program. If not, see <http://www.gnu.org/licenses/> 00017 * 00018 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00019 * 00020 */ 00021 00022 00023 #include "Nux.h" 00024 #include "Matrix3Editor.h" 00025 00026 namespace nux 00027 { 00028 00029 static void ThreadMatrix3EditorDialog (NThread *thread, void *InitData) 00030 { 00031 VLayout *MainLayout (new VLayout (NUX_TRACKER_LOCATION) ); 00032 Matrix3Editor *matrixeditor (new Matrix3Editor (Matrix3::IDENTITY(), NUX_TRACKER_LOCATION) ); 00033 matrixeditor->ComputeChildLayout(); // necessary so all element of the widget get their rightful size. 00034 Matrix3DialogProxy *matrixeditorproxy = static_cast<Matrix3DialogProxy *> (InitData); 00035 00036 if (matrixeditorproxy) 00037 { 00038 matrixeditor->SetMatrix (matrixeditorproxy->GetMatrix() ); 00039 matrixeditor->sigMatrixChanged.connect (sigc::mem_fun (matrixeditorproxy, &Matrix3DialogProxy::RecvDialogChange) ); 00040 } 00041 00042 HLayout *ButtonLayout (new HLayout (NUX_TRACKER_LOCATION) ); 00043 00044 ToggleButton *OkButton (new ToggleButton ("OK", NUX_TRACKER_LOCATION) ); 00045 OkButton->SetMinimumWidth (60); 00046 OkButton->SetMinimumHeight (20); 00047 00048 ToggleButton *CancelButton (new ToggleButton ("Cancel", NUX_TRACKER_LOCATION) ); 00049 CancelButton->SetMinimumWidth (60); 00050 CancelButton->SetMinimumHeight (20); 00051 00052 //FIXME - OkButton->sigClick.connect (sigc::mem_fun (static_cast<WindowThread *> (thread), &WindowThread::TerminateThread) ); 00053 //FIXME - OkButton->sigClick.connect (sigc::bind (sigc::mem_fun (matrixeditorproxy, &Matrix3DialogProxy::RecvDialogOk), matrixeditor) ); 00054 //FIXME - CancelButton->sigClick.connect (sigc::bind (sigc::mem_fun (matrixeditorproxy, &Matrix3DialogProxy::RecvDialogCancel), matrixeditor) ); 00055 //FIXME - CancelButton->sigClick.connect (sigc::mem_fun (static_cast<WindowThread *> (thread), &WindowThread::TerminateThread) ); 00056 00057 ButtonLayout->SetHorizontalInternalMargin (6); 00058 ButtonLayout->SetVerticalExternalMargin (2); 00059 ButtonLayout->AddView (OkButton, 0); 00060 ButtonLayout->AddView (CancelButton, 0); 00061 00062 MainLayout->AddView (matrixeditor); 00063 MainLayout->AddLayout (ButtonLayout, 0); 00064 static_cast<WindowThread *> (thread)->SetLayout (MainLayout); 00065 00066 MainLayout->SetBaseWidth (1); 00067 MainLayout->SetBaseHeight (1); 00068 MainLayout->ComputeLayout2(); 00069 00070 static_cast<WindowThread *> (thread)->SetWindowSize (MainLayout->GetBaseWidth(), MainLayout->GetBaseHeight() ); 00071 00072 // Call StopThreadMonitoring in case the dialog was close by clicking the window close button. 00073 //matrixeditorproxy->StopThreadMonitoring(); 00074 //delete CancelButton; 00075 //delete OkButton; 00076 //delete matrixeditor; 00077 } 00078 00079 Matrix3DialogProxy::Matrix3DialogProxy (bool ModalWindow) 00080 : m_bDialogChange (false) 00081 , m_bDialogRunning (false) 00082 , m_ModalWindow (ModalWindow) 00083 { 00084 00085 } 00086 00087 Matrix3DialogProxy::~Matrix3DialogProxy() 00088 { 00089 } 00090 00091 void Matrix3DialogProxy::Start() 00092 { 00093 m_PreviousMatrix = m_Matrix; 00094 m_Thread = CreateModalWindowThread (WINDOWSTYLE_TOOL, TEXT ("Matrix Editor"), 290, 230, GetWindowThread (), 00095 ThreadMatrix3EditorDialog, 00096 this); 00097 00098 if (m_Thread) 00099 { 00100 m_DialogThreadID = m_Thread->GetThreadId(); 00101 m_Thread->Start (0); 00102 } 00103 00104 m_bDialogRunning = true; 00105 } 00106 00107 bool Matrix3DialogProxy::IsActive() 00108 { 00109 return (m_Thread && (m_Thread->GetThreadState() != THREADSTOP) && m_bDialogRunning); 00110 } 00111 00112 void Matrix3DialogProxy::RecvDialogOk (Matrix3Editor *matrixeditor) 00113 { 00114 m_Matrix = matrixeditor->GetMatrix(); 00115 m_PreviousMatrix = m_Matrix; 00116 m_bDialogChange = true; 00117 m_bDialogRunning = false; 00118 } 00119 00120 void Matrix3DialogProxy::RecvDialogCancel (Matrix3Editor *matrixeditor) 00121 { 00122 m_Matrix = m_PreviousMatrix; 00123 m_bDialogChange = true; 00124 m_bDialogRunning = false; 00125 } 00126 00127 void Matrix3DialogProxy::RecvDialogChange (Matrix3Editor *matrixeditor) 00128 { 00129 m_Matrix = matrixeditor->GetMatrix(); 00130 m_bDialogChange = true; 00131 } 00132 00133 void Matrix3DialogProxy::StopThreadMonitoring() 00134 { 00135 m_Matrix = m_PreviousMatrix; 00136 m_bDialogChange = true; 00137 m_bDialogRunning = false; 00138 m_DialogThreadID = 0; 00139 m_Thread = 0; 00140 } 00141 00142 Matrix3Editor::Matrix3Editor (Matrix3 matrix, NUX_FILE_LINE_DECL) 00143 : View (NUX_FILE_LINE_PARAM) 00144 , m_Matrix (matrix) 00145 { 00146 m_vlayout = new VLayout (NUX_TRACKER_LOCATION); 00147 mtx_layout = new VLayout (NUX_TRACKER_LOCATION); 00148 m_MtxFunctionLayout = new HLayout (NUX_TRACKER_LOCATION); 00149 00150 mtx_row_layout[0] = new HLayout (NUX_TRACKER_LOCATION); 00151 mtx_row_layout[1] = new HLayout (NUX_TRACKER_LOCATION); 00152 mtx_row_layout[2] = new HLayout (NUX_TRACKER_LOCATION); 00153 00154 m_IdentityMtxBtn = new ToggleButton (TEXT (""), NUX_TRACKER_LOCATION); 00155 m_ZeroMtxBtn = new ToggleButton (TEXT (""), NUX_TRACKER_LOCATION); 00156 m_InverseMtxBtn = new ToggleButton (TEXT (""), NUX_TRACKER_LOCATION); 00157 m_NegateMtxBtn = new ToggleButton (TEXT (""), NUX_TRACKER_LOCATION); 00158 00159 //FIXME - m_IdentityMtxBtn->sigClick.connect (sigc::mem_fun (this, &Matrix3Editor::RecvIdentityMatrixCmd) ); 00160 //FIXME - m_ZeroMtxBtn->sigClick.connect (sigc::mem_fun (this, &Matrix3Editor::RecvZeroMatrixCmd) ); 00161 //FIXME - m_InverseMtxBtn->sigClick.connect (sigc::mem_fun (this, &Matrix3Editor::RecvInverseMatrixCmd) ); 00162 //FIXME - m_NegateMtxBtn->sigClick.connect (sigc::mem_fun (this, &Matrix3Editor::RecvNegateMatrixCmd) ); 00163 00164 for (int i = 0; i < 3; i++) 00165 { 00166 for (int j = 0; j < 3; j++) 00167 { 00168 m_MtxInput[i][j] = new EditTextBox (TEXT (""), NUX_TRACKER_LOCATION); 00169 m_MtxInput[i][j]->SetMinimumSize (DEFAULT_WIDGET_WIDTH + 5, PRACTICAL_WIDGET_HEIGHT); 00170 m_MtxInput[i][j]->SetGeometry (Geometry (0, 0, DEFAULT_WIDGET_WIDTH, DEFAULT_WIDGET_HEIGHT) ); 00171 m_MtxInput[i][j]->sigValidateKeyboardEntry.connect ( 00172 sigc::bind (sigc::mem_fun (this, &Matrix3Editor::RecvComponentInput), i * 3 + j) ); 00173 00174 } 00175 } 00176 00177 for (int i = 0; i < 3; i++) 00178 { 00179 mtx_row_layout[i]->SetHorizontalInternalMargin (4); 00180 //mtx_row_layout[i]->SetHorizontalExternalMargin(4); 00181 //mtx_row_layout[i]->SetVerticalExternalMargin(2); 00182 mtx_row_layout[i]->SetContentDistribution (eStackLeft); 00183 } 00184 00185 for (int i = 0; i < 3; i++) 00186 { 00187 for (int j = 0; j < 3; j++) 00188 { 00189 mtx_row_layout[i]->AddView (m_MtxInput[i][j], 0, eCenter, eFull); 00190 } 00191 } 00192 00193 for (int i = 0; i < 3; i++) 00194 { 00195 mtx_layout->AddLayout (mtx_row_layout[i], 0, eCenter); 00196 } 00197 00198 mtx_layout->SetContentDistribution (eStackExpand); 00199 00200 //FIXME - m_IdentityMtxBtn->SetCaption (TEXT ("Id") ); 00201 //FIXME - m_ZeroMtxBtn->SetCaption (TEXT ("Zero") ); 00202 //FIXME - m_InverseMtxBtn->SetCaption (TEXT ("Inv") ); 00203 //FIXME - m_NegateMtxBtn->SetCaption (TEXT ("+/-") ); 00204 00205 m_MtxFunctionLayout->AddView (m_IdentityMtxBtn, 0, eAbove, eMatchContent); 00206 m_MtxFunctionLayout->AddView (m_ZeroMtxBtn, 0, eAbove, eMatchContent); 00207 m_MtxFunctionLayout->AddView (m_InverseMtxBtn, 0, eAbove, eMatchContent); 00208 m_MtxFunctionLayout->AddView (m_NegateMtxBtn, 0, eAbove, eMatchContent); 00209 m_MtxFunctionLayout->SetVerticalExternalMargin (4); 00210 m_MtxFunctionLayout->SetHorizontalExternalMargin (4); 00211 m_MtxFunctionLayout->SetHorizontalInternalMargin (2); 00212 m_MtxFunctionLayout->SetContentDistribution (eStackLeft); 00213 //mtx_layout->AddLayout(&m_MtxFunctionLayout, 1, eCenter, eMatchContent); 00214 mtx_layout->SetContentDistribution (eStackCenter); 00215 mtx_layout->SetHorizontalExternalMargin (4); 00216 mtx_layout->SetVerticalExternalMargin (4); 00217 mtx_layout->SetVerticalInternalMargin (4); 00218 00219 m_vlayout->AddLayout (mtx_layout, 0, eCenter, eMatchContent); 00220 m_vlayout->AddLayout (m_MtxFunctionLayout, 0, eCenter, eMatchContent); 00221 m_vlayout->SetContentDistribution (eStackCenter); 00222 00223 SetCompositionLayout (m_vlayout); 00224 WriteMatrix(); 00225 } 00226 00227 Matrix3Editor::~Matrix3Editor() 00228 { 00229 } 00230 00231 void Matrix3Editor::SetMatrix (Matrix3 matrix) 00232 { 00233 m_Matrix = matrix; 00234 00235 for (int i = 0; i < 3; i++) 00236 { 00237 for (int j = 0; j < 3; j++) 00238 { 00239 m_MtxInput[i][j]->SetText (NString::Printf (TEXT ("%.3f"), m_Matrix.m[i][j]) ); 00240 } 00241 } 00242 } 00243 00244 Matrix3 Matrix3Editor::GetMatrix() const 00245 { 00246 return m_Matrix; 00247 } 00248 00249 void Matrix3Editor::RecvComponentInput (EditTextBox *textbox, const NString &text, int componentIndex) 00250 { 00251 int i = componentIndex / 3; 00252 int j = componentIndex - 3 * i; 00253 00254 float f = 0; 00255 f = CharToDouble (text.GetTCharPtr() ); 00256 m_MtxInput[i][j]->SetText (NString::Printf (TEXT ("%.3f"), f) ); 00257 m_Matrix.m[i][j] = f; 00258 00259 sigMatrixChanged.emit (this); 00260 } 00261 00262 void Matrix3Editor::WriteMatrix() 00263 { 00264 for (int i = 0; i < 3; i++) 00265 { 00266 for (int j = 0; j < 3; j++) 00267 { 00268 m_MtxInput[i][j]->SetText (NString::Printf (TEXT ("%.3f"), m_Matrix.m[i][j]) ); 00269 } 00270 } 00271 } 00272 00273 void Matrix3Editor::Draw (GraphicsEngine &GfxContext, bool force_draw) 00274 { 00275 Geometry base = GetGeometry(); 00276 00277 for (int i = 0; i < 3; i++) 00278 { 00279 for (int j = 0; j < 3; j++) 00280 { 00281 m_MtxInput[i][j]->QueueDraw(); 00282 } 00283 } 00284 00285 m_IdentityMtxBtn->QueueDraw(); 00286 m_ZeroMtxBtn->QueueDraw(); 00287 m_InverseMtxBtn->QueueDraw(); 00288 m_NegateMtxBtn->QueueDraw(); 00289 //GetPainter().PopBackground(); 00290 00291 //GetPainter().PopBackground(); 00292 } 00293 00294 void Matrix3Editor::DrawContent (GraphicsEngine &GfxContext, bool force_draw) 00295 { 00296 Geometry base = GetGeometry(); 00297 00298 if (force_draw) 00299 GetPainter().PushDrawShapeLayer (GfxContext, mtx_layout->GetGeometry(), eSHAPE_CORNER_ROUND4, Color (0xFF000000), eAllCorners); 00300 else 00301 GetPainter().PushShapeLayer (GfxContext, mtx_layout->GetGeometry(), eSHAPE_CORNER_ROUND4, Color (0xFF000000), eAllCorners); 00302 00303 for (int i = 0; i < 3; i++) 00304 { 00305 for (int j = 0; j < 3; j++) 00306 { 00307 m_MtxInput[i][j]->ProcessDraw (GfxContext, force_draw); 00308 } 00309 } 00310 00311 m_IdentityMtxBtn->ProcessDraw (GfxContext, force_draw); 00312 m_ZeroMtxBtn->ProcessDraw (GfxContext, force_draw); 00313 m_InverseMtxBtn->ProcessDraw (GfxContext, force_draw); 00314 m_NegateMtxBtn->ProcessDraw (GfxContext, force_draw); 00315 GetPainter().PopBackground(); 00316 } 00317 00318 void Matrix3Editor::PostDraw (GraphicsEngine &GfxContext, bool force_draw) 00319 { 00320 00321 } 00322 00323 void Matrix3Editor::SetParameterName (const char *parameter_name) 00324 { 00325 QueueDraw(); 00326 } 00327 00329 // RECEIVERS // 00331 void Matrix3Editor::EmitIncrementComponent (int index) 00332 { 00333 00334 //sigSetVector.emit(m_x, m_y, m_z, m_w); 00335 } 00336 00337 void Matrix3Editor::EmitDecrementComponent (int index) 00338 { 00339 00340 //sigSetVector.emit(m_x, m_y, m_z, m_w); 00341 } 00342 00343 void Matrix3Editor::EmitComponentValue (float f, int index) 00344 { 00345 00346 //sigSetVector.emit(m_x, m_y, m_z, m_w); 00347 } 00348 00349 00350 void Matrix3Editor::RecvIdentityMatrixCmd() 00351 { 00352 m_Matrix.Identity(); 00353 WriteMatrix(); 00354 sigMatrixChanged.emit (this); 00355 00356 QueueDraw(); 00357 } 00358 00359 void Matrix3Editor::RecvZeroMatrixCmd() 00360 { 00361 m_Matrix.Zero(); 00362 WriteMatrix(); 00363 sigMatrixChanged.emit (this); 00364 00365 QueueDraw(); 00366 } 00367 00368 void Matrix3Editor::RecvInverseMatrixCmd() 00369 { 00370 m_Matrix.Inverse(); 00371 WriteMatrix(); 00372 sigMatrixChanged.emit (this); 00373 00374 QueueDraw(); 00375 } 00376 00377 void Matrix3Editor::RecvNegateMatrixCmd() 00378 { 00379 m_Matrix = -m_Matrix; 00380 WriteMatrix(); 00381 sigMatrixChanged.emit (this); 00382 00383 QueueDraw(); 00384 } 00385 00386 00387 }