From 73cd171d38ad1f623fb4b435d31776d0a0de9e1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kay=20G=C3=BCrtzig?= Date: Tue, 2 Jul 2019 16:54:55 +0200 Subject: [PATCH 1/2] Fixes #1, fixes #2 (preparing version 10.0.1) --- Turtle.cpp | 6 ++++-- Turtleizer.cpp | 6 ++++-- Turtleizer.h | 12 ++++++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Turtle.cpp b/Turtle.cpp index 17adb35..8fb2a98 100644 --- a/Turtle.cpp +++ b/Turtle.cpp @@ -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-02 VERSION 10.0.1: Fixed #1 (environment-dependent char array type), #2 + * 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 @@ -31,7 +33,7 @@ #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) diff --git a/Turtleizer.cpp b/Turtleizer.cpp index 2fffa60..39ed0d1 100644 --- a/Turtleizer.cpp +++ b/Turtleizer.cpp @@ -1,3 +1,4 @@ +#define _CRT_SECURE_NO_WARNINGS #include "Turtleizer.h" /* * Fachhochschule Erfurt https://ai.fh-erfurt.de @@ -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: @@ -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] = { @@ -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) diff --git a/Turtleizer.h b/Turtleizer.h index bc4c8b2..e713ec1 100644 --- a/Turtleizer.h +++ b/Turtleizer.h @@ -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) @@ -201,7 +202,14 @@ class Turtleizer private: // Typename for the list of tracked line elements typedef list 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 @@ -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? From 52cc4b526a268b35828b6ced127403e5508606e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kay=20G=C3=BCrtzig?= Date: Tue, 9 Jul 2019 13:48:07 +0200 Subject: [PATCH 2/2] Fixes #3 (DPI-dependent turtle image positioning) --- Turtle.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Turtle.cpp b/Turtle.cpp index 8fb2a98..31b58f6 100644 --- a/Turtle.cpp +++ b/Turtle.cpp @@ -15,7 +15,7 @@ * * History (add at top): * -------------------------------------------------------- - * 2019-07-02 VERSION 10.0.1: Fixed #1 (environment-dependent char array type), #2 + * 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 @@ -36,7 +36,7 @@ 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) @@ -46,7 +46,7 @@ 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 { @@ -54,7 +54,7 @@ Turtle::Turtle(int x, int y, LPCWSTR imagePath) } // 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; @@ -234,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]; @@ -265,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);