Ticket #2414: minimapIconHover_v2_WIP.patch

File minimapIconHover_v2_WIP.patch, 5.0 KB (added by Michael, 10 years ago)

More generic version with image transparency mask but still WIP.

  • binaries/data/mods/public/gui/session/session.xml

     
    947947
    948948        <object name="minimapOverlay" size="4 4 100%-4 100%-4" type="image" sprite="stretched:session/minimap_circle_modern.png" ghost="true"/>
    949949
     950        <!-- Score Button (deactivated until function is implemented)-->
     951        <object size="100%-75 0 100% 75">
     952            <object name="minimap_button[1]" size="0 0 100% 100%" type="button" ghost="true"
     953            sprite="stretched:grayscale:session/icons/minimap/score_border.png"
     954            sprite_over="stretched:session/icons/minimap/score_border_hover.png"
     955            masked="true"
     956            enabled="false">
     957            </object>
     958        </object>
     959       
    950960        <!-- Idle Worker Button -->
    951         <object size="100%-36 100%-36 100%-5 100%-5">
    952             <!-- TODO: should highlight the button if there's non-zero idle workers -->
    953             <object name="idle-overlay" size="-85 -85 100% 100%" type="image" sprite="stretched:session/minimap-idle.png" ghost="true"/>
    954             <!-- Since we don't support non-rectangular buttons, we approximate the area using 3 rectangles TODO: Make this cleaner -->
    955             <object type="button"
    956                 tooltip_style="sessionToolTip"
    957                 tooltip="Find idle worker"
    958                 hotkey="selection.idleworker"
    959             >
    960                 <action on="Press">findIdleUnit(["Female", "Trade", "FishingBoat", "CitizenSoldier", "Healer"]);</action>
     961        <object size="100%-75 100%-75 100% 100%">
     962            <object name="minimap_button[2]" size="0 0 100% 100%" type="button"
     963            sprite="stretched:session/icons/minimap/idle_border.png"
     964            sprite_over="stretched:session/icons/minimap/idle_border_hover.png"
     965            tooltip_style="sessionToolTip"
     966            tooltip="Find idle worker"
     967            hotkey="selection.idleworker"
     968            masked="true">
     969            <action on="Press">findIdleUnit(["Female", "Trade", "FishingBoat", "CitizenSoldier", "Healer"]);</action>
    961970            </object>
    962             <object type="button"
    963                 tooltip_style="sessionToolTip"
    964                 tooltip="Find idle worker"
    965                 size="15 -15 100% 0"
    966             >
    967                 <action on="Press">findIdleUnit(["Female", "Trade", "FishingBoat", "CitizenSoldier", "Healer"]);</action>
     971        </object>
     972       
     973        <!-- Zoom Button (deactivated until function is implemented)-->
     974        <object size="0 100%-75 75 100%">
     975            <object name="minimap_button[3]" size="0 0 100% 100%" type="button"
     976            sprite="stretched:grayscale:session/icons/minimap/zoom_border.png"
     977            sprite_over="stretched:session/icons/minimap/zoom_border_hover.png"
     978            masked="true"
     979            enabled="false">
    968980            </object>
    969             <object type="button"
    970                 tooltip_style="sessionToolTip"
    971                 tooltip="Find idle worker"
    972                 size="-15 15 0 100%"
    973             >
    974                 <action on="Press">findIdleUnit(["Female", "Trade", "FishingBoat", "CitizenSoldier", "Healer"]);</action>
     981        </object>
     982       
     983        <!-- Flare Button (deactivated until function is implemented)-->
     984        <object size="0 0 75 75">
     985            <object name="minimap_button[4]" size="0 0 100% 100%" type="button"
     986            sprite="stretched:grayscale:session/icons/minimap/flare_border.png"
     987            sprite_over="stretched:session/icons/minimap/flare_border_hover.png"
     988            masked="true"
     989            enabled="false">
    975990            </object>
    976991        </object>
    977992    </object>
  • source/gui/CButton.cpp

     
    5252    AddSetting(GUIST_CColor,                "textcolor_disabled");
    5353    AddSetting(GUIST_CStrW,                 "tooltip");
    5454    AddSetting(GUIST_CStr,                  "tooltip_style");
     55    AddSetting(GUIST_bool,                  "masked"); // we don't want to check every button for "transparency mask"
    5556
    5657    // Add text
    5758    AddText(new SGUIText());
     
    123124    CColor color = ChooseColor();
    124125    DrawText(0, color, m_TextPos, bz+0.1f);
    125126}
     127
     128bool CButton::MouseOver()
     129{
     130    // return false, if mouse is in area of button
     131    if (!IGUIObject::MouseOver())
     132        return false;
     133   
     134    // check if masked flag is set
     135    bool masked = false;
     136    GUI<bool>::GetSetting(this, "masked", masked);
     137
     138    // return true, if masked flag is not set in button
     139    if (!masked)
     140        return true;
     141
     142    // get pixel coordinates relative to the button top left of the button
     143    CPos topLeftOfButton = m_CachedActualSize.TopLeft();
     144    CPos pos = GetMousePos();
     145    pos.x -= topLeftOfButton.x;
     146    pos.y -= topLeftOfButton.y;
     147
     148    // TODO: check in an efficient way, if pixel at (pos.x, pos.y) is transparent
     149    // or not in "sprite" attribute of button
     150    // IGUIButtonBehavior::DrawButton, CGUISpriteInstance::Draw or m_DrawCallCache of CGUISpriteInstance may help ?!
     151    return true;
     152}
     153
  • source/gui/CButton.h

     
    7777     */
    7878    virtual void Draw();
    7979
     80    /**
     81     * checks, if the mouse is over the button
     82     * @see IGUIObject#MouseOver()
     83     */
     84    virtual bool MouseOver();
     85
    8086protected:
    8187    /**
    8288     * Sets up text, should be called every time changes has been