[AmigaE, MUI] Notifying Coloradjust object
  • Order of the Butterfly
    Order of the Butterfly
    r-tea
    Posts: 306 from 2005/3/27
    From: Poland, Zdzies...
    How to notify Coloradjust Object properly to get proper response?
    I have tried all available InputMode values already: RelVerify, Toggle, Immediate.
    I set notification on Pressed attribute like this"

    Code:
    domethod(ca,[MUIM_Notify, MUIA_Pressed, MUI_TRUE, MUIV_Notify_Self,2,MUIM_CallHook,get_colHook])


    The procedure installed as a hook looks like this:

    Code:

    DEF get_colHook:hook

    PROC get_col()
    get(ca,MUIA_Coloradjust_RGB,[col])
    StringF(rgb,'zh[8]',col)
    set(str_hex, MUIA_String_Contents, rgb)
    set(str_dec, MUIA_String_Contents, rgb)
    WriteF(rgb, 'dn')
    ENDPROC


    And inside the main() procedure:

    .Code:
     installhook(get_colHook, {get_col})


    To simplify things I made all variables global. And everything would be ok for me except the Coloradjust gadget response only when one clicks outside the triangle and outside the thick circle. When I click inside the triangle or onto the thick color ring the notification seems to not work.
    Mac mini G4@1,5GHz silent upgrade + Xerox Phaser 3140 + EPSON Perfection 1240U
    Commodore C64C + 2 x 1541II + Datasette + SD-Box

    I miss draggable screens... and do you? I know I'm in a minority unfortunately.
  • »14.01.17 - 21:06
    Profile
  • Acolyte of the Butterfly
    Acolyte of the Butterfly
    Leif
    Posts: 111 from 2006/5/31
    From: Sweden
    Quote:

    r-tea wrote:
    How to notify Coloradjust Object properly to get proper response?
    I have tried all available InputMode values already: RelVerify, Toggle, Immediate.
    I set notification on Pressed attribute like this"

    Code:
    domethod(ca,[MUIM_Notify, MUIA_Pressed, MUI_TRUE, MUIV_Notify_Self,2,MUIM_CallHook,get_colHook])


    The procedure installed as a hook looks like this:

    Code:

    DEF get_colHook:hook

    PROC get_col()
    get(ca,MUIA_Coloradjust_RGB,[col])
    StringF(rgb,'zh[8]',col)
    set(str_hex, MUIA_String_Contents, rgb)
    set(str_dec, MUIA_String_Contents, rgb)
    WriteF(rgb, 'dn')
    ENDPROC


    And inside the main() procedure:

    .Code:
     installhook(get_colHook, {get_col})


    To simplify things I made all variables global. And everything would be ok for me except the Coloradjust gadget response only when one clicks outside the triangle and outside the thick circle. When I click inside the triangle or onto the thick color ring the notification seems to not work.



    Code:
    get(ca,MUIA_Coloradjust_RGB,[col])


    should be

    Code:
    get(ca,MUIA_Coloradjust_RGB,{col})


    doh

    /Leif


    [ Edited by Leif 15.01.2017 - 13:49 ]
  • »15.01.17 - 12:28
    Profile
  • Order of the Butterfly
    Order of the Butterfly
    igracki
    Posts: 416 from 2003/2/24
    From: Berlin
    Why don't you create a notify on MUIA_ColorAdjust_RGB?

    Code:

    domethod(ca, [MUIM_Notify, MUIA_ColorAdjust_RGB, MUIV_EveryTime, MUIV_Notify_Self, 2, MUIM_CallHook, get_colHook])


    Also better use subclassing, then you can use own methods instead of hooks.
  • »15.01.17 - 13:01
    Profile Visit Website
  • MorphOS Developer
    geit
    Posts: 1049 from 2004/9/23
    Yeah, hooks are more or less obsolete. There were a good idea for hooking into system libraries, but in MUI they were always a bad solution.

    There are a few classes which are not supporting methods, but generally you can use notifications.

    Same goes for lists. Avoid hooks for construct, destruct, sort and co. Just use the methods provided by mui. It is much less work as you dont need to deal with all the shit hooks and code jumps deliver. Just a clean method you receive when something happens and you are done.

    Of course this means subclassing, but it is not as bad as it sounds. once you have a proper source file to subclass something, you can simply use it everywhere and it is a nobrainer.

    Also if you create a fancy subclass in application one you can simply use that as often as you want and even copy it over to other applications of yours.

    Just take a look onto the system settings. The main settings application is just a pile of icons or a list with the settings panels. The panels itself are separate binaries and even inside those panels gui elements come from additional files like the blankers or the usb hardware driver.

    Those panels are also used during system installation as well, so going the mui sub class way is the smart way, even if it at first takes some time to understand.
  • »15.01.17 - 14:08
    Profile
  • Order of the Butterfly
    Order of the Butterfly
    r-tea
    Posts: 306 from 2005/3/27
    From: Poland, Zdzies...
    Quote:

    igracki wrote:
    Why don't you create a notify on MUIA_ColorAdjust_RGB?

    Code:

    domethod(ca, [MUIM_Notify, MUIA_ColorAdjust_RGB, MUIV_EveryTime, MUIV_Notify_Self, 2, MUIM_CallHook, get_colHook])



    Thanks. Now it works with the whole gadget :-)

    Quote:

    igracki wrote:
    Also better use subclassing, then you can use own methods instead of hooks.


    But hooks are better than putting all the handling stuff into MUI's main loop in SELECT CASE ENDSELECT block, and that was the way I did in my very first E/MUI programming attempts :-)

    There's still something wrong in my code. Now the hook is executed each time the color changes, but it allways returns the same color value.
    And I forgot to mention now I use ECX to make use of your Lamp module.
    Mac mini G4@1,5GHz silent upgrade + Xerox Phaser 3140 + EPSON Perfection 1240U
    Commodore C64C + 2 x 1541II + Datasette + SD-Box

    I miss draggable screens... and do you? I know I'm in a minority unfortunately.
  • »15.01.17 - 21:26
    Profile
  • Order of the Butterfly
    Order of the Butterfly
    igracki
    Posts: 416 from 2003/2/24
    From: Berlin
    Quote:

    r-tea wrote:
    Quote:

    igracki wrote:
    Also better use subclassing, then you can use own methods instead of hooks.


    But hooks are better than putting all the handling stuff into MUI's main loop in SELECT CASE ENDSELECT block, and that was the way I did in my very first E/MUI programming attempts :-)

    There's still something wrong in my code. Now the hook is executed each time the color changes, but it allways returns the same color value.
    And I forgot to mention now I use ECX to make use of your Lamp module.




    When using subclassing, the main MUI "loop" looks like this:
    Code:

    DoMethod(app, MUIM_Application_Run)


    Here is an example of how a MUI program in ecx looks like (with my own mui extensions):
    The main source:
    Code:

    OPT PREPROCESS, STACK = 32678 -> SEHR WICHTIG! Sonst gibts Hits, wenn AboutMUI oder meine AboutBox offen war!!!
    OPT EXENAME = 'ofdbMUI'

    MODULE '*mods/myApp' -> APP_NAME, APP_AUTHOR, APP_VER

    MODULE 'dos/dos', 'dos/rdargs'
    MODULE 'muimaster', 'new/muimaster'
    MODULE 'utility/tagitem', 'amigalib/boopsi' -> for doSuperMethodA
    -> my own public modules
    MODULE 'libMUI', 'mccSupport', 'muiSupport'
    MODULE 'myDebug', 'ezRequester'
    MODULE '*mods/lstMovies_mcc', '*mods/winMain_mcc', '*mods/app_mcc'

    -> shell args stuff
    #define ARGS_TEMPLATE 'E-Source/M,VERBOSE/S'

    OBJECT myArgs
    srcs: PTR TO LONG -> the source file(s)
    verbose
    ENDOBJECT

    VERBOSE MACRO IF args.verbose = DOSTRUE THEN 1

    DEF
    rda = NIL: PTR TO rdargs, args: PTR TO myArgs

    PROC main() HANDLE
    DEF app=NIL

    NEW args
    IFN rda := ReadArgs(ARGS_TEMPLATE, args, NIL) THEN Raise("ARGS")

    OpenMuiMasterLib()
    InitClasses 3
    AddNewClass MyApp
    AddNewClass WinMain
    AddNewClass LstMovies

    IF ClassesSetup()
    app := MyAppObject, End
    IFN app THEN Raise("APP")

    set(winMain, MUIA_Window_Open, MUI_TRUE)
    DoMethod(app, MUIM_Application_Run)
    set(winMain, MUIA_Window_Open, FALSE)
    ELSE
    PrintF('ClassesSetup() failed!!!n')
    ENDIF

    EXCEPT DO
    SELECT exception
    CASE "ARGS"; DOSError(NIL)
    CASE "APP" ; PrintF('ERROR: Failed to create Application!n')
    ENDSELECT

    IF rda THEN FreeArgs(rda)
    END args

    IF app THEN MUI_DisposeObject(app)

    ClassesCleanup()
    CloseMuiMasterLib()
    ENDPROC

    In this module I put all methods of all my subclasses, so I need to import only this module:
    Code:

    OPT MODULE, MODNAME='myApp'
    OPT PREPROCESS, EXPORT

    MODULE 'utility/tagitem', 'intuition/classes', 'workbench/workbench'
    MODULE 'libMUI', 'mccSupport', 'muiSupport'

    CONST MUISN_IGRACKI = <put your own mui serial here!>
    CONST TAGBASE_IGRACKI = TAG_USER OR (MUISN_IGRACKI SHL 16)

    -> change these 3 defines
    #define APP_VER '1.0'
    #define APP_NAME 'ofdbMUI' -> CHANGEME
    #define APP_AUTHOR 'Thomas Igracki' -> CHANGEME

    #define APP_VERSION '$VER: ' + APP_NAME + '_' + __TARGET__ + ' ' + APP_VER + ' ' + __AMIGADATE__ + ' by ' + APP_AUTHOR + ''
    #fmtstr APP_COMPILED 'Compiled: s s for s - ECX vs' __DATE__ __TIME__ __TARGET__ ECX_VERSION
    #define APP_COPYRIGHT '(c) 2014'


    #define DOSError(str) PrintFault(IoErr(), IF str THEN str ELSE APP_NAME)

    -> Now all attributes and methods of ALL my subclasses, so every module can access them

    ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    ->>> app_mcc.e: Attributes/Methods <<<<<<<<<<<<<<
    ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    ENUM
    MA_MyApp_Base = TAGBASE_IGRACKI

    ENUM
    MM_MyApp_Base = TAGBASE_IGRACKI,
    MM_MyApp_ShowAbout

    MOBJECT MP_MyApp_ShowAbout, mp_MyApp_ShowAbout
    methodID: LONG
    ENDOBJECT

    ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    ->>> winMain_mcc.e Attributes/Methods <<<<<<<<<<<
    ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    ENUM
    MA_WinMain_Base = TAGBASE_IGRACKI

    ENUM
    MM_WinMain_Base = TAGBASE_IGRACKI,
    MM_WinMain_MenuAction,
    MM_WinMain_Search

    MOBJECT MP_WinMain_Search, mp_WinMain_Search
    methodID: LONG
    ENDOBJECT

    MOBJECT MP_WinMain_MenuAction, mp_WinMain_MenuAction
    methodID: LONG
    itemID : LONG
    ENDOBJECT

    ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    ->>> lstMovies_mcc.e Attributes/Methods <<<<<<<<
    ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    ENUM
    MA_LstMovies_Base = TAGBASE_IGRACKI

    ENUM
    MM_LstMovies_Base = TAGBASE_IGRACKI,
    MM_LstMovies_Search

    MOBJECT MP_LstMovies_Search, mp_LstMovies_Search
    methodID: LONG
    forStr: PTR TO CHAR
    ENDOBJECT

    And a subclass, winMain_mcc.e:
    Code:

    OPT PREPROCESS, MODULE, MODNAME='winMain_mcc'

    MODULE 'exec/libraries', 'exec/lists',
    'mui/muicustomclass', 'muimaster','new/muimaster',
    'intuition/classes','intuition/classusr','intuition/screens','intuition/intuition',
    'utility', 'utility/tagitem',
    'workbench/startup', 'workbench/workbench',
    'amigalib/boopsi', ->
    'dos/dostags'
    ->MODULE 'libraries/asl'

    MODULE 'mui/StringHistory', 'mui/Lamp'

    -> my modules
    MODULE 'myDebug', 'libMUI', 'mccSupport', 'muiSupport', 'MUInames', 'ezRequester'
    MODULE '*myApp', '*lstMovies_mcc'

    /****************************************************************************/
    /* Here is the beginning of our new class... */
    /****************************************************************************/

    /*
    ** This is the instance data for our custom class.
    */

    DEF mcc = NIL: PTR TO mui_customclass
    OBJECT myData
    strip
    strSearch
    butSearch
    lstMovies
    lamp
    ENDOBJECT

    -> the attributes/methods of my subclass are defined in myApp.e, so all modules can access them!
    ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


    -> menu ids
    ENUM
    MEN_PROJECT = 0,
    MEN_PROJECT_ABOUT,
    MEN_PROJECT_ABOUTMUI,
    MEN_PROJECT_QUIT

    -> this macro creates the needed procs/defines:
    -> mccCreateXXX(), mccDeleteXXX(), XXXObject
    DEC_SUBCLASS MUIC_Window, WinMain

    PROC_MNEW winMain
    DEF nd: myData

    D('WinMain: nd = 0x%lxn', nd)
    ->nd := 0
    -> IF (obj := doSuperNewA(cl, obj, [
    IF (obj := DOSUPERNEW(
    MUIA_Window_ID, "MAIN",
    MUIA_Window_Title, APP_NAME,
    MUIA_Window_AppWindow, MUI_TRUE,

    MUIA_Window_Menustrip, nd.strip := MenustripObject,
    Child, MenuObjectT('Project'),
    Child, MyMenuitem('?About...', MEN_PROJECT_ABOUT),
    Child, MyMenuitem('About MUI...', MEN_PROJECT_ABOUTMUI),
    Child, MyMenuitem(NM_BARLABEL, 0),
    Child, MyMenuitem('QQuit', MEN_PROJECT_QUIT),
    End,
    End,

    WindowContents, VGroup,
    Child, HGroup,
    Child, nd.lamp := LampObject, MUIA_Lamp_Type,MUIV_Lamp_Type_Gigantic, End,
    Child, Label2('_Search'),
    Child, nd.strSearch := KeyString('', 128, "s"),
    End,
    Child, nd.butSearch := MakeButton('S_earch'),

    Child, VGroup,
    GroupFrameT('Movies'),
    Child, nd.lstMovies := LstMoviesObject,
    End,
    End,

    End,
    TAG_MORE, INIT_TAGS
    ))
    -> DDELAY(2)
    D('WinMain: obj = 0x%lxn', obj)
    GETDATA -> data := INST_DATA(cl, obj)
    COPYDATA -> copies contents of 'nd' to 'data'

    Notify(doMethodA(data.strip, [MUIM_FindUData, MEN_PROJECT_ABOUTMUI]),
    MUIA_Menuitem_Trigger, MUIV_EveryTime, MUIV_Notify_Application, 2, MUIM_Application_AboutMUI, obj)

    Notify(obj, MUIA_Window_MenuAction,MUIV_EveryTime, obj, 2, MM_WinMain_MenuAction, MUIV_TriggerValue)

    NotifyBut(data.butSearch, obj, 1, MM_WinMain_Search)

    ENDIF
    ENDPROC_MNEW winMain

    PROC_MSET winMain

    GETDATA -> data := INST_DATA(cl, obj)
    ->D('data = 0x%lx, msg = 0x%lxn', data, msg)

    FORTAG INIT_TAGS
    /*
    CASE MUIA_Window_Open
    DDELAY(2)
    DOSUPER
    D('in MUIA_Window_Open, TI_DATA =%ldn', TI_DATA)
    IF TI_DATA = MUI_TRUE
    DDELAY(3)
    ENDIF
    */

    DEFAULT
    ->DebugF('tag.tag = 0x%lx(%s)n', tag.tag, MID2STR(tag.tag))
    NEXTTAG

    ENDPROC_MSET winMain

    PROC_METHOD MM_WinMain_MenuAction, mp_WinMain_MenuAction

    GETDATA -> data := INSTDATA(cl, obj)

    SELECT msg.itemID
    CASE MEN_PROJECT_ABOUT; DoMethod(_app(obj), MM_MyApp_ShowAbout)
    ->CASE MEN_PROJECT_ABOUTMUI; doMethodA(_app(obj), [MUIM_Application_AboutMUI, obj, 0])
    CASE MEN_PROJECT_QUIT; setMuiTrue(obj, MUIA_Window_CloseRequest)
    DEFAULT
    DebugF('itemID = %ldn', msg.itemID)
    ENDSELECT

    ENDPROC_METHOD MM_WinMain_MenuAction, 0

    PROC_METHOD MM_WinMain_Search, MP_WinMain_Search
    GETDATA -> data := INSTDATA(cl, obj)
    ->Okay('Hallo!')
    set(data.lamp, MUIA_Lamp_Color, MUIV_Lamp_Color_Connecting)
    Delay(20)
    set(data.lamp, MUIA_Lamp_Color, MUIV_Lamp_Color_LoadingData)
    Delay(20)
    set(data.lamp, MUIA_Lamp_Color, MUIV_Lamp_Color_Ok)
    Delay(20)
    DoMethod(data.lstMovies, MM_LstMovies_Search, xget(data.strSearch, MUIA_String_Contents))
    ENDPROC_METHOD MM_WinMain_Search, 0

    /*********************************************************************
    ** Here comes the dispatcher for our custom class.
    ** Unknown/unused methods are passed to the superclass immediately.
    **********************************************************************/
    DISPATCHER_TABLE
    DEC_NEW
    DEC_SET
    DEC_METHOD MM_WinMain_MenuAction
    DEC_METHOD MM_WinMain_Search
    /*
    DEFAULT
    D('msg.methodid = 0x%lxn', msg.methodid)
    */
    DISPATCHER_TABLE_END
  • »16.01.17 - 14:04
    Profile Visit Website

  •