# Mirror Mirror, the writing is upside-down on the Wall!

30 views

### F Bek

Feb 12, 2021, 8:59:21 PMFeb 12
to
Beginner's question,
Dolphin Smalltalk 7.2.4

I've been toying with Gdipus and got it to draw a Rectangle or a T-section, based on dimensions entered by the user, while displaying some calculated properties, by:
- Scaling the graphics (+/-) to fit in no more than half the view;
- Reflecting the graphics about axis-x, to get the y-axis pointing upward instead of downward;
- Translating the graphics to shift the coord. Origin point, and center the graphics in the middle of the view;
- drawing & filling the model as a Path of points;
- drawing x & y arrows at the [new] origin point. - drawing a CG symbol at the centroid of the model.
- drawing an adaptive Grid, both horizontal & vertical, proportional to say half the model dimension, corrected to a power-of-10-multiple of 1, 2, 2.5, 5, or 10.

Most of the magic was performed in one transformation:
graphics transform: (GdiplusMatrix m11: 1 m12: 0 m21: 0 m22: -1 m31: tx m32: ty).
where, 1 & -1 are the Reflection about x-x, and tx ty are the translation vector.

With the above, I had 4 problems:

1)- I could have included scaling in the matrix but I kept it separate, as a simple multiplication, because a #scaleTransform would also affect the line width of the graphics, which was not what I wanted. I've found a partial workaround by experimenting with a line width of 0, which would keep the line thin. But what if I wanted a fixed line width, say 3, irrespective of scale? Is there any way to do that?

2)- Then, I displayed 'O', 'x' and 'y' text at the new Origin, and of course, the writing was upside-down due to the Reflection! I would hate to have to reset the Transform and have to recalculate the text locations to display them properly! Is there any more elegant way of doing this?

3)- I've also experimented for a while with the concept of layers, by constructing a second bitmap for the grids and displaying it on top of the main one, but got all sorts of truncated half grids due to the translation - I finally gave up. But will need to resolve that in order to display dimensions on the graphics as well. Any suggestions?

4)- Currently, the graphics code is still bulky and requires rewriting; it is based on a main method in the Presenter and the <graphics> variable being tossed around a coupe of other methods to add the various decorations... I am rethinking the approach.

FB
___________________________________________

### F Bek

Feb 25, 2021, 7:44:42 AMFeb 25
to
Ref to my message below, the current progress is as follows:

1)- Found a fix: (#Gdiplus.Pen) has a full set of transform methods, including (Pen >> scaleTransform: order:) which can be used to reverse the effects of (GdiplusGraphics >> scaleTransform:) on the pen, effectively maintaining the Pen width independent from scale - which was the required effect!

2)- In order to display text upside-up, I had to reset the transform, apply a translation-only and reverse the sign of 'point y' where the string will display. Still looking for a better way to control Graphics >> displayString: orientation.

Gdiplus.StringFormat Class is a promising alternative, sadly there is no documentation on how to use it to control _text orientation_. Any help would be much appreciated!

3 & 4)- Getting closer to restarting work on a 'Layer' approach to the various components of the graphics, as well as a general code re-write.