divyang4481 / gwen-dotnet

Automatically exported from code.google.com/p/gwen-dotnet
0 stars 0 forks source link

OpenTK Renderer not restoring previous states/values. #16

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
The OpenTK renderer doesn't restore any caps, states or vals that it changes.  
To remedy this, I added some code to Begin() and End() that restores 
everything, so as not to mess with any rendering that takes place outside of 
the UI.  I have attached the modified Gwen.Renderer.OpenTK.cs.

I will also look into the issue with caret placement being incorrent.  If and 
when I find a solution, I will post that also.

In a few days, I will post a modified Gwen.Input.OpenTK that handles most (if 
not all) keys on the keyboard, including shift values (1/!, a/A, etc) and many 
keyboard layouts.  Not having support for number/keypad keys was hindering my 
progress, so I went ahead and fixed it :P

Original issue reported on code.google.com by FauxBest...@gmail.com on 19 Jan 2012 at 6:51

Attachments:

GoogleCodeExporter commented 8 years ago
The reason the added lines in OpenTK.cs look like they are indented incorrectly 
is because I've setup VS to use tabs instead of 4 spaces.  Sorry about that.

Original comment by FauxBest...@gmail.com on 19 Jan 2012 at 6:54

GoogleCodeExporter commented 8 years ago

Original comment by der.ag...@gmail.com on 19 Jan 2012 at 8:41

GoogleCodeExporter commented 8 years ago
OK so, I've more-or-less fixed the caret/selection placement.  It was due to 
the StringFormat not being set to GenericTypographic when measuring or drawing. 
 Also, OpenTK seems to trim trailing spaces when measuring text, so I simply 
add 4 to the width if the string ends with a space character (not the best fix, 
but it works, and it looks nice).  Here are the edits, and I'll attach the 
edited files just in case:

Gwen.Renderer.OpenTK.cs:

In MeasureText(), change
    SizeF size = m_Graphics.MeasureString(text, sysFont);
to
     SizeF size = m_Graphics.MeasureString(text, sysFont, Point.Empty, StringFormat.GenericTypographic);
and also change
    return new Point((int)size.Width, (int)size.Height);
to
    return new Point((int)Math.Round(size.Width) + ((text.EndsWith(" ")) ? 4 : 0), (int)Math.Round(size.Height));

Gwen.Renderer.TextRenderer.cs (OpenTK):

In DrawString, change
    gfx.DrawString(text, font, brush, point);
to
    gfx.DrawString(text, font, brush, point, StringFormat.GenericTypographic);

Original comment by FauxBest...@gmail.com on 19 Jan 2012 at 9:01

Attachments:

GoogleCodeExporter commented 8 years ago
Sorry if it seems like I'm spamming, but there's also an issue with the cursor 
not changing when hovering over the sides of resizable windows.  It changes 
when hovering over the corners, showing that the window can be resized, but not 
on the sides.  I'm about to look into it (and I think I already know what the 
problem is), so I'll let you know when I've resolved it.

Original comment by FauxBest...@gmail.com on 19 Jan 2012 at 9:09

GoogleCodeExporter commented 8 years ago
Fixed the cursor problem.

Gwen.ControlInternal.Resizer.cs:

In ResizeDir set, change
    if (0 != (value & Pos.Right) && 0 != (value & Pos.Left))
to
    if (0 != (value & Pos.Right) || 0 != (value & Pos.Left))
and change
    if (0 != (value & Pos.Top) && 0 != (value & Pos.Bottom))
to
    if (0 != (value & Pos.Top) || 0 != (value & Pos.Bottom))

Original comment by FauxBest...@gmail.com on 19 Jan 2012 at 9:16

GoogleCodeExporter commented 8 years ago
So, after testing the caret thing a bit more, it's not fixed -.-  The further 
from the start of the string the caret is, the more offset it is from where the 
caret SHOULD be.  I've no idea why this is happening, but I'm going to try some 
hacks and see what I can do.

Original comment by FauxBest...@gmail.com on 19 Jan 2012 at 10:09

GoogleCodeExporter commented 8 years ago
It turns out that it all boils down to the fact that we're using hinting when 
drawing the string, but when being measured (even with MeasureCharacterRanges 
and TextRenderer.MeasureText), it doesn't use any hinting.  The space issue 
turned out to be quite simple to fix, btw.  Just change the StringFormat 
FormatFlags to MeasureTrailingSpaces.  Until we can find an accurate way of 
measuring, even with hinting enabled, the space fix is quite useless...

Original comment by FauxBest...@gmail.com on 19 Jan 2012 at 11:15

GoogleCodeExporter commented 8 years ago
I can get perfect rendering and measurement by using TextRenderer, but the text 
comes out fatter, and performance takes a hit, especially when selecting text 
by dragging.

Original comment by FauxBest...@gmail.com on 19 Jan 2012 at 11:48

GoogleCodeExporter commented 8 years ago
Generally GDI+'s text measurement is... bad. I'm not sure how to fix that 
without using some external library like FreeType.

Original comment by der.ag...@gmail.com on 20 Jan 2012 at 9:14

GoogleCodeExporter commented 8 years ago
Well, I had a look at a few alternatives, including QuickFont, but... it was a 
no-go.  I ended up just switching from AntiAliasGridFit to AntiAlias for 
TextRenderingHint.  I really wasn't up for writing my own FreeType wrapper...

Original comment by FauxBest...@gmail.com on 25 Jan 2012 at 3:20

GoogleCodeExporter commented 8 years ago
I suggest you implement texture fonts with proper kerning. I myself did it with 
AngelCode BMFonts if at all possible.

They work really well with Gwen. As far as GDI+ goes it seems to be fairly 
unrealiable cross-platform.

Original comment by ollipe...@gmail.com on 3 Feb 2012 at 5:33