Skip to content

Commit

Permalink
Updated scrollarea with const improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
midwan committed Sep 12, 2024
1 parent f045372 commit f880a52
Showing 1 changed file with 44 additions and 48 deletions.
92 changes: 44 additions & 48 deletions src/widgets/scrollarea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ namespace gcn

void ScrollArea::setVerticalScrollAmount(int vScroll)
{
int max = getVerticalMaxScroll();
const int max = getVerticalMaxScroll();

mVScroll = vScroll;

Expand All @@ -217,7 +217,7 @@ namespace gcn

void ScrollArea::setHorizontalScrollAmount(int hScroll)
{
int max = getHorizontalMaxScroll();
const int max = getHorizontalMaxScroll();

mHScroll = hScroll;

Expand Down Expand Up @@ -303,8 +303,8 @@ namespace gcn

void ScrollArea::mousePressed(MouseEvent& mouseEvent)
{
int x = mouseEvent.getX();
int y = mouseEvent.getY();
const int x = mouseEvent.getX();
const int y = mouseEvent.getY();

if (getUpButtonDimension().isPointInRect(x, y))
{
Expand Down Expand Up @@ -388,10 +388,10 @@ namespace gcn
{
if (mIsVerticalMarkerDragged)
{
int pos = mouseEvent.getY() - getVerticalBarDimension().y - mVerticalMarkerDragOffset;
int length = getVerticalMarkerDimension().height;
const int pos = mouseEvent.getY() - getVerticalBarDimension().y - mVerticalMarkerDragOffset;
const int length = getVerticalMarkerDimension().height;

Rectangle barDim = getVerticalBarDimension();
const Rectangle barDim = getVerticalBarDimension();

if ((barDim.height - length) > 0)
{
Expand All @@ -406,10 +406,10 @@ namespace gcn

if (mIsHorizontalMarkerDragged)
{
int pos = mouseEvent.getX() - getHorizontalBarDimension().x - mHorizontalMarkerDragOffset;
int length = getHorizontalMarkerDimension().width;
const int pos = mouseEvent.getX() - getHorizontalBarDimension().x - mHorizontalMarkerDragOffset;
const int length = getHorizontalMarkerDimension().width;

Rectangle barDim = getHorizontalBarDimension();
const Rectangle barDim = getHorizontalBarDimension();

if ((barDim.width - length) > 0)
{
Expand Down Expand Up @@ -459,11 +459,11 @@ namespace gcn

void ScrollArea::drawHBar(Graphics* graphics)
{
Rectangle dim = getHorizontalBarDimension();
const Rectangle dim = getHorizontalBarDimension();

graphics->pushClipArea(dim);

int alpha = getBaseColor().a;
const int alpha = getBaseColor().a;
Color trackColor = getBaseColor() - 0x101010;
trackColor.a = alpha;
Color shadowColor = getBaseColor() - 0x303030;
Expand All @@ -480,11 +480,11 @@ namespace gcn

void ScrollArea::drawVBar(Graphics* graphics)
{
Rectangle dim = getVerticalBarDimension();
const Rectangle dim = getVerticalBarDimension();

graphics->pushClipArea(dim);

int alpha = getBaseColor().a;
const int alpha = getBaseColor().a;
Color trackColor = getBaseColor() - 0x101010;
trackColor.a = alpha;
Color shadowColor = getBaseColor() - 0x303030;
Expand All @@ -510,14 +510,14 @@ namespace gcn

void ScrollArea::drawUpButton(Graphics* graphics)
{
Rectangle dim = getUpButtonDimension();
const Rectangle dim = getUpButtonDimension();
graphics->pushClipArea(dim);

Color highlightColor;
Color shadowColor;
Color faceColor;
int offset;
int alpha = getBaseColor().a;
const int alpha = getBaseColor().a;

if (mUpButtonPressed)
{
Expand Down Expand Up @@ -555,10 +555,9 @@ namespace gcn

graphics->setColor(getForegroundColor());

int i;
int w = dim.height / 2;
int h = w / 2 + 2;
for (i = 0; i < w / 2; ++i)
const int w = dim.height / 2;
const int h = w / 2 + 2;
for (int i = 0; i < w / 2; ++i)
{
graphics->drawLine(w - i + offset,
i + h + offset,
Expand All @@ -571,14 +570,14 @@ namespace gcn

void ScrollArea::drawDownButton(Graphics* graphics)
{
Rectangle dim = getDownButtonDimension();
const Rectangle dim = getDownButtonDimension();
graphics->pushClipArea(dim);

Color highlightColor;
Color shadowColor;
Color faceColor;
int offset;
int alpha = getBaseColor().a;
const int alpha = getBaseColor().a;

if (mDownButtonPressed)
{
Expand Down Expand Up @@ -616,10 +615,9 @@ namespace gcn

graphics->setColor(getForegroundColor());

int i;
int w = dim.height / 2;
int h = w + 1;
for (i = 0; i < w / 2; ++i)
const int w = dim.height / 2;
const int h = w + 1;
for (int i = 0; i < w / 2; ++i)
{
graphics->drawLine(w - i + offset,
-i + h + offset,
Expand All @@ -632,14 +630,14 @@ namespace gcn

void ScrollArea::drawLeftButton(Graphics* graphics)
{
Rectangle dim = getLeftButtonDimension();
const Rectangle dim = getLeftButtonDimension();
graphics->pushClipArea(dim);

Color highlightColor;
Color shadowColor;
Color faceColor;
int offset;
int alpha = getBaseColor().a;
const int alpha = getBaseColor().a;

if (mLeftButtonPressed)
{
Expand Down Expand Up @@ -677,10 +675,9 @@ namespace gcn

graphics->setColor(getForegroundColor());

int i;
int w = dim.width / 2;
int h = w - 2;
for (i = 0; i < w / 2; ++i)
const int w = dim.width / 2;
const int h = w - 2;
for (int i = 0; i < w / 2; ++i)
{
graphics->drawLine(i + h + offset,
w - i + offset,
Expand All @@ -693,14 +690,14 @@ namespace gcn

void ScrollArea::drawRightButton(Graphics* graphics)
{
Rectangle dim = getRightButtonDimension();
const Rectangle dim = getRightButtonDimension();
graphics->pushClipArea(dim);

Color highlightColor;
Color shadowColor;
Color faceColor;
int offset;
int alpha = getBaseColor().a;
const int alpha = getBaseColor().a;

if (mRightButtonPressed)
{
Expand Down Expand Up @@ -738,10 +735,9 @@ namespace gcn

graphics->setColor(getForegroundColor());

int i;
int w = dim.width / 2;
int h = w + 1;
for (i = 0; i < w / 2; ++i)
const int w = dim.width / 2;
const int h = w + 1;
for (int i = 0; i < w / 2; ++i)
{
graphics->drawLine(-i + h + offset,
w - i + offset,
Expand All @@ -754,10 +750,10 @@ namespace gcn

void ScrollArea::drawVMarker(Graphics* graphics)
{
Rectangle dim = getVerticalMarkerDimension();
const Rectangle dim = getVerticalMarkerDimension();
graphics->pushClipArea(dim);

int alpha = getBaseColor().a;
const int alpha = getBaseColor().a;
Color faceColor = getBaseColor();
faceColor.a = alpha;
Color highlightColor = faceColor + 0x303030;
Expand All @@ -781,10 +777,10 @@ namespace gcn

void ScrollArea::drawHMarker(Graphics* graphics)
{
Rectangle dim = getHorizontalMarkerDimension();
const Rectangle dim = getHorizontalMarkerDimension();
graphics->pushClipArea(dim);

int alpha = getBaseColor().a;
const int alpha = getBaseColor().a;
Color faceColor = getBaseColor();
faceColor.a = alpha;
Color highlightColor = faceColor + 0x303030;
Expand Down Expand Up @@ -823,8 +819,8 @@ namespace gcn

void ScrollArea::checkPolicies()
{
int w = getWidth();
int h = getHeight();
const int w = getWidth();
const int h = getHeight();

mHBarVisible = false;
mVBarVisible = false;
Expand Down Expand Up @@ -1057,7 +1053,7 @@ namespace gcn
}

int length, pos;
Rectangle barDim = getVerticalBarDimension();
const Rectangle barDim = getVerticalBarDimension();

if (getContent() && getContent()->getHeight() != 0)
{
Expand All @@ -1081,7 +1077,7 @@ namespace gcn

if (getVerticalMaxScroll() != 0)
{
pos = ((barDim.height - length) * getVerticalScrollAmount())
pos = (barDim.height - length) * getVerticalScrollAmount()
/ getVerticalMaxScroll();
}
else
Expand All @@ -1100,7 +1096,7 @@ namespace gcn
}

int length, pos;
Rectangle barDim = getHorizontalBarDimension();
const Rectangle barDim = getHorizontalBarDimension();

if (getContent() && getContent()->getWidth() != 0)
{
Expand All @@ -1124,7 +1120,7 @@ namespace gcn

if (getHorizontalMaxScroll() != 0)
{
pos = ((barDim.width - length) * getHorizontalScrollAmount())
pos = (barDim.width - length) * getHorizontalScrollAmount()
/ getHorizontalMaxScroll();
}
else
Expand Down

0 comments on commit f880a52

Please sign in to comment.