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.
Benutzeravatar
RSBasic
Admin
Beiträge: 8022
Registriert: 05.10.2006 18:55
Wohnort: Gernsbach
Kontaktdaten:

Re: EnableGadgetTransformation - Gadget zur laufzeit verände

Beitrag von RSBasic »

Nicht schlecht. :allright:
Aus privaten Gründen habe ich leider nicht mehr so viel Zeit wie früher. Bitte habt Verständnis dafür.
Bild
Bild
Benutzeravatar
alen
Beiträge: 107
Registriert: 09.04.2007 17:38
Computerausstattung: Main Hardware: AMD Ryzen 5 1600 - 6 Core / Gigabyte B450 Aorus Pro / Sapphire RX580 8GB
PB 5.61 and earlier @ Manjaro Linux XFCE x64/ Fedora Linux Cinnamon x64 / Windows 10 x64 on various Hardware Platforms
Wohnort: Duisburg
Kontaktdaten:

Re: EnableGadgetTransformation - Gadget zur laufzeit verände

Beitrag von alen »

Hallo STARGÅTE,

funktioniert bestens unter einem aktuellen 64 Bit Manjaro Linux (Archlinux Basis).
Sehr nett. Das gefällt mir.

Grüße
Alen
---
Main Hardware: AMD Ryzen 5 1600 - 6 Core / Asus B350M-A / Nvidia GTX650
PB 5.61 and earlier @ Manjaro Linux XFCE x64/ Fedora Linux Cinnamon x64 / Windows 10 x64
on various Hardware Platforms (Notebook and Desktop)
Benutzeravatar
Kiffi
Beiträge: 10620
Registriert: 08.09.2004 08:21
Wohnort: Amphibios 9

Re: EnableGadgetTransformation - Gadget zur laufzeit verände

Beitrag von Kiffi »

STARGÅTE hat geschrieben:Und hier das gewünschte Update: [...]
Super! Danke! :allright:

Grüße ... Peter
Hygge
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 »

Vielen Dank fürs Teilen Stargate, dein Code ist super.

Er hat gleich den Weg in meine Include Sammlung gefunden. :)

Getestet unter Kubuntu
Bild
Benutzeravatar
Sicro
Beiträge: 955
Registriert: 11.08.2005 19:08
Kontaktdaten:

Re: EnableGadgetTransformation - Gadget zur Laufzeit verände

Beitrag von Sicro »

Code wird zum CodeArchiv unter Gadgets/TransformationOfGadgetsAtRuntime.pbi hinzugefügt.
Bild
Warum OpenSource eine Lizenz haben sollte :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (Syntax-Farbschema) :: RegEx-Engine (kompiliert RegExes zu NFA/DFA)
Manjaro Xfce x64 (Hauptsystem) :: Windows 10 Home (VirtualBox) :: Neueste PureBasic-Version
ChrisR
Beiträge: 72
Registriert: 04.03.2017 12:23

Re: EnableGadgetTransformation - Gadget zur Laufzeit verände

Beitrag von ChrisR »

es ist großartig und sehr sauber :allright:
Vielen Dank für den Austausch :D
Ich ließ mich einige Ergänzungen zu machen

Drawing Area in a ScrollArea, a Window or a Container
Move Handle on Top, on Bottom or on the Gadget itself (windows only, need zOrder)
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
...

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
  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
Zuletzt geändert von ChrisR am 05.03.2017 13:56, insgesamt 2-mal geändert.
Benutzeravatar
Stevie63
Beiträge: 86
Registriert: 06.05.2009 23:02
Computerausstattung: Win 10, i7, fsc celsius

Re: EnableGadgetTransformation - Gadget zur Laufzeit verände

Beitrag von Stevie63 »

Geil!
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 »

Danke für die Änderungen, die Pfeiltasten funktionieren super.
Allerdings kann man (Hier unter Kubuntu 16.10) durch eine deiner Änderungen die Gadgets nicht mehr sehen sobald die Transformation aktiviert ist,
nur weiße Flächen.

Heut Abend hab ich Zeit und teste mal, woran genau es liegt.
Bild
ChrisR
Beiträge: 72
Registriert: 04.03.2017 12:23

Re: EnableGadgetTransformation - Gadget zur Laufzeit verände

Beitrag von ChrisR »

auch versucht:
#HandelMove = "Bottom" ;"Gadget" / "Top" / "Bottom"

#HandelMove = "Gadget" needs zOrder (Windows only) to work
On Linux or Mac, use #HandelMove = "Top" or #HandelMove = "Bottom"
Benutzeravatar
STARGÅTE
Kommando SG1
Beiträge: 6996
Registriert: 01.11.2005 13:34
Wohnort: Glienicke
Kontaktdaten:

Re: EnableGadgetTransformation - Gadget zur Laufzeit verände

Beitrag von STARGÅTE »

Hallo ChrisR,

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).

Aber ich habe gesehen, dass in der neuen PB Version nun die Möglichkeit besteht Das CanvasGadget selbst als Container für weitere Gadgets zu nutzen. Wie dann aber das Event-Verwaltung klappt oder wie ich das Gadget ins Canvas verschieben kann weiß ich nicht.
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
Antworten