SweetyVD (Visual Designer)

Share your advanced PureBasic knowledge/code with the community.
FlatEarth

Re: SweetyVD (Visual Designer)

Post by FlatEarth »

@ChrisR : you're welcome. :) I use these codes for spin control, this works perfectly without the container.

Code: Select all

Procedure capturespin(gadget,output)
  Protected hdc,hSpin,spsize.rect,Img
  hdc = StartDrawing(CanvasOutput(output))
  If hdc
    hSpin = FindWindowEx_(GetParent_(GadgetID(gadget)), GadgetID(gadget), 0, 0)
    If hSpin
      GetClientRect_(hSpin,spsize) 
      SendMessage_(hSpin,#WM_PRINT,hDC, #PRF_CHILDREN|#PRF_CLIENT|#PRF_NONCLIENT| #PRF_ERASEBKGND)
      Img = GrabDrawingImage(#PB_Any, 0,0,GadgetWidth(gadget)+18,GadgetHeight(gadget)+25)
      SendMessage_(GadgetID(gadget),#WM_PRINT,hDC, #PRF_CHILDREN|#PRF_CLIENT|#PRF_NONCLIENT| #PRF_ERASEBKGND)
      If Img
        DrawImage(ImageID(Img),ImageWidth(Img)-(spsize\right+18),0)
        FreeImage(Img)
      EndIf  
      StopDrawing()      
    EndIf
  EndIf
EndProcedure
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: SweetyVD (Visual Designer)

Post by ChrisR »

All roads lead to Rome, both work well.
:)
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: SweetyVD (Visual Designer)

Post by ChrisR »

@FlatEarth
It works well for All, there is just the text inside the EditorGadget that is not captured.
Do you have a specific procedure for it ?
FlatEarth

Re: SweetyVD (Visual Designer)

Post by FlatEarth »

I have never been able to properly capture the editor and shortcut controls.
I suggest you capture string control instead, this control is properly captured and encompasses all of their properties and appearance.the only difference with the editor appearance are scrollbars that can be ignored. In your designer the output code is taken from the position and size of the string control is (Editor and shortcut).

For multi-line support like the editor :

Code: Select all

StringGadget(#PB_Any,X,Y,Width,Height,"",#ES_MULTILINE|#ES_AUTOVSCROLL|#ES_AUTOHSCROLL)
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: SweetyVD (Visual Designer)

Post by ChrisR »

Thanks, I got it with GetGadgetText > DrawText.
Seems pretty compliant

Code: Select all

SendMessage_(GadgetID(Gadget),#WM_PRINT,hDC, #PRF_CHILDREN|#PRF_CLIENT|#PRF_NONCLIENT|#PRF_OWNED|#PRF_ERASEBKGND)
      
      Select GadgetType(Gadget)
        Case 22   ;Specific EditorGadget
          EditorText = GetGadgetText(Gadget)
          If EditorText <> ""
            DrawingFont(GetGadgetFont(#PB_Default))
            DrawingMode(#PB_2DDrawing_Transparent)
            SizeTextH = TextHeight(" ")
            CountLine = CountString(EditorText, #CRLF$)+1
            For I = 1 To CountLine
              DrawText(2, (I-1)*SizeTextH, StringField(EditorText, I, #LF$), $000000)
            Next
          EndIf
FlatEarth

Re: SweetyVD (Visual Designer)

Post by FlatEarth »

Okay but what do you do for the background of the editor gadget? Do we have to draw it all ourselves?
Image
Last edited by FlatEarth on Tue Feb 11, 2020 4:12 pm, edited 2 times in total.
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: SweetyVD (Visual Designer)

Post by ChrisR »

Latest CaptureGadget with #PB_Gadget_BackColor and #PB_Gadget_FrontColor

Edit: Procedure included in the following post
Last edited by ChrisR on Thu Feb 06, 2020 3:32 pm, edited 1 time in total.
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: SweetyVD (Visual Designer)

Post by ChrisR »

I like it, it's very fluid and flicker-free. It's unfortunately only for Windows but it's a really good base :)
I've made some modifications, improvements:
- Add Resize Gadget with the bottom/right handle (for now)
- Mouse Cursor Over Gadget
- Select or create Gadget with Lasso

Image

Code: Select all

; -----------------------------------------------------------------------------
; Move/Drag/Resize Captured Gadgets
; -----------------------------------------------------------------------------
; Credit:
; Base Code by FlatEarth:               https://www.purebasic.fr/english/viewtopic.php?f=12&t=68187&start=120
; Inspired by the following topics:
; - Move/Drag Canvas Image by Danilo:   https://www.purebasic.fr/english/viewtopic.php?f=13&t=54098&hilit=drag+move
; - Capture Gadget by Rashad:           https://www.purebasic.fr/english/viewtopic.php?f=5&t=70746&hilit=capture+gadget%3B+64bit%3B
; Modified by ChrisR
; - Add Resize Gadget with bottom/right handle, Mouse Cursor Over Gadget, Select or create Gadget with Lasso
; -----------------------------------------------------------------------------
; Date:       2020-02-06
; PB-Version: 5.71 LTS
; OS:         Windows Only
; -----------------------------------------------------------------------------

EnableExplicit

Structure canvasitem
  gadget.i
  img.i
  x.i
  y.i
  width.i
  height.i
EndStructure

Global DriveImage = LoadImage(#PB_Any, #PB_Compiler_Home + "Examples\Sources\Data\Drive.bmp")
Global Geebee2Image = LoadImage(#PB_Any, #PB_Compiler_Home + "Examples\Sources\Data\Geebee2.bmp")

Global Combo_Gadget
Global isCurrentItem = #False
Global CurrentItemXOffset.i, CurrentItemYOffset.i
Global x,y,x0,y0,width0,height0,Drag.b, Resize.b
Global NewList Images.canvasitem()               

Define ObjectID.i, Event.i

Declare.i Min(ValueA, ValueB)
Declare.i Max(ValueA, ValueB)
Declare DrawHandle(Handle)
Declare AddImage(Gadget,img,x,y)
Declare HitInside(MinX,MaxX,MinY,MaxY)
Declare HitTest(x,y)
Declare MouseOver(x,y)
Declare CreateGadget(Type$, Caption$="", Width=200, Height=100, X=0, Y=0, Param1=0, Param2=1, Param3=1000, Flag=0)
Declare CaptureGadget(Gadget)
Declare DrawCanvas()
Declare ResizeCanvas()
Declare MoveCanvas()

Procedure.i Min(ValueA, ValueB)
  If ValueA < ValueB
    ProcedureReturn ValueA
  Else
    ProcedureReturn ValueB
  EndIf
EndProcedure

Procedure.i Max(ValueA, ValueB)
  If ValueA > ValueB
    ProcedureReturn ValueA
  Else
    ProcedureReturn ValueB
  EndIf
EndProcedure

Procedure DrawHandle(Handle)
  If StartDrawing(CanvasOutput(Handle))
    DrawingMode(#PB_2DDrawing_Default)
    Box(0,0,8,8,#Blue)
    Box(1,1,6,6,#White)
    StopDrawing()
  EndIf
EndProcedure

Procedure AddImage(Gadget,img,x,y)
  If AddElement(Images())
    Images()\gadget = Gadget
    Images()\img    = img
    Images()\x      = x
    Images()\y      = y
    Images()\width  = ImageWidth(img)
    Images()\height = ImageHeight(img)
  EndIf
EndProcedure

Procedure HitInside(MinX,MaxX,MinY,MaxY)
  Protected ObjectID
  isCurrentItem = #False
  If MaxX > MinX + 4 And MaxY > MinY + 4
    If LastElement(Images())   ; search for hit, starting from end (z-order)
      Repeat
        If MaxX >= Images()\x And MinX <= Images()\x + Images()\width And MaxY >= Images()\y And MinY <= Images()\y + Images()\height
          MoveElement(Images(), #PB_List_Last)
          isCurrentItem = #True
          Break
        EndIf
      Until PreviousElement(Images())=0
    EndIf
    If isCurrentItem = #False
      If MaxX > MinX + 10 And MaxY > MinY + 10
        ObjectID = CreateGadget(GetGadgetText(Combo_Gadget)+"Gadget", " "+GetGadgetText(Combo_Gadget), Max(x0,x)-Min(x0,x), Max(y0,y)-Min(y0,y))
        HideGadget(ObjectID,1)
        AddImage(ObjectID, CaptureGadget(ObjectID), Min(x0,x),Min(y0,y))
        isCurrentItem = #True
      EndIf
    EndIf
  EndIf
  ProcedureReturn isCurrentItem
EndProcedure

Procedure HitTest(x,y)
  isCurrentItem = #False
  If LastElement(Images())   ; search for hit, starting from end (z-order)
    Repeat
      If x >= Images()\x And x < Images()\x + Images()\width And  y >= Images()\y And y < Images()\y + Images()\height
        MoveElement(Images(), #PB_List_Last)
        isCurrentItem = #True
        CurrentItemXOffset = x - Images()\x
        CurrentItemYOffset = y - Images()\y
        x0 = Images()\x : y0 = Images()\y
        Break
      EndIf
    Until PreviousElement(Images())=0
  EndIf
  ProcedureReturn isCurrentItem
EndProcedure

Procedure MouseOver(x,y)
  Protected MouseOverGadget = #False
  If LastElement(Images())   ; search for hit, starting from end (z-order)
    Repeat
      If x >= Images()\x And x < Images()\x + Images()\width And  y >= Images()\y And y < Images()\y + Images()\height
        MouseOverGadget = #True
        Break
      EndIf
    Until PreviousElement(Images())=0
  EndIf
  If MouseOverGadget
    SetGadgetAttribute(0, #PB_Canvas_Cursor,  #PB_Cursor_Arrows)
  Else
    SetGadgetAttribute(0, #PB_Canvas_Cursor, #PB_Cursor_Default)
  EndIf 
EndProcedure

Procedure CreateGadget(Type$, Caption$="", Width=200, Height=100, X=0, Y=0, Param1=0, Param2=1, Param3=1000, Flag=0)
  Protected ObjectID.i, a
  
  Select Type$
      ;Case "OpenWindow"          : ObjectID = OpenWindow          (#PB_Any, X,Y,Width,Height, Caption$, Flag)
    Case "ButtonGadget"        : ObjectID = ButtonGadget        (#PB_Any, X,Y,Width,Height, Caption$, Flag)
    Case "ButtonImageGadget"   : ObjectID = ButtonImageGadget   (#PB_Any, X,Y,Width,Height, ImageID(Geebee2Image), Flag)   ;Caption$, Flag)
    Case "CalendarGadget"      : ObjectID = CalendarGadget      (#PB_Any, X,Y,Width,Height, Param1, Flag)  
    Case "CanvasGadget"        : ObjectID = CanvasGadget        (#PB_Any, X,Y,Width,Height, Flag)
      If StartDrawing(CanvasOutput(ObjectID))
        DrawingFont(GetGadgetFont(#PB_Default))
        DrawingMode(#PB_2DDrawing_AllChannels)
        DrawImage(ImageID(Geebee2Image), 0, 0, OutputWidth(), OutputHeight())
        DrawingMode(#PB_2DDrawing_Transparent)
        DrawText(5, 5, Caption$, #Blue, #White)
        StopDrawing()
      EndIf
    Case "CheckBoxGadget"      : ObjectID = CheckBoxGadget      (#PB_Any, X,Y,Width,Height, Caption$, Flag)
    Case "ComboBoxGadget"      : ObjectID = ComboBoxGadget      (#PB_Any, X,Y,Width,Height, Flag)
      For a = 1 To 5
        AddGadgetItem(ObjectID, -1, "Element "+Str(a))
      Next
      SetGadgetState(ObjectID, 0)
    Case "ContainerGadget"     : ObjectID = ContainerGadget     (#PB_Any, X,Y,Width,Height, Flag)
      ButtonGadget                                              (#PB_Any, 120,40,120,30, "Container Button")
      CloseGadgetList()
    Case "DateGadget"          : ObjectID = DateGadget          (#PB_Any, X,Y,Width,Height, Caption$, Param1, Flag)
    Case "EditorGadget"        : ObjectID = EditorGadget        (#PB_Any, X,Y,Width,Height, #PB_Editor_ReadOnly)
      For a = 1 To 5
        AddGadgetItem(ObjectID, a, "Editor Line "+Str(a))
      Next
      SetGadgetColor(ObjectID, #PB_Gadget_BackColor, #Yellow)
      SetGadgetColor(ObjectID, #PB_Gadget_FrontColor, #Blue)
    Case "ExplorerComboGadget" : ObjectID = ExplorerComboGadget (#PB_Any, X,Y,Width,Height, "", Flag)   ;Caption$, Flag)        
    Case "ExplorerListGadget"  : ObjectID = ExplorerListGadget  (#PB_Any, X,Y,Width,Height, Caption$, Flag)
    Case "ExplorerTreeGadget"  : ObjectID = ExplorerTreeGadget  (#PB_Any, X,Y,Width,Height, Caption$, Flag)
    Case "FrameGadget"         : ObjectID = FrameGadget         (#PB_Any, X,Y,Width,Height, Caption$, Flag)
    Case "HyperLinkGadget"     : ObjectID = HyperLinkGadget     (#PB_Any, X,Y,Width,Height, Caption$, Param1, Flag)
    Case "ImageGadget"         : ObjectID = ImageGadget         (#PB_Any, X,Y,Width,Height, ImageID(Geebee2Image), Flag)   ; Caption$, Flag)
    Case "IPAddressGadget"
      ObjectID = IPAddressGadget                                (#PB_Any, X,Y,Width,Height)
      SetGadgetState(ObjectID, MakeIPAddress(127, 0, 0, 1))
    Case "ListIconGadget"      : ObjectID = ListIconGadget      (#PB_Any, X,Y,Width,Height, Caption$, Param1, Flag)
      AddGadgetColumn(ObjectID, 0, "Name", 100)
      AddGadgetColumn(ObjectID, 1, "Replica", 250)
      AddGadgetItem(ObjectID, -1, "Thomson"+Chr(10)+"X33: blablabla")
      AddGadgetItem(ObjectID, -1, "Thompson"+Chr(10)+"X33bis: i would say even more")
    Case "ListViewGadget"      : ObjectID = ListViewGadget      (#PB_Any, X,Y,Width,Height, Flag)
      For a = 1 To 12
        AddGadgetItem (ObjectID, -1, "List Element " + Str(a))
      Next
      SetGadgetState(ObjectID, 9)       
    Case "MDIGadget"         
      CompilerIf #PB_Compiler_OS = #PB_OS_Windows
        ObjectID = MDIGadget                                    (#PB_Any, X,Y,Width,Height, Param1, Param2, Flag)
      CompilerEndIf
      ;Case "OpenGL"              : ObjectID = OpenGLGadget        (#PB_Any, X,Y,Width,Height)
    Case "OptionGadget"        : ObjectID = OptionGadget        (#PB_Any, X,Y,Width,Height, Caption$)
    Case "PanelGadget"         : ObjectID = PanelGadget         (#PB_Any, X,Y,Width,Height)
      ButtonGadget                                              (#PB_Any, 120,40,120,30, "Container Button")
      CloseGadgetList()
    Case "ProgressBarGadget"   : ObjectID = ProgressBarGadget   (#PB_Any, X,Y,Width,Height, Param1, Param2*100, Flag)
      SetGadgetState   (ObjectID, 50) 
    Case "ScintillaGadget"
      If InitScintilla()
        ObjectID = ScintillaGadget                              (#PB_Any, X,Y,Width,Height, Param1)
      EndIf
    Case "SplitterGadget"     
      If IsGadget(Param1) And IsGadget(Param2)
        ObjectID = SplitterGadget                               (#PB_Any, X,Y,Width,Height, Param1, Param2, Flag)
      EndIf
    Case "ScrollAreaGadget"
      ;ObjectID = ScrollAreaGadget                              (#PB_Any, X,Y,Width,Height, Param1, Param2, Param3, Flag)
      ObjectID = ScrollAreaGadget                               (#PB_Any, X,Y,Width,Height, Width*2, Height*2, Param3, Flag)
      ButtonGadget                                              (#PB_Any, 120,40,120,30, "Container Button")
      CloseGadgetList()
    Case "ScrollBarGadget"     : ObjectID = ScrollBarGadget     (#PB_Any, X,Y,Width,Height, Param1, Param2*100, Param3, Flag) 
    Case "ShortcutGadget"      : ObjectID = ShortcutGadget      (#PB_Any, X,Y,Width,Height, Param1)  
    Case "SpinGadget"          : ObjectID = SpinGadget          (#PB_Any, X,Y,Width,Height, Param1, Param2*100, #PB_Spin_Numeric)
      SetGadgetState (ObjectID, (Param2*100-Param1)*2/3)
    Case "StringGadget"        : ObjectID = StringGadget        (#PB_Any, X,Y,Width,Height, Caption$, Flag)
    Case "StringMultiGadget"   : ObjectID = StringGadget        (#PB_Any,X,Y,Width,Height,Caption$ + " 1" +#CRLF$+ Caption$ + " 2", #ES_MULTILINE|#ES_AUTOVSCROLL|#ES_AUTOHSCROLL)
    Case "TextGadget"          : ObjectID = TextGadget          (#PB_Any, X,Y,Width,Height, Caption$, Flag)
    Case "TrackBarGadget"      : ObjectID = TrackBarGadget      (#PB_Any, X,Y,Width,Height, Param1, Param2*100, Flag)
      SetGadgetState (ObjectID, (Param2*100-Param1)*2/3)
    Case "TreeGadget"          : ObjectID = TreeGadget          (#PB_Any, X,Y,Width,Height, Flag)
      AddGadgetItem(ObjectID, -1, "Node", 0,  0): AddGadgetItem(ObjectID, -1, "Sub-element", 0,  1): AddGadgetItem(ObjectID, -1, "Element", 0,  0):SetGadgetItemState(ObjectID, 0, #PB_Tree_Expanded)
    Case "WebGadget"           : ObjectID = WebGadget           (#PB_Any, X,Y,Width,Height, Caption$)
  EndSelect
  
  ProcedureReturn ObjectID
EndProcedure 

Procedure CaptureGadget(Gadget)
  Protected Img,hdc,SizeTextH
  Protected hSpin,spsize.rect, SpinImg
  Protected EditorText.s, Color.i, CountLine, I
  Img = CreateImage(#PB_Any,GadgetWidth(Gadget),GadgetHeight(Gadget))
  If IsGadget(Gadget)
    hdc =  StartDrawing(ImageOutput(Img))
    If hdc
      DrawingMode(#PB_2DDrawing_Default)
      ;Gadget_BackColor
      Color = GetGadgetColor(Gadget, #PB_Gadget_BackColor)
      If Color = #PB_Default : Color = $FFFFFF : EndIf
      Box(0, 0, OutputWidth(), OutputHeight(), Color)
      
      If GadgetType(Gadget) = 26   ;Specific SpinGadget (Part1)
        hSpin = FindWindowEx_(GetParent_(GadgetID(Gadget)), GadgetID(Gadget), 0, 0)
        If hSpin
          GetClientRect_(hSpin,spsize)
          SendMessage_(hSpin,#WM_PRINT,hDC, #PRF_CHILDREN|#PRF_CLIENT|#PRF_NONCLIENT| #PRF_ERASEBKGND)
          SpinImg = GrabDrawingImage(#PB_Any, 0,0,GadgetWidth(gadget)+18,GadgetHeight(gadget)+25)
        EndIf
      EndIf
      
      SendMessage_(GadgetID(Gadget),#WM_PRINT,hDC, #PRF_CHILDREN|#PRF_CLIENT|#PRF_NONCLIENT|#PRF_OWNED|#PRF_ERASEBKGND)
      
      Select GadgetType(Gadget)
        Case  8   ;Specific ComboBoxGadget
          DrawingFont(GetGadgetFont(Gadget))
          DrawingMode(#PB_2DDrawing_Transparent)
          SizeTextH = TextHeight(" ")
          DrawText(4, (OutputHeight()-SizeTextH)/2, GetGadgetText(Gadget), $000000)
        Case 22   ;Specific EditorGadget
          EditorText = GetGadgetText(Gadget)
          If EditorText <> ""
            DrawingFont(GetGadgetFont(Gadget))
            Color = GetGadgetColor(Gadget, #PB_Gadget_FrontColor)
            If Color = #PB_Default : Color = $000000 : EndIf
            DrawingMode(#PB_2DDrawing_Transparent)
            SizeTextH = TextHeight(" ")
            CountLine = CountString(EditorText, #CRLF$)+1
            For I = 1 To CountLine
              DrawText(2, (I-1)*SizeTextH, StringField(EditorText, I, #LF$), Color)
            Next
          EndIf
        Case 25   ;Specific ExplorerComboGadget
          DrawingFont(GetGadgetFont(Gadget))
          DrawingMode(#PB_2DDrawing_Transparent)
          DrawImage(ImageID(DriveImage), 4, (OutputHeight()-ImageHeight(DriveImage))/2)
          SizeTextH = TextHeight(" ")
          If GetGadgetText(Gadget) =""
            ;Localized Computer Name: \SOFTWARE\Classes\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\LocalizedString,@%SystemRoot%\system32\windows.storage.dll,-9216
            DrawText(8+ImageWidth(DriveImage), (OutputHeight()-SizeTextH)/2, "This PC", $000000)
          Else
            DrawText(8+ImageWidth(DriveImage), (OutputHeight()-SizeTextH)/2, GetGadgetText(Gadget), $000000)
          EndIf
        Case 26  ;Specific SpinGadget (Part2)
          If IsImage(SpinImg)
            DrawImage(ImageID(SpinImg),ImageWidth(SpinImg)-(spsize\right+18),0)
            FreeImage(SpinImg)
          EndIf
        Case 33  ;Specific CanvasGadget
          DrawingMode(#PB_2DDrawing_AllChannels)
          DrawImage(ImageID(Geebee2Image), 0, 0, OutputWidth(), OutputHeight())
          DrawingFont(GetGadgetFont(#PB_Default))
          DrawingMode(#PB_2DDrawing_Transparent)
          DrawText(5, 5, "Canvas", #Blue, #White)
      EndSelect
      
      StopDrawing()
    EndIf 
  EndIf
  ProcedureReturn Img
EndProcedure

Procedure DrawCanvas()
  If StartDrawing(CanvasOutput(0))
    DrawingMode(#PB_2DDrawing_Default)
    Box(0,0,GadgetWidth(0),GadgetHeight(0), RGB(255,255,255))
    With Images()
      ForEach Images()
        DrawImage(ImageID(\img),\x,\y)   ; draw all images with z-order
        DrawingMode(#PB_2DDrawing_Outlined)
        Box(\x, \y, \Width, \Height, $FFD0D0)   ;Set Default Gadgets Border for those who don't have a contour drawn
      Next
      If isCurrentItem
        ;Gadget Contour #Blue
        DrawingMode(#PB_2DDrawing_Outlined)
        Box(\x,            \y,              \Width,    \Height,   #Blue)
        ;Inside Handles #White or disabled $F0F0F0
        DrawingMode(#PB_2DDrawing_Default) 
        Box(\x-3,          \y-3,            6,         6,         $F0F0F0) 
        Box(\x+\Width-3,   \y-3,            6,         6,         $F0F0F0)
        ;Box(\x+\Width-3,  \y+\Height-3,    6,         6,         $F0F0F0)  ;Real Bottom Right Handle for testing Resizing 
        Box(\x-3,          \y+\Height-3,    6,         6,         $F0F0F0)
        ;Outside Handles #Blue or disabled $505050
        DrawingMode(#PB_2DDrawing_Outlined)
        Box(\x-4,          \y-4,            8,         8,         $505050)
        Box(\x+\Width-4,   \y-4,            8,         8,         $505050)
        ;Box(\x+\Width-4,  \y+\Height-4,    8,         8,         $505050)   ;Real Bottom Right Handle for testing Resizing
        Box(\x-4,          \y+\Height-4,    8,         8,         $505050)        
        ;Real Bottom Right Handle
        ResizeGadget(100,\x+\Width-4, \y+\Height-4, #PB_Ignore, #PB_Ignore)
        SetGadgetData(100, Images())
      Else
        DrawingMode(#PB_2DDrawing_Outlined)
        Box(x0, y0, x-x0, y-y0, #Blue)
        ;Shadow
        ;DrawingMode(#PB_2DDrawing_AlphaBlend) : Box(\x+5, \y+5, \Width, \Height, RGBA($42, $42, $42, $50)) : DrawImage(ImageID(\img), \x, \y, \Width, \Height)
      EndIf
    EndWith  
    StopDrawing()
  EndIf
EndProcedure

Procedure ResizeCanvas()
  Protected *Images.canvasitem = GetGadgetData(EventGadget())
  Protected x.i, y.i
  With *Images
    Select EventType()
      Case #PB_EventType_LeftButtonDown
        CurrentItemXOffset = GadgetX(0) + GadgetX(EventGadget()) + GetGadgetAttribute(EventGadget(), #PB_Canvas_MouseX)
        CurrentItemYOffset = GadgetY(0) + GadgetY(EventGadget()) + GetGadgetAttribute(EventGadget(), #PB_Canvas_MouseY)
        x0 = \x : y0 = \y : width0 = \width : height0 = \height
        ;Debug " x0 " + Str(x0) + " y0 " + Str(y0) + " width0 " + Str(width0) + " height0 " + Str(height0)
        isCurrentItem = #True
        Resize = #True
      Case #PB_EventType_LeftButtonUp
        Resize = #False
      Case #PB_EventType_MouseMove
        If Resize = #True
          x = WindowMouseX(0)
          y = WindowMouseY(0)
          If LastElement(Images())
            ;Bottom Right Handle 
            \x = x0 : \y = y0
            \width  = width0  + x - CurrentItemXOffset
            \height = height0 + y - CurrentItemYOffset
            ;Possible improvement, Calculate Minimum gadget sizes (all OS) by freak: https://www.purebasic.fr/english/viewtopic.php?f=12&t=38349
            If \width < 10 : \width = 10 : EndIf
            If \height < 10 : \height = 10 : EndIf
            If \width <> width0 Or \height <> height0
              ResizeGadget(\gadget,#PB_Ignore,#PB_Ignore,\width,\height)
              FreeImage(\img)
              \img = CaptureGadget(\gadget)
              DrawCanvas()
            EndIf
          EndIf
        EndIf
    EndSelect
  EndWith
EndProcedure

Procedure MoveCanvas()
  Protected ObjectID
  Select EventType()
    Case #PB_EventType_LeftButtonDown
      x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
      y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
      x0 = x : y0 = y
      If HitTest(x,y)
        HideGadget(100,0)
        DrawCanvas()
      Else
        HideGadget(100,1)
      EndIf
      Drag = #True
    Case #PB_EventType_LeftButtonUp
      If HitInside(Min(x0,x),Max(x0,x),Min(y0,y),Max(y0,y))
        HideGadget(100,0)
      Else
        HideGadget(100,1)
      EndIf
      x0 = 0 : y0 = 0 : x = 0 : y = 0
      DrawCanvas()
      Drag = #False
    Case #PB_EventType_MouseMove
      x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
      y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
      If Drag = #True
        If isCurrentItem
          If LastElement(Images())
            Images()\x = x - CurrentItemXOffset
            Images()\y = y - CurrentItemYOffset
            If Images()\x <> x0 Or Images()\y <> y0
              DrawCanvas()
            EndIf  
          EndIf
        Else
          DrawCanvas()
        EndIf
      Else
        MouseOver(x,y)
      EndIf
  EndSelect
EndProcedure

;- Main
If OpenWindow(0, 0, 0, 800, 600, "Move/Drag/Resize Captured Gadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  Combo_Gadget = ComboBoxGadget(#PB_Any,10,0,120,20)
  ;AddGadgetItem(Combo_Gadget, -1, "Window")
  AddGadgetItem(Combo_Gadget, -1, "Button")
  AddGadgetItem(Combo_Gadget, -1, "ButtonImage")
  AddGadgetItem(Combo_Gadget, -1, "Calendar")
  AddGadgetItem(Combo_Gadget, -1, "Canvas")
  AddGadgetItem(Combo_Gadget, -1, "CheckBox")
  AddGadgetItem(Combo_Gadget, -1, "ComboBox")
  AddGadgetItem(Combo_Gadget, -1, "Container")
  AddGadgetItem(Combo_Gadget, -1, "Date")
  AddGadgetItem(Combo_Gadget, -1, "Editor")
  AddGadgetItem(Combo_Gadget, -1, "ExplorerCombo")
  AddGadgetItem(Combo_Gadget, -1, "ExplorerList")
  AddGadgetItem(Combo_Gadget, -1, "ExplorerTree")
  AddGadgetItem(Combo_Gadget, -1, "Frame")
  AddGadgetItem(Combo_Gadget, -1, "HyperLink")
  AddGadgetItem(Combo_Gadget, -1, "Image")
  AddGadgetItem(Combo_Gadget, -1, "IPAddress")
  AddGadgetItem(Combo_Gadget, -1, "ListIcon")
  AddGadgetItem(Combo_Gadget, -1, "ListView")
  AddGadgetItem(Combo_Gadget, -1, "Option")
  AddGadgetItem(Combo_Gadget, -1, "Panel")
  AddGadgetItem(Combo_Gadget, -1, "ProgressBar")
  AddGadgetItem(Combo_Gadget, -1, "Scintilla")
  AddGadgetItem(Combo_Gadget, -1, "ScrollArea")
  AddGadgetItem(Combo_Gadget, -1, "ScrollBar")
  AddGadgetItem(Combo_Gadget, -1, "Spin")
  AddGadgetItem(Combo_Gadget, -1, "String")
  AddGadgetItem(Combo_Gadget, -1, "StringMulti")
  AddGadgetItem(Combo_Gadget, -1, "Text")
  AddGadgetItem(Combo_Gadget, -1, "TrackBar")
  AddGadgetItem(Combo_Gadget, -1, "Tree")
  AddGadgetItem(Combo_Gadget, -1, "Web")
  ; AddGadgetItem(Combo_Gadget, -1, "OpenGL")
  ; AddGadgetItem(Combo_Gadget, -1, "Splitter")
  ; CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  ;   AddGadgetItem(Combo_Gadget, -1, "MDI")
  ; CompilerEndIf
  ; AddGadgetItem(Combo_Gadget, -1, "Shortcut")
  SetGadgetState(Combo_Gadget, 0)
  
  CanvasGadget(0, 0, 20, 800, 580,#PB_Canvas_Container)   ;#PB_Canvas_Keyboard
  CanvasGadget(100, 0, 0, 8, 8) : SetGadgetAttribute(100, #PB_Canvas_Cursor, #PB_Cursor_LeftUpRightDown) : HideGadget(100,1)
  DrawHandle(100)
  CloseGadgetList()
  
  BindGadgetEvent(0,  @MoveCanvas())
  BindGadgetEvent(100, @ResizeCanvas())
  
  Repeat
    Event = WaitWindowEvent()
;     ;Not required, done with HitInside
;     If Event = #PB_Event_Gadget
;       Select EventGadget()
;         Case Combo_Gadget
;           ObjectID = CreateGadget(GetGadgetText(Combo_Gadget)+"Gadget", " "+GetGadgetText(Combo_Gadget), 200, 100)
;           HideGadget(ObjectID,1) : HideGadget(100,0)
;           AddImage(ObjectID, CaptureGadget(ObjectID),  20,  20)
;           isCurrentItem = #True
;           DrawCanvas()
;       EndSelect
;     EndIf   
  Until Event = #PB_Event_CloseWindow
EndIf
FlatEarth

Re: SweetyVD (Visual Designer)

Post by FlatEarth »

@ChrisR : Excellent :) , this can be the start to making a great designer. You have the potential to do so.
It is always difficult for me to manage the container controls in the designer. If you can manage it, you have done all the steps.
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: SweetyVD (Visual Designer)

Post by ChrisR »

Thank you for your kind words 8)
It's the concept that has the potential, fluid, flicker-free, auto z-order... it's all good
Thanks to you for the idea and for assembling those great codes from Rashad, Danilo, Little John.
A pleasure to continue on it :)

Well, then it will only be for Windows. It's a shame, but it's worth continuing.
I think we can do something good and modern. I'll try to go further but it takes timeee.

For properties, flags... I will stay on the current interface, for now.
The appearance is probably less beautiful without a real grid module
But with the advantage of having the main properties directly accessible, avoiding the need to Scoller too much.
And most of all, not having to redo the work :wink:
Otherwise, it's open to anyone who wants to participate, contribute.

See you on a next post about Container
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: SweetyVD (Visual Designer)

Post by ChrisR »

It's complicated for the containers, I'm also having trouble seeing how it could be done in an easy way
An idea, however, to mature

The idea is to have an Edit button or Context menu option for each container.
The container would be opened in the same drawing area, as it is done for the main window.
Descendants or children, and only them, would then be accessible, to add gadgets and move them.
Once the design of the container done, you close it, with a button or other, to return to the previous level.
On this upper level, the container can be moved, resized, the gadgets included will follow (already like that), but they're not accessible.
The ScrollArea would be enlarged to the Inner size
Each tab of the Panel would be considered as a container and they have to be opened one after the other.

And to see the result, switch tabs in the Panel, changing the scrollbar position.
It should be possible via the preview with the Gadget Visible and in real situation.
I hope it' s clear with my poor English.

Just an idea for future and it's far from done.
Not just FlatEarth, what do you think ? another idea on how to manage them without turning into a gasworks ?
FlatEarth

Re: SweetyVD (Visual Designer)

Post by FlatEarth »

ChrisR wrote: The idea is to have an Edit button or Context menu option for each container.
Hi thanks for your idea
ChrisR wrote: The container would be opened in the same drawing area, as it is done for the main window.
It means creating a new form for every container control like window form, right?
Yes it is an good idea and I have seen it work in SDStudio newly developed environment.you can see a sample implementation of your idea in this environment.
But in my opinion, if there are too many containers or we have nested containers,this method will be confusing. also, I don't know how to manage splitter control with this method.
Perhaps the study of PB designer codes may be useful in this regard because one of pb designer strengths is the simple management of container controls.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: SweetyVD (Visual Designer)

Post by srod »

ChrisR, this looks a fantastic project - great looking designer.

I have a dedicated cross-platform property-box control which you are welcome to use if you decide to head down than path. Works on Windows, Linux (qt subsystem only) and MacOS (aside from a couple of bugs in Purebasic for MacOS, but it still runs).

As for your containers. I see a couple of options for you - if I have understood correctly? Each container control could sit on the form designer within its own embedded canvas gadget giving you a natural 'clipping' area if you target your StartDrawing() appropriately or simply use ClipOutput() etc. (buggy on MacOS). Alternatively, if each design element (gadget) is rendered to it's own image (as would appear to be the case looking at the code in this thread with your use of #WM_PRINT) then you have a hierarchy/tree of images representing each container gadget and their child gadgets placed on the design canvas. Drawing each such image to that representing it's parent container will, with suitable recursion, yield the correct display with all child gadgets correctly placed within their respective containers etc. with all necessary clipping handled automatically. There would probably be some additional manual clipping required so as not to draw over the non-client areas of some gadgets etc.

Definitely doable if you can get your head around the necessary recursive elements of the design.
I may look like a mule, but I'm not a complete ass.
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: SweetyVD (Visual Designer)

Post by ChrisR »

I saw it with only 2 tabs, one for the main window and the other for the container
Only 1 Level
when editing a container, the main window would be disabled and only here to see the visual with the other Gadgets
Once the drawing of the container is done, the main window takes the hand again

But I may have another idea on hand...
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: SweetyVD (Visual Designer)

Post by ChrisR »

Hi srod,
Oups, I missed your message, thank you for taking the time to look at, it's an honor :)
The next version uses the WM_PRINT Message, and that's pretty good
But unfortunately it will be only for Windows

I think I've found the right way for the containers... 8)
I think it has a BIG potential
A little GIF to get a little preview on next post
Well, I still have some work to do
Post Reply