EnableGadgetTransformation - Gadget zur Laufzeit verändern

Hier könnt Ihr gute, von Euch geschriebene Codes posten. Sie müssen auf jeden Fall funktionieren und sollten möglichst effizient, elegant und beispielhaft oder einfach nur cool sein.
ChrisR
Beiträge: 72
Registriert: 04.03.2017 12:23

Re: EnableGadgetTransformation - Gadget zur Laufzeit verände

Beitrag von ChrisR »

Hallo STARGÅTE,

Entschuldigung Google übersetzen
STARGÅTE hat geschrieben:Genau aus Kompatibilitätsgründen hatte ich das Verschieben von Gadgets nur über dieses "kleine Kästchen" ermöglicht und nicht über das ganze Gadget (was sicher praktischer ist, keine Frage).
ja, ich weiß, aber für Windows, es ist gut zu fügen

Code: Alles auswählen

CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  #HandelMove  = "Gadget"   ;"Gadget" / "Top" / "Bottom"
CompilerElse
  #HandelMove  = "Bottom"   ;"Top" / "Bottom"
CompilerEndIf
ChrisR
Beiträge: 72
Registriert: 04.03.2017 12:23

Re: EnableGadgetTransformation - Gadget zur Laufzeit verände

Beitrag von ChrisR »

Ich habe einen Test mit #PB_Canvas_Container (PB 5.60)
aber ohne Erfolg, Anzeigeproblem
und sogar Kompatibilitätsproblem mit Linux, Mac

Code: Alles auswählen

Procedure SetParent(Child.i, Parent.i)
  Protected ChildID.i, ParentID.i, PreviousParent.i
  If IsGadget(Child) : ChildID = GadgetID(child) : Else : ChildID = WindowID(child) : EndIf
  If IsGadget(Parent) : ParentID = GadgetID(Parent) : Else : ParentID = WindowID(Parent) : EndIf
  
  CompilerSelect #PB_Compiler_OS
      
    CompilerCase #PB_OS_Windows
      PreviousParent = SetParent_(ChildID, ParentID)
      
    CompilerCase #PB_OS_Linux
      Protected *childWidget.GtkWidget = ChildID
      Protected *parentWidget.GtkWidget = ParentID
      gdk_window_reparent_(*childWidget\Window, *parentWidget\Window, 0, 0)
      
    CompilerCase #PB_OS_MacOS
      Debug "No solution for MacOS yet !"
      
  CompilerEndSelect
EndProcedure
EnableGadgetTransformation:

Code: Alles auswählen

Case 1
  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)
  SetGadgetZOrder(Handle)
DisableGadgetTransformation:

Code: Alles auswählen

If I = 1
  ResizeGadget(Gadget, GadgetX(\Handle[I])+1, GadgetY(\Handle[I])+1, GadgetWidth(\Handle[I])-2, GadgetHeight(\Handle[I])-2)
  SetParent(Gadget, ParentGadget)
EndIf
FreeGadget(\Handle[I])
Benutzeravatar
Bisonte
Beiträge: 2430
Registriert: 01.04.2007 20:18

Re: EnableGadgetTransformation - Gadget zur Laufzeit verände

Beitrag von Bisonte »

So wäre eigentlich nur der Weg...

Transformation an.
Gadget wird komplett auf einem Canvas abgebildet.
Das Gadget wird versteckt.
Das Canvas wird bewegt
Transformation aus
Canvas wird ausgeblendet und Gadget wird mit neuer Position und Grösse wieder hervorgeholt.

Diese Vorgehensweise würde auch das Flackern bei einigen Gadgets minimieren.
Zusätzlich könnten die vielen verschiedenen "Anfasspunkte" nicht mehr aus einzelnen Canvas bestehen,
sondern dann im "KopiertenAbbildCanvas" integriert sein.

So die Theorie ;)
PureBasic 6.10 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
ChrisR
Beiträge: 72
Registriert: 04.03.2017 12:23

Re: EnableGadgetTransformation - Gadget zur Laufzeit verände

Beitrag von ChrisR »

Ich stimme mit der Theorie, es wäre gut, um zu versuchen :)
Benutzeravatar
Macros
Beiträge: 1314
Registriert: 23.12.2005 15:00
Wohnort: Olching(bei FFB)
Kontaktdaten:

Re: EnableGadgetTransformation - Gadget zur Laufzeit verände

Beitrag von Macros »

Nachdem ich nun (erfolglos) mit GTK und GDK Apis experimentiert habe für die Z-Order, fand ich eine simple Lösung:

Code: Alles auswählen

HideGadget(Handle,1)
in Zeile 299

Funktioniert nun unter Linux und auch in meiner kleinen Windows XP komplier VM (Das flackert!)

Edit: Halt Kommando zurück, damit gehen natürlich die Pfeiltasten zum Steuern nimmer.
Edit 2: funktioniert nun, siehe unten

Code: Alles auswählen

; ---------------------------------------------------------------------------------------
;    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

    #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()
  
  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_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)
          SetActiveGadget(\Handle[1])
          
        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)
            SetActiveGadget(\Handle[1])
            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
          SetActiveGadget(\Handle[1])
          
        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)
                HideGadget(Handle,1)
              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
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
Bild
Benutzeravatar
Macros
Beiträge: 1314
Registriert: 23.12.2005 15:00
Wohnort: Olching(bei FFB)
Kontaktdaten:

Re: EnableGadgetTransformation - Gadget zur Laufzeit verände

Beitrag von Macros »

So nun funktioniert doch alles (Code im Post drüber)

Ein paar SetActiveGadget auf das versteckte Gadget erlauben die Tasten zu benutzen.

Vorteile:
Windows und Linux gleichermaßen
Kein Windows-API Zugriff mehr nötig
Weniger Flackern unter Windows.
Bild
Benutzeravatar
mk-soft
Beiträge: 3701
Registriert: 24.11.2004 13:12
Wohnort: Germany

Re: EnableGadgetTransformation - Gadget zur Laufzeit verände

Beitrag von mk-soft »

:allright:
Alles ist möglich, fragt sich nur wie...
Projekte ThreadToGUI / EventDesigner V3 / OOP-BaseClass-Modul
Downloads auf MyWebspace / OneDrive
Benutzeravatar
STARGÅTE
Kommando SG1
Beiträge: 6999
Registriert: 01.11.2005 13:34
Wohnort: Glienicke
Kontaktdaten:

Re: EnableGadgetTransformation - Gadget zur Laufzeit verände

Beitrag von STARGÅTE »

Wie kann ich jetzt ein Gadget verschieben?
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Aktuelles Projekt: Lizard - Skriptsprache für symbolische Berechnungen und mehr
ChrisR
Beiträge: 72
Registriert: 04.03.2017 12:23

Re: EnableGadgetTransformation - Gadget zur Laufzeit verände

Beitrag von ChrisR »

Google übersetzen, sorry :oops:
In der Tat ist es nicht möglich, sich mit modifiziertem Code von Macros zu bewegen

Ich fand eine Lösung für das Moved Handle Gadget :allright:
Hier getestet mit Windows-und Ubuntu, Es sieht gut aus, die Tastatur und die Maus auf den Gadget verfügbar sind.

Wir müssen InitGadgetTransformation() kurz nach dem Zeichnungsbereich aufrufen: Fenster, ScrollArea oder Container und vor dem Erstellen der Gadetten
lassen Sie mich wissen, ob es Ihnen passt STARGÅTE

Code: Alles auswählen

; ---------------------------------------------------------------------------------------
;    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: 0Window, 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_Vertically,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
Michael Vogel
Beiträge: 71
Registriert: 16.03.2006 11:20

Re: EnableGadgetTransformation - Gadget zur Laufzeit verände

Beitrag von Michael Vogel »

Im englischen und französichen Forum wurde ein vielversprechender Visual Designer vorgestellt (der hoffentlich weiterentwickelt wird), der sich unter anderem auf den Code von Stargåte stützt.

Scheinbar habe ich mich seinerzeit auch ein wenig mit dem genialen Routinen von Stargåte herumgespielt und ein selbstmodifizierendes Programm geschrieben. Auch wenn die Variation nicht viel Neues bietet, möchte ich sie ergänzend an dieser Stelle beifügen:

Code: Alles auswählen

; Define Transformer Kit

	EnableExplicit

	#TxGadgetStart=		1
	#TxGadgetStop=		999
	#TxDemo=			1
	#TxStatus=			#TxGadgetStop+1

	#TxSizeGrid=			10
	#TxSizeBorder=		5
	#TxSizeBox=			#TxSizeBorder+4
	#TxSizeTop=			15

	#TxColorActive=		#Gray
	#TxColorInactive=	$E0D8D8
	#TxColorBackground=	$F0F0F0
	#TxColorGrid=		$04EDA9

	#Undefined=			-1

	Enumeration
		#TxModeOff
		#TxModeOn
		#TxModeSave
	EndEnumeration

	Structure TxGadgetType
		Gadget.i
		Border.i
		Grid.i
		Box.i
		X.i
		Y.i
		W.i
		H.i
		Code.s
		Line.i
	EndStructure

	Global TxGadgetCount
	Global TxMode
	Global TxGrid
	Global TxSourceCount

	Global Dim TxGadget.TxGadgetType(0)
	Global Dim TxSource.s(0)

	#Tx_LeftUp=			5
	#Tx_Left=			7
	#Tx_LeftDown=		6
	#Tx_RightUp=		9
	#Tx_Right=			11
	#Tx_RightDown=		10
	#Tx_Up=			13
	#Tx_Down=			14
	#Tx_Move=			17
	#Tx_Grid=			18

; EndDefine
Procedure.i TxChoose(selector,one,zero)

	If selector
		ProcedureReturn one
	Else
		ProcedureReturn zero
	EndIf

EndProcedure
Procedure.i TxGrid(Value.i)

	If TxGrid
		ProcedureReturn Round(Value/#TxSizeGrid,#PB_Round_Nearest)*#TxSizeGrid
	Else
		ProcedureReturn Value
	EndIf

EndProcedure
Procedure TxSetSource(ID)

	Protected s.s,t.s
	Protected p,line

	CompilerIf #PB_Compiler_Debugger

		With TxGadget(ID)

			If \Gadget<=TxSourceCount
				\Line=0
				\Code=":("
				If ReadFile(0,#PB_Compiler_File,#PB_File_SharedRead)
					While Eof(0)=0
						line+1
						s=Trim(Trim(ReadString(0)),#TAB$)
						p=FindString(s,"Gadget(")
						If p
							t=StringField(Mid(s,p+7),1,",")
							If PeekA(@t)='#' And t<>"#PB_Any"
								If FindString(TxSource(\Gadget)+"#",t+"#")
									\Line=line
									\Code=s
									; Debug " #"+Str(line)+": "+s
									ProcedureReturn line
								EndIf
							EndIf
						EndIf

					Wend
					CloseFile(0)
				EndIf
			EndIf

		EndWith

	CompilerEndIf


EndProcedure
Procedure TxGetID(gadget)

	Protected i

	i=TxGadgetCount
	While i
		If TxGadget(i)\Border=gadget
			ProcedureReturn i
		EndIf
		i-1
	Wend

	ProcedureReturn #Null

EndProcedure
Procedure TxBorderUpdate(ID)

	Protected w,h,i,c

	If StartDrawing(CanvasOutput(TxGadget(ID)\Border))
		w=OutputWidth()
		h=OutputHeight()

		c=TxChoose(TxGadget(ID)\Box,#TxColorActive,#TxColorInactive)
		Box(0,0,w,h,#TxColorBackground)
		Box(0,0,#TxSizeBox,#TxSizeBox,c)
		Box(0,h-#TxSizeBox,#TxSizeBox,#TxSizeBox,c)
		Box(w-#TxSizeBox,0,#TxSizeBox,#TxSizeBox,c)
		Box(w-#TxSizeBox,h-#TxSizeBox,#TxSizeBox,#TxSizeBox,c)
		Box((w-#TxSizeBox)>>1,0,#TxSizeBox,#TxSizeBox,c)
		Box((w-#TxSizeBox)>>1,h-#TxSizeBox,#TxSizeBox,#TxSizeBox,c)
		Box(0,(h-#TxSizeBox)>>1,#TxSizeBox,#TxSizeBox,c)
		Box(w-#TxSizeBox,(h-#TxSizeBox)>>1,#TxSizeBox,#TxSizeBox,c)

		w-1
		h-1
		If TxGadget(ID)\Box
			i=w
			While i>#TxSizeBox
				Plot(i,0,c)
				Plot(i,h,c)
				i-2
			Wend
			i=h
			While i>#TxSizeBox
				Plot(0,i,c)
				Plot(w,i,c)
				i-2
			Wend

			Box(#TxSizeBox+1,h-#TxSizeBorder+1,#TxSizeTop,#TxSizeBorder,TxChoose(TxGrid,#Black,#Gray))
			Box(#TxSizeBox+2,h-#TxSizeBorder+2,#TxSizeTop-2,#TxSizeBorder-2,TxChoose(TxGrid,#TxColorGrid,#White))

		EndIf

		Box(#TxSizeBox+1,0,#TxSizeTop,#TxSizeBorder,TxChoose(TxGadget(ID)\Box,#Black,c))
		Box(#TxSizeBox+2,1,#TxSizeTop-2,#TxSizeBorder-2,TxChoose(TxGadget(ID)\Box,#Yellow,#TxColorBackground))

		StopDrawing()
	EndIf

EndProcedure
Procedure TxGadgetUpdate(ID,x,y,w,h)

	x=TxGrid(x) : y=TxGrid(y) : w=TxGrid(w) : h=TxGrid(h)

	With TxGadget(ID)
		ResizeGadget(\Gadget,x,y,w,h)
		ResizeGadget(\Border,x-#TxSizeBorder,y-#TxSizeBorder,w+#TxSizeBorder<<1,h+#TxSizeBorder<<1)
		TxBorderUpdate(ID)
	EndWith

EndProcedure
Procedure TxGadgetCallback()

	Static Selected
	Static mx,my

	Protected ID,x,y,z
	Protected s.s

	ID=TxGetID(EventGadget())
	If ID; And IsWindowVisible_(TxGadget(ID)\Gadget)
		With TxGadget(ID)

			s=\Code
			x=FindString(s,",")
			y=FindString(s,",",FindString(s,",",FindString(s,",",x+1)+1)+1)
			z=FindString(s,",",y+1)
			If z=0 : z=FindString(s,")",y+1) : EndIf
			If z : \Code=Left(s,x)+Str(GadgetX(\Gadget))+","+Str(GadgetY(\Gadget))+","+Str(GadgetWidth(\Gadget))+","+Str(GadgetHeight(\Gadget))+Mid(s,z) : EndIf

			CompilerIf #TxDemo
				SetGadgetText(#TxStatus," Line "+Str(\Line)+" - "+\Code)
			CompilerEndIf

			Select EventType()
			Case #PB_EventType_LeftButtonDown
				Selected=#True
				If \Box=#Tx_Grid
					TxGrid!1
					TxBorderUpdate(ID)
				EndIf
				mx=TxGrid(GadgetX(\Border)+GetGadgetAttribute(\Border,#PB_Canvas_MouseX))
				my=TxGrid(GadgetY(\Border)+GetGadgetAttribute(\Border,#PB_Canvas_MouseY))

			Case #PB_EventType_LeftButtonUp
				\X=GadgetX(\Gadget)
				\Y=GadgetY(\Gadget)
				\W=GadgetWidth(\Gadget)
				\H=GadgetHeight(\Gadget)
				Selected = #False

			Case #PB_EventType_MouseLeave
				\Box=#Null
				TxBorderUpdate(ID)

			Case #PB_EventType_MouseMove

				If Selected
					X=TxGrid(WindowMouseX(GetActiveWindow())-mx)
					Y=TxGrid(WindowMouseY(GetActiveWindow())-my)

					Select \Box
					Case #Tx_Move
						TxGadgetUpdate(ID,\X+x,\Y+Y,\W,\H)
					Case #Tx_LeftUp
						TxGadgetUpdate(ID,\X+x,\Y+y,\W-x,\H-y)
					Case #Tx_Up
						TxGadgetUpdate(ID,\X,\Y+y,\W,\H-y)
					Case #Tx_RightUp
						TxGadgetUpdate(ID,\X,\Y+y,\W+x,\H-y)
					Case #Tx_Left
						TxGadgetUpdate(ID,\X+x,\Y,\W-x,\H)
					Case #Tx_Right
						TxGadgetUpdate(ID,\X,\Y,\W+x,\H)
					Case #Tx_LeftDown
						TxGadgetUpdate(ID,\X+x,\Y,\W-x,\H+y)
					Case #Tx_Down
						TxGadgetUpdate(ID,\X,\Y,\W,\H+y)
					Case #Tx_RightDown
						TxGadgetUpdate(ID,\X,\Y,\W+x,\H+y)
					EndSelect

				Else
					x=GetGadgetAttribute(EventGadget(),#PB_Canvas_MouseX)
					y=GetGadgetAttribute(EventGadget(),#PB_Canvas_MouseY)
					If y<=#TxSizeBox
						y=1
					ElseIf y>=GadgetHeight(EventGadget())-#TxSizeBox
						y=2
					ElseIf y>=(GadgetHeight(EventGadget())-#TxSizeBox)>>1 And y<=(GadgetHeight(EventGadget())+#TxSizeBox)>>1
						y=3
					Else
						y=#Undefined
					EndIf
					If x<=#TxSizeBox
						y+4
					ElseIf x>=GadgetWidth(EventGadget())-#TxSizeBox
						y+8
					ElseIf x>=(GadgetWidth(EventGadget())-#TxSizeBox)>>1 And x<=(GadgetWidth(EventGadget())+#TxSizeBox)>>1
						y+12
					ElseIf x<=#TxSizeBox+#TxSizeTop
						y+16
					EndIf

					Select y
					Case #Tx_LeftUp,#Tx_RightDown
						x=#PB_Cursor_LeftUpRightDown
					Case #Tx_LeftDown,#Tx_RightUp
						x=#PB_Cursor_LeftDownRightUp
					Case #Tx_Left,#Tx_Right
						x=#PB_Cursor_LeftRight
					Case #Tx_Up,#Tx_Down
						x=#PB_Cursor_UpDown
					Case #Tx_Move
						x=#PB_Cursor_Arrows
					Case #Tx_Grid
						x=#PB_Cursor_Hand
					Default
						x=#PB_Cursor_Default
						y=#Undefined
					EndSelect

					SetGadgetAttribute(\Border,#PB_Canvas_Cursor,x)
					If \Box<>y
						\Box=y
						TxBorderUpdate(ID)
					EndIf

				EndIf
			EndSelect
		EndWith
	EndIf

EndProcedure
Procedure TxGadgetAdd(Gadget.i)

	TxGadgetCount+1
	ReDim TxGadget(TxGadgetCount)

	With TxGadget(TxGadgetCount)
		\Gadget=Gadget
		\X=GadgetX(Gadget)
		\Y=GadgetY(Gadget)
		\W=GadgetWidth(Gadget)
		\H=GadgetHeight(Gadget)
		\Border=CanvasGadget(#PB_Any,\X-#TxSizeBorder,\Y-#TxSizeBorder,\W+#TxSizeBorder<<1,\H+#TxSizeBorder<<1)

		TxSetSource(TxGadgetCount)
		TxBorderUpdate(TxGadgetCount)
		BindGadgetEvent(\Border,@TxGadgetCallback())

		SetWindowLongPtr_(GadgetID(\Border),#GWL_STYLE,GetWindowLongPtr_(GadgetID(\Border),#GWL_STYLE)|#WS_CLIPSIBLINGS)
		SetWindowPos_(GadgetID(\Gadget),#HWND_TOP,-1,-1,-1,-1,#SWP_NOSIZE|#SWP_NOMOVE)
	EndWith

EndProcedure
Procedure TxGadgetMode(mode)

	Protected i
	Protected ThisWindow
	Protected GadgetWindow

	If mode=#TxModeSave

		Protected s.s,c.s
		Protected n,line

		CompilerIf #PB_Compiler_Debugger

			; Debug "SAVE - "+#PB_Compiler_File
			If TxGadgetCount
				If CopyFile(#PB_Compiler_File,#PB_Compiler_File+".tmp")
					If ReadFile(0,#PB_Compiler_File+".tmp")
						If CreateFile(1,#PB_Compiler_File)
							While Eof(0)=0
								line+1
								s=ReadString(0)
								n=0
								i=TxGadgetCount
								While i
									If TxGadget(i)\Line=line
										n=i
										i=1
									EndIf
									i-1
								Wend
								If n
									c=TxGadget(n)\Code
									n=FindString(s,Left(c,FindString(c,",")))
									s=Left(s,n-1)+c
								EndIf
								WriteStringN(1,s)
							Wend
							CloseFile(1)
						EndIf
						CloseFile(0)
					EndIf
				EndIf
			EndIf

		CompilerEndIf


	Else
		TxMode=mode

		; ThisWindow=WindowID(GetActiveWindow())
		; UseGadgetList(ThisWindow)

		If TxMode
			For i=#TxGadgetStart To #TxGadgetStop
				If IsGadget(i)
					GadgetWindow=GetParent_(GadgetID(i))
					If IsWindow_(GadgetWindow)
						If GadgetWindow<>ThisWindow
							ThisWindow=GadgetWindow
							UseGadgetList(ThisWindow)
						EndIf
						; If GadgetWindow=ThisWindow
						TxGadgetAdd(i)
						; EndIf
					EndIf
				EndIf
			Next i

		Else

			While TxGadgetCount
				With TxGadget(TxGadgetCount)
					UnbindGadgetEvent(\Border,@TxGadgetCallback())
					FreeGadget(\Border)
				EndWith
				TxGadgetCount-1
			Wend

		EndIf
	EndIf


EndProcedure
Procedure TxInit()

	Protected s.s
	Protected n,scan

	CompilerIf #PB_Compiler_Debugger

		If ReadFile(0,#PB_Compiler_File)
			While Eof(0)=0
				s=Trim(Trim(ReadString(0)),#TAB$)
				If Left(s,11)="Enumeration"
					n=0
					scan=1
				ElseIf Left(s,14)="EndEnumeration"
					scan=0
				ElseIf scan And PeekA(@s)='#'
					; Debug s+" = "+Str(n)
					If n>TxSourceCount
						TxSourceCount=n
						ReDim TxSource(TxSourceCount)
					EndIf
					TxSource(n)+s
					n+1
				EndIf
			Wend
			CloseFile(0)
		EndIf

	CompilerEndIf

	TxGrid=#True
	TxGadgetMode(#TxModeOn)

EndProcedure

; -----------------------------------------------------------------------------------------------------------------------------

Enumeration
	#Window1
	#Window2
	#TxGadgetDemo
	#TextGadget
	#EditorGadget
	#ButtonGadget
	#TrackBarGadget
	#CanvasGadget
	#ListGadget
	#FrameGadget
	#CheckboxGadget
	#SpinGadget
	#AnotherOne
	#Panel1
	#Panel2
	#PanButton1
	#PanButton2
EndEnumeration

OpenWindow(#Window1, 0, 0, 600, 400, "Window 1", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
EditorGadget(#EditorGadget,20,80,200,50, #PB_Editor_WordWrap) : SetGadgetText(#EditorGadget, "Grumpy wizards make toxic brew for the evil Queen and Jack.")
ButtonGadget(#ButtonGadget,20,150,200,30, "Hallo Welt!", #PB_Button_MultiLine)
TextGadget(#TextGadget,280,160,300,20,"The early bird gets the worm, but the early worm gets eaten.",#PB_Button_MultiLine)
TrackBarGadget(#TrackBarGadget,240,110,340,30, 0, 100) : SetGadgetState(#TrackBarGadget, 70)
CanvasGadget(#CanvasGadget,240,30,340,60)
CheckBoxGadget(#CheckboxGadget,20,250,560,20, "CheckBox checked"): SetGadgetState(#CheckboxGadget, #PB_Checkbox_Checked)
SpinGadget(#SpinGadget,20,200,560,30,0,100,#PB_Spin_Numeric) : SetGadgetState(#SpinGadget, 70)
ListIconGadget(#ListGadget,20,290,290,70,"Column 1",100,#PB_ListIcon_GridLines)
FrameGadget(#FrameGadget,340,290,240,70,"",#PB_Frame_Single)

ButtonGadget(#TxGadgetDemo,20,30,200,30,"SAVE GADGETS NOW!",#PB_Button_MultiLine)
TextGadget(#TxStatus,0,380,6000,20,"")

OpenWindow(#Window2,200,200,600,400,"Window 2",#PB_Window_MinimizeGadget)
EditorGadget(#AnotherOne,10,20,260,360, #PB_Editor_WordWrap) : SetGadgetText(#AnotherOne,"Grumpy wizards make toxic brew for the evil Queen and Jack.")
PanelGadget(#Panel1,290,20,290,360)
AddGadgetItem(#Panel1, -1, "Panel 1")
PanelGadget(#Panel2,20,80,250,180)
AddGadgetItem(#Panel2, -1, "Sub-Panel 1")
AddGadgetItem(#Panel2, -1, "Sub-Panel 2")
AddGadgetItem(#Panel2, -1, "Sub-Panel 3")
CloseGadgetList()
AddGadgetItem (#Panel1, -1,"Panel 2")
ButtonGadget(#PanButton1,20,30,100,60,"Button 1")
ButtonGadget(#PanButton2,130,30,100,60,"Button 2")
CloseGadgetList()

SetActiveWindow(#Window1)
TxInit()

Repeat

	Select WaitWindowEvent()

	Case #PB_Event_CloseWindow
		End

	Case #PB_Event_Gadget
		Select EventGadget()
		Case #TxGadgetDemo
			TxGadgetMode(#TxModeSave)
			TxGadgetMode(TxMode!1)
			SetGadgetText(#TxGadgetDemo,StringField("Enable Transformer.Save Gadget Location",TxMode+1,"."))
		EndSelect
	EndSelect

ForEver
Antworten