Resize Window Message and MUI
  • Butterfly
    Butterfly
    rebraist
    Posts: 96 from 2011/4/6
    From: Naples, Italy
    Hi!
    I would like to react to a window change size message (i think IDCMP_NEWSIZE) with mui.
    I looked about
    MUIM_Window_AddEventHandler
    but it wants objects and classes.
    Let's say i want to make it in plain C.
    Without using classes.
    Is there any way?
    Thnx
    Mac Mini g4 1,5 mos 3.1 registered
    Powerbook g4 1,67 mos 3.1 unregistered
    Sam440 Os4.1.6
    Aros-Aros-Aros.
  • »22.10.11 - 22:57
    Profile
  • Moderator
    Kronos
    Posts: 2240 from 2003/2/24
    If you want to make it a MUI app you should use the MUI way of doing things.....

    1st thing you need (for pretty much anything MUI) is atleast 1 costum class were you can add methods and attributes.

    Lets assume you did that to your application-class:

    DoMethod(win,MUIM_Notify,MUIA_Window_Height,MUIV_Everytime,_app(win),2,MM_NewHeight,MUIV_TriggerValue);
    DoMethod(win,MUIM_Notify,MUIA_Window_Width,MUIV_Everytime,_app(win),2,MM_NewWidth,MUIV_TriggerValue);

    MM_NewHeight and MM_NewWidth would be methods you added to your costum application-object.
  • »23.10.11 - 08:17
    Profile
  • Butterfly
    Butterfly
    rebraist
    Posts: 96 from 2011/4/6
    From: Naples, Italy
    thank you!!
    before of posting my question i had tried
    DoMethod(window,MUIM_Notify,MUIA_Window_Width,MUIV_EveryTime, (iptr)app, 2, MUIM_Application_ReturnID, ID_REDRAW);
    ID_REDRAW was a simple printf("\nwidth changed");
    but it never entered in that CASE so i thought i had to use event notification method like add event and so on.
    I'll try the custom class way...
    Mac Mini g4 1,5 mos 3.1 registered
    Powerbook g4 1,67 mos 3.1 unregistered
    Sam440 Os4.1.6
    Aros-Aros-Aros.
  • »23.10.11 - 08:43
    Profile
  • Moderator
    Kronos
    Posts: 2240 from 2003/2/24
    Actually that should have worked to (but is considered nasty)......
  • »23.10.11 - 08:50
    Profile
  • MorphOS Developer
    itix
    Posts: 1516 from 2003/2/24
    From: Finland
    Using MUIA_Window_Width/Height to get notified when window dimensions have changed is bad practise.

    In a custom class (don't use Window.mui but some actual UI element) you can overload MUIM_Setup method to find out new window dimensions. It also provides an access to display data (screen, pixel format, UI element dimensions and much more) what can be useful.
    1 + 1 = 3 with very large values of 1
  • »23.10.11 - 09:59
    Profile
  • Butterfly
    Butterfly
    rebraist
    Posts: 96 from 2011/4/6
    From: Naples, Italy
    :)thanx again!!
    Mac Mini g4 1,5 mos 3.1 registered
    Powerbook g4 1,67 mos 3.1 unregistered
    Sam440 Os4.1.6
    Aros-Aros-Aros.
  • »23.10.11 - 10:53
    Profile
  • Butterfly
    Butterfly
    rebraist
    Posts: 96 from 2011/4/6
    From: Naples, Italy
    hi! i made my own class based on class1.c exhample.
    I modified muim_draw to support my drawing function.
    What i don't understand is that it draws my content only on "refresh": resize, when i cover and uncover the window and so on.
    It doesn't draw when i launch the program...
    Mac Mini g4 1,5 mos 3.1 registered
    Powerbook g4 1,67 mos 3.1 unregistered
    Sam440 Os4.1.6
    Aros-Aros-Aros.
  • »04.11.11 - 12:21
    Profile
  • Moderator
    Kronos
    Posts: 2240 from 2003/2/24
    A straight compile of class1.c clearly show the pattern directly after starting (and updates it on every resize), so you've definitly done something wrong here (*doh*)

    Does you drawing functions rely on any (non-MUI) preconditions that might not be fullfilled at that time ?

    You might also add an kprintf("draw\n"); at the very beginning to see if it's realy gets called (don't use naked printf() might lock Intuition).
  • »04.11.11 - 13:08
    Profile
  • Butterfly
    Butterfly
    rebraist
    Posts: 96 from 2011/4/6
    From: Naples, Italy
    hi! sleeping with my cat on my belly (really) i discovered what's going on!
    In mdraw i write on a cairo surface.
    Problem is (at least i think) that i pass to cairo the intuition window pointer "after" mui window has been created in main(trumpet sound).
    So first time mui calls mdraw with cairo stuff, window pointer is NULL.
    Is there a way to force a mdraw in main? At least after window pointer is non NULL, cairo draws something on the fly? A Domethod?
    Is it better to create mui window structure in OM_NEW?

    [ Edited by rebraist 04.11.2011 - 14:12 ]
    Mac Mini g4 1,5 mos 3.1 registered
    Powerbook g4 1,67 mos 3.1 unregistered
    Sam440 Os4.1.6
    Aros-Aros-Aros.
  • »04.11.11 - 14:11
    Profile
  • Fab
  • MorphOS Developer
    Fab
    Posts: 1331 from 2003/6/16
    In OWB, i (re)allocate the cairo surface in MUIM_Show method, according to the area dimension.

    If you need to schedule a redraw operation manually from your program, you can call MUI_Redraw(obj, MADF_DRAWUPDATE); (flag can be different according to your needs).
  • »04.11.11 - 14:26
    Profile Visit Website
  • Moderator
    Kronos
    Posts: 2240 from 2003/2/24
    Well doing the same here (MUI+cairo) and it's really no magic:

    Code:


    static ULONG mSetup(struct IClass *cl,Object *obj,Msg msg)
    {
    struct Data *data = (struct Data*)INST_DATA(cl,obj);
    data->renderbuffer = new RenderBuffer(_screen(obj)->Width,_screen(obj)->Height);
    return DoSuperMethodA(cl,obj,msg);
    }


    DISPATCHER(DisplayClass)
    {
    switch (msg->MethodID)
    {
    ................
    case MUIM_Setup : return(mSetup (cl,obj,(Msg)msg));
    ................
    }
    return(DoSuperMethodA(cl,obj,msg));
    }
    DISPATCHER_END




    Were "RenderBuffer" is a class that encapsultes cairo_surfcae_t, cairo_t and a few other things.

    So now you have a valid cairo-instance before your object is drawn 1st time.

    A few things to add to my unfinished example:
    - I allocate based on the screensize as my MUI-object hasn't a size limit
    - I don't do any errorchecking (still to come)
    - I don't free the RenderBuffer in MUIM_Cleanup which will be triggered everytime the window gets iconified or is move to another screen. Instead I loose a freaking bunch of MBs everytime that happens

    So don't copy this vanilla, just use it as a starting point.

    Edit:

    Yeah, using MUIM_Show and MUIM_Hide instead might also be a good idea


    [ Edited by Kronos 04.11.2011 - 14:34 ]
  • »04.11.11 - 14:29
    Profile
  • Butterfly
    Butterfly
    rebraist
    Posts: 96 from 2011/4/6
    From: Naples, Italy
    thanx to both of you!
    now i've something to study on!!!:)
    Mac Mini g4 1,5 mos 3.1 registered
    Powerbook g4 1,67 mos 3.1 unregistered
    Sam440 Os4.1.6
    Aros-Aros-Aros.
  • »04.11.11 - 15:14
    Profile
  • Butterfly
    Butterfly
    rebraist
    Posts: 96 from 2011/4/6
    From: Naples, Italy
    I have to say i charged setup (and new) with some initialisation then i remembered of the exhistence of muim_notify(shame on me) and now it all works perfectly...
    next question time...
    Mac Mini g4 1,5 mos 3.1 registered
    Powerbook g4 1,67 mos 3.1 unregistered
    Sam440 Os4.1.6
    Aros-Aros-Aros.
  • »07.11.11 - 19:38
    Profile