3-Phase Button for Dialogs — File Browser

3-PhaseButtonforDialogsv1.0 / 3-PhaseButtonforDialogsv1.0 / 3-phase.mrc

3-phase.mrc — 3.51 KB — Download this file

;------------------------------
;3-Phase Button for dialogs - contr0l
;  --Example of how to make a 3-phase button from an icon control on a dialog.
; Usage: /3-phase
;------------------------------
;FootNotes:
; (Status Variable States)
; -- outbut¹ : this is the state when the mouse is outside of your button area
; -- inbut² : this is the state when the mouse is inside of your button area
; -- clicked³ : this is the state when the button has been clicked
; -- none  : this is the default state the status variable is set to on init
;------------------------------
; (*Note* I'm not sure if anyone has done anything like this before...
;  was just made as an example of one way to go about this.)
; Welcome to feedback, optimization methods, suggestions, flames...
;------------------------------
;[-Alias to open dialog-]
alias 3-phase {
  ;check that dialog isn't already open and open it
  if !$dialog(3-phase) { dialog -m 3-phase 3-phase }
}
;[-Dialog Events-]
on *:dialog:3-phase:*:*: {
  if $devent == init {
    ;on init set a status var to keep track of process.
    set %pb none
    ;set the original picture
    did -g $dname 1 $+(",$scriptdir,b.jpg,")
    ;tracking status
    did -ra $dname 4 Regular
  }
  if $devent == mouse { 
    ;when the user moves his/her mouse anywhere on the dialog ...
    ;check if the cursor is within the area of your "button"
    ; (will be different coordinates for your dialog of course, you'll have to figure them out)
    if $mouse.x isnum 27-74 && $mouse.y isnum 27-74 { 
      ;status check
      if %pb == none || %pb == outbut {
        ;set status var to inbut²
        set %pb inbut
        ;since its in the button area, switch to the hover pic.
        did -g $dname 1 $+(",$scriptdir,b-h.jpg,")
        ;tracking status
        did -ra $dname 4 Reg -> Hover 
      }
    }
    ;if the cursor isnt in the button area...
    else {
      ;status check
      if %pb == inbut {
        ;set status var back to outbut¹
        set %pb outbut
        ;set back to original pic
        did -g $dname 1 $+(",$scriptdir,b.jpg,")
        ;status tracking
        did -ra $dname 4 Hover -> Reg
      }
    }
  }
  ;when user clicks the button
  if $devent == sclick && $did == 1 {
    ;status check
    if %pb == inbut { 
      ;set status var to clicked³
      set %pb clicked
      ;set to clicked pic
      did -g $dname 1 $+(",$scriptdir,b-p.jpg,")
      ;status tracking
      did -ra $dname 4 Hover -> Clicked
      ; * if this were your button, this would be the line to add your /command ... *
    }
  }
  ;after user has clicked.. when the button is released...
  if $devent == uclick { 
    if %pb == clicked {
      ;if mouse is still within button area, set state to hover
      if $mouse.x isnum 27-74 && $mouse.y isnum 27-74 {
        ;set status var to inbut²
        set %pb inbut
        ;set to hover pic
        did -g $dname 1 $+(",$scriptdir,b-h.jpg,")
        ;tracking status
        did -ra $dname 4 Clicked -> Hover 
      }
      else {
        ;set status var to outbut¹
        set %pb outbut
        ;set back to original pic
        did -g $dname 1 $+(",$scriptdir,b.jpg,")
        ;tracking status
        did -ra $dname 4 Clicked -> Reg 
      }
    }
  }
  if $devent == close {
    ;cleanup
    unset %pb 
  }
}
;[-Dialog-]
dialog 3-phase {
  title "3-phase"
  size -1 -1 53 65
  option dbu
  icon 1, 2 2 48 45
  box "", 2, 1 -2 51 51
  box "Status", 3, 1 49 51 16
  text "", 4, 2 56 49 8, center
}
;EOF