Skip to content

Commit

Permalink
Widget improvements/fixes (#22)
Browse files Browse the repository at this point in the history
* Widget improvements/fixes
  - Use different color when a widget is Enabled or Disabled
  - Fixed: bug with button widgets triggering by mouse events even if mouse wasn't on top of them
  - Fixed: some widgets didn't have enough spacing or had hardcoded values
  - Fixed: Listbox widget would iterate over all elements, even if they were not visible on screen. Now using CurrentClipArea instead.
* Ignore Visual Studio hidden dir
* Upgraded VS projects to latest Visual Studio 2022
  • Loading branch information
midwan authored Mar 8, 2022
1 parent ceea04a commit ae05476
Show file tree
Hide file tree
Showing 13 changed files with 330 additions and 268 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.sconsign.dblite
config.log
/Debug/
/Debug/
.vs
12 changes: 6 additions & 6 deletions Guisan.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,28 @@
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{3F89CFFD-556A-404C-8E6E-9F7BF5C5525C}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down Expand Up @@ -264,4 +264,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
10 changes: 5 additions & 5 deletions demo/ff/Demo.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,28 @@
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{C38D3313-382B-41C3-8CCE-AC2EBC51DCA7}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down
15 changes: 7 additions & 8 deletions src/widgets/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ namespace gcn
graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1);
graphics->drawLine(1, getHeight() - 1, getWidth() - 1, getHeight() - 1);

graphics->setColor(getForegroundColor());
if (isEnabled())
graphics->setColor(getForegroundColor());
else
graphics->setColor(Color(128, 128, 128));

int textX;
int textY = getHeight() / 2 - getFont()->getHeight() / 2;
Expand Down Expand Up @@ -238,12 +241,9 @@ namespace gcn
{
if (mMousePressed)
{
return mHasMouse;
}
else
{
return mKeyPressed;
return true;
}
return mKeyPressed;
}

void Button::mousePressed(MouseEvent& mouseEvent)
Expand All @@ -268,8 +268,7 @@ namespace gcn
void Button::mouseReleased(MouseEvent& mouseEvent)
{
if (mouseEvent.getButton() == MouseEvent::LEFT
&& mMousePressed
&& mHasMouse)
&& mMousePressed)

This comment has been minimized.

Copy link
@Jarod42

Jarod42 Sep 26, 2024

Collaborator

Why removing mHasMouse?
It breaks the non-action behavior with

  • pressed on button
  • release outside

This comment has been minimized.

Copy link
@midwan

midwan Sep 26, 2024

Author Collaborator

This was a fix for this bug: #17

{
mMousePressed = false;
generateAction();
Expand Down
18 changes: 12 additions & 6 deletions src/widgets/checkbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ namespace gcn
drawBox(graphics);

graphics->setFont(getFont());
graphics->setColor(getForegroundColor());
if (isEnabled())
graphics->setColor(getForegroundColor());
else
graphics->setColor(Color(128, 128, 128));

int h = getHeight() + getHeight() / 2;

Expand Down Expand Up @@ -125,7 +128,7 @@ namespace gcn
}
}

void CheckBox::drawBox(Graphics *graphics)
void CheckBox::drawBox(Graphics* graphics)
{
int h = getHeight() - 2;

Expand All @@ -145,16 +148,19 @@ namespace gcn
graphics->drawLine(h, 1, h, h);
graphics->drawLine(1, h, h - 1, h);

graphics->setColor(getBackgroundColor());
Color backCol = getBackgroundColor();
if (!isEnabled())
backCol = backCol - 0x303030;
graphics->setColor(backCol);
graphics->fillRectangle(Rectangle(2, 2, h - 2, h - 2));

graphics->setColor(getForegroundColor());

if (isFocused())
{
graphics->drawRectangle(Rectangle(0, 0, h + 2, h + 2));
}
graphics->drawRectangle(Rectangle(0, 0, getWidth(), getHeight()));
}

if (mSelected)
{
graphics->drawLine(3, 5, 3, h - 2);
Expand Down
82 changes: 43 additions & 39 deletions src/widgets/dropdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,16 @@ namespace gcn

DropDown::~DropDown()
{
if (widgetExists(mListBox))
mListBox->removeSelectionListener(this);
if (widgetExists(mListBox))
mListBox->removeSelectionListener(this);

if (mInternalScrollArea)
delete mScrollArea;
if (mInternalScrollArea)
delete mScrollArea;

if (mInternalListBox)
delete mListBox;
if (mInternalListBox)
delete mListBox;

setInternalFocusHandler(NULL);
setInternalFocusHandler(NULL);
}

void DropDown::draw(Graphics* graphics)
Expand All @@ -156,11 +156,17 @@ namespace gcn
Color shadowColor = faceColor - 0x303030;
shadowColor.a = alpha;


graphics->setColor(getBackgroundColor());
Color backCol = getBackgroundColor();
if (!isEnabled())
backCol = backCol - 0x303030;
graphics->setColor(backCol);
graphics->fillRectangle(Rectangle(0, 0, getWidth(), h));

graphics->setColor(getForegroundColor());
if (isEnabled())
graphics->setColor(getForegroundColor());
else
graphics->setColor(Color(128, 128, 128));

graphics->setFont(getFont());

if (isFocused())
Expand All @@ -171,23 +177,21 @@ namespace gcn
}

if (mListBox->getListModel() && mListBox->getSelected() >= 0)
{
graphics->drawText(mListBox->getListModel()->getElementAt(mListBox->getSelected()), 1, 0);
}
graphics->drawText(mListBox->getListModel()->getElementAt(mListBox->getSelected()), 2, 1);

drawButton(graphics);

if (mDroppedDown)
{
drawChildren(graphics);
if (mDroppedDown)
{
drawChildren(graphics);

// Draw two lines separating the ListBox with se selected
// element view.
graphics->setColor(highlightColor);
graphics->drawLine(0, h, getWidth(), h);
graphics->setColor(shadowColor);
graphics->drawLine(0, h + 1,getWidth(),h + 1);
}
graphics->drawLine(0, h + 1, getWidth(), h + 1);
}
}

void DropDown::drawBorder(Graphics* graphics)
Expand Down Expand Up @@ -287,9 +291,9 @@ namespace gcn
for (i = 0; i < hh; i++)
{
graphics->drawLine(hx - i + offset,
hy - i + offset,
hx + i + offset,
hy - i + offset);
hy - i + offset,
hx + i + offset,
hy - i + offset);
}
}

Expand Down Expand Up @@ -329,7 +333,7 @@ namespace gcn
}

void DropDown::mousePressed(MouseEvent& mouseEvent)
{
{
// If we have a mouse press on the widget.
if (0 <= mouseEvent.getY()
&& mouseEvent.getY() < getHeight()
Expand All @@ -345,22 +349,22 @@ namespace gcn
}
// Fold up the listbox if the upper part is clicked after fold down
else if (0 <= mouseEvent.getY()
&& mouseEvent.getY() < mFoldedUpHeight
&& mouseEvent.getX() >= 0
&& mouseEvent.getX() < getWidth()
&& mouseEvent.getButton() == MouseEvent::LEFT
&& mDroppedDown
&& mouseEvent.getSource() == this)
&& mouseEvent.getY() < mFoldedUpHeight
&& mouseEvent.getX() >= 0
&& mouseEvent.getX() < getWidth()
&& mouseEvent.getButton() == MouseEvent::LEFT
&& mDroppedDown
&& mouseEvent.getSource() == this)
{
mPushed = false;
foldUp();
releaseModalMouseInputFocus();
}
// If we have a mouse press outside the widget
else if (0 > mouseEvent.getY()
|| mouseEvent.getY() >= getHeight()
|| mouseEvent.getX() < 0
|| mouseEvent.getX() >= getWidth())
|| mouseEvent.getY() >= getHeight()
|| mouseEvent.getX() < 0
|| mouseEvent.getX() >= getWidth())
{
mPushed = false;
foldUp();
Expand Down Expand Up @@ -426,8 +430,8 @@ namespace gcn
if (mScrollArea == NULL)
throw GCN_EXCEPTION("Scroll Area has been deleted.");

if (mListBox == NULL)
throw GCN_EXCEPTION("List box has been deleted.");
if (mListBox == NULL)
throw GCN_EXCEPTION("List box has been deleted.");

int listBoxHeight = mListBox->getHeight();
int h2 = getFont()->getHeight();
Expand Down Expand Up @@ -567,9 +571,9 @@ namespace gcn
Widget::setForegroundColor(color);
}

void DropDown::setFont(Font *font)
{
if (mInternalScrollArea)
void DropDown::setFont(Font *font)
{
if (mInternalScrollArea)
{
mScrollArea->setFont(font);
}
Expand All @@ -580,10 +584,10 @@ namespace gcn
}

Widget::setFont(font);
}
}

void DropDown::mouseWheelMovedUp(MouseEvent& mouseEvent)
{
void DropDown::mouseWheelMovedUp(MouseEvent& mouseEvent)
{
if (isFocused() && mouseEvent.getSource() == this)
{
mouseEvent.consume();
Expand Down
35 changes: 19 additions & 16 deletions src/widgets/label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,24 @@ namespace gcn

switch (getAlignment())
{
case Graphics::LEFT:
textX = 0;
break;
case Graphics::CENTER:
textX = getWidth() / 2;
break;
case Graphics::RIGHT:
textX = getWidth();
break;
default:
throw GCN_EXCEPTION("Unknown alignment.");
case Graphics::LEFT:
textX = 0;
break;
case Graphics::CENTER:
textX = getWidth() / 2;
break;
case Graphics::RIGHT:
textX = getWidth();
break;
default:
throw GCN_EXCEPTION("Unknown alignment.");
}

graphics->setFont(getFont());
graphics->setColor(getForegroundColor());
Color color = getForegroundColor();
if (!isEnabled())
color = Color(128, 128, 128);
graphics->setColor(color);
graphics->drawText(getCaption(), textX, textY, getAlignment());
}

Expand All @@ -141,11 +144,11 @@ namespace gcn
for (i = 0; i < getBorderSize(); ++i)
{
graphics->setColor(shadowColor);
graphics->drawLine(i,i, width - i, i);
graphics->drawLine(i,i + 1, i, height - i - 1);
graphics->drawLine(i, i, width - i, i);
graphics->drawLine(i, i + 1, i, height - i - 1);
graphics->setColor(highlightColor);
graphics->drawLine(width - i,i + 1, width - i, height - i);
graphics->drawLine(i,height - i, width - i - 1, height - i);
graphics->drawLine(width - i, i + 1, width - i, height - i);
graphics->drawLine(i, height - i, width - i - 1, height - i);
}
}

Expand Down
Loading

0 comments on commit ae05476

Please sign in to comment.