void C4FileSelDlg::DefaultListItem::UpdateOwnPos() { BaseClass::UpdateOwnPos(); if (!pLbl) return; C4GUI::ComponentAligner caMain(GetContainedClientRect(), 0, 0); caMain.GetFromLeft(caMain.GetInnerHeight() * (1 + !!pCheck)); pLbl->SetBounds(caMain.GetAll()); }
C4GameOptionsList::OptionDropdown::OptionDropdown(class C4GameOptionsList *pForDlg, const char *szCaption, bool fReadOnly) : Option(pForDlg) { CStdFont &rUseFont = ::GraphicsResource.TextFont; // get size of caption label bool fTabular = pForDlg->IsTabular(); int32_t iCaptWidth, iCaptHeight; if (fTabular) { // tabular layout: Caption label width by largest caption rUseFont.GetTextExtent(LoadResStr("IDS_NET_RUNTIMEJOIN"), iCaptWidth, iCaptHeight, true); iCaptWidth = iCaptWidth * 5 / 4; } else { rUseFont.GetTextExtent(szCaption, iCaptWidth, iCaptHeight, true); } // calc total height for component int iHorizontalMargin = 1; int iVerticalMargin = 1; int iComboMargin = 5; int iSelComboHgt = C4GUI::ComboBox::GetDefaultHeight(); SetBounds(C4Rect(0, 0, pForDlg->GetItemWidth(), (!fTabular) * (iCaptHeight + iVerticalMargin*2) + iVerticalMargin*2 + iSelComboHgt)); C4GUI::ComponentAligner ca(GetContainedClientRect(), iHorizontalMargin, iVerticalMargin); // create subcomponents AddElement(pCaption = new C4GUI::Label(FormatString("%s:", szCaption).getData(), fTabular ? ca.GetFromLeft(iCaptWidth, iCaptHeight) : ca.GetFromTop(iCaptHeight), ALeft)); ca.ExpandLeft(-iComboMargin); AddElement(pPrimarySubcomponent = pDropdownList = new C4GUI::ComboBox(ca.GetAll())); pDropdownList->SetReadOnly(fReadOnly); pDropdownList->SetComboCB(new C4GUI::ComboBox_FillCallback<C4GameOptionsList::OptionDropdown>(this, &C4GameOptionsList::OptionDropdown::OnDropdownFill, &C4GameOptionsList::OptionDropdown::OnDropdownSelChange)); // final init InitOption(pForDlg); }
C4StartupAboutDlg::C4StartupAboutDlg() : C4StartupDlg(LoadResStr("IDS_DLG_ABOUT")) { // ctor UpdateSize(); CStdFont &rUseFont = ::GraphicsResource.TextFont; C4Rect rcClient = GetContainedClientRect(); // bottom line buttons and copyright messages C4GUI::ComponentAligner caMain(rcClient, 0,0, true); C4GUI::ComponentAligner caButtons(caMain.GetFromBottom(caMain.GetHeight()*1/8), 0,0, false); C4GUI::CallbackButton<C4StartupAboutDlg> *btn; #if AUDIO_TK == AUDIO_TK_FMOD AddElement(new C4GUI::Label("Using FMOD Sound System, copyright (c) Firelight Technologies Pty, Ltd., 1994-2010.", caMain.GetFromBottom(rUseFont.GetLineHeight()))); #endif int32_t iButtonWidth = caButtons.GetInnerWidth() / 4; AddElement(btn = new C4GUI::CallbackButton<C4StartupAboutDlg>(LoadResStr("IDS_BTN_BACK"), caButtons.GetGridCell(0,3,0,1,iButtonWidth,C4GUI_ButtonHgt,true), &C4StartupAboutDlg::OnBackBtn)); btn->SetToolTip(LoadResStr("IDS_DLGTIP_BACKMAIN")); #ifdef WITH_AUTOMATIC_UPDATE AddElement(btn = new C4GUI::CallbackButton<C4StartupAboutDlg>(LoadResStr("IDS_BTN_CHECKFORUPDATES"), caButtons.GetGridCell(2,3,0,1,iButtonWidth,C4GUI_ButtonHgt,true), &C4StartupAboutDlg::OnUpdateBtn)); btn->SetToolTip(LoadResStr("IDS_DESC_CHECKONLINEFORNEWVERSIONS")); #endif AddElement(new C4GUI::Label("'Clonk' is a registered trademark of Matthes Bender.", caButtons.GetFromBottom(rUseFont.GetLineHeight()))); }
TextWindow::TextWindow(C4Rect &rtBounds, size_t iPicWdt, size_t iPicHgt, size_t iPicPadding, size_t iMaxLines, size_t iMaxTextLen, const char *szIndentChars, bool fAutoGrow, const C4Facet *pOverlayPic, int iOverlayBorder, bool fMarkup) : Control(rtBounds), pLogBuffer(NULL), fDrawBackground(true), fDrawFrame(true), iPicPadding(iPicPadding) { // calc client rect UpdateOwnPos(); // create content scroll window pClientWindow = new ScrollWindow(this); pClientWindow->SetBounds(GetContainedClientRect()); // create content multiline label pLogBuffer = new MultilineLabel(pClientWindow->GetContainedClientRect(), iMaxLines, iMaxTextLen, szIndentChars, fAutoGrow, fMarkup); // add to scroll window pClientWindow->AddElement(pLogBuffer); // update scrolling (for empty buffer) pClientWindow->SetClientHeight(1); // create content picture, if desired C4Rect rcContentSize = pClientWindow->GetClientRect(); if (iPicWdt && iPicHgt) { C4Rect rcImage; rcImage.x = std::max<int32_t>(rcContentSize.GetMiddleX() - iPicWdt/2, 0); rcImage.y = 0; rcImage.Wdt = std::min<size_t>(iPicWdt, rcContentSize.Wdt); rcImage.Hgt = iPicHgt * rcImage.Wdt / iPicWdt; rcContentSize.y += rcImage.Hgt + iPicPadding; if (pOverlayPic) pTitlePicture = new OverlayPicture(rcImage, false, *pOverlayPic, iOverlayBorder); else pTitlePicture = new Picture(rcImage, false); pClientWindow->AddElement(pTitlePicture); } else pTitlePicture = NULL; // update size UpdateSize(); }
C4Network2ResDlg::ListItem::ListItem(C4Network2ResDlg *pForResDlg, const C4Network2Res *pByRes) : pSaveBtn(NULL) { // init by res core (2do) iResID = pByRes->getResID(); const char *szFilename = GetFilename(pByRes->getCore().getFileName()); // get size int iIconSize = ::GraphicsResource.TextFont.GetLineHeight(); int iWidth = pForResDlg->GetItemWidth(); int iVerticalIndent = 2; SetBounds(C4Rect(0, 0, iWidth, iIconSize+2*iVerticalIndent)); C4GUI::ComponentAligner ca(GetContainedClientRect(), 0,iVerticalIndent); // create subcomponents pFileIcon = new C4GUI::Icon(ca.GetFromLeft(iIconSize), C4GUI::Ico_Resource); pLabel = new C4GUI::Label(szFilename, iIconSize + IconLabelSpacing,iVerticalIndent, ALeft); pProgress = NULL; // add components AddElement(pFileIcon); AddElement(pLabel); // tooltip SetToolTip(LoadResStr("IDS_DESC_RESOURCE")); // add to listbox (will eventually get moved) pForResDlg->AddElement(this); // first-time update Update(pByRes); }
C4Rect Element::GetToprightCornerRect(int32_t iWidth, int32_t iHeight, int32_t iHIndent, int32_t iVIndent, int32_t iIndexX) { // bounds by topright corner of element C4Rect rtBounds = (GetContainer() != this) ? GetClientRect() : GetContainedClientRect(); rtBounds.x += rtBounds.Wdt - (iWidth + iHIndent) * (iIndexX + 1); rtBounds.y += iVIndent; rtBounds.Wdt = rtBounds.Hgt = iHeight; return rtBounds; }
C4Network2ClientListBox::ClientListItem::ClientListItem(class C4Network2ClientListBox *pForDlg, int iClientID) // ctor : ListItem(pForDlg, iClientID), pStatusIcon(nullptr), pName(nullptr), pPing(nullptr), pActivateBtn(nullptr), pKickBtn(nullptr), last_sound_time(0) { // get associated client const C4Client *pClient = GetClient(); // get size int iIconSize = ::GraphicsResource.TextFont.GetLineHeight(); if (pForDlg->IsStartup()) iIconSize *= 2; int iWidth = pForDlg->GetItemWidth(); int iVerticalIndent = 2; SetBounds(C4Rect(0, 0, iWidth, iIconSize+2*iVerticalIndent)); C4GUI::ComponentAligner ca(GetContainedClientRect(), 0,iVerticalIndent); // create subcomponents bool fIsHost = pClient && pClient->isHost(); pStatusIcon = new C4GUI::Icon(ca.GetFromLeft(iIconSize), fIsHost ? C4GUI::Ico_Host : C4GUI::Ico_Client); StdStrBuf sNameLabel; if (pClient) { if (pForDlg->IsStartup()) sNameLabel.Ref(pClient->getName()); else sNameLabel.Format("%s:%s", pClient->getName(), pClient->getNick()); } else { sNameLabel.Ref("???"); } pName = new C4GUI::Label(sNameLabel.getData(), iIconSize + IconLabelSpacing,iVerticalIndent, ALeft); int iPingRightPos = GetBounds().Wdt - IconLabelSpacing; if (::Network.isHost()) iPingRightPos -= 48; if (::Network.isHost() && pClient && !pClient->isHost()) { // activate/deactivate and kick btns for clients at host if (!pForDlg->IsStartup()) { pActivateBtn = new C4GUI::CallbackButtonEx<C4Network2ClientListBox::ClientListItem, C4GUI::IconButton>(C4GUI::Ico_Active, GetToprightCornerRect(std::max(iIconSize, 16),std::max(iIconSize, 16),2,1,1), 0, this, &ClientListItem::OnButtonActivate); fShownActive = true; } pKickBtn = new C4GUI::CallbackButtonEx<C4Network2ClientListBox::ClientListItem, C4GUI::IconButton>(C4GUI::Ico_Kick, GetToprightCornerRect(std::max(iIconSize, 16),std::max(iIconSize, 16),2,1,0), 0, this, &ClientListItem::OnButtonKick); pKickBtn->SetToolTip(LoadResStrNoAmp("IDS_NET_KICKCLIENT")); } if (!pForDlg->IsStartup()) if (pClient && !pClient->isLocal()) { // wait time pPing = new C4GUI::Label("???", iPingRightPos, iVerticalIndent, ARight); pPing->SetToolTip(LoadResStr("IDS_DESC_CONTROLWAITTIME")); } // add components AddElement(pStatusIcon); AddElement(pName); if (pPing) AddElement(pPing); if (pActivateBtn) AddElement(pActivateBtn); if (pKickBtn) AddElement(pKickBtn); // add to listbox (will eventually get moved) pForDlg->AddElement(this); // first-time update Update(); }
void C4ChatControl::ChatSheet::NickItem::UpdateOwnPos() { typedef C4GUI::Window ParentClass; ParentClass::UpdateOwnPos(); // reposition elements if (pStatusIcon && pNameLabel) { C4GUI::ComponentAligner caMain(GetContainedClientRect(), 1, 0); pStatusIcon->SetBounds(caMain.GetFromLeft(caMain.GetInnerHeight())); pNameLabel->SetBounds(caMain.GetAll()); } }
void TextWindow::UpdateSize() { Control::UpdateSize(); pClientWindow->SetBounds(GetContainedClientRect()); // resize log buffer pos to horizontal extents C4Rect rcChildBounds = pLogBuffer->GetBounds(); rcChildBounds.x = 0; rcChildBounds.y = (pTitlePicture && pTitlePicture->IsVisible()) ? pTitlePicture->GetBounds().Hgt + iPicPadding : 0; rcChildBounds.Wdt = pClientWindow->GetClientRect().Wdt; pLogBuffer->SetBounds(rcChildBounds); }
void C4ChatDlg::UpdateSize() { // parent update typedef C4GUI::Dialog ParentClass; ParentClass::UpdateSize(); // position child elements C4GUI::ComponentAligner caMain(GetContainedClientRect(), 0, 0); // C4GUI::ComponentAligner // caBottom(caMain.GetFromBottom(C4GUI_ButtonHgt+C4GUI_DefDlgIndent*2), // C4GUI_DefDlgIndent,C4GUI_DefDlgIndent); pChatCtrl->SetBounds(caMain.GetAll()); // pBtnClose->SetBounds(caBottom.GetFromLeft(100)); }
C4Network2StartWaitDlg::C4Network2StartWaitDlg() : C4GUI::Dialog(DialogWidth, DialogHeight, LoadResStr("IDS_NET_CAPTION"), false) { C4GUI::ComponentAligner caAll(GetContainedClientRect(), C4GUI_DefDlgIndent, C4GUI_DefDlgIndent); C4GUI::ComponentAligner caButtonArea(caAll.GetFromBottom(C4GUI_ButtonAreaHgt), 0,0); // create top label C4GUI::Label *pLbl; AddElement(pLbl = new C4GUI::Label(LoadResStr("IDS_NET_WAITFORSTART"), caAll.GetFromTop(25), ACenter)); // create client list box AddElement(pClientListBox = new C4Network2ClientListBox(caAll.GetAll(), true)); // place abort button C4GUI::Button *pBtnAbort = new C4GUI::CancelButton(caButtonArea.GetCentered(C4GUI_DefButtonWdt, C4GUI_ButtonHgt)); AddElement(pBtnAbort); }
void C4ChatControl::ChatSheet::UpdateSize() { // parent update typedef C4GUI::Window ParentClass; ParentClass::UpdateSize(); // position child elements C4GUI::ComponentAligner caMain(GetContainedClientRect(), 0, 0); C4GUI::ComponentAligner caChat( caMain.GetFromBottom(C4GUI::Edit::GetDefaultEditHeight()), 0, 0); if (pNickList) pNickList->SetBounds( caMain.GetFromRight(Max<int32_t>(caMain.GetInnerWidth() / 5, 100))); pChatBox->SetBounds(caMain.GetAll()); if (pInputLbl) pInputLbl->SetBounds(caChat.GetFromLeft(40)); pInputEdit->SetBounds(caChat.GetAll()); }
C4GameOptionsList::OptionDropdown::OptionDropdown(class C4GameOptionsList *pForDlg, const char *szCaption, bool fReadOnly) : Option(pForDlg), fReadOnly(fReadOnly) { bool fIsPreGame = pForDlg->IsPreGame(); CStdFont &rUseFont = fIsPreGame ? C4Startup::Get()->Graphics.BookFont : ::GraphicsResource.TextFont; uint32_t dwFontClr = fIsPreGame ? C4StartupFontClr : 0xffffffff; // get size of caption label bool fTabular = pForDlg->IsTabular(); int32_t iCaptWidth, iCaptHeight; if (fTabular) { // tabular layout: Caption label width by largest caption on runtime; fixed 1/3rd on startup rUseFont.GetTextExtent(LoadResStr("IDS_NET_RUNTIMEJOIN"), iCaptWidth, iCaptHeight, true); if (pForDlg->IsPreGame()) { iCaptWidth = pForDlg->GetItemWidth() * 1 / 3; } else { iCaptWidth = iCaptWidth * 5 / 4; } } else { rUseFont.GetTextExtent(szCaption, iCaptWidth, iCaptHeight, true); } // calc total height for component int iHorizontalMargin = 1; int iVerticalMargin = 1; int iComboMargin = 5; int iSelComboHgt = C4GUI::ComboBox::GetDefaultHeight(); SetBounds(C4Rect(0, 0, pForDlg->GetItemWidth(), (!fTabular) * (iCaptHeight + iVerticalMargin*2) + iVerticalMargin*2 + iSelComboHgt)); C4GUI::ComponentAligner ca(GetContainedClientRect(), iHorizontalMargin, iVerticalMargin); // create subcomponents AddElement(pCaption = new C4GUI::Label(FormatString("%s:", szCaption).getData(), fTabular ? ca.GetFromLeft(iCaptWidth, iCaptHeight) : ca.GetFromTop(iCaptHeight), ALeft, dwFontClr, &rUseFont, false, false)); ca.ExpandLeft(-iComboMargin); AddElement(pPrimarySubcomponent = pDropdownList = new C4GUI::ComboBox(ca.GetAll())); pDropdownList->SetReadOnly(fReadOnly); pDropdownList->SetComboCB(new C4GUI::ComboBox_FillCallback<C4GameOptionsList::OptionDropdown>(this, &C4GameOptionsList::OptionDropdown::OnDropdownFill, &C4GameOptionsList::OptionDropdown::OnDropdownSelChange)); if (fIsPreGame) { pDropdownList->SetColors(C4StartupFontClr, C4StartupEditBGColor, C4StartupEditBorderColor); pDropdownList->SetFont(&rUseFont); pDropdownList->SetDecoration(&(C4Startup::Get()->Graphics.fctContext)); } // final init InitOption(pForDlg); }
C4ChartDialog::C4ChartDialog() : Dialog(DialogWidth, DialogHeight, LoadResStr("IDS_NET_STATISTICS"), false) { // register singleton pChartDlg = this; // add main chart switch component C4GUI::ComponentAligner caAll(GetContainedClientRect(), 5,5); pChartTabular = new C4GUI::Tabular(caAll.GetAll(), C4GUI::Tabular::tbTop); AddElement(pChartTabular); // add some graphs as subcomponents AddChart(StdStrBuf("oc")); AddChart(StdStrBuf("FPS")); AddChart(StdStrBuf("NetIO")); if (::Network.isEnabled()) AddChart(StdStrBuf("Pings")); AddChart(StdStrBuf("Control")); AddChart(StdStrBuf("APM")); }
C4StartupNetListEntry::C4StartupNetListEntry(C4GUI::ListBox *pForListBox, C4GUI::Element *pInsertBefore, C4StartupNetDlg *pNetDlg) : pNetDlg(pNetDlg), pList(pForListBox), pRefClient(nullptr), pRef(nullptr), fError(false), eQueryType(NRQT_Unknown), iTimeout(0), iInfoIconCount(0), iSortOrder(0), fIsSmall(false), fIsCollapsed(false), fIsEnabled(true), fIsImportant(false) { // calc height int32_t iLineHgt = ::GraphicsResource.TextFont.GetLineHeight(), iHeight = iLineHgt * 2 + 4; // add icons - normal icons use small size, only animated netgetref uses full size rctIconLarge.Set(0, 0, iHeight, iHeight); int32_t iSmallIcon = iHeight * 2 / 3; rctIconSmall.Set((iHeight - iSmallIcon)/2, (iHeight - iSmallIcon)/2, iSmallIcon, iSmallIcon); pIcon = new C4GUI::Icon(rctIconSmall, C4GUI::Ico_Host); AddElement(pIcon); SetBounds(pIcon->GetBounds()); // add to listbox (will get resized horizontally and moved) pForListBox->InsertElement(this, pInsertBefore); // add status icons and text labels now that width is known CStdFont *pUseFont = &(::GraphicsResource.TextFont); int32_t iIconSize = pUseFont->GetLineHeight(); C4Rect rcIconRect = GetContainedClientRect(); int32_t iThisWdt = rcIconRect.Wdt; rcIconRect.x = iThisWdt - iIconSize * (iInfoIconCount + 1); rcIconRect.Wdt = rcIconRect.Hgt = iIconSize; for (auto & pInfoIcon : pInfoIcons) { AddElement(pInfoIcon = new C4GUI::Icon(rcIconRect, C4GUI::Ico_None)); rcIconRect.x -= rcIconRect.Wdt; } C4Rect rcLabelBounds; rcLabelBounds.x = iHeight+3; rcLabelBounds.Hgt = iLineHgt; for (int i=0; i<InfoLabelCount; ++i) { C4GUI::Label *pLbl; rcLabelBounds.y = 1+i*(iLineHgt+2); rcLabelBounds.Wdt = iThisWdt - rcLabelBounds.x - 1; if (!i) rcLabelBounds.Wdt -= iLineHgt; // leave space for topright extra icon AddElement(pLbl = pInfoLbl[i] = new C4GUI::Label("", rcLabelBounds, ALeft, C4GUI_CaptionFontClr)); // label will have collapsed due to no text: Repair it pLbl->SetAutosize(false); pLbl->SetBounds(rcLabelBounds); } // update small state, which will resize this to a small entry UpdateSmallState(); // Set*-function will fill icon and text and calculate actual size }
C4FileSelDlg::DefaultListItem::DefaultListItem(const char *szFilename, bool fTruncateExtension, bool fCheckbox, bool fGrayed, C4GUI::Icons eIcon) : C4FileSelDlg::ListItem(szFilename), pLbl(NULL), pCheck(NULL), pKeyCheck(NULL), fGrayed(fGrayed) { StdStrBuf sLabel; if (szFilename) sLabel.Ref(::GetFilename(szFilename)); else sLabel.Ref(LoadResStr("IDS_CTL_NONE")); if (szFilename && fTruncateExtension) { sLabel.Copy(); char *szFilename = sLabel.GrabPointer(); RemoveExtension(szFilename); sLabel.Take(szFilename); } rcBounds.Hgt = C4GUI::GetRes()->TextFont.GetLineHeight(); UpdateSize(); C4GUI::ComponentAligner caMain(GetContainedClientRect(), 0, 0); int32_t iHeight = caMain.GetInnerHeight(); if (fCheckbox) { pCheck = new C4GUI::CheckBox(caMain.GetFromLeft(iHeight), NULL, false); if (fGrayed) pCheck->SetEnabled(false); AddElement(pCheck); pKeyCheck = new C4KeyBinding( C4KeyCodeEx(K_SPACE), "FileSelToggleFileActive", KEYSCOPE_Gui, new C4GUI::ControlKeyCB<ListItem>(*this, &ListItem::UserToggleCheck), C4CustomKey::PRIO_Ctrl); } C4GUI::Icon *pIco = new C4GUI::Icon(caMain.GetFromLeft(iHeight), eIcon); AddElement(pIco); pLbl = new C4GUI::Label( sLabel.getData(), caMain.GetAll(), ALeft, fGrayed ? C4GUI_CheckboxDisabledFontClr : C4GUI_CheckboxFontClr); AddElement(pLbl); }
void C4ChatControl::UpdateSize() { // parent update typedef C4GUI::Window ParentClass; ParentClass::UpdateSize(); // position child elements pTabMain->SetBounds(GetContainedClientRect()); pTabChats->SetBounds(pTabChats->GetParent()->GetContainedClientRect()); C4GUI::Tabular::Sheet *pSheetLogin = pTabMain->GetSheet(0); C4GUI::ComponentAligner caLoginSheet(pSheetLogin->GetContainedClientRect(), 0, 0, false); CStdFont *pUseFont = &C4GUI::GetRes()->TextFont; int32_t iIndent1 = C4GUI_DefDlgSmallIndent / 2, iIndent2 = C4GUI_DefDlgIndent / 2; int32_t iLoginHgt = pUseFont->GetLineHeight() * 8 + iIndent1 * 10 + iIndent2 * 10 + C4GUI_ButtonHgt + 20; int32_t iLoginWdt = iLoginHgt * 2 / 3; C4GUI::ComponentAligner caLogin( caLoginSheet.GetCentered( Min<int32_t>(iLoginWdt, caLoginSheet.GetInnerWidth()), Min<int32_t>(iLoginHgt, caLoginSheet.GetInnerHeight())), iIndent1, iIndent1); pLblLoginNick->SetBounds(caLogin.GetFromTop(pUseFont->GetLineHeight())); pEdtLoginNick->SetBounds( caLogin.GetFromTop(C4GUI::Edit::GetDefaultEditHeight())); caLogin.ExpandTop(2 * (iIndent1 - iIndent2)); pLblLoginPass->SetBounds(caLogin.GetFromTop(pUseFont->GetLineHeight())); pEdtLoginPass->SetBounds( caLogin.GetFromTop(C4GUI::Edit::GetDefaultEditHeight())); caLogin.ExpandTop(2 * (iIndent1 - iIndent2)); pLblLoginRealName->SetBounds(caLogin.GetFromTop(pUseFont->GetLineHeight())); pEdtLoginRealName->SetBounds( caLogin.GetFromTop(C4GUI::Edit::GetDefaultEditHeight())); caLogin.ExpandTop(2 * (iIndent1 - iIndent2)); pLblLoginChannel->SetBounds(caLogin.GetFromTop(pUseFont->GetLineHeight())); pEdtLoginChannel->SetBounds( caLogin.GetFromTop(C4GUI::Edit::GetDefaultEditHeight())); caLogin.ExpandTop(2 * (iIndent1 - iIndent2)); pBtnLogin->SetBounds(caLogin.GetFromTop(C4GUI_ButtonHgt, C4GUI_DefButtonWdt)); }
C4Network2ClientListBox::ConnectionListItem::ConnectionListItem(class C4Network2ClientListBox *pForDlg, int32_t iClientID, int32_t iConnectionID) // ctor : ListItem(pForDlg, iClientID), iConnID(iConnectionID), pDesc(nullptr), pPing(nullptr), pReconnectBtn(nullptr), pDisconnectBtn(nullptr) { // get size CStdFont &rUseFont = ::GraphicsResource.TextFont; int iIconSize = rUseFont.GetLineHeight(); int iWidth = pForDlg->GetItemWidth(); int iVerticalIndent = 2; SetBounds(C4Rect(0, 0, iWidth, iIconSize+2*iVerticalIndent)); C4GUI::ComponentAligner ca(GetContainedClientRect(), 0,iVerticalIndent); // left indent ca.ExpandLeft(-iIconSize*2); // create subcomponents // reconnect/disconnect buttons if (!Game.Parameters.isLeague()) { pDisconnectBtn = new C4GUI::CallbackButtonEx<C4Network2ClientListBox::ConnectionListItem, C4GUI::IconButton>(C4GUI::Ico_Disconnect, ca.GetFromRight(iIconSize, iIconSize), 0, this, &ConnectionListItem::OnButtonDisconnect); pDisconnectBtn->SetToolTip(LoadResStr("IDS_MENU_DISCONNECT")); } else pDisconnectBtn = nullptr; // ping time int32_t sx=40, sy=iIconSize; rUseFont.GetTextExtent("???? ms", sx,sy, true); pPing = new C4GUI::Label("???", ca.GetFromRight(sx, sy), ARight); pPing->SetToolTip(LoadResStr("IDS_NET_CONTROL_PING")); // main description item pDesc = new C4GUI::Label("???", ca.GetAll(), ALeft); // add components AddElement(pDesc); AddElement(pPing); if (pDisconnectBtn) AddElement(pDisconnectBtn); // add to listbox (will eventually get moved) pForDlg->AddElement(this); // first-time update Update(); }
C4Network2ClientListDlg::C4Network2ClientListDlg() : Dialog(::pGUI->GetPreferredDlgRect().Wdt*3/4, ::pGUI->GetPreferredDlgRect().Hgt*3/4, LoadResStr("IDS_NET_CAPTION"), false) { // component layout CStdFont *pUseFont = &::GraphicsResource.TextFont; C4GUI::ComponentAligner caAll(GetContainedClientRect(), 0,0); C4Rect rcStatus = caAll.GetFromBottom(pUseFont->GetLineHeight()); // create game options; max 1/2 of dialog height pGameOptions = new C4GameOptionsList(caAll.GetFromTop(caAll.GetInnerHeight()/2), true, C4GameOptionsList::GOLS_Runtime); pGameOptions->SetDecoration(false, nullptr, true, false); pGameOptions->SetSelectionDiabled(); // but resize to actually used height int32_t iFreedHeight = pGameOptions->ContractToElementHeight(); caAll.ExpandTop(iFreedHeight); AddElement(pGameOptions); // create client list box AddElement(pListBox = new C4Network2ClientListBox(caAll.GetAll(), false)); // create status label AddElement(pStatusLabel = new C4GUI::Label("", rcStatus)); // add timer Application.Add(this); // initial update Update(); }
void C4Menu::UpdateElementPositions() { // only if already shown and made visible by first drawing // this will postpone the call of menu initialization until it's really needed if (!IsVisible() || !pClientWindow) return; // reposition client scrolling window pClientWindow->SetBounds(GetContainedClientRect()); // re-stack all list items int xOff, yOff = 0; C4MenuItem *pCurr = static_cast<C4MenuItem *>(pClientWindow->GetFirst()), *pPrev = NULL; if (HasPortrait() && pCurr) { // recheck portrait xOff = C4MN_DlgPortraitWdt + C4MN_DlgPortraitIndent; C4Facet &fctPortrait = pCurr->Symbol; C4Rect rcPortraitBounds(0,0, C4MN_DlgPortraitWdt + C4MN_DlgPortraitIndent, fctPortrait.Hgt * C4MN_DlgPortraitWdt / std::max<int>(fctPortrait.Wdt, 1)); if (pCurr->GetBounds() != rcPortraitBounds) { pCurr->GetBounds() = rcPortraitBounds; pCurr->UpdateOwnPos(); } pCurr = static_cast<C4MenuItem *>(pCurr->GetNext()); } else xOff = 0; // recheck list items int32_t iMaxDlgOptionHeight = -1; int32_t iIndex = 0; C4Rect rcNewBounds(0,0,ItemWidth,ItemHeight); C4MenuItem *pFirstStack = pCurr, *pNext = pFirstStack; while ((pCurr = pNext)) { pNext = static_cast<C4MenuItem *>(pCurr->GetNext()); if (Style == C4MN_Style_Dialog) { // y-margin always, except between options if (!pPrev || (!pPrev->IsSelectable || !pCurr->IsSelectable)) yOff += C4MN_DlgLineMargin; else yOff += C4MN_DlgOptionLineMargin; // determine item height. StdStrBuf sText; int32_t iAssumedItemHeight = ::GraphicsResource.FontRegular.GetLineHeight(); int32_t iWdt, iAvailWdt = ItemWidth, iSymWdt; for (;;) { iSymWdt = std::min<int32_t>(pCurr->GetSymbolWidth(iAssumedItemHeight), iAvailWdt/2); iAvailWdt = ItemWidth - iSymWdt; ::GraphicsResource.FontRegular.BreakMessage(pCurr->Caption, iAvailWdt, &sText, true); ::GraphicsResource.FontRegular.GetTextExtent(sText.getData(),iWdt,rcNewBounds.Hgt, true); if (!iSymWdt || rcNewBounds.Hgt <= iAssumedItemHeight) break; // If there is a symbol, the symbol grows as more lines become available // Thus, less space is available for the text, and it might become larger iAssumedItemHeight = rcNewBounds.Hgt; } if (fEqualIconItemHeight && iSymWdt) { // force equal height for all symbol items if (iMaxDlgOptionHeight < 0) { // first selectable item inits field iMaxDlgOptionHeight = rcNewBounds.Hgt; } else if (rcNewBounds.Hgt <= iMaxDlgOptionHeight) { // following item height smaller or equal: Force equal rcNewBounds.Hgt = iMaxDlgOptionHeight; } else { // following item larger height: Need to re-stack from beginning iMaxDlgOptionHeight = rcNewBounds.Hgt; pNext = pFirstStack; pPrev = NULL; yOff = 0; iIndex = 0; continue; } } assert(iWdt <= iAvailWdt); rcNewBounds.x = 0; rcNewBounds.y = yOff; yOff += rcNewBounds.Hgt; } else { rcNewBounds.x = (iIndex % std::max<int32_t>(Columns, 1)) * ItemWidth; rcNewBounds.y = (iIndex / std::max<int32_t>(Columns, 1)) * ItemHeight; } rcNewBounds.x += xOff; if (pCurr->GetBounds() != rcNewBounds) { pCurr->GetBounds() = rcNewBounds; pCurr->UpdateOwnPos(); } ++iIndex; pPrev = pCurr; } // update scrolling pClientWindow->SetClientHeight(rcNewBounds.y + rcNewBounds.Hgt); // re-set caption C4MenuItem *pSel = GetSelectedItem(); const char *szCapt; if (pSel && Style == C4MN_Style_Normal) szCapt = pSel->Caption; else szCapt = Caption; SetTitle((*szCapt || Style == C4MN_Style_Dialog) ? szCapt : " ", HasMouse()); }
C4StartupAboutDlg::C4StartupAboutDlg() : C4StartupDlg("") { // ctor UpdateSize(); // key bindings: No longer back on any key pKeyBack = NULL; //C4CustomKey::CodeList keys; //keys.push_back(C4KeyCodeEx(KEY_Any)); keys.push_back(C4KeyCodeEx(KEY_JOY_AnyButton)); //pKeyBack = new C4KeyBinding(keys, "StartupAboutBack", KEYSCOPE_Gui, // new C4GUI::DlgKeyCB<C4StartupAboutDlg>(*this, &C4StartupAboutDlg::KeyBack), C4CustomKey::PRIO_Dlg); // version and registration info in topright corner C4Rect rcClient = GetContainedClientRect(); StdStrBuf sVersion; sVersion.Format(LoadResStr("IDS_DLG_VERSION"), C4VERSION); CStdFont &rUseFont = C4GUI::GetRes()->TextFont; int32_t iInfoWdt = Min<int32_t>(rcClient.Wdt/2, rUseFont.GetTextWidth("General info text width")*2); C4GUI::ComponentAligner caInfo(C4Rect(rcClient.x + rcClient.Wdt - iInfoWdt, rcClient.y, iInfoWdt, rcClient.Hgt/8), 0,0, false); AddElement(new C4GUI::Label(sVersion.getData(), caInfo.GetGridCell(0,1,0,4), ARight)); StdStrBuf sRegStr, sKeyFile; if (Config.Registered()) { StdStrBuf sRegName, sFirstName, sLastName, sNick; sFirstName.Copy(Config.GetRegistrationData("FirstName")); sLastName.Copy(Config.GetRegistrationData("LastName")); sNick.Copy(Config.GetRegistrationData("Nick")); sRegName.Format("%s %s (%s)", sFirstName.getData(), sLastName.getData(), sNick.getData()); sRegStr.Format(LoadResStr("IDS_PRC_REG"), sRegName.getData()); sKeyFile.Format(LoadResStr("IDS_CTL_KEYFILE")); sKeyFile+=" "; sKeyFile+=Config.GetKeyFilename(); C4GUI::Label *pLbl; AddElement(pLbl = new C4GUI::Label(sRegStr.getData(), caInfo.GetGridCell(0,1,1,4), ARight)); pLbl->SetToolTip(sKeyFile.getData()); AddElement(pLbl = new C4GUI::Label(FormatString("%s %s", LoadResStr("IDS_CTL_CUID"), Config.GetRegistrationData("Cuid")).getData(), caInfo.GetGridCell(0,1,2,4), ARight)); pLbl->SetToolTip(sKeyFile.getData()); AddElement(pWebCodeLbl = new C4GUI::Label("", caInfo.GetGridCell(0,1,3,4), ARight)); pWebCodeLbl ->SetToolTip(sKeyFile.getData()); } else { /*AddElement(new C4GUI::Label(FormatString("%s - %s", "FREEWARE", LoadResStr("IDS_CTL_UNREGISTERED")).getData(), caInfo.GetGridCell(0,1,1,4), ARight));*/ AddElement(new C4GUI::Label("FREEWARE", caInfo.GetGridCell(0,1,1,4), ARight)); AddElement(new C4GUI::Label(Config.GetRegistrationError(), caInfo.GetGridCell(0,1,2,4), ARight)); pWebCodeLbl = NULL; } // webcode-display timer iWebCodeTimer = C4AboutWebCodeShowTime + 1; pSec1Timer = new C4Sec1TimerCallback<C4StartupAboutDlg>(this); OnSec1Timer(); // bottom line buttons C4GUI::ComponentAligner caMain(rcClient, 0,0, true); C4GUI::ComponentAligner caButtons(caMain.GetFromBottom(caMain.GetHeight()*1/8), 0,0, false); C4GUI::CallbackButton<C4StartupAboutDlg> *btn; int32_t iButtonWidth = caButtons.GetInnerWidth() / 4; AddElement(btn = new C4GUI::CallbackButton<C4StartupAboutDlg>(LoadResStr("IDS_BTN_BACK"), caButtons.GetGridCell(0,3,0,1,iButtonWidth,C4GUI_ButtonHgt,true), &C4StartupAboutDlg::OnBackBtn)); btn->SetToolTip(LoadResStr("IDS_DLGTIP_BACKMAIN")); /*if (!Config.Registered()) { AddElement(btn = new C4GUI::CallbackButton<C4StartupAboutDlg>(LoadResStr("IDS_BTN_REGISTERNOW"), caButtons.GetGridCell(1,3,0,1,iButtonWidth,C4GUI_ButtonHgt,true), &C4StartupAboutDlg::OnRegisterBtn)); btn->SetToolTip(LoadResStr("IDS_DESC_GOTOTHEONLINEREGISTRATION")); }*/ #ifdef NETWORK AddElement(btn = new C4GUI::CallbackButton<C4StartupAboutDlg>(LoadResStr("IDS_BTN_CHECKFORUPDATES"), caButtons.GetGridCell(2,3,0,1,iButtonWidth,C4GUI_ButtonHgt,true), &C4StartupAboutDlg::OnUpdateBtn)); btn->SetToolTip(LoadResStr("IDS_DESC_CHECKONLINEFORNEWVERSIONS")); #endif }