/* Guigfx example - Add/Remove example */

signal on halt
signal on break_c

call Init
call CreateApp
call HandleApp
/* never reached */
/***********************************************************************/
Init: procedure expose global.
    l="rmh.library";if ~show("L",l) then;if ~addlib(l,0,-30) then exit
    if AddLibrary("rexxsupport.library","rxmui.library")~=0 then exit
    if ~ReadArgs("FILE") then do
        call PrintFault()
        exit
    end
    if parm.0.flag then global.file=parm.0.value
    else global.file=""
    global.GfxExt=0
    global.GfxLoad=0
    call RxMUIOpt("debugmode showerr")
    return
/***********************************************************************/
HandleApp: procedure expose global.

    ctrl_c=2**12
    do forever
        call NewHandle("app","h",ctrl_c)
        if and(h.signals,ctrl_c)>0 then exit
        select
            when h.event="QUIT" then exit
            otherwise interpret h.event
        end
    end
    /* never reached */
/***********************************************************************/
CreateApp: procedure expose global.

    app.Title="Guigfx example"
    app.Version="$VER: Guigfx example 1.1 (22.1.2001)"
    app.Copyright="©2001, alfie"
    app.Author="alfie"
    app.Description="Guigfx example"
    app.Base="RXMUIEXAMPLE"

    app.SubWindow.0="win"
     win.ID="MAIN"
     win.Title="Guigfx example"
     win.Contents="MGROUP"

      mgroup.0="gfxg"
       gfxg.class="group"
       gfxg.frame="string"
       gfxg.spacing=0
        gfxg.0="gfx1"
         gfx1.class="rectangle"

      mgroup.1=text(info)

      mgroup.2="ctrlg"
       ctrlg.class="group"
       ctrlg.frame="group"
       ctrlg.FrameTitle="Control"
       ctrlg.Columns=2

        ctrlg.0=label("_File")
        ctrlg.1="popf"
         popf.class="popasl"
         popf.string=string("file","f",global.file)

        ctrlg.2=label("ScaleMode")
        ctrlg.3="scalemg"
         scalemg.class="group"
         scalemg.horiz=1
          scalemg.0=Checkmark("sup",0,"u")
          scalemg.1=Label("_Up")
          scalemg.2=hspace(4)
          scalemg.3=Checkmark("sdown",0,"d")
          scalemg.4=Label("_Down")
          scalemg.5=hspace(4)
          scalemg.6=Checkmark("sfree",1,"e")
          scalemg.7=Label("Fr_ee")
          scalemg.8=hspace()
        ctrlg.4=label("Trasparency")
        ctrlg.5="trg"
         trg.class="group"
         trg.horiz=1
          trg.0=Checkmark("tmask",0,"m")
          trg.1=Label("_Mask")
          trg.2=hspace(4)
          trg.3=Checkmark("trgb",0,"r")
          trg.4=Label("_RGB")
          trg.5=hspace(4)
          trg.6="tps"
           tps.class="popstring"
           tps.toggle=1
           tps.string=text("ts","00000000")
           tps.window="tcawin"
            tcawin.class="window"
            tcawin.ID="TWIN"
            tcawin.Title="Adjust trasparency"
            tcawin.Contents="tcawinmg"
             tcawinmg.0="tca"
             tca.class="coloradjust"
             tca.red="00000000"x
             tca.green="00000000"x
             tca.blue="00000000"x
             tcawinmg.1="tcc"
              tcc.class="group"
              tcc.horiz=1
               tcc.0=button("tuse","_Use")
               tcc.1=hspace()
               tcc.2=button("tcancel","_Cancel")
           tps.button="tcf"
            tcf.class="colorfield"
            tcf.InputMode="Relverify"
            tcf.FixWidthTxt="nn"
            tcf.FixHeightTxt="nn"
            tcf.Frame="button"
            tcf.red="00FFFFFF"x
            tcf.green="00000000"x
            tcf.blue="00000000"x
          trg.7=hspace()

    res=NewObj("APPLICATION","APP")
    if res~=0 then exit

    if global.file~="" then call NewFile(global.file)
    else call Info("No file load.")

    call add("app","tcawin")

    call Notify("win","CloseRequest",1,"app","ReturnID","quit")

    call Notify("tcawin","CloseRequest",1,"tps","close",0)
    call Notify("tcancel","pressed",0,"tps","close",0)
    call Notify("tuse","pressed",0,"tps","close",1)
    call notify("tps","success",1,"app","return","call ChangeTrasparentColor()")

    call notify("tmask","selected","everytime","app","return","call ChangeTrasparencyMode()")
    call notify("trgb","selected","everytime","app","return","call ChangeTrasparencyMode()")

    call notify("sup","selected","everytime","app","return","call ChangeScaleMode()")
    call notify("sdown","selected","everytime","app","return","call ChangeScaleMode()")
    call notify("sfree","selected","everytime","app","return","call ChangeScaleMode()")

    call Notify("file","newcontents","everytime","app","Return","call newfile(h.contents)","Contents")

    call set("win","open",1)

    return
/***********************************************************************/
NewFile: procedure expose global.
parse arg file
    say File
    if FilePart(file)="" then return
    call set("app","sleep",1)
    call Info("Reading file '"file"'...")
    call DoMethod("gfxg","InitChanges")
    oname="gfx"||global.GfxExt
    other=~global.GfxExt
    gfx.ScaleMode="SCALEFREE"
    gfx.filename=file
    call RxMUIOpt("")
    res=NewObj("guigfx",oname,"gfx")
    call RxMUIOpt("debugmode showerr")
    if res~=0 then do
        call Info("Can't create Gfx for '"file"'.")
        global.GfxLoad=0
    end
    else do
        call Dispose("gfx"other)
        call Add("gfxg",oname)
        call Info("Gfx for '"file"' created.")
        global.GfxExt=other
        global.GfxName=oname
        call SetNotifies()
        global.GfxLoad=1
    end
    call DoMethod("gfxg","ExitChanges")
    call set("app","sleep",0)
    return
/***********************************************************************/
ChangeTrasparentColor: procedure expose global.
    call getattr("tca","red","r")
    call getattr("tca","green","g")
    call getattr("tca","blue","b")
    t=x2c("00" || left(c2x(r),2) || left(c2x(g),2) || left(c2x(b),2))
    call set("tcf","red",r)
    call set("tcf","green",g)
    call set("tcf","blue",b)
    call set("ts","contents",c2x(t))
    if ~global.GfxLoad then return
    call set("app","sleep",1)
    call set(global.GfxName,"TransparentColor",t)
    call set("app","sleep",0)
    return
/***********************************************************************/
ChangeTrasparencyMode: procedure expose global.
    if ~global.GfxLoad then return
    tmode=""
    call getattr("tmask","selected","m")
    if m then tmode=tmode||" MASK"
    call getattr("trgb","selected","m")
    if m then tmode=tmode||" RGB"
    call set(global.GfxName,"Transparency",tmode)
    return
/***********************************************************************/
ChangeScaleMode: procedure expose global.
    if ~global.GfxLoad then return
    smode=""
    call getattr("sup","selected","m")
    if m then smode=smode||" SCALEUP"
    call getattr("sdown","selected","m")
    if m then smode=smode||" SCALEDOWN"
    call getattr("sfree","selected","m")
    if m then smode=smode||" SCALEFREE"
    call DoMethod("gfxg","InitChanges")
    call set(global.GfxName,"ScaleMode",smode)
    call DoMethod("gfxg","ExitChanges")
    return
/***********************************************************************/
SetNotifies: procedure expose global.
    return
/***********************************************************************/
info: procedure expose global.
parse arg msg
    call set("info","contents",msg)
    return
/***********************************************************************/
halt:
break_c:
    exit
/**************************************************************************/

