~hikiko/nux/arb-srgba-shader

« back to all changes in this revision

Viewing changes to Nux/Matrix3Editor.cpp

  • Committer: Neil Jagdish Patel
  • Date: 2010-09-02 03:28:11 UTC
  • Revision ID: neil.patel@canonical.com-20100902032811-i2m18tfb6pkasnvt
Remove Win EOL chars

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 */
21
21
 
22
22
 
23
 
#include "Nux.h"
24
 
#include "Matrix3Editor.h"
25
 
 
26
 
NAMESPACE_BEGIN_GUI
27
 
 
28
 
static void ThreadMatrix3EditorDialog(NThread* thread, void* InitData)
29
 
{
30
 
    smptr(VLayout) MainLayout(new VLayout());
31
 
    smptr(Matrix3Editor) matrixeditor(new Matrix3Editor());
32
 
    matrixeditor->ComputeChildLayout(); // necessary so all element of the widget get their rightful size.
33
 
    Matrix3DialogProxy* matrixeditorproxy = static_cast<Matrix3DialogProxy*>(InitData);
34
 
    if(matrixeditorproxy)
35
 
    {
36
 
        matrixeditor->SetMatrix(matrixeditorproxy->GetMatrix());
37
 
        matrixeditor->sigMatrixChanged.connect(sigc::mem_fun(matrixeditorproxy, &Matrix3DialogProxy::RecvDialogChange));
38
 
    }
39
 
 
40
 
    smptr(HLayout) ButtonLayout(new HLayout(TEXT("Dialog Buttons")));
41
 
 
42
 
    smptr(Button) OkButton(new Button(TEXT("OK")));
43
 
    OkButton->SetMinimumWidth(60);
44
 
    OkButton->SetMinimumHeight(20);
45
 
 
46
 
    smptr(Button) CancelButton(new Button(TEXT("Cancel")));
47
 
    CancelButton->SetMinimumWidth(60);
48
 
    CancelButton->SetMinimumHeight(20);
49
 
 
50
 
    OkButton->sigClick.connect(sigc::mem_fun(static_cast<WindowThread*>(thread), &WindowThread::TerminateThread));
51
 
    OkButton->sigClick.connect(sigc::bind(sigc::mem_fun(matrixeditorproxy, &Matrix3DialogProxy::RecvDialogOk), weaksmptr(Matrix3Editor)(matrixeditor)));
52
 
    CancelButton->sigClick.connect(sigc::bind(sigc::mem_fun(matrixeditorproxy, &Matrix3DialogProxy::RecvDialogCancel), weaksmptr(Matrix3Editor)(matrixeditor)));
53
 
    CancelButton->sigClick.connect(sigc::mem_fun(static_cast<WindowThread*>(thread), &WindowThread::TerminateThread));
54
 
 
55
 
    ButtonLayout->SetHorizontalInternalMargin(6);
56
 
    ButtonLayout->SetVerticalExternalMargin(2);
57
 
    ButtonLayout->AddActiveInterfaceObject(OkButton, 0);
58
 
    ButtonLayout->AddActiveInterfaceObject(CancelButton, 0);
59
 
 
60
 
    MainLayout->AddActiveInterfaceObject(matrixeditor);
61
 
    MainLayout->AddLayout(ButtonLayout, 0);
62
 
    static_cast<WindowThread*>(thread)->SetLayout(MainLayout);
63
 
 
64
 
    MainLayout->SetBaseWidth(1);
65
 
    MainLayout->SetBaseHeight(1);
66
 
    MainLayout->ComputeLayout2();
67
 
 
68
 
    static_cast<WindowThread*>(thread)->SetWindowSize(MainLayout->GetBaseWidth(), MainLayout->GetBaseHeight());
69
 
 
70
 
    // Call StopThreadMonitoring in case the dialog was close by clicking the window close button.
71
 
    matrixeditorproxy->StopThreadMonitoring();
72
 
    //delete CancelButton;
73
 
    //delete OkButton;
74
 
    //delete matrixeditor;
75
 
}
76
 
 
77
 
Matrix3DialogProxy::Matrix3DialogProxy(bool ModalWindow)
78
 
:   m_bDialogChange(false)
79
 
,   m_bDialogRunning(false)
80
 
,   m_ModalWindow(ModalWindow)
81
 
{
82
 
 
83
 
}
84
 
 
85
 
Matrix3DialogProxy::~Matrix3DialogProxy()
86
 
{
87
 
}
88
 
 
89
 
void Matrix3DialogProxy::Start()
90
 
{
91
 
    m_PreviousMatrix = m_Matrix;
92
 
    m_Thread = CreateModalWindowThread(WINDOWSTYLE_TOOL, TEXT("Matrix Editor"), 290, 230, GetGraphicsThread(),
93
 
        ThreadMatrix3EditorDialog,
94
 
        this);
95
 
 
96
 
    if(m_Thread)
97
 
    {
98
 
        m_DialogThreadID = m_Thread->GetThreadId();
99
 
        m_Thread->Start(0);
100
 
    }
101
 
 
102
 
    m_bDialogRunning = true;
103
 
}
104
 
 
105
 
bool Matrix3DialogProxy::IsActive()
106
 
{
107
 
    return (m_Thread && (m_Thread->GetThreadState() != THREADSTOP) && m_bDialogRunning);
108
 
}
109
 
 
110
 
void Matrix3DialogProxy::RecvDialogOk(const weaksmptr(Matrix3Editor) matrixeditor)
111
 
{
112
 
    m_Matrix = matrixeditor->GetMatrix();
113
 
    m_PreviousMatrix = m_Matrix;
114
 
    m_bDialogChange = true;
115
 
    m_bDialogRunning = false;
116
 
}
117
 
 
118
 
void Matrix3DialogProxy::RecvDialogCancel(const weaksmptr(Matrix3Editor) matrixeditor)
119
 
{
120
 
    m_Matrix = m_PreviousMatrix;
121
 
    m_bDialogChange = true;
122
 
    m_bDialogRunning = false;
123
 
}
124
 
 
125
 
void Matrix3DialogProxy::RecvDialogChange(const weaksmptr(Matrix3Editor) matrixeditor)
126
 
{
127
 
    m_Matrix = matrixeditor->GetMatrix();
128
 
    m_bDialogChange = true;
129
 
}
130
 
 
131
 
void Matrix3DialogProxy::StopThreadMonitoring()
132
 
{
133
 
    m_Matrix = m_PreviousMatrix;
134
 
    m_bDialogChange = true;
135
 
    m_bDialogRunning = false;
136
 
    m_DialogThreadID = 0;
137
 
    m_Thread = 0;
138
 
}
139
 
 
140
 
Matrix3Editor::Matrix3Editor(Matrix3 matrix)
141
 
:   m_Matrix(matrix)
142
 
{
143
 
    m_vlayout = smptr(VLayout)(new VLayout());
144
 
    mtx_layout = smptr(VLayout)(new VLayout());
145
 
    m_MtxFunctionLayout = smptr(HLayout)(new HLayout());
146
 
 
147
 
    mtx_row_layout[0] = smptr(HLayout)(new HLayout());
148
 
    mtx_row_layout[1] = smptr(HLayout)(new HLayout());
149
 
    mtx_row_layout[2] = smptr(HLayout)(new HLayout());
150
 
 
151
 
    m_IdentityMtxBtn = smptr(Button)(new Button());
152
 
    m_ZeroMtxBtn = smptr(Button)(new Button());
153
 
    m_InverseMtxBtn = smptr(Button)(new Button());
154
 
    m_NegateMtxBtn = smptr(Button)(new Button());
155
 
 
156
 
    m_IdentityMtxBtn->sigClick.connect(sigc::mem_fun(this, &Matrix3Editor::RecvIdentityMatrixCmd));
157
 
    m_ZeroMtxBtn->sigClick.connect(sigc::mem_fun(this, &Matrix3Editor::RecvZeroMatrixCmd));
158
 
    m_InverseMtxBtn->sigClick.connect(sigc::mem_fun(this, &Matrix3Editor::RecvInverseMatrixCmd));
159
 
    m_NegateMtxBtn->sigClick.connect(sigc::mem_fun(this, &Matrix3Editor::RecvNegateMatrixCmd));
160
 
 
161
 
    for(int i = 0; i < 3; i++)
162
 
    {
163
 
        for(int j = 0; j < 3; j++)
164
 
        {
165
 
            m_MtxInput[i][j] = smptr(EditTextBox)(new EditTextBox());
166
 
            m_MtxInput[i][j]->SetMinimumSize(DEFAULT_WIDGET_WIDTH + 5, PRACTICAL_WIDGET_HEIGHT);
167
 
            m_MtxInput[i][j]->setGeometry(Geometry(0, 0, DEFAULT_WIDGET_WIDTH, DEFAULT_WIDGET_HEIGHT));
168
 
            m_MtxInput[i][j]->sigValidateKeyboardEntry.connect(
169
 
                sigc::bind(sigc::mem_fun(this, &Matrix3Editor::RecvComponentInput), i*3+j));
170
 
 
171
 
        }
172
 
    }
173
 
 
174
 
    for(int i = 0; i < 3; i++)
175
 
    {
176
 
        mtx_row_layout[i]->SetHorizontalInternalMargin(4);
177
 
        //mtx_row_layout[i]->SetHorizontalExternalMargin(4);
178
 
        //mtx_row_layout[i]->SetVerticalExternalMargin(2);
179
 
        mtx_row_layout[i]->SetContentStacking(eStackLeft);
180
 
    }
181
 
 
182
 
    for(int i = 0; i < 3; i++)
183
 
    {
184
 
        for(int j = 0; j < 3; j++)
185
 
        {
186
 
            mtx_row_layout[i]->AddActiveInterfaceObject(m_MtxInput[i][j], 0, eCenter, eFull);
187
 
        }
188
 
    }
189
 
 
190
 
    for(int i = 0; i < 3; i++)
191
 
    {
192
 
        mtx_layout->AddLayout(mtx_row_layout[i], 0, eCenter);
193
 
    }
194
 
    mtx_layout->SetContentStacking(eStackExpand);
195
 
 
196
 
    m_IdentityMtxBtn->SetCaption(TEXT("Id"));
197
 
    m_ZeroMtxBtn->SetCaption(TEXT("Zero"));
198
 
    m_InverseMtxBtn->SetCaption(TEXT("Inv"));
199
 
    m_NegateMtxBtn->SetCaption(TEXT("+/-"));
200
 
 
201
 
    m_MtxFunctionLayout->AddActiveInterfaceObject(m_IdentityMtxBtn, 0, eAbove, eMatchContent);
202
 
    m_MtxFunctionLayout->AddActiveInterfaceObject(m_ZeroMtxBtn, 0, eAbove, eMatchContent);
203
 
    m_MtxFunctionLayout->AddActiveInterfaceObject(m_InverseMtxBtn, 0, eAbove, eMatchContent);
204
 
    m_MtxFunctionLayout->AddActiveInterfaceObject(m_NegateMtxBtn, 0, eAbove, eMatchContent);
205
 
    m_MtxFunctionLayout->SetVerticalExternalMargin(4);
206
 
    m_MtxFunctionLayout->SetHorizontalExternalMargin(4);
207
 
    m_MtxFunctionLayout->SetHorizontalInternalMargin(2);
208
 
    m_MtxFunctionLayout->SetContentStacking(eStackLeft);
209
 
    //mtx_layout->AddLayout(&m_MtxFunctionLayout, 1, eCenter, eMatchContent);
210
 
    mtx_layout->SetContentStacking(eStackCenter);
211
 
    mtx_layout->SetHorizontalExternalMargin(4);
212
 
    mtx_layout->SetVerticalExternalMargin(4);
213
 
    mtx_layout->SetVerticalInternalMargin(4);
214
 
 
215
 
    m_vlayout->AddLayout(mtx_layout, 0, eCenter, eMatchContent);
216
 
    m_vlayout->AddLayout(m_MtxFunctionLayout, 0,  eCenter, eMatchContent);
217
 
    m_vlayout->SetContentStacking(eStackCenter);
218
 
 
219
 
    SetCompositionLayout(m_vlayout);
220
 
    WriteMatrix();
221
 
}
222
 
 
223
 
Matrix3Editor::~Matrix3Editor()
224
 
{
225
 
}
226
 
 
227
 
void Matrix3Editor::SetMatrix(Matrix3 matrix)
228
 
{
229
 
    m_Matrix = matrix;
230
 
    for(int i = 0; i < 3; i++)
231
 
    {
232
 
        for(int j = 0; j < 3; j++)
233
 
        {
234
 
            m_MtxInput[i][j]->SetText(inlPrintf(TEXT("%.3f"), m_Matrix.m[i][j]));
235
 
        }
236
 
    }
237
 
}
238
 
 
239
 
Matrix3 Matrix3Editor::GetMatrix() const
240
 
{
241
 
    return m_Matrix;
242
 
}
243
 
 
244
 
void Matrix3Editor::RecvComponentInput(const weaksmptr(EditTextBox) textbox, const NString& text, int componentIndex)
245
 
{
246
 
    int i = componentIndex / 3;
247
 
    int j = componentIndex - 3*i;
248
 
 
249
 
    float f = 0;
250
 
    CharToFloat(text.GetTCharPtr(), f);
251
 
    m_MtxInput[i][j]->SetText(inlPrintf(TEXT("%.3f"), f));
252
 
    m_Matrix.m[i][j] = f;
253
 
 
254
 
    sigMatrixChanged.emit(smptr(Matrix3Editor)(this, false));
255
 
}
256
 
 
257
 
void Matrix3Editor::WriteMatrix()
258
 
{
259
 
    for(int i = 0; i < 3; i++)
260
 
    {
261
 
        for(int j = 0; j < 3; j++)
262
 
        {
263
 
            m_MtxInput[i][j]->SetText(inlPrintf(TEXT("%.3f"), m_Matrix.m[i][j]));
264
 
        }
265
 
    }
266
 
}
267
 
 
268
 
long Matrix3Editor::ProcessEvent(IEvent &ievent, long TraverseInfo, long ProcessEventInfo) 
269
 
{
270
 
    long ret = TraverseInfo;
271
 
    for(int i = 0; i < 3; i++)
272
 
    {
273
 
        for(int j = 0; j < 3; j++)
274
 
        {
275
 
            ret = m_MtxInput[i][j]->ProcessEvent(ievent, ret, ProcessEventInfo);
276
 
        }
277
 
    }
278
 
    ret = m_IdentityMtxBtn->ProcessEvent(ievent, ret, ProcessEventInfo);
279
 
    ret = m_ZeroMtxBtn->ProcessEvent(ievent, ret, ProcessEventInfo);
280
 
    ret = m_InverseMtxBtn->ProcessEvent(ievent, ret, ProcessEventInfo);
281
 
    ret = m_NegateMtxBtn->ProcessEvent(ievent, ret, ProcessEventInfo);
282
 
 
283
 
    ret = PostProcessEvent2(ievent, ret, ProcessEventInfo);
284
 
    return ret;
285
 
}
286
 
 
287
 
void Matrix3Editor::Draw(GraphicsContext& GfxContext, bool force_draw)
288
 
{
289
 
    Geometry base = GetGeometry();
290
 
 
291
 
    for(int i = 0; i < 3; i++)
292
 
    {
293
 
        for(int j = 0; j < 3; j++)
294
 
        {
295
 
            m_MtxInput[i][j]->NeedRedraw();
296
 
        }
297
 
    }
298
 
 
299
 
    m_IdentityMtxBtn->NeedRedraw();
300
 
    m_ZeroMtxBtn->NeedRedraw();
301
 
    m_InverseMtxBtn->NeedRedraw();
302
 
    m_NegateMtxBtn->NeedRedraw();
303
 
    //gPainter.PopBackground();
304
 
 
305
 
    //gPainter.PopBackground();
306
 
}
307
 
 
308
 
void Matrix3Editor::DrawContent(GraphicsContext& GfxContext, bool force_draw)
309
 
{
310
 
    Geometry base = GetGeometry();
311
 
    if(force_draw)
312
 
        gPainter.PushDrawShapeLayer(GfxContext, mtx_layout->GetGeometry(), eSHAPE_CORNER_ROUND4, Color(0xFF000000), eAllCorners);
313
 
    else
314
 
        gPainter.PushShapeLayer(GfxContext, mtx_layout->GetGeometry(), eSHAPE_CORNER_ROUND4, Color(0xFF000000), eAllCorners);
315
 
 
316
 
    for(int i = 0; i < 3; i++)
317
 
    {
318
 
        for(int j = 0; j < 3; j++)
319
 
        {
320
 
            m_MtxInput[i][j]->ProcessDraw(GfxContext, force_draw);
321
 
        }
322
 
    }
323
 
 
324
 
    m_IdentityMtxBtn->ProcessDraw(GfxContext, force_draw);
325
 
    m_ZeroMtxBtn->ProcessDraw(GfxContext, force_draw);
326
 
    m_InverseMtxBtn->ProcessDraw(GfxContext, force_draw);
327
 
    m_NegateMtxBtn->ProcessDraw(GfxContext, force_draw);
328
 
    gPainter.PopBackground();
329
 
}
330
 
 
331
 
void Matrix3Editor::PostDraw(GraphicsContext& GfxContext, bool force_draw)
332
 
{
333
 
 
334
 
}
335
 
 
336
 
void Matrix3Editor::SetParameterName(const char* parameter_name)
337
 
{
338
 
    NeedRedraw();
339
 
}
340
 
 
341
 
/////////////////
342
 
//  RECEIVERS  //
343
 
/////////////////
344
 
void Matrix3Editor::EmitIncrementComponent(int index) 
345
 
346
 
 
347
 
    //sigSetVector.emit(m_x, m_y, m_z, m_w);
348
 
}
349
 
 
350
 
void Matrix3Editor::EmitDecrementComponent(int index)
351
 
{
352
 
 
353
 
    //sigSetVector.emit(m_x, m_y, m_z, m_w);
354
 
}
355
 
 
356
 
void Matrix3Editor::EmitComponentValue(float f, int index)
357
 
{
358
 
 
359
 
    //sigSetVector.emit(m_x, m_y, m_z, m_w);
360
 
}
361
 
 
362
 
 
363
 
void Matrix3Editor::RecvIdentityMatrixCmd()
364
 
{
365
 
    m_Matrix.Identity();
366
 
    WriteMatrix();
367
 
    sigMatrixChanged.emit(smptr(Matrix3Editor)(this, false));
368
 
 
369
 
    NeedRedraw();
370
 
}
371
 
 
372
 
void Matrix3Editor::RecvZeroMatrixCmd()
373
 
{
374
 
    m_Matrix.Zero();
375
 
    WriteMatrix();
376
 
    sigMatrixChanged.emit(smptr(Matrix3Editor)(this, false));
377
 
 
378
 
    NeedRedraw();
379
 
}
380
 
 
381
 
void Matrix3Editor::RecvInverseMatrixCmd()
382
 
{
383
 
    m_Matrix.Zero();
384
 
    WriteMatrix();
385
 
    sigMatrixChanged.emit(smptr(Matrix3Editor)(this, false));
386
 
 
387
 
    NeedRedraw();
388
 
}
389
 
 
390
 
void Matrix3Editor::RecvNegateMatrixCmd()
391
 
{
392
 
    m_Matrix = -m_Matrix;
393
 
    WriteMatrix();
394
 
    sigMatrixChanged.emit(smptr(Matrix3Editor)(this, false));
395
 
 
396
 
    NeedRedraw();
397
 
}
398
 
 
399
 
 
400
 
NAMESPACE_END_GUI
 
23
#include "Nux.h"
 
24
#include "Matrix3Editor.h"
 
25
 
 
26
NAMESPACE_BEGIN_GUI
 
27
 
 
28
static void ThreadMatrix3EditorDialog(NThread* thread, void* InitData)
 
29
{
 
30
    smptr(VLayout) MainLayout(new VLayout());
 
31
    smptr(Matrix3Editor) matrixeditor(new Matrix3Editor());
 
32
    matrixeditor->ComputeChildLayout(); // necessary so all element of the widget get their rightful size.
 
33
    Matrix3DialogProxy* matrixeditorproxy = static_cast<Matrix3DialogProxy*>(InitData);
 
34
    if(matrixeditorproxy)
 
35
    {
 
36
        matrixeditor->SetMatrix(matrixeditorproxy->GetMatrix());
 
37
        matrixeditor->sigMatrixChanged.connect(sigc::mem_fun(matrixeditorproxy, &Matrix3DialogProxy::RecvDialogChange));
 
38
    }
 
39
 
 
40
    smptr(HLayout) ButtonLayout(new HLayout(TEXT("Dialog Buttons")));
 
41
 
 
42
    smptr(Button) OkButton(new Button(TEXT("OK")));
 
43
    OkButton->SetMinimumWidth(60);
 
44
    OkButton->SetMinimumHeight(20);
 
45
 
 
46
    smptr(Button) CancelButton(new Button(TEXT("Cancel")));
 
47
    CancelButton->SetMinimumWidth(60);
 
48
    CancelButton->SetMinimumHeight(20);
 
49
 
 
50
    OkButton->sigClick.connect(sigc::mem_fun(static_cast<WindowThread*>(thread), &WindowThread::TerminateThread));
 
51
    OkButton->sigClick.connect(sigc::bind(sigc::mem_fun(matrixeditorproxy, &Matrix3DialogProxy::RecvDialogOk), weaksmptr(Matrix3Editor)(matrixeditor)));
 
52
    CancelButton->sigClick.connect(sigc::bind(sigc::mem_fun(matrixeditorproxy, &Matrix3DialogProxy::RecvDialogCancel), weaksmptr(Matrix3Editor)(matrixeditor)));
 
53
    CancelButton->sigClick.connect(sigc::mem_fun(static_cast<WindowThread*>(thread), &WindowThread::TerminateThread));
 
54
 
 
55
    ButtonLayout->SetHorizontalInternalMargin(6);
 
56
    ButtonLayout->SetVerticalExternalMargin(2);
 
57
    ButtonLayout->AddActiveInterfaceObject(OkButton, 0);
 
58
    ButtonLayout->AddActiveInterfaceObject(CancelButton, 0);
 
59
 
 
60
    MainLayout->AddActiveInterfaceObject(matrixeditor);
 
61
    MainLayout->AddLayout(ButtonLayout, 0);
 
62
    static_cast<WindowThread*>(thread)->SetLayout(MainLayout);
 
63
 
 
64
    MainLayout->SetBaseWidth(1);
 
65
    MainLayout->SetBaseHeight(1);
 
66
    MainLayout->ComputeLayout2();
 
67
 
 
68
    static_cast<WindowThread*>(thread)->SetWindowSize(MainLayout->GetBaseWidth(), MainLayout->GetBaseHeight());
 
69
 
 
70
    // Call StopThreadMonitoring in case the dialog was close by clicking the window close button.
 
71
    matrixeditorproxy->StopThreadMonitoring();
 
72
    //delete CancelButton;
 
73
    //delete OkButton;
 
74
    //delete matrixeditor;
 
75
}
 
76
 
 
77
Matrix3DialogProxy::Matrix3DialogProxy(bool ModalWindow)
 
78
:   m_bDialogChange(false)
 
79
,   m_bDialogRunning(false)
 
80
,   m_ModalWindow(ModalWindow)
 
81
{
 
82
 
 
83
}
 
84
 
 
85
Matrix3DialogProxy::~Matrix3DialogProxy()
 
86
{
 
87
}
 
88
 
 
89
void Matrix3DialogProxy::Start()
 
90
{
 
91
    m_PreviousMatrix = m_Matrix;
 
92
    m_Thread = CreateModalWindowThread(WINDOWSTYLE_TOOL, TEXT("Matrix Editor"), 290, 230, GetGraphicsThread(),
 
93
        ThreadMatrix3EditorDialog,
 
94
        this);
 
95
 
 
96
    if(m_Thread)
 
97
    {
 
98
        m_DialogThreadID = m_Thread->GetThreadId();
 
99
        m_Thread->Start(0);
 
100
    }
 
101
 
 
102
    m_bDialogRunning = true;
 
103
}
 
104
 
 
105
bool Matrix3DialogProxy::IsActive()
 
106
{
 
107
    return (m_Thread && (m_Thread->GetThreadState() != THREADSTOP) && m_bDialogRunning);
 
108
}
 
109
 
 
110
void Matrix3DialogProxy::RecvDialogOk(const weaksmptr(Matrix3Editor) matrixeditor)
 
111
{
 
112
    m_Matrix = matrixeditor->GetMatrix();
 
113
    m_PreviousMatrix = m_Matrix;
 
114
    m_bDialogChange = true;
 
115
    m_bDialogRunning = false;
 
116
}
 
117
 
 
118
void Matrix3DialogProxy::RecvDialogCancel(const weaksmptr(Matrix3Editor) matrixeditor)
 
119
{
 
120
    m_Matrix = m_PreviousMatrix;
 
121
    m_bDialogChange = true;
 
122
    m_bDialogRunning = false;
 
123
}
 
124
 
 
125
void Matrix3DialogProxy::RecvDialogChange(const weaksmptr(Matrix3Editor) matrixeditor)
 
126
{
 
127
    m_Matrix = matrixeditor->GetMatrix();
 
128
    m_bDialogChange = true;
 
129
}
 
130
 
 
131
void Matrix3DialogProxy::StopThreadMonitoring()
 
132
{
 
133
    m_Matrix = m_PreviousMatrix;
 
134
    m_bDialogChange = true;
 
135
    m_bDialogRunning = false;
 
136
    m_DialogThreadID = 0;
 
137
    m_Thread = 0;
 
138
}
 
139
 
 
140
Matrix3Editor::Matrix3Editor(Matrix3 matrix)
 
141
:   m_Matrix(matrix)
 
142
{
 
143
    m_vlayout = smptr(VLayout)(new VLayout());
 
144
    mtx_layout = smptr(VLayout)(new VLayout());
 
145
    m_MtxFunctionLayout = smptr(HLayout)(new HLayout());
 
146
 
 
147
    mtx_row_layout[0] = smptr(HLayout)(new HLayout());
 
148
    mtx_row_layout[1] = smptr(HLayout)(new HLayout());
 
149
    mtx_row_layout[2] = smptr(HLayout)(new HLayout());
 
150
 
 
151
    m_IdentityMtxBtn = smptr(Button)(new Button());
 
152
    m_ZeroMtxBtn = smptr(Button)(new Button());
 
153
    m_InverseMtxBtn = smptr(Button)(new Button());
 
154
    m_NegateMtxBtn = smptr(Button)(new Button());
 
155
 
 
156
    m_IdentityMtxBtn->sigClick.connect(sigc::mem_fun(this, &Matrix3Editor::RecvIdentityMatrixCmd));
 
157
    m_ZeroMtxBtn->sigClick.connect(sigc::mem_fun(this, &Matrix3Editor::RecvZeroMatrixCmd));
 
158
    m_InverseMtxBtn->sigClick.connect(sigc::mem_fun(this, &Matrix3Editor::RecvInverseMatrixCmd));
 
159
    m_NegateMtxBtn->sigClick.connect(sigc::mem_fun(this, &Matrix3Editor::RecvNegateMatrixCmd));
 
160
 
 
161
    for(int i = 0; i < 3; i++)
 
162
    {
 
163
        for(int j = 0; j < 3; j++)
 
164
        {
 
165
            m_MtxInput[i][j] = smptr(EditTextBox)(new EditTextBox());
 
166
            m_MtxInput[i][j]->SetMinimumSize(DEFAULT_WIDGET_WIDTH + 5, PRACTICAL_WIDGET_HEIGHT);
 
167
            m_MtxInput[i][j]->setGeometry(Geometry(0, 0, DEFAULT_WIDGET_WIDTH, DEFAULT_WIDGET_HEIGHT));
 
168
            m_MtxInput[i][j]->sigValidateKeyboardEntry.connect(
 
169
                sigc::bind(sigc::mem_fun(this, &Matrix3Editor::RecvComponentInput), i*3+j));
 
170
 
 
171
        }
 
172
    }
 
173
 
 
174
    for(int i = 0; i < 3; i++)
 
175
    {
 
176
        mtx_row_layout[i]->SetHorizontalInternalMargin(4);
 
177
        //mtx_row_layout[i]->SetHorizontalExternalMargin(4);
 
178
        //mtx_row_layout[i]->SetVerticalExternalMargin(2);
 
179
        mtx_row_layout[i]->SetContentStacking(eStackLeft);
 
180
    }
 
181
 
 
182
    for(int i = 0; i < 3; i++)
 
183
    {
 
184
        for(int j = 0; j < 3; j++)
 
185
        {
 
186
            mtx_row_layout[i]->AddActiveInterfaceObject(m_MtxInput[i][j], 0, eCenter, eFull);
 
187
        }
 
188
    }
 
189
 
 
190
    for(int i = 0; i < 3; i++)
 
191
    {
 
192
        mtx_layout->AddLayout(mtx_row_layout[i], 0, eCenter);
 
193
    }
 
194
    mtx_layout->SetContentStacking(eStackExpand);
 
195
 
 
196
    m_IdentityMtxBtn->SetCaption(TEXT("Id"));
 
197
    m_ZeroMtxBtn->SetCaption(TEXT("Zero"));
 
198
    m_InverseMtxBtn->SetCaption(TEXT("Inv"));
 
199
    m_NegateMtxBtn->SetCaption(TEXT("+/-"));
 
200
 
 
201
    m_MtxFunctionLayout->AddActiveInterfaceObject(m_IdentityMtxBtn, 0, eAbove, eMatchContent);
 
202
    m_MtxFunctionLayout->AddActiveInterfaceObject(m_ZeroMtxBtn, 0, eAbove, eMatchContent);
 
203
    m_MtxFunctionLayout->AddActiveInterfaceObject(m_InverseMtxBtn, 0, eAbove, eMatchContent);
 
204
    m_MtxFunctionLayout->AddActiveInterfaceObject(m_NegateMtxBtn, 0, eAbove, eMatchContent);
 
205
    m_MtxFunctionLayout->SetVerticalExternalMargin(4);
 
206
    m_MtxFunctionLayout->SetHorizontalExternalMargin(4);
 
207
    m_MtxFunctionLayout->SetHorizontalInternalMargin(2);
 
208
    m_MtxFunctionLayout->SetContentStacking(eStackLeft);
 
209
    //mtx_layout->AddLayout(&m_MtxFunctionLayout, 1, eCenter, eMatchContent);
 
210
    mtx_layout->SetContentStacking(eStackCenter);
 
211
    mtx_layout->SetHorizontalExternalMargin(4);
 
212
    mtx_layout->SetVerticalExternalMargin(4);
 
213
    mtx_layout->SetVerticalInternalMargin(4);
 
214
 
 
215
    m_vlayout->AddLayout(mtx_layout, 0, eCenter, eMatchContent);
 
216
    m_vlayout->AddLayout(m_MtxFunctionLayout, 0,  eCenter, eMatchContent);
 
217
    m_vlayout->SetContentStacking(eStackCenter);
 
218
 
 
219
    SetCompositionLayout(m_vlayout);
 
220
    WriteMatrix();
 
221
}
 
222
 
 
223
Matrix3Editor::~Matrix3Editor()
 
224
{
 
225
}
 
226
 
 
227
void Matrix3Editor::SetMatrix(Matrix3 matrix)
 
228
{
 
229
    m_Matrix = matrix;
 
230
    for(int i = 0; i < 3; i++)
 
231
    {
 
232
        for(int j = 0; j < 3; j++)
 
233
        {
 
234
            m_MtxInput[i][j]->SetText(inlPrintf(TEXT("%.3f"), m_Matrix.m[i][j]));
 
235
        }
 
236
    }
 
237
}
 
238
 
 
239
Matrix3 Matrix3Editor::GetMatrix() const
 
240
{
 
241
    return m_Matrix;
 
242
}
 
243
 
 
244
void Matrix3Editor::RecvComponentInput(const weaksmptr(EditTextBox) textbox, const NString& text, int componentIndex)
 
245
{
 
246
    int i = componentIndex / 3;
 
247
    int j = componentIndex - 3*i;
 
248
 
 
249
    float f = 0;
 
250
    CharToFloat(text.GetTCharPtr(), f);
 
251
    m_MtxInput[i][j]->SetText(inlPrintf(TEXT("%.3f"), f));
 
252
    m_Matrix.m[i][j] = f;
 
253
 
 
254
    sigMatrixChanged.emit(smptr(Matrix3Editor)(this, false));
 
255
}
 
256
 
 
257
void Matrix3Editor::WriteMatrix()
 
258
{
 
259
    for(int i = 0; i < 3; i++)
 
260
    {
 
261
        for(int j = 0; j < 3; j++)
 
262
        {
 
263
            m_MtxInput[i][j]->SetText(inlPrintf(TEXT("%.3f"), m_Matrix.m[i][j]));
 
264
        }
 
265
    }
 
266
}
 
267
 
 
268
long Matrix3Editor::ProcessEvent(IEvent &ievent, long TraverseInfo, long ProcessEventInfo) 
 
269
{
 
270
    long ret = TraverseInfo;
 
271
    for(int i = 0; i < 3; i++)
 
272
    {
 
273
        for(int j = 0; j < 3; j++)
 
274
        {
 
275
            ret = m_MtxInput[i][j]->ProcessEvent(ievent, ret, ProcessEventInfo);
 
276
        }
 
277
    }
 
278
    ret = m_IdentityMtxBtn->ProcessEvent(ievent, ret, ProcessEventInfo);
 
279
    ret = m_ZeroMtxBtn->ProcessEvent(ievent, ret, ProcessEventInfo);
 
280
    ret = m_InverseMtxBtn->ProcessEvent(ievent, ret, ProcessEventInfo);
 
281
    ret = m_NegateMtxBtn->ProcessEvent(ievent, ret, ProcessEventInfo);
 
282
 
 
283
    ret = PostProcessEvent2(ievent, ret, ProcessEventInfo);
 
284
    return ret;
 
285
}
 
286
 
 
287
void Matrix3Editor::Draw(GraphicsContext& GfxContext, bool force_draw)
 
288
{
 
289
    Geometry base = GetGeometry();
 
290
 
 
291
    for(int i = 0; i < 3; i++)
 
292
    {
 
293
        for(int j = 0; j < 3; j++)
 
294
        {
 
295
            m_MtxInput[i][j]->NeedRedraw();
 
296
        }
 
297
    }
 
298
 
 
299
    m_IdentityMtxBtn->NeedRedraw();
 
300
    m_ZeroMtxBtn->NeedRedraw();
 
301
    m_InverseMtxBtn->NeedRedraw();
 
302
    m_NegateMtxBtn->NeedRedraw();
 
303
    //gPainter.PopBackground();
 
304
 
 
305
    //gPainter.PopBackground();
 
306
}
 
307
 
 
308
void Matrix3Editor::DrawContent(GraphicsContext& GfxContext, bool force_draw)
 
309
{
 
310
    Geometry base = GetGeometry();
 
311
    if(force_draw)
 
312
        gPainter.PushDrawShapeLayer(GfxContext, mtx_layout->GetGeometry(), eSHAPE_CORNER_ROUND4, Color(0xFF000000), eAllCorners);
 
313
    else
 
314
        gPainter.PushShapeLayer(GfxContext, mtx_layout->GetGeometry(), eSHAPE_CORNER_ROUND4, Color(0xFF000000), eAllCorners);
 
315
 
 
316
    for(int i = 0; i < 3; i++)
 
317
    {
 
318
        for(int j = 0; j < 3; j++)
 
319
        {
 
320
            m_MtxInput[i][j]->ProcessDraw(GfxContext, force_draw);
 
321
        }
 
322
    }
 
323
 
 
324
    m_IdentityMtxBtn->ProcessDraw(GfxContext, force_draw);
 
325
    m_ZeroMtxBtn->ProcessDraw(GfxContext, force_draw);
 
326
    m_InverseMtxBtn->ProcessDraw(GfxContext, force_draw);
 
327
    m_NegateMtxBtn->ProcessDraw(GfxContext, force_draw);
 
328
    gPainter.PopBackground();
 
329
}
 
330
 
 
331
void Matrix3Editor::PostDraw(GraphicsContext& GfxContext, bool force_draw)
 
332
{
 
333
 
 
334
}
 
335
 
 
336
void Matrix3Editor::SetParameterName(const char* parameter_name)
 
337
{
 
338
    NeedRedraw();
 
339
}
 
340
 
 
341
/////////////////
 
342
//  RECEIVERS  //
 
343
/////////////////
 
344
void Matrix3Editor::EmitIncrementComponent(int index) 
 
345
 
346
 
 
347
    //sigSetVector.emit(m_x, m_y, m_z, m_w);
 
348
}
 
349
 
 
350
void Matrix3Editor::EmitDecrementComponent(int index)
 
351
{
 
352
 
 
353
    //sigSetVector.emit(m_x, m_y, m_z, m_w);
 
354
}
 
355
 
 
356
void Matrix3Editor::EmitComponentValue(float f, int index)
 
357
{
 
358
 
 
359
    //sigSetVector.emit(m_x, m_y, m_z, m_w);
 
360
}
 
361
 
 
362
 
 
363
void Matrix3Editor::RecvIdentityMatrixCmd()
 
364
{
 
365
    m_Matrix.Identity();
 
366
    WriteMatrix();
 
367
    sigMatrixChanged.emit(smptr(Matrix3Editor)(this, false));
 
368
 
 
369
    NeedRedraw();
 
370
}
 
371
 
 
372
void Matrix3Editor::RecvZeroMatrixCmd()
 
373
{
 
374
    m_Matrix.Zero();
 
375
    WriteMatrix();
 
376
    sigMatrixChanged.emit(smptr(Matrix3Editor)(this, false));
 
377
 
 
378
    NeedRedraw();
 
379
}
 
380
 
 
381
void Matrix3Editor::RecvInverseMatrixCmd()
 
382
{
 
383
    m_Matrix.Zero();
 
384
    WriteMatrix();
 
385
    sigMatrixChanged.emit(smptr(Matrix3Editor)(this, false));
 
386
 
 
387
    NeedRedraw();
 
388
}
 
389
 
 
390
void Matrix3Editor::RecvNegateMatrixCmd()
 
391
{
 
392
    m_Matrix = -m_Matrix;
 
393
    WriteMatrix();
 
394
    sigMatrixChanged.emit(smptr(Matrix3Editor)(this, false));
 
395
 
 
396
    NeedRedraw();
 
397
}
 
398
 
 
399
 
 
400
NAMESPACE_END_GUI