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