[solved] - How Do I Get The Colours That I Want? | Page 2

Discussion in 'MediaPortal 1 Skins' started by CyberSimian, December 26, 2016.

Loading...
  1. CyberSimian
    • Team MediaPortal

    CyberSimian Test Group

    Joined:
    June 10, 2013
    Messages:
    1,638
    Likes Received:
    541
    Gender:
    Male
    Location:
    Southampton
    Ratings:
    +961 / 3
    Home Country:
    United Kingdom United Kingdom
    Show System Specs
    That is not what the Wiki says! :eek:

    The Wiki implies that either decimal or hexadecimal values can be specified (and gives an example). A value containing one or more hexadecimal digits is clearly hex (if it is valid). But if a value contains only decimal digits (e.g. 12345678), how does the skin engine know whether the value is decimal or hex? I imagined that that was what the "#" prefix is for:

    12345678 -- a decimal number
    #12345678 -- a hexadecimal number



    Also, I have just tried both "cc00ff00" and "#cc00ff00" (without the quotes), and both give the same result -- a light green background. :confused:

    -- from CyberSimian in the UK
     
    • Like Like x 1
    • Agree Agree x 1
  2. Google AdSense Guest Advertisement



    to hide all adverts.
  3. ajs
    • Team MediaPortal

    ajs Development Group

    Joined:
    February 29, 2008
    Messages:
    8,620
    Likes Received:
    2,652
    Gender:
    Male
    Occupation:
    IT
    Location:
    Kyiv
    Ratings:
    +4,603 / 29
    Home Country:
    Ukraine Ukraine
    Show System Specs
    @mm1352000
    In WIKI: https://www.team-mediaportal.com/wiki/display/MediaPortal1/Colors
    Code (XML):
    1. <textcolor>White</textcolor>
    2. <textcolor>#20FFFFFF</textcolor>
    3. <textcolor>#330099</textcolor>
    4. <textcolor>Gainsboro</textcolor>
    5. <!-- specify a named color with non-default alpha (using hex, preferred) -->
    6. <textcolor>White:#60</textcolor>
    7. <!-- not using hex -->
    8. <textcolor>White:96</textcolor>
    The code handles these values is one: https://github.com/MediaPortal/Medi...al/Core/guilib/GUIControlFactory.cs#L261-L263
    Code (C#):
    1.           if (String.Compare(valueName, "textcolor", StringComparison.OrdinalIgnoreCase) == 0 ||
    2.               String.Compare(valueName, "colorkey", StringComparison.OrdinalIgnoreCase) == 0 ||
    3.               String.Compare(valueName, "colordiffuse", StringComparison.OrdinalIgnoreCase) == 0)
    4.           {
     
    • Like Like x 1
  4. ajs
    • Team MediaPortal

    ajs Development Group

    Joined:
    February 29, 2008
    Messages:
    8,620
    Likes Received:
    2,652
    Gender:
    Male
    Occupation:
    IT
    Location:
    Kyiv
    Ratings:
    +4,603 / 29
    Home Country:
    Ukraine Ukraine
    Show System Specs
    When we specify the color with # Media portal thinks that it is a named color And using the function: Color.FromName But she knows how to work with string type #FFFFFFFF ... https://github.com/MediaPortal/Medi...aportal/Core/guilib/GUIControlFactory.cs#L305
    When we not specify the color with # Media portal use ColorTranslator.FromHtml https://github.com/MediaPortal/Medi...aportal/Core/guilib/GUIControlFactory.cs#L311
    Both methods should work. #FFFFFFFF and FFFFFFFF ...
    How to convert a color you can see: https://referencesource.microsoft.c...ystem/Drawing/Advanced/ColorTranslator.cs,228
     
    • Like Like x 1
    • Thank You! Thank You! x 1
  5. mm1352000
    • Team MediaPortal

    mm1352000 Development Group

    Joined:
    September 1, 2008
    Messages:
    21,526
    Likes Received:
    4,735
    Ratings:
    +8,201 / 17
    Home Country:
    New Zealand New Zealand
    The wiki may well be wrong. Its happened in the past and I'm sure it will happen again in the future.

    As you can see from the code, the engine doesn't appear to explicitly handle decimals for the colordiffuse, colorkey and textcolor elements/attributes. I can't say more than that.

    Again, as you can see from the code, it appears that your imagination was wrong.

    From what I can see, the #cc00ff00 can only ever be recognised as a valid colour in one scenario due to a quirk of the engine's colour caching mechanism.

    Use of cc00ff00 (always valid) will cause the engine to cache the corresponding colour (ARGB cc00ff00) with cache key #cc00ff00:
    https://github.com/MediaPortal/Medi...aportal/Core/guilib/GUIControlFactory.cs#L311

    If you subsequently attempt to use colour #cc00ff00, the engine code will start with the assumption that you're attempting to use a named colour. That assumption is based on the presence of the non 0-9A-Fa-f character (#) in the colour value:
    https://github.com/MediaPortal/Medi...al/Core/guilib/GUIControlFactory.cs#L267-L278

    So, isNamedColor will be true even though we know that #cc00ff00 is not and never has been a valid named colour.

    We can ignore the next little section of code because #cc00ff00 does not contain a colon:
    https://github.com/MediaPortal/Medi...al/Core/guilib/GUIControlFactory.cs#L284-L304

    Now we come to the revelation. Before attempting to convert the assumed-to-be-valid-named-colour to it's ARGB representation, the engine checks the cache for the corresponding key. The key for a named colour is just its name, which in this case is #cc00ff00:
    https://github.com/MediaPortal/Medi...aportal/Core/guilib/GUIControlFactory.cs#L305

    If you recall, the cc00ff00 colour was previously also stored with that same #cc00ff00 cache key.

    ...and now you should understand what's going on. ;)

    Had you not previously used that cc00ff00 colour, the engine would try to convert #cc00ff00 to it's ARGB representation using Color.FromName(). That function silently fails and returns a colour with ARGB value 0 (black). As a result, the engine will cache #cc00ff00 as ARGB 0. Subsequent attempts to use either cc00ff00 or #cc00ff00 would result in use of ARGB 0 instead of the desired ARGB cc00ff00.


    So I repeat: catavolt's advice to not use the # prefix is good.


    You have the code so you can see how it works. I advise you to use it and not get hung up on what the wiki says. Please do update the wiki if/where it is not correct. This would be much appreciated.


    DISCLAIMER:
    I'm not a skin engine expert, and I didn't write the code or the wiki content that has been linked here. I'm simply trying to assist you towards an answer to your question(s).
     
    • Thank You! Thank You! x 2
    • Like Like x 1
  6. ajs
    • Team MediaPortal

    ajs Development Group

    Joined:
    February 29, 2008
    Messages:
    8,620
    Likes Received:
    2,652
    Gender:
    Male
    Occupation:
    IT
    Location:
    Kyiv
    Ratings:
    +4,603 / 29
    Home Country:
    Ukraine Ukraine
    Show System Specs
    It is necessary to modify the wiki, or remove in source code the # character at the beginning of the line. Or do not consider the color with # at the beginning, as a named. :):whistle::coffee:
     
  7. mm1352000
    • Team MediaPortal

    mm1352000 Development Group

    Joined:
    September 1, 2008
    Messages:
    21,526
    Likes Received:
    4,735
    Ratings:
    +8,201 / 17
    Home Country:
    New Zealand New Zealand
    I recommend this one to avoid breaking existing skins.
     
  8. ajs
    • Team MediaPortal

    ajs Development Group

    Joined:
    February 29, 2008
    Messages:
    8,620
    Likes Received:
    2,652
    Gender:
    Male
    Occupation:
    IT
    Location:
    Kyiv
    Ratings:
    +4,603 / 29
    Home Country:
    Ukraine Ukraine
    Show System Specs
    How can it affect the current skin? If now no one uses the # symbol in the color designation in the fields of: textcolor, colorkey, colordiffuse? :):coffee:
     
  9. CyberSimian
    • Team MediaPortal

    CyberSimian Test Group

    Joined:
    June 10, 2013
    Messages:
    1,638
    Likes Received:
    541
    Gender:
    Male
    Location:
    Southampton
    Ratings:
    +961 / 3
    Home Country:
    United Kingdom United Kingdom
    Show System Specs
    Crikey! :eek: It will take me some time to digest all that. But thank you for taking the time to look at the code and then explain it to me. :)

    It also explains some inconsistencies in the results during testing, but for which I could not identify any pattern. Now it seems (if I have understood correctly) that the behaviour depends on what value was used previously, thereby confusing the results of the tests. :(

    I will remove all the "#" and see what result I get. Thank you @mm1352000 , @catavolt , @ajs .

    -- from CyberSimian in the UK
     
    • Like Like x 1
  10. mm1352000
    • Team MediaPortal

    mm1352000 Development Group

    Joined:
    September 1, 2008
    Messages:
    21,526
    Likes Received:
    4,735
    Ratings:
    +8,201 / 17
    Home Country:
    New Zealand New Zealand
    You don't know that no one uses the # symbol in the color designation. Any third party skin including unmaintained skins could be using that.
     
    • Agree Agree x 1
  11. mm1352000
    • Team MediaPortal

    mm1352000 Development Group

    Joined:
    September 1, 2008
    Messages:
    21,526
    Likes Received:
    4,735
    Ratings:
    +8,201 / 17
    Home Country:
    New Zealand New Zealand
    Indeed, it took me quite a long time to figure it out. ;)

    You're welcome. :)
     
    • Like Like x 1
Loading...
Loading...

Users Viewing Thread (Users: 0, Guests: 0)

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice
  • About The Project

    The vision of the MediaPortal project is to create a free open source media centre application, which supports all advanced media centre functions, and is accessible to all Windows users.

    In reaching this goal we are working every day to make sure our software is one of the best.

             

  • Support MediaPortal!

    The team works very hard to make sure the community is running the best HTPC-software. We give away MediaPortal for free but hosting and software is not for us.

    Care to support our work with a few bucks? We'd really appreciate it!