Graphic gadgets GG

Share your advanced PureBasic knowledge/code with the community.
User avatar
minimy
Enthusiast
Enthusiast
Posts: 675
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

Graphic gadgets GG

Post by minimy »

This is my first version of graphic gadgets (the draft) i use this in my 3D editor to simplify the number of gadgets and get control over vectors, color and other aspects what need a lot of gadgets to use.
My new versión work with return key to enter numbers or ok in any window.
You can modify for your app, I think is not bad idea to save the number of gadgets in your app.
With gridGadget can have a lot of buttons in only one gadget and vector gadget are 4 in 1 (title and the 3 params).
The code allways work with strings to handle floats and other data, i no detect speed problems.

I use a procedure called Free() to get free number and not use #PB_any, in that way i can handle the ID better. (and avoid any bugs with any old versions of PB in macOS)

To create a gadget use this:
ggAdd(x,y,w,h,txt.s,label.s="",tipo=#GG_button,state=0,min=0,max=100)
Change tipo with another #GG_.... gadget like #GG_Hselect, #GG_Vector or other.

ggAdd(x,y,w,h,txt.s,label.s="",tipo=#GG_GridButton,state=0,min=0,max=100)
where min are columns and max are rows.

Code: Select all

In the code you have the example of this gadgets
b1= ggAdd(10,10,100,30,"Botón","",#GG_button)
t1= ggAdd(110,10,100,30,"Toggle","",#GG_toggle,1)
s1= ggAdd(310,10,200,25,"Texto","String",#GG_String)
v1= ggAdd(10,240,200,25,"Pos","0.00|0,00|0,00|",#GG_Vector)
we pass every field for the vector with this: ,"0.00|0,00|0,00|"

Code: Select all

g1= ggAdd(10,320,200,90,tx,"",#GG_GridButton,0,5,3)
h1= ggAdd(10,40,300,30,"Hselect","Uno|Dos|Tres|Cuatro|Cinco|",#GG_Hselect)
h1= ggAdd(10,80,100,150,"Vselect","Uno|Dos|Tres|Cuatro|Cinco|",#GG_Vselect)
c1= ggAdd(110,80,100,25,"","",#GG_Color,$0000ff)

Is a draft but work. :mrgreen:

Code: Select all


;{ FREE
Enumeration                 ;para usar con free() y con getFileBagId()
#FREE__img
#FREE__spr
#FREE__ttx
#FREE__mes
#FREE__ent
#FREE__mat
#FREE__wav
#FREE__s3D
#FREE__mov
#FREE__fnt
#FREE__joi
#FREE__gad
#FREE__PRE  ;usado para cuando se necesitan numero que nunca se repitan
#FREE__win
EndEnumeration
Procedure   free(tipo.a=#FREE__img)
  Static  img,spr,ttx=100,mes,ent,mat,wav,s3D,mov,fnt,joi,gad, pre
  Static  win
  Select tipo
    Case 0
      img+1: ProcedureReturn img
    Case 1
      spr+1: ProcedureReturn spr
    Case 2
      ttx+1: ProcedureReturn ttx
    Case 3
      mes+1: ProcedureReturn mes
    Case 4
      ent+1: ProcedureReturn ent
    Case 5
      mat+1: ProcedureReturn mat
    Case 6
      wav+1: ProcedureReturn wav
    Case 7
      s3D+1: ProcedureReturn s3D
    Case 8
      mov+1: ProcedureReturn mov
    Case 9
      fnt+1: ProcedureReturn fnt
    Case 10
      joi+1: ProcedureReturn joi
    Case 11
      gad+1: ProcedureReturn gad
    Case 12
      pre+1: ProcedureReturn pre
      
    Case 13
      win+1: ProcedureReturn win
  EndSelect
EndProcedure
;}

Enumeration 1
#GG_button
#GG_toggle
#GG_Hselect
#GG_Vselect
#GG_Vector
#GG_GridButton
#GG_String
#GG_Color
EndEnumeration
Structure gg_color
  fo.l    ;fondo
  t0.l    ;tinta
  p0.l    ;papel
  t1.l    ;tinta on
  p1.l    ;papel on
  t2.l    ;tinta label
  p2.l    ;papel label
  t3.l    ;tinta entrada de texto
  p3.l    ;papel entrada de texto
EndStructure
Structure gg_global Extends gg_color
  win.i
  winReq.i
  conReq.i
  strReq.i
  txtReq.i
  canReq.i
  btnReq.i

  edTipo.b
  edGad.i
  edItem.i
  r.a
  g.a
  b.a
  
  gsel.i
  
  f1.i    ;fuente1
  f2.i    ;fuente2
  f3.i    ;fuente3
EndStructure
Structure gg_data Extends gg_color
  g.i     ;gadget
  g2.i    ;gadget
  tipo.b  ;tipo
  
  state.i
  min.i
  max.i
  
  l.s     ;label
  t.s     ;texto
  f.f     ;float
  i.i     ;int
EndStructure
Global NewList gg.gg_data()
Global gg.gg_global

Procedure.s stringFieldSet(t.s,pos,change.s,s.s="|")
  Protected   p,tc= CountString(t,"|")
  Protected.s t1,t2
  For p= 1 To tc
    t1= StringField(t,p,s)
    If p-1=pos
      t2+change+s
    Else
      t2+StringField(t,p,s)+s
    EndIf
  Next p
  Debug pos
  
  ProcedureReturn t2
EndProcedure

Procedure   ggGet(g)
  ForEach gg()
    If gg()\g= g
      ProcedureReturn gg()\g
    EndIf
  Next
  ProcedureReturn #False
EndProcedure
Procedure   ggIni(window=0)
  gg\win=   window
  gg\winReq=free(#FREE__win)
  gg\conReq=free(#FREE__gad)
  gg\txtReq=free(#FREE__gad)
  gg\strReq=free(#FREE__gad)
  gg\canReq=free(#FREE__gad)
  gg\btnReq=free(#FREE__gad)
  
  
  gg\f1=    free(#FREE__fnt): LoadFont(gg\f1,"Arial",10)
  gg\f2=    free(#FREE__fnt): LoadFont(gg\f2,"Arial",12)
  gg\f3=    free(#FREE__fnt): LoadFont(gg\f3,"Arial",16)
  gg\fo=    $444444
  gg\t0=    $cccccc
  gg\p0=    $555555
;   gg\t1=    $ffffff
;   gg\p1=    $0055ff
  gg\t1=    $ffff00
  gg\p1=    $552200
  gg\t2=    $999999
  gg\p2=    $000000
  gg\t3=    $99ff99
  gg\p3=    $003300
EndProcedure
Procedure   ggDraw()
  Protected.l ti,pa
  Protected.f wc
  Protected.s t
  StartDrawing(CanvasOutput(gg()\g))
  DrawingMode(#PB_2DDrawing_Transparent)
  Box(0,0,OutputWidth(),OutputHeight(), gg()\fo)
  DrawingFont(FontID(gg\f1))
  Select gg()\tipo
    Case #GG_Color
      Box(1,1,OutputWidth()-2,OutputHeight()-2, gg()\state)
      
    Case #GG_GridButton
      w2= OutputWidth()/gg()\min
      tc= OutputHeight()/gg()\max
      p=1
      For y= 0 To gg()\max-1
      For x= 0 To gg()\min-1
        t= StringField(gg()\t,p,"|")
        If gg()\state= p
          Box(x*w2,y*tc,w2-1,tc-1,gg()\p1)
          DrawText( (x*w2)+((w2-TextWidth(t))/2), (y*tc)+((tc-TextHeight(t))/2), t,gg()\t1)
        Else
          Box(x*w2,y*tc,w2-1,tc-1,gg()\p0)
          DrawText( (x*w2)+((w2-TextWidth(t))/2), (y*tc)+((tc-TextHeight(t))/2), t,gg()\t0)
        EndIf
        p+1
      Next x
      Next y
    Case #GG_Vector
;       Box(1,1,OutputWidth()-2,OutputHeight()-2, gg()\p3)
      gg()\min= TextWidth(" "+gg()\t+" ")
      gg()\max= (OutputWidth()-gg()\min) /3
      Box(1,1,gg()\min,OutputHeight()-2, gg()\p2)
      DrawText((gg()\min-TextWidth(gg()\t))/2,(OutputHeight()-TextHeight("kg"))/2,gg()\t,gg()\t2)
      For p=0 To 2
        x= gg()\min+p*gg()\max
        Box(x,1,gg()\max-1,OutputHeight()-2, gg()\p3)
        t= StringField(gg()\l,p+1,"|")
        DrawText(x+((gg()\max-TextWidth(t))/2),(OutputHeight()-TextHeight("kg"))/2, t,gg()\t3)
      Next p
      
    Case #GG_button,#GG_toggle
      ;{
      If gg()\state
        Box(1,1,OutputWidth()-2,OutputHeight()-2, gg()\p1)
        DrawText((OutputWidth()-TextWidth(gg()\t))/2,(OutputHeight()-TextHeight(gg()\t))/2,gg()\t, gg()\t1)
      Else
        Box(1,1,OutputWidth()-2,OutputHeight()-2, gg()\p0)
        DrawText((OutputWidth()-TextWidth(gg()\t))/2,(OutputHeight()-TextHeight(gg()\t))/2,gg()\t, gg()\t0)
      EndIf
      ;}
    Case #GG_Vselect
      ;{
      w2= OutputHeight()-2
      tc= CountString(gg()\l,"|")
      wc= w2/tc
      x=1
      For p= 1 To tc
        If gg()\state= p-1 
          Box(1,x,OutputWidth(),wc-2, gg()\p1)
          DrawText((OutputWidth()-TextWidth(StringField(gg()\l,p,"|")))/2,x+((wc-TextHeight("Kg"))/2), StringField(gg()\l,p,"|"), gg()\t1)
        Else
          Box(1,x,OutputWidth(),wc-2, gg()\p0)
          DrawText((OutputWidth()-TextWidth(StringField(gg()\l,p,"|")))/2,x+((wc-TextHeight("Kg"))/2), StringField(gg()\l,p,"|"), gg()\t0)
        EndIf
        x+wc
      Next p
      ;}
    Case #GG_Hselect
      ;{
      w2= OutputWidth()-2
      tc= CountString(gg()\l,"|")
      wc= w2/tc
      x=  1
      For p= 1 To tc
        ClipOutput(x,1,wc-2,OutputHeight()-2)
        If gg()\state= p-1
          Box(x,1,wc-2,OutputHeight()-2, gg()\p1)
          DrawText(x+((wc-2)-TextWidth( StringField(gg()\l,p,"|") ))/2,(OutputHeight()-TextHeight(gg()\t))/2, StringField(gg()\l,p,"|"), gg()\t1)
        Else
          Box(x,1,wc-2,OutputHeight()-2, gg()\p0)
          DrawText(x+((wc-2)-TextWidth( StringField(gg()\l,p,"|") ))/2,(OutputHeight()-TextHeight(gg()\t))/2, StringField(gg()\l,p,"|"), gg()\t0)
          
        EndIf
        UnclipOutput()
        x+wc
      Next p
      ;}
  EndSelect
  StopDrawing()
EndProcedure
Procedure   ggAdd(x,y,w,h,txt.s,label.s="",tipo=#GG_button,state=0,min=0,max=100)
  ;vi=int, vf=float
  Protected   nw,nh
  If label And tipo<>#GG_Hselect And tipo<>#GG_Vselect
    StartDrawing(WindowOutput(gg\win))
      DrawingFont(FontID(gg\f1))
      nw= TextWidth(" "+label+" ")
      nh= TextHeight(label)
    StopDrawing()
  EndIf  
  
    
  AddElement(gg())
    gg()\fo=    gg\fo
    gg()\p0=    gg\p0
    gg()\p1=    gg\p1
    gg()\p2=    gg\p2
    gg()\p3=    gg\p3
    gg()\t0=    gg\t0
    gg()\t1=    gg\t1
    gg()\t2=    gg\t2
    gg()\t3=    gg\t3
    gg()\t=     txt
    gg()\l=     label
    gg()\i=     vi
    gg()\f=     vf
    gg()\state= state
    gg()\min=   min
    gg()\max=   max
    gg()\tipo=  tipo
  If tipo >=  #GG_String
    gg()\g2= free(#FREE__gad):TextGadget(gg()\g2,x,y,nw,h,label,#PB_Text_Center):SetGadgetFont(gg()\g2,FontID(gg\f1))
    SetGadgetColor(gg()\g2,#PB_Gadget_BackColor,gg()\p2)
    SetGadgetColor(gg()\g2,#PB_Gadget_FrontColor,gg()\t2)
    x+nw:w-nw
  EndIf
  
  If tipo >=  #GG_String
    Select tipo
      Case #GG_String
        gg()\g= free(#FREE__gad):   StringGadget(gg()\g,x,y,w,h,txt,#PB_String_BorderLess)
        SetGadgetColor(gg()\g,#PB_Gadget_BackColor,gg()\p3)
        SetGadgetColor(gg()\g,#PB_Gadget_FrontColor,gg()\t3):SetGadgetFont(gg()\g,FontID(gg\f1))
      Case #GG_Color
        gg()\g= free(#FREE__gad):   CanvasGadget(gg()\g,x,y,w,h);,txt,#PB_String_BorderLess)
        StartDrawing(CanvasOutput(gg()\g))
          Box(0,0,OutputWidth(),OutputHeight(),gg()\fo)
          Box(1,1,OutputWidth()-2,OutputHeight()-2,gg()\state)
        StopDrawing()
;         SetGadgetColor(gg()\g,#PB_Gadget_FrontColor,gg()\t3):SetGadgetFont(gg()\g,FontID(gg\f1))
    EndSelect
  Else
    gg()\g= free(#FREE__gad):   CanvasGadget(gg()\g,x,y,w,h)
    ggDraw()
  EndIf
  ProcedureReturn gg()\g
EndProcedure
Procedure   ggEvent(eg,et)
  Protected.s t
  Protected.f f
  Protected   tc,wc,px,py,n
  Static push
  ;{ gadgets de windows - detección directa - #GG_color
  If EventWindow()= gg\winReq
    Select eg
      Case gg\canReq
        If et= #PB_EventType_LeftButtonDown
          push= 1
        ElseIf et= #PB_EventType_LeftButtonUp
          push= 0
        EndIf
        If push
          px= GetGadgetAttribute(eg,#PB_Canvas_MouseX)
          py= GetGadgetAttribute(eg,#PB_Canvas_MouseY)
          If py<0:py=0:ElseIf py>255:py=255:EndIf
          wc= GadgetWidth(eg)/3:n=px/wc
;           Debug Str(n)+"  "+Str(255-py)
          StartDrawing(CanvasOutput(gg\canReq))
            DrawingMode(#PB_2DDrawing_Transparent):DrawingFont(FontID(gg\f1))
            If px < wc
              ;rojo
              Box(0,0,wc,OutputHeight(),0)
              Box(10,0,wc-20,OutputHeight(),$000088)
              gg\r= 255-py: Box(5,py,wc-10,255,$0000ff)
              Line(5,py,wc-10,1,$ffffff)
            ElseIf px => wc And px < wc*2
              ;verde
              Box(wc,0,wc,OutputHeight(),0)
              Box(10+wc,0,wc-20,OutputHeight(),$008800)
              gg\g= 255-py: Box(5+wc,py,wc-10,255,$00ff00)
              Line(5+wc,py,wc-10,1,$ffffff)
            Else
              ;azul
              Box(wc*2,0,wc,OutputHeight(),0)
              Box(10+wc*2,0,wc-20,OutputHeight(),$880000)
              gg\b= 255-py: Box(5+wc*2,py,wc-10,255,$ff0000)
              Line(5+wc*2,py,wc-10,1,$ffffff)
            EndIf
            DrawText(5,240,Str(gg\r),$ffffff)
            DrawText(5+wc,240,Str(gg\g),$ffffff)
            DrawText(5+wc*2,240,Str(gg\b),$ffffff)
          StopDrawing()
          gg()\state= RGB(gg\r,gg\g,gg\b)
          SetGadgetText( gg\strReq, RSet(Hex(Blue(gg()\state),#PB_Byte),2,"0")+RSet(Hex(Green(gg()\state),#PB_Byte),2,"0")+RSet(Hex(Red(gg()\state),#PB_Byte),2,"0") )
          
          SelectElement(gg(),gg\edGad)
          StartDrawing(CanvasOutput(gg()\g))
            Box(1,1,OutputWidth()-2,OutputHeight()-2,gg()\state)
          StopDrawing()
          SetGadgetColor(gg\txtReq,#PB_Gadget_BackColor,gg()\state)
        EndIf
      
      Case gg\btnReq
        If et= #PB_EventType_LeftButtonUp
          Select gg\edTipo
            Case #GG_Color
              SelectElement(gg(),gg\edGad)
  ;             gg()\l= stringFieldSet(gg()\l,gg\edItem,GetGadgetText(gg\strReq))
              CloseWindow(gg\winReq)
              DisableWindow(gg\win,0)
              ggDraw()
            Case #GG_Vector
              SelectElement(gg(),gg\edGad)
              gg()\l= stringFieldSet(gg()\l,gg\edItem,GetGadgetText(gg\strReq))
              CloseWindow(gg\winReq)
              DisableWindow(gg\win,0)
              ggDraw()
          EndSelect
        EndIf
    EndSelect
  EndIf
  ;}
  
  
  ForEach gg()
    If eg= gg()\g
      Select gg()\tipo
        Case #GG_GridButton
          ;{
          Select et
            Case #PB_EventType_LeftButtonDown
              wc= GadgetWidth(gg()\g)/gg()\min
              tc= GadgetHeight(gg()\g)/gg()\max
              px= GetGadgetAttribute(gg()\g,#PB_Canvas_MouseX) / wc
              py= GetGadgetAttribute(gg()\g,#PB_Canvas_MouseY) / tc
              gg()\state= 1+px+ (py * gg()\min)
              Debug Str(gg()\state)+","+Str(px)+","+Str(py)
              ggDraw()
            Case #PB_EventType_LeftButtonUp
              gg()\state= 0
              ggDraw()
         EndSelect
         ;}
        Case #GG_Color
          ;{ 
          Select et
            Case #PB_EventType_LeftButtonDown
;               tc= ColorRequester(gg()\state,WindowID(gg\win))
;               If tc>-1
;                 gg()\state= tc
;                 ggDraw()
;               EndIf
              OpenWindow(gg\winReq,0,0,100,350,"Color",#PB_Window_BorderLess|#PB_Window_ScreenCentered|#PB_Window_Invisible, WindowID(gg\win))
;               ResizeWindow(gg\winReq,WindowX(gg\win)+GadgetX(gg()\g),WindowY(gg\win)+GadgetY(gg()\g),#PB_Ignore,#PB_Ignore)
              ResizeWindow(gg\winReq,WindowX(gg\win)+GadgetX(gg()\g2),#PB_Ignore,#PB_Ignore,#PB_Ignore)
              SetWindowColor(gg\winReq, 0)
              ContainerGadget(gg\conReq,1,1,WindowWidth(gg\winReq)-2,WindowHeight(gg\winReq)-2,#PB_Container_BorderLess)
                SetGadgetColor(gg\conReq,#PB_Gadget_BackColor,gg\fo)
                TextGadget(gg\txtReq,0,0,WindowWidth(gg\winReq)-2,25," Color"):SetGadgetFont(gg\txtReq,FontID(gg\f2))
                SetGadgetColor(gg\txtReq,#PB_Gadget_BackColor,gg\p1): SetGadgetColor(gg\txtReq,#PB_Gadget_FrontColor,gg\t1)
                CanvasGadget(gg\canReq,5,35,GadgetWidth(gg\conReq)-10,255)
                StartDrawing(CanvasOutput(gg\canReq))
                  Box(0,0,OutputWidth(),OutputHeight(),0)
                StopDrawing()
                t= RSet(Hex(Blue(gg()\state),#PB_Byte),2,"0")+RSet(Hex(Green(gg()\state),#PB_Byte),2,"0")+RSet(Hex(Red(gg()\state),#PB_Byte),2,"0")
                StringGadget(gg\strReq,5,295,GadgetWidth(gg\conReq)-10,20,t,#PB_String_BorderLess)
                SetGadgetColor(gg\strReq,#PB_Gadget_BackColor,gg\p3): SetGadgetColor(gg\strReq,#PB_Gadget_FrontColor,gg\t3)
                CanvasGadget(gg\btnReq,GadgetWidth(gg\conReq)-50,GadgetHeight(gg\conReq)-25,45,20)
                StartDrawing(CanvasOutput(gg\btnReq))
                  DrawingMode(#PB_2DDrawing_Transparent)
                  Box(0,0,OutputWidth(),OutputHeight(),gg\p0)
                  t="OK"
                  DrawText((OutputWidth()-TextWidth(t))/2,(OutputHeight()-TextHeight(t))/2,t,gg\t1)
                StopDrawing()
              CloseGadgetList()
              
;               Debug Str(n)+"  "+Str(255-py)
              StartDrawing(CanvasOutput(gg\canReq))
                wc= OutputWidth()/3:n=px/wc
                DrawingMode(#PB_2DDrawing_Transparent):DrawingFont(FontID(gg\f1))
                ;rojo
                Box(0,0,wc,OutputHeight(),0)
                Box(10,0,wc-20,OutputHeight(),$000088)
                gg\r= Red(gg()\state): Box(5,255-gg\r,wc-10,255,$0000ff)
                Line(5,py,wc-10,1,$ffffff)
                ;verde
                Box(wc,0,wc,OutputHeight(),0)
                Box(10+wc,0,wc-20,OutputHeight(),$008800)
                gg\g= Green(gg()\state): Box(5+wc,255-gg\g,wc-10,255,$00ff00)
                Line(5+wc,py,wc-10,1,$ffffff)
                ;azul
                Box(wc*2,0,wc,OutputHeight(),0)
                Box(10+wc*2,0,wc-20,OutputHeight(),$880000)
                gg\b= Blue(gg()\state): Box(5+wc*2,255-gg\b,wc-10,255,$ff0000)
                Line(5+wc*2,py,wc-10,1,$ffffff)
                DrawText(5,240,Str(gg\r),$ffffff)
                DrawText(5+wc,240,Str(gg\g),$ffffff)
                DrawText(5+wc*2,240,Str(gg\b),$ffffff)
              StopDrawing()
              SetGadgetColor(gg\txtReq,#PB_Gadget_BackColor,gg()\state)
;               Debug Str(gg\r)+","+Str(gg\g)+","+Str(gg\b)
              HideWindow(gg\winReq,0)
              DisableWindow(gg\win,1)
              gg\edGad= ListIndex(gg())
              gg\edItem=gg()\state
              gg\edTipo=gg()\tipo
          EndSelect
          ;}
        Case #GG_String
          If et= #PB_EventType_Focus: SendMessage_(GadgetID(gg()\g),#EM_SETSEL,0,-1): EndIf
        Case #GG_Vector
          ;{
          Select et
            Case #PB_EventType_MouseWheel
              tc= (GetGadgetAttribute(gg()\g,#PB_Canvas_MouseX)-gg()\min)/gg()\max
              If GetAsyncKeyState_(#VK_LSHIFT) & $8000
                f= ValF(StringField(gg()\l,tc+1,"|")) + (GetGadgetAttribute(gg()\g,#PB_Canvas_WheelDelta) * 0.1)
              ElseIf GetAsyncKeyState_(#VK_LCONTROL) & $8000
                f= ValF(StringField(gg()\l,tc+1,"|")) + (GetGadgetAttribute(gg()\g,#PB_Canvas_WheelDelta) * 0.01)
              Else
                f= ValF(StringField(gg()\l,tc+1,"|")) + GetGadgetAttribute(gg()\g,#PB_Canvas_WheelDelta)
              EndIf
              gg()\l= stringFieldSet(gg()\l,tc,StrF(f,2))
              ggDraw()
              ProcedureReturn gg()\g
            Case #PB_EventType_LeftButtonDown
              gg()\state= (GetGadgetAttribute(gg()\g,#PB_Canvas_MouseX)-gg()\min)/gg()\max: ggDraw()
;               resps.s= InputRequester("Input",gg()\t,StringField(gg()\l,gg()\state+1,"|"))
;               gg()\l= stringFieldSet(gg()\l,gg()\state,resps)
              Select gg()\state
                Case 0:t="X"
                Case 1:t="Y"
                Case 2:t="Z"
              EndSelect
              OpenWindow(gg\winReq,0,0,200,85,"Input",#PB_Window_BorderLess|#PB_Window_WindowCentered|#PB_Window_Invisible, WindowID(gg\win))
              ResizeWindow(gg\winReq,WindowX(gg\win)+GadgetX(gg()\g),WindowY(gg\win)+GadgetY(gg()\g),#PB_Ignore,#PB_Ignore)
              SetWindowColor(gg\winReq, 0)
              ContainerGadget(gg\conReq,1,1,WindowWidth(gg\winReq)-2,WindowHeight(gg\winReq)-2,#PB_Container_BorderLess)
                SetGadgetColor(gg\conReq,#PB_Gadget_BackColor,gg\fo)
                TextGadget(gg\txtReq,0,0,WindowWidth(gg\winReq)-2,25," Input - "+gg()\t+" "+t):SetGadgetFont(gg\txtReq,FontID(gg\f2))
                SetGadgetColor(gg\txtReq,#PB_Gadget_BackColor,gg\p1): SetGadgetColor(gg\txtReq,#PB_Gadget_FrontColor,gg\t1)
                StringGadget(gg\strReq,5,35,WindowWidth(gg\winReq)-10,20,StringField(gg()\l,gg()\state+1,"|"),#PB_String_BorderLess):SetGadgetFont(gg\strReq,FontID(gg\f1))
                SetGadgetColor(gg\strReq,#PB_Gadget_BackColor,gg\p3)
                SetGadgetColor(gg\strReq,#PB_Gadget_FrontColor,gg\t3)
                CanvasGadget(gg\btnReq,GadgetWidth(gg\conReq)-80,GadgetHeight(gg\conReq)-25,75,20)
                StartDrawing(CanvasOutput(gg\btnReq))
                  DrawingMode(#PB_2DDrawing_Transparent)
                  Box(0,0,OutputWidth(),OutputHeight(),gg\p0)
                  t="OK"
                  DrawText((OutputWidth()-TextWidth(t))/2,(OutputHeight()-TextHeight(t))/2,t,gg\t1)
                StopDrawing()
              CloseGadgetList()
              HideWindow(gg\winReq,0)
              DisableWindow(gg\win,1)
              gg\edGad= ListIndex(gg())
              gg\edItem=gg()\state
              gg\edTipo=gg()\tipo
              
              ggDraw()
              ProcedureReturn gg()\g
          EndSelect
          ;}
        Case #GG_Vselect
          ;{
          tc= CountString(gg()\l,"|")
          wc= GadgetHeight(gg()\g)/tc
          Select et
            Case #PB_EventType_LeftButtonDown
              gg()\state= GetGadgetAttribute(gg()\g,#PB_Canvas_MouseY)/wc: ggDraw()
              ProcedureReturn gg()\g
          EndSelect
          ;}
        Case #GG_Hselect
          ;{
          tc= CountString(gg()\l,"|")
          wc= GadgetWidth(gg()\g)/tc
          Select et
            Case #PB_EventType_LeftButtonDown
              gg()\state= GetGadgetAttribute(gg()\g,#PB_Canvas_MouseX)/wc: ggDraw()
              ProcedureReturn gg()\g
          EndSelect
          ;}
        Case #GG_toggle
          ;{
          Select et
            Case #PB_EventType_LeftButtonDown
              gg()\state !1: ggDraw()
              ProcedureReturn gg()\g
          EndSelect
          ;}
        Case #GG_button
          ;{
          Select et
            Case #PB_EventType_LeftButtonDown
              gg()\state= 1: ggDraw()
            Case #PB_EventType_LeftButtonUp
              gg()\state= 0: ggDraw()
              ProcedureReturn gg()\g
          EndSelect
          ;}
      EndSelect
      
    EndIf
  Next
EndProcedure

ggIni(0)
OpenWindow(gg\win,0,0,1200,600,"Gadgets Graphics",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
SetWindowColor(gg\win,gg\fo)

b1= ggAdd(10,10,100,30,"Botón","",#GG_button)
t1= ggAdd(110,10,100,30,"Toggle","",#GG_toggle,1)
s1= ggAdd(310,10,200,25,"Texto","String",#GG_String)
v1= ggAdd(10,240,200,25,"Pos","0.00|0,00|0,00|",#GG_Vector)
v2= ggAdd(10,265,200,25,"Rot","0.00|0,00|0,00|",#GG_Vector)
v3= ggAdd(10,290,200,25,"Sca","0.00|0,00|0,00|",#GG_Vector)

tx.s=""
tx= "1|2|3|4|5|"
tx+ "6|7|8|9|10|"
tx+ "11|12|13|14|15|"
g1= ggAdd(10,320,200,90,tx,"",#GG_GridButton,0,5,3)
h1= ggAdd(10,40,300,30,"Hselect","Uno|Dos|Tres|Cuatro|Cinco|",#GG_Hselect)
h1= ggAdd(10,80,100,150,"Vselect","Uno|Dos|Tres|Cuatro|Cinco|",#GG_Vselect)
c1= ggAdd(110,80,100,25,"","",#GG_Color,$0000ff)


Repeat
  event= WindowEvent()
  
  Select event
    Case #PB_Event_Gadget
      eg= EventGadget()
      et= EventType()
      e2= ggEvent(eg,et)
      
      Select e2
        Case g1
          Debug gg()\state
        Case h1
          Debug gg()\state
        Case b1
          Debug "B1"
          
      EndSelect
      
    Case #PB_Event_CloseWindow
      Break
  EndSelect
  
  Delay(1)
ForEver







If translation=Error: reply="Sorry, Im Spanish": Endif
User avatar
idle
Always Here
Always Here
Posts: 6011
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Graphic gadgets GG

Post by idle »

I was wondering how you did that and here it is.
nice.
Post Reply