SweetyVD (Visual Designer)

Partagez votre expérience de PureBasic avec les autres utilisateurs.
Avatar de l’utilisateur
falsam
Messages : 7317
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: SweetyVD (Visual Designer)

Message par falsam »

Toutefois il ne semble pas en rapport avec z-order mais avec #WS_CLIPSIBLINGS
Moi et les API ça fait deux. Voila pourquoi j'ai proposé une solution de Gally.

Peut être pourrais tu m'éclairer. z-order et WS_CLIPSIBLINGS n'ont aucun rapport ?
Configuration : Windows 11 Famille 64-bit - PB 6.20 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Avatar de l’utilisateur
ChrisR
Messages : 235
Inscription : sam. 14/févr./2015 16:20

Re: SweetyVD (Visual Designer)

Message par ChrisR »

T'éclairer sur les APIs! haha, tu plaisante, je suis un vrai newbie :wink:
toutefois, WS_CLIPSIBLINGS semble être pour le chevauchement et SetWindowPos_() pour le zOrder
La proc devrait sans doute être:

Code : Tout sélectionner

Procedure SetGadgetZOrder(gadget, zorder=0)
  ;Correct the z-order and draw order for [potentially] overlapping gadgets
  ;Call with zorder=0 just after creating each gadget
  ;Call with zorder=1 to later bring a gadget to the top of the z-order
  ;Call with zorder=-1 to later bring a gadget to the bottom of the z-order
  If IsGadget(gadget)
    If zorder = 0
      SetWindowLong_(GadgetID(gadget), #GWL_STYLE, GetWindowLong_(GadgetID(gadget), #GWL_STYLE) | #WS_CLIPSIBLINGS)
    ElseIf zorder = 1
      SetWindowPos_(GadgetID (gadget), #HWND_BOTTOM, 0,0,0,0, #SWP_NOSIZE|#SWP_NOMOVE)
    Else
      SetWindowPos_(GadgetID(gadget), #HWND_TOP, 0, 0, 0, 0, #SWP_NOSIZE|#SWP_NOMOVE)
    EndIf
  EndIf
EndProcedure
Avatar de l’utilisateur
ChrisR
Messages : 235
Inscription : sam. 14/févr./2015 16:20

Re: SweetyVD (Visual Designer)

Message par ChrisR »

J'ai essayé de continuer sur l'idée du module avec #PB_Canvas_Container mais sans vrai succès:
Des problèmes d'affichage (redessin) de la Scrollarea suite à SetParent(Gadget, ScrollAreaGadget) : FreeGadget(Canvas_0)

Code : Tout sélectionner

EnableGadgetTransformation:
Handle = CanvasGadget(#PB_Any, GadgetX(Gadget)-1, GadgetY(Gadget)-1, GadgetWidth(Gadget)+2, GadgetHeight(Gadget)+2, #PB_Canvas_Container|#PB_Canvas_Keyboard)
ResizeGadget(Gadget, 1, 1, #PB_Ignore, #PB_Ignore)
SetParent(Gadget, Handle)
CloseGadgetList()
SetGadgetZOrder(Handle)

Code : Tout sélectionner

DisableGadgetTransformation:
ResizeGadget(Gadget, GadgetX(\Handle[1])+1, GadgetY(\Handle[1])+1, GadgetWidth(\Handle[1])-2, GadgetHeight(\Handle[1])-2)
SetParent(Gadget, ScrollAreaGadget)
FreeGadget(Canvas_0)
Avatar de l’utilisateur
ChrisR
Messages : 235
Inscription : sam. 14/févr./2015 16:20

Re: SweetyVD (Visual Designer)

Message par ChrisR »

Sinon, J'ai continué sur l'idée du module de TransformationOfGadgetsAtRuntime avec quelques ajouts:
. Possibilité de choisir entre une fenêtre, une ScrollArea ou un Container
. La poignée pour le déplacement peut être en haut, en bas ou le gadget lui même (windows seulement, besoin de zOrder).
voir constante #HandelMove = "Gadget" ;"Gadget" / "Top" / "Bottom"
. Contrôle des positions mini et maxi pour rester sur la zone de dessin
. Flèches du clavier Haut, Bas, Gauche, Droite et Maj+Haut, Ma+Bas, ... pour redimensionner
...

TransformationOfGadgetsAtRuntime.pbi

Code : Tout sélectionner

; ---------------------------------------------------------------------------------------
;    Description: Transformation of gadgets at runtime
;         Author: STARGÅTE
;           Date: 2016-05-06
;     PB-Version: 5.42
;             OS: Windows, Linux, Mac
;  English-Forum:
;   French-Forum:
;   German-Forum: http://www.purebasic.fr/german/viewtopic.php?f=8&t=29423
; ---------------------------------------------------------------------------------------
;      Additions: Drawing Area in a ScrollArea, a Window or a Container
;                 Move Handle on Top, on Bottom or on the Gadget itself (win)
;                 Check Grid Mini in addition to Maxi to stay in the area
;                 Keyboard Arrows Up,Down,Left,Right and Shift+Up,Shift+Down... to resize
;         Author: ChrisR
;           Date: 2017-03-04
;     PB-Version: 5.44 5.51 5.60 (x86/x64)
;             OS: Windows, on Linux, Mac use #HandelMove = "Top" or "Bottom"
;  English-Forum:
;   French-Forum: http://www.purebasic.fr/french/viewtopic.php?f=3&t=16527
;   German-Forum: 
; ---------------------------------------------------------------------------------------

DeclareModule GadgetTransformation
  
  EnumerationBinary 1
    #GadgetTransformation_Position
    #GadgetTransformation_Horizontally
    #GadgetTransformation_Vertically
  EndEnumeration
  
  #GadgetTransformation_Size = #GadgetTransformation_Horizontally|#GadgetTransformation_Vertically
  #GadgetTransformation_All  = #GadgetTransformation_Position|#GadgetTransformation_Horizontally|#GadgetTransformation_Vertically
  
  Declare DisableGadgetTransformation(Gadget.i)
  Declare EnableGadgetTransformation(ParentGadget.i, Gadget.i, Flags.i=#GadgetTransformation_All, Grid.i=1)
  
EndDeclareModule

Module GadgetTransformation
  
  EnableExplicit
  
  #HandelSize  = 7
  #HandelColor = $480000   ;BlueDark / Black=$000000
  CompilerIf #PB_Compiler_OS = #PB_OS_Windows
    #HandelMove  = "Gadget"   ;"Gadget" / "Top" / "Bottom"
  CompilerElse
    #HandelMove  = "Bottom"   ;"Top" / "Bottom"
  CompilerEndIf
    
  Structure GadgetTransformation
    ParentGadget.i
    Gadget.i
    Handle.i[10]
    Grid.i
  EndStructure
  
  Structure DataBuffer
    Handle.i[10]
  EndStructure
  
  Global NewList GadgetTransformation.GadgetTransformation()
  
  Procedure SetGadgetZOrder(gadget, zorder=0)
    ;Correct the z-order and draw order for [potentially] overlapping gadgets. Windows only
    CompilerIf #PB_Compiler_OS = #PB_OS_Windows
      If IsGadget(gadget)
        If zorder = 0   ;Call with zorder=0 just after creating each gadget
          SetWindowLong_(GadgetID(gadget), #GWL_STYLE, GetWindowLong_(GadgetID(gadget), #GWL_STYLE) | #WS_CLIPSIBLINGS)
        ElseIf zorder = 1   ;Call with zorder=1 to later bring a gadget to the top of the z-order
          SetWindowPos_(GadgetID (gadget), #HWND_BOTTOM, 0,0,0,0, #SWP_NOSIZE | #SWP_NOMOVE)
        Else   ;Call with zorder=-1 to later bring a gadget to the bottom of the z-order
          SetWindowPos_(GadgetID(gadget), #HWND_TOP, 0, 0, 0, 0, #SWP_NOSIZE | #SWP_NOMOVE)
        EndIf
      EndIf
    CompilerEndIf
  EndProcedure
  
  Procedure.i GridMatch(Value.i, Grid.i, Min.i=0, Max.i=$7FFFFFFF)
    Value = Round(Value/Grid, #PB_Round_Nearest)*Grid
    If Value < Min
      ProcedureReturn Min
    Else
      If Value > Max
        ProcedureReturn Max
      Else
        ProcedureReturn Value
      EndIf
    EndIf
  EndProcedure
  
  Procedure.i ResizeHandle(Gadget)
    Protected *GadgetTransformation.GadgetTransformation
    With GadgetTransformation()
      ForEach GadgetTransformation()
        If \Gadget = Gadget
          If \Handle[1]   ;Moved Handle
            If #HandelMove = "Top"
              ResizeGadget(\Handle[1], GadgetX(\Gadget)+#HandelSize, GadgetY(\Gadget)-#HandelSize, #PB_Ignore, #PB_Ignore)
            ElseIf #HandelMove = "Bottom"
              ResizeGadget(\Handle[1], GadgetX(\Gadget)+GadgetWidth(\Gadget)-4*#HandelSize, GadgetY(\Gadget)+GadgetHeight(\Gadget), #PB_Ignore, #PB_Ignore)
            Else   ;"Gadget"
              ResizeGadget(\Handle[1], GadgetX(\Gadget)-1, GadgetY(\Gadget)-1, GadgetWidth(\Gadget)+2, GadgetHeight(\Gadget)+2)
              If StartDrawing(CanvasOutput(\Handle[1]))
                Box(0, 0, OutputWidth(), OutputHeight(), #HandelColor)
                Box(1, 1, OutputWidth()-2, OutputHeight()-2, $FFFFFF)
                StopDrawing()
              EndIf
            EndIf
          EndIf        
          If \Handle[2]   ;Handle top, middle (N)
            ResizeGadget(\Handle[2], GadgetX(\Gadget)+(GadgetWidth(\Gadget)-#HandelSize)/2, GadgetY(\Gadget)-#HandelSize, #PB_Ignore, #PB_Ignore)
          EndIf
          If \Handle[3]   ;Handle top, right (NE)
            ResizeGadget(\Handle[3], GadgetX(\Gadget)+GadgetWidth(\Gadget), GadgetY(\Gadget)-#HandelSize, #PB_Ignore, #PB_Ignore)
          EndIf
          If \Handle[4]   ;Handle middle, right (E)
            ResizeGadget(\Handle[4], GadgetX(\Gadget)+GadgetWidth(\Gadget), GadgetY(\Gadget)+(GadgetHeight(\Gadget)-#HandelSize)/2, #PB_Ignore, #PB_Ignore)
          EndIf
          If \Handle[5]   ;Handle bottom, right (SE)
            ResizeGadget(\Handle[5], GadgetX(\Gadget)+GadgetWidth(\Gadget), GadgetY(\Gadget)+GadgetHeight(\Gadget), #PB_Ignore, #PB_Ignore)
          EndIf
          If \Handle[6]   ;Handle bottom, middle (S)
            ResizeGadget(\Handle[6], GadgetX(\Gadget)+(GadgetWidth(\Gadget)-#HandelSize)/2, GadgetY(\Gadget)+GadgetHeight(\Gadget), #PB_Ignore, #PB_Ignore)
          EndIf
          If \Handle[7]   ;Handle bottom, left (SW)
            ResizeGadget(\Handle[7], GadgetX(\Gadget)-#HandelSize, GadgetY(\Gadget)+GadgetHeight(\Gadget), #PB_Ignore, #PB_Ignore)
          EndIf
          If \Handle[8]   ;Handle middle, left (W)
            ResizeGadget(\Handle[8], GadgetX(\Gadget)-#HandelSize, GadgetY(\Gadget)+(GadgetHeight(\Gadget)-#HandelSize)/2, #PB_Ignore, #PB_Ignore)
          EndIf
          If \Handle[9]   ;Handle top, left (NW)
            ResizeGadget(\Handle[9], GadgetX(\Gadget)-#HandelSize, GadgetY(\Gadget)-#HandelSize, #PB_Ignore, #PB_Ignore)
          EndIf
          Break
        EndIf
      Next
    EndWith
  EndProcedure                  
  
  Procedure GadgetTransformation_Callback()
    Static Selected.i, X.i, Y.i, OffsetX.i, OffsetY.i, GadgetX0.i, GadgetX1.i, GadgetY0.i, GadgetY1.i, ScrollX.i, ScrollY.i, MaxX.i,MaxY.i
    Protected *GadgetTransformation.GadgetTransformation = GetGadgetData(EventGadget()), I.i
    With *GadgetTransformation
      Select EventType()
          
        Case #PB_EventType_Focus
          ;Workaround to redraw gadget on the Window, scrollArea or container and avoid a white background
          If IsGadget(\ParentGadget) : ResizeGadget(\ParentGadget, #PB_Ignore, #PB_Ignore, #PB_Ignore, #PB_Ignore) : EndIf
          For I = 1 To 9
            If \Handle[I]
              SetGadgetZOrder(\Handle[I], -1)
            EndIf
          Next
          
        Case #PB_EventType_LostFocus
          ;Workaround to redraw gadget on the window, scrollArea or container and avoid a white background
          ;If IsGadget(\ParentGadget) : ResizeGadget(\ParentGadget, #PB_Ignore, #PB_Ignore, #PB_Ignore, #PB_Ignore) : EndIf
          ;If IsWindow(\ParentGadget) : HideGadget(\Gadget, #True) : HideGadget(\Gadget, #False) : EndIf
          HideGadget(\Gadget, #True)
          HideGadget(\Gadget, #False)
          
        Case #PB_EventType_KeyDown
          GadgetX0 = GadgetX(\Gadget)
          GadgetY0 = GadgetY(\Gadget)
          Select GetGadgetAttribute(EventGadget(),#PB_Canvas_Key)
            Case #PB_Shortcut_Up
              If GetGadgetAttribute(\Handle[1], #PB_Canvas_Modifiers) = #PB_Canvas_Shift And IsGadget(\Handle[2])
                ResizeGadget(\Gadget, #PB_Ignore, #PB_Ignore, #PB_Ignore, GridMatch(GadgetHeight(\Gadget)-\Grid, \Grid, 0))
              ElseIf IsGadget(\Handle[1]) Or IsGadget(\Handle[2])
                ResizeGadget(\Gadget, #PB_Ignore, GridMatch(GadgetY0-\Grid, \Grid, 0), #PB_Ignore, #PB_Ignore)
              EndIf
            Case #PB_Shortcut_Right
              If GetGadgetAttribute(\Handle[1],#PB_Canvas_Modifiers) = #PB_Canvas_Shift And IsGadget(\Handle[4])
                ResizeGadget(\Gadget, #PB_Ignore, #PB_Ignore, GridMatch(GadgetWidth(\Gadget)+\Grid, \Grid, GadgetWidth(\Gadget)+\Grid, MaxX-GadgetX(\Gadget)), #PB_Ignore)
              ElseIf IsGadget(\Handle[1]) Or IsGadget(\Handle[4])
                ResizeGadget(\Gadget, GridMatch(GadgetX0+\Grid, \Grid, GadgetX0+\Grid, MaxX-GadgetWidth(\Gadget)), #PB_Ignore, #PB_Ignore, #PB_Ignore)
              EndIf
            Case #PB_Shortcut_Down
              If GetGadgetAttribute(\Handle[1], #PB_Canvas_Modifiers) = #PB_Canvas_Shift And IsGadget(\Handle[6])
                ResizeGadget(\Gadget, #PB_Ignore, #PB_Ignore, #PB_Ignore, GridMatch(GadgetHeight(\Gadget)+\Grid, \Grid, GadgetHeight(\Gadget)+\Grid, MaxY-GadgetY(\Gadget)))
              ElseIf IsGadget(\Handle[1]) Or IsGadget(\Handle[6])
                ResizeGadget(\Gadget, #PB_Ignore, GridMatch(GadgetY0+\Grid, \Grid, GadgetY0+\Grid, MaxY-GadgetHeight(\Gadget)), #PB_Ignore, #PB_Ignore)
              EndIf
            Case #PB_Shortcut_Left
              If GetGadgetAttribute(\Handle[1], #PB_Canvas_Modifiers) = #PB_Canvas_Shift And IsGadget(\Handle[8])
                ResizeGadget(\Gadget, #PB_Ignore, #PB_Ignore, GridMatch(GadgetWidth(\Gadget)-\Grid, \Grid, 0), #PB_Ignore)
              ElseIf IsGadget(\Handle[1]) Or IsGadget(\Handle[8])
                ResizeGadget(\Gadget, GridMatch(GadgetX0-\Grid, \Grid, 0), #PB_Ignore, #PB_Ignore, #PB_Ignore)
              EndIf
          EndSelect
          ResizeHandle(\Gadget)
          
        Case #PB_EventType_LeftButtonDown
          Selected = #True
          OffsetX = GetGadgetAttribute(EventGadget(), #PB_Canvas_MouseX)
          OffsetY = GetGadgetAttribute(EventGadget(), #PB_Canvas_MouseY)
          GadgetX0 = GadgetX(\Gadget)
          GadgetX1 = GadgetX0 + GadgetWidth(\Gadget)
          GadgetY0 = GadgetY(\Gadget)
          GadgetY1 = GadgetY0 + GadgetHeight(\Gadget)
          If IsGadget(\ParentGadget)
            If GetGadgetAttribute(\ParentGadget,#PB_ScrollArea_InnerWidth)   ;Scrollarea
              ScrollX = GadgetX(\ParentGadget)-GetGadgetAttribute(\ParentGadget, #PB_ScrollArea_X)
              ScrollY = GadgetY(\ParentGadget)-GetGadgetAttribute(\ParentGadget, #PB_ScrollArea_Y)
              MaxX = GetGadgetAttribute(\ParentGadget,#PB_ScrollArea_InnerWidth)
              MaxY = GetGadgetAttribute(\ParentGadget,#PB_ScrollArea_InnerHeight)
            Else   ;Container
              ScrollX = GadgetX(\ParentGadget) : ScrollY = GadgetY(\ParentGadget)
              MaxX = GadgetWidth(\ParentGadget)
              MaxY = GadgetHeight(\ParentGadget)
            EndIf
          ElseIf IsWindow(\ParentGadget)   ;Window
            ScrollX = 0 : ScrollY = 0
            MaxX = WindowWidth(\ParentGadget)
            MaxY = WindowHeight(\ParentGadget)
          EndIf
          ;Debug Str(GadgetX0)+" , "+Str(GadgetX1)+" , "+Str(ScrollX)
          ;Debug Str(GadgetY0)+" , "+Str(GadgetY1)+" , "+Str(ScrollY)
          
        Case #PB_EventType_LeftButtonUp
          Selected = #False
          
        Case #PB_EventType_MouseMove
          If Selected
            X = WindowMouseX(GetActiveWindow())-OffsetX-ScrollX
            Y = WindowMouseY(GetActiveWindow())-OffsetY-ScrollY
            ;Debug Str(GadgetX(\Gadget))+" , "+Str(GadgetY(\Gadget))+" , "+Str(GadgetWidth(\Gadget))+" , "+Str(GadgetHeight(\Gadget))
            Select EventGadget()
              Case \Handle[1]   ;Moved Gadget NESW
                If #HandelMove = "Top"
                  ResizeGadget(\Gadget, GridMatch(X-#HandelSize, \Grid, 0, MaxX-GadgetWidth(\Gadget)), GridMatch(Y+#HandelSize, \Grid, 0, MaxY-GadgetHeight(\Gadget)), #PB_Ignore, #PB_Ignore)
                ElseIf #HandelMove = "Bottom"
                  ResizeGadget(\Gadget, GridMatch(X-GadgetWidth(\Gadget)+4*#HandelSize, \Grid, 0, MaxX-GadgetWidth(\Gadget)), GridMatch(Y-GadgetHeight(\Gadget), \Grid, 0, MaxY-GadgetHeight(\Gadget)), #PB_Ignore, #PB_Ignore)
                Else   ;"Gadget"
                  ResizeGadget(\Gadget, GridMatch(X-1, \Grid, 0, MaxX-GadgetWidth(\Gadget)), GridMatch(Y-1, \Grid, 0, MaxY-GadgetHeight(\Gadget)), #PB_Ignore, #PB_Ignore)
                EndIf
              Case \Handle[2]   ;Handle top, middle (N)
                ResizeGadget(\Gadget, #PB_Ignore, GridMatch(Y+#HandelSize, \Grid, 0, GadgetY1), #PB_Ignore, GadgetY1-GridMatch(Y+#HandelSize, \Grid))
              Case \Handle[3]   ;Handle top, right (NE)
                ResizeGadget(\Gadget, #PB_Ignore, GridMatch(Y+#HandelSize, \Grid, 0, GadgetY1), GridMatch(X, \Grid, GadgetX0, MaxX)-GadgetX0, GadgetY1-GridMatch(Y+#HandelSize, \Grid))
              Case \Handle[4]   ;Handle middle, right (E)
                ResizeGadget(\Gadget, #PB_Ignore, #PB_Ignore, GridMatch(X, \Grid, GadgetX0, MaxX)-GadgetX0, #PB_Ignore)
              Case \Handle[5]   ;Handle bottom, right (SE)
                ResizeGadget(\Gadget, #PB_Ignore, #PB_Ignore, GridMatch(X, \Grid, GadgetX0, MaxX)-GadgetX0, GridMatch(Y, \Grid, GadgetY0, MaxY)-GadgetY0)
              Case \Handle[6]   ;Handle bottom, middle (S)
                ResizeGadget(\Gadget, #PB_Ignore, #PB_Ignore, #PB_Ignore, GridMatch(Y, \Grid, GadgetY0, MaxY)-GadgetY0)
              Case \Handle[7]   ;Handle bottom, left (SW)
                ResizeGadget(\Gadget, GridMatch(X+#HandelSize, \Grid, 0, GadgetX1), #PB_Ignore, GadgetX1-GridMatch(X+#HandelSize, \Grid), GridMatch(Y, \Grid, GadgetY0, MaxY)-GadgetY0)
              Case \Handle[8]   ;Handle middle, left (W)
                ResizeGadget(\Gadget, GridMatch(X+#HandelSize, \Grid, 0, GadgetX1), #PB_Ignore, GadgetX1-GridMatch(X+#HandelSize, \Grid), #PB_Ignore)
              Case \Handle[9]   ;Handle top, left (NW)
                ResizeGadget(\Gadget, GridMatch(X+#HandelSize, \Grid, 0, GadgetX1), GridMatch(Y+#HandelSize, \Grid, 0, GadgetY1), GadgetX1-GridMatch(X+#HandelSize, \Grid), GadgetY1-GridMatch(Y+#HandelSize, \Grid))
            EndSelect
            ResizeHandle(\Gadget)
            
          EndIf
      EndSelect
    EndWith
  EndProcedure
  
  Procedure DisableGadgetTransformation(Gadget.i)
    Protected I.i, *GadgetTransformation.GadgetTransformation
    With GadgetTransformation()
      ForEach GadgetTransformation()
        If \Gadget = Gadget
          For I = 1 To 9
            If \Handle[I]
              FreeGadget(\Handle[I])
            EndIf
          Next
          DeleteElement(GadgetTransformation())
        EndIf
      Next
    EndWith
  EndProcedure
  
  Procedure EnableGadgetTransformation(ParentGadget.i, Gadget.i, Flags.i=#GadgetTransformation_All, Grid.i=1)
    Protected Handle.i, GadgetX1.i, GadgetY1.i, I.i
    Protected *GadgetTransformation.GadgetTransformation
    Protected *Cursors.DataBuffer = ?Cursors
    Protected *Flags.DataBuffer = ?Flags
    
    DisableGadgetTransformation(Gadget)
    *GadgetTransformation = AddElement(GadgetTransformation())
    With *GadgetTransformation
      \ParentGadget = ParentGadget
      \Gadget = Gadget
      \Grid = Grid
      For I = 1 To 9
        If Flags & *Flags\Handle[I] = *Flags\Handle[I]
          Select I
            Case 1   ;Moved Handle
              If #HandelMove = "Top"
                Handle = CanvasGadget(#PB_Any, GadgetX(Gadget)+#HandelSize, GadgetY(Gadget)-#HandelSize, 3*#HandelSize, #HandelSize, #PB_Canvas_Keyboard)
              ElseIf #HandelMove = "Bottom"
                Handle = CanvasGadget(#PB_Any, GadgetX(Gadget)+GadgetWidth(Gadget)-4*#HandelSize, GadgetY(Gadget)+GadgetHeight(Gadget), 3*#HandelSize, #HandelSize, #PB_Canvas_Keyboard)
              Else   ;"Gadget"
                Handle = CanvasGadget(#PB_Any, GadgetX(Gadget)-1, GadgetY(Gadget)-1, GadgetWidth(Gadget)+2, GadgetHeight(Gadget)+2, #PB_Canvas_Keyboard)
              EndIf
            Case 2   ;Handle top, middle (N)
              Handle = CanvasGadget(#PB_Any, GadgetX(Gadget)+(GadgetWidth(Gadget)-#HandelSize)/2, GadgetY(Gadget)-#HandelSize, #HandelSize, #HandelSize)
            Case 3   ;Handle top, right (NE)
              Handle = CanvasGadget(#PB_Any, GadgetX(Gadget)+GadgetWidth(Gadget), GadgetY(Gadget)-#HandelSize+1, #HandelSize, #HandelSize)
            Case 4   ;Handle middle, right (E)
              Handle = CanvasGadget(#PB_Any, GadgetX(Gadget)+GadgetWidth(Gadget), GadgetY(Gadget)+(GadgetHeight(Gadget)-#HandelSize)/2, #HandelSize, #HandelSize)
            Case 5   ;Handle bottom, right (SE)
              Handle = CanvasGadget(#PB_Any, GadgetX(Gadget)+GadgetWidth(Gadget), GadgetY(Gadget)+GadgetHeight(Gadget), #HandelSize, #HandelSize)
            Case 6   ;Handle bottom, middle (S)
              Handle = CanvasGadget(#PB_Any, GadgetX(Gadget)+(GadgetWidth(Gadget)-#HandelSize)/2, GadgetY(Gadget)+GadgetHeight(Gadget), #HandelSize, #HandelSize)
            Case 7   ;Handle bottom, left (SW)
              Handle = CanvasGadget(#PB_Any, GadgetX(Gadget)-#HandelSize, GadgetY(Gadget)+GadgetHeight(Gadget), #HandelSize, #HandelSize)
            Case 8   ;Handle middle, left (W)
              Handle = CanvasGadget(#PB_Any, GadgetX(Gadget)-#HandelSize, GadgetY(Gadget)+(GadgetHeight(Gadget)-#HandelSize)/2, #HandelSize, #HandelSize)
            Case 9   ;Handle top, left (NW)
              Handle = CanvasGadget(#PB_Any, GadgetX(Gadget)-#HandelSize, GadgetY(Gadget)-#HandelSize, #HandelSize, #HandelSize)
          EndSelect
          SetGadgetZOrder(Handle)
          ;SetGadgetZOrder(Handle, -1)
          If I = 1 : SetGadgetZOrder(Handle, -1) : EndIf
          \Handle[I] = Handle
          SetGadgetData(Handle, *GadgetTransformation)
          SetGadgetAttribute(Handle, #PB_Canvas_Cursor, *Cursors\Handle[I])
          If StartDrawing(CanvasOutput(Handle))
            Box(0, 0, OutputWidth(), OutputHeight(), #HandelColor)
            Box(1, 1, OutputWidth()-2, OutputHeight()-2, $FFFFFF)
            StopDrawing()
          EndIf
          BindGadgetEvent(Handle, @GadgetTransformation_Callback())
        EndIf
      Next
    EndWith
    DataSection
      Cursors:
      Data.i 0, #PB_Cursor_Arrows, #PB_Cursor_UpDown, #PB_Cursor_LeftDownRightUp, #PB_Cursor_LeftRight
      Data.i #PB_Cursor_LeftUpRightDown, #PB_Cursor_UpDown, #PB_Cursor_LeftDownRightUp, #PB_Cursor_LeftRight, #PB_Cursor_LeftUpRightDown
      Flags:
      Data.i 0, #GadgetTransformation_Position, #GadgetTransformation_Vertically, #GadgetTransformation_Size, #GadgetTransformation_Horizontally
      Data.i #GadgetTransformation_Size, #GadgetTransformation_Vertically, #GadgetTransformation_Size, #GadgetTransformation_Horizontally, #GadgetTransformation_Size
    EndDataSection
  EndProcedure
EndModule

;-Example
CompilerIf #PB_Compiler_IsMainFile
  UseModule GadgetTransformation
  
  Enumeration
    #Window
    #GadgetTransformation
    #Container
    #ScrollArea
    #EditorGadget
    #ButtonGadget
    #TrackBarGadget
    #SpinGadget
  EndEnumeration
  
  OpenWindow(#Window, 0, 0, 600, 400, "WindowTitle", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
  ButtonGadget(#GadgetTransformation, 30, 5, 150, 25, "Enable Transformation", #PB_Button_Toggle)
  
  ;ContainerGadget(#Container, 30, 35, 540, 340, #PB_Container_Single)
  ScrollAreaGadget(#ScrollArea, 30, 35, 540, 340, 800, 600, 20, #PB_ScrollArea_Single)
  
  EditorGadget(#EditorGadget, 50, 100, 200, 50, #PB_Editor_WordWrap) : SetGadgetText(#EditorGadget, "Grumpy wizards make toxic brew for the evil Queen and Jack.")
  ButtonGadget(#ButtonGadget, 50, 200, 200, 25, "Hallo Welt!", #PB_Button_MultiLine)
  TrackBarGadget(#TrackBarGadget, 300, 100, 200, 25, 0, 100) : SetGadgetState(#TrackBarGadget, 70)
  SpinGadget(#SpinGadget, 350, 250, 100, 25, 0, 100, #PB_Spin_Numeric) : SetGadgetState(#SpinGadget, 70)
  
  Repeat
    Select WaitWindowEvent()
      
      Case #PB_Event_CloseWindow
        End
      
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #GadgetTransformation
            Select GetGadgetState(#GadgetTransformation)
              Case #False
                SetGadgetText(#GadgetTransformation, "Enable Transformation")
                DisableGadgetTransformation(#EditorGadget)
                DisableGadgetTransformation(#ButtonGadget)
                DisableGadgetTransformation(#TrackBarGadget)
                DisableGadgetTransformation(#SpinGadget)
              Case #True
                SetGadgetText(#GadgetTransformation, "Disable Transformation")
                ;ScrollAreaGadget: Comment the ContainerGadget
                EnableGadgetTransformation(#ScrollArea, #EditorGadget, #GadgetTransformation_All, 10)
                EnableGadgetTransformation(#ScrollArea, #ButtonGadget, #GadgetTransformation_All)
                EnableGadgetTransformation(#ScrollArea, #TrackBarGadget, #GadgetTransformation_Position|#GadgetTransformation_Horizontally)
                EnableGadgetTransformation(#ScrollArea, #SpinGadget, #GadgetTransformation_Position|#GadgetTransformation_Horizontally,5)
                
                ;Window: Comment the ScrollAreaGadget and the ContainerGadget
                ;EnableGadgetTransformation(#Window, #EditorGadget, #GadgetTransformation_All, 10)
                ;EnableGadgetTransformation(#Window, #ButtonGadget, #GadgetTransformation_All)
                ;EnableGadgetTransformation(#Window, #TrackBarGadget, #GadgetTransformation_Position|#GadgetTransformation_Horizontally)
                ;EnableGadgetTransformation(#Window, #SpinGadget, #GadgetTransformation_Position|#GadgetTransformation_Horizontally,5)
                
                ;ContainerGadget: Comment the ScrollAreaGadget
                ;EnableGadgetTransformation(#Container, #EditorGadget, #GadgetTransformation_All, 10)
                ;EnableGadgetTransformation(#Container, #ButtonGadget, #GadgetTransformation_All)
                ;EnableGadgetTransformation(#Container, #TrackBarGadget, #GadgetTransformation_Position|#GadgetTransformation_Horizontally)
                ;EnableGadgetTransformation(#Container, #SpinGadget, #GadgetTransformation_Position|#GadgetTransformation_Horizontally,5)              
            EndSelect
            
        EndSelect
        
    EndSelect
    
  ForEver
CompilerEndIf
; IDE Options = PureBasic 5.42 LTS (Linux - x64) - PureBasic 5.44 LTS, 5.51 and 5.60 (Windows - x86/x64)
; EnableUnicode
; EnableXP
; EnablePurifier
Edit: Ajout compatibilité Win,Linux,Mac: CompilerIf #PB_Compiler_OS = #PB_OS_Windows : #HandelMove = "Gadget" ;"Gadget" / "Top" / "Bottom" : CompilerElse : #HandelMove = "Bottom" ;"Top" / "Bottom" : CompilerEndIf
Dernière modification par ChrisR le dim. 05/mars/2017 14:13, modifié 2 fois.
Avatar de l’utilisateur
Kwai chang caine
Messages : 6989
Inscription : sam. 23/sept./2006 18:32
Localisation : Isere

Re: SweetyVD (Visual Designer)

Message par Kwai chang caine »

Marche bien sous W10, mais toujours un peu de flickering au resize des gadget 8)
ImageLe bonheur est une route...
Pas une destination

PureBasic Forum Officiel - Site PureBasic
Avatar de l’utilisateur
ChrisR
Messages : 235
Inscription : sam. 14/févr./2015 16:20

Re: SweetyVD (Visual Designer)

Message par ChrisR »

Salut KCC,
Je suis sur Win10 également et en effet il y a un peu de flickering et effet de superposition au resize des gadgets.
Je crois, un peu inévitable avec la méthode du canva qui englobe le gadget.

Il serait bien d'essayer avec:
. Un canva qui englobe le gadget en capturant l'image du Gadget (X,Y,Width,Heigth) pour l'afficher, la dessiner sur le canva.
. Cacher alors le gadget pour le repositionnement, redimensionnement a partir du canva.
. A la fin des transformations, Resize du Gadget avec les dimensions du Canva, supprimer le canva et rendre le gadget a nouveau visible.
Sur la théorie, il devrait permettre d'éviter le scintillement. A tester...

J'ai pas encore joué avec ce genre de chose. Est-ce que quelqu'un a une procédure (Win,Linux,Mac) pour Capturer l'image (X,Y,Width,Heigth) et la dessiner sur le Canva ?
Avatar de l’utilisateur
ChaudEf
Messages : 179
Inscription : dim. 27/déc./2015 17:02
Localisation : Strasbourg

Re: SweetyVD (Visual Designer)

Message par ChaudEf »

Chapeau Chris, un tres beau projet!!
Windows 10 x64 -- Purebasic 5.70 LTS x86
Avatar de l’utilisateur
ChrisR
Messages : 235
Inscription : sam. 14/févr./2015 16:20

Re: SweetyVD (Visual Designer)

Message par ChrisR »

La poignée de déplacement sur le gadget est maintenant disponible sur Linux également, en plus de Windows.
Pas de Mac autour pour vérifier mais il devrait être compatible également.

Code : Tout sélectionner

; ---------------------------------------------------------------------------------------
;    Description: Transformation of gadgets at runtime
;         Author: STARGÅTE
;           Date: 2016-05-06
;     PB-Version: 5.42
;             OS: Windows, Linux, Mac
;  English-Forum:
;   French-Forum:
;   German-Forum: http://www.purebasic.fr/german/viewtopic.php?f=8&t=29423
; ---------------------------------------------------------------------------------------
;      Additions: Drawing Area in a ScrollArea, a Window or a Container
;                 Move Handle on Top, on Bottom or on the Gadget itself (win)
;                 Check Grid Mini in addition to Maxi to stay in the area
;                 Keyboard Arrows Up,Down,Left,Right and Shift+Up,Shift+Down... to resize
;         Author: ChrisR
;           Date: 2017-03-04
;     PB-Version: 5.44 5.51 5.60 (x86/x64)
;             OS: Windows, on Linux, Mac use #HandelMove = "Top" or "Bottom"
;  English-Forum:
;   French-Forum: http://www.purebasic.fr/french/viewtopic.php?f=3&t=16527
;   German-Forum: 
; ---------------------------------------------------------------------------------------
;      Additions: Solution for the Moved Handle on gadget, also on Linux now, in addtion to Windows
;                 We need to call InitGadgetTransformation just after the drawing area: Window, ScrollArea Or Container
;                 and before creating the Gadets in it
;         Author: ChrisR
;           Date: 2017-03-08
; ---------------------------------------------------------------------------------------

DeclareModule GadgetTransformation
  
  EnumerationBinary 1
    #GadgetTransformation_Position
    #GadgetTransformation_Horizontally
    #GadgetTransformation_Vertically
  EndEnumeration
  
  #GadgetTransformation_Size = #GadgetTransformation_Horizontally|#GadgetTransformation_Vertically
  #GadgetTransformation_All  = #GadgetTransformation_Position|#GadgetTransformation_Horizontally|#GadgetTransformation_Vertically
  
  Declare InitGadgetTransformation(CountGadget.i = 99)  
  Declare DisableGadgetTransformation(Gadget.i)
  Declare EnableGadgetTransformation(ParentGadget.i, Gadget.i, Flags.i=#GadgetTransformation_All, Grid.i=1)

EndDeclareModule

Module GadgetTransformation
  
  EnableExplicit
  
  #HandelSize  = 7
  #HandelColor = $480000   ;BlueDark / Black=$000000
  #HandelMove  = "Gadget"   ;"Gadget" /"Top" / "Bottom"
    
  Structure GadgetTransformation
    ParentGadget.i
    Gadget.i
    Handle.i[10]
    Grid.i
  EndStructure
  
  Structure DataBuffer
    Handle.i[10]
  EndStructure
  
  Global NewList GadgetTransformation.GadgetTransformation()
  
  Structure GadgetHandle
    Handle.i
    Gadget.i
  EndStructure

  Global Dim GadgetHandleArray.GadgetHandle(0)
  
  Procedure.i GridMatch(Value.i, Grid.i, Min.i=0, Max.i=$7FFFFFFF)
    Value = Round(Value/Grid, #PB_Round_Nearest)*Grid
    If Value < Min
      ProcedureReturn Min
    Else
      If Value > Max
        ProcedureReturn Max
      Else
        ProcedureReturn Value
      EndIf
    EndIf
  EndProcedure
  
  Procedure.i ResizeHandle(Gadget)
    Protected *GadgetTransformation.GadgetTransformation
    With GadgetTransformation()
      ForEach GadgetTransformation()
        If \Gadget = Gadget
          If \Handle[1]   ;Moved Handle
            If #HandelMove = "Top"
              ResizeGadget(\Handle[1], GadgetX(\Gadget)+#HandelSize, GadgetY(\Gadget)-#HandelSize, #PB_Ignore, #PB_Ignore)
            ElseIf #HandelMove = "Bottom"
              ResizeGadget(\Handle[1], GadgetX(\Gadget)+GadgetWidth(\Gadget)-4*#HandelSize, GadgetY(\Gadget)+GadgetHeight(\Gadget), #PB_Ignore, #PB_Ignore)
            ElseIf #HandelMove = "Gadget"
              ResizeGadget(\Handle[1], GadgetX(\Gadget)-1, GadgetY(\Gadget)-1, GadgetWidth(\Gadget)+2, GadgetHeight(\Gadget)+2)
              If StartDrawing(CanvasOutput(\Handle[1]))
                Box(0, 0, OutputWidth(), OutputHeight(), #HandelColor)
                Box(1, 1, OutputWidth()-2, OutputHeight()-2, $FFFFFF)
                StopDrawing()
              EndIf
            EndIf
          EndIf        
          If \Handle[2]   ;Handle top, middle (N)
            ResizeGadget(\Handle[2], GadgetX(\Gadget)+(GadgetWidth(\Gadget)-#HandelSize)/2, GadgetY(\Gadget)-#HandelSize, #PB_Ignore, #PB_Ignore)
          EndIf
          If \Handle[3]   ;Handle top, right (NE)
            ResizeGadget(\Handle[3], GadgetX(\Gadget)+GadgetWidth(\Gadget), GadgetY(\Gadget)-#HandelSize, #PB_Ignore, #PB_Ignore)
          EndIf
          If \Handle[4]   ;Handle middle, right (E)
            ResizeGadget(\Handle[4], GadgetX(\Gadget)+GadgetWidth(\Gadget), GadgetY(\Gadget)+(GadgetHeight(\Gadget)-#HandelSize)/2, #PB_Ignore, #PB_Ignore)
          EndIf
          If \Handle[5]   ;Handle bottom, right (SE)
            ResizeGadget(\Handle[5], GadgetX(\Gadget)+GadgetWidth(\Gadget), GadgetY(\Gadget)+GadgetHeight(\Gadget), #PB_Ignore, #PB_Ignore)
          EndIf
          If \Handle[6]   ;Handle bottom, middle (S)
            ResizeGadget(\Handle[6], GadgetX(\Gadget)+(GadgetWidth(\Gadget)-#HandelSize)/2, GadgetY(\Gadget)+GadgetHeight(\Gadget), #PB_Ignore, #PB_Ignore)
          EndIf
          If \Handle[7]   ;Handle bottom, left (SW)
            ResizeGadget(\Handle[7], GadgetX(\Gadget)-#HandelSize, GadgetY(\Gadget)+GadgetHeight(\Gadget), #PB_Ignore, #PB_Ignore)
          EndIf
          If \Handle[8]   ;Handle middle, left (W)
            ResizeGadget(\Handle[8], GadgetX(\Gadget)-#HandelSize, GadgetY(\Gadget)+(GadgetHeight(\Gadget)-#HandelSize)/2, #PB_Ignore, #PB_Ignore)
          EndIf
          If \Handle[9]   ;Handle top, left (NW)
            ResizeGadget(\Handle[9], GadgetX(\Gadget)-#HandelSize, GadgetY(\Gadget)-#HandelSize, #PB_Ignore, #PB_Ignore)
          EndIf
          Break
        EndIf
      Next
    EndWith
  EndProcedure                  
  
  Procedure GadgetTransformation_Callback()
    Static Selected.i, X.i, Y.i, OffsetX.i, OffsetY.i, GadgetX0.i, GadgetX1.i, GadgetY0.i, GadgetY1.i, ScrollX.i, ScrollY.i, MaxX.i,MaxY.i
    Protected *GadgetTransformation.GadgetTransformation = GetGadgetData(EventGadget()), I.i
    With *GadgetTransformation
      Select EventType()
          
        Case #PB_EventType_KeyDown
          GadgetX0 = GadgetX(\Gadget)
          GadgetY0 = GadgetY(\Gadget)
          Select GetGadgetAttribute(EventGadget(),#PB_Canvas_Key)
            Case #PB_Shortcut_Up
              If GetGadgetAttribute(\Handle[1], #PB_Canvas_Modifiers) = #PB_Canvas_Shift And IsGadget(\Handle[2])
                ResizeGadget(\Gadget, #PB_Ignore, #PB_Ignore, #PB_Ignore, GridMatch(GadgetHeight(\Gadget)-\Grid, \Grid, 0))
              ElseIf IsGadget(\Handle[1]) Or IsGadget(\Handle[2])
                ResizeGadget(\Gadget, #PB_Ignore, GridMatch(GadgetY0-\Grid, \Grid, 0), #PB_Ignore, #PB_Ignore)
              EndIf
            Case #PB_Shortcut_Right
              If GetGadgetAttribute(\Handle[1],#PB_Canvas_Modifiers) = #PB_Canvas_Shift And IsGadget(\Handle[4])
                ResizeGadget(\Gadget, #PB_Ignore, #PB_Ignore, GridMatch(GadgetWidth(\Gadget)+\Grid, \Grid, GadgetWidth(\Gadget)+\Grid, MaxX-GadgetX(\Gadget)), #PB_Ignore)
              ElseIf IsGadget(\Handle[1]) Or IsGadget(\Handle[4])
                ResizeGadget(\Gadget, GridMatch(GadgetX0+\Grid, \Grid, GadgetX0+\Grid, MaxX-GadgetWidth(\Gadget)), #PB_Ignore, #PB_Ignore, #PB_Ignore)
              EndIf
            Case #PB_Shortcut_Down
              If GetGadgetAttribute(\Handle[1], #PB_Canvas_Modifiers) = #PB_Canvas_Shift And IsGadget(\Handle[6])
                ResizeGadget(\Gadget, #PB_Ignore, #PB_Ignore, #PB_Ignore, GridMatch(GadgetHeight(\Gadget)+\Grid, \Grid, GadgetHeight(\Gadget)+\Grid, MaxY-GadgetY(\Gadget)))
              ElseIf IsGadget(\Handle[1]) Or IsGadget(\Handle[6])
                ResizeGadget(\Gadget, #PB_Ignore, GridMatch(GadgetY0+\Grid, \Grid, GadgetY0+\Grid, MaxY-GadgetHeight(\Gadget)), #PB_Ignore, #PB_Ignore)
              EndIf
            Case #PB_Shortcut_Left
              If GetGadgetAttribute(\Handle[1], #PB_Canvas_Modifiers) = #PB_Canvas_Shift And IsGadget(\Handle[8])
                ResizeGadget(\Gadget, #PB_Ignore, #PB_Ignore, GridMatch(GadgetWidth(\Gadget)-\Grid, \Grid, 0), #PB_Ignore)
              ElseIf IsGadget(\Handle[1]) Or IsGadget(\Handle[8])
                ResizeGadget(\Gadget, GridMatch(GadgetX0-\Grid, \Grid, 0), #PB_Ignore, #PB_Ignore, #PB_Ignore)
              EndIf
          EndSelect
          ResizeHandle(\Gadget)
          
        Case #PB_EventType_LeftButtonDown
          Selected = #True
          OffsetX = GetGadgetAttribute(EventGadget(), #PB_Canvas_MouseX)
          OffsetY = GetGadgetAttribute(EventGadget(), #PB_Canvas_MouseY)
          GadgetX0 = GadgetX(\Gadget)
          GadgetX1 = GadgetX0 + GadgetWidth(\Gadget)
          GadgetY0 = GadgetY(\Gadget)
          GadgetY1 = GadgetY0 + GadgetHeight(\Gadget)
          If IsGadget(\ParentGadget)
            If GetGadgetAttribute(\ParentGadget,#PB_ScrollArea_InnerWidth)   ;Scrollarea
              ScrollX = GadgetX(\ParentGadget)-GetGadgetAttribute(\ParentGadget, #PB_ScrollArea_X)
              ScrollY = GadgetY(\ParentGadget)-GetGadgetAttribute(\ParentGadget, #PB_ScrollArea_Y)
              MaxX = GetGadgetAttribute(\ParentGadget,#PB_ScrollArea_InnerWidth)
              MaxY = GetGadgetAttribute(\ParentGadget,#PB_ScrollArea_InnerHeight)
            Else   ;Container
              ScrollX = GadgetX(\ParentGadget) : ScrollY = GadgetY(\ParentGadget)
              MaxX = GadgetWidth(\ParentGadget)
              MaxY = GadgetHeight(\ParentGadget)
            EndIf
          ElseIf IsWindow(\ParentGadget)   ;Window
            ScrollX = 0 : ScrollY = 0
            MaxX = WindowWidth(\ParentGadget)
            MaxY = WindowHeight(\ParentGadget)
          EndIf
          ;to avoid a white gadget background (=Canvas) in case of double click in Windows 
          If IsGadget(\ParentGadget) : ResizeGadget(\ParentGadget, #PB_Ignore, #PB_Ignore, #PB_Ignore, #PB_Ignore) : EndIf
          
        Case #PB_EventType_LeftButtonUp
          Selected = #False
          
        Case #PB_EventType_MouseMove
          If Selected
            X = WindowMouseX(GetActiveWindow())-OffsetX-ScrollX
            Y = WindowMouseY(GetActiveWindow())-OffsetY-ScrollY
            Select EventGadget()
              Case \Handle[1]   ;Moved Gadget NESW
                If #HandelMove = "Top"
                  ResizeGadget(\Gadget, GridMatch(X-#HandelSize, \Grid, 0, MaxX-GadgetWidth(\Gadget)), GridMatch(Y+#HandelSize, \Grid, 0, MaxY-GadgetHeight(\Gadget)), #PB_Ignore, #PB_Ignore)
                ElseIf #HandelMove = "Bottom"
                  ResizeGadget(\Gadget, GridMatch(X-GadgetWidth(\Gadget)+4*#HandelSize, \Grid, 0, MaxX-GadgetWidth(\Gadget)), GridMatch(Y-GadgetHeight(\Gadget), \Grid, 0, MaxY-GadgetHeight(\Gadget)), #PB_Ignore, #PB_Ignore)
                ElseIf #HandelMove = "Gadget"
                  ResizeGadget(\Gadget, GridMatch(X-1, \Grid, 0, MaxX-GadgetWidth(\Gadget)), GridMatch(Y-1, \Grid, 0, MaxY-GadgetHeight(\Gadget)), #PB_Ignore, #PB_Ignore)
                EndIf
              Case \Handle[2]   ;Handle top, middle (N)
                ResizeGadget(\Gadget, #PB_Ignore, GridMatch(Y+#HandelSize, \Grid, 0, GadgetY1), #PB_Ignore, GadgetY1-GridMatch(Y+#HandelSize, \Grid))
              Case \Handle[3]   ;Handle top, right (NE)
                ResizeGadget(\Gadget, #PB_Ignore, GridMatch(Y+#HandelSize, \Grid, 0, GadgetY1), GridMatch(X, \Grid, GadgetX0, MaxX)-GadgetX0, GadgetY1-GridMatch(Y+#HandelSize, \Grid))
              Case \Handle[4]   ;Handle middle, right (E)
                ResizeGadget(\Gadget, #PB_Ignore, #PB_Ignore, GridMatch(X, \Grid, GadgetX0, MaxX)-GadgetX0, #PB_Ignore)
              Case \Handle[5]   ;Handle bottom, right (SE)
                ResizeGadget(\Gadget, #PB_Ignore, #PB_Ignore, GridMatch(X, \Grid, GadgetX0, MaxX)-GadgetX0, GridMatch(Y, \Grid, GadgetY0, MaxY)-GadgetY0)
              Case \Handle[6]   ;Handle bottom, middle (S)
                ResizeGadget(\Gadget, #PB_Ignore, #PB_Ignore, #PB_Ignore, GridMatch(Y, \Grid, GadgetY0, MaxY)-GadgetY0)
              Case \Handle[7]   ;Handle bottom, left (SW)
                ResizeGadget(\Gadget, GridMatch(X+#HandelSize, \Grid, 0, GadgetX1), #PB_Ignore, GadgetX1-GridMatch(X+#HandelSize, \Grid), GridMatch(Y, \Grid, GadgetY0, MaxY)-GadgetY0)
              Case \Handle[8]   ;Handle middle, left (W)
                ResizeGadget(\Gadget, GridMatch(X+#HandelSize, \Grid, 0, GadgetX1), #PB_Ignore, GadgetX1-GridMatch(X+#HandelSize, \Grid), #PB_Ignore)
              Case \Handle[9]   ;Handle top, left (NW)
                ResizeGadget(\Gadget, GridMatch(X+#HandelSize, \Grid, 0, GadgetX1), GridMatch(Y+#HandelSize, \Grid, 0, GadgetY1), GadgetX1-GridMatch(X+#HandelSize, \Grid), GadgetY1-GridMatch(Y+#HandelSize, \Grid))
            EndSelect
            ResizeHandle(\Gadget)
            
          EndIf
      EndSelect
    EndWith
  EndProcedure
  
  Procedure DisableGadgetTransformation(Gadget.i)
    Protected I.i, K.i, *GadgetTransformation.GadgetTransformation
    With GadgetTransformation()
      ForEach GadgetTransformation()
        If \Gadget = Gadget
          For I = 2 To 9
            If \Handle[I] : FreeGadget(\Handle[I]) : EndIf
          Next
          If #HandelMove = "Gadget"
            For K = 0 To ArraySize(GadgetHandleArray())
              If GadgetHandleArray(K)\Gadget = Gadget
                DisableGadget(GadgetHandleArray(K)\Handle,#True)
                HideGadget(GadgetHandleArray(K)\Handle,#True)
                ResizeGadget(GadgetHandleArray(K)\Handle, 0, 0, 0, 0)              
                GadgetHandleArray(K)\Gadget = 0
                SortStructuredArray(GadgetHandleArray(), #PB_Sort_Descending, OffsetOf(GadgetHandle\Gadget), TypeOf(GadgetHandle\Gadget))
                Break
              EndIf
            Next
          Else
            If \Handle[1] : FreeGadget(\Handle[1]) : EndIf
          EndIf
          DeleteElement(GadgetTransformation())
          Break
        EndIf
      Next
    EndWith
  EndProcedure
  
  Procedure EnableGadgetTransformation(ParentGadget.i, Gadget.i, Flags.i=#GadgetTransformation_All, Grid.i=1)
    Protected Handle.i, GadgetX1.i, GadgetY1.i, I.i, K.i
    Protected *GadgetTransformation.GadgetTransformation
    Protected *Cursors.DataBuffer = ?Cursors
    Protected *Flags.DataBuffer = ?Flags
    
    DisableGadgetTransformation(Gadget)
    *GadgetTransformation = AddElement(GadgetTransformation())
    With *GadgetTransformation
      \ParentGadget = ParentGadget
      \Gadget = Gadget
      \Grid = Grid
      For I = 1 To 9
        If Flags & *Flags\Handle[I] = *Flags\Handle[I]
          Select I
            Case 1   ;Moved Handle
              If #HandelMove = "Top"
                Handle = CanvasGadget(#PB_Any, GadgetX(Gadget)+#HandelSize, GadgetY(Gadget)-#HandelSize, 3*#HandelSize, #HandelSize, #PB_Canvas_Keyboard)
              ElseIf #HandelMove = "Bottom"
                Handle = CanvasGadget(#PB_Any, GadgetX(Gadget)+GadgetWidth(Gadget)-4*#HandelSize, GadgetY(Gadget)+GadgetHeight(Gadget), 3*#HandelSize, #HandelSize, #PB_Canvas_Keyboard)
              ElseIf #HandelMove = "Gadget"
                For K = 0 To ArraySize(GadgetHandleArray())
                  If GadgetHandleArray(K)\Gadget = 0 And GadgetHandleArray(K)\Handle
                    handle = GadgetHandleArray(K)\Handle
                    GadgetHandleArray(K)\Gadget = Gadget
                    ResizeGadget(Handle, GadgetX(Gadget)-1, GadgetY(Gadget)-1, GadgetWidth(Gadget)+2, GadgetHeight(Gadget)+2)
                    DisableGadget(Handle,#False)
                    HideGadget(Handle,#False)
                    Break
                  EndIf
                Next
              EndIf
            Case 2   ;Handle top, middle (N)
              Handle = CanvasGadget(#PB_Any, GadgetX(Gadget)+(GadgetWidth(Gadget)-#HandelSize)/2, GadgetY(Gadget)-#HandelSize, #HandelSize, #HandelSize)
            Case 3   ;Handle top, right (NE)
              Handle = CanvasGadget(#PB_Any, GadgetX(Gadget)+GadgetWidth(Gadget), GadgetY(Gadget)-#HandelSize+1, #HandelSize, #HandelSize)
            Case 4   ;Handle middle, right (E)
              Handle = CanvasGadget(#PB_Any, GadgetX(Gadget)+GadgetWidth(Gadget), GadgetY(Gadget)+(GadgetHeight(Gadget)-#HandelSize)/2, #HandelSize, #HandelSize)
            Case 5   ;Handle bottom, right (SE)
              Handle = CanvasGadget(#PB_Any, GadgetX(Gadget)+GadgetWidth(Gadget), GadgetY(Gadget)+GadgetHeight(Gadget), #HandelSize, #HandelSize)
            Case 6   ;Handle bottom, middle (S)
              Handle = CanvasGadget(#PB_Any, GadgetX(Gadget)+(GadgetWidth(Gadget)-#HandelSize)/2, GadgetY(Gadget)+GadgetHeight(Gadget), #HandelSize, #HandelSize)
            Case 7   ;Handle bottom, left (SW)
              Handle = CanvasGadget(#PB_Any, GadgetX(Gadget)-#HandelSize, GadgetY(Gadget)+GadgetHeight(Gadget), #HandelSize, #HandelSize)
            Case 8   ;Handle middle, left (W)
              Handle = CanvasGadget(#PB_Any, GadgetX(Gadget)-#HandelSize, GadgetY(Gadget)+(GadgetHeight(Gadget)-#HandelSize)/2, #HandelSize, #HandelSize)
            Case 9   ;Handle top, left (NW)
              Handle = CanvasGadget(#PB_Any, GadgetX(Gadget)-#HandelSize, GadgetY(Gadget)-#HandelSize, #HandelSize, #HandelSize)
          EndSelect
          \Handle[I] = Handle
          SetGadgetData(Handle, *GadgetTransformation)
          SetGadgetAttribute(Handle, #PB_Canvas_Cursor, *Cursors\Handle[I])
          If StartDrawing(CanvasOutput(Handle))
            Box(0, 0, OutputWidth(), OutputHeight(), #HandelColor)
            Box(1, 1, OutputWidth()-2, OutputHeight()-2, $FFFFFF)
            StopDrawing()
          EndIf
          BindGadgetEvent(Handle, @GadgetTransformation_Callback())
        EndIf
      Next
    EndWith
    DataSection
      Cursors:
      Data.i 0, #PB_Cursor_Arrows, #PB_Cursor_UpDown, #PB_Cursor_LeftDownRightUp, #PB_Cursor_LeftRight
      Data.i #PB_Cursor_LeftUpRightDown, #PB_Cursor_UpDown, #PB_Cursor_LeftDownRightUp, #PB_Cursor_LeftRight, #PB_Cursor_LeftUpRightDown
      Flags:
      Data.i 0, #GadgetTransformation_Position, #GadgetTransformation_Vertically, #GadgetTransformation_Size, #GadgetTransformation_Horizontally
      Data.i #GadgetTransformation_Size, #GadgetTransformation_Vertically, #GadgetTransformation_Size, #GadgetTransformation_Horizontally, #GadgetTransformation_Size
    EndDataSection
  EndProcedure
  
  Procedure InitGadgetTransformation(CountGadget.i = 99)
    Protected I.i
    If #HandelMove = "Gadget"
      ReDim GadgetHandleArray(CountGadget)
      For I = 0 To CountGadget
        GadgetHandleArray(I)\Handle = CanvasGadget(#PB_Any, 0, 0, 0, 0, #PB_Canvas_Keyboard)
        DisableGadget(GadgetHandleArray(I)\Handle,#True)
        HideGadget(GadgetHandleArray(I)\Handle,#True)
      Next
    EndIf
  EndProcedure  
EndModule

;-Example
CompilerIf #PB_Compiler_IsMainFile
  UseModule GadgetTransformation
  
  Enumeration
    #Window
    #GadgetTransformation
    #Container
    #ScrollArea
    #EditorGadget
    #ButtonGadget
    #TrackBarGadget
    #SpinGadget
  EndEnumeration
  
  OpenWindow(#Window, 0, 0, 600, 400, "WindowTitle", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
  ButtonGadget(#GadgetTransformation, 30, 5, 150, 25, "Enable Transformation", #PB_Button_Toggle)
  
  ;ContainerGadget(#Container, 30, 35, 540, 340, #PB_Container_Single)
  ScrollAreaGadget(#ScrollArea, 30, 35, 540, 340, 800, 600, 20, #PB_ScrollArea_Single)
  
  ;*** Important *** Call InitGadgetTransformation just after the drawing area: Window, ScrollArea or Container and before creating the Gadets on it 
  InitGadgetTransformation()
  
  EditorGadget(#EditorGadget, 50, 100, 200, 50, #PB_Editor_WordWrap) : SetGadgetText(#EditorGadget, "Grumpy wizards make toxic brew for the evil Queen and Jack.")
  ButtonGadget(#ButtonGadget, 50, 200, 200, 25, "Hallo Welt!", #PB_Button_MultiLine)
  TrackBarGadget(#TrackBarGadget, 300, 100, 200, 25, 0, 100) : SetGadgetState(#TrackBarGadget, 70)
  SpinGadget(#SpinGadget, 350, 250, 100, 25, 0, 100, #PB_Spin_Numeric) : SetGadgetState(#SpinGadget, 70)
  
  Repeat
    Select WaitWindowEvent()
      
      Case #PB_Event_CloseWindow
        End
      
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #GadgetTransformation
            Select GetGadgetState(#GadgetTransformation)
              Case #False
                ;DisableGadgetTransformation Parameters: Gadget
                SetGadgetText(#GadgetTransformation, "Enable Transformation")
                DisableGadgetTransformation(#ButtonGadget)
                DisableGadgetTransformation(#EditorGadget)
                DisableGadgetTransformation(#TrackBarGadget)
                DisableGadgetTransformation(#SpinGadget)
              Case #True
                ;EnableGadgetTransformation Parameters:
                ;1: drawing area or Parent Gadget: a Window, ScrollArea or Container
                ;2: Gadget
                ;3: #GadgetTransformation_Position
                ;   #GadgetTransformation_Horizontally
                ;   #GadgetTransformation_Vertically
                ;   #GadgetTransformation_Size Idem #GadgetTransformation_Horizontally|#GadgetTransformation_Vertically
                ;   #GadgetTransformation_All Idem #GadgetTransformation_Position|#GadgetTransformation_Horizontally|#GadgetTransformation_Vertically
                ;4: Grid or Progression with the mouse or keyboard 
                
                SetGadgetText(#GadgetTransformation, "Disable Transformation")
                ;ScrollAreaGadget: Comment the ContainerGadget
                EnableGadgetTransformation(#ScrollArea, #EditorGadget, #GadgetTransformation_All, 10)
                EnableGadgetTransformation(#ScrollArea, #ButtonGadget, #GadgetTransformation_All)
                EnableGadgetTransformation(#ScrollArea, #TrackBarGadget, #GadgetTransformation_Position|#GadgetTransformation_Horizontally)
                EnableGadgetTransformation(#ScrollArea, #SpinGadget, #GadgetTransformation_Position|#GadgetTransformation_Horizontally,5)
                
                ;Window: Comment the ScrollAreaGadget and the ContainerGadget
                ;EnableGadgetTransformation(#Window, #EditorGadget, #GadgetTransformation_All, 10)
                ;EnableGadgetTransformation(#Window, #ButtonGadget, #GadgetTransformation_All)
                ;EnableGadgetTransformation(#Window, #TrackBarGadget, #GadgetTransformation_Position|#GadgetTransformation_Horizontally)
                ;EnableGadgetTransformation(#Window, #SpinGadget, #GadgetTransformation_Position|#GadgetTransformation_Horizontally,5)
                
                ;ContainerGadget: Comment the ScrollAreaGadget
                ;EnableGadgetTransformation(#Container, #EditorGadget, #GadgetTransformation_All, 10)
                ;EnableGadgetTransformation(#Container, #ButtonGadget, #GadgetTransformation_All)
                ;EnableGadgetTransformation(#Container, #TrackBarGadget, #GadgetTransformation_Position|#GadgetTransformation_Horizontally)
                ;EnableGadgetTransformation(#Container, #SpinGadget, #GadgetTransformation_Position|#GadgetTransformation_Horizontally,5)              
            EndSelect
        EndSelect
    EndSelect
    
  ForEver
CompilerEndIf
; IDE Options = PureBasic 5.42 LTS (Linux - x64) - PureBasic 5.44 LTS, 5.51 and 5.60 (Windows - x86/x64)
; EnableUnicode
; EnableXP
; EnablePurifier
Avatar de l’utilisateur
Kwai chang caine
Messages : 6989
Inscription : sam. 23/sept./2006 18:32
Localisation : Isere

Re: SweetyVD (Visual Designer)

Message par Kwai chang caine »

Je suis ton projet avec la plus grande attention 8)

Je suis un maniaque presque pervers :oops: des VD :wink:
Image
ImageLe bonheur est une route...
Pas une destination

PureBasic Forum Officiel - Site PureBasic
Avatar de l’utilisateur
ChrisR
Messages : 235
Inscription : sam. 14/févr./2015 16:20

Re: SweetyVD (Visual Designer)

Message par ChrisR »

Merci ChaudEf, KCC pour votre soutiens.
N'oublions pas qu'il est, au départ, juste un exercice sans prétentions pour vraiment rentrer dans PB.

@KCC
Merci pour ton humour :lol:
Moi aussi je suis un pervers des VD. J'ai du avoir un manque quand j'étais petit. Et plus tard sur AS400.

Image
Avatar de l’utilisateur
falsam
Messages : 7317
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: SweetyVD (Visual Designer)

Message par falsam »

ChrisR a écrit : J'ai du avoir un manque quand j'étais petit. Et plus tard sur AS400.
#souvenir, #comemo j'ai codé sur IBM 36/38, IBM4341 et AS400 en cobol et GAP et évidement pas de VD :wink:

Pas de manque pour moi puisque l'idée n'existait pas ..... à l'époque.
Configuration : Windows 11 Famille 64-bit - PB 6.20 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Avatar de l’utilisateur
falsam
Messages : 7317
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: SweetyVD (Visual Designer)

Message par falsam »

Oops j'ai oublié. Joli ce dernier code de Stargate. Je l'avais vu sur le forum Allemand.
Configuration : Windows 11 Famille 64-bit - PB 6.20 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Avatar de l’utilisateur
Kwai chang caine
Messages : 6989
Inscription : sam. 23/sept./2006 18:32
Localisation : Isere

Re: SweetyVD (Visual Designer)

Message par Kwai chang caine »

#souvenir, #comemo j'ai codé sur IBM 36/38, IBM4341 et AS400 en cobol et GAP et évidement pas de VD
@FALSAM
Tu devais humidifier ton pantalon à cette époque en pratiquant la prog sur ce genre de monstre de technologie sortis de nulle part 8)
Moi j'ai tripoté un vieux ronblon comme ça...rien que de repenser au bruit du clavier, j'ai presque une petite erection :mrgreen:
Quand je pense que je l'ai tout démonté, comme un con, toutes les cartes en epoxy marron avec des millions de diodes au germanium soudées debout sur le dessus de la plaque.
Je m'en mort encore les glaouis d'avoir désossé cette merveille, rien que par curiosité, en fait c'est presque un crime :twisted:
Bon... j'ai été un peu moins pervers que les barjots de maintenant...j'ai pas entérré les morceaux :mrgreen:
Moi aussi je suis un pervers des VD
@CHRISR
Perso moi, c'est de voir s'écrire le code tout seul qui m'a toujours émerveillé 8O
Comme si whatmille petits chinois étaient sous mon bureau pour taper ces foutus #%¨$$* de coordonnées X, Y de chaque gadget :twisted:
Je crois que en fait, c'est un des logiciels qui m'a le plus épaté, surtout quand on est passionné des utilitaires comme moi, ou y'a plus de boutons sur mes programmes que j'en ai jamais eu sur mes fesses de bébés en toute une vie :mrgreen:
Et puis je suis passé par VB...et bon faut dire que le langage est pas optimum, mais le VD....y'a rien à dire 8)

Mais bon sang, qu'est ce que c'est long de faire un VD qui tourne...j'ai moi aussi essayé...et j'ai eu des problemes :|
Cela dit...j'ai vraiment pas été rapide :mrgreen:

Image

C'est sur que si tu as travaillé sur AS400, tu as du broyer du noir avant de te mettre au vert :lol:
Moi je n'ai pas programmé dessus, mais j'utilise encore pour quelques années ce genre de tromblon, via emulateur
Mais la aussi, y'a beau avoir une "ultra HD" de 80 x 24 :mrgreen: et ben je m'éclate tout le temps quand je l'utilise....
En fait, je me dit que je suis en train de tripoter le mamouth de l'informatique, celui par qui sont passé les plus grands, la génese du bit, du langage C....
Enfin.... le johnny hallyday numerique quoi :D

Bon..j'arrête c'est mon coté vieux con qui ressort :oops:

Allez courage, fout nous la honte, à tout ceux, dont je suis, qui ont commencé et jamais fini, et crois moi...la liste est longue comme mon bras :|
ImageLe bonheur est une route...
Pas une destination

PureBasic Forum Officiel - Site PureBasic
Avatar de l’utilisateur
falsam
Messages : 7317
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: SweetyVD (Visual Designer)

Message par falsam »

je pense que la bonne méthode serait de recréer les gadgets 100% Canvas comme dans le Form Designer de PureBasic.

Si ça peut t'aider. Je te passe une base permettant de :
- créer quelques gadgets depuis un menu contextuel.
- Sélectionner un gadget.
- Déplacer un gadget.

Les models de gadget ainsi que la configuration du grid de conception sont défini dans deux fichiers JSON

Exemple de configuration actuel d'un gadget

Code : Tout sélectionner

{
    "name"    : "ButtonGadget",	;Nom du gadget
    "enum"    : "Button_",		;Nom génerique de l'énumération (Exemple #Button_1)	
    "width"   : 80,				;Largeur par défaut
    "height"  : 24,				;Hauteur par défaut		
    "caption" : 1,				;Gadget avec texte (#True/#False)
    "any"     : 0,				;Générer automatiquement la variable enumeration (#True/#False)
    "splitter": 0,				;C'est un splitter (#True/#False)
    "tooltype": 1,				;Une aide est possible (#True/#False)
    "item"    : 0,				;Item ou colonne (#True/#False)
    "flag"    : []				;Array de flag
},
A toi les joie du redimensionnement d'un gadget, mise en place d'un inspecteur et génération du code.

:arrow: http://falsam.com/download/purebasic/TVD100.zip

Enjoy :wink:
Configuration : Windows 11 Famille 64-bit - PB 6.20 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Avatar de l’utilisateur
ChrisR
Messages : 235
Inscription : sam. 14/févr./2015 16:20

Re: SweetyVD (Visual Designer)

Message par ChrisR »

Avec les gadgets 100% recréé en canva
je comprends l'intérêt, Yaouuuh :D , merci Falsam :D
Et bravo pour ton Tiny Visual Designer.
Bon il va falloir que j'étudie
Répondre