strange request: A mirrored editor

  • Thread starter Thread starter sklett
  • Start date Start date
S

sklett

I have a friend that likes to read text upside down and write in mirror
(right to left, letters flipped on the Y axis, order reversed) - he used to
be a professional athlete and adopted the techniques to increase his
peripheral range of vision.

Anyway, he asked me if I could create a VERY simple text editor (could be
just an edit control) that would allow him to type in mirror. I said yes.
I created a POC test application, you can see it here:
http://pmddirect.com/temp/meditor.swf

In this crude example I've taken the Bitmap from the edit control, flipped
it and painted on the panel to the right.

This of course won't work for the final solution. I've got a couple of
possible ideas floating around in my head but I thought I would ask here to
see if anyone else has any clever ideas. It's a strange request, hopefully
someone will find it interesting.

Thanks for any ideas, I'm curious to see how others might approach this.

-Steve
 
[...]
In this crude example I've taken the Bitmap from the edit control,
flipped it and painted on the panel to the right.

This of course won't work for the final solution. I've got a couple of
possible ideas floating around in my head but I thought I would ask here
to see if anyone else has any clever ideas. It's a strange request,
hopefully someone will find it interesting.

Thanks for any ideas, I'm curious to see how others might approach this.

If you create a custom control to do all the text output, you can simply
set the Transform for the Graphics before drawing the text in the
control's OnPaint() method to do whatever transformation you like.

That's what I'd use for handling the mirror-image and/or upside-down
aspect, and then of course the custom control can do whatever other layout
operations it needs to to accommodate other goals (all of which would be
normal for a custom control anyway, not counting having to take into
account whatever transformation you've set).

There could be some way to do something similar in the existing TextBox
control (I assume that's what you mean by "edit control"), but it would
require some non-.NET code, since the forms controls in .NET are almost
all just wrappers around the existing Windows common control classes, and
so they aren't actually drawing themselves via the exposed .NET
mechanisms. But the native Windows GDI API does allow for setting the
transformation for a device context, and so assuming you can set it before
the common control class actually draws you could co-opt the common
control class to do what you want.

That said, implementing a custom control to handle text editing and output
isn't really all that hard, and IMHO it would be a cleaner solution in
this case.

Pete
 
Peter Duniho said:
[...]
In this crude example I've taken the Bitmap from the edit control,
flipped it and painted on the panel to the right.

This of course won't work for the final solution. I've got a couple of
possible ideas floating around in my head but I thought I would ask here
to see if anyone else has any clever ideas. It's a strange request,
hopefully someone will find it interesting.

Thanks for any ideas, I'm curious to see how others might approach this.

If you create a custom control to do all the text output, you can simply
set the Transform for the Graphics before drawing the text in the
control's OnPaint() method to do whatever transformation you like.

WPF.

If people can get textboxes on 3-D surfaces then I think mirroring should be
attainable.
 
On Tue, 04 Dec 2007 13:23:39 -0800, Ben Voigt [C++ MVP]

[...]
WPF.

If people can get textboxes on 3-D surfaces then I think mirroring
should be attainable.

Could be. I know practically nothing about WPF...heck I wasn't even aware
anyone had a working sample of a TextBox on a 3D surface. But yes,
assuming that works, I'm sure you can put a TextBox anywhere you want,
including mirrored.

Pete
 
Peter Duniho said:
[...]
In this crude example I've taken the Bitmap from the edit control,
flipped it and painted on the panel to the right.

This of course won't work for the final solution. I've got a couple of
possible ideas floating around in my head but I thought I would ask here
to see if anyone else has any clever ideas. It's a strange request,
hopefully someone will find it interesting.

Thanks for any ideas, I'm curious to see how others might approach this.

If you create a custom control to do all the text output, you can simply
set the Transform for the Graphics before drawing the text in the
control's OnPaint() method to do whatever transformation you like.

That's what I'd use for handling the mirror-image and/or upside-down
aspect, and then of course the custom control can do whatever other layout
operations it needs to to accommodate other goals (all of which would be
normal for a custom control anyway, not counting having to take into
account whatever transformation you've set).

There could be some way to do something similar in the existing TextBox
control (I assume that's what you mean by "edit control"), but it would
require some non-.NET code, since the forms controls in .NET are almost
all just wrappers around the existing Windows common control classes, and
so they aren't actually drawing themselves via the exposed .NET
mechanisms. But the native Windows GDI API does allow for setting the
transformation for a device context, and so assuming you can set it before
the common control class actually draws you could co-opt the common
control class to do what you want.

Thanks for the great reply Peter!

I derived my own TextBox control, overrode the OnPaint and toyed with the
Graphics.Transform Matrix but it appears to have no effect at all. I
suppose this indicates that the drawing is already done by the time I get my
hands on the Graphics object. I will do some additional reading and see
what I can find out.
That said, implementing a custom control to handle text editing and output
isn't really all that hard, and IMHO it would be a cleaner solution in
this case.

My only concern with doing a full custom control is splitting the text and
wrapping. I've looked over a few algorithms for doing this and they aren't
trivial. It could be that I'm missing your point, but from what I
understand you suggesting essentially creating a Textbox control from
scratch, no?

Thanks again for the reply,
Steve
 
Ben Voigt said:
Peter Duniho said:
[...]
In this crude example I've taken the Bitmap from the edit control,
flipped it and painted on the panel to the right.

This of course won't work for the final solution. I've got a couple of
possible ideas floating around in my head but I thought I would ask here
to see if anyone else has any clever ideas. It's a strange request,
hopefully someone will find it interesting.

Thanks for any ideas, I'm curious to see how others might approach this.

If you create a custom control to do all the text output, you can simply
set the Transform for the Graphics before drawing the text in the
control's OnPaint() method to do whatever transformation you like.

WPF.

If people can get textboxes on 3-D surfaces then I think mirroring should
be attainable.

Hi Ben,

Thanks for the reply. As much as I would like an excuse to play with the
new WPF stuff I can't on this project. Thanks for the suggestion though!

-Steve
 
[...]
I derived my own TextBox control, overrode the OnPaint and toyed with the
Graphics.Transform Matrix but it appears to have no effect at all. I
suppose this indicates that the drawing is already done by the time I
get my hands on the Graphics object. I will do some additional reading
and see what I can find out.

Well, as I said, the .NET forms controls are almost all just wrappers
around the regular Windows common controls. This does include the TextBox
control. For those controls, the drawing isn't handled via the normal
..NET mechanisms, and so it means you can't override them using .NET. You
can add your own drawing over the control via those mechanisms, but you
can't affect the control's drawing, not from .NET.

So the problem you've run into is exactly what I was warning about.

It's _possible_ that you could intercept the painting mechanism via
p/invoke and/or the WndProc override in the Control class. I'm not really
sure. To be honest, whenever I run into this sort of thing, I just give
up and write my own control to do whatever I want. I don't like hacking
the built-in OS stuff, because it almost never works exactly right, and it
leaves your own code open to breaking in the future, at least in
situations where the hack doesn't use some documented mechanism for
overriding behaviors.
My only concern with doing a full custom control is splitting the text
and
wrapping. I've looked over a few algorithms for doing this and they
aren't
trivial. It could be that I'm missing your point, but from what I
understand you suggesting essentially creating a Textbox control from
scratch, no?

Yes, that's pretty much what I'm suggesting. :) It's true, the built-in
control has to handle a wide variety of situations, since it's used for
pretty much all text display in Windows. It has to handle all kinds of
different typography, languages, etc.

If you require the full breadth of functionality that is contained in the
built-in control, then maybe writing your own is more of a challenge. But
basic line-wrap functionality should not be all that hard. White space is
easily detected, and you could even explicitly handle a hyphen as well.
The Char class includes properties to help you know whether a character is
a combining character or not (obviously you wouldn't want to split a line
between two characters that are supposed to combine).

Now, all that said I'm not sure I understand your hesitation to use WPF.
You _might_ be able to make the argument that writing a custom control
that only supports basic functionality is less work than learning WPF.
But I can't imagine that something like overriding the Win32 common
control textbox control from .NET would actually be easier than learning
WPF.

Granted, since I haven't learned WPF yet I can't say for sure. But how
hard could it be? I've found .NET in general to be very easy to learn,
certainly a lot easier than figuring out things like hacking the behavior
of some built-in OS object, and I would guess that WPF is at least as easy
to learn as .NET was.

In your shoes, the first thing I'd do is use Google to try to find one of
these WPF examples where they've put a textbox on a 3D surface. If you
can find that, then someone else has already done most of the work for you
anyway. All that would be left is to make sure the 3D surface that
example uses is positioned just in the right place so that the text shown
is mirrored in the way you want.

I really think Ben's suggestion is potentially the most useful you've
received so far. The only reason I can't say that for sure is that I
don't know WPF myself. :)

Pete
 
Peter Duniho said:
[...]
In this crude example I've taken the Bitmap from the edit control,
flipped it and painted on the panel to the right.
This of course won't work for the final solution. I've got a couple of
possible ideas floating around in my head but I thought I would ask here
to see if anyone else has any clever ideas. It's a strange request,
hopefully someone will find it interesting.
Thanks for any ideas, I'm curious to see how others might approach this.
If you create a custom control to do all the text output, you can simply
set the Transform for the Graphics before drawing the text in the
control's OnPaint() method to do whatever transformation you like.

If people can get textboxes on 3-D surfaces then I think mirroring should
be attainable.

Hi Ben,

Thanks for the reply. As much as I would like an excuse to play with the
new WPF stuff I can't on this project. Thanks for the suggestion though!

-Steve

It's a shame you can't use WPF. In WPF you can just drag a TextBox
onto the Window and use this code:

TextBox1.RenderTransformOrigin = new Point(0.5, 0.5);
TextBox1.RenderTransform = new ScaleTranform(-1, 1);

And voila! Your textbox is mirrored!

Chris
 
Chris Dunaway said:
message



[...]
In this crude example I've taken the Bitmap from the edit control,
flipped it and painted on the panel to the right.
This of course won't work for the final solution. I've got a couple
of
possible ideas floating around in my head but I thought I would ask
here
to see if anyone else has any clever ideas. It's a strange request,
hopefully someone will find it interesting.
Thanks for any ideas, I'm curious to see how others might approach
this.
If you create a custom control to do all the text output, you can
simply
set the Transform for the Graphics before drawing the text in the
control's OnPaint() method to do whatever transformation you like.

If people can get textboxes on 3-D surfaces then I think mirroring
should
be attainable.

Hi Ben,

Thanks for the reply. As much as I would like an excuse to play with the
new WPF stuff I can't on this project. Thanks for the suggestion though!

-Steve

It's a shame you can't use WPF. In WPF you can just drag a TextBox
onto the Window and use this code:

TextBox1.RenderTransformOrigin = new Point(0.5, 0.5);
TextBox1.RenderTransform = new ScaleTranform(-1, 1);

And voila! Your textbox is mirrored!

I knew it would be possible, but I didn't know it would be that easy. Wow!
 
I created a POC test application, you can see it here:
http://pmddirect.com/temp/meditor.swf ....
This of course won't work for the final solution. I've got a couple of
possible ideas floating around in my head but I thought I would ask here to
see if anyone else has any clever ideas. It's a strange request, hopefully
someone will find it interesting.

Take a look at Adobe Flex.
Flex Builder 3 is public beta 2 at labs.adobe.com
(http://labs.adobe.com/technologies/flex/flexbuilder3/)

You can use a transformation matrix and do a lot of things
(mirroring, scalling, translations, rotations).
I did give it a try, it is a 10 min job.

But you will have to use an embeded the font.
Looks like the text rendering engine used for embeded fonts is
more powerfull (but slower :-) than the default one.
 
Back
Top