$OPTIMIZE ON
$INCLUDE "rapidq.inc"
DECLARE FUNCTION LoadImage LIB "user32" ALIAS "LoadImageA" (hInst AS LONG,_
BYVAL lpsz AS STRING, dwImageType AS LONG,_
dwDesiredWidth AS LONG, dwDesiredHeight AS LONG,_
dwFlags AS LONG) AS LONG
$INCLUDE "c:\rapidq\rapidq.inc"
DECLARE SUB ColorDlg
DECLARE SUB ForgroundColor
DECLARE SUB Brush1
DECLARE SUB Brush2
DECLARE SUB Brush3
DECLARE SUB Brush4
DECLARE SUB Brush5
DECLARE SUB Brush6
DECLARE SUB Brush7
DECLARE SUB Brush8
DECLARE SUB Brush9
DECLARE SUB FormPaint
DECLARE SUB KeyDown (Key AS WORD,_
Shift AS INTEGER)
DECLARE SUB NewClick_
(sender AS QMENUITEM)
DECLARE SUB OpenClick
DECLARE SUB TraceOpenClick
DECLARE SUB SaveAsClick_
(sender AS QMENUITEM)
DECLARE SUB HelpClick_
(sender AS QMENUITEM)
DECLARE SUB PrinterClick_
(sender AS QMENUITEM)
DECLARE SUB Copy_
(sender AS QMENUITEM)
DECLARE SUB PasteTrace_
(Sender AS QMENUITEM)
DECLARE SUB PasteTrace2_
(Sender AS QMENUITEM)
DECLARE SUB MenuUndo_
(sender AS QMENUITEM)
DECLARE SUB KeyDown(Key AS WORD,_
Shift AS INTEGER)
DECLARE SUB MouseDown(Button AS LONG,_
x AS LONG, y AS LONG,_
Sender AS QCANVAS)
DECLARE SUB MouseMove (x AS LONG,_
y AS LONG,_
Shift AS LONG,_
Sender AS QCANVAS)
DECLARE SUB MouseUp (Button AS LONG,_
x AS LONG, y AS LONG,_
Sender AS QCANVAS)
DECLARE SUB CanvasPaint (Sender AS QCANVAS)
DIM Image1 AS QIMAGE
DIM Image2 AS QIMAGE
DIM startx AS INTEGER
DIM starty AS INTEGER
DIM endx AS INTEGER
DIM endy AS INTEGER
DIM checkbutton AS INTEGER
DIM Straight$ AS STRING
DIM undo$ AS STRING
Undo$="good"
DIM Brush AS INTEGER
Brush=1
DIM Source AS QRECT
DIM Destination AS QRECT
DIM pastecount AS INTEGER
pastecount=0
DIM forwaitx AS INTEGER
DIM forwaity AS INTEGER
DIM Counter AS INTEGER
DIM LineColor AS LONG
LineColor=&HFFFFFF
DIM InkColor AS LONG
InkColor=&H000000
CREATE Form AS QFORM
CAPTION = "Ink Draw"
Center
WindowState=2
AutoScroll=1
OnKeyDown=KeyDown
COLOR=LineColor
CREATE MNUMAIN AS QMAINMENU
CREATE FileItem AS QMENUITEM
CAPTION = "&File"
CREATE NewItem AS QMENUITEM
CAPTION = "New"
OnClick = NewClick
END CREATE
CREATE OpenItem AS QMENUITEM
CAPTION= "Open For Edit"
OnClick = OpenClick
END CREATE
CREATE OpenTraceItem AS QMENUITEM
CAPTION= "Open For Trace"
OnClick = OpenClick
END CREATE
CREATE SaveItem AS QMENUITEM
CAPTION = "Save As"
OnClick = SaveAsClick
END CREATE
CREATE PrintItem AS QMENUITEM
CAPTION = "&Print"
Hint = "Print to Default Printer"
OnClick = PrinterClick
END CREATE
END CREATE
CREATE EditItem AS QMENUITEM
CAPTION = "Edit"
CREATE UndoItem AS QMENUITEM
CAPTION="Undo"
ShortCut="Ctrl+Z"
OnClick=MenuUndo
END CREATE
CREATE CopyItem AS QMENUITEM
CAPTION="Copy to Clipboard"
shortcut="Ctrl+C"
OnClick=Copy
END CREATE
CREATE PasteItem AS QMENUITEM
CAPTION="Paste to Trace(Ctrl-V)"
OnClick=PasteTrace
END CREATE
CREATE PasteItem2 AS QMENUITEM
CAPTION="Paste to Edit(Ctrl-V)"
OnClick=PasteTrace2
END CREATE
END CREATE
CREATE ToolItems AS QMENUITEM
CAPTION="Color Picker"
CREATE ChooseColor AS QMENUITEM
CAPTION="Background Color"
onclick=ColorDlg
END CREATE
CREATE InkColors AS QMENUITEM
CAPTION = "Forground Color"
onclick=ForGroundColor
END CREATE
END CREATE
CREATE BrushesItems AS QMENUITEM
CAPTION="Brushes"
CREATE Brush1Item AS QMENUITEM
CAPTION="Single Pixel"
OnClick=Brush1
END CREATE
CREATE Brush2Item AS QMENUITEM
CAPTION="No2 Sable"
OnClick=Brush2
END CREATE
CREATE Brush3Item AS QMENUITEM
CAPTION="Double Line"
OnClick=Brush3
END CREATE
CREATE Brush4Item AS QMENUITEM
CAPTION="Triple Line"
OnClick=Brush4
END CREATE
CREATE Brush5Item AS QMENUITEM
CAPTION="Filled Pearls"
OnClick=Brush5
END CREATE
CREATE Brush6Item AS QMENUITEM
CAPTION="Ribbon Brush"
OnClick=Brush6
END CREATE
CREATE Brush7Item AS QMENUITEM
CAPTION="Filled Squares"
OnClick=Brush7
END CREATE
CREATE Brush8Item AS QMENUITEM
CAPTION="Pine Needles"
OnClick=Brush8
END CREATE
CREATE Brush9Item AS QMENUITEM
CAPTION="Leaf Brush"
OnClick=Brush9
END CREATE
END CREATE
CREATE HelpItem AS QMENUITEM
CAPTION = "Help"
CREATE AboutItem AS QMENUITEM
CAPTION="About"
OnClick = HelpClick
END CREATE
END CREATE
END CREATE
CREATE Canvas AS QCANVAS
Width=Form.ClientWidth
Height=Form.ClientHeight
OnMouseDown=MouseDown
OnMouseMove=MouseMove
OnMouseUp=MouseUp
OnPaint=CanvasPaint
END CREATE
END CREATE
CONST CC_RGBINIT = &H1
CONST CC_FULLOPEN = &H2
CONST CC_PREVENTFULLOPEN = &H4
CONST CC_SHOWHELP = &H8
CONST CC_ENABLEHOOK = &H10
CONST CC_ENABLETEMPLATE = &H20
CONST CC_ENABLETEMPLATEHANDLE = &H40
CONST CC_SOLIDCOLOR = &H80
CONST CC_ANYCOLOR = &H100
TYPE TCHOOSECOLOR
lStructSize AS LONG
hWndOwner AS LONG
hInstance AS LONG
rgbResult AS LONG
CustColors(1 TO 16) AS LONG
Flags AS DWORD
lCustData AS LONG
lpfnHook AS LONG
lpTemplateName AS LONG
END TYPE
DECLARE FUNCTION ChooseColorDlg LIB "COMDLG32" ALIAS "ChooseColorA" _
(CC AS TCHOOSECOLOR) AS LONG
DECLARE SUB ButtonClick (Sender AS QBUTTON)
DIM CC AS TCHOOSECOLOR
CC.CustColors(1) = &HFF0000
CC.CustColors(2) = &H00FF00
CC.CustColors(3) = &H0000FF
CC.CustColors(4) = &HFF00FF
CC.CustColors(5) = &H00FFFF
CC.CustColors(6) = &HFFFFFF
CC.CustColors(7) = &H559911
CC.CustColors(8) = &HEE44BB
CC.CustColors(9) = &HBB44EE
CC.CustColors(10) = &H115599
CC.CustColors(11) = &H333333
CC.CustColors(12) = &H666666
CC.CustColors(13) = &H999999
CC.CustColors(14) = &HABABAB
CC.CustColors(15) = &HDDDDDD
CC.CustColors(16) = &H550000
CREATE ColorForm AS QFORM
END CREATE
SUB ColorDlg (Sender AS QMENUITEM)
DIM ReturnVal AS LONG
CC.lStructSize = SIZEOF(CC)
CC.hWndOwner = Form.Handle
CC.Flags = CC_RGBINIT + CC_FULLOPEN
CC.rgbResult = Form.COLOR
ReturnVal = ChooseColorDlg(CC)
IF ReturnVal <> 0 THEN lineColor = CC.rgbResult
END SUB
SUB ForGroundColor (Sender AS QMENUITEM)
DIM ReturnVal AS LONG
CC.lStructSize = SIZEOF(CC)
CC.hWndOwner = Form.Handle
CC.Flags = CC_RGBINIT + CC_FULLOPEN
CC.rgbResult = Form.COLOR
ReturnVal = ChooseColorDlg(CC)
IF ReturnVal <> 0 THEN inkcolor = CC.rgbResult
END SUB
DIM UndoBitmap AS QBITMAP
UndoBitmap.Height=Canvas.Height
UndoBitmap.Width=Canvas.Width
DIM ShowBitmap AS QBITMAP
ShowBitmap.Height=Canvas.Height
ShowBitmap.Width=Canvas.Width
DIM TraceBitmap AS QBITMAP
TraceBitmap.Height=Canvas.Height
TraceBitmap.Width=Canvas.Width
DIM UndoTraceBitmap AS QBITMAP
UndoTraceBitmap.Height=Canvas.Height
UndoTraceBitmap.Width=Canvas.Width
Form.SHOWMODAL
SUB CanvasPaint (Sender AS QCANVAS)
IF undo$="good" THEN Sender.Draw(0,0,_
ShowBitmap.BMP)
IF undo$="undo" THEN
Sender.Draw(0,0,UndoBitmap.BMP)
TraceBitmap.Draw(0,0,UndoTraceBitmap.BMP)
undo$="good"
END IF
IF undo$="paste" THEN
Sender.Draw(0,0,Image1.bmp)
TraceBitmap.Draw(0,0,Image1.bmp)
END IF
END SUB
SUB KeyDown(Key AS WORD,_
Shift AS INTEGER)
IF shift=256 THEN Straight$="straight"
IF shift=0 THEN Straight$="notstraight"
END SUB
SUB NewClick
Canvas.COLOR=14
END SUB
SUB MouseDown(Button AS LONG,_
x AS LONG,_
y AS LONG, Sender AS QCANVAS)
startx=x
starty=y
checkbutton=1
UndoBitmap.Height=Canvas.Height
UndoBitmap.Width=Canvas.Width
UndoTraceBitmap.Height=Canvas.Height
UndoTraceBitmap.Width=Canvas.Width
WITH Destination
.Top = 0
.Left = 0
.Right = .Left+UndoBitmap.Width
.Bottom = .Top+UndoBitmap.Height
END WITH
WITH Source
.Top = 0
.Left = 0
.Right = Canvas.Width
.Bottom = Canvas.Height
END WITH
UndoBitmap.CopyRect(Destination,_
Canvas, Source)
WITH Destination
.Top = 0
.Left = 0
.Right = .Left+UndoBitmap.Width
.Bottom = .Top+UndoBitmap.Height
END WITH
WITH Source
.Top = 0
.Left = 0
.Right = Canvas.Width
.Bottom = Canvas.Height
END WITH
UndoTraceBitmap.CopyRect(Destination,_
TraceBitmap, Source)
END SUB
SUB MouseMove(x AS LONG,y AS LONG,_
Shift AS LONG, Sender AS QCANVAS)
IF shift=0 THEN
Straight$="notstraight"
IF brush=1 THEN
IF Checkbutton=1 THEN
Canvas.Line(x,y,x,y,InkColor)
TraceBitmap.Line(x,y,x,y,InkColor)
END IF
END IF
IF brush=2 THEN
IF Checkbutton=1 THEN
Canvas.FillRect(x,y,x+2,y+2,InkColor)
TraceBitmap.FillRect(x,y,x+2,y+2,InkColor)
END IF
END IF
IF brush=3 THEN
IF Checkbutton=1 THEN
Canvas.Line(x,y,x,y,InkColor)
Canvas.Line(x+3,y+3,x+3,y+3,InkColor)
TraceBitmap.Line(x,y,x,y,InkColor)
TraceBitmap.Line(x+3,y+3,x+3,y+3,InkColor)
END IF
END IF
IF brush=4 THEN
IF Checkbutton=1 THEN
Canvas.Line(x-3,y-3,x-3,y-3,InkColor)
Canvas.Line(x,y,x,y,InkColor)
Canvas.Line(x+3,y+3,x+3,y+3,InkColor)
TraceBitmap.Line(x,y,x,y,InkColor)
TraceBitmap.Line(x+3,y+3,x+3,y+3,InkColor)
END IF
END IF
IF brush=5 THEN
IF Checkbutton=1 THEN
Canvas.Circle(x,y,x+8,y+8,InkColor,LineColor)
TraceBitmap.Circle(x,y,x+8,y+8,InkColor,LineColor)
SLEEP=.02
END IF
END IF
IF brush=6 THEN
IF Checkbutton=1 THEN
Canvas.Line (x-2,y+2,x+2,y-2,InkColor)
Canvas.Line (x-2,y+2,x+2,y-2,InkColor)
TraceBitmap.Line(x-2,y+2,x+2,y-2,InkColor)
TraceBitmap.Line(x-2,y+2,x+2,y-2,InkColor)
Canvas.Line (x-1,y+1,x+1,y-1,LineColor)
Canvas.Line (x-1,y+1,x+1,y-1,LineColor)
TraceBitmap.Line(x-1,y+1,x+1,y-1,LineColor)
TraceBitmap.Line(x-1,y+1,x+1,y-1,LineColor)
END IF
END IF
IF brush=7 THEN
IF Checkbutton=1 THEN
Canvas.rectangle(x,y,x+12,y+12,InkColor)
Canvas.circle(x,y,x+12,y+15,LineColor,LineColor)
TraceBitmap.rectangle(x,y,x+12,y+12,InkColor)
TraceBitmap.circle(x,y,x+12,y+15,LineColor,LineColor)
SLEEP .02
END IF
END IF
IF brush=8 THEN
IF Checkbutton=1 THEN
Canvas.Line(x,y,x+6,y,InkColor)
Canvas.Line(x,y,x-6,y+6,InkColor)
Canvas.Line(x,y,x,y-6,InkColor)
Canvas.Line(x,y,x,y-6,InkColor)
TraceBitmap.Line(x,y,x+6,y,InkColor)
TraceBitmap.Line(x,y,x-6,y+6,InkColor)
TraceBitmap.Line(x,y,x,y-6,InkColor)
TraceBitmap.Line(x,y,x,y-6,InkColor)
Canvas.Line(x,y,x-6,y,LineColor)
Canvas.Line(x,y,x+6,y-6,LineColor)
Canvas.Line(x,y,x,y+6,LineColor)
Canvas.Line(x,y,x,y+6,LineColor)
TraceBitmap.Line(x,y,x-6,y,LineColor)
TraceBitmap.Line(x,y,x+6,y-6,LineColor)
TraceBitmap.Line(x,y,x,y+6,LineColor)
TraceBitmap.Line(x,y,x,y+6,LineColor)
SLEEP .05
END IF
END IF
IF brush=9 THEN
IF Checkbutton=1 THEN
Canvas.Textout(x,y,CHR$(129),InkColor,LineColor)
Canvas.Textout(x,y+5,CHR$(129),InkColor,LineColor)
TraceBitmap.Textout(x,y,CHR$(129),InkColor,LineColor)
TraceBitmap.Textout(x,y+5,CHR$(129),InkColor,LineColor)
SLEEP .02
END IF
END IF
END IF
END SUB
SUB MouseUp(Button AS LONG, x AS LONG,_
y AS LONG, Sender AS QCANVAS)
endx=x
endy=y
checkbutton=0
IF Straight$= "straight" THEN
IF Brush=1 THEN
Canvas.Line(Startx,Starty,Endx,Endy,InkColor)
TraceBitmap.Line(Startx,Starty,Endx,Endy,InkColor)
END IF
IF brush=2 THEN
Canvas.Line(startx,starty,endx,endy,InkColor)
Canvas.Line(startx+3,starty+3,endx+3,endy+3,InkColor)
TraceBitmap.Line(startx,starty,endx,endy,InkColor)
TraceBitmap.Line(startx+3,starty+3,endx+3,endy+3,InkColor)
END IF
IF brush=3 THEN
Canvas.Line(startx-3,starty-3,endx-3,endy-3,InkColor)
Canvas.Line(startx,starty,endx,endy,InkColor)
Canvas.Line(startx+3,starty+3,endx+3,endy+3,InkColor)
TraceBitmap.Line(startx-3,starty-3,endx-3,endy-3,InkColor)
TraceBitmap.Line(startx,starty,endx,endy,InkColor)
TraceBitmap.Line(startx+3,starty+3,endx+3,endy+3,InkColor)
END IF
IF brush=4 THEN
Canvas.Line(startx-6,starty-6,endx-6,endy-6,InkColor)
Canvas.Line(startx-3,starty-3,endx-3,endy-3,InkColor)
Canvas.Line(startx,starty,endx,endy,InkColor)
Canvas.Line(startx+3,starty+3,endx+3,endy+3,InkColor)
TraceBitmap.Line(startx-6,starty-6,endx-6,endy-6,InkColor)
TraceBitmap.Line(startx-3,starty-3,endx-3,endy-3,InkColor)
TraceBitmap.Line(startx,starty,endx,endy,InkColor)
TraceBitmap.Line(startx+3,starty+3,endx+3,endy+3,InkColor)
END IF
IF brush=5 THEN
DIM addx AS INTEGER
DIM addy AS INTEGER
addx=endx-startx
addy=endy-starty
forwaitx=startx
forwaity=starty
DO
counter++
Canvas.Circle(forwaitx,forwaity,forwaitx-8,forwaity-8,InkColor,LineColor)
TraceBitmap.Circle(startx,starty,startx-x,starty-y,InkColor,LineColor)
forwaitx=forwaitx+addx
forwaity=forwaity+addy
LOOP UNTIL counter=addx
counter= 0
END IF
IF brush=6 THEN
Canvas.Line (startx-2,starty+2,endx+2,endy-2,InkColor)
Canvas.Line (startx-2,starty+2,endx+2,endy-2,InkColor)
TraceBitmap.Line(startx-2,starty+2,startx+2,starty-2,InkColor)
TraceBitmap.Line(startx-2,starty+2,startx+2,starty-2,InkColor)
END IF
IF brush=7 THEN
Canvas.rectangle(startx,starty,endx+12,endy+12,InkColor)
Canvas.circle(startx,starty,endx+12,endy+15,LineColor,LineColor)
TraceBitmap.rectangle(startx,starty,endx+12,endy+12,InkColor)
TraceBitmap.circle(startx,starty,endx+12,endy+15,LineColor,LineColor)
END IF
IF brush=8 THEN
Canvas.Line(startx,starty,endx+6,endy,InkColor)
Canvas.Line(startx,starty,endx-6,endy+6,InkColor)
Canvas.Line(startx,starty,endx,endy-6,InkColor)
Canvas.Line(startx,starty,endx,endy-6,InkColor)
TraceBitmap.Line(startx,starty,endx+6,endy,InkColor)
TraceBitmap.Line(startx,starty,endx-6,endy+6,InkColor)
TraceBitmap.Line(startx,starty,endx,endy-6,InkColor)
TraceBitmap.Line(startx,starty,endx,endy-6,InkColor)
END IF
IF brush = 9 THEN
FOR forwaitx=startx TO endx STEP 5
FOR forwaity=starty TO endy STEP 5
IF forwaitx>startx THEN
IF forwaity>starty THEN
Canvas.Textout(forwaitx,forwaity,CHR$(129),InkColor,LineColor)
END IF
END IF
NEXT forwaitx
NEXT forwaity
END IF
END IF
ShowBitmap.Height=Canvas.Height
ShowBitmap.Width=Canvas.Width
WITH Destination
.Top = 0
.Left = 0
.Right = .Left+ShowBitmap.Width
.Bottom = .Top+ShowBitmap.Height
END WITH
WITH Source
.Top = 0
.Left = 0
.Right = Canvas.Width
.Bottom = Canvas.Height
END WITH
ShowBitmap.CopyRect(Destination,Canvas, Source)
Straight$="NotStraight"
END SUB
SUB OpenClick
DIM openDialog AS QOPENDIALOG
openDialog.filter = "*.BMP (Bitmap)|*.BMP"
IF openDialog.EXECUTE THEN
ShowBitmap.bmp=(openDialog.fileName)
Canvas.Repaint
END IF
END SUB
SUB TraceOpenClick
DIM openDialog AS QOPENDIALOG
openDialog.filter = "*.BMP (Bitmap)|*.BMP"
IF openDialog.EXECUTE THEN
Image1.Height=1059
Image1.bmp=(openDialog.fileName)
IF Image1.Height>Form.Height THEN
Form.Height=Image1.Height
END IF
END IF
CALL FormPaint
undo$="undo"
Canvas.repaint
END SUB
SUB SaveAsClick
DIM SaveAsDialog AS QSAVEDIALOG
SaveAsDialog.Filter = "*.BMP (Bitmap) |*.BMP"
IF SaveAsDialog.EXECUTE THEN
IF RIGHT$(SaveAsDialog.FileName,4)=".bmp" THEN
SaveASDialog.FileName=SaveAsDialog.FileName - ".bmp"
END IF
TraceBitmap.SaveToFile (SaveASDialog.FileName+".bmp")
END IF
END SUB
SUB FormPaint
IF pastecount=1 THEN
Form.Draw(0,0, Image1.BMP)
END IF
IF pastecount=0 THEN
Form.Draw(0, 0, Image1.BMP)
END IF
pastecount=0
END SUB
SUB MenuUndo
Undo$="undo"
Canvas.Repaint
END SUB
SUB HelpClick
SHOWMESSAGE "Silly Draw Example \r By John Graves"
END SUB
SUB Copy
tracebitmap.SaveToFile "untitled.bmp"
DIM crucial AS LONG
crucial = LoadImage(App.hInstance,"untitled.bmp",0,Bitmap.Width,Bitmap.Height,&H10)
Clipboard.SetAsHandle(2,crucial)
Image1.Handle=Clipboard.GetAsHandle(2)
KILL "untitled.bmp"
END SUB
SUB PasteTrace
pastecount=1
Image1.Handle = Clipboard.GetAsHandle(2)
CALL FormPaint
END SUB
SUB PasteTrace2
pastecount=1
Image1.Handle = Clipboard.GetAsHandle(2)
undo$="paste"
Canvas.Repaint
END SUB
SUB Brush1
Brush=1
END SUB
SUB Brush2
Brush=2
END SUB
SUB Brush3
Brush=3
END SUB
SUB Brush4
Brush=4
END SUB
SUB Brush5
Brush=5
END SUB
SUB Brush6
Brush=6
END SUB
SUB Brush7
Brush=7
END SUB
SUB Brush8
Brush=8
END SUB
SUB Brush9
Brush=9
END SUB
|
|