Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get OSD (on-screen display) width/height without actually rendering
#2
Not too much work.

Function OsdCalcSize
Code:
Copy      Help
;/
function'SIZE $text [x] [y] [$fname] [fsize] [flags] [wrapwidth] [RECT&rect] ;;flags: 1 nontransparent, 4 click to hide, 16 use raw x y, 32 place by the mouse, 0x100 bold, 0x200 italic

;Calculates width and height of OnScreenDisplay window if you would call it with these parameters.

;Parameters are the same as of <help>OnScreenDisplay</help>. Uses only flags listed above. Does not have pictfile parameter. Also uses <help>_monitor</help>. If need rectangle in screen, use the rect parameter.


SIZE z
fsize=iif(fsize fsize 24)
if(flags&1=0) if(flags&4 or ScreenColors<8) flags|1
__Font hfont.Create(fname fsize flags>>8&3)

int ww retry monf monitor
if(flags&32) flags|16; monitor=-1; x+xm; y+ym; else if(flags&16=0) monitor=_monitor
GetWorkArea 0 0 ww
;g2
RECT rt
int hdc=GetDC(0)
int oldfont=SelectObject(hdc hfont)
rt.right=iif(wrapwidth>0 wrapwidth ww)
DrawTextW hdc @text -1 &rt DT_CALCRECT|DT_WORDBREAK|DT_EXPANDTABS|DT_NOPREFIX
if(flags&0x200) rt.right+fsize/4 ;;avoid clipping part of last char when italic
SelectObject hdc oldfont; ReleaseDC 0 hdc
if(flags&1) rt.right+8; rt.bottom+3
z.cx=rt.right; z.cy=rt.bottom

OffsetRect &rt x y
AdjustWindowPos 0 &rt iif(flags&16 1|4|8 1)|monf monitor

if(!retry and wrapwidth<=0) ;;maybe nonprimary monitor, different width
,monitor=MonitorFromRect(&rt 2); monf=32
,if(monitor!=MonitorFromWindow(0 1))
,,MonitorFromIndex monitor 33 &rt
,,ww=rt.right-rt.left
,,RECT r0; rt=r0
,,retry=1; goto g2

if(&rect) rect=rt
ret z


Messages In This Thread
RE: Get OSD (on-screen display) width/height without actually rendering - by Gintaras - 03-12-2018, 04:37 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)