Skip to content

Commit

Permalink
Refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
xinhuang committed Jan 10, 2012
1 parent 5ad58c8 commit aa9fe08
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 51 deletions.
8 changes: 4 additions & 4 deletions MineGame_Lib/View/ConfigForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ void ConfigForm::InitializeComponents()
Controls.Add(_d->widthLabel);
_d->widthLabel.set_AutoSize(true);
_d->widthLabel.set_Text(L"Width:");
_d->widthLabel.set_AnchorStyles(AnchorStyles::Left);
_d->widthLabel.set_Anchor(AnchorStyles::Left);

Controls.Add(_d->widthTextBox);
_d->widthTextBox.set_Location(Point(_d->widthLabel.get_Right(), _d->widthLabel.get_Location().Y));
_d->widthTextBox.set_Size(Size(get_Width() - _d->widthTextBox.get_Left() - 5, _d->widthLabel.get_Height()));
_d->widthTextBox.set_AnchorStyles(AnchorStyles::LeftRight);
_d->widthTextBox.set_Anchor(AnchorStyles::LeftRight);
_d->widthTextBox.set_BorderStyle(FormBorderStyle::FixedSingle);

Controls.Add(_d->heightLabel);
_d->heightLabel.set_Text(L"Height:");
_d->heightLabel.set_AutoSize(true);
_d->heightLabel.set_Location(Point(0, _d->widthLabel.get_Height() + gap));
_d->heightLabel.set_AnchorStyles(AnchorStyles::Left);
_d->heightLabel.set_Anchor(AnchorStyles::Left);

Controls.Add(_d->mineTotalLabel);
_d->mineTotalLabel.set_Text(L"Mines:");
_d->mineTotalLabel.set_AutoSize(true);
_d->mineTotalLabel.set_Location(Point(0, _d->heightLabel.get_Top() + _d->heightLabel.get_Height() + gap));
_d->mineTotalLabel.set_AnchorStyles(AnchorStyles::Left);
_d->mineTotalLabel.set_Anchor(AnchorStyles::Left);
}
2 changes: 1 addition & 1 deletion MineGame_Lib/View/MGameView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void MGameView::InitializeComponents()
Controls.Add(_d->remainMines);
_d->remainMines.set_Location(Point(5, 5));
_d->remainMines.set_Size(Size(39, 24));
_d->remainMines.set_AnchorStyles(AnchorStyles::TopLeft);
_d->remainMines.set_Anchor(AnchorStyles::TopLeft);

ResumeLayout(true);

Expand Down
14 changes: 7 additions & 7 deletions mUI/System.Forms/Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ void Control::PrivateLayout(Control& container, LayoutEventArgs* e)
Control& element = **iter;

Rectangle bounds = element.get_Bounds();
if (element.get_AnchorStyles() == AnchorStyles::None)
if (element.get_Anchor() == AnchorStyles::None)
continue;
if ((element.get_AnchorStyles() & AnchorStyles::Bottom) != 0)
if ((element.get_Anchor() & AnchorStyles::Bottom) != 0)
{
if ((element.get_AnchorStyles() & AnchorStyles::Top) != 0)
if ((element.get_Anchor() & AnchorStyles::Top) != 0)
{
bounds.Size.Height = container.get_Size().Height
- element._d->anchorInfo.Top
Expand All @@ -134,9 +134,9 @@ void Control::PrivateLayout(Control& container, LayoutEventArgs* e)
- element._d->anchorInfo.Bottom;
bounds.Location.Y = bounds.get_Top() + vertDelta;
}
if ((element.get_AnchorStyles() & AnchorStyles::Right) != 0)
if ((element.get_Anchor() & AnchorStyles::Right) != 0)
{
if ((element.get_AnchorStyles() & AnchorStyles::Left) != 0)
if ((element.get_Anchor() & AnchorStyles::Left) != 0)
{
bounds.Size.Width = container.get_Size().Width
- element._d->anchorInfo.Left
Expand Down Expand Up @@ -583,12 +583,12 @@ void Control::OnKeyPress( KeyPressEventArgs* e )
KeyPress(this, e);
}

void Control::set_AnchorStyles( AnchorStyles::Enum value )
void Control::set_Anchor( AnchorStyles::Enum value )
{
SetAnchor(value, *get_Parent());
}

AnchorStyles::Enum Control::get_AnchorStyles() const
AnchorStyles::Enum Control::get_Anchor() const
{
return _d->anchorStyles;
}
Expand Down
4 changes: 2 additions & 2 deletions mUI/System.Forms/Control.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ class FORMS_ENTRY Control : public ComponentModel::ISynchronizeInvoke, public Th
Control* get_Parent() { return parent_; }
const Control* get_Parent() const { return parent_; }

AnchorStyles::Enum get_AnchorStyles() const;
void set_AnchorStyles(AnchorStyles::Enum value);
AnchorStyles::Enum get_Anchor() const;
void set_Anchor(AnchorStyles::Enum value);

// ---------------------------------------------------------- //

Expand Down
11 changes: 6 additions & 5 deletions mUI/System.Forms/Form.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ struct Form::Data
: dragMove(false)
, moving(false)
, topMost(false)
, borderStyle(FormBorderStyle::FixedSingle)
{}

bool topMost;
bool dragMove;
bool moving;
Point mouseDownLocation;
FormBorderStyle formBoarderStyle;
FormBorderStyle::Enum borderStyle;

static const int DEFAULT_WIDTH = 800;
static const int DEFAULT_HEIGHT = 600;
Expand Down Expand Up @@ -96,18 +97,18 @@ void Form::OnDeactivate( EventArgs* e )
Deactivate(this, e);
}

void Form::set_FormBorderStyle( const FormBorderStyle& style )
void Form::set_FormBorderStyle( FormBorderStyle::Enum style )
{
if (get_FormBorderStyle() != style)
{
_d->formBoarderStyle = style;
_d->borderStyle = style;
OnBorderStyleChanged(&EventArgs::Empty);
}
}

const FormBorderStyle& Form::get_FormBorderStyle() const
FormBorderStyle::Enum Form::get_FormBorderStyle() const
{
return _d->formBoarderStyle;
return _d->borderStyle;
}

void Form::OnBorderStyleChanged( EventArgs* e )
Expand Down
4 changes: 2 additions & 2 deletions mUI/System.Forms/Form.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class FORMS_ENTRY Form : public Control

virtual Point PointToScreen(Point pt) const;

const FormBorderStyle& get_FormBorderStyle() const;
void set_FormBorderStyle(const FormBorderStyle& style);
FormBorderStyle::Enum get_FormBorderStyle() const;
void set_FormBorderStyle(FormBorderStyle::Enum style);

Size get_ClientSize() const;

Expand Down
21 changes: 5 additions & 16 deletions mUI/System.Forms/FormBorderStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
limitations under the License.
*/

#ifndef __FORMBOARDERSTYLE_H__
#define __FORMBOARDERSTYLE_H__
#ifndef __MUI_FORMS_FORMBORDERSTYLE_H__
#define __MUI_FORMS_FORMBORDERSTYLE_H__

namespace mUI{ namespace System{ namespace Forms{

class FORMS_ENTRY FormBorderStyle
namespace FormBorderStyle
{
public:
enum FBS {
enum Enum {
None,
FixedSingle,
//Fixed3D, // Not supported yet
Expand All @@ -31,18 +30,8 @@ class FORMS_ENTRY FormBorderStyle
//FixedToolWindow, // Not supported yet
//SizableToolWindow, // Not supported yet
};

FormBorderStyle() : fbs_(None)
{}
FormBorderStyle(FBS fbs) : fbs_(fbs)
{}

operator FBS() const { return fbs_; }

private:
FBS fbs_;
};

}}}

#endif
#endif // __MUI_FORMS_FORMBORDERSTYLE_H__
4 changes: 2 additions & 2 deletions mUI/System.Forms/Label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ void Label::set_Text( const String& text )
void Label::AdjustSize()
{
if (!get_AutoSize()
|| (get_AnchorStyles() & AnchorStyles::LeftRight) == AnchorStyles::LeftRight
|| (get_AnchorStyles() & AnchorStyles::TopBottom) == AnchorStyles::TopBottom)
|| (get_Anchor() & AnchorStyles::LeftRight) == AnchorStyles::LeftRight
|| (get_Anchor() & AnchorStyles::TopBottom) == AnchorStyles::TopBottom)
return;

Graphics* g = CreateGraphics();
Expand Down
8 changes: 4 additions & 4 deletions mUI/System.Forms/TextBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace mUI{ namespace System{ namespace Forms{

struct TextBox::Data
{
FormBorderStyle borderStyle;
FormBorderStyle::Enum borderStyle;
};

TextBox::TextBox() : _d(new Data())
Expand Down Expand Up @@ -35,8 +35,8 @@ void TextBox::set_Text( const String& text )
void TextBox::AdjustSize()
{
if (!get_AutoSize()
|| (get_AnchorStyles() & AnchorStyles::LeftRight) == AnchorStyles::LeftRight
|| (get_AnchorStyles() & AnchorStyles::TopBottom) == AnchorStyles::TopBottom)
|| (get_Anchor() & AnchorStyles::LeftRight) == AnchorStyles::LeftRight
|| (get_Anchor() & AnchorStyles::TopBottom) == AnchorStyles::TopBottom)
return;

Graphics* g = CreateGraphics();
Expand All @@ -55,7 +55,7 @@ void TextBox::OnKeyPress( KeyPressEventArgs* e )
set_Text(get_Text() + e->KeyChar);
}

void TextBox::set_BorderStyle( FormBorderStyle borderStyle )
void TextBox::set_BorderStyle( FormBorderStyle::Enum borderStyle )
{
_d->borderStyle = borderStyle;
Update();
Expand Down
2 changes: 1 addition & 1 deletion mUI/System.Forms/TextBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FORMS_ENTRY TextBox : public Control

virtual void set_Text(const String& text);
virtual void set_AutoSize(bool value);
void set_BorderStyle( FormBorderStyle borderStyle );
void set_BorderStyle( FormBorderStyle::Enum borderStyle );

protected:
virtual void OnPaint( PaintEventArgs* e );
Expand Down
14 changes: 7 additions & 7 deletions mUI_UnitTest/ControlTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ TEST_F(ControlTest, PerformLayout_WhenAnchorStyleTop)
Rectangle arbitraryBounds(30, 30, 10, 10);
AddChildCtrl(arbitraryBounds);

_childCtrl->set_AnchorStyles(AnchorStyles::Top);
_childCtrl->set_Anchor(AnchorStyles::Top);
_sut->set_Size(Size(200, 200));

ASSERT_EQ(arbitraryBounds.Location, _childCtrl->get_Location());
Expand All @@ -217,7 +217,7 @@ TEST_F(ControlTest, PerformLayout_WhenAnchorStyleBottom)

int expectDistance = DistanceFromChildBottomToParentBottom(*_sut, *_childCtrl);

_childCtrl->set_AnchorStyles(AnchorStyles::Bottom);
_childCtrl->set_Anchor(AnchorStyles::Bottom);
_sut->set_Size(Size(200, 200));

ASSERT_EQ(arbitraryBounds.Location.X, _childCtrl->get_Location().X);
Expand All @@ -230,7 +230,7 @@ TEST_F(ControlTest, PerformLayout_WhenAnchorStyleLeft)
Rectangle arbitraryBounds(30, 30, 10, 10);
AddChildCtrl(arbitraryBounds);

_childCtrl->set_AnchorStyles(AnchorStyles::Left);
_childCtrl->set_Anchor(AnchorStyles::Left);
_sut->set_Size(Size(200, 200));

ASSERT_EQ(arbitraryBounds.Location, _childCtrl->get_Location());
Expand All @@ -243,7 +243,7 @@ TEST_F(ControlTest, PerformLayout_WhenAnchorStyleRight)
AddChildCtrl(arbitraryBounds);
int expectedDistance = DistanceFromChildRightToParentRight(*_sut, *_childCtrl);

_childCtrl->set_AnchorStyles(AnchorStyles::Right);
_childCtrl->set_Anchor(AnchorStyles::Right);
_sut->set_Size(Size(200, 200));

ASSERT_EQ(expectedDistance, DistanceFromChildRightToParentRight(*_sut, *_childCtrl));
Expand All @@ -261,7 +261,7 @@ TEST_F(ControlTest, PerformLayout_WhenAnchorStyleTopBottom)

int expectDistance = DistanceFromChildBottomToParentBottom(*_sut, *_childCtrl);

_childCtrl->set_AnchorStyles(AnchorStyles::TopBottom);
_childCtrl->set_Anchor(AnchorStyles::TopBottom);
_sut->set_Size(Size(333, newHeight));

ASSERT_EQ(arbitraryBounds.Location.X, _childCtrl->get_Location().X);
Expand All @@ -279,7 +279,7 @@ TEST_F(ControlTest, PerformLayout_WhenAnchorStyleLeftRight)

int expectDistance = DistanceFromChildBottomToParentBottom(*_sut, *_childCtrl);

_childCtrl->set_AnchorStyles(AnchorStyles::LeftRight);
_childCtrl->set_Anchor(AnchorStyles::LeftRight);
_sut->set_Size(Size(newWidth, 333));

ASSERT_EQ(arbitraryBounds.Location.X, _childCtrl->get_Location().X);
Expand All @@ -297,7 +297,7 @@ TEST_F(ControlTest, PerformLayout_WhenAnchorStyleAll)
int expectVertDistance = DistanceFromChildBottomToParentBottom(*_sut, *_childCtrl);
int expectHoriDistance = DistanceFromChildRightToParentRight(*_sut, *_childCtrl);

_childCtrl->set_AnchorStyles(AnchorStyles::All);
_childCtrl->set_Anchor(AnchorStyles::All);
_sut->set_Size(Size(newWidth, newHeight));

ASSERT_EQ(arbitraryBounds.Location.X, _childCtrl->get_Location().X);
Expand Down

0 comments on commit aa9fe08

Please sign in to comment.