1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: lyt_Pane.cpp
4
5 Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Revision: 25594 $
14 *---------------------------------------------------------------------------*/
15
16 #include "precompiled.h"
17
18 #include <nw/lyt/lyt_Common.h>
19 #include <nw/lyt/lyt_Pane.h>
20 #include <nw/lyt/lyt_DrawInfo.h>
21 #include <nw/lyt/lyt_GraphicsResource.h>
22 #include <nw/lyt/lyt_Layout.h>
23 #include <nw/lyt/lyt_Animation.h>
24 #include <nw/lyt/lyt_Material.h>
25
26 using namespace nw::math;
27
28 namespace nw
29 {
30 namespace lyt
31 {
32 namespace internal
33 {
34
PaneBase()35 PaneBase::PaneBase()
36 {
37 }
38
~PaneBase()39 PaneBase::~PaneBase()
40 {
41 }
42
43 } // namespace nw::lyt::internal
44
45 namespace local
46 {
47 namespace
48 {
49
50 #ifndef NW_PLATFORM_CTR
51
52 inline void
MultMatrixSRTxST(NW_LYT_WRITEONLY nw::math::MTX34 * __restrict pMtx,const nw::math::MTX34 * __restrict pMtxParent,const nw::math::VEC2 * __restrict pScale,const nw::math::VEC3 * __restrict pTransform)53 MultMatrixSRTxST(
54 NW_LYT_WRITEONLY nw::math::MTX34* __restrict pMtx,
55 const nw::math::MTX34* __restrict pMtxParent,
56 const nw::math::VEC2* __restrict pScale,
57 const nw::math::VEC3* __restrict pTransform)
58 {
59 //Ma . Mb
60 //
61 // = [ a00 a01 a02 a03 ] . [ b00 0 0 b03 ]
62 // [ ] [ ]
63 // [ a10 a11 a12 a13 ] [ 0 b11 0 b13 ]
64 // [ ] [ ]
65 // [ a20 a21 a22 a23 ] [ 0 0 1 b23 ]
66 // [ ] [ ]
67 // [ 0 0 0 1 ] [ 0 0 0 1 ]
68 //
69 // = [ a00*b00 a01*b11 a02 a02*b23 + a01*b13 + a00*b03 + a03 ]
70 // [ ]
71 // [ a10*b00 a11*b11 a12 a12*b23 + a11*b13 + a10*b03 + a13 ]
72 // [ ]
73 // [ a20*b00 a21*b11 a22 a22*b23 + a21*b13 + a20*b03 + a23 ]
74 // [ ]
75 // [ 0 0 0 1 ]
76
77 register const f32 b00 = pScale->x;
78 register const f32 b11 = pScale->y;
79 register const f32 b03 = pTransform->x;
80 register const f32 b13 = pTransform->y;
81 register const f32 b23 = pTransform->z;
82
83 register const f32 a00 = pMtxParent->m[0][0];
84 register const f32 a01 = pMtxParent->m[0][1];
85 register const f32 a02 = pMtxParent->m[0][2];
86 register const f32 a03 = pMtxParent->m[0][3];
87
88 register const f32 a10 = pMtxParent->m[1][0];
89 register const f32 a11 = pMtxParent->m[1][1];
90 register const f32 a12 = pMtxParent->m[1][2];
91 register const f32 a13 = pMtxParent->m[1][3];
92
93 register const f32 a20 = pMtxParent->m[2][0];
94 register const f32 a21 = pMtxParent->m[2][1];
95 register const f32 a22 = pMtxParent->m[2][2];
96 register const f32 a23 = pMtxParent->m[2][3];
97
98 pMtx->m[0][0] = a00 * b00;
99 pMtx->m[0][1] = a01 * b11;
100 pMtx->m[0][2] = a02;
101 pMtx->m[0][3] = a02 * b23 + a01 * b13 + a00 * b03 + a03;
102
103 pMtx->m[1][0] = a10 * b00;
104 pMtx->m[1][1] = a11 * b11;
105 pMtx->m[1][2] = a12;
106 pMtx->m[1][3] = a12 * b23 + a11 * b13 + a10 * b03 + a13;
107
108 pMtx->m[2][0] = a20 * b00;
109 pMtx->m[2][1] = a21 * b11;
110 pMtx->m[2][2] = a22;
111 pMtx->m[2][3] = a22 * b23 + a21 * b13 + a20 * b03 + a23;
112 }
113
114 #else // NW_PLATFORM_CTR
115
116 #include <nn/hw/ARM/code32.h>
117
118 asm void
119 MultMatrixSRTxST(
120 NW_LYT_WRITEONLY nw::math::MTX34* __restrict /*pMtx*/,
121 const nw::math::MTX34* __restrict /*pMtxParent*/,
122 const nw::math::VEC2* __restrict /*pScale*/,
123 const nw::math::VEC3* __restrict /*pTransform*/)
124 {
125 //Ma . Mb
126 //
127 // = [ a00 a01 a02 a03 ] . [ b00 0 0 b03 ]
128 // [ ] [ ]
129 // [ a10 a11 a12 a13 ] [ 0 b11 0 b13 ]
130 // [ ] [ ]
131 // [ a20 a21 a22 a23 ] [ 0 0 1 b23 ]
132 // [ ] [ ]
133 // [ 0 0 0 1 ] [ 0 0 0 1 ]
134 //
135 // = [ a00*b00 a01*b11 a02 a02*b23 + a01*b13 + a00*b03 + a03 ]
136 // [ ]
137 // [ a10*b00 a11*b11 a12 a12*b23 + a11*b13 + a10*b03 + a13 ]
138 // [ ]
139 // [ a20*b00 a21*b11 a22 a22*b23 + a21*b13 + a20*b03 + a23 ]
140 // [ ]
141 // [ 0 0 0 1 ]
142
143 #define a00 s0
144 #define a01 s1
145 #define a02 s2
146 #define a03 s3
147 #define a10 s4
148 #define a11 s5
149 #define a12 s6
150 #define a13 s7
151 #define a20 s8
152 #define a21 s9
153 #define a22 s10
154 #define a23 s11
155 #define b00 s12
156 #define b11 s13
157 #define b03 s12
158 #define b13 s13
159 #define b23 s14
160
161 VLDMIA r1,{a00-a23}
162 VLDMIA r3,{b03,b13,b23}
163
164 VMLA.F32 a03,a00,b03
165 VMLA.F32 a13,a10,b03
166 VMLA.F32 a23,a20,b03
167
168 VMLA.F32 a03,a01,b13
169 VMLA.F32 a13,a11,b13
170 VMLA.F32 a23,a21,b13
171
172 VMLA.F32 a03,a02,b23
173 VLDMIA r2,{b00,b11}
174 VMLA.F32 a13,a12,b23
175 VMLA.F32 a23,a22,b23
176
177 VMUL.F32 a00,a00,b00
178 VMUL.F32 a01,a01,b11
179
180 VMUL.F32 a10,a10,b00
181 VMUL.F32 a11,a11,b11
182
183 VMUL.F32 a20,a20,b00
184 VMUL.F32 a21,a21,b11
185
186 VSTMIA r0,{a00-a23} // 結果をストア
187 BX lr
188
189 #undef a00
190 #undef a01
191 #undef a02
192 #undef a03
193 #undef a10
194 #undef a11
195 #undef a12
196 #undef a13
197 #undef a20
198 #undef a21
199 #undef a22
200 #undef a23
201 #undef b00
202 #undef b11
203 #undef b03
204 #undef b13
205 #undef b23
206 }
207
208 #include <nn/hw/ARM/codereset.h>
209
210 #endif // NW_PLATFORM_CTR
211
212 // Scale、Rotate、Transの設定
213 inline void
MakeMatrixSRT(NW_LYT_WRITEONLY nw::math::MTX34 & o,const nw::math::VEC2 & s,const f32 rotateZ,const nw::math::VEC3 & t)214 MakeMatrixSRT(NW_LYT_WRITEONLY nw::math::MTX34& o, const nw::math::VEC2& s, const f32 rotateZ, const nw::math::VEC3& t)
215 {
216 register f32 sin, cos;
217
218 nn::math::SinCosDeg(&sin, &cos, rotateZ);
219
220 const f32 tmp0 = s.x * cos;
221 const f32 tmp1 = -s.y * sin;
222 const f32 tmp2 = s.x * sin;
223 const f32 tmp3 = s.y * cos;
224
225 o.m[0][0] = tmp0;
226 o.m[0][1] = tmp1;
227 o.m[0][2] = 0.f;
228 o.m[0][3] = t.x;
229
230 o.m[1][0] = tmp2;
231 o.m[1][1] = tmp3;
232 o.m[1][2] = 0.f;
233 o.m[1][3] = t.y;
234
235 o.m[2][0] = 0.f;
236 o.m[2][1] = 0.f;
237 o.m[2][2] = 1.f;
238 o.m[2][3] = t.z;
239 }
240
241 inline void
MakeMatrixSRT(NW_LYT_WRITEONLY nw::math::MTX34 & o,const nw::math::VEC2 & s,const nw::math::VEC3 & r,const nw::math::VEC3 & t)242 MakeMatrixSRT(NW_LYT_WRITEONLY nw::math::MTX34& o, const nw::math::VEC2& s, const nw::math::VEC3& r, const nw::math::VEC3& t)
243 {
244 register f32 sinx, cosx;
245 register f32 siny, cosy;
246 register f32 sinz, cosz;
247
248 nn::math::SinCosDeg(&sinx, &cosx, r.x);
249 nn::math::SinCosDeg(&siny, &cosy, r.y);
250 nn::math::SinCosDeg(&sinz, &cosz, r.z);
251
252 const f32 opt1 = cosx * cosz;
253 const f32 opt2 = sinx * siny;
254 const f32 opt3 = cosx * sinz;
255
256 const f32 tmp00 = s.x * (cosy * cosz);
257 const f32 tmp10 = s.x * (cosy * sinz);
258 const f32 tmp20 = s.x * (-siny);
259
260 const f32 tmp01 = s.y * ((opt2 * cosz) - (opt3));
261 const f32 tmp11 = s.y * ((opt2 * sinz) + (opt1));
262 const f32 tmp21 = s.y * ((sinx * cosy));
263
264 const f32 tmp02 = (opt1 * siny) + (sinx * sinz);
265 const f32 tmp12 = (opt3 * siny) - (sinx * cosz);
266 const f32 tmp22 = (cosx * cosy);
267
268 o.m[0][0] = tmp00;
269 o.m[0][1] = tmp01;
270 o.m[0][2] = tmp02;
271 o.m[0][3] = t.x;
272
273 o.m[1][0] = tmp10;
274 o.m[1][1] = tmp11;
275 o.m[1][2] = tmp12;
276 o.m[1][3] = t.y;
277
278 o.m[2][0] = tmp20;
279 o.m[2][1] = tmp21;
280 o.m[2][2] = tmp22;
281 o.m[2][3] = t.z;
282 }
283
284 } // namespace nw::lyt::local::{anonymous}
285 } // namespace nw::lyt::local
286
287 NW_UT_RUNTIME_TYPEINFO_ROOT_DEFINITION(Pane); // 実行時型情報の実体を定義
288
Pane()289 Pane::Pane()
290 {
291 NW_COMPILER_ASSERT(
292 (sizeof(m_Translate) + sizeof(m_Rotate) + sizeof(m_Scale) + sizeof(m_Size)) / sizeof(f32) == ANIMTARGET_PANE_MAX
293 );
294
295 using namespace std;
296
297 Init();
298
299 m_BasePosition =
300 HORIZONTALPOSITION_CENTER
301 + VERTICALPOSITION_CENTER * VERTICALPOSITION_MAX;
302 memset(m_Name, 0, sizeof(m_Name));
303 memset(m_UserData, 0, sizeof(m_UserData));
304
305 m_Translate = VEC3(0, 0, 0);
306 m_Rotate = VEC3(0, 0, 0);
307 m_Scale = VEC2(1, 1);
308 m_Size = Size(0.f, 0.f);
309 m_Alpha = ut::Color8::ALPHA_MAX;
310 m_GlbAlpha = m_Alpha;
311
312 SetVisible(true);
313 }
314
Pane(const res::Pane * pBlock)315 Pane::Pane(const res::Pane* pBlock)
316 {
317 using namespace std;
318
319 Init();
320
321 m_BasePosition = pBlock->basePosition;
322 SetName(pBlock->name);
323 SetUserData(pBlock->userData);
324
325 m_Translate = pBlock->translate;
326 m_Rotate = pBlock->rotate;
327 m_Scale = pBlock->scale;
328 m_Size = pBlock->size;
329 m_Alpha = pBlock->alpha;
330 m_GlbAlpha = m_Alpha;
331
332 m_Flag = pBlock->flag;
333 }
334
335 void
Init()336 Pane::Init()
337 {
338 m_pParent = 0;
339 m_Flag = 0;
340 m_pExtUserDataList = 0;
341 #ifdef NW_LYT_FULLCACHEDRAWMANAGER_ENABLE
342 m_UniversalFlag = 0;
343 #endif
344 MTX34Identity(&m_Mtx);
345 MTX34Identity(&m_GlbMtx);
346 }
347
~Pane()348 Pane::~Pane()
349 {
350 // OSReport("Pane::~Pane()\n");
351
352 // 子供Paneの後処理
353 for (PaneList::Iterator it = m_ChildList.GetBeginIter(); it != m_ChildList.GetEndIter();)
354 {
355 PaneList::Iterator currIt = it++;
356 m_ChildList.Erase(currIt);
357 if (! currIt->IsUserAllocated())
358 {
359 Layout::DeleteObj(&(*currIt));
360 }
361 }
362
363 UnbindAnimationSelf(0);
364 }
365
366 void
SetName(const char * name)367 Pane::SetName(const char* name)
368 {
369 ut::strcpy(m_Name, sizeof(m_Name), name);
370 }
371
372 void
SetUserData(const char * userData)373 Pane::SetUserData(const char* userData)
374 {
375 ut::strcpy(m_UserData, sizeof(m_UserData), userData);
376 }
377
378 void
AppendChild(Pane * pChild)379 Pane::AppendChild(Pane* pChild)
380 {
381 InsertChild(m_ChildList.GetEndIter(), pChild);
382 }
383
384 void
PrependChild(Pane * pChild)385 Pane::PrependChild(Pane* pChild)
386 {
387 InsertChild(m_ChildList.GetBeginIter(), pChild);
388 }
389
390 void
InsertChild(Pane * pNext,Pane * pChild)391 Pane::InsertChild(
392 Pane* pNext,
393 Pane* pChild
394 )
395 {
396 NW_NULL_ASSERT(pNext);
397 NW_ASSERT(pNext->m_pParent == this);
398
399 InsertChild(m_ChildList.GetIteratorFromPointer(pNext), pChild);
400 }
401
402 void
InsertChild(PaneList::Iterator next,Pane * pChild)403 Pane::InsertChild(
404 PaneList::Iterator next,
405 Pane* pChild
406 )
407 {
408 NW_NULL_ASSERT(pChild);
409 NW_ASSERT(pChild->m_pParent == 0);
410
411 m_ChildList.Insert(next, pChild);
412 pChild->m_pParent = this;
413 }
414
415 void
RemoveChild(Pane * pChild)416 Pane::RemoveChild(Pane* pChild)
417 {
418 NW_NULL_ASSERT(pChild);
419 NW_ASSERT(pChild->m_pParent == this);
420
421 m_ChildList.Erase(pChild);
422 pChild->m_pParent = NULL;
423 }
424
425 const ut::Rect
GetPaneRect() const426 Pane::GetPaneRect() const
427 {
428 ut::Rect ret;
429 VEC2 basePt = GetVtxPos();
430
431 ret.left = basePt.x;
432 ret.top = basePt.y;
433 ret.right = ret.left + m_Size.width;
434 ret.bottom = ret.top - m_Size.height;
435
436 return ret;
437 }
438
439 const ut::Color8
GetVtxColor(u32 idx) const440 Pane::GetVtxColor(u32 idx) const
441 {
442 NW_UNUSED_VARIABLE(idx)
443
444 return ut::Color8::WHITE;
445 }
446
447 void
SetVtxColor(u32 idx,ut::Color8 value)448 Pane::SetVtxColor(
449 u32 idx,
450 ut::Color8 value
451 )
452 {
453 NW_UNUSED_VARIABLE(idx)
454 NW_UNUSED_VARIABLE(value)
455 }
456
457 u8
GetColorElement(u32 idx) const458 Pane::GetColorElement(u32 idx) const
459 {
460 NW_ASSERT(idx < ANIMTARGET_PANE_COLOR_MAX);
461
462 switch (idx)
463 {
464 case ANIMTARGET_PANE_ALPHA:
465 return m_Alpha;
466 default:
467 return GetVtxColorElement(idx);
468 }
469 }
470
471 void
SetColorElement(u32 idx,u8 value)472 Pane::SetColorElement(
473 u32 idx,
474 u8 value
475 )
476 {
477 NW_ASSERT(idx < ANIMTARGET_PANE_COLOR_MAX);
478
479 switch (idx)
480 {
481 case ANIMTARGET_PANE_ALPHA:
482 m_Alpha = value;
483 break;
484 default:
485 SetVtxColorElement(idx, value);
486 }
487 }
488
489 u8
GetVtxColorElement(u32 idx) const490 Pane::GetVtxColorElement(u32 idx) const
491 {
492 NW_UNUSED_VARIABLE(idx)
493 return ut::Color8::ELEMENT_MAX;
494 }
495
496 void
SetVtxColorElement(u32 idx,u8 value)497 Pane::SetVtxColorElement(
498 u32 idx,
499 u8 value)
500 {
501 NW_UNUSED_VARIABLE(idx)
502 NW_UNUSED_VARIABLE(value)
503 }
504
505 Pane*
FindPaneByName(const char * findName,bool bRecursive)506 Pane::FindPaneByName(
507 const char* findName,
508 bool bRecursive
509 )
510 {
511 if (internal::EqualsResName(m_Name, findName))
512 {
513 return this;
514 }
515
516 if (bRecursive)
517 {
518 // 子供に一致するものが無いか検索
519 for (PaneList::Iterator it = m_ChildList.GetBeginIter(); it != m_ChildList.GetEndIter(); ++it)
520 {
521 if (Pane* pPane = it->FindPaneByName(findName, bRecursive))
522 {
523 return pPane;
524 }
525 }
526 }
527
528 return 0;
529 }
530
531 Material*
FindMaterialByName(const char * findName,bool bRecursive)532 Pane::FindMaterialByName(
533 const char* findName,
534 bool bRecursive
535 )
536 {
537 u32 nbMaterial = GetMaterialNum();
538 for (u32 idx = 0; idx < nbMaterial; ++idx)
539 {
540 Material* pMaterial = GetMaterial(idx);
541 if (pMaterial)
542 {
543 if (internal::EqualsMaterialName(pMaterial->GetName(), findName))
544 {
545 return pMaterial;
546 }
547 }
548 }
549
550 if (bRecursive)
551 {
552 // 子供に一致するものが無いか検索
553 for (PaneList::Iterator it = m_ChildList.GetBeginIter(); it != m_ChildList.GetEndIter(); ++it)
554 {
555 if (Material* pMat = it->FindMaterialByName(findName, bRecursive))
556 {
557 return pMat;
558 }
559 }
560 }
561
562 return 0;
563 }
564
565 void
CalculateMtx(const DrawInfo & drawInfo)566 Pane::CalculateMtx(const DrawInfo& drawInfo)
567 {
568 if (! IsVisible() && ! drawInfo.IsInvisiblePaneCalculateMtx())
569 {
570 return;
571 }
572
573 if (!this->IsUserGlobalMtx())
574 {
575 // 行列計算
576 // m_Mtx = T * Rz * Ry * Rx * S
577
578 const math::MTX34* pParentMtx = NULL;
579 if (m_pParent)
580 {
581 pParentMtx = &m_pParent->m_GlbMtx;
582 }
583 else
584 {
585 pParentMtx = &drawInfo.GetViewMtx();
586 }
587
588 // 行列の計算
589 if (this->IsUserMtx())
590 {
591 math::MTX34Mult(&m_GlbMtx, pParentMtx, &m_Mtx);
592 }
593 else
594 {
595 MtxCondition mtxCondition = MTXCONDITION_CLEAN;
596 math::VEC2 scale;
597
598 {
599 // RVCTコンパイラ対策。
600 //
601 // 構造体のコピーは整数レジスタで行われるため、
602 // 読み込んだ値を浮動小数点数演算に利用できない。
603 // メモリに書き込んだものを再度、浮動小数点レジスタで読み直す必要がある。
604 //
605 // 明示的に浮動小数点として読み込み、計算結果をストアする。
606 //
607 register f32 sx = this->GetScale().x;
608 register f32 sy = this->GetScale().y;
609
610 if (drawInfo.IsLocationAdjust() && this->IsLocationAdjust())
611 {
612 mtxCondition = MTXCONDITION_CLEAN_LOCATION_ADJUST;
613 sx *= drawInfo.GetLocationAdjustScale().x;
614 sy *= drawInfo.GetLocationAdjustScale().y;
615 }
616
617 scale.Set(sx, sy);
618 }
619
620 if (m_Rotate.x != 0 || m_Rotate.y != 0)
621 { // XY回転有り
622 if (this->GetMtxCondition() != mtxCondition)
623 {
624 this->SetMtxCondition(mtxCondition);
625 local::MakeMatrixSRT(m_Mtx, scale, m_Rotate, m_Translate);
626 }
627
628 math::MTX34Mult(&m_GlbMtx, pParentMtx, &m_Mtx);
629 }
630 else if (m_Rotate.z != 0)
631 { // Z回転有り
632 if (this->GetMtxCondition() != mtxCondition)
633 {
634 this->SetMtxCondition(mtxCondition);
635 local::MakeMatrixSRT(m_Mtx, scale, m_Rotate.z, m_Translate);
636 }
637
638 math::MTX34Mult(&m_GlbMtx, pParentMtx, &m_Mtx);
639 }
640 else
641 {
642 local::MultMatrixSRTxST(&m_GlbMtx, pParentMtx, &scale, &m_Translate);
643 }
644 }
645 }
646
647 // アルファの計算
648 if (drawInfo.IsInfluencedAlpha() && m_pParent)
649 {
650 m_GlbAlpha = u8(m_Alpha * drawInfo.GetGlobalAlpha());
651 }
652 else
653 {
654 m_GlbAlpha = m_Alpha;
655 }
656
657 /*
658 PANEFLAG_INFLUENCEDALPHAが立っていて、自分の透明度が255でないなら、
659 drawInfoに累積透明度(0.f - 1.f)をセットして、子供の計算に影響させる。
660 */
661 if (IsInfluencedAlpha() && m_Alpha != ut::Color8::ALPHA_MAX)
662 {
663 const f32 crGlobalAlpha = drawInfo.GetGlobalAlpha();
664 const bool bCrInfluenced = drawInfo.IsInfluencedAlpha();
665 DrawInfo& mtDrawInfo = const_cast<DrawInfo&>(drawInfo);
666 const f32 invAlpha = 1.0f / ut::Color8::ALPHA_MAX;
667 mtDrawInfo.SetGlobalAlpha(crGlobalAlpha * m_Alpha * invAlpha);
668 mtDrawInfo.SetInfluencedAlpha(true);
669
670 // 子供の行列計算
671 for (PaneList::Iterator it = m_ChildList.GetBeginIter(); it != m_ChildList.GetEndIter(); ++it)
672 {
673 it->CalculateMtx(drawInfo);
674 }
675
676 // 変更した値を元に戻す
677 mtDrawInfo.SetGlobalAlpha(crGlobalAlpha);
678 mtDrawInfo.SetInfluencedAlpha(bCrInfluenced);
679 }
680 else
681 {
682 // 子供の行列計算
683 for (PaneList::Iterator it = m_ChildList.GetBeginIter(); it != m_ChildList.GetEndIter(); ++it)
684 {
685 it->CalculateMtx(drawInfo);
686 }
687 }
688 }
689
690 // 子供の行列計算
691 void
CalculateMtxChild(const DrawInfo & drawInfo)692 Pane::CalculateMtxChild(const DrawInfo& drawInfo)
693 {
694 for (PaneList::Iterator it = m_ChildList.GetBeginIter(); it != m_ChildList.GetEndIter(); ++it)
695 {
696 it->CalculateMtx(drawInfo);
697 }
698 }
699
700 #ifdef NW_LYT_DMPGL_ENABLED
701 void
Draw(const DrawInfo & drawInfo)702 Pane::Draw(const DrawInfo& drawInfo)
703 {
704 if (! IsVisible())
705 {
706 return;
707 }
708
709 DrawSelf(drawInfo);
710
711 // 子供の描画
712 for (PaneList::Iterator it = m_ChildList.GetBeginIter(); it != m_ChildList.GetEndIter(); ++it)
713 {
714 it->Draw(drawInfo);
715 }
716 }
717 #endif
718
719 #ifdef NW_LYT_DMPGL_ENABLED
720 void
DrawSelf(const DrawInfo & drawInfo)721 Pane::DrawSelf(const DrawInfo& drawInfo)
722 {
723 #if defined(NW_RELEASE)
724
725 NW_UNUSED_VARIABLE(drawInfo)
726
727 #else // #if ! defined(NW_RELEASE)
728
729 if (m_pParent && drawInfo.IsDebugDrawMode()) // 枠の描画
730 {
731 // 行列
732 LoadMtx(drawInfo);
733
734 internal::DrawLine(drawInfo, GetVtxPos(), m_Size, ut::Color8::GREEN);
735
736 drawInfo.GetGraphicsResource()->ResetGlState();
737 }
738
739 #endif // #if ! defined(NW_RELEASE)
740 }
741 #endif // NW_LYT_DMPGL_ENABLED
742
743 void
Animate(u32 option)744 Pane::Animate(u32 option)
745 {
746 AnimateSelf(option);
747
748 if ( IsVisible()
749 || 0 == (option & ANIMATEOPT_NOANIMATEINVISIBLE)
750 )
751 {
752 // 子供のアニメーション
753 for (PaneList::Iterator it = m_ChildList.GetBeginIter(); it != m_ChildList.GetEndIter(); ++it)
754 {
755 it->Animate(option);
756 }
757 }
758 }
759
760 void
AnimateSelf(u32 option)761 Pane::AnimateSelf(u32 option)
762 {
763 for (AnimationList::Iterator it = m_AnimList.GetBeginIter(); it != m_AnimList.GetEndIter(); ++it)
764 {
765 if (it->IsEnable())
766 {
767 AnimTransform* animTrans = it->GetAnimTransform();
768 animTrans->Animate(it->GetIndex(), this);
769 }
770 }
771
772 if ( IsVisible()
773 || 0 == (option & ANIMATEOPT_NOANIMATEINVISIBLE)
774 )
775 {
776 u32 nbMaterial = GetMaterialNum();
777 for (u32 idx = 0; idx < nbMaterial; ++idx)
778 {
779 Material* pMaterial = GetMaterial(idx);
780 if (pMaterial)
781 {
782 pMaterial->Animate();
783 }
784 }
785 }
786 }
787
788 void
BindAnimation(AnimTransform * pAnimTrans,bool bRecursive,bool bDisable)789 Pane::BindAnimation(
790 AnimTransform* pAnimTrans,
791 bool bRecursive,
792 bool bDisable
793 )
794 {
795 NW_NULL_ASSERT(pAnimTrans);
796
797 pAnimTrans->Bind(this, bRecursive, bDisable);
798 }
799
800 void
UnbindAnimation(AnimTransform * pAnimTrans,bool bRecursive)801 Pane::UnbindAnimation(
802 AnimTransform* pAnimTrans,
803 bool bRecursive
804 )
805 {
806 UnbindAnimationSelf(pAnimTrans);
807
808 // 再帰的にたどる
809 if (bRecursive)
810 {
811 for (PaneList::Iterator it = m_ChildList.GetBeginIter(); it != m_ChildList.GetEndIter(); ++it)
812 {
813 it->UnbindAnimation(pAnimTrans, bRecursive);
814 }
815 }
816 }
817
818 void
UnbindAllAnimation(bool bRecursive)819 Pane::UnbindAllAnimation(bool bRecursive)
820 {
821 UnbindAnimation(0, bRecursive);
822 }
823
824 void
UnbindAnimationSelf(AnimTransform * pAnimTrans)825 Pane::UnbindAnimationSelf(AnimTransform* pAnimTrans)
826 {
827 u32 nbMaterial = GetMaterialNum();
828 for (u32 idx = 0; idx < nbMaterial; ++idx)
829 {
830 Material* pMaterial = GetMaterial(idx);
831 if (pMaterial)
832 {
833 pMaterial->UnbindAnimation(pAnimTrans);
834 }
835 }
836
837 internal::UnbindAnimationLink(&m_AnimList, pAnimTrans);
838 }
839
840 void
AddAnimationLink(AnimationLink * pAnimationLink)841 Pane::AddAnimationLink(AnimationLink* pAnimationLink)
842 {
843 NW_NULL_ASSERT(pAnimationLink);
844
845 m_AnimList.PushBack(pAnimationLink);
846 }
847
848 AnimationLink*
FindAnimationLinkSelf(AnimTransform * pAnimTrans)849 Pane::FindAnimationLinkSelf(AnimTransform* pAnimTrans)
850 {
851 return internal::FindAnimationLink(&m_AnimList, pAnimTrans);
852 }
853
854 AnimationLink*
FindAnimationLinkSelf(const AnimResource & animRes)855 Pane::FindAnimationLinkSelf(const AnimResource& animRes)
856 {
857 return internal::FindAnimationLink(&m_AnimList, animRes);
858 }
859
860 void
SetAnimationEnable(AnimTransform * pAnimTrans,bool bEnable,bool bRecursive)861 Pane::SetAnimationEnable(
862 AnimTransform* pAnimTrans,
863 bool bEnable,
864 bool bRecursive
865 )
866 {
867 if (AnimationLink* pAnimLink = FindAnimationLinkSelf(pAnimTrans))
868 {
869 pAnimLink->SetEnable(bEnable);
870 }
871
872 const u32 materialNum = GetMaterialNum();
873 for (u32 i = 0; i < materialNum; ++i)
874 {
875 GetMaterial(i)->SetAnimationEnable(pAnimTrans, bEnable);
876 }
877
878 // 再帰的にたどる
879 if (bRecursive)
880 {
881 for (PaneList::Iterator it = m_ChildList.GetBeginIter(); it != m_ChildList.GetEndIter(); ++it)
882 {
883 it->SetAnimationEnable(pAnimTrans, bEnable, bRecursive);
884 }
885 }
886 }
887
888 void
SetAnimationEnable(const AnimResource & animRes,bool bEnable,bool bRecursive)889 Pane::SetAnimationEnable(
890 const AnimResource& animRes,
891 bool bEnable,
892 bool bRecursive
893 )
894 {
895 if (AnimationLink* pAnimLink = FindAnimationLinkSelf(animRes))
896 {
897 pAnimLink->SetEnable(bEnable);
898 }
899
900 const u32 materialNum = GetMaterialNum();
901 for (u32 i = 0; i < materialNum; ++i)
902 {
903 GetMaterial(i)->SetAnimationEnable(animRes, bEnable);
904 }
905
906 // 再帰的にたどる
907 if (bRecursive)
908 {
909 for (PaneList::Iterator it = m_ChildList.GetBeginIter(); it != m_ChildList.GetEndIter(); ++it)
910 {
911 it->SetAnimationEnable(animRes, bEnable, bRecursive);
912 }
913 }
914 }
915
916 #ifdef NW_LYT_DMPGL_ENABLED
917 void
LoadMtx(const DrawInfo & drawInfo)918 Pane::LoadMtx(const DrawInfo& drawInfo)
919 {
920 GraphicsResource& graphicsResource = *drawInfo.GetGraphicsResource();
921 graphicsResource.SetMtxModelView(this->GetGlobalMtx());
922 }
923 #endif
924
925 const math::VEC2
GetVtxPos() const926 Pane::GetVtxPos() const
927 {
928 VEC2 basePt(0, 0);
929
930 switch (this->GetBasePositionH())
931 {
932 case HORIZONTALPOSITION_LEFT:
933 default: basePt.x = 0; break;
934 case HORIZONTALPOSITION_CENTER: basePt.x = - m_Size.width / 2; break;
935 case HORIZONTALPOSITION_RIGHT: basePt.x = - m_Size.width; break;
936 }
937
938 switch (this->GetBasePositionV())
939 {
940 case VERTICALPOSITION_TOP:
941 default: basePt.y = 0; break;
942 case VERTICALPOSITION_CENTER: basePt.y = m_Size.height / 2; break;
943 case VERTICALPOSITION_BOTTOM: basePt.y = m_Size.height; break;
944 }
945
946 return basePt;
947 }
948
949 Material*
GetMaterial() const950 Pane::GetMaterial() const
951 {
952 if (GetMaterialNum() > 0)
953 {
954 return GetMaterial(0);
955 }
956 else
957 {
958 return 0;
959 }
960 }
961
962 u8
GetMaterialNum() const963 Pane::GetMaterialNum() const
964 {
965 return 0;
966 }
967
968 Material*
GetMaterial(u32 idx) const969 Pane::GetMaterial(u32 idx) const
970 {
971 NW_UNUSED_VARIABLE(idx);
972 NW_WARNING(idx < GetMaterialNum(), "idx >= GetMaterialNum() : %d >= %d", idx, GetMaterialNum());
973
974 return 0;
975 }
976
977 u16
GetExtUserDataNum() const978 Pane::GetExtUserDataNum() const
979 {
980 if (! m_pExtUserDataList)
981 {
982 return 0;
983 }
984
985 return m_pExtUserDataList->num;
986 }
987
988 const ExtUserData*
GetExtUserDataArray() const989 Pane::GetExtUserDataArray() const
990 {
991 if (! m_pExtUserDataList)
992 {
993 return 0;
994 }
995
996 return internal::ConvertOffsToPtr<const ExtUserData>(m_pExtUserDataList, sizeof(*m_pExtUserDataList));
997 }
998
999 const ExtUserData*
FindExtUserDataByName(const char * name)1000 Pane::FindExtUserDataByName(const char* name)
1001 {
1002 const ExtUserData* pExtUserData = GetExtUserDataArray();
1003 if (! pExtUserData)
1004 {
1005 return 0;
1006 }
1007
1008 for (int i = 0; i < m_pExtUserDataList->num; ++i, ++pExtUserData)
1009 {
1010 if (0 == std::strcmp(name, pExtUserData->GetName()))
1011 {
1012 return pExtUserData;
1013 }
1014 }
1015
1016 return 0;
1017 }
1018
1019 } // namespace nw::lyt
1020 } // namespace nw
1021