!------------------------------------------------------------------------------!
! Test hilite feature on a Line Plot.
! BUG 1392 - Line feature on raster fails.
! BUG 1714 - highlight feature with VBAR with a different fillColor (Since 3.3.1)
!
! Author:  J. Roush / Neon Ngo
!------------------------------------------------------------------------------!
startmacro/msgid=main hiliteColor["WHITE"] hiliteBgColor["#80808080"] hilite2BgColor["#06808080"]
   switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE
   switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE

   if interAct then
     pipe on
       panel/setup/controls=gc

       gcontrol label  macro "MACRO" AlwaysOpen
       gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
       set gc.main.itemColors {PASS=GREEN,FAIL=RED}
       gcontrol text idtext "Instructions" &
         "1. Click on 'Raster Plot' to enable highlight FEATUREs on both PLOTs. \n&
          2. Should see two vertical bars (VLINE) on both PLOTs with color ^hiliteColor. \n&
          3. The line plot's (DATA) should be highlighted color '^hiliteColor' between the two vertical bars. \n&
          4. The (VBAR) region between the vertical bars should be filled in color ^hiliteBgColor for line plot and ^hilite2BgColor for raster plot. \n&
          5. Move the mouse around the 'Line Plot' to move the center frequency of the plot. \n&
          6. The highlighted area should stay between the two vertical selection bars. \n&
          7. Click on 'Raster Plot' again to move highlight FEATUREs. \n&
          8. Deselect 'Data' and 'VLine' the ^{hiliteColor} shaded part should still appear in the upper plot (Bug 2915)." 24 24 /title

       set sr 1e5
       waveform/rt _wave{ps=32k} shape=sin form=cf elem=1e9 amp=32e3 freq=sr/10 delta=1/sr
       fft/psd/log _wave _waveb nfft=1k

       ! using {CL=8} qualifier as a very fast block thin of the data before it is displayed by the line plotter.
       ! also turn on BStore and DBuffer to reduce flicking
       plot/id=plot1 _waveb{cl=8} cnt=motion|click type=line axis=tf  options=+BStore|+DBuffer

       !feature ,, hilite {NAME=PK,TYPE=DATA|VLINE,COLOR=WHITE,ENABLE=0,X=sr/8,DX=sr/10} plot1 ! orig prior to 3.3.1
       ! Note that for Bug 2915 the Y value needs to be off-screen to show the bug
       feature ,, hilite {NAME=HILITE,TYPE=DATA|VLINE|VBAR,COLOR=^hiliteColor,FILLCOLOR=hiliteBgColor,ENABLE=0,X=sr/8,DX=sr/10,Y=-1000,DY=10} plot1

       set typeList "Data,VLine,VBar"  ! Only show those applicable
       gcontrol menu   featureType     "Type/Flags" "^typeList" "^hilite.type" /toggle /chkbox


       plot/id=plot2 _waveb cnt=click axis=bf
       ! note: fill color on real-time raster need to be a very transparent otherwise it hides the data underneath
       feature ,, hilite2 {NAME=HILITERASTER,TYPE=VLINE|VBAR,COLOR=^hiliteColor,FILLCOLOR=^hilite2BgColor,ENABLE=0,X=sr/8,DX=sr/10} plot2

     pipe off
   endif

endmacro

!****************************************************************************!
! This is the callback procedure that is automatically called by NeXtMidas
! when there is a (targeted or automatic) message (msg) to send to this macro.
! See the Users's Guide ->Macros ->Messages in Macros section for more details
procedure processMessage m:msg
  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: User indicated tests" msg.data eqss "PASS"
    pipe stop

  elseif msg.fid eqss "PLOT" then
    set fid msg.fid
    if msg.fid eqs "PLOT1"
      set toid "PLOT2"
    else
      set toid "PLOT1"
    endif
    if msg.name eqs "MARK" or msg.name eqs "POINTER" then
      if msg.fid eqs "PLOT2"
        set hilite.x msg.data.x
        set hilite.enable 0x1
        set hilite2.x msg.data.x
        set hilite2.enable 0x1
      endif
      set reg.waveform.freq msg.data.x
    elseif msg.name eqs "ZOOM" then
      set msg.name "ZOOMX"
      message pass ^toid msg
    elseif msg.name eqs "UNZOOM" then
      message pass ^toid msg
    elseif msg.name eqs "PANXY" then
      pause 0.2
      message prune ,, msg
      set msg.name "PANX"
      message pass ^toid msg
    elseif msg.name eqs "PANX" then
      message pass ^toid msg
    endif
  elseif msg.name eqs "FEATURETYPE" then
    set hilite.type "^gc.featureType.value"
  else
    ! say "Unhandled message ^msg.name from ^msg.fid"
  endif
return
