30 int32_t ContextMenu::iGlobalMenuIndex = 0;
62 :
Element(), cHotkey(0), icoIcon(icoIcon), pMenuHandler(pMenuHandler), pSubmenuHandler(pSubmenuHandler)
88 iMenuIndex = ++iGlobalMenuIndex;
93 Keys.emplace_back(K_UP);
102 Keys.emplace_back(K_DOWN);
111 Keys.emplace_back(K_RIGHT);
120 Keys.emplace_back(K_LEFT);
129 Keys.emplace_back(K_ESCAPE);
138 Keys.emplace_back(K_RETURN);
213 if (pCurr->GetBounds().Contains(iX, iY))
238 bool ContextMenu::KeySelUp()
252 bool ContextMenu::KeySelDown()
266 bool ContextMenu::KeySubmenu()
274 bool ContextMenu::KeyBack()
283 bool ContextMenu::KeyAbort()
291 bool ContextMenu::KeyConfirm()
300 bool ContextMenu::KeyHotkey(
const C4KeyCodeEx &key)
309 if (Inside<C4KeyCode, C4KeyCode, C4KeyCode>(wKey,
'A',
'Z') || Inside<C4KeyCode, C4KeyCode, C4KeyCode>(wKey,
'0',
'9'))
314 if (pCurr->OnHotkey(ch))
328 void ContextMenu::UpdateElementPositions()
333 pCurr->GetBounds().y = 0;
334 int32_t iMinWdt = std::max<int32_t>(20, pCurr->GetBounds().Wdt);;
335 int32_t iOverallHgt = pCurr->GetBounds().Hgt;
337 while ((pCurr = pCurr->GetNext()))
339 iMinWdt = std::max(iMinWdt, pCurr->GetBounds().Wdt);
340 int32_t iYSpace = pCurr->GetListItemTopSpacing();
341 int32_t iNewY = iOverallHgt + iYSpace;
342 iOverallHgt += pCurr->GetBounds().Hgt + iYSpace;
343 if (iNewY != pCurr->GetBounds().y)
345 pCurr->GetBounds().y = iNewY;
346 pCurr->UpdateOwnPos();
353 if (pCurr->GetBounds().Wdt != iMinWdt)
355 pCurr->GetBounds().Wdt = iMinWdt;
356 pCurr->UpdateOwnPos();
384 UpdateElementPositions();
387 bool ContextMenu::AddElement(
Element *pChild)
392 UpdateElementPositions();
397 bool ContextMenu::InsertElement(Element *pChild, Element *pInsertBefore)
402 UpdateElementPositions();
412 UpdateElementPositions();
420 UpdateElementPositions();
429 if (fByUser)
GUISound(
"UI::Select");
493 if (!pSubmenuHandler)
return;
505 if (iY < pSubmenu->
GetBounds().Hgt) iY = iScreenHgt;
538 if (!pCallback)
return;
565 RegisterContextKey();
578 RegisterContextKey();
586 void ContextButton::RegisterContextKey()
590 ContextKeys.emplace_back(K_RIGHT);
591 ContextKeys.emplace_back(K_DOWN);
592 ContextKeys.emplace_back(K_SPACE);
593 ContextKeys.emplace_back(K_RIGHT,
KEYS_Alt);
594 ContextKeys.emplace_back(K_DOWN,
KEYS_Alt);
595 ContextKeys.emplace_back(K_SPACE,
KEYS_Alt);
610 if (!pCtx)
return false;
611 if (!pCtx->OnContext(
this, iX, iY))
return false;
614 if (!pScr)
return false;
615 iOpenMenu = pScr->GetContextMenuIndex();
C4GraphicsResource GraphicsResource
#define C4GUI_ContextBGColor
#define C4GUI_ContextFontClr
#define C4GUI_ContextSelColor
const int32_t C4MC_Button_RightDown
const int32_t C4MC_Button_LeftDown
#define C4GFXBLIT_ADDITIVE
int32_t GamepadGuiControl
C4ConfigControls Controls
std::vector< C4KeyCodeEx > CodeList
void SetBlitMode(DWORD dwBlitMode)
void DrawBoxDw(C4Surface *sfcDest, int iX1, int iY1, int iX2, int iY2, DWORD dwClr)
bool TextOut(const char *szText, CStdFont &rFont, float fZoom, C4Surface *sfcDest, float iTx, float iTy, DWORD dwFCol=0xffffffff, BYTE byForm=ALeft, bool fDoMarkup=true)
C4Facet GetPhase(int iPhaseX=0, int iPhaseY=0)
void Draw(C4Facet &cgo, bool fAspect=true, int32_t iPhaseX=0, int32_t iPhaseY=0, bool fTransparent=true)
bool GetPhaseNum(int32_t &rX, int32_t &rY)
void DrawX(C4Surface *sfcTarget, float iX, float iY, float iWdt, float iHgt, int32_t iPhaseX=0, int32_t iPhaseY=0) const
void RemoveElement(Element *pChild)
virtual Element * GetLastContained()
void AddElement(Element *pChild)
void RemoveElement(Element *pChild) override
virtual void ElementSizeChanged(Element *pOfElement)
Element * GetElementByIndex(int32_t i)
void InsertElement(Element *pChild, Element *pInsertBefore)
Element * GetFirstContained() override
void DrawElement(C4TargetFacet &cgo) override
void MouseEnter(CMouse &rMouse) override
void MouseInput(CMouse &rMouse, int32_t iButton, int32_t iX, int32_t iY, DWORD dwKeyParam) override
void MouseLeave(CMouse &rMouse) override
~ContextButton() override
ContextButton(C4Rect &rtBounds)
virtual ContextMenu * OnSubcontext(Element *pOnElement)=0
void MouseInput(CMouse &rMouse, int32_t iButton, int32_t iX, int32_t iY, DWORD dwKeyParam) override
Element * GetPrev() const
virtual Container * GetContainer()
C4Rect GetToprightCornerRect(int32_t iWidth=16, int32_t iHeight=16, int32_t iHIndent=4, int32_t iVIndent=4, int32_t iIndexX=0)
virtual Screen * GetScreen()
Element * GetNext() const
bool IsInActiveDlg(bool fForKeyboard)
virtual void UpdateSize()
void SetBounds(const C4Rect &rcNewBound)
virtual ContextHandler * GetContextHandler()
virtual void MouseEnter(CMouse &rMouse)
void SetContextHandler(ContextHandler *pNewHd)
virtual void MouseLeave(CMouse &rMouse)
void Draw3DFrame(C4TargetFacet &cgo, bool fUp=false, int32_t iIndent=1, BYTE byAlpha=C4GUI_BorderAlpha, bool fDrawTop=true, int32_t iTopOff=0, bool fDrawLeft=true, int32_t iLeftOff=0)
virtual void OnOK(Element *pTarget)=0
static Screen * GetScreenS()
int32_t GetContextMenuIndex()
void AbortContext(bool fByUser)
void RemoveElement(Element *pChild) override
void MouseInput(CMouse &rMouse, int32_t iButton, int32_t iX, int32_t iY, DWORD dwKeyParam) override
void Draw(C4TargetFacet &cgo) override
C4Rect & GetClientRect() override
C4FacetID fctButtonHighlight
bool Contains(int32_t iX, int32_t iY) const
int GetLineHeight() const
bool GetTextExtent(const char *szText, int32_t &rsx, int32_t &rsy, bool fCheckMarkup=true)
const char * getData() const
bool ExpandHotkeyMarkup(StdStrBuf &sText, uint32_t &rcHotkey, bool for_tooltip)
void GUISound(const char *szSound)
static StdStrBuf KeyCode2String(C4KeyCode wCode, bool fHumanReadable, bool fShort)