How to set label and background colour/picture?
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    connor
    Posts: 570 from 2007/7/29
    I want to build a window with a picture and some text below it. I tried the following:


    Code:

    WindowContents, VGroup,
    Child, MUI_NewObject("Dtpic.mui",
    MUIA_Dtpic_Name, "PROGDIR:picture.jpg",
    End,
    Child, ColGroup(3),
    Child, HVSpace,
    Child, var.obj_info = label1("tell me your name"),
    Child, var.obj_string = name(NULL, 128, NULL, 200),
    Child, HVSpace,
    End,
    Child, horiz_line(100),
    Child, ColGroup(2),
    Child, streetname("tell me your street name"),
    Child, var.obj_string = streetname(NULL, 128, NULL, 200),
    End,
    Child, horiz_line(100),
    Child, ColGroup(3),
    Child, HVSpace,
    // MUIA_Text_Contents, ("33c33bMUI33nnis magic"),
    Child, MUIA_Text_Contents, label3("tell me something about
    you"),
    Child, var.obj_string = story(NULL, 128, NULL, 200),
    Child, HVSpace,
    End,
    End,



    I want to change the colours of the labels and window background but do not
    know how. I read MUIA_Font but it is about fonts, not colours. I did not
    find the right part of the documentation. Can someone give me an example
    how to set e.g. the font colour to white or SHINEPEN? And please also a
    nexample for the background colour if it is used differently.

    Instead of embedding the picture I also would like to have it as full window
    background and paint my gadgets onto it. I found out about MUIA_Background
    but to me it looks like I can only choose an existing background but not my
    own image from disk. How can I do that, please?

    Sorry the code formatting looks ugly but whitespaces as spaces and tabs are omitted inside of code brackets.
  • »09.04.13 - 20:23
    Profile
  • Moderator
    Kronos
    Posts: 2236 from 2003/2/24
    Changing backgrounds, fonts and colors is for USERS not for developers, atleast aslong as we talk about standard GUI-elemets.

    What does look o.k. for you could look awfull on a users setup with a different skin (or just a different taste).

    As for the label in your code ("tell me your name"), there are various predefined in mui.h just make sure you use fitting the purpose not just your taste.
  • »09.04.13 - 22:06
    Profile
  • MorphOS Developer
    Krashan
    Posts: 1107 from 2003/6/11
    From: Białystok...
    Kronos is right here. The main principle of MUI is that user decides about backgrounds, colors, fonts, frames and overall appearance. Hacking on this is theoretically possible, but not recommended without a really good reason.

    [ Edited by Krashan 10.04.2013 - 07:53 ]
  • »10.04.13 - 06:52
    Profile Visit Website
  • MorphOS Developer
    itix
    Posts: 1516 from 2003/2/24
    From: Finland
    However, the system and therefore also MUI allows using some predefined pens in the text (i.e. highlighted text). There are examples in Text.mui class documentation how to use different pen in text rendering. Using RGB colour is also possible.

    Using custom background image is possible. I cant check documentation right now but IIRC you use something like "3:PROGDIR:Gfx/Background.png" or something like that. It is documented in MUI.

    If you use custom background then it could be also good idea use custom text colors because otherwise user could be stuck with black text on black background for example. But user defined background and colours are always preferred.

    [ Edited by itix 10.04.2013 - 13:25 ]
    1 + 1 = 3 with very large values of 1
  • »10.04.13 - 10:21
    Profile
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    connor
    Posts: 570 from 2007/7/29
    I'm not asking without a real reason.

    For sure it is all inside MUI documentation ... somewhere. And "somewhere"
    is the problem. I read a lot of documents and yet did not find out about it. I
    googled for example code and did not find it or did not recognise it. MUI documentation is
    not very friendly to starters. It's like throwing someone into the hay and
    saying "the needle is inside". So I am asking for a direct pointer please to
    where to find it or a short example code and I'm asking for a real reason.
  • »11.04.13 - 18:21
    Profile
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    connor
    Posts: 570 from 2007/7/29
    @ itix

    Quote:


    If you use custom background then it could be also good idea use custom text colors because otherwise user could be stuck with black text on black background for example.


    That's exactly the reason why I need to set it on my own.

    Is your comment addressing MUIA_Background? Displaying the image itself works as own object (see the first Child in the quoted code above) but I did not yet succeed to place it as window backdrop. I want to achieve both, anyway. Having it as single gadget and the others like string gadgets or radio buttons around it (which works more or less, have to get more familiar with the different gadget types) but also putting the picture as window background and drawing other gadgets directly on it.
  • »11.04.13 - 18:29
    Profile
  • MorphOS Developer
    itix
    Posts: 1516 from 2003/2/24
    From: Finland
    Shame that Multiview can not search from linked documents, could be easier to find. But the place you should be looking at is MUI/MUI_Text - MUIA_Text_Contents in Includes & Autodocs.

    Quote:


    ESC p[p]
    ESC P[p] Pen number

    ESC p[RRGGBB]
    Direct RGB color value for truecolor displays.

    ESC P[RRGGBB]
    ESC P[AARRGGBB]
    ESC P[AA------]
    Direct (A)RGB value specifying text color on truecolor displays.
    When AA------ is used, currently set color is not altered,
    only its alpha value (transparency).



    MUIA_Text_Contents, "\33P[778833]Some text here" sets direct RGB color value. You can embed color coding anywhere in your text and of course it is not limited to TextObjects but it can be used in most classes (listviews for example).

    To display custom background you can use MUIA_Image_Spec formatting (IIRC) used in MUIA_Background tag, however most likely it might work better if you use custom class and render it yourself. You can also install window backfill hook but not sure how well it works in MUI. It has been about ten years when I had to mess with it even remotely in MUI applications.
    1 + 1 = 3 with very large values of 1
  • »11.04.13 - 18:31
    Profile
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    connor
    Posts: 570 from 2007/7/29
    Thanks for your input. Yes, aa better Multiview would be helpful. But there is search command at least. So I can search in Shell.

    So I use ESC sequences like in a normal Shell, just throw it somewhere inside my text and all the following letters will change their format? Then I could write every single letter differently as well, right? Just for a playground, not really needed by me now.

    Are the pen numbers still the same 8 pens as in MUI 3.8: http://en.wikipedia.org/wiki/Magic_User_Interface, starting with Pen0 at 149/149/149?

    Writing my own custom class is yet a bit far but maybe one day I can do that. I think MUIA_Background tag is the easiest for the start, right? I do not know yet anything about hooks. I think I have to learn that, too, because MUI uses them a lot as far as I have heard. Does it have advantages over using MUIA_Background? Technical ones? Speedwise? Elegance? More modern? Whatever?
  • »11.04.13 - 19:39
    Profile
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    connor
    Posts: 570 from 2007/7/29
    I could set the font colours via ESC sequences and place the picture in the background now. I did not yet understand why it does not show up when I set the attribute in the initial attribute list with all other window attributes like "no closing gadget" and such but have to place the attribute inside the VGroup definition where the object itself is to make it work. I thought "the more up, the more global it is". But then the attribute gets ignored. I expected it to be globally in the background of all my windows then. Why could that be that it only works locally?
  • »16.04.13 - 17:54
    Profile
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    boot_wb
    Posts: 874 from 2007/4/9
    From: Kingston upon ...
    If child objects/groups are not transparent, wouldn't they be occluding any image in the window/parent group?
    www.hullchimneyservices.co.uk

    UI: Powerbook 5,6 (1.67GHz, 128MB VRam): OS3.1, OSX 10.5.8
    HTPC: Mac Mini G4 (1,5GHz, 64MB VRam): OS3.1 (ZVNC)
    Audiophile: Efika 5200b (SB Audigy): OS3.1 (VNC + Virtual Monitor)

    Windows free since 2011!
  • »16.04.13 - 18:07
    Profile Visit Website
  • MorphOS Developer
    itix
    Posts: 1516 from 2003/2/24
    From: Finland
    Quote:


    Are the pen numbers still the same 8 pens as in MUI 3.8: http://en.wikipedia.org/wiki/Magic_User_Interface, starting with Pen0 at 149/149/149?



    They are configurable by user.

    Quote:


    Writing my own custom class is yet a bit far but maybe one day I can do that. I think MUIA_Background tag is the easiest for the start, right? I do not know yet anything about hooks.



    Window backfill hook is global backfill hook where you can "easily" draw custom background. "Easily" as in read ROM Kernel Reference manuals and figure out how to get it working with MUI. Since there is no direct support to use custom background you have to experiment a lot with MUI internals to get it working as you want it to be. And I am not sure if backfill hook would work (never tried).

    My good old friend UltraGelb (author of AmiNetRadio) spent great amount of time to get it working. I dont think he was using backfill hook but just MUI custom classes (i.e. override background rendering methods).
    1 + 1 = 3 with very large values of 1
  • »16.04.13 - 18:45
    Profile
  • MorphOS Developer
    itix
    Posts: 1516 from 2003/2/24
    From: Finland
    Quote:


    I did not yet understand why it does not show up when I set the attribute in the initial attribute list with all other window attributes like "no closing gadget"



    MUIA_Background is Area.mui class tag and only objects inherited from Area.mui class (VGroup, text, buttons etc) support this tag. Window class is not inherited from Area.mui and therefore dont have this tag (see class hierarchy in libraries/mui.h).
    1 + 1 = 3 with very large values of 1
  • »16.04.13 - 18:52
    Profile
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    connor
    Posts: 570 from 2007/7/29
    @ boot_wb

    The picture is not transparent. It is placed as a separate object in the layout, so no gadget is close enough to be drawn on top or bottom of the picture. Not exactly what I want but with the background colour it looks okay for the moment. Best would be to have my gadgets drawn "on" it. I did not achieve this yet. Is this what you mean by "transparent"?


    @ itix

    "All" I had to do now was to set the MUIA_Backgroud attribute to the image file but place it locally into the VGroup instead of globally. Is this the/a proper/recommended way?
    What I want to do next is to include the picture into the binary, means it should not be an extra resource anymore. I read about png2c from Zapek. Is this the proper way to do it? Is there a similar program for "jpg2c"?

    Ah, I remember AmiNetRadio and its green/black GUI! Great program! It's a shame that it is not developed anymore.
    Yes, I want to achieve a similar effect, that's it: Having one picture being the whole window backdrop. So for this I need to learn hooks?
  • »16.04.13 - 19:03
    Profile
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    connor
    Posts: 570 from 2007/7/29
    itix,
    Quote:

    MUIA_Background is Area.mui class tag and only objects inherited from Area.mui class (VGroup, text, buttons etc) support this tag. Window class is not inherited from Area.mui and therefore dont have this tag (see class hierarchy in libraries/mui.h).

    I see. Wouldn't that be a useful feature to globally set this attribute for windows or even the whole application?
  • »16.04.13 - 19:08
    Profile
  • MorphOS Developer
    itix
    Posts: 1516 from 2003/2/24
    From: Finland
    Quote:


    I see. Wouldn't that be a useful feature to globally set this attribute for windows or even the whole application?



    It could be but there is no guarantee MUI classes (i.e. 3rd party classes) would respect it and it is not clear when they should use their own background or global one. It is tricky because every object has a "right" to decide its background. Should buttons use global background or normal background? It really depends on a context.
    1 + 1 = 3 with very large values of 1
  • »16.04.13 - 19:33
    Profile
  • MorphOS Developer
    itix
    Posts: 1516 from 2003/2/24
    From: Finland
    Quote:


    Is this the/a proper/recommended way?



    It is the proper way.

    Quote:


    I read about png2c from Zapek. Is this the proper way to do it?



    It depends. The png2c generates an ARGB array you can WritePixelArray() to a bitmap. You cant use it in MUIA_Background because that one supports only external files, boopsi image classes or predefined image type. If you embed your gfx to program code using png2 you must draw it yourself to the window.

    In short png2c is useful in custom classes only.

    Quote:


    Is there a similar program for "jpg2c"?



    I would use PNG because generated C code is just uncompressed ARGB data. You dont get any advantages of jpg but only disadvantages.

    Quote:


    Yes, I want to achieve a similar effect, that's it: Having one picture being the whole window backdrop. So for this I need to learn hooks?



    Not necessarily. I cant remember how UltraGelb achieved it. I would just try with MUI custom class first. If you go for backfill hooks it is not guaranteed to work (they are intrusive to MUI) and any mistake there may result in complete lockup of your machine.

    So better just go for MUI custom class. Probably you have to subclass your VGroup and overload MUIM_Backfill. This would allow better control to you background graphics and it is almost like window backfill hooks but easier to debug and control.
    1 + 1 = 3 with very large values of 1
  • »16.04.13 - 19:51
    Profile
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    connor
    Posts: 570 from 2007/7/29
    Quote:


    It is tricky because every object has a "right" to decide its background.


    I see. So in these rare cases I have to define some more. It is okay, usually it won't be necessary I guess.


    Quote:


    In short png2c is useful in custom classes only.


    I would use PNG images wherever possible but in this case the original picture is just a JPG. I have no better quality data of this image, so I have to use it. I could convert it to PNG, though.
    If I want to skip custom classes for a while because I did not learn about them yet: what else could I do to embed a picture as source into my executable?


    Sadly, as Amigans/MorphOSians we are used to software locking up the whole system :-) No, of course this is not my intention. I want to make use of the program. Otherwise I could just hit the reset button on the front instead of learning MUI.


    I read about "internal" and "external" custom classes. The latter one being those .mcc, I guess. Are you talking about internal ones? I guess the main difference is whether you want to share them with other applications (external) or not (internal). Is that right?
    I found some custom class examples on Aminet like http://aminet.net/package/dev/mui/MCC_Time but for a starter I think they are too complex. Is there a minimal example somewhere out there to learn from it?
  • »16.04.13 - 20:12
    Profile
  • MorphOS Developer
    itix
    Posts: 1516 from 2003/2/24
    From: Finland
    Quote:


    If I want to skip custom classes for a while because I did not learn about them yet: what else could I do to embed a picture as source into my executable?



    Nothing really. If you embed picture into executable you either use raw format (png2c) or load it via datatypes/reggae but you still cant supply it directly to MUI because it wants real filename.

    Quote:


    I read about "internal" and "external" custom classes. The latter one being those .mcc, I guess. Are you talking about internal ones? I guess the main difference is whether you want to share them with other applications (external) or not (internal). Is that right?



    Yes that is right. External custom classes are .mcc files and internal ones are, well, internal. Internal custom classes are easy to construct. You have to provide your own dispatcher and call MUI_CreateCustomClass(). This returns IClass pointer you can supply to NewObject() to create new objects like they were any MUI objects.

    Quote:


    Is there a minimal example somewhere out there to learn from it?



    Try Chocolate Castle. Real external MCCs need lot more support code you dont have to usually care about.
    1 + 1 = 3 with very large values of 1
  • »16.04.13 - 20:30
    Profile
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    connor
    Posts: 570 from 2007/7/29
    Thanks for the infos so far. I will see how the picture looks like when converted to PNG. Then I will try with png2c. And Chocolate Castle may be my next toy the coming days.
  • »16.04.13 - 20:47
    Profile