Page 1 of 1

Gadgets, and more gadgets - All OS

Posted: Sat Feb 11, 2017 6:03 pm
by minimy
Buton, Toggle and slidebar based on canvas and small 'circus' animation :mrgreen: . List is only half part.
If some body want improve or modify is free to do.
I hope be of interest.
Greetings!

Code: Select all

; ========================d===========================
; Proyecto: Interfaz 2017-a
; Autor: Toni 2016-2017 ©
; Versión: a
; Botónes y deslizadores basados en canvas + vector
; ====================================================

Procedure Wait(milisec.l)
  Protected mils.l=0
  Repeat: WindowEvent():Delay(1):mils+1 :Until mils>milisec
EndProcedure

;{ constantes
Enumeration 0 ;Tipos de gadgets
  #TypeEx_CountRound
  #TypeEx_Button
  #TypeEx_Toggle
  #TypeEx_SlideBar
  #TypeEx_List
EndEnumeration
Enumeration 0 ;flags procedures
  ;DrawCircleProgreso
  #Tx_DCP_Integer
  #Tx_DCP_Time
EndEnumeration
Enumeration 0 ;flags gadgets
  ;TypeEx_CountRound
  #Tx_CR_Normal
  #Tx_CR_Shadow
  #Tx_CR_ShadowPaper
  #Tx_CR_Paper
  ;TypeEx_Boton
EndEnumeration
Enumeration 0 ;flags fields
  ;TypeEx_List
  #Tx_Field_Texto
  #Tx_Field_Boton
  #Tx_Field_Toggle
  #Tx_Field_CountRound
  #Tx_Field_Image
EndEnumeration
;}

;{ Interfaz
Structure interfaz_campos
  x.i
  y.i
  w.i
  h.i
  tx.s
  state.d
  type.b
EndStructure
Structure interfaz_objetos
  state.d
  List field.interfaz_campos()
EndStructure
Structure interfaz_gadgets
  gadget.l
  type.b
  ti.l
  pa.l
  grosor.d
  tx.s
  state.d
  maxim.d
  activo.b
  flags.b
  extra.b
  objh.b
  objmargen.b
  nowoverobj.d
  nowoverfield.d
  posy.d
  List obj.interfaz_objetos()
EndStructure
Structure interfaz_interface
  window.l
  papel.l
  tinta.l
  font.l
  nowover.l
  anim.b
  List gadget.interfaz_gadgets()
EndStructure
Global Interfaz.Interfaz_interface
Interfaz\window = $ff333333
Interfaz\tinta  = $ffffaaaa
Interfaz\papel  = $ff550000

Interfaz\window = $ffffffff ;blanco
Interfaz\tinta  = $ffff0000
Interfaz\papel  = $ff0000ff

; Interfaz\window = $ff333333 ;oscuro
; Interfaz\tinta  = $ffffaa00
; Interfaz\papel  = $ff00aaff

Interfaz\nowover = -1
Interfaz\font = LoadFont(#PB_Any,"Arial",10,#PB_Font_Bold)
;}

Procedure DrawCircleProgreso(progreso.d,txt.s,color.l=$ffff00ff,fondo.l=$ff444444,grosor.i=50,x.d=0,y.d=0,r.d=0,font.l=0,tipodato.b=0,maximo.d=360,flags.b=0)
  ;tipodato #Tx_DCP_Integer=Entero, #Tx_DCP_Time=Tiempo
    If grosor=0:grosor=VectorOutputHeight()/8:EndIf
    If x=0:x=VectorOutputWidth()/2:EndIf
    If y=0:y=VectorOutputHeight()/2:EndIf
    If r=0:r=VectorOutputHeight()/2-(grosor/2):EndIf
    Protected palo.i=360/24
    ;fondo
    VectorSourceColor(fondo)
    FillVectorOutput()
    ;sombra
    If flags>0 And flags<3
      AddPathCircle(x, y, r, 0, 360)
      VectorSourceColor(RGBA(Red(color),Green(color),Blue(color),50))
      StrokePath(grosor,#PB_Path_RoundEnd)
      FillPath()
    EndIf
    ;papel
    If flags>1
      AddPathCircle(x, y, r*0.8, 0, 360)
;       VectorSourceColor(papel)
      VectorSourceColor(RGBA(Red(color),Green(color),Blue(color),50))
;       StrokePath(r-5,#PB_Path_RoundEnd)
      FillPath()
    EndIf
    ;circulo
    If progreso>0
    Protected np.d = (360*progreso)/maximo
    AddPathCircle(x, y, r, -90, np-90)
    VectorSourceColor(color)
    DotPath(10,12,#PB_Path_RoundEnd,6)
    StrokePath(grosor,#PB_Path_RoundEnd)
    ResetPath()
    Else
      VectorSourceColor(color)
    EndIf
    ;texto
    Protected vt$ = StrD(progreso),borrafont.b=0
    If tipodato=#Tx_DCP_Time:vt$=FormatDate("%hh:%ii:%ss",progreso):EndIf
    If font=-1
      borrafont=1
      font = LoadFont(#PB_Any,"Arial",14,#PB_Font_HighQuality)
    EndIf
    VectorFont(FontID(font))
    Protected nx.d=x-(VectorTextWidth(vt$)/2)
    Protected ny.d=y-(VectorTextHeight(vt$)/2)
    If txt
      Protected nxt.d=x-(VectorTextWidth(txt)/2)
      MovePathCursor(nxt,ny-(VectorTextHeight(txt)/2))
      DrawVectorText(txt)
      FillPath()
      MovePathCursor(nx,ny+(VectorTextHeight(txt)/2))
      DrawVectorText(vt$)
      FillPath()
    Else
      MovePathCursor(nx,ny)
      DrawVectorText(vt$)
      FillPath()
    EndIf
    
    If borrafont:FreeFont(font):EndIf

EndProcedure
Procedure Ex_DrawGadget(gadget.l=-1)
  Protected ti.l,pa.l
  If gadget>-1
    ForEach Interfaz\gadget()
      If gadget=Interfaz\gadget()\gadget
        Break
      EndIf
    Next
  EndIf
  If StartVectorDrawing(CanvasVectorOutput(Interfaz\gadget()\gadget))
    Select Interfaz\gadget()\type
      Case #TypeEx_CountRound
        DrawCircleProgreso(Interfaz\gadget()\state, Interfaz\gadget()\tx,Interfaz\gadget()\ti,Interfaz\window,Interfaz\gadget()\grosor,0,0,0,Interfaz\font,Interfaz\gadget()\extra,Interfaz\gadget()\maxim,Interfaz\gadget()\flags)
        
      Case #TypeEx_Button, #TypeEx_Toggle
        If Interfaz\gadget()\state
          ti=Interfaz\gadget()\pa
          pa=Interfaz\gadget()\ti
        Else
          ti=Interfaz\gadget()\ti
          pa=Interfaz\gadget()\pa
        EndIf
        ;fondo
        VectorSourceColor(Interfaz\window)
        FillVectorOutput()
        FillPath()
        ;centro
        VectorSourceColor(RGBA(Red(ti),Green(ti),Blue(ti),50))
        AddPathBox(3, 3, VectorOutputWidth()-6, VectorOutputHeight()-6)
        FillPath()
        ;borde
        If Interfaz\nowover=Interfaz\gadget()\gadget
        VectorSourceColor(RGBA(Red(ti),Green(ti),Blue(ti),250))
;         AddPathBox(1, 1, VectorOutputWidth()-2, VectorOutputHeight()-2)
;         DotPath(10,20,#PB_Path_SquareEnd,Interfaz\anim)
        AddPathBox(5, 5, VectorOutputWidth()-10, VectorOutputHeight()-10)
        DotPath(5,10,#PB_Path_RoundEnd,Interfaz\anim)
        StrokePath(2)
        FillPath()
        EndIf
        ;texto
        VectorFont(FontID(Interfaz\font))
        MovePathCursor((VectorOutputWidth()-VectorTextWidth(Interfaz\gadget()\tx))/2, (VectorOutputHeight()-VectorTextHeight(Interfaz\gadget()\tx))/2)
        AddPathText(Interfaz\gadget()\tx);+" "+Str(Interfaz\gadget()\state))
        VectorSourceColor(ti)
        FillPath()
        
      Case #TypeEx_SlideBar
          ti=Interfaz\tinta
          pa=Interfaz\papel
;         If Interfaz\gadget()\gadget=Interfaz\nowover
;           ti=Interfaz\papel
;           pa=Interfaz\tinta
;         Else
;           ti=Interfaz\tinta
;           pa=Interfaz\papel
;         EndIf
        ;fondo
        VectorSourceColor(Interfaz\window)
        FillVectorOutput()
        FillPath()
        ;centro
        VectorSourceColor(RGBA(Red(ti),Green(ti),Blue(ti),50))
        AddPathBox(3, 3, VectorOutputWidth()-6, VectorOutputHeight()-6)
        FillPath()
        ;barra fondo
        VectorSourceColor(Interfaz\window)
        la=((VectorOutputWidth()-20)*Interfaz\gadget()\state) /Interfaz\gadget()\maxim 
        AddPathBox(10, 10, la, VectorOutputHeight()-20)
;         StrokePath(2)
        FillPath()
        ;barra
        VectorSourceColor(RGBA(Red(pa),Green(pa),Blue(pa),100))
        la=((VectorOutputWidth()-20)*Interfaz\gadget()\state) /Interfaz\gadget()\maxim 
        AddPathBox(10, 10, la, VectorOutputHeight()-20)
;         StrokePath(2)
        FillPath()
        ;borde
        If Interfaz\nowover=Interfaz\gadget()\gadget
        VectorSourceColor(RGBA(Red(ti),Green(ti),Blue(ti),250))
        AddPathBox(5, 5, VectorOutputWidth()-10, VectorOutputHeight()-10)
        DotPath(5,10,#PB_Path_RoundEnd,Interfaz\anim)
        StrokePath(2)
        FillPath()
        EndIf
        ;texto
        VectorFont(FontID(Interfaz\font))
        MovePathCursor((VectorOutputWidth()-VectorTextWidth(Interfaz\gadget()\tx))/2, (VectorOutputHeight()-VectorTextHeight(Interfaz\gadget()\tx))/2)
        AddPathText(Interfaz\gadget()\tx+" "+Str(Interfaz\gadget()\state))
        VectorSourceColor(ti)
        FillPath()
        
      Case #TypeEx_List
;         If Interfaz\gadget()\state
;           ti=Interfaz\gadget()\pa
;           pa=Interfaz\gadget()\ti
;         Else
;           ti=Interfaz\gadget()\ti
;           pa=Interfaz\gadget()\pa
;         EndIf
          ti=Interfaz\gadget()\ti
          pa=Interfaz\gadget()\pa
        ;fondo
        VectorSourceColor(Interfaz\window)
        FillVectorOutput()
        FillPath()
        ;centro
        VectorSourceColor(RGBA(Red(ti),Green(ti),Blue(ti),50))
        AddPathBox(3, 3, VectorOutputWidth()-6, VectorOutputHeight()-6)
        FillPath()
        ;objetos
        y=Interfaz\gadget()\objmargen + Interfaz\gadget()\posy
        ForEach Interfaz\gadget()\obj()
          VectorSourceColor(Interfaz\window)
          AddPathBox(Interfaz\gadget()\objmargen, y, VectorOutputWidth()-(Interfaz\gadget()\objmargen*2), Interfaz\gadget()\objh)
          FillPath()
          ;campos del objeto
          ForEach Interfaz\gadget()\obj()\field()
            fx.i=Interfaz\gadget()\obj()\field()\x + Interfaz\gadget()\objmargen
            fy.i=Interfaz\gadget()\obj()\field()\y + y
            fw.i=Interfaz\gadget()\obj()\field()\w
            fh.i=Interfaz\gadget()\obj()\field()\h
            ft.s=Interfaz\gadget()\obj()\field()\tx
            ;borra fondo
            VectorSourceColor(Interfaz\window)
            AddPathBox(fx, fy, fw, fh)
            FillPath()
            ;papel
            If Interfaz\gadget()\obj()\field()\type <> #Tx_Field_Texto
              If Interfaz\gadget()\obj()\field()\state
                VectorSourceColor(RGBA(Red(pa),Green(pa),Blue(pa),50))
              Else
                VectorSourceColor(RGBA(Red(ti),Green(ti),Blue(ti),50))
              EndIf
              AddPathBox(fx, fy, fw, fh)
              FillPath()
            EndIf
            ;texto
            VectorFont(FontID(Interfaz\font))
            MovePathCursor((fw-VectorTextWidth(ft))/2+fx, (fh-VectorTextHeight(ft))/2+fy )
            AddPathText(ft);+" "+Str(Interfaz\gadget()\state))
            If Interfaz\gadget()\obj()\field()\state
              VectorSourceColor(Interfaz\papel)
            Else
              VectorSourceColor(Interfaz\tinta)
            EndIf
            FillPath()
            ;borde campo
            If Interfaz\gadget()\nowoverobj = ListIndex(Interfaz\gadget()\obj()) And Interfaz\gadget()\nowoverfield = ListIndex(Interfaz\gadget()\obj()\field())
              If Interfaz\gadget()\obj()\field()\state
                VectorSourceColor(Interfaz\papel)
              Else
                VectorSourceColor(Interfaz\tinta)
              EndIf  
              AddPathBox(fx, fy, fw, fh)
              DotPath(5,10,#PB_Path_RoundEnd,Interfaz\anim)
              StrokePath(2)
              FillPath()
            EndIf
          Next
          ;objeto seleccionado
          If Interfaz\gadget()\obj()\state
            VectorSourceColor(Interfaz\papel)
            AddPathBox(Interfaz\gadget()\objmargen, y, VectorOutputWidth()-(Interfaz\gadget()\objmargen*2), Interfaz\gadget()\objh)
;             DotPath(5,10,#PB_Path_RoundEnd,Interfaz\anim)
            StrokePath(1)
            FillPath()
          EndIf
          ;borde obj
          If Interfaz\gadget()\nowoverobj=ListIndex(Interfaz\gadget()\obj()) And Interfaz\gadget()\nowoverfield=-1
;             VectorSourceColor(RGBA(Red(ti),Green(ti),Blue(ti),250))
            If Interfaz\gadget()\obj()\state
              VectorSourceColor(Interfaz\papel)
            Else
              VectorSourceColor(Interfaz\tinta)
            EndIf  
            AddPathBox(Interfaz\gadget()\objmargen, y, VectorOutputWidth()-(Interfaz\gadget()\objmargen*2), Interfaz\gadget()\objh)
            DotPath(5,10,#PB_Path_RoundEnd,Interfaz\anim)
            StrokePath(2)
            FillPath()
          EndIf
          
          y+Interfaz\gadget()\objh+5
        Next
        
    EndSelect
;     Debug Interfaz\gadget()\type
    StopVectorDrawing()
  EndIf
  
EndProcedure
Procedure Ex_Gadget(gadget.l,tyoe.i,x.i,y.i,w.i,h.i,tx.s,ti.l,pa.l,grosor.d=0,state.d=0,maxim.d=100,flags.b=0,extra.b=0)
  If gadget=#PB_Any
    gadget = CanvasGadget(#PB_Any,x,y,w,h)
  Else
    CanvasGadget(gadget,x,y,w,h)
  EndIf
  
  AddElement(Interfaz\gadget())
  Interfaz\gadget()\gadget=gadget
  Interfaz\gadget()\type=tyoe
  Interfaz\gadget()\ti=ti
  Interfaz\gadget()\pa=pa
  
  Interfaz\gadget()\tx=tx
  
  Interfaz\gadget()\grosor = grosor
  Interfaz\gadget()\state = state
  Interfaz\gadget()\maxim = maxim
  Interfaz\gadget()\flags = flags
  Interfaz\gadget()\extra = extra
  
  Interfaz\nowover =-1
  Interfaz\gadget()\nowoverobj  =-1
  Interfaz\gadget()\nowoverfield=-1
  
  Interfaz\gadget()\objh=60 ;alto del objeto
  Interfaz\gadget()\objmargen=10 ;margen del objeto con respecto a la lista
  Ex_DrawGadget()
  
  ProcedureReturn Gadget
EndProcedure
Procedure Ex_AddObj(gadget.l=-1,state.b=0)
  ;añade objeto a la lista
  If gadget>-1
    ForEach Interfaz\gadget()
      If gadget=Interfaz\gadget()\gadget
        Break
      EndIf
    Next
  EndIf
  AddElement(Interfaz\gadget()\obj())
  Interfaz\gadget()\obj()\state=state
EndProcedure
Procedure Ex_AddField(gadget.l,obj.i,x.i,y.i,w.i,h.i,tx.s,state.d=0,type.b=0)
  ;añade campo a la lista
  Protected found.b
  If gadget>-1
    ForEach Interfaz\gadget()
      If gadget=Interfaz\gadget()\gadget
        found=1
        Break
      EndIf
    Next
  EndIf
  If found
    Debug "add"
    If obj>-1
      SelectElement(Interfaz\gadget()\obj(),obj)
    Else
      LastElement(Interfaz\gadget()\obj())
    EndIf
    AddElement(Interfaz\gadget()\obj()\field())
    Interfaz\gadget()\obj()\field()\x=x
    Interfaz\gadget()\obj()\field()\y=y
    Interfaz\gadget()\obj()\field()\w=w
    Interfaz\gadget()\obj()\field()\h=h
    Interfaz\gadget()\obj()\field()\tx=tx
    Interfaz\gadget()\obj()\field()\state=state
    Interfaz\gadget()\obj()\field()\type=type
  EndIf
EndProcedure

Procedure Ex_SetGadgetColor(gadget.l,color.l,papel.b=0)
  ForEach Interfaz\gadget()
    If gadget = Interfaz\gadget()\gadget
      If papel=1
        Interfaz\gadget()\pa=color
        Debug Interfaz\gadget()\tx
      Else
        Interfaz\gadget()\ti=color
      EndIf
      Ex_DrawGadget()
      Break
    EndIf
  Next
EndProcedure
Procedure Ex_SetGadgetState(gadget.l,state.d)
  ForEach Interfaz\gadget()
    If gadget = Interfaz\gadget()\gadget
        Interfaz\gadget()\state=state
      Ex_DrawGadget()
      Break
    EndIf
  Next
EndProcedure

Procedure Ex_EventGadget(EventGadget.l,EventType.l)
  Static push.b,dentro.d
  Protected gadget.l=-1
  Protected x.i,y.i
  
  ForEach Interfaz\gadget()
  If EventGadget = Interfaz\gadget()\gadget
    Select Interfaz\gadget()\type
      Case #TypeEx_Button, #TypeEx_Toggle
        Select EventType
          Case #PB_EventType_MouseEnter
            Interfaz\nowover=Interfaz\gadget()\gadget
            Ex_DrawGadget()
            SetGadgetAttribute(Interfaz\gadget()\gadget,#PB_Canvas_Cursor,#PB_Cursor_Hand)
          Case #PB_EventType_MouseLeave
            Interfaz\nowover=-1
            Ex_DrawGadget()
            push=0
          Case #PB_EventType_LeftButtonDown
            gadget=Interfaz\gadget()\gadget
            Interfaz\gadget()\state =Abs(Interfaz\gadget()\state-1)
            Ex_DrawGadget()
            If Interfaz\gadget()\type=#TypeEx_Button
              Wait(50)
              Interfaz\gadget()\state =Abs(Interfaz\gadget()\state-1)
              Ex_DrawGadget()
            EndIf
          Case #PB_EventType_LeftButtonUp
            push=0
        EndSelect

      Case #TypeEx_SlideBar
        Select EventType
          Case #PB_EventType_MouseEnter
            Interfaz\nowover=Interfaz\gadget()\gadget
            Ex_DrawGadget()
            SetGadgetAttribute(Interfaz\gadget()\gadget,#PB_Canvas_Cursor,#PB_Cursor_Hand)
          Case #PB_EventType_MouseLeave
            Interfaz\nowover=-1
            Ex_DrawGadget()
            push=0
          Case #PB_EventType_LeftButtonDown
            gadget=Interfaz\gadget()\gadget
            push=#TypeEx_SlideBar
            dentro=ListIndex(Interfaz\gadget())
          Case #PB_EventType_LeftButtonUp
            push=0
        EndSelect

      Case #TypeEx_List
        Select EventType
          Case #PB_EventType_MouseEnter
            Interfaz\nowover=Interfaz\gadget()\gadget
            Interfaz\gadget()\nowoverobj=-1
            Interfaz\gadget()\nowoverfield=-1
            Ex_DrawGadget()
            SetGadgetAttribute(Interfaz\gadget()\gadget,#PB_Canvas_Cursor,#PB_Cursor_Hand)
          Case #PB_EventType_MouseLeave
            Interfaz\nowover=-1
            Interfaz\gadget()\nowoverobj=-1
            Interfaz\gadget()\nowoverfield=-1
            Ex_DrawGadget()
            push=0
          Case #PB_EventType_MouseMove
            push=100
          
          Case #PB_EventType_LeftButtonDown
            gadget=Interfaz\gadget()\gadget
            push=#TypeEx_SlideBar
            dentro=ListIndex(Interfaz\gadget())
            x=GetGadgetAttribute(Interfaz\gadget()\gadget,#PB_Canvas_MouseX)
            y=GetGadgetAttribute(Interfaz\gadget()\gadget,#PB_Canvas_MouseY)
            Interfaz\gadget()\nowoverobj=-1
            Interfaz\gadget()\nowoverfield=-1
            ForEach Interfaz\gadget()\obj()
              xx=Interfaz\gadget()\objmargen
              yy=Interfaz\gadget()\objmargen + (ListIndex(Interfaz\gadget()\obj())* interfaz\gadget()\objh) + 5 +Interfaz\gadget()\posy
              If x>xx And x<xx+GadgetWidth(Interfaz\gadget()\gadget)-(Interfaz\gadget()\objmargen*2)
              If y>yy And y<yy+Interfaz\gadget()\objh
                Interfaz\gadget()\nowoverobj=ListIndex(Interfaz\gadget()\obj())
;                 Debug "Objeto "+Str(Interfaz\gadget()\nowoverobj) + "  Campo "+Str(Interfaz\gadget()\nowoverfield)
                
                ForEach Interfaz\gadget()\obj()\field()
                  xxf=xx+Interfaz\gadget()\obj()\field()\x
                  yyf=yy+Interfaz\gadget()\obj()\field()\y
                  If x>xxf And x<xxf+Interfaz\gadget()\obj()\field()\w
                  If y>yyf And y<yyf+Interfaz\gadget()\obj()\field()\h
;                     Debug Interfaz\gadget()\obj()\field()\tx +" "+ Str(Interfaz\gadget()\nowoverfield)
                    Interfaz\gadget()\nowoverfield=ListIndex(Interfaz\gadget()\obj()\field())
                    If Interfaz\gadget()\obj()\field()\type=#Tx_Field_Toggle
                      Interfaz\gadget()\obj()\field()\state= Abs(Interfaz\gadget()\obj()\field()\state-1)
                    EndIf
                  EndIf
                  EndIf
                Next
                
                If Interfaz\gadget()\nowoverfield = -1 And Interfaz\gadget()\nowoverobj > -1
                  Interfaz\gadget()\obj()\state= Abs(Interfaz\gadget()\obj()\state-1)
                  Debug "OBJ "+Str(ListIndex(Interfaz\gadget()\obj()))+"   "+Str(Interfaz\gadget()\obj()\state)
                  Debug "nowoverfield "+Str(Interfaz\gadget()\nowoverfield)+"   nowoverobj "+Str(Interfaz\gadget()\nowoverobj)
                EndIf
              EndIf
              EndIf
            Next
            Ex_DrawGadget()
          Case #PB_EventType_LeftButtonUp
            push=0
            
        Case #PB_EventType_MouseWheel
          pasov=20
          Interfaz\gadget()\posy+(GetGadgetAttribute(Interfaz\gadget()\gadget,#PB_Canvas_WheelDelta)*pasov)
;           Debug Interfaz\gadget()\posy
          If Interfaz\gadget()\posy>0:Interfaz\gadget()\posy=0:EndIf
          If Interfaz\gadget()\posy<0
;             If Ex_List()\listh+Ex_List()\menuh+Interfaz\gadget()\posy < GadgetHeight(Interfaz\gadget()\gadget)
;               Interfaz\gadget()\posy+pasov
;             EndIf
;             top = Ex_List()\listh-(GadgetHeight(Ex_List()\gadget)-Ex_List()\menuh)
;             If Abs(Interfaz\gadget()\posy) > top And top>0
;               Interfaz\gadget()\posy=top *-1
;             EndIf
          EndIf
          push=100

        EndSelect


      EndSelect
      
    Break
  EndIf

  Next
  
  ;sobre objeto o boton de la lista
  If push=100
    x=GetGadgetAttribute(Interfaz\gadget()\gadget,#PB_Canvas_MouseX)
    y=GetGadgetAttribute(Interfaz\gadget()\gadget,#PB_Canvas_MouseY)
    Interfaz\gadget()\nowoverobj=-1
    Interfaz\gadget()\nowoverfield=-1
    ForEach Interfaz\gadget()\obj()
      xx=Interfaz\gadget()\objmargen
      yy=Interfaz\gadget()\objmargen + (ListIndex(Interfaz\gadget()\obj())* interfaz\gadget()\objh) + 5 +Interfaz\gadget()\posy
      If x>xx And x<xx+GadgetWidth(Interfaz\gadget()\gadget)-(Interfaz\gadget()\objmargen*2)
      If y>yy And y<yy+Interfaz\gadget()\objh
        Interfaz\gadget()\nowoverobj=ListIndex(Interfaz\gadget()\obj())
;         Debug "Objeto "+Str(Interfaz\gadget()\nowoverobj) + "  Campo "+Str(Interfaz\gadget()\nowoverfield)
        
        ForEach Interfaz\gadget()\obj()\field()
          xxf=xx+Interfaz\gadget()\obj()\field()\x
          yyf=yy+Interfaz\gadget()\obj()\field()\y
          If x>xxf And x<xxf+Interfaz\gadget()\obj()\field()\w
          If y>yyf And y<yyf+Interfaz\gadget()\obj()\field()\h
            If interfaz\gadget()\obj()\field()\type = #Tx_Field_Toggle
              Interfaz\gadget()\nowoverfield=ListIndex(Interfaz\gadget()\obj()\field())
            EndIf
            Debug Interfaz\gadget()\obj()\field()\tx +" "+ Str(Interfaz\gadget()\nowoverfield)
          EndIf
          EndIf
        Next
        
      EndIf
      EndIf
    Next
    Ex_DrawGadget()
  EndIf
    
  If push=#TypeEx_SlideBar
    SelectElement(Interfaz\gadget(),dentro)
    x=GetGadgetAttribute(Interfaz\gadget()\gadget,#PB_Canvas_MouseX)-2
    Interfaz\gadget()\state = (Interfaz\gadget()\maxim * x) / (GadgetWidth(Interfaz\gadget()\gadget)-4)
    If Interfaz\gadget()\state<0:Interfaz\gadget()\state=0:EndIf
    If Interfaz\gadget()\state>Interfaz\gadget()\maxim:Interfaz\gadget()\state=Interfaz\gadget()\maxim:EndIf
    Ex_DrawGadget()
  EndIf
  ProcedureReturn gadget
EndProcedure

CompilerIf #PB_Compiler_IsMainFile
  If OpenWindow(0, 0, 0, 600, 600, "Gadgets 2017", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    SetWindowColor(0,RGB(Red(Interfaz\window),Green(Interfaz\window),Blue(Interfaz\window)))
    AddWindowTimer(0,0,50)
    
    gadget01 = Ex_Gadget(#PB_Any,#TypeEx_Button,10,120,100,50,"Boton",Interfaz\tinta,Interfaz\papel,0,0,100,0,0)
    gadget02 = Ex_Gadget(#PB_Any,#TypeEx_Toggle,120,120,100,50,"Toggle",Interfaz\tinta,Interfaz\papel,0,0,100,0,0)
    gadget03 = Ex_Gadget(#PB_Any,#TypeEx_SlideBar,230,120,200,50,"SlideBar",Interfaz\tinta,Interfaz\papel,0,50,1000,0,0)
    gadget04 = Ex_Gadget(#PB_Any,#TypeEx_List,10,180,500,400,"Lista",Interfaz\tinta,Interfaz\papel,0,50,1000,0,0)
    ;añade objeto a la lista
    Ex_AddObj(gadget04)
    ;añade campo
    Ex_AddField(gadget04,0,5,5,50,30,"Texto",0,#Tx_Field_Texto)
    Ex_AddField(gadget04,0,60,5,50,30,"Otro",0,0)
    
    Ex_DrawGadget()
    
    gadget1 = Ex_Gadget(  0,#TypeEx_CountRound,10,10,100,100,"Normal",Interfaz\tinta,Interfaz\papel,0,90,100,#Tx_CR_Normal,#Tx_DCP_Time)
    gadget2 = Ex_Gadget(#PB_Any,#TypeEx_CountRound,120,10,100,100,"Sombra",Interfaz\tinta,Interfaz\papel,0,150,200,#Tx_CR_Shadow,#Tx_DCP_Integer)
    gadget3 = Ex_Gadget(#PB_Any,#TypeEx_CountRound,230,10,100,100,"Pa+So",Interfaz\tinta,Interfaz\papel,0,50,200,#Tx_CR_ShadowPaper,#Tx_DCP_Integer)
    gadget4 = Ex_Gadget(#PB_Any,#TypeEx_CountRound,340,10,100,100,"Papel",Interfaz\tinta,Interfaz\papel,0,50,200,#Tx_CR_Paper,#Tx_DCP_Integer)
    
    Repeat
      Event = WindowEvent()
      
      Select Event
       Case #PB_Event_Gadget
         Gadget= EventGadget()
         EventType = EventType()
         
         Select Gadget
           Case gadget1
              
         EndSelect
         
         Ex_EventGadget = Ex_EventGadget(Gadget,EventType)
         Select Ex_EventGadget
           Case gadget01
             Debug "01"
             Ex_SetGadgetColor(gadget1,Interfaz\papel)
             Ex_SetGadgetColor(gadget02,RGBA(255,0,255,255),1)
             Ex_SetGadgetState(gadget02,1)
    ;añade objeto a la lista
    Ex_AddObj(gadget04)
    ;añade campo
    Ex_AddField(gadget04,-1,5,5,50,30,"Texto",0,#Tx_Field_Texto)
    Ex_AddField(gadget04,-1,60,5,50,30,"Toggle",0,#Tx_Field_Toggle)
    Ex_DrawGadget()
          EndSelect
          
       Case #PB_Event_Timer
         If EventTimer()=0
           If Interfaz\nowover>-1
             Ex_DrawGadget(Interfaz\nowover)
             Interfaz\anim-1:If Interfaz\anim<0:Interfaz\anim=20:EndIf
           EndIf
         EndIf
      EndSelect
     
     
      Delay(1)
    Until Event = #PB_Event_CloseWindow
  EndIf
CompilerEndIf



Re: Gadgets, and more gadgets - All OS

Posted: Sat Feb 11, 2017 9:54 pm
by davido
@minimy,

Very nice, thank you for sharing. :D

After replacing .l with .i it ran on my MacBook Pro, PureBasic 5.50 x64.

Re: Gadgets, and more gadgets - All OS

Posted: Sat Feb 11, 2017 10:14 pm
by #NULL
very cool :)
just one issue: if you add some entries via 'Boton' and then scroll down with the mousewheel the toggle button within the entries gets a mouseover at a wrong y-offset.

Re: Gadgets, and more gadgets - All OS

Posted: Sun Feb 12, 2017 3:07 pm
by minimy
#NULL wrote:very cool :)
just one issue: if you add some entries via 'Boton' and then scroll down with the mousewheel the toggle button within the entries gets a mouseover at a wrong y-offset.
Hi #Null, yes i know. Is not finished. You are free to modify, add or change this code. It was only and idea about anim gadgets.
Greetings!

Re: Gadgets, and more gadgets - All OS

Posted: Tue Feb 14, 2017 12:33 pm
by Wolfram
On OSX x64 I have to change the type from long to integer.
I don't know how it works on other Systems but on OSX all gadget variables have to be integer.

Re: Gadgets, and more gadgets - All OS

Posted: Wed Feb 15, 2017 10:15 am
by Bisonte
Wolfram wrote:On OSX x64 I have to change the type from long to integer.
I don't know how it works on other Systems but on OSX all gadget variables have to be integer.
All OS handles have to be integer... on x64 !
The OS is not important...

Re: Gadgets, and more gadgets - All OS

Posted: Wed Feb 15, 2017 10:57 am
by ts-soft
Bisonte wrote:All OS handles have to be integer... on x64 !
Not only on x64, ever!

Re: Gadgets, and more gadgets - All OS

Posted: Wed Feb 15, 2017 12:05 pm
by Kwai chang caine
Really nice, pro effect :shock:
Thanks for sharing 8)

Re: Gadgets, and more gadgets - All OS

Posted: Fri Feb 17, 2017 11:29 pm
by minimy
Thanks @Kwai chang caine, @bisonte and @wolfram, i learn a lot in PBforum and is time to share a little.
My code is not very good, but the idea i think is interesting. Position fields in objects from list, , etc.

I dont know that. I go to change long to integer because you know better me. Windows use integer too?, or only gadgets?
@ts-sodt: Not only on x64, ever!
@ts-sodt thanks for lessons master!
You will never go to bed without learning something new! :mrgreen: Not sir! not in PBforum! :mrgreen:
Any way, the code needs a good debugging. Feel free to change or modify and how not, share later.. :wink:
Greetings!