Skip to content

Commit

Permalink
Merge pull request #4 from codemanyak/bugfix
Browse files Browse the repository at this point in the history
Bugfixes #1 through #3
  • Loading branch information
codemanyak authored Jul 9, 2019
2 parents 31e72d5 + 52cc4b5 commit c917f5a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
22 changes: 15 additions & 7 deletions Turtle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
*
* Theme: Prep course Programming Fundamentals / Object-oriented Programming
* Author: Kay Gürtzig
* Version: 10.0.0 (covering capabilities of Structorizer 3.28-07, new versioning mechanism)
* Version: 10.0.1 (covering capabilities of Structorizer 3.28-07)
*
* History (add at top):
* --------------------------------------------------------
* 2019-07-08 VERSION 10.0.1: Fixed #1 (environment-dependent char array type), #2, #3
* 2018-10-23 VERSION 10.0.0: Casts added to avoid compiler warnings.
* 2018-07-30 VERSION 9: API adaptation to Structorizer 3.28-07: clear() procedure
* 2017-10-29 New methods getX(), getY(), getOrientation() implemented
* 2016-12-09 Created for VERSION 6
Expand All @@ -31,10 +33,10 @@
#define WIDEN(x) WIDEN2(x)
#define __WFILE__ WIDEN(__FILE__)

const LPCWSTR Turtle::TURTLE_IMAGE_FILE = TEXT("turtle.png");
const LPCWSTR Turtle::TURTLE_IMAGE_FILE = WIDEN("turtle.png");

Turtle::Turtle(int x, int y, LPCWSTR imagePath)
: turtleImagePath(NULL)
: turtleImagePath(nullptr)
, turtleWidth(35) // Just some default
, turtleHeight(35) // Just some default
, pos((REAL)x, (REAL)y)
Expand All @@ -44,15 +46,15 @@ Turtle::Turtle(int x, int y, LPCWSTR imagePath)
, defaultColour(Color::Black)
, pTurtleizer(Turtleizer::getInstance())
{
if (imagePath != NULL) {
if (imagePath != nullptr) {
this->turtleImagePath = this->makeFilePath(imagePath, false);
}
else {
this->turtleImagePath = this->makeFilePath();
}
// Store the size of the turtle symbol
Image* image = new Image(this->turtleImagePath);
if (image != NULL) {
if (image != nullptr) {
this->turtleWidth = image->GetWidth();
this->turtleHeight = image->GetHeight();
delete image;
Expand Down Expand Up @@ -232,7 +234,7 @@ LPCWSTR Turtle::makeFilePath(LPCWSTR filename, bool addProductPath) const
}
size_t pathLen = 0;
if (addProductPath || filename == nullptr) {
pathLen = (pPosSlash != NULL) ? pPosSlash - pMyPath : wcslen(pMyPath);
pathLen = (pPosSlash != nullptr) ? pPosSlash - pMyPath : wcslen(pMyPath);
}
size_t buffLen = pathLen + wcslen(filename) + 2;
WCHAR* pFilePath = new WCHAR[buffLen];
Expand Down Expand Up @@ -263,7 +265,13 @@ void Turtle::draw(Graphics& gr) const
// Display an image
//Image* image = new Image(L"Turtle.png");
Image* image = new Image(this->turtleImagePath);
PointF pointF(-(REAL)this->turtleWidth / (REAL)2.0, -(REAL)this->turtleHeight / (REAL)2.0);
// START KGU 2019-07-08 Workaround #3
//PointF pointF(-(REAL)this->turtleWidth / (REAL)2.0, -(REAL)this->turtleHeight / (REAL)2.0);
REAL scaleX = gr.GetDpiX() / image->GetHorizontalResolution();
REAL scaleY = gr.GetDpiY() / image->GetVerticalResolution();
PointF pointF(-(REAL)this->turtleWidth * scaleX / (REAL)2.0,
-(REAL)this->turtleHeight * scaleY / (REAL)2.0);
// END KGU 2019-07-08
#if DEBUG_PRINT
printf("The width of the image is %u.\n", this->turtleWidth);
printf("The height of the image is %u.\n", this->turtleHeight);
Expand Down
6 changes: 4 additions & 2 deletions Turtleizer.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define _CRT_SECURE_NO_WARNINGS
#include "Turtleizer.h"
/*
* Fachhochschule Erfurt https://ai.fh-erfurt.de
Expand All @@ -15,6 +16,7 @@
*
* History (add at top):
* --------------------------------------------------------
* 2019-07-02 VERSION 10.0.1: Fixed #1 (environment-dependent char array type), #2
* 2018-10-23 VERSION 10.0.0: Now semantic version numbering with Version class.
* 2018-07-30 VERSION 9: API adaptation to Structorizer 3.28-07: clear() procedure
* 2017-10-29 VERSION 7: API adaptation to Structorizer 3.27:
Expand Down Expand Up @@ -50,7 +52,7 @@

const Turtleizer::Version Turtleizer::VERSION(10, 0, 0);

const LPCWSTR Turtleizer::WCLASS_NAME = TEXT("Turtleizer");
const Turtleizer::NameType Turtleizer::WCLASS_NAME = TEXT("Turtleizer");

const Color Turtleizer::colourTable[TC_VIOLET + 1] =
{
Expand All @@ -68,7 +70,7 @@ const Color Turtleizer::colourTable[TC_VIOLET + 1] =

Turtleizer* Turtleizer::pInstance = NULL;

Turtleizer::Turtleizer(wstring caption, unsigned int sizeX, unsigned int sizeY, HINSTANCE hInstance)
Turtleizer::Turtleizer(String caption, unsigned int sizeX, unsigned int sizeY, HINSTANCE hInstance)
: hWnd(NULL)
, autoUpdate(true)
, gdiplusToken(NULL)
Expand Down
12 changes: 10 additions & 2 deletions Turtleizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
*
* History (add at top):
* --------------------------------------------------------
* 2019-07-02 VERSION 10.0.1: Fixed #1 (environment-dependent char array type), #2
* 2018-10-23 VERSION 10.0.0: Now semantic version numbering with Version class.
* 2018-10-09 New turtle symbol according to Structorizer versions >= 3.28
* 2018-07-30 VERSION 9: New function clear() added (according to Structorizer 3.28-07)
Expand Down Expand Up @@ -201,7 +202,14 @@ class Turtleizer
private:
// Typename for the list of tracked line elements
typedef list<Turtle*> Turtles;
static const LPCWSTR WCLASS_NAME; // Name of the window class
#ifdef UNICODE
typedef LPCWSTR NameType;
typedef wstring String;
#else
typedef LPCSTR NameType;
typedef string String;
#endif /*UNICODE*/
static const NameType WCLASS_NAME; // Name of the window class
static const Color colourTable[TC_VIOLET + 1]; // Look-up table for colour codes
static Turtleizer* pInstance; // The singleton instance
ULONG_PTR gdiplusToken; // Token of the GDI+ session
Expand All @@ -213,7 +221,7 @@ class Turtleizer
Turtles turtles; // List of turtles to be handled here
Color backgroundColour; // Current background colour
// Hidden constructor - use Turtleizer::startUp() to create an instance!
Turtleizer(wstring caption, unsigned int sizeX, unsigned int sizeY, HINSTANCE hInstance = NULL);
Turtleizer(String caption, unsigned int sizeX, unsigned int sizeY, HINSTANCE hInstance = NULL);
// Callback method for refresh (OnPaint event)
VOID onPaint(HDC hdc);
// Listener method (parallel thread) FIXME: better static?
Expand Down

0 comments on commit c917f5a

Please sign in to comment.