Skip to content

Commit 26eb1c7

Browse files
author
huairen
committed
change size event and pos event
1 parent 08ec104 commit 26eb1c7

9 files changed

+28
-38
lines changed

src/base/JuiControl.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -103,30 +103,30 @@ void JuiControl::SetBackground(const std::string& drawable)
103103
void JuiControl::SetPosition(const JPoint2I& point)
104104
{
105105
m_rcBounds.position = point;
106-
if(m_pLayoutParam != NULL)
107-
m_pLayoutParam->UpdatePos(m_pParent, m_rcBounds);
106+
if(m_pLayoutParam != NULL && m_pParent != NULL)
107+
m_pLayoutParam->UpdatePos(m_pParent->GetExtent(), m_rcBounds);
108108
}
109109

110110
void JuiControl::SetPosition( int x, int y )
111111
{
112112
m_rcBounds.position.x = x;
113113
m_rcBounds.position.y = y;
114-
if(m_pLayoutParam != NULL)
115-
m_pLayoutParam->UpdatePos(m_pParent, m_rcBounds);
114+
if(m_pLayoutParam != NULL && m_pParent != NULL)
115+
m_pLayoutParam->UpdatePos(m_pParent->GetExtent(), m_rcBounds);
116116
}
117117

118118
void JuiControl::SetPosX(int x)
119119
{
120120
m_rcBounds.position.x = x;
121-
if(m_pLayoutParam != NULL)
122-
m_pLayoutParam->UpdatePos(m_pParent, m_rcBounds);
121+
if(m_pLayoutParam != NULL && m_pParent != NULL)
122+
m_pLayoutParam->UpdatePos(m_pParent->GetExtent(), m_rcBounds);
123123
}
124124

125125
void JuiControl::SetPosY(int y)
126126
{
127127
m_rcBounds.position.y = y;
128-
if(m_pLayoutParam != NULL)
129-
m_pLayoutParam->UpdatePos(m_pParent, m_rcBounds);
128+
if(m_pLayoutParam != NULL && m_pParent != NULL)
129+
m_pLayoutParam->UpdatePos(m_pParent->GetExtent(), m_rcBounds);
130130
}
131131

132132
bool JuiControl::IsPointIn( const JPoint2I& pt )

src/base/JuiControl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class JuiControl : public JObject
131131

132132
virtual void OnKeyDown() {}
133133

134-
virtual void OnSizeChanged(const JPoint2I& newSize) {}
134+
virtual void OnSizeChanged() {}
135135
virtual void OnRender(JPoint2I offset, const JRectI& rcPaint);
136136
// @ }
137137

src/base/JuiControl.inl

+8-14
Original file line numberDiff line numberDiff line change
@@ -40,56 +40,50 @@ inline JuiLayoutParameter * JuiControl::GetLayoutParameter()
4040
//---------------------------------------------------------------------------
4141
inline void JuiControl::SetBounds(const JPoint2I& position, const JPoint2I& extent)
4242
{
43-
if(m_rcBounds.extent != extent)
44-
{
45-
OnSizeChanged(m_rcBounds.extent);
46-
m_rcBounds.extent = extent;
47-
}
48-
m_rcBounds.position = position;
43+
SetPosition(position);
44+
SetExtent(extent);
4945
}
5046

5147
inline void JuiControl::SetBounds( const JRectI& bounds )
5248
{
53-
if(m_rcBounds.extent != bounds.extent)
54-
OnSizeChanged(m_rcBounds.extent);
55-
56-
m_rcBounds = bounds;
49+
SetPosition(bounds.position);
50+
SetExtent(bounds.extent);
5751
}
5852

5953
inline void JuiControl::SetExtent(const JPoint2I& size)
6054
{
6155
if(m_rcBounds.extent != size)
6256
{
63-
OnSizeChanged(size);
6457
m_rcBounds.extent = size;
58+
OnSizeChanged();
6559
}
6660
}
6761

6862
inline void JuiControl::SetExtent( int width, int height )
6963
{
7064
if(m_rcBounds.extent.x != width == m_rcBounds.extent.y != height)
7165
{
72-
OnSizeChanged(JPoint2I(width,height));
7366
m_rcBounds.extent.x = width;
7467
m_rcBounds.extent.y = height;
68+
OnSizeChanged();
7569
}
7670
}
7771

7872
inline void JuiControl::SetWidth(int width)
7973
{
8074
if(m_rcBounds.extent.x != width)
8175
{
82-
OnSizeChanged(JPoint2I(width,m_rcBounds.extent.y));
8376
m_rcBounds.extent.x = width;
77+
OnSizeChanged();
8478
}
8579
}
8680

8781
inline void JuiControl::SetHeight(int height)
8882
{
8983
if(m_rcBounds.extent.y != height)
9084
{
91-
OnSizeChanged(JPoint2I(m_rcBounds.extent.x,height));
9285
m_rcBounds.extent.y = height;
86+
OnSizeChanged();
9387
}
9488
}
9589

src/base/JuiReader.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ bool JuiReader::LoadScript( JuiContainer *root, const char* filename )
8080
{
8181
JuiContainer *container = dynamic_cast<JuiContainer*>(currObject);
8282
if(container != NULL)
83-
container->OnSizeChanged(container->GetExtent());
83+
container->OnSizeChanged();
8484
}
8585

8686
if(stackIndex >= 0)

src/base/win32/JuiFrame.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ JuiEventManager * JuiFrame::GetInputGenerator()
3737
}
3838

3939

40-
void JuiFrame::OnSizeChanged(const JPoint2I& newSize)
40+
void JuiFrame::OnSizeChanged()
4141
{
42-
Parent::OnSizeChanged(newSize);
43-
JuiWindow::SetSize(newSize.x,newSize.y);
42+
Parent::OnSizeChanged();
43+
JuiWindow::SetSize(GetWidth(),GetHeight());
4444
}
4545

4646
bool JuiFrame::HandleHitTest( POINTS pt, LRESULT* result )

src/base/win32/JuiFrame.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class JuiFrame : public JuiFrameLayout, public JuiWindow
1616

1717
virtual void AddUpdateRegion( const JPoint2I& pos, const JPoint2I& extent );
1818
virtual JuiEventManager *GetInputGenerator();
19-
virtual void OnSizeChanged(const JPoint2I& newSize);
19+
virtual void OnSizeChanged();
2020

2121
protected:
2222
virtual bool HandleHitTest(POINTS pt, LRESULT* result);

src/layout/JuiFrameLayout.cpp

+3-7
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,8 @@ void JuiFrameLayoutParameter::UpdateControl( JuiControl *pCtrl, const JPoint2I &
7171
pCtrl->SetPosition(m_ptOrigPos);
7272
}
7373

74-
void JuiFrameLayoutParameter::UpdatePos(JuiContainer* pParent, JRectI& bound)
74+
void JuiFrameLayoutParameter::UpdatePos(const JPoint2I &parentSize, JRectI& bound)
7575
{
76-
if(pParent == NULL)
77-
return;
78-
79-
JPoint2I parentSize = pParent->GetExtent();
8076
m_ptOrigPos = bound.position;
8177

8278
if(m_Gravity == GRAVITY_RIGHT)
@@ -98,15 +94,15 @@ JuiFrameLayoutParameter* JuiFrameLayout::CreateParameter()
9894
return new JuiFrameLayoutParameter;
9995
}
10096

101-
void JuiFrameLayout::OnSizeChanged(const JPoint2I& newSize)
97+
void JuiFrameLayout::OnSizeChanged()
10298
{
10399
JuiControl* pCtrl = (JuiControl*)m_lsChilds.First();
104100
while(pCtrl)
105101
{
106102
JuiFrameLayoutParameter *pParam = static_cast<JuiFrameLayoutParameter*>(pCtrl->GetLayoutParameter());
107103
if(pParam != NULL)
108104
{
109-
pParam->UpdateControl(pCtrl, newSize);
105+
pParam->UpdateControl(pCtrl, GetExtent());
110106
}
111107

112108
pCtrl = (JuiControl*)m_lsChilds.Next();

src/layout/JuiFrameLayout.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class JuiFrameLayoutParameter : public JuiLayoutParameter
3939

4040
void UpdateControl(JuiControl *pCtrl, const JPoint2I &parentSize);
4141

42-
virtual void UpdatePos(JuiContainer* pParent, JRectI& bound);
42+
virtual void UpdatePos(const JPoint2I &parentSize, JRectI& bound);
4343

4444
private:
4545
LayoutSizeType m_LayoutWidth;
@@ -54,7 +54,7 @@ class JuiFrameLayout : public JuiContainer
5454
JDECLARE_DYNAMIC_CLASS(JuiRelativeLayout)
5555
public:
5656
virtual JuiFrameLayoutParameter* CreateParameter();
57-
virtual void OnSizeChanged(const JPoint2I& newSize);
57+
virtual void OnSizeChanged();
5858
virtual void OnChildAdded(JuiControl *child);
5959
virtual void OnChildRemoved(JuiControl *child);
6060
};

src/layout/JuiLayoutParameter.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class JuiLayoutParameter : public JObject
88
{
99
JDECLARE_ABSTRACT_CLASS(JuiLayoutParameter)
1010
public:
11-
virtual void UpdatePos(JuiContainer* pParent, JRectI& bound) = 0;
11+
virtual void UpdatePos(const JPoint2I &parentSize, JRectI& bound) = 0;
1212
};
1313

1414
#endif

0 commit comments

Comments
 (0)