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: 26780 $
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 #ifdef NW_LYT_DMPGL_ENABLED
691 void
Draw(const DrawInfo & drawInfo)692 Pane::Draw(const DrawInfo& drawInfo)
693 {
694 if (! IsVisible())
695 {
696 return;
697 }
698
699 DrawSelf(drawInfo);
700
701 // 子供の描画
702 for (PaneList::Iterator it = m_ChildList.GetBeginIter(); it != m_ChildList.GetEndIter(); ++it)
703 {
704 it->Draw(drawInfo);
705 }
706 }
707 #endif
708
709 #ifdef NW_LYT_DMPGL_ENABLED
710 void
DrawSelf(const DrawInfo & drawInfo)711 Pane::DrawSelf(const DrawInfo& drawInfo)
712 {
713 #if defined(NW_RELEASE)
714
715 NW_UNUSED_VARIABLE(drawInfo)
716
717 #else // #if ! defined(NW_RELEASE)
718
719 if (m_pParent && drawInfo.IsDebugDrawMode()) // 枠の描画
720 {
721 // 行列
722 LoadMtx(drawInfo);
723
724 internal::DrawLine(drawInfo, GetVtxPos(), m_Size, ut::Color8::GREEN);
725
726 drawInfo.GetGraphicsResource()->ResetGlState();
727 }
728
729 #endif // #if ! defined(NW_RELEASE)
730 }
731 #endif // NW_LYT_DMPGL_ENABLED
732
733 void
Animate(u32 option)734 Pane::Animate(u32 option)
735 {
736 AnimateSelf(option);
737
738 if ( IsVisible()
739 || 0 == (option & ANIMATEOPT_NOANIMATEINVISIBLE)
740 )
741 {
742 // 子供のアニメーション
743 for (PaneList::Iterator it = m_ChildList.GetBeginIter(); it != m_ChildList.GetEndIter(); ++it)
744 {
745 it->Animate(option);
746 }
747 }
748 }
749
750 void
AnimateSelf(u32 option)751 Pane::AnimateSelf(u32 option)
752 {
753 for (AnimationList::Iterator it = m_AnimList.GetBeginIter(); it != m_AnimList.GetEndIter(); ++it)
754 {
755 if (it->IsEnable())
756 {
757 AnimTransform* animTrans = it->GetAnimTransform();
758 animTrans->Animate(it->GetIndex(), this);
759 }
760 }
761
762 if ( IsVisible()
763 || 0 == (option & ANIMATEOPT_NOANIMATEINVISIBLE)
764 )
765 {
766 u32 nbMaterial = GetMaterialNum();
767 for (u32 idx = 0; idx < nbMaterial; ++idx)
768 {
769 Material* pMaterial = GetMaterial(idx);
770 if (pMaterial)
771 {
772 pMaterial->Animate();
773 }
774 }
775 }
776 }
777
778 void
BindAnimation(AnimTransform * pAnimTrans,bool bRecursive,bool bDisable)779 Pane::BindAnimation(
780 AnimTransform* pAnimTrans,
781 bool bRecursive,
782 bool bDisable
783 )
784 {
785 NW_NULL_ASSERT(pAnimTrans);
786
787 pAnimTrans->Bind(this, bRecursive, bDisable);
788 }
789
790 void
UnbindAnimation(AnimTransform * pAnimTrans,bool bRecursive)791 Pane::UnbindAnimation(
792 AnimTransform* pAnimTrans,
793 bool bRecursive
794 )
795 {
796 UnbindAnimationSelf(pAnimTrans);
797
798 // 再帰的にたどる
799 if (bRecursive)
800 {
801 for (PaneList::Iterator it = m_ChildList.GetBeginIter(); it != m_ChildList.GetEndIter(); ++it)
802 {
803 it->UnbindAnimation(pAnimTrans, bRecursive);
804 }
805 }
806 }
807
808 void
UnbindAllAnimation(bool bRecursive)809 Pane::UnbindAllAnimation(bool bRecursive)
810 {
811 UnbindAnimation(0, bRecursive);
812 }
813
814 void
UnbindAnimationSelf(AnimTransform * pAnimTrans)815 Pane::UnbindAnimationSelf(AnimTransform* pAnimTrans)
816 {
817 u32 nbMaterial = GetMaterialNum();
818 for (u32 idx = 0; idx < nbMaterial; ++idx)
819 {
820 Material* pMaterial = GetMaterial(idx);
821 if (pMaterial)
822 {
823 pMaterial->UnbindAnimation(pAnimTrans);
824 }
825 }
826
827 internal::UnbindAnimationLink(&m_AnimList, pAnimTrans);
828 }
829
830 void
AddAnimationLink(AnimationLink * pAnimationLink)831 Pane::AddAnimationLink(AnimationLink* pAnimationLink)
832 {
833 NW_NULL_ASSERT(pAnimationLink);
834
835 m_AnimList.PushBack(pAnimationLink);
836 }
837
838 AnimationLink*
FindAnimationLinkSelf(AnimTransform * pAnimTrans)839 Pane::FindAnimationLinkSelf(AnimTransform* pAnimTrans)
840 {
841 return internal::FindAnimationLink(&m_AnimList, pAnimTrans);
842 }
843
844 AnimationLink*
FindAnimationLinkSelf(const AnimResource & animRes)845 Pane::FindAnimationLinkSelf(const AnimResource& animRes)
846 {
847 return internal::FindAnimationLink(&m_AnimList, animRes);
848 }
849
850 void
SetAnimationEnable(AnimTransform * pAnimTrans,bool bEnable,bool bRecursive)851 Pane::SetAnimationEnable(
852 AnimTransform* pAnimTrans,
853 bool bEnable,
854 bool bRecursive
855 )
856 {
857 if (AnimationLink* pAnimLink = FindAnimationLinkSelf(pAnimTrans))
858 {
859 pAnimLink->SetEnable(bEnable);
860 }
861
862 const u32 materialNum = GetMaterialNum();
863 for (u32 i = 0; i < materialNum; ++i)
864 {
865 GetMaterial(i)->SetAnimationEnable(pAnimTrans, bEnable);
866 }
867
868 // 再帰的にたどる
869 if (bRecursive)
870 {
871 for (PaneList::Iterator it = m_ChildList.GetBeginIter(); it != m_ChildList.GetEndIter(); ++it)
872 {
873 it->SetAnimationEnable(pAnimTrans, bEnable, bRecursive);
874 }
875 }
876 }
877
878 void
SetAnimationEnable(const AnimResource & animRes,bool bEnable,bool bRecursive)879 Pane::SetAnimationEnable(
880 const AnimResource& animRes,
881 bool bEnable,
882 bool bRecursive
883 )
884 {
885 if (AnimationLink* pAnimLink = FindAnimationLinkSelf(animRes))
886 {
887 pAnimLink->SetEnable(bEnable);
888 }
889
890 const u32 materialNum = GetMaterialNum();
891 for (u32 i = 0; i < materialNum; ++i)
892 {
893 GetMaterial(i)->SetAnimationEnable(animRes, bEnable);
894 }
895
896 // 再帰的にたどる
897 if (bRecursive)
898 {
899 for (PaneList::Iterator it = m_ChildList.GetBeginIter(); it != m_ChildList.GetEndIter(); ++it)
900 {
901 it->SetAnimationEnable(animRes, bEnable, bRecursive);
902 }
903 }
904 }
905
906 #ifdef NW_LYT_DMPGL_ENABLED
907 void
LoadMtx(const DrawInfo & drawInfo)908 Pane::LoadMtx(const DrawInfo& drawInfo)
909 {
910 GraphicsResource& graphicsResource = *drawInfo.GetGraphicsResource();
911 graphicsResource.SetMtxModelView(this->GetGlobalMtx());
912 }
913 #endif
914
915 const math::VEC2
GetVtxPos() const916 Pane::GetVtxPos() const
917 {
918 VEC2 basePt(0, 0);
919
920 switch (this->GetBasePositionH())
921 {
922 case HORIZONTALPOSITION_LEFT:
923 default: basePt.x = 0; break;
924 case HORIZONTALPOSITION_CENTER: basePt.x = - m_Size.width / 2; break;
925 case HORIZONTALPOSITION_RIGHT: basePt.x = - m_Size.width; break;
926 }
927
928 switch (this->GetBasePositionV())
929 {
930 case VERTICALPOSITION_TOP:
931 default: basePt.y = 0; break;
932 case VERTICALPOSITION_CENTER: basePt.y = m_Size.height / 2; break;
933 case VERTICALPOSITION_BOTTOM: basePt.y = m_Size.height; break;
934 }
935
936 return basePt;
937 }
938
939 Material*
GetMaterial() const940 Pane::GetMaterial() const
941 {
942 if (GetMaterialNum() > 0)
943 {
944 return GetMaterial(0);
945 }
946 else
947 {
948 return 0;
949 }
950 }
951
952 u8
GetMaterialNum() const953 Pane::GetMaterialNum() const
954 {
955 return 0;
956 }
957
958 Material*
GetMaterial(u32 idx) const959 Pane::GetMaterial(u32 idx) const
960 {
961 NW_UNUSED_VARIABLE(idx);
962 NW_WARNING(idx < GetMaterialNum(), "idx >= GetMaterialNum() : %d >= %d", idx, GetMaterialNum());
963
964 return 0;
965 }
966
967 u16
GetExtUserDataNum() const968 Pane::GetExtUserDataNum() const
969 {
970 if (! m_pExtUserDataList)
971 {
972 return 0;
973 }
974
975 return m_pExtUserDataList->num;
976 }
977
978 const ExtUserData*
GetExtUserDataArray() const979 Pane::GetExtUserDataArray() const
980 {
981 if (! m_pExtUserDataList)
982 {
983 return 0;
984 }
985
986 return internal::ConvertOffsToPtr<const ExtUserData>(m_pExtUserDataList, sizeof(*m_pExtUserDataList));
987 }
988
989 const ExtUserData*
FindExtUserDataByName(const char * name)990 Pane::FindExtUserDataByName(const char* name)
991 {
992 const ExtUserData* pExtUserData = GetExtUserDataArray();
993 if (! pExtUserData)
994 {
995 return 0;
996 }
997
998 for (int i = 0; i < m_pExtUserDataList->num; ++i, ++pExtUserData)
999 {
1000 if (0 == std::strcmp(name, pExtUserData->GetName()))
1001 {
1002 return pExtUserData;
1003 }
1004 }
1005
1006 return 0;
1007 }
1008
1009 } // namespace nw::lyt
1010 } // namespace nw
1011