Les sources du VisualDesigner

Sujets variés concernant le développement en PureBasic
Avatar de l’utilisateur
Ulix
Messages : 315
Inscription : ven. 04/juin/2004 14:27
Localisation : Frontignan

Les sources du VisualDesigner

Message par Ulix »

Savez-vous s'il est possible d'avoir les sources du VisualDesigner de PB ?
Aprés une recherche j'ai vu que ceux de l'éditeur était disponible, mais je n'est pas trouvé pour le Visual ? Sont-il compris avec l'éditeur ?
Merci d'avance :lol:
julien
Messages : 846
Inscription : ven. 30/janv./2004 15:06
Contact :

Message par julien »

va sur ce site et contact Berikco pour savoir si c'est dispo :
http://purebasic.be/
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Message par Backup »

pour ton info Erix14 est en train de nous preparer un bijoux
donc un peut de patience :D
Avatar de l’utilisateur
Ulix
Messages : 315
Inscription : ven. 04/juin/2004 14:27
Localisation : Frontignan

Message par Ulix »

J'ai consulté le site PureBasic.be, les sources ne sont apparemment pas disponible !
Merci quand même :wink:
Patrick88
Messages : 1564
Inscription : mer. 21/janv./2004 18:24

Message par Patrick88 »

les sources, non, par contre on peut trouver l'ébauche...

remarque: le source demande quelque modif, il date un peu...

fichier include: ObjectViewer.pb

Code : Tout sélectionner

;
; Object Viewer
;

Procedure OpenWindow_ObjectViewer()

  If OpenWindow(#WINDOW_ObjectViewer, 10, 300, 200, 200, #PB_Window_SystemMenu, "Objects Viewer")

    CreateGadgetList(WindowID())
    
    TreeGadget(#GADGET_ObjectTree, 10, 10, WindowWidth()-25, WindowHeight()-40)
    
    Result = WindowID()
  EndIf

  ProcedureReturn Result
EndProcedure
le code source promemant dit : auteur ????

Code : Tout sélectionner

; 
; PureBasic Visual Designer
;
;
; 12/11/2001
;   Today, the multi window mode finally works.
; 
; 05/11/2001
;   Continued a bit the work: can move the gadgets and generate a pseudo code
;
; 14/10/2001
;   Added the object viewer tree
;
; 06/10/2001
;   First version
;

;InitGadget(100)

#NbLangageStrings = 5  ; Including the '0'
Dim Langage.s(#NbLangageStrings)

For k=0 To #NbLangageStrings : Read Langage(k) : Next

#WINDOW_Main         = 0
#WINDOW_Properties   = 1
#WINDOW_ObjectViewer = 2 
#WINDOW_PoolStart    = 10

#MENU_Quit           = 0
#MENU_NewWindow      = 1
#MENU_GenerateSource = 2

#GADGET_PropertyCaption = 1
#GADGET_PropertyX       = 2
#GADGET_PropertyY       = 3
#GADGET_PropertyWidth   = 4
#GADGET_PropertyHeight  = 5
#GADGET_ObjectTree      = 6

IncludeFile "ObjectViewer.pb"

Global  UsedCreatedWindow ; Tell which window is being activated.
Global *MemoryBuffer      ; Multi-Purpose memory buffer
Global  SelectMode        ; Can be 0 or 1, indicating if it a gadget or the window which is selected..
Global  CurrentGadgetType ; GadgetType currently selected (Button, StringGadget, CheckBox etc...)

Structure Window
  Address.l
  NumericID.l
  GadgetArea.l
  Flags.l
  Title.s
  x.w
  y.w
  Width.w
  Height.w
  TreePosition.w
  TreeState.b
EndStructure


Structure Gadget
  Address.l
  NumericID.l
  WindowID.l
  Flags.l
  Title.s
  x.w
  y.w
  Width.w
  Height.w
  Type.w
  TreePosition.w
EndStructure


NewList CreatedWindow.Window()
NewList CreatedGadget.Gadget()

DefaultTitle$ = Langage(3)

CurrentGadgetType = 1 ; Default to ButtonGadget

*MemoryBuffer = AllocateMemory(10000)  

If CreateMenu(0,WindowID())
  MenuTitle(Langage(0))
    MenuItem(#MENU_NewWindow     , Langage(2))
    MenuBar()
    MenuItem(#MENU_GenerateSource, Langage(5))
    MenuBar()
    MenuItem(#MENU_Quit          , Langage(1))
EndIf


Procedure BuildObjectTree()

  *CurrentWindow = CreatedWindow()
  *CurrentGadget = CreatedGadget()
  
  ; First, as we rebuilt the whole tree, we memorise the actual window nodes state (expanded or shrinked)
  ;  
  ResetList(CreatedWindow())
  While NextElement(CreatedWindow())
    CreatedWindow()\TreeState = TreeGadgetItemState(#GADGET_ObjectTree, CreatedWindow()\TreePosition)
  Wend

  ; Now we can clear the tree list
  ;  
  ClearGadgetItemList(#GADGET_ObjectTree)

  CurrentPosition = 0

  ResetList(CreatedWindow())
  While NextElement(CreatedWindow())
    AddTreeGadgetItem(#GADGET_ObjectTree, CreatedWindow()\Title, 0)
    CreatedWindow()\TreePosition = CurrentPosition

    FirstTime = 1
    
    ResetList(CreatedGadget())
    While NextElement(CreatedGadget())
      If CreatedGadget()\WindowID = CreatedWindow()\NumericID
        
        If FirstTime : OpenTreeGadgetNode() : FirstTime = 0 : EndIf
        
        AddTreeGadgetItem(#GADGET_ObjectTree, CreatedGadget()\Title, 0)
        
        CurrentPosition+1
        CreatedGadget()\TreePosition = CurrentPosition
      EndIf
    Wend
    
    If FirstTime = 0 : CloseTreeGadgetNode() : EndIf
    
    If CreatedWindow()\TreeState : ExpandTreeGadgetItem(#GADGET_ObjectTree,  CreatedWindow()\TreePosition) : EndIf
    
    CurrentPosition+1
  Wend
  
  ChangeCurrentElement(CreatedWindow(), *CurrentWindow)
  ChangeCurrentElement(CreatedGadget(), *CurrentGadget)
EndProcedure


Procedure OpenWindow_Properties()
  If OpenWindow(#WINDOW_Properties, 10, 100, 200, 200, #PB_Window_SystemMenu, "Properties")
    If CreateGadgetList(WindowID())
    
      GadgetTop    = 10
      GadgetHeight = 20
    
      TextGadget  (0, 10, GadgetTop+2, 100, GadgetHeight, Langage(4))
      StringGadget(#GADGET_PropertyCaption, 60, GadgetTop  , 125, GadgetHeight, "") : GadgetTop+30
      
      TextGadget  (0, 10, GadgetTop+2, 100, GadgetHeight, Langage(4))
      StringGadget(#GADGET_PropertyX, 60, GadgetTop  , 125, GadgetHeight, "") : GadgetTop+30
      
      TextGadget  (0, 10, GadgetTop+2, 100, GadgetHeight, Langage(4))
      StringGadget(#GADGET_PropertyY, 60, GadgetTop  , 125, GadgetHeight, "") : GadgetTop+30
      
      TextGadget  (0, 10, GadgetTop+2, 100, GadgetHeight, Langage(4))
      StringGadget(#GADGET_PropertyWidth, 60, GadgetTop  , 125, GadgetHeight, "") : GadgetTop+30
      
      TextGadget  (0, 10, GadgetTop+2, 100, GadgetHeight, Langage(4))
      StringGadget(#GADGET_PropertyHeight, 60, GadgetTop  , 125, GadgetHeight, "") : GadgetTop+30
    
    EndIf
  EndIf
EndProcedure

DisableDebugger
Procedure UpdateWindowData()
  ResetList(CreatedWindow())
  While (NextElement(CreatedWindow()))
    If CreatedWindow()\NumericID = UsedCreatedWindow
      UseWindow(UsedCreatedWindow)
      GetWindowText_(WindowID(), *MemoryBuffer, 1000)
    
      CreatedWindow()\Title  = PeekS(*MemoryBuffer)
      CreatedWindow()\x      = WindowX()
      CreatedWindow()\y      = WindowY()
      CreatedWindow()\Width  = WindowWidth()
      CreatedWindow()\Height = WindowHeight()
      
      ; Now update the properties
      ;
      SetGadgetText(#GADGET_PropertyCaption, CreatedWindow()\Title)
      SetGadgetText(#GADGET_PropertyX      , Str(CreatedWindow()\x))
      SetGadgetText(#GADGET_PropertyY      , Str(CreatedWindow()\y))
      SetGadgetText(#GADGET_PropertyWidth  , Str(CreatedWindow()\Width))
      SetGadgetText(#GADGET_PropertyHeight , Str(CreatedWindow()\Height))
      
      SelectMode = 0
      
      ProcedureReturn
    EndIf
  Wend
EndProcedure

; This callback is called automatically by Windows when an event occurs.
; We use it to update the size of the statusbar when the user size the window.
; This is useful only when solid mode sizing is used.
;

Procedure WindowCallBack(WindowID, Message, wParam, lParam)

  WindowNumericID = EventWindowID()

  If Message = #WM_ACTIVATE 
    If wParam = #WA_CLICKACTIVE Or wParam = #WA_ACTIVE 
    If WindowNumericID >= #WINDOW_PoolStart
      UsedCreatedWindow = WindowNumericID
      UpdateWindowData()
      SetGadgetState(#GADGET_ObjectTree, 0) ; CreatedWindow()\TreePosition+1)
    Else
      UseWindow(WindowNumericID)
    EndIf
    EndIf
  EndIf
  
  If Message = #WM_MOVE Or Message = #WM_SIZE
    If WindowNumericID >= #WINDOW_PoolStart
      UpdateWindowData()
    EndIf
  EndIf
EndProcedure
EnableDebugger

*StringBase.l

OpenDefaultConsole()


Procedure IsInsideAGadget(x, y)

  ResetList(CreatedGadget())
  While NextElement(CreatedGadget())
    
    If CreatedGadget()\WindowID = CreatedWindow()\NumericID
      If CreatedGadget()\x < x And CreatedGadget()\y < y And CreatedGadget()\x+CreatedGadget()\Width > x  And CreatedGadget()\y+CreatedGadget()\Height > y 
        ProcedureReturn 1
      EndIf
    EndIf    
  Wend
  
  ProcedureReturn 0
EndProcedure


Procedure UpdateGadgetData()

  ; CreatedGadget()\Title  = PeekS(*MemoryBuffer)
  ; CreatedGadget()\x      = WindowX()
  ; CreatedGadget()\y      = WindowY()
  ; CreatedGadget()\Width  = WindowWidth()
  ; CreatedGadget()\Height = WindowHeight()
  
  ; Now update the properties
  ;
  SetGadgetText(#GADGET_PropertyCaption, CreatedGadget()\Title)
  SetGadgetText(#GADGET_PropertyX      , Str(CreatedGadget()\x))
  SetGadgetText(#GADGET_PropertyY      , Str(CreatedGadget()\y))
  SetGadgetText(#GADGET_PropertyWidth  , Str(CreatedGadget()\Width))
  SetGadgetText(#GADGET_PropertyHeight , Str(CreatedGadget()\Height))
  
  SelectMode = 1
  
EndProcedure


#PanelOffsetX = -2
#PanelOffsetY = -23

; Diplay on the current active window the Gadget depending of its type (Button, CheckBox etc...)
;
Procedure DisplaySpecificGadget(GadgetType, x, y, Width, Height, Title$)

  UseGadgetList(CreatedWindow()\GadgetArea)
  
  x-#PanelOffsetX
  y-#PanelOffsetY
  
  Select GadgetType
    Case 1
      *Address = ButtonGadget(10, x, y, Width, Height, Title$)
      
    Case 2
      *Address = StringGadget(10, x, y, Width, Height, Title$)

    Case 3
      *Address = CheckBoxGadget(10, x, y, Width, Height, Title$)

  EndSelect
  
  ProcedureReturn *Address
EndProcedure


Procedure DisplayXORSelection()

  StartPointX = WindowMouseX()+#PanelOffsetX ; Due to window borders (top and left)
  StartPointY = WindowMouseY()+#PanelOffsetY 

  StartDrawing(WindowOutput())
  DrawingMode(7)
    
  SetCapture_(WindowID())
  
  If IsInsideAGadget(StartPointX, StartPointY)
 
    OffsetX = StartPointX-CreatedGadget()\x
    OffsetY = StartPointY-CreatedGadget()\y
 
    Repeat
      Event = WaitWindowEvent()
      
      If Event = #WM_MOUSEMOVE
        
        If Drawed
          Box(PreviousX , PreviousY, CreatedGadget()\Width, CreatedGadget()\Height)
        EndIf
        
        PreviousX = WindowMouseX()+#PanelOffsetX-OffsetX 
        PreviousY = WindowMouseY()+#PanelOffsetY-OffsetY 
        Box(PreviousX , PreviousY, CreatedGadget()\Width , CreatedGadget()\Height)
        Drawed = 1
      EndIf
    Until Event = #WM_LBUTTONUP
    
    If Drawed
      Box(PreviousX , PreviousY, CreatedGadget()\Width, CreatedGadget()\Height)
      
      CreatedGadget()\x        = PreviousX
      CreatedGadget()\y        = PreviousY
      
      DestroyWindow_(CreatedGadget()\Address)
      CreatedGadget()\Address  = DisplaySpecificGadget(CreatedGadget()\Type, PreviousX, PreviousY, CreatedGadget()\Width, CreatedGadget()\Height, CreatedGadget()\Title)
    EndIf

    UpdateGadgetData()
    
  Else
                
    Repeat
      Event = WaitWindowEvent()
      
        If Event = #WM_MOUSEMOVE
          Drawed = 1
          
          Box(StartPointX, StartPointY, PreviousX , PreviousY)
          
          PreviousX = WindowMouseX()-StartPointX-2+#PanelOffsetX
          PreviousY = WindowMouseY()-StartPointY+#PanelOffsetY
          Box(StartPointX, StartPointY, PreviousX , PreviousY)
          
          ; EnableWindow_(*Panel, 0)
          ; ReSizeGadget(21, 0, 0, 10, 10)
        EndIf
    Until Event = #WM_LBUTTONUP
    
    If Drawed
      Box(StartPointX, StartPointY, PreviousX , PreviousY)
      
      If PreviousX > 8 And PreviousY > 8
        AddElement(CreatedGadget())
        CreatedGadget()\WindowID = CreatedWindow()\NumericID
        CreatedGadget()\Title    = ""
        CreatedGadget()\x        = StartPointX
        CreatedGadget()\y        = StartPointY
        CreatedGadget()\Width    = PreviousX
        CreatedGadget()\Height   = PreviousY
        CreatedGadget()\Type     = CurrentGadgetType
        CreatedGadget()\Address  = DisplaySpecificGadget(CurrentGadgetType, StartPointX, StartPointY, PreviousX, PreviousY, CreatedGadget()\Title)
         
        UpdateGadgetData()
            
        BuildObjectTree()
        
        ActivateGadget(#GADGET_PropertyCaption)
        UseWindow(#WINDOW_Properties)
      EndIf
      
    Else
      UpdateWindowData()
    EndIf
        
  EndIf    
  
  ReleaseCapture_()
  StopDrawing()
  
EndProcedure


If OpenWindow(#WINDOW_Main, 300, 120, 300, 85, #PB_Window_SystemMenu, "PureBasic Visual Designer v0.11")
  AttachMenu(0, WindowID())
  
  If CreateGadgetList(WindowID())
    ButtonGadget(1,  10, 10, 50, 25, "But")
    ButtonGadget(2,  60, 10, 50, 25, "Str")
    ButtonGadget(3, 110, 10, 50, 25, "Chk")
  EndIf
  
  OpenWindow_Properties()
  
  OpenWindow_ObjectViewer()
  
  SetWindowCallback(@WindowCallBack())
      
  Repeat
    Event = WaitWindowEvent()
    
    Select Event
      WindowID = EventWindowID()
      
      If WindowID >= #WINDOW_PoolStart
      
        If WindowMouseX() > 0
          If WindowMouseY() > 0
            If Event = #WM_LBUTTONDOWN
              DisplayXORSelection()
            EndIf
          EndIf
        EndIf
      
      EndIf
      
    
      Case #PB_EventMenu
            
        Select EventMenuID()
        
          Case #MENU_NewWindow
            Gosub CreateNewWindow

          Case #MENU_GenerateSource
            Gosub GenerateSource

          Case #MENU_Quit
            Quit = 1  
    
        EndSelect
        

      Case #PB_EventGadget
      
        GadgetID = EventGadgetID()
        
        If EventWindowID() = #WINDOW_Main
          
          Select GadgetID
            Case 1
              CurrentGadgetType = 1
            
            Case 2
              CurrentGadgetType = 2
              
            Case 3
              CurrentGadgetType = 3
            
          EndSelect          
        Else
        
          Select GadgetID
          
            Case #GADGET_PropertyCaption
              If UsedCreatedWindow
                a$ = GetGadgetText(#GADGET_PropertyCaption)
                
                If SelectMode = 0
                  SetWindowText_(UseWindow(UsedCreatedWindow), a$)
                  CreatedWindow()\Title = a$
                Else
                  CreatedGadget()\Title = a$
                  SetWindowText_(CreatedGadget()\Address, a$)
                EndIf
                
                BuildObjectTree()
                ; UseWindow(#WINDOW_Properties)
              EndIf
              
              
            Case #GADGET_ObjectTree
              SelectedItem = GetGadgetState(#GADGET_ObjectTree)
              PrintN(Str(SelectedItem))
              Found = 0
              
              ResetList(CreatedGadget())
              While NextElement(CreatedGadget())
                If CreatedGadget()\TreePosition = SelectedItem
                  SelectMode = 1
                  UpdateGadgetData()
                  Found = 1
                  Goto Skip22
                EndIf
              Wend
              Skip22:
              
              If Found = 0
                ResetList(CreatedWindow())
                While NextElement(CreatedWindow())
                  If CreatedWindow()\TreePosition = SelectedItem
                    SelectMode = 0
                    UsedCreatedWindow = CreatedWindow()\NumericID
                    UpdateWindowData()
                    BringWindowToTop_(CreatedWindow()\Address)
                    Found = 1
                    Goto Skip23
                  EndIf
                Wend
                Skip23:
                
              EndIf
              
          EndSelect
        EndIf  
    
      Case #PB_EventCloseWindow
        
        If WindowID  = #WINDOW_Main
          Quit = 1
        Else
          If WindowID >= #WINDOW_PoolStart
            UsedCreatedWindow = WindowID
            UpdateWindowData()
            DeleteElement(CreatedWindow())
            CloseWindow(WindowID)
          EndIf
        EndIf

    EndSelect
    
  Until Quit = 1
EndIf

End


Procedure GetFreeWindowNumber(StartWindowID)

  DisableDebugger  
  While (UseWindow(StartWindowID) <> 0)
    StartWindowID+1
  Wend
  EnableDebugger
  
  ProcedureReturn StartWindowID
EndProcedure


CreateNewWindow:

  LastElement(CreatedWindow())
  If AddElement(CreatedWindow())
    UsedCreatedWindow = GetFreeWindowNumber(#WINDOW_PoolStart)
    
    Title$ = DefaultTitle$+" ( "+Str(UsedCreatedWindow-#WINDOW_PoolStart)+" )"

    If OpenWindow(UsedCreatedWindow, 120, 200, 300, 300, #PB_Window_SystemMenu | #PB_Window_SizeGadget, Title$)

      CreatedWindow()\NumericID  = UsedCreatedWindow
      CreatedWindow()\Address    = WindowID()

      UpdateWindowData()
      
      CreateGadgetList(WindowID())
      
      CreatedWindow()\GadgetArea = PanelGadget(20, -2, -22, 2000, 2000)
      DisableGadget(20, 1)
      
      BuildObjectTree()
    EndIf
  EndIf
Return


GenerateSource:

  If CreateFile(0, "C:\Generated Source.pb")
    
    WriteStringN("; PB Generated GUI - V0.01")
    WriteStringN(";")
    WriteStringN("")
    
    *CurrentWindow = CreatedWindow()
    *CurrentGadget = CreatedGadget()
    
    WriteStringN("InitGadget(100)")

    ResetList(CreatedWindow())
    While NextElement(CreatedWindow())
    
      WriteStringN("Procedure OpenWindow_1()")
      WriteStringN("  If OpenWindow(0,"+Str(CreatedWindow()\x)+","+Str(CreatedWindow()\y)+","+Str(CreatedWindow()\Width)+","+Str(CreatedWindow()\Height)+",#PB_Window_SystemMenu"+","+Chr(34)+CreatedWindow()\Title+Chr(34)+")")
      WriteStringN("    If CreateGadgetList(WindowID())")

      ResetList(CreatedGadget())
      While NextElement(CreatedGadget())
        If CreatedGadget()\WindowID = CreatedWindow()\NumericID
          WriteStringN("      ButtonGadget(0,"+Str(CreatedGadget()\x)+","+Str(CreatedGadget()\y)+","+Str(CreatedGadget()\Width)+","+Str(CreatedGadget()\Height)+","+Chr(34)+CreatedGadget()\Title+Chr(34)+")")
        EndIf
      Wend
      
      WriteStringN("    EndIf")
      WriteStringN("  EndIf")
      WriteStringN("EndProcedure")
      WriteStringN("")
      WriteStringN("OpenWindow_1()")
      WriteStringN("")
    Wend
    
    WriteStringN("Repeat")
    WriteStringN("  Event = WaitWindowEvent()")
    WriteStringN("Until Event = #PB_EventCloseWindow")
    
    ChangeCurrentElement(CreatedWindow(), *CurrentWindow)
    ChangeCurrentElement(CreatedGadget(), *CurrentGadget)
    
    CloseFile(0)
    
    RunProgram("C:\Generated Source.pb", "", 0)  ; Windows automatically launch a program associated to a file.. Nice :)
  EndIf
Return

DataSection

LangageStrings:

Data.s "File", "Quit", "New Window...", "New Window", "Caption", "Generate Source"
patrick
Avatar de l’utilisateur
Ulix
Messages : 315
Inscription : ven. 04/juin/2004 14:27
Localisation : Frontignan

Message par Ulix »

Merci patrick !

J'ai examiné le code pour le comprendre !
Hélas certaine instruction ont évolués et bien que j'en comprends le sens je n'est pas réussi a faire fonctionné le programme.
Mais ça fait rien, c'est toujours intructif.
Merci encore une fois ! Wink
Répondre