Skip to content

Commit

Permalink
MWGIS-228; GDI+ brushes and pens initialized following GDI+ startup
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryfaust committed Aug 17, 2020
1 parent 465ad46 commit 3fbb4a5
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 42 deletions.
24 changes: 16 additions & 8 deletions src/Control/Map.cpp
Expand Up @@ -161,15 +161,15 @@ END_EVENT_MAP()
// CMapView() constructor
// ********************************************************************
CMapView::CMapView()
: _vals("AZ0CY1EX2GV3IT4KR5MP6ON7QL8SJ9UH0WF1DB2"),
: _vals("AZ0CY1EX2GV3IT4KR5MP6ON7QL8SJ9UH0WF1DB2"),
_valsLen(39), _isSnapshot(false),
_brushBlue(Gdiplus::Color::Blue),
_brushBlack(Gdiplus::Color::Black),
_brushWhite(Gdiplus::Color::White),
_brushLightGray(Gdiplus::Color::LightGray),
_penGray(Gdiplus::Color::Gray),
_brushGray(Gdiplus::Color::Gray),
_penDarkGray(Gdiplus::Color::DarkSlateGray),
_brushBlue(NULL),
_brushBlack(NULL),
_brushWhite(NULL),
_brushLightGray(NULL),
_brushGray(NULL),
_penGray(NULL),
_penDarkGray(NULL),
_propertyExchange(NULL),
_bufferBitmap(NULL),
_tilesBitmap(NULL),
Expand Down Expand Up @@ -231,6 +231,14 @@ void CMapView::Startup()
{
InitializeIIDs(&IID_DMap, &IID_DMapEvents);

_brushBlue = new Gdiplus::SolidBrush(Gdiplus::Color::Blue);
_brushBlack = new Gdiplus::SolidBrush(Gdiplus::Color::Black);
_brushWhite = new Gdiplus::SolidBrush(Gdiplus::Color::White);
_brushLightGray = new Gdiplus::SolidBrush(Gdiplus::Color::LightGray);
_brushGray = new Gdiplus::SolidBrush(Gdiplus::Color::Gray);
_penGray = new Gdiplus::Pen(Gdiplus::Color::Gray);
_penDarkGray = new Gdiplus::Pen(Gdiplus::Color::DarkSlateGray);

Utility::InitGdiPlusFont(&_fontCourier, L"Courier New", 9.0f);
Utility::InitGdiPlusFont(&_fontArial, L"Arial", 9.0f);
_fontCourierSmall = new Gdiplus::Font(L"Courier New", 8.0f);
Expand Down
15 changes: 8 additions & 7 deletions src/Control/Map.h
Expand Up @@ -761,13 +761,14 @@ class CMapView : public COleControl, IMapViewCallback
Gdiplus::Bitmap* _moveBitmap; // shapes being moved are rendered to this bitmap
Gdiplus::Bitmap* _tempBitmap; // to scale contents of the rest bitmaps

Gdiplus::SolidBrush _brushBlue;
Gdiplus::SolidBrush _brushBlack;
Gdiplus::SolidBrush _brushWhite;
Gdiplus::SolidBrush _brushLightGray;
Gdiplus::SolidBrush _brushGray;
Gdiplus::Pen _penGray;
Gdiplus::Pen _penDarkGray;
Gdiplus::SolidBrush* _brushBlue;
Gdiplus::SolidBrush* _brushBlack;
Gdiplus::SolidBrush* _brushWhite;
Gdiplus::SolidBrush* _brushLightGray;
Gdiplus::SolidBrush* _brushGray;
Gdiplus::Pen* _penGray;
Gdiplus::Pen* _penDarkGray;

Gdiplus::Font* _fontCourier;
Gdiplus::Font* _fontCourierSmall;
Gdiplus::Font* _fontCourierLink;
Expand Down
54 changes: 27 additions & 27 deletions src/Control/Map_Scalebar.cpp
Expand Up @@ -258,12 +258,12 @@ void CMapView::DrawScaleBar(Gdiplus::Graphics* g)

for(size_t i = 0; i < parts.size(); i++)
{
g->FillRectangle(&_brushWhite, parts[i]->X - 2, parts[i]->Y - 2, parts[i]->Width + 4, parts[i]->Height + 4);
g->FillRectangle(_brushWhite, parts[i]->X - 2, parts[i]->Y - 2, parts[i]->Width + 4, parts[i]->Height + 4);
}

for(size_t i = 0; i < parts.size(); i++)
{
g->FillRectangle(&_brushBlack, parts[i]->X - 1, parts[i]->Y - 1, parts[i]->Width + 2, parts[i]->Height + 2);
g->FillRectangle(_brushBlack, parts[i]->X - 1, parts[i]->Y - 1, parts[i]->Width + 2, parts[i]->Height + 2);
}

for(size_t i = 0; i < parts.size(); i++)
Expand All @@ -289,32 +289,32 @@ void CMapView::DrawScaleBar(Gdiplus::Graphics* g)
{
s.Format(L"0");
Gdiplus::PointF point(xPadding + 4.0f, -4.0f);
DrawStringWithShade(g, s, &font, point, &_brushBlack, &_brushWhite);
DrawStringWithShade(g, s, &font, point, _brushBlack, _brushWhite);

// max
FormatUnits(s, step, power, count);
point.X = (Gdiplus::REAL)(step * count/unitsPerPixel + xPadding + 3 + 1.0f);
point.Y = -4.0f;
DrawStringWithShade(g, s, &font, point, &_brushBlack, &_brushWhite);
DrawStringWithShade(g, s, &font, point, _brushBlack, _brushWhite);

// units
s = Utility::GetLocalizedUnitsText(targetUnits);
point.X = (Gdiplus::REAL)(step * count/unitsPerPixel + xPadding + 3 + 1.0f);
point.Y = (Gdiplus::REAL)(barHeight - yPadding - 12 + 1.0f);
DrawStringWithShade(g, s, &font, point, &_brushBlack, &_brushWhite);
DrawStringWithShade(g, s, &font, point, _brushBlack, _brushWhite);
}
else
{
// metric
USES_CONVERSION;
s.Format(L"%s %s", FormatUnits(s, step, power, count), Utility::GetLocalizedUnitsText(targetUnits));
Gdiplus::PointF point(xPadding + 8.0f, -10.0f);
DrawStringWithShade(g, s, &font, point, &_brushBlack, &_brushWhite);
DrawStringWithShade(g, s, &font, point, _brushBlack, _brushWhite);

// miles
s.Format(L"%s %s", FormatUnits(s, step2, power2, count2), Utility::GetLocalizedUnitsText(targetUnits2));
point.Y = 8.0f;
DrawStringWithShade(g, s, &font, point, &_brushBlack, &_brushWhite);
DrawStringWithShade(g, s, &font, point, _brushBlack, _brushWhite);
}
g->SetTextRenderingHint(hint);
g->ResetTransform();
Expand Down Expand Up @@ -365,12 +365,12 @@ void CMapView::ShowRedrawTime(Gdiplus::Graphics* g, float time, bool layerRedraw
_copyrightRect.Y += point.Y;

//bool active = _copyrightRect.Contains((Gdiplus::REAL)mousePnt.x, (Gdiplus::REAL)mousePnt.y);
Gdiplus::SolidBrush* textBrush = _copyrightLinkActive ? &_brushBlue : &_brushBlack;
Gdiplus::SolidBrush* textBrush = _copyrightLinkActive ? _brushBlue : _brushBlack;
Gdiplus::Font* font = _copyrightLinkActive ? _fontCourierLink : _fontCourierSmall;

format.SetAlignment(Gdiplus::StringAlignmentCenter);
format.SetLineAlignment(Gdiplus::StringAlignmentCenter);
g->FillRectangle(&_brushLightGray, _copyrightRect);
g->FillRectangle(_brushLightGray, _copyrightRect);
g->DrawString(s.GetString(), s.GetLength(), font, _copyrightRect, &format, textBrush);
}
}
Expand All @@ -386,7 +386,7 @@ void CMapView::ShowRedrawTime(Gdiplus::Graphics* g, float time, bool layerRedraw
{
point.X = (float)(_viewWidth - rect.Width);
point.Y = (float)(_viewHeight - rect.Height - _copyrightRect.Height - 3);
DrawStringWithShade(g, s, _fontCourierSmall, point, &_brushBlack, &_brushWhite);
DrawStringWithShade(g, s, _fontCourierSmall, point, _brushBlack, _brushWhite);
}
}

Expand All @@ -407,7 +407,7 @@ void CMapView::ShowRedrawTime(Gdiplus::Graphics* g, float time, bool layerRedraw
{
point.X = (float)(_viewWidth - rect.Width - 10);
point.Y = _showCoordinates != cdmNone ? 10.0f + rect.Height : 10.0f;
DrawStringWithShade(g, s, _fontCourier, point, &_brushBlack, &_brushWhite);
DrawStringWithShade(g, s, _fontCourier, point, _brushBlack, _brushWhite);
}
}
gstate.RestoreTextRenderingHint(g);
Expand Down Expand Up @@ -524,26 +524,26 @@ void CMapView::DrawZoombar(Gdiplus::Graphics* g)
BOOL highlight = _zoombarParts.PlusButton.PtInRect(pnt);
g->TranslateTransform(x, y);
DrawGradientShadowForPath(path, g);
g->FillPath(&_brushWhite, &path);
g->DrawPath( highlight ? &_penDarkGray : &_penGray, &path);
g->FillPath(_brushWhite, &path);
g->DrawPath( highlight ? _penDarkGray : _penGray, &path);
g->SetTransform(&m);

// lower minus button
_zoombarParts.MinusButton.SetRect((int)x, (int)(y + height), (int)(x + boxSize), (int)(y + height + boxSize));
highlight = _zoombarParts.MinusButton.PtInRect(pnt);
g->TranslateTransform(x, y + height);
DrawGradientShadowForPath(path, g);
g->FillPath(&_brushWhite, &path);
g->DrawPath(highlight ? &_penDarkGray : &_penGray, &path);
g->FillPath(_brushWhite, &path);
g->DrawPath(highlight ? _penDarkGray : _penGray, &path);
g->SetTransform(&m);

// plus sign
g->SetPixelOffsetMode(Gdiplus::PixelOffsetMode::PixelOffsetModeHighQuality);
g->FillRectangle(&_brushGray, x + 5.0f, y + 8.0f, 8.0f, 2.0f);
g->FillRectangle(&_brushGray, x + 8.0f, y + 5.0f, 2.0f, 8.0f);
g->FillRectangle(_brushGray, x + 5.0f, y + 8.0f, 8.0f, 2.0f);
g->FillRectangle(_brushGray, x + 8.0f, y + 5.0f, 2.0f, 8.0f);

// minus sign
g->FillRectangle(&_brushGray, x + 5.0f, y + height + 8.0f, 8.0f, 2.0f);
g->FillRectangle(_brushGray, x + 5.0f, y + height + 8.0f, 8.0f, 2.0f);

g->SetPixelOffsetMode(pixelOffsetMode);

Expand Down Expand Up @@ -631,9 +631,9 @@ void CMapView::DrawZoombar(Gdiplus::Graphics* g)
Gdiplus::SolidBrush tooltipBrush(Gdiplus::Color(255, 255, 255)/*Gdiplus::Color(246, 212, 178 )*/);
tooltipBox.Inflate(9.0f, 5.0f);
g->FillRectangle(&tooltipBrush, tooltipBox);
g->DrawRectangle(&_penGray, tooltipBox);
g->DrawRectangle(_penGray, tooltipBox);
tooltipBox.Inflate(-9.0f, -5.0f);
g->DrawString(s, s.GetLength(), _fontArial, tooltipOrigin, &_brushBlack );
g->DrawString(s, s.GetLength(), _fontArial, tooltipOrigin, _brushBlack );
}
}

Expand All @@ -648,8 +648,8 @@ void CMapView::DrawZoombar(Gdiplus::Graphics* g)
path3.AddRectangle(line);
DrawGradientShadowForPath(path3, g);

g->FillRectangle(&_brushWhite, line);
g->DrawRectangle(highlight && !handleHighlight ? &_penDarkGray : &_penGray, line);
g->FillRectangle(_brushWhite, line);
g->DrawRectangle(highlight && !handleHighlight ? _penDarkGray : _penGray, line);


// notches for zoom levels
Expand All @@ -659,7 +659,7 @@ void CMapView::DrawZoombar(Gdiplus::Graphics* g)
for (int i = 1; i < maxZoom - minZoom; i++)
{
float tempY = (float)(int)(y + boxSize + lineOffset + step * i + 0.5);
g->FillRectangle(&_brushGray, tempX, tempY, 4.0f, 1.0f);
g->FillRectangle(_brushGray, tempX, tempY, 4.0f, 1.0f);
}
g->SetPixelOffsetMode(pixelOffsetMode);

Expand All @@ -678,15 +678,15 @@ void CMapView::DrawZoombar(Gdiplus::Graphics* g)
// drawing the handle
g->TranslateTransform(x, handleY); // boxSize/4.0 = center of handle is the position
DrawGradientShadowForPath(path2, g);
g->FillPath(&_brushWhite, &path2);
g->DrawPath(handleHighlight ? &_penDarkGray : &_penGray, &path2);
g->FillPath(_brushWhite, &path2);
g->DrawPath(handleHighlight ? _penDarkGray : _penGray, &path2);
g->SetTransform(&m);

// minus sign
g->SetPixelOffsetMode(Gdiplus::PixelOffsetMode::PixelOffsetModeHighQuality);
g->FillRectangle(&_brushGray, x + 5.0f, handleY + 4.0f, 8.0f, 2.0f);
g->FillRectangle(_brushGray, x + 5.0f, handleY + 4.0f, 8.0f, 2.0f);
g->SetPixelOffsetMode(pixelOffsetMode);
_penDarkGray.SetWidth(1.0f);
_penDarkGray->SetWidth(1.0f);
}

// ****************************************************************
Expand Down

0 comments on commit 3fbb4a5

Please sign in to comment.