Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Centered (multiline) text in OnScreenDisplay
#1
Hello All,
Does anyone know how to center text, even multiline, in OnScreenDisplay

eg. something like "This[]is multiline[]text[]that is[]centered" -->

Code:
Copy      Help
This
       is multiline
          text
         that's
        centered


I have to resize the vertical and horizontal size of the OSD dimensions depending on the size of other onscreen elements. Ideally, I would also change the size of the font depending on how much room there is and text size.
This seems very complicated if starting from scratch but I think there is something already like this in placing text onto dialog elements like buttons where there is a RIGHT or LEFT or CENTERED style.

If there was a way to figure it out in text formatting function first and then transfer it to OSD, that would be fine but don't know such a function.

Thanks for any thoughts!
S
#2
I see 3 ways:
1. Copy and modify OnScreenDisplay code.
2. Calculate and add spaces.
3. Draw text (or/and whatever) in a memory DC, save in a temporary file, and use OnScreenDisplay parameter pictfile:

Macro OnScreenDisplay - draw anything
Code:
Copy      Help
;It is possible to display anything with function OnScreenDisplay, using its paramater pictfile. We can even create the file at run time.
;This macro displays horizontally centered text.

str text=
;This
;is multiline
;text
;that's
;centered

;font, text color and background color
__Font font.Create("Segoe UI" 20)
int textColor=0xff0080
int brush=GetSysColorBrush(COLOR_BTNFACE) ;;transparent
;__GdiHandle brush=CreateSolidBrush(0xc0ffff) ;;color

;measure
RECT r
__MemBmp m.Create(1 1)
_i=SelectObject(m.dc font)
DrawTextW(m.dc @text -1 &r DT_CALCRECT|DT_CENTER)
SelectObject(m.dc _i)

;draw
m.Create(r.right r.bottom)
FillRect m.dc &r brush; SetBkMode m.dc TRANSPARENT
SetTextColor m.dc textColor
_i=SelectObject(m.dc font)
DrawTextW(m.dc @text -1 &r DT_CENTER)
SelectObject(m.dc _i)

;save in a temp bmp file
__TempFile tf.Init(".bmp")
SaveBitmap(m.bm tf)
m.Delete

;OSD with the bmp file
OnScreenDisplay "" 5 0 0 "" 0 0 128 "" 0 0 tf
#3
Hi Gintaras,
This is fantastic on an unbelievable level. With my QM scripting skills and a bit of cleverness, I think I could have managed "Calculate and add spaces" but it would be very hack-ey. What you showed with the memory DC just blows my mind. It led me to look at this link:

http://www.codeproject.com/Articles/2247...-Memory-DC


where author states:

Quote:My previous articles have been written with WTL. I still prefer to do Win32 development with WTL. However, the demonstration source code provided will be raw C/C++ Win32 calls and window management. This is to simplify the code that you are looking at, and eliminate a code dependency.

Which led me to look up WTL and came across these many links below.

So it seems like WTL is similar to QM in that it makes use of win32 functions easier through templates (vs QM wizards) but still requires knowledge of Visual C+ or C#.
Is this a correct description? Are there any "treasure troves" of UI elements, dialog elements, or other code snippets out there that a person familiar with QM and pulling in stuff from MSDN could take advantage of? The QM extensions Archive already has blown my mind and been such a treasure of useful code and learning examples. Wondering how much more out there that QM could be a bridge to? Your thoughts?
Thanks!!!!
S

http://www.gamedev.net/page/resources/_/...rted-r2042

http://archive.gamedev.net/archive/refer...index.html

http://www.codeproject.com/Articles/498/...o-WTL-Part

http://www.codeproject.com/Articles/2816...WTL-Hybrid

http://discuss.fogcreek.com/joelonsoftwa...ost=143333

http://archive.gamedev.net/archive/refer...page4.html
#4
Thank you.

WTL wraps Windows API functions and messages into C++ classes. Like many QM functions do. As well as like MFC, .NET and many other libraries do. Of course if you have WTL source code, you can see what API functions and messages they use to implement something. I sometimes look at MFC source code to discover what API to use or how. But WTL (and most other libraries) don't have anything that you could not do by calling Windows API directly. All these libraries just make programming easier.


Forum Jump:


Users browsing this thread: 1 Guest(s)