Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Draw text vertically
#1
In the example which it follows I have experienced that I had to use a different RECT [r1] to display the second label of text (Counts). I wonder whether this is reasonable or is it likely that I could re-use the previous RECT [r] ? Furthermore, I wonder whether there exists any simple way to draw the second label (Counts) vertically. Any advice is mostly welcome.

Function Bov_On
Code:
Copy      Help
;---> Comment 19-03-2020 11:57:56 :
;str si.getmacro(getopt(itemid) 1)
;str caller.getmacro(getopt(itemid 1) 1);err    caller=si
;if ideb; min 0; err out "<>%s : <open ''%s /%i''>%s</open> - Called by : <open>%s</open>%s" NowT si _error.place si caller

int xini yini xsc ysc
xini=50; yini=40; xsc=0.8*xres; ysc=0.7*yres
int hBov
hBov=OnScreenDraw(xini yini xsc ysc &OSD_Bov 0 0 0 0 hBov)



;int rad=5
;x0=x0+10 ; y0=y0+10
;OnScreenDraw(x0+0 y0+10 rad rad &OSD_Proc_Red_Light)
;OnScreenDraw(155 140 rad rad &OSD_Proc_Red_Light)
;OnScreenDraw(160 150 rad rad &OSD_Proc_Red_Light)
;h1=OnScreenLine(250 250 400 400 175 2)

2
;OnScreenDrawEnd hBov

Function OSD_Bov
Code:
Copy      Help
function hwnd hdc cx cy param

;---> Comment 19-03-2020 12:10:24 :
;str si.getmacro(getopt(itemid) 1)
;str caller.getmacro(getopt(itemid 1) 1);err    caller=si
;if ideb; min 0; err out "<>%s : <open ''%s /%i''>%s</open> - Called by : <open>%s</open>%s" NowT si _error.place si caller

int hpen oldpen hbrush oldbrush oldfont
int xini yini ipen x00 y00 dx dy
ipen=8
xini=5; yini=5
dx=cx-(2*xini)-ipen ; dy=cy-(2*yini)-ipen
;create/select pen and draw rectangle
hpen=CreatePen(0 ipen 0xff0000); oldpen=SelectObject(hdc hpen)
RoundRect hdc xini yini cx-(2*xini) cy-(2*yini) 20 20 ;;rounded corners
;create/select brush and pen, and draw internal rectangle - background

hbrush=CreateSolidBrush(14614245); oldbrush=SelectObject(hdc hbrush)
hpen=CreatePen(0 ipen 14614245); oldpen=SelectObject(hdc hpen)
RoundRect hdc xini+ipen yini+ipen dx dy  3 3

DeleteObject SelectObject(hdc oldbrush)
DeleteObject SelectObject(hdc oldpen)

;create/select brush and pen, and draw ellipse - points - Αρχή των Αξόνων
hbrush=CreateSolidBrush(0xFF0000); oldbrush=SelectObject(hdc hbrush)
hpen=CreatePen(0 1 0xFF0000); oldpen=SelectObject(hdc hpen)
int rad=10 ;; point size
x00=50
y00=dy-40
Ellipse hdc x00 y00 x00+rad y00+rad


DeleteObject SelectObject(hdc oldbrush)
DeleteObject SelectObject(hdc oldpen)

;draw text - Label under x axis
str txt="Channel"
;create font. To create fonts easily, download CFont class from the forum
#ifdef CFont
CFont hfont.Create("Tahoma" 11 0)
oldfont=SelectObject(hdc hfont)
#endif
;set text color and transparent background
SetTextColor(hdc 0xff0000)
SetBkMode(hdc TRANSPARENT)
;set rectangle
RECT r
DrawText hdc txt -1 &r DT_CALCRECT
OffsetRect &r x00+dx-150 y00+15
;draw
DrawText hdc txt -1 &r 0

txt="Counts"
RECT r1
DrawText hdc txt -1 &r1 DT_CALCRECT
OffsetRect &r1 x00+dx-150 y00-150
;draw
DrawText hdc txt -1 &r1 0




#ifdef CFont
SelectObject hdc oldfont
#endif
#2
For vertical text, create font with angle 90 or 270 degrees and draw with TextOutW or ExtTextOutW.

Function Dialog66
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""

if(!ShowDialog(dd &sub.DlgProc 0)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG

,case WM_DESTROY
,case WM_PAINT
,PAINTSTRUCT ps
,int dc=BeginPaint(hDlg &ps)
,
,__Font f.Create("Tahoma" 11 0 270)
,int oldfont=SelectObject(dc f)
,TextOutW dc 30 30 @"Text" 4
,SelectObject dc oldfont
,
,EndPaint hDlg &ps
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#3
Dear Gintaras, thank you for your detailed advice. I would dare one more question. In the case of my macro  OSD_Bov  above, what is the best way to load a bitmap file with a symbol that I need?
#4
Function dialog_draw_image
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""

if(!ShowDialog(dd &sub.DlgProc 0)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_PAINT
,PAINTSTRUCT ps
,int dc=BeginPaint(hDlg &ps)
,
,__GdiHandle bitmap=LoadPictureFile("Q:\Test\test.png")
,__GdiHandle brush=CreatePatternBrush(bitmap)
,RECT r; TO_GetBitmapRect(bitmap r); OffsetRect &r 50 50
,FillRect dc &r brush
,;brush.Delete
,;bitmap.Delete
,
,EndPaint hDlg &ps
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#5
Thank you! It is perfect. However, I am still wondering if - and how? - I could draw this bitmap from macro OSD_Bov  above. Best regards.
#6
Yes, you need only the 4 lines. Replace dc with hdc.
#7
Many thanks, indeed!


Forum Jump:


Users browsing this thread: 1 Guest(s)