![]() |
||
| Home | SwiftForth Archive | SwiftX Archive | |

Sure - Windows renders (draws) on what known as a Device Context (DC) -
a printer or display or memory. Nearly all drawing commands work with
any DC. Notice the stack diagram in Rectangle:
Function: Rectangle ( hdc nLeftRect nTopRect nRightRect nBottomRect
-- res )
hdc is the handle to a device context (DC). To get the DC of any window
use GetDC.
For example, the DC of the SwiftForth console is HWND GetDC
Now to draw a line (or rectangle) we need to create a pen and select it
into the DC. Follows is an example.
Mike
{ ====================================================================
Simply Drawing Example
Created 06/06/2007 by Mike Ghan
==================================================================== }
Function: CreatePen ( style width|0 rgbColor -- hPen )
Function: MoveToEx ( hDC X Y point -- res )
Function: LineTo ( hDC X Y -- res )
Function: SetROP2 ( hDC ROP2 -- res )
Function: Rectangle ( hdc nLeftRect nTopRect nRightRect nBottomRect --
res )
\ ********************************************************************
\ Colors
\ ********************************************************************
: >RGB ( red green blue --- rgb ) \ rgb = 00bbggrr
16 LSHIFT SWAP 8 LSHIFT OR OR ;
: RGB-COLOR ( red green blue -- )
>RGB ( ColorRGB ) CONSTANT ;
\ Some Common Colors
\ Red Grn Blu RGB-COLOR name
255 255 255 RGB-COLOR WHITE-COLOR
255 0 0 RGB-COLOR RED-COLOR
0 255 0 RGB-COLOR GREEN-COLOR
0 0 255 RGB-COLOR BLUE-COLOR
255 128 0 RGB-COLOR ORANGE-COLOR
255 255 0 RGB-COLOR YELLOW-COLOR
255 0 255 RGB-COLOR MAGENTA-COLOR
0 0 0 RGB-COLOR BLACK-COLOR
128 128 128 RGB-COLOR GRAY-COLOR
\ ********************************************************************
\ DC Tools
\ ********************************************************************
[UNDEFINED] CURRENT-DC [IF]
\ User Vars
#USER
CELL +USER CURRENT-DC \ Device Context
TO #USER
: MY-DC ( -- hDC ) CURRENT-DC @ ;
: IS-MY-DC ( hDC -- ) CURRENT-DC ! ; \ Set at BeginPaint etc
: GET-MY-DC ( -- ) HWND GetDC IS-MY-DC ;
: RELEASE-MY-DC ( -- ) HWND MY-DC ReleaseDC DROP ;
[THEN]
\ ********************************************************************
\ Draw Lines
\ ********************************************************************
: DRAW-LINE ( x1 y1 x2 y2 -- )
2>R MY-DC -ROT 0 MoveToEx DROP MY-DC 2R> LineTo DROP ;
: MOVE-TO ( x y -- )
MY-DC -ROT NULL MoveToEx DROP ;
: +LINE ( x y -- ) \ Append to Previous
MY-DC -ROT LineTo DROP ;
\ ********************************************************************
\ Testbed
\ ********************************************************************
: DRAW-TEST ( -- ) \ Draw lines on SF Console
GET-MY-DC ( get DC of our window )
PS_SOLID 5 ( width ) RED-COLOR CreatePen ( hPen )
MY-DC SWAP ( hPen ) SelectObject ( hPrevPen ) >R ( Stash )
25 100 ( x1y1 ) 125 200 ( x2y2 ) DRAW-LINE
225 200 +LINE 25 100 +LINE
\ Next we'll restore the previous pen and delete the pen we created.
MY-DC R> ( hPrevPen ) SelectObject ( hPen ) DeleteObject DROP
RELEASE-MY-DC ;
-----Original Message-----
From: sftalk-bounce_at_forth.com [mailto:sftalk-bounce_at_forth.com] On Behalf
Of Allen Anway
Sent: Wednesday, June 06, 2007 9:02 AM
To: sftalk
Subject: [sftalk] Fw: line drawing on a printer
I noted in Mike Gahn's FormatText.F, FontTools.F, and PrintExample.F for
printing generalized fonts on a printer, that there was such as
Function: Rectangle and
: DRAW-RECT
and this system did indeed print a rectangle on the printer. Is there
an equivalent for printing a line on the printer? Could the line have
various thicknesses more than one pixel?
Thank you for your consideration --- Allen Anway
----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe" to sftalk-request_at_forth.com
For list command help, send subject "help" to sftalk-request_at_forth.com
Message archives are located at http://www.forth.com/archive/sftalk
----------------------------------------------------------------------
This list is a forum for SwiftForth users. For product support and
bug reports, please send email to support_at_forth.com
----------------------------------------------------------------------
Received on Wed Jun 06 2007 - 09:50:51 PDT
This archive was generated by hypermail 2.2.0 : Tue Dec 02 2008 - 03:04:42 PST