Ticket #2414: minimapIconHover_v2_WIP.patch
File minimapIconHover_v2_WIP.patch, 5.0 KB (added by , 10 years ago) |
---|
-
binaries/data/mods/public/gui/session/session.xml
947 947 948 948 <object name="minimapOverlay" size="4 4 100%-4 100%-4" type="image" sprite="stretched:session/minimap_circle_modern.png" ghost="true"/> 949 949 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 950 960 <!-- 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> 961 970 </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"> 968 980 </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"> 975 990 </object> 976 991 </object> 977 992 </object> -
source/gui/CButton.cpp
52 52 AddSetting(GUIST_CColor, "textcolor_disabled"); 53 53 AddSetting(GUIST_CStrW, "tooltip"); 54 54 AddSetting(GUIST_CStr, "tooltip_style"); 55 AddSetting(GUIST_bool, "masked"); // we don't want to check every button for "transparency mask" 55 56 56 57 // Add text 57 58 AddText(new SGUIText()); … … 123 124 CColor color = ChooseColor(); 124 125 DrawText(0, color, m_TextPos, bz+0.1f); 125 126 } 127 128 bool 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
77 77 */ 78 78 virtual void Draw(); 79 79 80 /** 81 * checks, if the mouse is over the button 82 * @see IGUIObject#MouseOver() 83 */ 84 virtual bool MouseOver(); 85 80 86 protected: 81 87 /** 82 88 * Sets up text, should be called every time changes has been