Is there a way to draw mirrored text to a wxDC object.
I tried the wxMirrorDC class but it didn't work. I also tried the SetLayoutDirection method and
it didn't work either.
Thank you.
Using:
- wxWidgets 3.1.0
- Window 7 Professional
- Visual Studio 2015.
Mirrored Text
Re: Mirrored Text
Code: Select all
void OnPaint( wxPaintEvent &evt )
{
wxPaintDC pdc(this);
wxGraphicsContext *gc = wxGraphicsContext::Create( pdc );
wxGraphicsFont gf = gc->CreateFont( 24, "Lucida Sans Unicode" );
gc->SetFont(gf);
// normal text
gc->DrawText("some text", 150,30 );
wxGraphicsMatrix gmc = gc->CreateMatrix();
gmc.Scale( -1.0, 1.0 );
gc->SetTransform( gmc );
// mirrored text
// beware that coordinates are affected by the negative x-scale, too
gc->DrawText("some text", -130, 30 );
delete gc;
}
I'm also not sure if this would work on all platforms. Tested on Windows only.
Use the source, Luke!
-
- Super wx Problem Solver
- Posts: 469
- Joined: Tue Jun 20, 2006 6:47 pm
- Contact:
Re: Mirrored Text
In addition to the above, you can use a transformation matrix for the DC itself without wrapping it into a graphics context first. For example to mirror across the line x=50, you could do something like
To mirror across the line y=50, you would change this slightly to
Code: Select all
wxAffineMatrix2D mat = dc.GetTransformMatrix();
mat.Translate(50, 0);
mat.Mirror();
dc.SetTransformMatrix(mat);
dc.DrawText("Hello",0,0);
dc.ResetTransformMatrix();
Code: Select all
wxAffineMatrix2D mat=dc.GetTransformMatrix();
mat.Translate(0, 50);
mat.Mirror(wxVERTICAL);
dc.SetTransformMatrix(mat);
dc.DrawText("Hello",0,0);
dc.ResetTransformMatrix();
Re: Mirrored Text
Thank you both, I'll try and let you know.
Re: Mirrored Text
We're not drawing inside a paint event handler so I couldn't use the first option.
The second worked well when mirroring around the x or y axis.
How would the second option work for text displayed at a 45 degree rotation
or anything other than 0, 90, 180, 270.
Thanks.
The second worked well when mirroring around the x or y axis.
How would the second option work for text displayed at a 45 degree rotation
or anything other than 0, 90, 180, 270.
Thanks.
-
- Super wx Problem Solver
- Posts: 469
- Joined: Tue Jun 20, 2006 6:47 pm
- Contact:
Re: Mirrored Text
You can use the Rotate method to add a rotation factor to the matrix.
Just remember that when dealing with matrices, the order of operation matters. For example, this code:
results in:
And changing the order slightly:
results in:
Just remember that when dealing with matrices, the order of operation matters. For example, this code:
Code: Select all
mat.Translate(50, 50);
mat.Mirror(wxVERTICAL);
mat.Rotate(45*3.14/180);
dc.SetTransformMatrix(mat);
dc.DrawText("Hello",0,0);
Code: Select all
mat.Translate(50, 50);
mat.Rotate(45*3.14/180);
mat.Mirror(wxVERTICAL);
dc.SetTransformMatrix(mat);
dc.DrawText("Hello",0,0);
Re: Mirrored Text
Thank you.