Guidance
指路人
g.yi.org
software / rapidq / Examples / Graphics & Animation / Paint / paint.bas

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  

'=========================================================================
' PAINT Version 1.1 30/12/2003
' Auteur:D.Glodt
'=========================================================================
     $TYPECHECK ON
     $OPTION ICON "palet.ico"
     $INCLUDE "rapidq.inc"
     $INCLUDE "QFuncLib.inc"
     $INCLUDE "object\QcanvasEx.inc"
     $INCLUDE "OBJECT\QCOLORDIALOG.INC"
     $INCLUDE "OBJECT\QDrawFocus.INC"
     $INCLUDE "OBJECT\QBitmapEx.INC"
     $INCLUDE "OBJECT\QAbout.INC"
     $INCLUDE "Object\QFormEx.inc"
     $INCLUDE "Object\QPageSetup.inc"
     $INCLUDE "Object\QPrinterInfo.inc"
     $INCLUDE "Object\QCursor.inc"
     $INCLUDE "Object\QimageDialog.inc"
'==========================================================================
' ressources bitmap
'==========================================================================
     $RESOURCE pen AS "pen.cur"
     $RESOURCE ico AS "palet.ico"
     $RESOURCE Btview2_bmp AS "Btview2.bmp"
     $RESOURCE Btfocus_bmp AS "Btfocus.bmp"
     $RESOURCE Btpipe_bmp AS "Btpipe.bmp"
     $RESOURCE Btfill_bmp AS "Btfill.bmp"
     $RESOURCE Bttext_bmp AS "Bttext.bmp"
     $RESOURCE BtPen_bmp AS "BtPen.bmp"
     $RESOURCE Btpaint_bmp AS "Btpaint.bmp"
     $RESOURCE Btline_bmp AS "Btline.bmp"
     $RESOURCE Btsquare_bmp AS "Btsquare.bmp"
     $RESOURCE BtsquareFilled_bmp AS "BtsquareFilled.bmp"
     $RESOURCE Btcircle_bmp AS "Btcircle.bmp"
     $RESOURCE BtcircleFilled_bmp AS "BtcircleFilled.bmp"
'==========================================================================
' declarations routines
'==========================================================================
     DECLARE SUB Paint
     DECLARE SUB SelectMenuExit
     DECLARE SUB SelectMenuNew
     DECLARE SUB SelectMenuOpen
     DECLARE SUB SelectMenuClose
     DECLARE SUB SelectMenuPrint
     DECLARE SUB SelectMenuConfig
     DECLARE SUB SelectPenColor
     DECLARE SUB SelectBackcolor
     DECLARE SUB move(x AS INTEGER,y AS INTEGER)
     DECLARE SUB start(bt AS INTEGER,x AS INTEGER,y AS INTEGER)
     DECLARE SUB stop(Bt AS INTEGER,x AS INTEGER,y AS INTEGER)
     DECLARE SUB SelectPipe
     DECLARE SUB SelectZoom
     DECLARE SUB SelectPen
     DECLARE SUB SelectPaint
     DECLARE SUB SelectLine
     DECLARE SUB SelectRect
     DECLARE SUB SelectRectFilled
     DECLARE SUB SelectCircle
     DECLARE SUB SelectCircleFilled
     DECLARE SUB SelectFill
     DECLARE SUB SelectText
     DECLARE SUB SelectTextFont
     DECLARE SUB SelectMenuMirrorX
     DECLARE SUB SelectMenuMirrorY
     DECLARE SUB SelectMenuInvert
     DECLARE SUB SelectMenuInvertColor
     DECLARE SUB SelectMenuColoring
     DECLARE SUB SelectMenuTransparentImage
     DECLARE SUB SelectMenuRemoveColor
     DECLARE SUB SelectMenuRotation
     DECLARE SUB SelectFocus
     DECLARE SUB SelectMenuEdit
     DECLARE SUB SelectMenuCopy
     DECLARE SUB SelectMenuPaste
     DECLARE SUB SelectMenuPasteFrom
     DECLARE SUB SelectMenuCut
     DECLARE SUB SelectMenuTransparent
     DECLARE SUB SelectMenuAll
     DECLARE SUB SelectMenuUndo
     DECLARE SUB SelectMenuSaveAs
     DECLARE SUB SelectMenuSave
     DECLARE SUB SelectMenuDimensions
     DECLARE SUB OkDimensions
     DECLARE SUB OkText
     DECLARE SUB AnnulerText
     DECLARE SUB AnnulerDimensions
     DECLARE SUB OkZoom
     DECLARE SUB AnnulerZoom
     DECLARE SUB SelectPenSize
     DECLARE SUB Grille
     DECLARE SUB Zoom
     DECLARE SUB ResizePaint
     DECLARE SUB ResetPaste
     DECLARE SUB TransfertImgUndo
     DECLARE SUB FermerEcran(Key AS WORD)
     DECLARE SUB SelectMenuImageShow
     DECLARE SUB SelectMenuAbout
     DECLARE SUB ResetButton
     DECLARE SUB ChoixDim(Sender AS QRADIOBUTTON)
'==========================================================================
' declarations données
'==========================================================================
     DIM curseur AS QCursor
     curseur.LoadFromResource(0)
     CONST VK_ESCAPE=27
     DIM imgWidth AS INTEGER
     DIM imgHeight AS INTEGER
     imgWidth=200
     imgHeight=200
     DIM TypeDraw AS INTEGER
     TypeDraw=0
     DIM MemoTypeDraw AS INTEGER
     MemoTypeDraw=0
     DIM FlagDraw AS INTEGER
     DIM pencolor AS LONG
     pencolor=&h0
     DIM backcolor AS LONG
     backcolor=&hffffff
     DIM imgMemory AS QBitmapEx
     imgMemory.width=imgWidth
     imgMemory.height=imgHeight
     imgMemory.pixelformat=pf24bit
     imgMemory.FillRect(0,0,imgWidth,imgHeight,&hffffff)
     DIM save24 AS QBITMAP
     DIM ImgTmp AS QBITMAP
     DIM ImgZoom AS QBITMAP
     DIM ImgEffect AS QBitmapEx
     DIM ImgUndo AS QBITMAP
     DIM OPEN AS QImageDialog
     OPEN.CAPTION="Ouvrir image"
     OPEN.DlgCaption(1)="Nom du fichier:"
     OPEN.DlgCaption(2)="Type du fichier:"
     OPEN.DlgCaption(3)="Ouvrir"
     OPEN.DlgCaption(4)="Annuler"
     OPEN.errorLanguage="french"
     OPEN.Filter="Tous format|*.bmp;*.gif;*.jpg;*.dib;*.rle;*.tga;*.pcx|Fichiers bitmap(*.bmp)|*.bmp|Fichiers gif(*.gif)|*.gif|Fichiers jpg(*.jpg)|*.jpg"
     DIM SaveDialog AS QSAVEDIALOG
     SaveDialog.Filter="Fichiers bitmap(*.bmp)|*.bmp|Fichiers jpg(*.jpg)|*.jpg"
     SaveDialog.CAPTION= "Sauver image"
     DIM ColorDial AS QColorDialog
     DIM PgSetup AS QPageSetup
     PgSetup.DisableMargins=true
     PgSetup.CAPTION="Configuration imprimante"
     DIM PrtInfo AS QPrinterInfo
     DIM orx AS INTEGER
     DIM ory AS INTEGER
     DIM ox AS INTEGER
     DIM oy AS INTEGER
     DIM source AS QRECT
     DIM dest AS QRECT
     CONST ValZoom=800
     DIM flagZoom AS INTEGER
     DIM flagPaste AS INTEGER
     DIM leftPaste AS INTEGER
     DIM topPaste AS INTEGER
     DIM flagUndo AS INTEGER
     DIM flagModif AS INTEGER
     DIM flagFill AS INTEGER
     DIM flagSelectAll AS INTEGER
     CONST ZoomWidth=100
     CONST ZoomHeight=100
     DIM flagText AS INTEGER
     DIM leftText AS INTEGER
     DIM topText AS INTEGER
     DIM focus AS QDrawFocus
     DIM fontdialog AS QFONTDIALOG
     DIM font AS QFONT
     DIM FileName AS STRING
     FileName="Sans Titre"
     DIM about AS QAbout
'==========================================================================
' interface application
'==========================================================================
     CREATE Form AS QFORMEX
      CAPTION=Application.title+" - "+FileName
      Width=600
      Height=400
      Center
      CREATE Panel1 AS QPANEL
       Left=0
       Top=0
       Width=62
       Height=400
       BevelOuter=0
       Align=3
       CREATE BtZoom AS QCOOLBTN
        BmpHandle=Btview2_bmp
        Left=5
        Top=0
        Width=24
        Height=24
        ShowHint=true
        Hint="Zoom"
        GroupIndex=2
        AllowAllUp=true
        OnClick=SelectZoom
       END CREATE
       CREATE BtFocus AS QCOOLBTN
        BMPHandle=Btfocus_bmp
        Left=29
        Top=0
        Width=24
        Height=24
        ShowHint=1
        Hint="Focus"
        GroupIndex=1
        AllowAllUp=true
        OnClick=SelectFocus
       END CREATE
       CREATE BtPipe AS QCOOLBTN
        BMPHandle=Btpipe_bmp
        Left=5
        Top=24
        Width=24
        Height=24
        ShowHint=1
        Hint="Pipette"
        GroupIndex=1
        OnClick=SelectPipe
        AllowAllUp=true
       END CREATE
       CREATE BtFill AS QCOOLBTN
        BMPHandle=Btfill_bmp
        Left=29
        Top=24
        Width=24
        Height=24
        ShowHint=1
        Hint="Remplir"
        GroupIndex=1
        AllowAllUp=true
        OnClick=SelectFill
       END CREATE
       CREATE BtText AS QCOOLBTN
        BMPHandle=Bttext_bmp
        Left=5
        Top=48
        Width=24
        Height=24
        ShowHint=1
        Hint="Texte"
        GroupIndex=1
        AllowAllUp=true
        OnClick=SelectText
       END CREATE
       CREATE BtBrush AS QCOOLBTN
        BMPHandle=BtPaint_bmp
        Left=29
        Top=48
        Width=24
        Height=24
        ShowHint=1
        Hint="Pinceau"
        GroupIndex=1
        AllowAllUp=true
        OnClick=SelectPaint
       END CREATE
       CREATE BtPen AS QCOOLBTN
        BMPHandle=BtPen_bmp
        Left=5
        Top=72
        Width=24
        Height=24
        ShowHint=1
        Hint="Crayon"
        GroupIndex=1
        AllowAllUp=true
        OnClick=SelectPen
       END CREATE
       CREATE BtLine AS QCOOLBTN
        BMPHandle=Btline_bmp
        Left=29
        Top=72
        Width=24
        Height=24
        ShowHint=1
        Hint="Ligne"
        GroupIndex=1
        AllowAllUp=true
        OnClick=SelectLine
       END CREATE
       CREATE BtSquare AS QCOOLBTN
        BMPHandle=Btsquare_bmp
        Left=5
        Top=96
        Width=24
        Height=24
        ShowHint=1
        Hint="Rectangle"
        GroupIndex=1
        AllowAllUp=true
        OnClick=SelectRect
       END CREATE
       CREATE BtSquareFilled AS QCOOLBTN
        BMPHandle=BtsquareFilled_bmp
        Left=29
        Top=96
        Width=24
        Height=24
        ShowHint=1
        Hint="Rectangle plein"
        GroupIndex=1
        AllowAllUp=true
        OnClick=SelectRectFilled
       END CREATE
       CREATE BtCircle AS QCOOLBTN
        BMPHandle=Btcircle_bmp
        Left=5
        Top=120
        Width=24
        Height=24
        ShowHint=1
        Hint="Cercle"
        GroupIndex=1
        AllowAllUp=true
        OnClick=SelectCircle
       END CREATE
       CREATE BtCircleFilled AS QCOOLBTN
        BMPHandle=BtcircleFilled_bmp
        Left=29
        Top=120
        Width=24
        Height=24
        ShowHint=1
        Hint="Cercle plein"
        GroupIndex=1
        AllowAllUp=true
        OnClick=SelectCircleFilled
       END CREATE
       CREATE Panel2 AS QPANEL
        Left=5
        Top=160
        Width=24
        Height=24
        BevelInner=1
        BevelOuter=1
        ShowHint=1
        Hint="Couleur"
        COLOR=&h0
        OnClick=SelectPenColor
       END CREATE
       CREATE Panel3 AS QPANEL
        Left=29
        Top=160
        Width=24
        Height=24
        BevelInner=1
        BevelOuter=1
        ShowHint=1
        Hint="Couleur de fond"
        COLOR=&hffffff
        OnClick=SelectBackcolor
       END CREATE
       CREATE PenSize AS QCOMBOBOX
        style=2
        AddItems "1","2","3","4","5","6","7","8","9","10"
        Left=5
        Top=194
        Width=49
        ShowHint=1
        Hint="Taille crayon"
        ItemIndex=0
        OnChange=SelectPenSize
       END CREATE
      END CREATE
      CREATE ScrollBox1 AS QSCROLLBOX
       AutoScroll=true
       Align=5
       HorzTracking=true
       VertTracking=true
       COLOR=&H808080
       CREATE Image AS QCANVASEX
        left=0
        top=0
        width=imgWidth
        height=imgHeight
        COLOR=&hffffff
        OnPaint=Paint
        OnMouseMove=move
        OnMouseDown=start
        OnMouseUp=stop
       END CREATE
       OnResize=ResizePaint
      END CREATE
      OnClose=SelectMenuExit
      OnResize=ResizePaint
     END CREATE

'==========================================================================
' menu application
'==========================================================================
     CREATE MainMenu AS QMAINMENU
      PARENT=Form
      CREATE FileMenu AS QMENUITEM
       CAPTION="&Fichier"
       CREATE ItemNew AS QMENUITEM
        CAPTION="&Nouveau"
        OnClick=SelectMenuNew
       END CREATE
       CREATE ItemOpen AS QMENUITEM
        CAPTION="&Ouvrir"
        OnClick=SelectMenuOpen
       END CREATE
       CREATE ItemClose AS QMENUITEM
        CAPTION="&Fermer"
        OnClick=SelectMenuClose
       END CREATE
       CREATE ItemSave AS QMENUITEM
        CAPTION="&Sauver"
        OnClick=SelectMenuSave
       END CREATE
       CREATE ItemSaveAs AS QMENUITEM
        CAPTION="Sauver s&ous..."
        OnClick=SelectMenuSaveAs
       END CREATE
       CREATE ItemSeparator1 AS QMENUITEM
        CAPTION="-"
       END CREATE
       CREATE ItemPrint AS QMENUITEM
        CAPTION="&Imprimer"
        OnClick=SelectMenuPrint
       END CREATE
       CREATE ItemConfig AS QMENUITEM
        CAPTION="&Configuration imprimante"
        OnClick=SelectMenuConfig
       END CREATE
       CREATE ItemSeparator2 AS QMENUITEM
        CAPTION="-"
       END CREATE
       CREATE ItemQuit AS QMENUITEM
        CAPTION="&Quitter"
        OnClick=SelectMenuExit
       END CREATE
      END CREATE
      CREATE EditMenu AS QMENUITEM
       CAPTION="&Edition"
       OnClick=SelectMenuEdit
       CREATE ItemUndo AS QMENUITEM
        CAPTION="&Annuler"
        Enabled=false
        OnClick=SelectMenuUndo
       END CREATE
       CREATE ItemSeparator3 AS QMENUITEM
        CAPTION="-"
       END CREATE
       CREATE ItemCut AS QMENUITEM
        CAPTION="&Couper"
        Enabled=false
        OnClick=SelectMenuCut
       END CREATE
       CREATE ItemCopy AS QMENUITEM
        CAPTION="Co&pier"
        Enabled=false
        OnClick=SelectMenuCopy
       END CREATE
       CREATE ItemPaste AS QMENUITEM
        CAPTION="C&oller"
        Enabled=false
        OnClick=SelectMenuPaste
       END CREATE
       CREATE ItemPasteFrom AS QMENUITEM
        CAPTION="Coller a partir &de.."
        OnClick=SelectMenuPasteFrom
       END CREATE
       CREATE ItemTransparent AS QMENUITEM
        CAPTION="M&ode transparence"
        OnClick=SelectMenuTransparent
       END CREATE
       CREATE ItemSeparator5 AS QMENUITEM
        CAPTION="-"
       END CREATE
       CREATE ItemSelectAll AS QMENUITEM
        CAPTION="S&electionner tout"
        OnClick=SelectMenuAll
       END CREATE
      END CREATE
      CREATE ShowMenu AS QMENUITEM
       CAPTION="&Affichage"
       CREATE ItemImageShow AS QMENUITEM
        CAPTION="&Afficher l'image"
        OnClick=SelectMenuImageShow
       END CREATE
      END CREATE
      CREATE ImageMenu AS QMENUITEM
       CAPTION="&Image"
       CREATE ItemMirrorX AS QMENUITEM
        CAPTION="&Symétrie horizontale"
        OnClick=SelectMenuMirrorX
       END CREATE
       CREATE ItemMirrorY AS QMENUITEM
        CAPTION="S&ymétrie verticale"
        OnClick=SelectMenuMirrorY
       END CREATE
       CREATE ItemTurn90 AS QMENUITEM
        CAPTION="&Rotation 90°"
        OnClick=SelectMenuRotation
       END CREATE
       CREATE ItemInvertColor AS QMENUITEM
        CAPTION="&Inverser les couleurs"
        OnClick=SelectMenuInvert
       END CREATE
       CREATE ItemNegatifColor AS QMENUITEM
        CAPTION="&Negatif couleur"
        OnClick=SelectMenuInvertColor
       END CREATE
       CREATE ItemColoring AS QMENUITEM
        CAPTION="&Coloriser"
        OnClick=SelectMenuColoring
       END CREATE
       CREATE ItemTransparentImage AS QMENUITEM
        CAPTION="&Transparent"
        OnClick=SelectMenuTransparentImage
       END CREATE
       CREATE ItemRemoveColor AS QMENUITEM
        CAPTION="&Supprimer couleur"
        OnClick=SelectMenuRemoveColor
       END CREATE
       CREATE ItemSeparator4 AS QMENUITEM
        CAPTION="-"
       END CREATE
       CREATE ItemDimensions AS QMENUITEM
        CAPTION="&Dimensions..."
        OnClick=SelectMenuDimensions
       END CREATE
      END CREATE
      CREATE HelpMenu AS QMENUITEM
       CAPTION="&?"
       CREATE ItemAbout AS QMENUITEM
        CAPTION="&A propos..."
        OnClick=SelectMenuAbout
       END CREATE
      END CREATE
     END CREATE


'==========================================================================
' boite dialogue dimensions
'==========================================================================
     CREATE Form2 AS QFORM
      CAPTION="Dimensions"
      Width=320
      Height=215
      Center
      BorderStyle=3
      CREATE Taille AS QGROUPBOX
       Left=5
       Top=5
       width=150
       height=180
       CAPTION="Nouvelle taille"
       CREATE Choix1 AS QRADIOBUTTON
        CAPTION="pourcentage:"
        left=5
        top=25
        TabOrder=3
        Tag=0
        OnClick=ChoixDim
       END CREATE
       CREATE pourcent AS QCOMBOBOX
        left=50
        Top=50
        width=60
        AddItems "10","20","30","40","50","60","70","80","90","110","120","130","140","150","200"
        ItemIndex=0
        Enabled=false
        TabOrder=4
       END CREATE
       CREATE Choix2 AS QRADIOBUTTON
        CAPTION="Autres valeurs:"
        left=5
        top=80
        Checked=true
        TabOrder=5
        Tag=1
        OnClick=ChoixDim
       END CREATE
       CREATE Label1 AS QLABEL
        CAPTION="Largeur:"
        Left=5
        Top=111
        Width=48
        Height=21
        Transparent=1
       END CREATE
       CREATE Label2 AS QLABEL
        CAPTION="Hauteur:"
        Left=5
        Top=137
        Width=40
        Transparent=1
       END CREATE
       CREATE WidthEdit AS QEDIT
        Left=50
        Top=110
        Width=60
        TabOrder=1
       END CREATE
       CREATE HeightEdit AS QEDIT
        Left=50
        Top=135
        Width=60
        TabOrder=2
       END CREATE
      END CREATE
      CREATE CheckStretch AS QCHECKBOX
       CAPTION="Etirer a la nouvelle taille"
       Left=170
       Top=10
       Width=137
       TabOrder=6
      END CREATE
      CREATE BtOk AS QBUTTON
       CAPTION="&Ok"
       Left=160
       Top=160
       Width=59
       TabOrder=7
       OnClick=OkDimensions
      END CREATE
      CREATE BtUndo AS QBUTTON
       CAPTION="&Annuler"
       Left=230
       Top=160
       Width=59
       TabOrder=8
       OnClick=AnnulerDimensions
      END CREATE
     END CREATE


'==========================================================================
' boite dialogue insertion texte
'==========================================================================
     CREATE Form3 AS QFORM
      CAPTION="Texte"
      Width=347
      Height=125
      BorderStyle=3
      Center
      CREATE EdText AS QEDIT
       autosize=false
       Left=5
       Top=3
       Width=249
       Height=89
       TabOrder=1
      END CREATE
      CREATE BtTextFont AS QBUTTON
       CAPTION="&Police"
       Left=266
       Top=3
       Width=67
       OnClick=SelectTextFont
       TabOrder=2
      END CREATE
      CREATE BtTextUndo AS QBUTTON
       CAPTION="&Annuler"
       Left=266
       Top=34
       Width=67
       OnClick=AnnulerText
       TabOrder=3
      END CREATE
      CREATE BtTextOk AS QBUTTON
       CAPTION="&Ok"
       Left=266
       Top=64
       Width=67
       OnClick=OkText
       TabOrder=4
      END CREATE
     END CREATE

'========================================================
' fenetre ecran
'========================================================
     CREATE Form4 AS QFORM
      BorderStyle=bsNone
      top=0
      left=0
      width=Screen.Width
      height=Screen.Height
      COLOR=&H0
      cursor=crnone
      OnKeyDown=FermerEcran
      CREATE ecran AS QIMAGE
       visible=false
       stretch=true
      END CREATE
     END CREATE

     form.DeskBar=true
     Form.SHOWMODAL

'============================
' Evenement affichage image
'============================
     SUB Paint
      image.draw(0,0,imgMemory.bmp)
      IF BtZoom.down AND flagZoom THEN Grille
      IF FlagPaste THEN image.draw(focus.left,focus.top,ImgEffect.bmp)
      IF focus.visible THEN
       focus.visible=false
       focus.start(image.handle,focus.left,focus.top)
       focus.draw(image.handle,focus.left+focus.width,focus.top+focus.height,true)
      END IF
     END SUB

'======================================
' Evenement resize fenetre principale
'======================================
     SUB ResizePaint
      image.repaint
     END SUB

'============================
' Selection menu edition
'============================
     SUB SelectMenuEdit
      IF (btFocus.down OR flagSelectAll) AND focus.visible AND btZoom.down=false THEN
       ItemCut.enabled=true
       ItemCopy.enabled=true
      ELSE
       ItemCut.enabled=false
       ItemCopy.enabled=false
      END IF
      IF image.canPaste() THEN
       ItemPaste.enabled=true
      ELSE
       ItemPaste.enabled=false
      END IF
      IF FlagUndo THEN
       ItemUndo.enabled=true
      ELSE
       ItemUndo.enabled=false
      END IF
     END SUB

'============================
' Selection menu annuler
'============================
     SUB SelectMenuUndo
      IF focus.visible THEN focus.remove(image.handle)
      ImgMemory.width=ImgUndo.width
      ImgMemory.height=ImgUndo.height
      ImgMemory.pixelFormat=ImgUndo.pixelFormat
      ImgMemory.bmp=ImgUndo.bmp
      ImgWidth=ImgUndo.width
      ImgHeight=ImgUndo.height
      Image.width=ImgWidth
      Image.height=ImgHeight
      FlagPaste=false
      Image.repaint
      FlagUndo=false
     END SUB

'============================
' Selection menu copier
'============================
     SUB SelectMenuCopy
      IF flagSelectAll THEN
       ImgMemory.CopyToClipboard
      ELSE
       Source.left=focus.left+1
       Source.top=focus.top+1
       Source.right=focus.left+focus.width-1
       Source.bottom=focus.top+focus.height-1
       image.CopyToClipboard(Source)
      END IF
     END SUB

'============================
' Selection menu couper
'============================
     SUB SelectMenuCut
      TransfertImgUndo
      IF flagSelectAll THEN
       ImgMemory.CopyToClipboard
       IF focus.visible THEN focus.remove(image.handle)
       ImgMemory.fillRect(0,0,ImgMemory.width,ImgMemory.height,&hffffff)
      ELSE
       Source.left=focus.left+1
       Source.top=focus.top+1
       Source.right=focus.left+focus.width-1
       Source.bottom=focus.top+focus.height-1
       image.CopyToClipboard(Source)
       IF focus.visible THEN focus.remove(image.handle)
       ImgMemory.fillRect(focus.left+1,focus.top+1,focus.left+focus.width-1,focus.top+focus.height-1,&hffffff)
      END IF
      image.repaint
     END SUB

'==================================
' Selection menu selectionner tout
'==================================
     SUB SelectMenuAll
      IF focus.visible THEN focus.remove(image.handle)
      flagSelectAll=true
      focus.ShowCursor=false
      focus.start(image.handle,0,0)
      focus.draw(image.handle,image.width,image.height,true)
     END SUB

'============================
' Selection menu coller
'============================
     SUB SelectMenuPaste
      DIM msgButton AS INTEGER

      ResetButton
      IF focus.visible THEN focus.remove(image.handle)
      ImgEffect.transparent=false
      ImgEffect.width=ImgEffect.GetWidthClipboard()
      ImgEffect.height=ImgEffect.GetHeightClipboard()
      ImgEffect.fillRect(0,0,ImgEffect.width,ImgEffect.height,&hffffff)
      ImgEffect.PasteFromClipboard(0,0)
      IF ItemTransparent.checked THEN
       ImgEffect.transparent=true
       ImgEffect.transparentColor=backcolor
      ELSE
       ImgEffect.transparent=false
      END IF
      IF ImgEffect.GetWidthClipboard()>image.width OR ImgEffect.GetHeightClipboard()>image.height THEN
       msgButton=MESSAGEBOX("Agrandir l'image?",application.title,36)
       IF msgButton=mrYes THEN
        IF ImgEffect.GetWidthClipboard()>image.width THEN imgWidth=ImgEffect.GetWidthClipboard()
        IF ImgEffect.GetHeightClipboard()>image.height THEN imgHeight=ImgEffect.GetHeightClipboard()
        imgMemory.width=imgWidth
        imgMemory.height=imgHeight
        image.width=imgWidth
        image.height=imgHeight
       END IF
      END IF
      image.draw(0,0,ImgEffect.bmp)
      focus.noResize=true
      leftPaste=0
      topPaste=0
      focus.start(image.handle,0,0)
      focus.draw(image.handle,ImgEffect.width,ImgEffect.height,true)
      TypeDraw=10
      FlagPaste=true
     END SUB

'=============================================
' Selection menu coller a partir d'un fichier
'=============================================
     SUB SelectMenuPasteFrom
      DIM msgButton AS INTEGER

      ResetButton
      IF focus.visible THEN focus.remove(image.handle)
      IF OPEN.EXECUTE THEN
       ImgEffect.transparent=false
       IF INSTR(LCASE$(OPEN.FileName),".bmp")>0 THEN
        ImgEffect.LoadFromFile(OPEN.FileName)
       ELSE
        ImgEffect.LoadOtherImage(OPEN.FileName,true,"french")
       END IF
       ImgEffect.pixelformat=ImgMemory.pixelformat
       IF ItemTransparent.checked THEN
        ImgEffect.transparent=true
        ImgEffect.transparentColor=backcolor
       ELSE
        ImgEffect.transparent=false
       END IF
       IF ImgEffect.Width>image.width OR ImgEffect.Height>image.height THEN
        msgButton=MESSAGEBOX("Agrandir l'image?",application.title,36)
        IF msgButton=mrYes THEN
         IF ImgEffect.Width>image.width THEN imgWidth=ImgEffect.Width
         IF ImgEffect.Height>image.height THEN imgHeight=ImgEffect.Height
         imgMemory.width=imgWidth
         imgMemory.height=imgHeight
         image.width=imgWidth
         image.height=imgHeight
        END IF
       END IF
       image.draw(0,0,ImgEffect.bmp)
       focus.noResize=true
       leftPaste=0
       topPaste=0
       focus.start(image.handle,0,0)
       focus.draw(image.handle,ImgEffect.width,ImgEffect.height,true)
       TypeDraw=10
       FlagPaste=true
      END IF
     END SUB

'==================================================
' Coller image du presse papier si autre selection
'==================================================
     SUB ResetPaste
      IF FlagPaste THEN
       focus.remove(image.handle)
       focus.stop(image.handle,false)
       ImgMemory.draw(leftPaste,topPaste,ImgEffect.bmp)
       TypeDraw=0
       FlagPaste=false
       image.repaint
       FlagUndo=true
       FlagModif=true
      END IF
     END SUB

'============================
' Selection menu transparent
'============================
     SUB SelectMenuTransparent
      IF ItemTransparent.checked THEN
       ItemTransparent.checked=false
      ELSE
       ItemTransparent.checked=true
      END IF
     END SUB

'============================
' Selection menu quitter
'============================
     SUB SelectMenuExit
      DIM msgButton AS INTEGER

      IF FlagModif THEN
       msgButton=MESSAGEBOX("Sauver fichier?",application.title,35)
       IF msgButton<>mrCancel THEN
        IF msgButton=mrYes THEN
         SelectMenuSave
        END IF
        application.terminate
       ELSE
        form.modalresult=0
       END IF
      ELSE
       application.terminate
      END IF
     END SUB

'============================
' Selection menu nouveau
'============================
     SUB SelectMenuNew
      DIM msgButton AS INTEGER

      IF FlagModif THEN
       msgButton=MESSAGEBOX("Sauver fichier?",application.title,35)
       IF msgButton<>mrCancel THEN
        IF msgButton=mrYes THEN
         SelectMenuSave
        END IF
        FlagUndo=false
        FlagModif=false
        IF focus.visible THEN focus.remove(image.handle)
        ImgMemory.pixelformat=pf24bit
        imgMemory.fillrect(0,0,imgMemory.width,imgMemory.height,&hffffff)
        image.repaint
        filename="Sans Titre"
        OPEN.FileName=""
        form.CAPTION=application.title+" - "+filename
       END IF
      ELSE
       FlagUndo=false
       FlagModif=false
       IF focus.visible THEN focus.remove(image.handle)
       ImgMemory.pixelformat=pf24bit
       imgMemory.fillrect(0,0,imgMemory.width,imgMemory.height,&hffffff)
       image.repaint
       filename="Sans Titre"
       OPEN.FileName=""
       form.CAPTION=application.title+" - "+filename
      END IF
     END SUB

'============================
' Selection menu fermer
'============================
     SUB SelectMenuClose
      DIM msgButton AS INTEGER

      IF FlagModif THEN
       msgButton=MESSAGEBOX("Sauver fichier?",application.title,35)
       IF msgButton<>mrCancel THEN
        IF msgButton=mrYes THEN
         SelectMenuSave
        END IF
        FlagUndo=false
        FlagModif=false
        IF focus.visible THEN focus.remove(image.handle)
        ImgMemory.pixelformat=pf24bit
        imgMemory.fillrect(0,0,imgMemory.width,imgMemory.height,&hffffff)
        image.repaint
        filename="Sans Titre"
        OPEN.FileName=""
        form.CAPTION=application.title+" - "+filename
       END IF
      ELSE
       FlagUndo=false
       FlagModif=false
       IF focus.visible THEN focus.remove(image.handle)
       ImgMemory.pixelformat=pf24bit
       imgMemory.fillrect(0,0,imgMemory.width,imgMemory.height,&hffffff)
       image.repaint
       filename="Sans Titre"
       OPEN.FileName=""
       form.CAPTION=application.title+" - "+filename
      END IF
     END SUB

'============================
' Selection menu ouvrir
'============================
     SUB SelectMenuOpen
      DIM msgButton AS INTEGER

      IF FlagModif THEN
       msgButton=MESSAGEBOX("Sauver fichier?",application.title,35)
       IF msgButton<>mrCancel THEN
        IF msgButton=mrYes THEN
         SelectMenuSave
        END IF
        FlagUndo=false
        FlagModif=false
        IF OPEN.EXECUTE THEN
         IF focus.visible THEN focus.remove(image.handle)
         IF INSTR(LCASE$(OPEN.FileName),".bmp")>0 THEN
          imgMemory.LoadFromFile(OPEN.FileName)
          ImgMemory.pixelformat=pf24bit
         ELSE
          imgMemory.LoadOtherImage(OPEN.FileName,true,"french")
         END IF
         FileName=OPEN.FileName
         image.width=imgMemory.width
         image.height=imgMemory.height
         imgWidth=imgMemory.width
         imgHeight=imgMemory.height
         Form.CAPTION=application.title+" - "+filename
         Image.repaint
        END IF
       END IF
      ELSE
       FlagUndo=false
       FlagModif=false
       IF OPEN.EXECUTE THEN
        IF focus.visible THEN focus.remove(image.handle)
        IF INSTR(LCASE$(OPEN.FileName),".bmp")>0 THEN
         imgMemory.LoadFromFile(OPEN.FileName)
         ImgMemory.pixelformat=pf24bit
        ELSE
         imgMemory.LoadOtherImage(OPEN.FileName,true,"french")
        END IF
        FileName=OPEN.FileName
        image.width=imgMemory.width
        image.height=imgMemory.height
        imgWidth=imgMemory.width
        imgHeight=imgMemory.height
        Form.CAPTION=application.title+" - "+filename
        Image.repaint
       END IF
      END IF
     END SUB

'============================
' Selection menu sauver sous
'============================
     SUB SelectMenuSaveAs

      SaveDialog.InitialDir=CURDIR$
      IF INSTR(LCASE$(FileName),".bmp")>0 THEN SaveDialog.FilterIndex=1
      IF INSTR(LCASE$(FileName),".jpg")>0 THEN SaveDialog.FilterIndex=2
      SaveDialog.FileName=FileName
      IF saveDialog.EXECUTE THEN
       FileName=SaveDialog.FileName
       OPEN.Filename=SaveDialog.FileName
       IF INSTR(LCASE$(FileName),".bmp")=0 AND SaveDialog.FilterIndex=1 THEN
        FileName=FileName+".bmp"
       END IF
       IF INSTR(LCASE$(FileName),".jpg")=0 AND SaveDialog.FilterIndex=2 THEN
        FileName=FileName+".jpg"
       END IF
       form.CAPTION=application.title+" - "+FileName
       screen.cursor=crHourGlass
       IF INSTR(LCASE$(FileName),".bmp")>0 THEN
        save24.pixelformat=5
        save24.width=imgmemory.width
        save24.height=imgmemory.height
        save24.draw(0,0,imgmemory.bmp)
        save24.pixelformat=6
        save24.SaveToFile(filename)
       ELSE
        imgMemory.SaveAsJpg(filename,100)
       END IF
       screen.cursor=crDefault
       FlagUndo=false
       FlagModif=false
      END IF
     END SUB

'============================
' Selection menu sauver
'============================
     SUB SelectMenuSave

      IF FileName="Sans Titre" THEN
       SelectMenuSaveAs
      ELSE
       OPEN.Filename=SaveDialog.FileName
       screen.cursor=crHourGlass
       IF INSTR(LCASE$(FileName),".bmp")>0 THEN
        save24.pixelformat=5
        save24.width=imgmemory.width
        save24.height=imgmemory.height
        save24.draw(0,0,imgmemory.bmp)
        save24.pixelformat=6
        save24.SaveToFile(filename)
       ELSE
        imgMemory.SaveAsJpg(filename,100)
       END IF
       screen.cursor=crDefault
       FlagUndo=false
       FlagModif=false
      END IF
     END SUB

'============================
' Selection couleur crayon
'============================
     SUB SelectPenColor
      ColorDial.CAPTION="Couleur du crayon"
      IF ColorDial.EXECUTE THEN
       Panel2.COLOR=ColorDial.COLOR
       pencolor=ColorDial.COLOR
      END IF
     END SUB

'============================
' Selection couleur de fond
'============================
     SUB SelectBackcolor
      ColorDial.CAPTION="Couleur de fond"
      IF ColorDial.EXECUTE THEN
       Panel3.COLOR=ColorDial.COLOR
       backcolor=ColorDial.COLOR
      END IF
     END SUB

'============================
' Selection pipette
'============================
     SUB SelectPipe
      IF btPipe.down AND BtZoom.down=false THEN
       ResetPaste
       IF focus.visible THEN focus.remove(image.handle)
       TypeDraw=1
       image.cursor=crdefault
      ELSEIF BtZoom.down=false THEN
       TypeDraw=0
      ELSE
       MemoTypeDraw=1
      END IF
     END SUB

'============================
' Selection menu miroir x
'============================
     SUB SelectMenuMirrorX
      IF focus.visible THEN focus.remove(image.handle)
      TransfertImgUndo
      ImgEffect.pixelformat=ImgMemory.pixelformat
      ImgEffect.width=ImgMemory.width
      ImgEffect.height=ImgMemory.height
      ImgEffect.bmp=ImgMemory.bmp
      ImgEffect.mirror(0,0,ImgEffect.width,ImgEffect.height)
      ImgMemory.bmp=ImgEffect.bmp
      image.repaint
     END SUB

'============================
' Selection menu miroir y
'============================
     SUB SelectMenuMirrorY
      IF focus.visible THEN focus.remove(image.handle)
      TransfertImgUndo
      ImgEffect.pixelformat=ImgMemory.pixelformat
      ImgEffect.width=ImgMemory.width
      ImgEffect.height=ImgMemory.height
      ImgEffect.bmp=ImgMemory.bmp
      ImgEffect.flip(0,0,ImgEffect.width,ImgEffect.height)
      ImgMemory.bmp=ImgEffect.bmp
      image.repaint
     END SUB

'============================
' Selection menu inverser
'============================
     SUB SelectMenuInvert
      IF focus.visible THEN focus.remove(image.handle)
      TransfertImgUndo
      ImgEffect.pixelformat=ImgMemory.pixelformat
      ImgEffect.width=ImgMemory.width
      ImgEffect.height=ImgMemory.height
      ImgEffect.bmp=ImgMemory.bmp
      ImgEffect.invertColor(0,0,ImgEffect.width,ImgEffect.height)
      ImgMemory.bmp=ImgEffect.bmp
      image.repaint
     END SUB

'=================================
' Selection menu inverser couleur
'=================================
     SUB SelectMenuInvertColor
      IF focus.visible THEN focus.remove(image.handle)
      TransfertImgUndo
      ImgEffect.pixelformat=ImgMemory.pixelformat
      ImgEffect.width=ImgMemory.width
      ImgEffect.height=ImgMemory.height
      ImgEffect.bmp=ImgMemory.bmp
      source.left=0
      source.top=0
      source.right=ImgMemory.width
      source.bottom=ImgMemory.height
      dest.left=0
      dest.top=0
      dest.right=ImgMemory.width
      dest.bottom=ImgMemory.height
      imgMemory.fillrect(0,0,imgMemory.width,imgMemory.height,backcolor)
      imgMemory.copymode=cmSrcInvert
      imgMemory.copyrect(Dest,ImgEffect,Source)
      imgMemory.copymode=cmSrcCopy
      image.repaint
     END SUB

'============================
' Selection menu coloriser
'============================
     SUB SelectMenuColoring
      IF focus.visible THEN focus.remove(image.handle)
      TransfertImgUndo
      ImgEffect.pixelformat=ImgMemory.pixelformat
      ImgEffect.width=ImgMemory.width
      ImgEffect.height=ImgMemory.height
      ImgEffect.bmp=ImgMemory.bmp
      source.left=0
      source.top=0
      source.right=ImgMemory.width
      source.bottom=ImgMemory.height
      dest.left=0
      dest.top=0
      dest.right=ImgMemory.width
      dest.bottom=ImgMemory.height
      imgMemory.fillrect(0,0,imgMemory.width,imgMemory.height,backcolor)
      imgMemory.copymode=cmMergeCopy
      imgMemory.copyrect(Dest,ImgEffect,Source)
      imgMemory.copymode=cmSrcCopy
      image.repaint
     END SUB


'===================================
' Selection menu transparence image
'===================================
     SUB SelectMenuTransparentImage
      IF focus.visible THEN focus.remove(image.handle)
      TransfertImgUndo
      ImgEffect.pixelformat=ImgMemory.pixelformat
      ImgEffect.width=ImgMemory.width
      ImgEffect.height=ImgMemory.height
      ImgEffect.bmp=ImgMemory.bmp
      source.left=0
      source.top=0
      source.right=ImgMemory.width
      source.bottom=ImgMemory.height
      dest.left=0
      dest.top=0
      dest.right=ImgMemory.width
      dest.bottom=ImgMemory.height
      imgMemory.fillrect(0,0,imgMemory.width,imgMemory.height,backcolor)
      imgMemory.copymode=cmMergePaint
      imgMemory.copyrect(Dest,ImgEffect,Source)
      imgMemory.copymode=cmSrcCopy
      image.repaint
     END SUB

'===================================
' Selection menu supprimer couleur
'===================================
     SUB SelectMenuRemoveColor
      DIM i AS INTEGER
      DIM j AS INTEGER

      IF focus.visible THEN focus.remove(image.handle)
      screen.cursor=crHourGlass
      TransfertImgUndo
      FOR i=0 TO ImgMemory.width
       FOR j=0 TO ImgMemory.height
        IF image.Pixel(i,j)=backcolor THEN ImgMemory.pset(i,j,&hffffff)
       NEXT j
      NEXT i
      screen.cursor=crDefault
      image.repaint
     END SUB

'=============================
' Selection menu rotation 90°
'=============================
     SUB SelectMenuRotation
      IF focus.visible THEN focus.remove(image.handle)
      TransfertImgUndo
      screen.cursor=crHourGlass
      ImgEffect.pixelformat=ImgMemory.pixelformat
      IF ImgMemory.width>ImgMemory.height THEN
       ImgEffect.width=ImgMemory.width
       ImgEffect.height=ImgMemory.width
       ImgEffect.draw(0,((ImgMemory.width-ImgMemory.height)/2),ImgMemory.bmp)
       source.left=(ImgMemory.width-ImgMemory.height)/2
       source.top=0
       source.right=source.left+ImgMemory.height
       source.bottom=ImgMemory.width
       dest.left=0
       dest.top=0
       dest.right=ImgMemory.height
       dest.bottom=ImgMemory.width
      ELSE
       ImgEffect.width=ImgMemory.height
       ImgEffect.height=ImgMemory.height
       ImgEffect.draw(((ImgMemory.height-ImgMemory.width)/2),0,ImgMemory.bmp)
       source.left=0
       source.top=(ImgMemory.height-ImgMemory.width)/2
       source.right=ImgMemory.height
       source.bottom=source.top+ImgMemory.width
       dest.left=0
       dest.top=0
       dest.right=ImgMemory.height
       dest.bottom=ImgMemory.width
      END IF
      ImgEffect.rotate((ImgEffect.width/2),(ImgEffect.height/2),90)
      ImgMemory.width=Imgheight
      ImgMemory.height=Imgwidth
      ImgMemory.copyrect(dest,ImgEffect,source)
      Image.width=Imgheight
      Image.height=Imgwidth
      Imgheight=Image.height
      Imgwidth=Image.width
      screen.cursor=crdefault
      image.repaint
     END SUB

'============================
' Selection zoom
'============================
     SUB SelectZoom
      IF BtZoom.down THEN
       MemoTypeDraw=TypeDraw
       ResetPaste
       IF focus.visible THEN focus.remove(image.handle)
       TypeDraw=0
       ImageMenu.enabled=false
       EditMenu.enabled=false
       FileMenu.enabled=false
       image.cursor=crnone
      ELSE
       image.cursor=crdefault
       IF focus.visible THEN focus.remove(image.handle)
       FileMenu.enabled=true
       ImageMenu.enabled=true
       EditMenu.enabled=true
       TypeDraw=MemoTypeDraw
       IF flagZoom THEN
        ImgMemory.width=imgwidth
        ImgMemory.height=imgheight
        ImgMemory.bmp=ImgTmp.bmp
        image.width=imgwidth
        image.height=imgheight
        IF flagFill=false THEN
         flagModif=false
         flagUndo=false
        END IF
        image.repaint
       END IF
       flagFill=false
       flagZoom=false
      END IF
     END SUB

'============================
' Zoom image
'============================
     SUB Zoom
      TransfertImgUndo
      ImgZoom.width=ZoomWidth
      ImgZoom.height=ZoomHeight
      imgZoom.pixelformat=ImgMemory.pixelformat
      source.left=focus.left
      source.top=focus.top
      source.right=focus.left+focus.width
      source.bottom=focus.top+focus.height
      dest.left=0
      dest.top=0
      dest.right=focus.width
      dest.bottom=focus.height
      imgZoom.copyrect(dest,image,source)
      ImgTmp.width=ImgMemory.width
      ImgTmp.height=ImgMemory.height
      ImgTmp.bmp=ImgMemory.bmp
      ImgTmp.pixelformat=ImgMemory.pixelformat
      source.left=0
      source.top=0
      source.right=(ImgZoom.width*ValZoom)/100
      source.bottom=(ImgZoom.height*ValZoom)/100
      ImgMemory.width=(ImgZoom.width*ValZoom)/100
      ImgMemory.height=(ImgZoom.height*ValZoom)/100
      ImgMemory.StretchDraw(source,ImgZoom.bmp)
      image.width=(ImgZoom.width*ValZoom)/100
      image.height=(ImgZoom.height*ValZoom)/100
      image.repaint
     END SUB

'============================
' Selection focus
'============================
     SUB SelectFocus
      IF btFocus.down AND BtZoom.down=false THEN
       flagSelectAll=false
       IF focus.visible THEN focus.remove(image.handle)
       ResetPaste
       TypeDraw=10
       image.cursor=crdefault
      ELSEIF BtZoom.down=false THEN
       TypeDraw=0
       IF focus.visible THEN focus.remove(image.handle)
       ItemCut.enabled=false
       ItemCopy.enabled=false
      ELSE
       MemoTypeDraw=10
      END IF
     END SUB

'============================
' Selection crayon
'============================
     SUB SelectPen
      IF btPen.down AND BtZoom.down=false THEN
       ResetPaste
       IF focus.visible THEN focus.remove(image.handle)
       TypeDraw=2
       image.cursor=1
       image.pensize=VAL(PenSize.item(PenSize.itemindex))
       imgMemory.pensize=VAL(PenSize.item(PenSize.itemindex))
      ELSEIF BtZoom.down=false THEN
       TypeDraw=0
       image.cursor=crdefault
      ELSE
       MemoTypeDraw=2
      END IF
     END SUB

'============================
' Selection pinceau
'============================
     SUB SelectPaint
      IF btBrush.down AND BtZoom.down=false THEN
       ResetPaste
       IF focus.visible THEN focus.remove(image.handle)
       TypeDraw=2
       image.cursor=1
       image.pensize=VAL(PenSize.item(PenSize.itemindex))*10
       imgMemory.pensize=VAL(PenSize.item(PenSize.itemindex))*10
      ELSEIF BtZoom.down=false THEN
       TypeDraw=0
       image.cursor=crdefault
       image.pensize=VAL(PenSize.item(PenSize.itemindex))
       imgMemory.pensize=VAL(PenSize.item(PenSize.itemindex))
      ELSE
       MemoTypeDraw=2
      END IF
     END SUB

'============================
' Selection ligne
'============================
     SUB SelectLine
      IF btLine.down AND BtZoom.down=false THEN
       ResetPaste
       IF focus.visible THEN focus.remove(image.handle)
       TypeDraw=4
       image.cursor=1
       image.pensize=VAL(PenSize.item(PenSize.itemindex))
       imgMemory.pensize=VAL(PenSize.item(PenSize.itemindex))
      ELSEIF BtZoom.down=false THEN
       image.cursor=crdefault
       TypeDraw=0
      ELSE
       MemoTypeDraw=4
      END IF
     END SUB

'============================
' Selection rectangle
'============================
     SUB SelectRect
      IF btSquare.down AND BtZoom.down=false  THEN
       ResetPaste
       IF focus.visible THEN focus.remove(image.handle)
       TypeDraw=5
       image.cursor=1
       image.pensize=VAL(PenSize.item(PenSize.itemindex))
       imgMemory.pensize=VAL(PenSize.item(PenSize.itemindex))
      ELSEIF BtZoom.down=false THEN
       image.cursor=crdefault
       TypeDraw=0
      ELSE
       MemoTypeDraw=5
      END IF
     END SUB

'============================
' Selection rectangle plein
'============================
     SUB SelectRectFilled
      IF btSquareFilled.down AND BtZoom.down=false THEN
       ResetPaste
       IF focus.visible THEN focus.remove(image.handle)
       TypeDraw=6
       image.cursor=1
       image.pensize=VAL(PenSize.item(PenSize.itemindex))
       imgMemory.pensize=VAL(PenSize.item(PenSize.itemindex))
      ELSEIF BtZoom.down=false THEN
       image.cursor=crdefault
       TypeDraw=0
      ELSE
       MemoTypeDraw=6
      END IF
     END SUB

'============================
' Selection cercle
'============================
     SUB SelectCircle
      IF btCircle.down AND BtZoom.down=false THEN
       ResetPaste
       IF focus.visible THEN focus.remove(image.handle)
       TypeDraw=7
       image.cursor=1
       image.pensize=VAL(PenSize.item(PenSize.itemindex))
       imgMemory.pensize=VAL(PenSize.item(PenSize.itemindex))
      ELSEIF BtZoom.down=false THEN
       image.cursor=crdefault
       TypeDraw=0
      ELSE
       MemoTypeDraw=7
      END IF
     END SUB

'============================
' Selection cercle plein
'============================
     SUB SelectCircleFilled
      IF btCircleFilled.down AND BtZoom.down=false THEN
       ResetPaste
       IF focus.visible THEN focus.remove(image.handle)
       TypeDraw=8
       image.cursor=1
       image.pensize=VAL(PenSize.item(PenSize.itemindex))
       imgMemory.pensize=VAL(PenSize.item(PenSize.itemindex))
      ELSEIF BtZoom.down=false THEN
       image.cursor=crdefault
       TypeDraw=0
      ELSE
       MemoTypeDraw=8
      END IF
     END SUB

'============================
' Selection remplissage
'============================
     SUB SelectFill
      IF btFill.down THEN
       ResetPaste
       IF focus.visible THEN focus.remove(image.handle)
       TypeDraw=9
       image.cursor=1
      ELSE
       image.cursor=crdefault
       TypeDraw=0
      END IF
     END SUB

'============================
' Selection texte
'============================
     SUB SelectText
      IF btText.down AND BtZoom.down=false THEN
       ResetPaste
       IF focus.visible THEN focus.remove(image.handle)
       TypeDraw=3
       image.cursor=crdefault
      ELSEIF BtZoom.down=false THEN
       TypeDraw=0
      ELSE
       MemoTypeDraw=3
      END IF
     END SUB

'================================================
' Selection police du texte boite dialogue texte
'================================================
     SUB SelectTextFont
      IF fontdialog.EXECUTE THEN
       fontdialog.setfont(font)
       EdText.font=font
       imgMemory.font=font
      END IF
     END SUB

'============================================
' Selection annuler boite dialogue texte
'============================================
     SUB AnnulerText
      Form3.CLOSE
      EdText.text=""
      FlagText=false
     END SUB

'===================================
' Selection ok boite dialogue texte
'===================================
     SUB OkText
      TransfertImgUndo
      Form3.CLOSE
      imgMemory.textout(leftText,topText,EdText.text,font.COLOR,-1)
      image.repaint
     END SUB

'==========================================
' Evenement mouse down du composant image
'==========================================
     SUB Start(bt AS INTEGER,x AS INTEGER,y AS INTEGER)
      flagDraw=true
      orx=x
      ory=y
      ox=x
      oy=y
      SELECT CASE typeDraw
      CASE 1
      'pipette couleur
       IF bt=0 THEN
        Panel2.COLOR=image.pixel(x,y)
        pencolor=image.pixel(x,y)
       ELSEIF bt=1 THEN
        Panel3.COLOR=image.pixel(x,y)
        backcolor=image.pixel(x,y)
       END IF
      CASE 2
      'crayon
       TransfertImgUndo
       image.line(x,y,x,y,PenColor)
       imgMemory.line(x,y,x,y,PenColor)
      CASE 3
      'texte
       leftText=x
       topText=y
       Form3.show
      CASE 4
     'ligne
       TransfertImgUndo
       image.mixmode=R2_NOTXORPEN_CAN
       image.line(x,y,x,y,PenColor)
      CASE 5,6
     'rectangle
       TransfertImgUndo
       image.mixmode=R2_NOTXORPEN_CAN
       image.rectangle(x,y,x,y,PenColor)
      CASE 7,8
     'cercle
       TransfertImgUndo
       image.mixmode=R2_NOTXORPEN_CAN
       image.circle(x,y,x,y,PenColor)
      CASE 9
     'remplissage
       TransfertImgUndo
       image.fillSurface(x,y,pencolor)
       imgMemory.fillSurface(x,y,pencolor)
      CASE 10
     'focus
       IF flagPaste=false THEN focus.noResize=false
       focus.showcursor=true
       focus.start(image.handle,x,y)
      END SELECT
      IF btZoom.down AND flagZoom THEN
       image.fillSurface(x,y,pencolor)
       imgTmp.pixel(INT(x/8)+focus.left,INT(y/8)+focus.top)=pencolor
       flagFill=true
      ELSEIF btZoom.down AND flagZoom=false THEN
       focus.remove(image.handle)
       flagZoom=true
       Zoom
       image.cursor=1
      END IF
     END SUB

'=========================================
' Evenement mouse move du composant image
'=========================================
     SUB Move(x AS INTEGER,y AS INTEGER)
      SELECT CASE typeDraw
      CASE 2
       IF flagDraw THEN
        image.line(ox,oy,x,y,PenColor)
        imgMemory.line(ox,oy,x,y,PenColor)
       END IF
      CASE 4
       IF flagDraw THEN
        image.line(orx,ory,ox,oy,PenColor)
        image.line(orx,ory,x,y,PenColor)
       END IF
      CASE 5,6
       IF flagDraw THEN
        image.rectangle(orx,ory,ox,oy,PenColor)
        image.rectangle(orx,ory,x,y,PenColor)
       END IF
      CASE 7,8
       IF flagDraw THEN
        image.circle(orx,ory,ox,oy,PenColor)
        image.circle(orx,ory,x,y,PenColor)
       END IF
      CASE 10
       focus.draw(image.handle,x,y,flagDraw)
      END SELECT
      ox=x
      oy=y
      IF btZoom.down AND flagZoom=false THEN
       focus.showcursor=false
       IF focus.visible THEN focus.remove(image.handle)
       focus.start(image.handle,x,y)
       focus.draw(image.handle,x+ZoomWidth,y+ZoomHeight,true)
      END IF
     END SUB

'=======================================
' Selection mouse up du composant image
'=======================================
     SUB Stop(Bt AS INTEGER,x AS INTEGER,y AS INTEGER)
      IF flagDraw THEN
       image.mixmode=R2_COPYPEN_CAN
       flagDraw=false
      END IF
      SELECT CASE typeDraw
      CASE 4
       image.line(orx,ory,ox,oy,PenColor)
       imgMemory.line(orx,ory,ox,oy,PenColor)
      CASE 5
       image.rectangle(orx,ory,ox,oy,PenColor)
       imgMemory.rectangle(orx,ory,ox,oy,PenColor)
      CASE 6
       image.rectangleFilled(orx,ory,ox,oy,PenColor,backcolor)
       imgMemory.rectangleFilled(orx,ory,ox,oy,PenColor,backcolor)
      CASE 7
       image.circle(orx,ory,ox,oy,PenColor)
       imgMemory.circle(orx,ory,ox,oy,PenColor)
      CASE 8
       image.circleFilled(orx,ory,ox,oy,PenColor,backcolor)
       imgMemory.circleFilled(orx,ory,ox,oy,PenColor,backcolor)
      CASE 10
       IF FlagPaste THEN
        TransfertImgUndo
        focus.remove(image.handle)
        IF focus.inside THEN
         image.repaint
         leftPaste=focus.left
         topPaste=focus.top
         image.draw(focus.left,focus.top,ImgEffect.bmp)
         focus.noResize=true
         focus.start(image.handle,focus.left,focus.top)
         focus.draw(image.handle,focus.left+ImgEffect.width,focus.top+ImgEffect.height,true)
        ELSE
         ImgMemory.draw(leftPaste,topPaste,ImgEffect.bmp)
         TypeDraw=0
         focus.remove(image.handle)
         FlagPaste=false
         image.repaint
        END IF
       ELSE
        focus.stop(image.handle,false)
       END IF
      END SELECT
     END SUB

'============================
' Selection menu dimensions
'============================
     SUB SelectMenuDimensions
      WidthEdit.text=STR$(imgWidth)
      HeightEdit.text=STR$(imgHeight)
      Form2.show
     END SUB

'========================================
' Selection ok boite dialogue dimensions
'========================================
     SUB OkDimensions
      TransfertImgUndo
      IF Choix1.checked THEN
       imgWidth=(ImgMemory.width*VAL(pourcent.item(pourcent.itemIndex)))/100
       imgHeight=(ImgMemory.height*VAL(pourcent.item(pourcent.itemIndex)))/100
      ELSE
       imgWidth=VAL(WidthEdit.text)
       imgHeight=VAL(HeightEdit.text)
      END IF
      IF CheckStretch.checked THEN
       ImgTmp.width=ImgMemory.width
       ImgTmp.height=ImgMemory.height
       ImgTmp.bmp=ImgMemory.bmp
       ImgTmp.pixelformat=ImgMemory.pixelformat
       source.left=0
       source.top=0
       source.right=imgWidth
       source.bottom=imgHeight
       ImgMemory.width=imgWidth
       ImgMemory.height=imgHeight
       ImgMemory.StretchDraw(source,ImgTmp.bmp)
      ELSE
       imgMemory.width=imgWidth
       imgMemory.height=imgHeight
      END IF
      image.width=imgWidth
      image.height=imgHeight
      Form2.CLOSE
     END SUB

'=============================================
' Selection annuler boite dialogue dimensions
'=============================================
     SUB AnnulerDimensions
      WidthEdit.text=STR$(imgWidth)
      HeightEdit.text=STR$(imgHeight)
      Form2.CLOSE
     END SUB

     SUB ChoixDim(Sender AS QRADIOBUTTON)
      IF Sender.tag THEN
       pourcent.enabled=false
      ELSE
       pourcent.enabled=true
      END IF
     END SUB

'============================
' Selection taille crayon
'============================
     SUB SelectPenSize
      IF IF btBrush.down THEN
       image.pensize=VAL(PenSize.item(PenSize.itemindex))*10
       imgMemory.pensize=VAL(PenSize.item(PenSize.itemindex))*10
      ELSE
       image.pensize=VAL(PenSize.item(PenSize.itemindex))
       imgMemory.pensize=VAL(PenSize.item(PenSize.itemindex))
      END IF
     END SUB

'============================
' Affichage grille zoom
'============================
     SUB Grille
      DIM ptHorz AS INTEGER
      DIM ptVert AS INTEGER
      DIM i AS INTEGER

      ptHorz=0
      ptVert=0
      image.pensize=1
      FOR i=1 TO INT(imgMemory.height/8)
       ptHorz=ptHorz+8
       image.line(0,ptHorz,imgMemory.width,ptHorz,&h0)
      NEXT i
      FOR i=1 TO INT(imgMemory.width/8)
       ptVert=ptVert+8
       image.line(ptVert,0,ptVert,imgMemory.height,&h0)
      NEXT i
      IF btBrush.down THEN
       image.pensize=VAL(PenSize.item(PenSize.itemindex))*10
      ELSE
       image.pensize=VAL(PenSize.item(PenSize.itemindex))
      END IF
     END SUB

'================================
' Mise a jour image d'annulation
'================================
     SUB TransfertImgUndo
      imgUndo.pixelformat=ImgMemory.pixelformat
      ImgUndo.width=ImgMemory.width
      ImgUndo.height=ImgMemory.height
      ImgUndo.bmp=ImgMemory.bmp
      FlagUndo=true
      FlagModif=true
     END SUB

'===============================
' Evenement onkey fenetre ecran
'===============================
     SUB FermerEcran(Key AS WORD)
      IF Key=VK_ESCAPE THEN
       form4.CLOSE
       form.show
      END IF
     END SUB

'================================
' Selection menu affichage ecran
'================================
     SUB SelectMenuImageShow
      DIM reduction AS INTEGER
      DIM reduction1 AS INTEGER
      DIM reduction2 AS INTEGER
      DIM showWidth AS INTEGER
      DIM showHeight AS INTEGER

      form.visible=false
      form4.show
      reduction=100
      reduction1=100
      reduction2=100
      showWidth=ImgMemory.width
      showHeight=ImgMemory.Height
      IF showWidth>Screen.Width OR showHeight>Screen.Height THEN
       IF showWidth>Screen.Width THEN
        reduction1=100-Ratio(showWidth,Screen.Width)
       END IF
       IF showHeight>Screen.Height THEN
        reduction2=100-Ratio(showHeight,Screen.Height)
       END IF
       IF reduction1<reduction2 THEN
        reduction=reduction1
       ELSE
        reduction=reduction2
       END IF
       IF reduction1=reduction2 THEN reduction=reduction1
      END IF
      ecran.left=INT((Screen.Width-((showWidth*reduction)/100))/2)
      ecran.top=INT((Screen.Height-((showHeight*reduction)/100))/2)
      ecran.Width=INT(showWidth*(reduction/100))
      ecran.Height=INT(showHeight*(reduction/100))
      ecran.bmp=ImgMemory.bmp
      ecran.visible=true
     END SUB

'============================
' Selection menu a propos
'============================
     SUB SelectMenuAbout
      about.Appname=Application.title
      about.Appversion="1.1"
      about.CAPTION="A propos de "+about.Appname
      about.text="Auteur:Glodt dominique"+CHR$(13)+"Copyright(c)software 2000-2004 "
      about.image.icohandle=ico
      about.show
     END SUB

'============================
' Reset boutons
'============================
     SUB ResetButton
      image.cursor=crDefault
      IF btFocus.down THEN btFocus.down=false
      IF btPipe.down THEN btPipe.down=false
      IF btFill.down THEN btFill.down=false
      IF btText.down THEN btText.down=false
      IF btBrush.down THEN btBrush.down=false
      IF btPen.down THEN btPen.down=false
      IF btLine.down THEN btLine.down=false
      IF btSquare.down THEN btSquare.down=false
      IF btSquareFilled.down THEN btSquareFilled.down=false
      IF btCircle.down THEN btCircle.down=false
      IF btCircleFilled.down THEN btCircleFilled.down=false
     END SUB

'====================================
' Impression image
'====================================
     SUB SelectMenuPrint
      DIM R AS QRECT
      DIM factor AS SINGLE
      DIM factorX AS SINGLE
      DIM factorY AS SINGLE

      R.Top=0
      R.Left=0
      IF imgMemory.width*PrtInfo.scale()>printer.pagewidth OR imgMemory.height*PrtInfo.scale()>printer.pageheight THEN
       factorX=printer.pagewidth/imgMemory.width
       factorY=printer.pageheight/imgMemory.height
       IF factorX<factorY THEN
        factor=factorX
       ELSE
        factor=factorY
       END IF
       R.Right=imgMemory.width*factor
       R.Bottom=imgMemory.height*factor
      ELSE
       R.Right=imgMemory.width*PrtInfo.scale()
       R.Bottom=imgMemory.height*PrtInfo.scale()
      END IF
      Printer.BeginDoc
      Printer.StretchDraw(R,imgMemory.Bmp)
      Printer.EndDoc
     END SUB

'====================================
' Configuration imprimante
'====================================
     SUB SelectMenuConfig
      PgSetup.orientation=printer.orientation
      IF PgSetup.EXECUTE THEN
       printer.orientation=PgSetup.orientation
      END IF
     END SUB
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Wed 2024-4-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2003-12-31 15:52:46