Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Drawing a line on a rectangle
#1
With the following macros I can draw a line on a rectangle :
Function test_BRect
Code:
Copy      Help
int x0 y0 xsc ysc
x0=50; y0=40; xsc=0.8*xres; ysc=0.7*yres
int h=OnScreenDraw(x0 y0 xsc ysc &OSD_BRect 0 0 0 0 h)
OnScreenLine(250 250 400 400 175 2)
3
OnScreenDrawEnd h
3

Function OSD_BRect
Code:
Copy      Help
function hwnd hdc cx cy param
int hpen oldpen hbrush oldbrush oldfont
int x0 y0 ipen
ipen=8
x0=5; y0=5

hbrush=CreateSolidBrush(14614245); oldbrush=SelectObject(hdc hbrush)
hpen=CreatePen(0 ipen 14614245); oldpen=SelectObject(hdc hpen)
RoundRect hdc x0+ipen y0+ipen cx-(2*x0)-ipen cy-(2*y0)-ipen 3 3

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

However, OnScreenDrawEnd closes only the rectangle. If I use "h" as last argument in OnScreenLine, then rectangle is erased before the line appears, as actually expected. Any advice is mostly welcome. I understand I can close these two graphs (rectangle and line) separately.

Let me extend a bit my question. If I need to add some text on this rectangle, I experienced that I can do it inside OSD_BRect, no problem. However, I am wondering whether I have the flexibility to do it in the main module (test_BRect).

Many thanks in advance.
#2
Add line drawing code to OSD_BRect. See how OSD_LineProc does it.

Function OSD_BRect
Code:
Copy      Help
function hwnd hdc cx cy param
int hpen oldpen hbrush oldbrush oldfont
int x0 y0 ipen
ipen=8
x0=5; y0=5

hbrush=CreateSolidBrush(14614245); oldbrush=SelectObject(hdc hbrush)
hpen=CreatePen(0 ipen 14614245); oldpen=SelectObject(hdc hpen)
RoundRect hdc x0+ipen y0+ipen cx-(2*x0)-ipen cy-(2*y0)-ipen 3 3

int hpen2 oldpen2
hpen2=CreatePen(0 2 0xff0000); oldpen2=SelectObject(hdc hpen2)
MoveToEx hdc 200 200 0 ;;set current position
LineTo hdc 300 300
DeleteObject SelectObject(hdc oldpen2)

DeleteObject SelectObject(hdc oldbrush)
DeleteObject SelectObject(hdc oldpen)
ret
#3
Thanks, Best Regards!


Forum Jump:


Users browsing this thread: 1 Guest(s)