Guidance
指路人
g.yi.org
software / rapidq / Examples / Tools - IDE, Designer, Builder / FreeQ IDE src / tools / Paint / Paint.bas

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

  

'=========================================================================
' PAINT Version 1.1 6/9/2010
' Auteur:D.Glodt, modified by JohnK
'=========================================================================
     $TYPECHECK ON
     $OPTION ICON "palet.ico"
     $INCLUDE <rapidq2.INC>
     $INCLUDE <QFuncLib.INC>
     $INCLUDE <QDrawFocus.INC>

'==========================================================================
' ressources bitmap
'==========================================================================
     $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 FUNCTION LoadCursorFromFile LIB "USER32" ALIAS "LoadCursorFromFileA" (CursorFileName AS STRING) AS LONG

     Screen.Cursors(1)= LoadCursorFromFile("PEN.CUR")
     Screen.Cursors(2)= LoadCursorFromFile("FILL.CUR")
     Screen.Cursors(3)= LoadCursorFromFile("PICK.CUR")
     Screen.Cursors(4)= LoadCursorFromFile("SPRAY.CUR")
     Screen.Cursors(5)= LoadCursorFromFile("BRUSH.CUR")

     DECLARE FUNCTION ExtractFileName(FileName AS STRING) AS STRING
     DECLARE SUB Paint
     DECLARE SUB SelectMenuExit
     DECLARE SUB SelectMenuNew
     DECLARE SUB SelectMenuOpen
     DECLARE SUB SelectMenuClose
     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
     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 SelectMenuUndo
     DECLARE SUB SelectMenuSaveAs
     DECLARE SUB SelectMenuSave
     DECLARE SUB SelectMenuDimensions
     DECLARE SUB SelectMenuFormat16
     DECLARE SUB SelectMenuFormat256
     DECLARE SUB SelectMenuFormat24
     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 ShowFormat
     DECLARE SUB OpenCL
     DECLARE SUB CreateColorGrid
     DECLARE SUB PickColors(Button%, X%, Y%, Shift%,Sender AS QPANEL)
'==========================================================================
' declarations données
'==========================================================================
     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 ImgTmp AS QBITMAP
     DIM ImgZoom AS QBITMAP
     DIM ImgEffect AS QBitmapEx
     DIM ImgUndo AS QBITMAP
     DIM OPEN AS QOPENDIALOG
     OPEN.CAPTION="Open image"
     OPEN.Filter="Files bitmap(*.bmp)|*.bmp"
     DIM SaveDialog AS QSAVEDIALOG
     SaveDialog.Filter="Files bitmap(*.bmp)|*.bmp"
     SaveDialog.CAPTION= "Save image"
     DIM ColorDial AS QColorDialog
     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 flagUndo AS INTEGER
     DIM flagModif 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="Noname"
     DIM about AS QAbout
     DIM p(15) AS QPANEL
     DIM offset AS INTEGER

'==========================================================================
' interface application
'==========================================================================
     CREATE Form1 AS QFORMEX
      IcoHandle = ico
      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="Pick Color"
        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="Fill"
        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="Text"
        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="Brush"
        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="Pen"
        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="Line"
        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="Filled Rectangle"
        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="Ellipse"
        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="Filled Ellipse"
        GroupIndex=1
        AllowAllUp=true
        OnClick=SelectCircleFilled
       END CREATE
       CREATE Pn AS QPANEL
        Top =  154
        Left = 5
        Width = 50
        Height = 50
        BevelInner = bvLowered
        BevelOuter = bvNone
        CREATE Panel3 AS QPANEL
         Left=5
         Top=10
         Width=22
         Height=22
         BevelInner= bvNone
         BevelOuter= bvNone
         ShowHint=1
         Hint= "Background Color"
         COLOR=&h0
         OnClick=SelectBackcolor
        END CREATE
        CREATE Panel2 AS QPANEL
         Left=22
         Top= 20
         Width=22
         Height=22
         BevelInner= bvNone
         BevelOuter= bvNone
         ShowHint=1
         Hint="Pen Color"
         COLOR=&hffffff
         OnClick=SelectPenColor
        END CREATE
       END CREATE
       CREATE PenSize AS QCOMBOBOX
        style=2
        AddItems "1","2","3","4","5","6","7","8","9","10"
        Left=5
        Top=214
        Width=49
        ShowHint=1
        Hint="Pen Size"
        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
      CREATE StatusBar AS QSTATUSBAR
       Align = alBottom
       AddPanels "0","1","2"
       Panel(0).CAPTION = ""
       Panel(0).Width = 100
       Panel(0).Alignment = taCenter
       Panel(1).CAPTION = ""
       Panel(1).Width = 120
       Panel(1).Alignment = taCenter
       Panel(2).CAPTION = ""
       Panel(2).Alignment = taCenter
      END CREATE
      CREATE cgPanel AS QPANEL
       Height = 34
       Align = alBottom
       BevelInner = bvNone
       BevelOuter = bvNone
      END CREATE
      OnClose=SelectMenuExit
      OnResize=ResizePaint
      OnPaint = CreateColorGrid
     END CREATE

'==========================================================================
' menu application
'==========================================================================
     CREATE MainMenu AS QMAINMENU
      PARENT=Form1
      CREATE FileMenu AS QMENUITEM
       CAPTION="File"
       CREATE ItemNew AS QMENUITEM
        CAPTION="New"
        OnClick=SelectMenuNew
       END CREATE
       CREATE ItemOpen AS QMENUITEM
        CAPTION="Open"
        OnClick=SelectMenuOpen
       END CREATE
       CREATE ItemClose AS QMENUITEM
        CAPTION="Close"
        OnClick=SelectMenuClose
       END CREATE
       CREATE ItemSave AS QMENUITEM
        CAPTION="Save"
        OnClick=SelectMenuSave
       END CREATE
       CREATE ItemSaveAs AS QMENUITEM
        CAPTION="Save As..."
        OnClick=SelectMenuSaveAs
       END CREATE
       CREATE ItemSeparator1 AS QMENUITEM
        CAPTION="-"
       END CREATE
       CREATE ItemQuit AS QMENUITEM
        CAPTION="Exit"
        OnClick=SelectMenuExit
       END CREATE
      END CREATE
      CREATE EditMenu AS QMENUITEM
       CAPTION="Edit"
       OnClick=SelectMenuEdit
       CREATE ItemUndo AS QMENUITEM
        CAPTION="Undo"
        Enabled=false
        OnClick=SelectMenuUndo
       END CREATE
       CREATE ItemSeparator2 AS QMENUITEM
        CAPTION="-"
       END CREATE
       CREATE ItemCut AS QMENUITEM
        CAPTION="Cut"
        Enabled=false
        OnClick=SelectMenuCut
       END CREATE
       CREATE ItemCopy AS QMENUITEM
        CAPTION="Copy"
        Enabled=false
        OnClick=SelectMenuCopy
       END CREATE
       CREATE ItemPaste AS QMENUITEM
        CAPTION="Paste"
        Enabled=false
        OnClick=SelectMenuPaste
       END CREATE
       CREATE ItemPasteFrom AS QMENUITEM
        CAPTION="Paste From..."
        OnClick=SelectMenuPasteFrom
       END CREATE
       CREATE ItemTransparent AS QMENUITEM
        CAPTION="Transparent"
        OnClick=SelectMenuTransparent
       END CREATE
      END CREATE
      CREATE ShowMenu AS QMENUITEM
       CAPTION="Show"
       CREATE ItemImageShow AS QMENUITEM
        CAPTION="Image Show"
        OnClick=SelectMenuImageShow
       END CREATE
      END CREATE
      CREATE ImageMenu AS QMENUITEM
       CAPTION="Image"
       CREATE ItemDimensions AS QMENUITEM
        CAPTION="Dimensions..."
        OnClick=SelectMenuDimensions
       END CREATE
       CREATE ItemSeparator3 AS QMENUITEM
        CAPTION="-"
       END CREATE
       CREATE ItemMirrorX AS QMENUITEM
        CAPTION="Mirror X"
        OnClick=SelectMenuMirrorX
       END CREATE
       CREATE ItemMirrorY AS QMENUITEM
        CAPTION="Mirror Y"
        OnClick=SelectMenuMirrorY
       END CREATE
       CREATE ItemTurn90 AS QMENUITEM
        CAPTION="Turn 90°"
        OnClick=SelectMenuRotation
       END CREATE
       CREATE ItemInvertColor AS QMENUITEM
        CAPTION="Invert colors"
        OnClick=SelectMenuInvert
       END CREATE
       CREATE ItemNegatifColor AS QMENUITEM
        CAPTION="Negativ color"
        OnClick=SelectMenuInvertColor
       END CREATE
       CREATE ItemColoring AS QMENUITEM
        CAPTION="Coloring"
        OnClick=SelectMenuColoring
       END CREATE
       CREATE ItemTransparentImage AS QMENUITEM
        CAPTION="Transparent"
        OnClick=SelectMenuTransparentImage
       END CREATE
       CREATE ItemRemoveColor AS QMENUITEM
        CAPTION="Remove color"
        OnClick=SelectMenuRemoveColor
       END CREATE
       CREATE ItemConvertFormat AS QMENUITEM
        CAPTION="&Convert color format"
        CREATE ItemFormat16 AS QMENUITEM
         CAPTION="Format 16 colors"
         OnClick=SelectMenuFormat16
        END CREATE
        CREATE ItemFormat256 AS QMENUITEM
         CAPTION="Format 256 colors"
         OnClick=SelectMenuFormat256
        END CREATE
        CREATE ItemFormat24 AS QMENUITEM
         CAPTION="Format coulors 24 bits"
         OnClick=SelectMenuFormat24
        END CREATE
       END CREATE
      END CREATE
      CREATE HelpMenu AS QMENUITEM
       CAPTION="?"
       CREATE ItemAbout AS QMENUITEM
        CAPTION="About..."
        OnClick=SelectMenuAbout
       END CREATE
      END CREATE
     END CREATE


'==========================================================================
' boite dialogue dimensions
'==========================================================================
     CREATE Form2 AS QFORM
      CAPTION="Dimensions"
      Width=280
      Height=140
      Center
      BorderStyle=3
      CREATE GROUPBOX AS QGROUPBOX
       CAPTION = " Bitmap Dimensions "
       Align = alClient
       CREATE Label1 AS QLABEL
        CAPTION="Width :"
        Left=10
        Top=21
        Width=48
        Height=21
        Transparent=1
       END CREATE
       CREATE Label2 AS QLABEL
        CAPTION="Height :"
        Left=10
        Top=47
        Width=40
        Transparent=1
       END CREATE
       CREATE WidthEdit AS QEDIT
        Left=55
        Top=20
        Width=60
        TabOrder=1
       END CREATE
       CREATE HeightEdit AS QEDIT
        Left=55
        Top=45
        Width=60
        TabOrder=2
       END CREATE
       CREATE CheckStretch AS QCHECKBOX
        CAPTION="Stretch"
        Left=135
        Top=20
        Width=137
        TabOrder=3
       END CREATE
       CREATE BtOk AS QBUTTON
        CAPTION="Ok"
        Left=130
        Top=82
        Width=59
        TabOrder=4
        OnClick=OkDimensions
       END CREATE
       CREATE BtUndo AS QBUTTON
        CAPTION="Abort"
        Left=200
        Top=82
        Width=59
        TabOrder=5
        OnClick=AnnulerDimensions
       END CREATE
      END CREATE
     END CREATE


'==========================================================================
' boite dialogue insertion texte
'==========================================================================
     CREATE Form3 AS QFORM
      CAPTION="Text"
      Width=347
      Height=125
      BorderStyle=3
      Center
      CREATE BtTextFont AS QBUTTON
       CAPTION="Font"
       Left=266
       Top=3
       Width=67
       OnClick=SelectTextFont
      END CREATE
      CREATE BtTextUndo AS QBUTTON
       CAPTION="Undo Text"
       Left=266
       Top=34
       Width=67
       OnClick=AnnulerText
      END CREATE
      CREATE BtTextOk AS QBUTTON
       CAPTION="Ok"
       Left=266
       Top=64
       Width=67
       OnClick=OkText
      END CREATE
      CREATE EdText AS QEDIT
       autosize=false
       Left=5
       Top=3
       Width=249
       Height=89
      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


'-- command line
     IF COMMANDCOUNT = 1 THEN
      FileName = COMMAND$(1)
      OpenCl
     END IF

     Form1.SHOWMODAL

'------------------------------- ExtractFileName -------------------------------------------
     FUNCTION ExtractFileName(FileName AS STRING) AS STRING
      DIM Length AS INTEGER
      Length = RInStr(FileName, "\\") OR RInStr(FileName, "/") OR RInStr(FileName, "\")
      Result = MID$(FileName, Length+1, LEN(FileName) - Length + 1)
     END FUNCTION
'------------------------------ PickColors ------------------------------------------------
     SUB PickColors(Button%, X%, Y%, Shift%, Sender AS QPANEL)
      IF Button% = 0 THEN  ' add in rapidq.inc ( mbLeft = 0, mbRight = 1, mbMiddle = 2)
       Panel2.COLOR = Sender.COLOR
       pencolor = Sender.COLOR
      END IF
      IF Button% = 1 THEN
       Panel3.COLOR = Sender.COLOR
       backcolor = Sender.COLOR
      END IF
     END SUB
'-------------------------------- Create colorGrid ----------------------------------------
     SUB CreateColorGrid
      DIM i AS INTEGER

      offset = 0
      FOR i = 0 TO 15 DO
       p(i).PARENT = cgPanel
       p(i).Width = 20
       p(i).Height = 20
       p(i).Top = 7
       p(i).Left = offset + 2
       p(i).BevelInner = bvlowered
       p(i).BevelOuter = bvNone
       p(i).COLOR = QBcolor(i)
       p(i).Hint = " Left Click: PenColor" + _
        CHR$(10)+"-----------------------------------------------" + _
        CHR$(10)+ " Right Click: BackgroundColor "
       p(i).ShowHint = True
       p(i).OnMouseDown = PickColors
       INC(offset,20)
      NEXT i
      StatusBar.Panel(0).CAPTION = Format$(" %d x %d ", Image.Width, Image.Height)
     END SUB

'============================
' Evenement affichage image
'============================
     SUB Paint
      image.draw(0,0,imgMemory.bmp)
      IF BtZoom.down AND flagZoom THEN Grille
      IF flagText THEN
       image.textout(leftText,topText,EdText.text,font.COLOR,&hffffff)
       imgMemory.textout(leftText,topText,EdText.text,font.COLOR,&hffffff)
       flagText=false
      END IF
      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 AND focus.visible AND btZoom.down=false THEN
       ItemCut.enabled=true
       ItemCopy.enabled=true
      END IF
      IF image.canPaste() THEN
       ItemPaste.enabled=true
      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
      Image.repaint
      FlagUndo=false
      FlagPaste=false
      ShowFormat
     END SUB

'============================
' Selection menu copier
'============================
     SUB SelectMenuCopy
      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 SUB

'============================
' Selection menu couper
'============================
     SUB SelectMenuCut
      TransfertImgUndo
      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)
      image.repaint
     END SUB

'============================
' Selection menu coller
'============================
     SUB SelectMenuPaste
      ResetButton
      IF focus.visible THEN focus.remove(image.handle)
      ImgEffect.width=ImgEffect.GetWidthClipboard()
      ImgEffect.height=ImgEffect.GetHeightClipboard()
      ImgEffect.PasteFromClipboard(0,0)
      IF ItemTransparent.checked THEN
       ImgEffect.transparent=true
       ImgEffect.transparentColor=backcolor
      ELSE
       ImgEffect.transparent=false
      END IF
      image.draw(0,0,ImgEffect.bmp)
      focus.noResize=true
      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
      ResetButton
      IF focus.visible THEN focus.remove(image.handle)
      IF OPEN.EXECUTE THEN
       ImgEffect.Bmp=OPEN.FileName
       ImgEffect.pixelformat=ImgMemory.pixelformat
       IF ItemTransparent.checked THEN
        ImgEffect.transparent=true
        ImgEffect.transparentColor=backcolor
       ELSE
        ImgEffect.transparent=false
       END IF
       image.draw(0,0,ImgEffect.bmp)
       focus.noResize=true
       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(0,0,ImgEffect.bmp)
       TypeDraw=0
       image.repaint
       FlagPaste=false
       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("Save file " + FileName + " ?",application.title,35)
       IF msgButton<>mrCancel THEN
        IF msgButton=mrYes THEN
         SelectMenuSave
        END IF
        application.terminate
       ELSE
        form1.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("Save file "+ ExtractFileName(FileName) + " ?"  ,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
        ShowFormat
        imgMemory.fillrect(0,0,imgMemory.width,imgMemory.height,&hffffff)
        image.repaint
        filename="Noname"
        form1.CAPTION=application.title + " - " + ExtractFileName(FileName)
       END IF
      ELSE
       FlagUndo=false
       FlagModif=false
       IF focus.visible THEN focus.remove(image.handle)
       ImgMemory.pixelformat=pf24bit
       ShowFormat
       imgMemory.fillrect(0,0,imgMemory.width,imgMemory.height,&hffffff)
       image.repaint
       filename="Noname"
       form1.CAPTION=application.title + " - " + ExtractFileName(FileName)
      END IF
      StatusBar.Panel(0).CAPTION = Format$(" %d x %d ", imgWidth , imgHeight)
      StatusBar.Panel(2).CAPTION = ""
     END SUB

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

      IF FlagModif THEN
       msgButton=MESSAGEBOX("Save file " + ExtractFileName(FileName) + " ?",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
        ShowFormat
        imgMemory.fillrect(0,0,imgMemory.width,imgMemory.height,&hffffff)
        image.repaint
        filename="Noname"
        form1.CAPTION=application.title+" - "+filename
       END IF
      ELSE
       FlagUndo=false
       FlagModif=false
       IF focus.visible THEN focus.remove(image.handle)
       ImgMemory.pixelformat=pf24bit
       ShowFormat
       imgMemory.fillrect(0,0,imgMemory.width,imgMemory.height,&hffffff)
       image.repaint
       filename="Noname"
       form1.CAPTION=application.title + " - " + ExtractFileName(FileName)
      END IF
     END SUB

'----------------------------
' Open by commandline
'----------------------------
     SUB OpenCL
      IF focus.visible THEN
       focus.remove(image.handle)
      END IF
      imgMemory.Bmp=FileName
      image.width=imgMemory.width
      image.height=imgMemory.height
      imgWidth=imgMemory.width
      imgHeight=imgMemory.height
      Form1.CAPTION=application.title + " - " + ExtractFileName(FileName)
      ShowFormat
      Image.repaint
     END SUB

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

      IF FlagModif THEN
       msgButton=MESSAGEBOX("Save file " + ExtractFileName(FileName) +" ?",application.title,35)
       IF msgButton<>mrCancel THEN
        IF msgButton=mrYes THEN
         SelectMenuSave
        END IF
        FlagUndo=false
        FlagModif=false
        OPEN.InitialDir=CURDIR$
        IF OPEN.EXECUTE THEN
         IF focus.visible THEN focus.remove(image.handle)
         imgMemory.Bmp=OPEN.FileName
         FileName=OPEN.FileName
         image.width=imgMemory.width
         image.height=imgMemory.height
         imgWidth=imgMemory.width
         imgHeight=imgMemory.height
         Form1.CAPTION=application.title + " - " + ExtractFileName(FileName)
         ShowFormat
         Image.repaint
        END IF
       END IF
      ELSE
       OPEN.InitialDir=CURDIR$
       FlagUndo=false
       FlagModif=false
       IF OPEN.EXECUTE THEN
        IF focus.visible THEN focus.remove(image.handle)
        imgMemory.Bmp=OPEN.FileName
        FileName=OPEN.FileName
        image.width=imgMemory.width
        image.height=imgMemory.height
        imgWidth=imgMemory.width
        imgHeight=imgMemory.height
        Form1.CAPTION=application.title+" - " + ExtractFileName(FileName)
        ShowFormat
        Image.repaint
       END IF
      END IF
      StatusBar.Panel(0).CAPTION = Format$(" %d x %d ", imgWidth , imgHeight)
      StatusBar.Panel(2).CAPTION = OPEN.FileName
     END SUB

'============================
' Selection menu sauver sous
'============================
     SUB SelectMenuSaveAs
      SaveDialog.InitialDir=CURDIR$
      IF saveDialog.EXECUTE THEN
       FileName=SaveDialog.FileName
       IF INSTR(LCASE$(FileName),".bmp")=0 THEN
        FileName=FileName+".bmp"
       END IF
       form1.CAPTION=application.title+" - "+FileName
       screen.cursor=crHourGlass
       imgMemory.SaveToFile(filename)
       screen.cursor=crDefault
       FlagUndo=false
       FlagModif=false
      END IF
     END SUB

'============================
' Selection menu sauver
'============================
     SUB SelectMenuSave
      IF FileName="Noname" THEN
       SelectMenuSaveAs
      ELSE
       screen.cursor=crHourGlass
       imgMemory.SaveToFile(filename)
       screen.cursor=crDefault
       FlagUndo=false
       FlagModif=false
      END IF
     END SUB

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

'============================
' Selection couleur de fond
'============================
     SUB SelectBackcolor
      ColorDial.CAPTION="Background Color"
      ColorDial.COLOR=Panel3.COLOR
      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=3
      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
       END IF
       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
     END SUB
'============================
' Selection focus
'============================
     SUB SelectFocus(Sender AS QMENUITEM)
      IF btFocus.down AND BtZoom.down=false THEN
       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=5
       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=2
      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
       image.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
      FlagText=true
      Form3.CLOSE
      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=10
       image.line(x,y,x,y,PenColor)
      CASE 5,6
     'rectangle
       TransfertImgUndo
       image.mixmode=10
       image.rectangle(x,y,x,y,PenColor)
      CASE 7,8
     'cercle
       TransfertImgUndo
       image.mixmode=10
       image.circle(x,y,x,y,PenColor)
' type mixmode
'R2_BLACK_CAN=1
'R2_NOTMERGEPEN_CAN=2
'R2_MASKNOTPEN_CAN=3
'R2_NOTCOPYPEN_CAN=4
'R2_MASKPENNOT_CAN=5
'R2_NOT_CAN=6
'R2_XORPEN_CAN=7
'R2_NOTMASKPEN_CAN=8
'R2_MASKPEN_CAN=9
'R2_NOTXORPEN_CAN=10
'R2_NOP_CAN=11
'R2_MERGENOTPEN_CAN=12
'R2_COPYPEN_CAN=13
'R2_MERGEPENNOT_CAN=14
'R2_MERGEPEN_CAN=15
'R2_WHITE_CAN=16

      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
      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
      StatusBar.Panel(1).CAPTION = Format$(" X: %d Y: %d ",x,y)
     END SUB

'=======================================
' Selection mouse up du composant image
'=======================================
     SUB Stop
      IF flagDraw THEN
       image.mixmode= 13 '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)
        focus.stop(image.handle,false)
        IF focus.move THEN
         ImgMemory.draw(focus.left,focus.top,ImgEffect.bmp)
        ELSE
         ImgMemory.draw(0,0,ImgEffect.bmp)
        END IF
        TypeDraw=0
        image.repaint
       ELSE
        focus.stop(image.handle,false)
       END IF
      END SELECT
      FlagPaste=false
     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
      imgWidth=VAL(WidthEdit.text)
      imgHeight=VAL(HeightEdit.text)
      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

'============================
' 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
       form1.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

      form1.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.0"
      about.CAPTION="About "+about.Appname
      about.text="Author: D.Glodt" + CHR$(10 )+ "Modified by : Nastase Eodor" _
       + CHR$(10) + "Copyright " + CHR$(169) + " eBorg Software 2002-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

'===============================
' Conversion format 16 couleurs
'===============================
     SUB SelectMenuFormat16
      TransfertImgUndo
      ImgMemory.pixelformat=pf4bit
      ShowFormat
      image.repaint
     END SUB

'===============================
' Conversion format 256 couleurs
'===============================
     SUB SelectMenuFormat256
      TransfertImgUndo
      ImgMemory.pixelformat=pf8bit
      ShowFormat
      image.repaint
     END SUB

'====================================
' Conversion format couleurs 24 bits
'====================================
     SUB SelectMenuFormat24
      TransfertImgUndo
      ImgMemory.pixelformat=pf24bit
      ShowFormat
      image.repaint
     END SUB

'===============================
' Affiche le format couleur
'===============================
     SUB ShowFormat
      SELECT CASE ImgMemory.pixelformat
      CASE 2
       itemFormat16.checked=true
       itemFormat256.checked=false
       itemFormat24.checked=false
      CASE 3
       itemFormat256.checked=true
       itemFormat24.checked=false
       itemFormat16.checked=false
      CASE ELSE
       itemFormat24.checked=true
       itemFormat16.checked=false
       itemFormat256.checked=false
      END SELECT
     END SUB
掌柜推荐
 
 
¥490.00 ·
 
 
¥307.00 ·
 
 
¥288.00 ·
 
 
¥900.00 ·
 
 
¥790.00 ·
 
 
¥487.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2010-12-07 21:18:04