C4DownloadDlg::C4DownloadDlg(const char *szDLType) : C4GUI::Dialog(C4GUI_ProgressDlgWdt, 100, FormatString(LoadResStr("IDS_CTL_DL_TITLE"), szDLType).getData(), false), szError(NULL)
{
#ifdef HAVE_WINSOCK
	fWinSock = AcquireWinSock();
#endif
	// add all elements - will be reposisioned when text is displayed
	AddElement(pIcon = new C4GUI::Icon(C4Rect(), C4GUI::Ico_NetWait));
	AddElement(pStatusLabel = new C4GUI::Label("", C4Rect(), ACenter, C4GUI_MessageFontClr, &::GraphicsResource.TextFont, false));
	pProgressBar = NULL; // created when necessary
	AddElement(pCancelBtn = new C4GUI::CancelButton(C4Rect()));
}
Example #2
0
Screen::Screen(int32_t tx, int32_t ty, int32_t twdt, int32_t thgt) : Window(), Mouse(tx+twdt/2, ty+thgt/2), pContext(NULL), fExclusive(true), pGamePadOpener(NULL)
	{
	// no dialog active
	pActiveDlg = NULL;
	// set size - calcs client area as well
	SetBounds(C4Rect(tx,ty,twdt,thgt));
	SetPreferredDlgRect(C4Rect(0,0,twdt,thgt));
	// set static var
	pScreen = this;
	// GamePad
	if (Application.pGamePadControl && Config.Controls.GamepadGuiControl) 
		pGamePadOpener = new C4GamePadOpener(0);
	}
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);
}
Example #4
0
C4FileSelDlg::ListItem::ListItem(const char *szFilename)
    : C4GUI::Control(C4Rect(0, 0, 0, 0)) {
  if (szFilename)
    sFilename.Copy(szFilename);
  else
    sFilename.Clear();
}
Example #5
0
void C4ScoreboardDlg::Update()
{
	// counts
	int32_t iRowCount = pBrd->iRows; int32_t iColCount = pBrd->iCols;
	delete [] piColWidths; piColWidths = nullptr;
	// invalid board - scipters can create those, but there's no reason why the engine
	// should display something pretty then; just keep dialog defaults
	if (!iRowCount || !iColCount) return;
	// calc sizes as max col widths plus some indent pixels
	piColWidths = new int32_t[iColCount];
	int32_t iWdt=XMargin*2, iHgt=YMargin*2;
	for (int32_t iCol = 0; iCol < iColCount; ++iCol)
	{
		piColWidths[iCol] = XIndent;
		for (int32_t iRow = 0; iRow < iRowCount; ++iRow)
		{
			C4Scoreboard::Entry *pCell = pBrd->GetCell(iCol, iRow);
			if ((iRow || iCol) && !pCell->Text.isNull()) piColWidths[iCol] = std::max<int32_t>(piColWidths[iCol], ::GraphicsResource.FontRegular.GetTextWidth(pCell->Text.getData()) + XIndent);
		}
		iWdt += piColWidths[iCol];
	}
	iHgt += iRowCount * (::GraphicsResource.FontRegular.GetLineHeight() + YIndent);
	const char *szTitle = pBrd->GetCell(0,0)->Text.getData();
	if (szTitle) iWdt = std::max<int32_t>(iWdt, ::GraphicsResource.FontRegular.GetTextWidth(szTitle) + 40);
	if (!pTitle != !szTitle) SetTitle(szTitle); // needed for title margin...
	iWdt += GetMarginLeft() + GetMarginRight();
	iHgt += GetMarginTop() + GetMarginBottom();
	// update dialog
	SetBounds(C4Rect(rcBounds.x, rcBounds.y, iWdt, iHgt));
	SetTitle(szTitle);
	if (szTitle && pTitle) pTitle->SetIcon(C4GUI::Icon::GetIconFacet(C4GUI::Ico_Player));
	// realign
	C4GUI::Screen *pScr = GetScreen();
	if (pScr) DoPlacement(pScr, pScr->GetPreferredDlgRect());
}
Example #6
0
void C4MouseControl::UpdateClip()
{
#ifdef _DEBUG
	// never in debug
	return;
#endif
#ifdef USE_WIN32_WINDOWS
	// fullscreen only
	if (Application.isEditor) return;
	// application or mouse control not active? remove any clips
	if (!Active || !Application.Active || ::pGUI->HasMouseFocus()) { ClipCursor(nullptr); return; }
	// get controlled viewport
	C4Viewport *pVP=::Viewports.GetViewport(Player);
	if (!pVP) { ClipCursor(nullptr); return; }
	// adjust size by viewport size
	RECT vpRct;
	vpRct.left=pVP->OutX; vpRct.top=pVP->OutY; vpRct.right=pVP->OutX+pVP->ViewWdt; vpRct.bottom=pVP->OutY+pVP->ViewHgt;
	// adjust by window pos
	RECT rtWindow;
	if (GetWindowRect(FullScreen.hWindow, &rtWindow))
	{
		vpRct.left += rtWindow.left; vpRct.top += rtWindow.top;
		vpRct.right += rtWindow.left; vpRct.bottom+= rtWindow.top;
	}
	ClipCursor(&vpRct);
	// and inform GUI
	::pGUI->SetPreferredDlgRect(C4Rect(pVP->OutX, pVP->OutY, pVP->ViewWdt, pVP->ViewHgt));
#endif
	//StdWindow manages this.
}
Example #7
0
void C4Menu::InitSize()
{
	C4GUI::Element *pLast = pClientWindow->GetLast();
	// Size calculation
	int Width, Height;
	Width=Columns*ItemWidth;
	Height=Lines*ItemHeight;
	VisibleCount = Columns*Lines;
	bool fBarNeeded;
	if (HasPortrait()) Width += C4MN_DlgPortraitWdt + C4MN_DlgPortraitIndent;
	// dialogs have auto-enlarge vertically
	if (pLast && Style == C4MN_Style_Dialog)
	{
		Height = std::max<int>(Height, pLast->GetBounds().y + pLast->GetBounds().Hgt + C4MN_DlgLineMargin);
		fBarNeeded = false;
	}
	else
		fBarNeeded = pLast && pLast->GetBounds().y + pLast->GetBounds().Hgt > pClientWindow->GetBounds().Hgt;
	// add dlg margins
	Width += GetMarginLeft() + GetMarginRight() + pClientWindow->GetMarginLeft() + pClientWindow->GetMarginRight();
	Height += GetMarginTop() + GetMarginBottom() + pClientWindow->GetMarginTop() + pClientWindow->GetMarginBottom();
	if (fBarNeeded) Width += C4GUI_ScrollBarWdt;
	SetBounds(C4Rect(rcBounds.x, rcBounds.y, Width, Height));
	pClientWindow->SetScrollBarEnabled(fBarNeeded);
	UpdateOwnPos();
}
Example #8
0
void C4FoWAmbient::CreateFromLandscape(const C4Landscape& landscape, double resolution, double radius, double full_coverage)
{
	assert(resolution >= 1.);
	assert(radius >= 1.);
	assert(full_coverage > 0 && full_coverage <= 1.);

	// Clear old map
	Clear();

	Resolution = resolution;
	Radius = radius;
	FullCoverage = full_coverage;

	// Number of zoomed pixels
	LandscapeX = Landscape.GetWidth();
	LandscapeY = Landscape.GetHeight();
	SizeX = std::min<unsigned int>(static_cast<unsigned int>(ceil(LandscapeX / resolution)), pDraw->MaxTexSize);
	SizeY = std::min<unsigned int>(static_cast<unsigned int>(ceil(LandscapeY / resolution)), pDraw->MaxTexSize);

#ifndef USE_CONSOLE
	glGenTextures(1, &Tex);
	glBindTexture(GL_TEXTURE_2D, Tex);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, SizeX, SizeY, 0, GL_RED, GL_FLOAT, nullptr);

	const C4TimeMilliseconds begin = C4TimeMilliseconds::Now();
	UpdateFromLandscape(landscape, C4Rect(0, 0, Landscape.GetWidth(), Landscape.GetHeight()));
	uint32_t dt = C4TimeMilliseconds::Now() - begin;
	LogF("Created %ux%u ambient map in %g secs", SizeX, SizeY, dt / 1000.);
#endif
}
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);
}
Example #10
0
	FacetButton::FacetButton(const C4Facet &rBaseFct, const C4Facet &rHighlightFct, const FLOAT_RECT &rtfBounds, char cHotkey)
			: Button("", C4Rect(rtfBounds)), fctBase(rBaseFct), fctHighlight(rHighlightFct), dwTextClrInact(0x7f000000), dwTextClrAct(0xff000000), rcfDrawBounds(rtfBounds), pFont(NULL), fFontZoom(1.0f)
	{
		// ctor
		this->cHotkey = cHotkey;
		iTxtOffX=iTxtOffY=0;
		byTxtAlign=ALeft;
	}
Example #11
0
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();
}
Example #12
0
bool FnParRect(C4MapScriptLayer *layer, C4ValueArray *rect, C4Rect *rc_bounds)
{
	// Convert rect parameter passed to script function to C4Rect structure
	// and makes sure it is completely contained in bounding rectangle of layer
	// rect==NULL defaults to bounding rectangle of layer
	*rc_bounds = layer->GetBounds();
	if (!rect) return true; // nil is OK for rect parameter. Defaults to bounds rectangle
	if (rect->GetSize() != 4) return false;
	rc_bounds->Intersect(C4Rect(rect->GetItem(0).getInt(), rect->GetItem(1).getInt(), rect->GetItem(2).getInt(), rect->GetItem(3).getInt()));
	return true;
}
Example #13
0
C4ChatControl::ChatSheet::ChatSheet(C4ChatControl *pChatControl,
                                    const char *szTitle, const char *szIdent,
                                    SheetType eType)
    : C4GUI::Tabular::Sheet(szTitle, C4Rect(0, 0, 10, 10), C4GUI::Ico_None,
                            true, false),
      iBackBufferIndex(-1),
      eType(eType),
      pNickList(NULL),
      pInputLbl(NULL),
      pChatControl(pChatControl),
      fHasUnread(false) {
  if (szIdent) sIdent.Copy(szIdent);
  // create elements - positioned later
  C4Rect rcDefault(0, 0, 10, 10);
  pChatBox = new C4GUI::TextWindow(rcDefault);
  // pChatBox->SetToolTip(LoadResStr("IDS_DLGTIP_CHATWIN")); tooltip doesn't
  // really help, only makes things unübersichtlich
  pChatBox->SetDecoration(false, false, NULL, false);
  AddElement(pChatBox);
  if (eType == CS_Channel) {
    pNickList = new C4GUI::ListBox(rcDefault);
    pNickList->SetDecoration(false, NULL, true, false);
    pNickList->SetSelectionDblClickFn(
        new C4GUI::CallbackHandler<C4ChatControl::ChatSheet>(
            this, &C4ChatControl::ChatSheet::OnNickDblClick));
    AddElement(pNickList);
  }
  if (eType != CS_Server)
    pInputLbl = new C4GUI::WoodenLabel(LoadResStr("IDS_DLG_CHAT"), rcDefault,
                                       C4GUI_CaptionFontClr,
                                       &C4GUI::GetRes()->TextFont);
  pInputEdit = new C4GUI::CallbackEdit<C4ChatControl::ChatSheet>(
      rcDefault, this, &C4ChatControl::ChatSheet::OnChatInput);
  pInputEdit->SetToolTip(LoadResStr("IDS_DLGTIP_CHAT"));
  if (pInputLbl) {
    pInputLbl->SetToolTip(LoadResStr("IDS_DLGTIP_CHAT"));
    pInputLbl->SetClickFocusControl(pInputEdit);
    AddElement(pInputLbl);
  }
  AddElement(pInputEdit);
  // key bindings
  pKeyHistoryUp = new C4KeyBinding(
      C4KeyCodeEx(K_UP), "ChatHistoryUp", KEYSCOPE_Gui,
      new C4GUI::DlgKeyCBEx<C4ChatControl::ChatSheet, bool>(
          *this, true, &C4ChatControl::ChatSheet::KeyHistoryUpDown),
      C4CustomKey::PRIO_CtrlOverride);
  pKeyHistoryDown = new C4KeyBinding(
      C4KeyCodeEx(K_DOWN), "ChatHistoryDown", KEYSCOPE_Gui,
      new C4GUI::DlgKeyCBEx<C4ChatControl::ChatSheet, bool>(
          *this, false, &C4ChatControl::ChatSheet::KeyHistoryUpDown),
      C4CustomKey::PRIO_CtrlOverride);
}
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);
}
Example #15
0
C4PortraitSelDlg::ListItem::ListItem(const char *szFilename)
    : C4FileSelDlg::ListItem(szFilename), fError(false), fLoaded(false) {
  CStdFont *pUseFont = &(C4GUI::GetRes()->MiniFont);
  // determine label text
  StdStrBuf sDisplayLabel;
  if (szFilename) {
    sDisplayLabel.Copy(::GetFilename(szFilename));
    ::RemoveExtension(&sDisplayLabel);
  } else {
    sDisplayLabel.Ref(LoadResStr("IDS_MSG_NOPORTRAIT"));
  }
  // insert linebreaks into label text
  int32_t iLineHgt = Max<int32_t>(
      pUseFont->BreakMessage(sDisplayLabel.getData(), ImagePreviewSize - 6,
                             &sFilenameLabelText, false),
      1);
  // set size
  SetBounds(C4Rect(0, 0, ImagePreviewSize, ImagePreviewSize + iLineHgt));
}
Example #16
0
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();
}
void C4GraphicsSystem::RecalculateViewports()
	{

	// Fullscreen only
	if (!Application.isFullScreen) return;

	// Sort viewports
	SortViewportsByPlayerControl();

	// Viewport area
	int32_t iBorderTop = 0, iBorderBottom = 0;
	if (Config.Graphics.UpperBoard) 
		iBorderTop = C4UpperBoardHeight;
	iBorderBottom = MessageBoard.Output.Hgt;
	ViewportArea.Set(Application.DDraw->lpBack,0,iBorderTop, Config.Graphics.ResX, Config.Graphics.ResY-iBorderTop-iBorderBottom);

	// Redraw flag
	InvalidateBg();
#ifdef _WIN32
	// reset mouse clipping
	ClipCursor(NULL);
#else
	// StdWindow handles this.
#endif
	// reset GUI dlg pos
	if (Game.pGUI)
		Game.pGUI->SetPreferredDlgRect(C4Rect(ViewportArea.X, ViewportArea.Y, ViewportArea.Wdt, ViewportArea.Hgt));

	// fullscreen background: First, cover all of screen
	BackgroundAreas.Clear();
	BackgroundAreas.AddRect(C4Rect(ViewportArea.X, ViewportArea.Y, ViewportArea.Wdt, ViewportArea.Hgt));

	// Viewports
	C4Viewport *cvp;
	int32_t iViews = 0;
	for (cvp=FirstViewport; cvp; cvp=cvp->Next) iViews++;
	if (!iViews) return;
	int32_t iViewsH = (int32_t) sqrt(float(iViews));
	int32_t iViewsX = iViews / iViewsH;
	int32_t iViewsL = iViews % iViewsH;
	int32_t cViewH,cViewX,ciViewsX;
	int32_t cViewWdt,cViewHgt,cOffWdt,cOffHgt,cOffX,cOffY;
	cvp=FirstViewport;
	for (cViewH=0; cViewH<iViewsH; cViewH++)
		{
		ciViewsX = iViewsX;	if (cViewH<iViewsL) ciViewsX++;
		for (cViewX=0; cViewX<ciViewsX; cViewX++)
			{
			cViewWdt = ViewportArea.Wdt/ciViewsX;
			cViewHgt = ViewportArea.Hgt/iViewsH;
			cOffX = ViewportArea.X;
			cOffY = ViewportArea.Y;
			cOffWdt=cOffHgt=0;
			int32_t ViewportScrollBorder = Application.isFullScreen ? C4ViewportScrollBorder : 0;
			if (ciViewsX*Min<int32_t>(cViewWdt, GBackWdt+2*ViewportScrollBorder)<ViewportArea.Wdt)
				cOffX=(ViewportArea.Wdt-ciViewsX*Min<int32_t>(cViewWdt, GBackWdt+2*ViewportScrollBorder))/2;
			if (iViewsH*Min<int32_t>(cViewHgt, GBackHgt+2*ViewportScrollBorder)<ViewportArea.Hgt)
				cOffY=(ViewportArea.Hgt-iViewsH*Min<int32_t>(cViewHgt, GBackHgt+2*ViewportScrollBorder))/2 + ViewportArea.Y;
			if (Config.Graphics.SplitscreenDividers) 
				{
				if (cViewX<ciViewsX-1) cOffWdt=4;
				if (cViewH<iViewsH-1) cOffHgt=4;
				}
			int32_t coViewWdt=cViewWdt-cOffWdt; if (coViewWdt>GBackWdt+2*ViewportScrollBorder) { coViewWdt=GBackWdt+2*ViewportScrollBorder; }
			int32_t coViewHgt=cViewHgt-cOffHgt; if (coViewHgt>GBackHgt+2*ViewportScrollBorder) { coViewHgt=GBackHgt+2*ViewportScrollBorder; }
			C4Rect rcOut(cOffX+cViewX*cViewWdt, cOffY+cViewH*cViewHgt, coViewWdt, coViewHgt);
			cvp->SetOutputSize(rcOut.x,rcOut.y,rcOut.x,rcOut.y,rcOut.Wdt,rcOut.Hgt);
			cvp=cvp->Next;
			// clip down area avaiable for background drawing
			BackgroundAreas.ClipByRect(rcOut);
			}
		}
	}
Example #18
0
void C4LArea::Set(C4LSectors *pSectors, C4Object *pObj)
{
	// set to object facet rect
	Set(pSectors, C4Rect(pObj->Left(), pObj->Top(), pObj->Width(), pObj->Height()));
}
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
	}
Example #20
0
C4FindObject *C4FindObject::CreateByValue(const C4Value &DataVal,
                                          C4SortObject **ppSortObj) {
  // Must be an array
  C4ValueArray *pArray = C4Value(DataVal).getArray();
  if (!pArray) return NULL;

  const C4ValueArray &Data = *pArray;
  int32_t iType = Data[0].getInt();
  if (Inside<int32_t>(iType, C4SO_First, C4SO_Last)) {
    // this is not a FindObject but a sort condition!
    // sort condition not desired here?
    if (!ppSortObj) return NULL;
    // otherwise, create it!
    *ppSortObj = C4SortObject::CreateByValue(iType, Data);
    // done
    return NULL;
  }

  switch (iType) {
    case C4FO_Not: {
      // Create child condition
      C4FindObject *pCond = C4FindObject::CreateByValue(Data[1]);
      if (!pCond) return NULL;
      // wrap
      return new C4FindObjectNot(pCond);
    }

    case C4FO_And:
    case C4FO_Or: {
      // Trivial case (one condition)
      if (Data.GetSize() == 2) return C4FindObject::CreateByValue(Data[1]);
      // Create all childs
      int32_t i;
      C4FindObject **ppConds = new C4FindObject *[Data.GetSize() - 1];
      for (i = 0; i < Data.GetSize() - 1; i++)
        ppConds[i] = C4FindObject::CreateByValue(Data[i + 1]);
      // Count real entries, move them to start of list
      int32_t iSize = 0;
      for (i = 0; i < Data.GetSize() - 1; i++)
        if (ppConds[i])
          if (iSize++ != i) ppConds[iSize - 1] = ppConds[i];
      // Create
      if (iType == C4FO_And)
        return new C4FindObjectAnd(iSize, ppConds);
      else
        return new C4FindObjectOr(iSize, ppConds);
    }

    case C4FO_Exclude:
      return new C4FindObjectExclude(Data[1].getObj());

    case C4FO_ID:
      return new C4FindObjectID(Data[1].getC4ID());

    case C4FO_InRect:
      return new C4FindObjectInRect(C4Rect(Data[1].getInt(), Data[2].getInt(),
                                           Data[3].getInt(), Data[4].getInt()));

    case C4FO_AtPoint:
      return new C4FindObjectAtPoint(Data[1].getInt(), Data[2].getInt());

    case C4FO_AtRect:
      return new C4FindObjectAtRect(Data[1].getInt(), Data[2].getInt(),
                                    Data[3].getInt(), Data[4].getInt());

    case C4FO_OnLine:
      return new C4FindObjectOnLine(Data[1].getInt(), Data[2].getInt(),
                                    Data[3].getInt(), Data[4].getInt());

    case C4FO_Distance:
      return new C4FindObjectDistance(Data[1].getInt(), Data[2].getInt(),
                                      Data[3].getInt());

    case C4FO_OCF:
      return new C4FindObjectOCF(Data[1].getInt());

    case C4FO_Category:
      return new C4FindObjectCategory(Data[1].getInt());

    case C4FO_Action: {
      C4String *pStr = Data[1].getStr();
      if (!pStr) return NULL;
      // Don't copy, it should be safe
      return new C4FindObjectAction(pStr->Data.getData());
    }

    case C4FO_Func: {
      // Get function name
      C4String *pStr = Data[1].getStr();
      if (!pStr) return NULL;
      // Construct
      C4FindObjectFunc *pFO = new C4FindObjectFunc(pStr->Data.getData());
      // Add parameters
      for (int i = 2; i < Data.GetSize(); i++) pFO->SetPar(i - 2, Data[i]);
      // Done
      return pFO;
    }

    case C4FO_ActionTarget: {
      int index = 0;
      if (Data.GetSize() >= 3) index = BoundBy(Data[2].getInt(), 0, 1);
      return new C4FindObjectActionTarget(Data[1].getObj(), index);
    }

    case C4FO_Container:
      return new C4FindObjectContainer(Data[1].getObj());

    case C4FO_AnyContainer:
      return new C4FindObjectAnyContainer();

    case C4FO_Owner:
      return new C4FindObjectOwner(Data[1].getInt());

    case C4FO_Controller:
      return new C4FindObjectController(Data[1].getInt());

    case C4FO_Layer:
      return new C4FindObjectLayer(Data[1].getObj());
  }
  return NULL;
}
void C4LandscapeRenderClassic::Update(C4Rect To, C4Landscape *pSource)
{
	// clip to landscape size
	To.Intersect(C4Rect(0,0,iWidth,iHeight));
	// everything clipped?
	if (To.Wdt<=0 || To.Hgt<=0) return;
	if (!Surface32->Lock()) return;

	// We clear the affected region here because ClearBoxDw allocates the
	// main memory buffer for the box, so that only that box needs to be
	// sent to the gpu, and not the whole texture, or every pixel
	// separately. It's an important optimization.
	Surface32->ClearBoxDw(To.x, To.y, To.Wdt, To.Hgt);

	// do lightning
	for (int32_t iX=To.x; iX<To.x+To.Wdt; ++iX)
	{
		int AboveDensity = 0, BelowDensity = 0;
		for (int i = 1; i <= 8; ++i)
		{
			AboveDensity += pSource->GetPlacement(iX, To.y - i - 1);
			BelowDensity += pSource->GetPlacement(iX, To.y + i - 1);
		}
		for (int32_t iY=To.y; iY<To.y+To.Hgt; ++iY)
		{
			AboveDensity -= pSource->GetPlacement(iX, iY - 9);
			AboveDensity += pSource->GetPlacement(iX, iY - 1);
			BelowDensity -= pSource->GetPlacement(iX, iY);
			BelowDensity += pSource->GetPlacement(iX, iY + 8);
			BYTE pix = pSource->_GetPix(iX, iY);
			// Sky
			if (!pix)
			{
				Surface32->SetPixDw(iX, iY, 0x00ffffff);
				continue;
			}
			// get density
			int iOwnDens = pSource->_GetPlacement(iX, iY);
			if (!iOwnDens) continue;
			iOwnDens *= 2;
			iOwnDens += pSource->GetPlacement(iX + 1, iY) + pSource->GetPlacement(iX - 1, iY);
			iOwnDens /= 4;
			// get texture map entry for pixel
			const C4TexMapEntry *pTex = pTexs->GetEntry(PixCol2Tex(pix));
			assert(pTex);
			// get texture contents
			DWORD dwBackClr = 0u;
			if (pTex) dwBackClr = pTex->GetPattern().PatternClr(iX, iY);
			// get density of surrounding materials
			int iCompareDens = AboveDensity / 8;
			if (iOwnDens > iCompareDens)
			{
				// apply light
				LightenClrBy(dwBackClr, std::min(30, 2 * (iOwnDens - iCompareDens)));
			}
			else if (iOwnDens < iCompareDens && iOwnDens < 30)
			{
				DarkenClrBy(dwBackClr, std::min(30, 2 * (iCompareDens - iOwnDens)));
			}
			iCompareDens = BelowDensity / 8;
			if (iOwnDens > iCompareDens)
			{
				DarkenClrBy(dwBackClr, std::min(30, 2 * (iOwnDens - iCompareDens)));
			}
			Surface32->SetPixDw(iX, iY, dwBackClr);
		}
	}
	Surface32->Unlock();
}
Example #22
0
void C4LandscapeRenderGL::Update(C4Rect To, C4Landscape *pSource)
{
	// clip to landscape size
	To.Intersect(C4Rect(0,0,iWidth,iHeight));
	// everything clipped?
	if (To.Wdt<=0 || To.Hgt<=0) return;

	// Lock surfaces
	// We clear the affected region here because ClearBoxDw allocates the
	// main memory buffer for the box, so that only that box needs to be
	// sent to the gpu, and not the whole texture, or every pixel
	// separately. It's an important optimization.
	for (int i = 0; i < C4LR_SurfaceCount; i++)
	{
		if (!Surfaces[i]->Lock()) return;
		Surfaces[i]->ClearBoxDw(To.x, To.y, To.Wdt, To.Hgt);
	}

	// Initialize up & down placement arrays. These arrays are always updated
	// so that they contain the placement sums of C4LR_BiasDistanceY pixels
	// above and below the current row.
	int x, y;
	int placementSumsWidth = C4LR_BiasDistanceX * 2 + To.Wdt;
	int *placementSumsUp = new int [placementSumsWidth * 2];
	int *placementSumsDown = placementSumsUp + placementSumsWidth;
	for(x = 0; x < placementSumsWidth; x++)
	{
		placementSumsUp[x] = 0;
		placementSumsDown[x] = 0;
		if (To.x + x - C4LR_BiasDistanceX < 0 || To.x + x - C4LR_BiasDistanceX >= iWidth) continue;
		for(y = 1; y <= std::min(C4LR_BiasDistanceY, To.y); y++)
			placementSumsUp[x] += pSource->_GetPlacement(To.x+x-C4LR_BiasDistanceX, To.y-y);
		for(y = 1; y <= std::min(C4LR_BiasDistanceY, iHeight - 1 - To.y); y++)
			placementSumsDown[x] += pSource->_GetPlacement(To.x+x-C4LR_BiasDistanceX, To.y+y);
	}

	// Get tex refs (shortcut, we will use them quite heavily)
	C4TexRef *texture[C4LR_SurfaceCount];
	x = y = 0;
	for(int i = 0; i < C4LR_SurfaceCount; i++)
		texture[i] = Surfaces[i]->texture.get();

	// Go through it from top to bottom
	for(y = 0; y < To.Hgt; y++)
	{
		// Initialize left & right placement sums. These are meant to contain
		// the placement sum of a (C4LR_BiasDistanceX, 2*C4LR_BiasDistanceY+1)
		// rectangle left/right of the current pixel. So we initialise it to
		// be correct at x=0. Note that the placementSum arrays don't contain
		// information about the current row, therefore we need a special case
		// for those pixels.
		int sumLeft = 0, sumRight = 0;
		for(x = 1; x <= std::min(C4LR_BiasDistanceX, To.x); x++)
			sumLeft += pSource->_GetPlacement(To.x-x,To.y+y);
		for(x = 1; x <= std::min(C4LR_BiasDistanceX, iWidth - 1 - To.x ); x++)
			sumRight += pSource->_GetPlacement(To.x+x,To.y+y);
		for (int i = 1; i <= C4LR_BiasDistanceX; i++) {
			sumLeft += placementSumsUp[C4LR_BiasDistanceX - i];
			sumLeft += placementSumsDown[C4LR_BiasDistanceX - i];
			sumRight += placementSumsUp[C4LR_BiasDistanceX + i];
			sumRight += placementSumsDown[C4LR_BiasDistanceX + i];
		}

		// Initialise up & down sums. Same principle as above, but slightly
		// easier as we do not miss pixels if we just use the placement sums.
		int sumUp = 0, sumDown = 0;
		for (int i = -C4LR_BiasDistanceX; i <= C4LR_BiasDistanceX; i++) {
			sumUp += placementSumsUp[C4LR_BiasDistanceX + i];
			sumDown += placementSumsDown[C4LR_BiasDistanceX + i];
		}

		for(x = 0; x < To.Wdt; x++)
		{
			int pixel = pSource->_GetPix(To.x+x, To.y+y);
			int placement = pSource->_GetPlacement(To.x+x, To.y+y);

			// Calculate bias. The scale here is the size of the rectangle (see above)
			const int horizontalFactor = C4LR_BiasDistanceX * (2 * C4LR_BiasDistanceY + 1);
			int horizontalBias = std::max(0, placement * horizontalFactor - sumRight) -
			                     std::max(0, placement * horizontalFactor - sumLeft);
			const int verticalFactor = C4LR_BiasDistanceY * (2 * C4LR_BiasDistanceX + 1);
			int verticalBias = std::max(0, placement * verticalFactor - sumDown) -
			                   std::max(0, placement * verticalFactor - sumUp);

			// Maximum placement differences that make a difference in the result,  after which we are at the limits of
			// what can be packed into a byte
			const int maximumPlacementDifference = 40;
			int horizontalBiasScaled = Clamp(horizontalBias * 127 / maximumPlacementDifference / horizontalFactor + 128, 0, 255);
			int verticalBiasScaled = Clamp(verticalBias * 127 / maximumPlacementDifference / verticalFactor + 128, 0, 255);

			// Collect data to save per pixel
			unsigned char data[C4LR_SurfaceCount * 4];
			memset(data, 0, sizeof(data));

			data[C4LR_Material] = pixel;
			data[C4LR_BiasX] = horizontalBiasScaled;
			data[C4LR_BiasY] = verticalBiasScaled;
			data[C4LR_Scaler] = CalculateScalerBitmask(x, y, To, pSource);
			data[C4LR_Place] = placement;

			for(int i = 0; i < C4LR_SurfaceCount; i++)
				texture[i]->SetPix(To.x+x, To.y+y, 
					RGBA(data[i*4+0], data[i*4+1], data[i*4+2], data[i*4+3]));

			// Update sums (last column would be out-of-bounds, and not
			// necessary as we will re-initialise it for the next row)
			if (x < To.Wdt - 1) {
				sumLeft -= placementSumsUp[x] + placementSumsDown[x];
				sumLeft += placementSumsUp[x + C4LR_BiasDistanceX] + placementSumsDown[x + C4LR_BiasDistanceX];
				sumRight -= placementSumsUp[x + C4LR_BiasDistanceX + 1] + placementSumsDown[x + C4LR_BiasDistanceX + 1];
				sumUp -= placementSumsUp[x];
				sumDown -= placementSumsDown[x];
				sumRight += placementSumsUp[x + 2 * C4LR_BiasDistanceX + 1] + placementSumsDown[x + 2 * C4LR_BiasDistanceX + 1];
				sumUp += placementSumsUp[x + 2 * C4LR_BiasDistanceX + 1];
				sumDown += placementSumsDown[x + 2 * C4LR_BiasDistanceX + 1];
			}

			// Update left & right for next pixel in line
			if(x + To.x + 1 < iWidth)
				sumRight -= pSource->_GetPlacement(To.x+x + 1, To.y+y);
			if(To.x+x + C4LR_BiasDistanceX + 1 < iWidth)
				sumRight += pSource->_GetPlacement(To.x+x + C4LR_BiasDistanceX + 1, To.y+y);
			sumLeft += placement;
			if(To.x+x - C4LR_BiasDistanceX >= 0)
				sumLeft -= pSource->_GetPlacement(To.x+x - C4LR_BiasDistanceX, To.y+y);

			// Update up & down arrays (for next line already)
			if (To.x + x >= C4LR_BiasDistanceX) {
				if (To.y + y + 1 < iHeight)
					placementSumsDown[x] -= pSource->_GetPlacement(To.x + x - C4LR_BiasDistanceX, To.y + y + 1);
				if (To.y + y + C4LR_BiasDistanceY + 1 < iHeight)
					placementSumsDown[x] += pSource->_GetPlacement(To.x + x - C4LR_BiasDistanceX, To.y + y + C4LR_BiasDistanceY + 1);
				if (To.y + y - C4LR_BiasDistanceY >= 0)
					placementSumsUp[x] -= pSource->_GetPlacement(To.x + x - C4LR_BiasDistanceX, To.y + y - C4LR_BiasDistanceY);
				placementSumsUp[x] += pSource->_GetPlacement(To.x + x - C4LR_BiasDistanceX, To.y + y);
			}
		}

		// Finish updating up & down arrays for the next line
		if (To.x + x >= C4LR_BiasDistanceX)
		{
			for (; x < std::min(placementSumsWidth, iWidth - To.x + C4LR_BiasDistanceX); x++) {
				if (To.y + y + 1 < iHeight)
					placementSumsDown[x] -= pSource->_GetPlacement(To.x + x - C4LR_BiasDistanceX, To.y + y + 1);
				if (To.y + y + C4LR_BiasDistanceY + 1 < iHeight)
					placementSumsDown[x] += pSource->_GetPlacement(To.x + x - C4LR_BiasDistanceX, To.y + y + C4LR_BiasDistanceY + 1);
				if (To.y + y - C4LR_BiasDistanceY >= 0)
					placementSumsUp[x] -= pSource->_GetPlacement(To.x + x - C4LR_BiasDistanceX, To.y + y - C4LR_BiasDistanceY);
				placementSumsUp[x] += pSource->_GetPlacement(To.x + x - C4LR_BiasDistanceX, To.y + y);
			}
		}
	}

	// done
	delete[] placementSumsUp;
	for (int i = 0; i < C4LR_SurfaceCount; i++)
		Surfaces[i]->Unlock();
}
Example #23
0
C4FindObject *C4FindObject::CreateByValue(const C4Value &DataVal, C4SortObject **ppSortObj, const C4Object *context, bool *has_layer_check)
{
	// Must be an array
	C4ValueArray *pArray = C4Value(DataVal).getArray();
	if (!pArray) return NULL;

	const C4ValueArray &Data = *pArray;
	int32_t iType = Data[0].getInt();
	if (Inside<int32_t>(iType, C4SO_First, C4SO_Last))
	{
		// this is not a FindObject but a sort condition!
		// sort condition not desired here?
		if (!ppSortObj) return NULL;
		// otherwise, create it!
		*ppSortObj = C4SortObject::CreateByValue(iType, Data, context);
		// done
		return NULL;
	}

	switch (iType)
	{
	case C4FO_Not:
	{
		// Create child condition
		C4FindObject *pCond = C4FindObject::CreateByValue(Data[1], nullptr, context, has_layer_check);
		if (!pCond) return NULL;
		// wrap
		return new C4FindObjectNot(pCond);
	}

	case C4FO_And: case C4FO_Or:
	{
		// Trivial case (one condition)
		if (Data.GetSize() == 2)
			return C4FindObject::CreateByValue(Data[1], nullptr, context, has_layer_check);
		// Create all childs
		int32_t i;
		C4FindObject **ppConds = new C4FindObject *[Data.GetSize() - 1];
		for (i = 0; i < Data.GetSize() - 1; i++)
			ppConds[i] = C4FindObject::CreateByValue(Data[i + 1], nullptr, context, has_layer_check);
		// Count real entries, move them to start of list
		int32_t iSize = 0;
		for (i = 0; i < Data.GetSize() - 1; i++)
			if (ppConds[i])
				if (iSize++ != i)
					ppConds[iSize-1] = ppConds[i];
		// Create
		if (iType == C4FO_And)
			return new C4FindObjectAnd(iSize, ppConds);
		else
			return new C4FindObjectOr(iSize, ppConds);
	}

	case C4FO_Exclude:
		return new C4FindObjectExclude(Data[1].getObj());

	case C4FO_ID:
		return new C4FindObjectDef(Data[1].getPropList());


	// #973: For all criteria using coordinates: If FindObject et al. are called in object context, offset by object center
	case C4FO_InRect:
	{
		int32_t x = Data[1].getInt();
		int32_t y = Data[2].getInt();
		int32_t w = Data[3].getInt();
		int32_t h = Data[4].getInt();
		if (context)
		{
			x += context->GetX();
			y += context->GetY();
		}
		return new C4FindObjectInRect(C4Rect(x, y, w, h));
	}

	case C4FO_AtPoint:
	{
		int32_t x = Data[1].getInt();
		int32_t y = Data[2].getInt();
		if (context)
		{
			x += context->GetX();
			y += context->GetY();
		}
		return new C4FindObjectAtPoint(x, y);
	}

	case C4FO_AtRect:
	{
		int32_t x = Data[1].getInt();
		int32_t y = Data[2].getInt();
		int32_t w = Data[3].getInt();
		int32_t h = Data[4].getInt();
		if (context)
		{
			x += context->GetX();
			y += context->GetY();
		}
		return new C4FindObjectAtRect(x, y, w, h);
	}

	case C4FO_OnLine:
	{
		int32_t x1 = Data[1].getInt();
		int32_t y1 = Data[2].getInt();
		int32_t x2 = Data[3].getInt();
		int32_t y2 = Data[4].getInt();
		if (context)
		{
			x1 += context->GetX();
			x2 += context->GetX();
			y1 += context->GetY();
			y2 += context->GetY();
		}
		return new C4FindObjectOnLine(x1, y1, x2, y2);
	}

	case C4FO_Distance:
	{
		int32_t x = Data[1].getInt();
		int32_t y = Data[2].getInt();
		if (context)
		{
			x += context->GetX();
			y += context->GetY();
		}
		return new C4FindObjectDistance(x, y, Data[3].getInt());
	}

	case C4FO_OCF:
		return new C4FindObjectOCF(Data[1].getInt());

	case C4FO_Category:
		return new C4FindObjectCategory(Data[1].getInt());

	case C4FO_Action:
	{
		C4String *pStr = Data[1].getStr();
		if (!pStr) return NULL;
		// Don't copy, it should be safe
		return new C4FindObjectAction(pStr->GetCStr());
	}

	case C4FO_Func:
	{
		// Get function name
		C4String *pStr = Data[1].getStr();
		if (!pStr) return NULL;
		// Construct
		C4FindObjectFunc *pFO = new C4FindObjectFunc(pStr);
		// Add parameters
		for (int i = 2; i < Data.GetSize(); i++)
			pFO->SetPar(i - 2, Data[i]);
		// Done
		return pFO;
	}

	case C4FO_ActionTarget:
	{
		int index = 0;
		if (Data.GetSize() >= 3)
			index = Clamp(Data[2].getInt(), 0, 1);
		return new C4FindObjectActionTarget(Data[1].getObj(), index);
	}

	case C4FO_Procedure:
		return new C4FindObjectProcedure(Data[1].getStr());

	case C4FO_Container:
		return new C4FindObjectContainer(Data[1].getObj());

	case C4FO_AnyContainer:
		return new C4FindObjectAnyContainer();

	case C4FO_Owner:
		return new C4FindObjectOwner(Data[1].getInt());

	case C4FO_Controller:
		return new C4FindObjectController(Data[1].getInt());

	case C4FO_Layer:
		// explicit layer check given. do not add implicit layer check
		if (has_layer_check) *has_layer_check = true;
		return new C4FindObjectLayer(Data[1].getObj());

	case C4FO_InArray:
		return new C4FindObjectInArray(Data[1].getArray());

	case C4FO_Property:
	{
		// Get property name
		C4String *pStr = Data[1].getStr();
		if (!pStr) return NULL;
		// Construct
		C4FindObjectProperty *pFO = new C4FindObjectProperty(pStr);
		// Done
		return pFO;
	}

	case C4FO_AnyLayer:
		// do not add implicit layer check
		if (has_layer_check) *has_layer_check = true;
		return NULL;

	}
	return NULL;
}
Example #24
0
C4ChatInputDialog::C4ChatInputDialog(bool fObjInput, C4Object *pScriptTarget,
                                     bool fUppercase, bool fTeam, int32_t iPlr,
                                     const StdStrBuf &rsInputQuery)
    : C4GUI::InputDialog(
          fObjInput ? rsInputQuery.getData() : LoadResStrNoAmp("IDS_CTL_CHAT"),
          NULL, C4GUI::Ico_None, NULL,
          !fObjInput || IsSmallInputQuery(rsInputQuery.getData())),
      fObjInput(fObjInput),
      fUppercase(fUppercase),
      pTarget(pScriptTarget),
      BackIndex(-1),
      iPlr(iPlr),
      fProcessed(false) {
  // singleton-var
  pInstance = this;
  // set custom edit control
  SetCustomEdit(new C4GUI::CallbackEdit<C4ChatInputDialog>(
      C4Rect(0, 0, 10, 10), this, &C4ChatInputDialog::OnChatInput,
      &C4ChatInputDialog::OnChatCancel));
  // key bindings
  pKeyHistoryUp =
      new C4KeyBinding(C4KeyCodeEx(K_UP), "ChatHistoryUp", KEYSCOPE_Gui,
                       new C4GUI::DlgKeyCBEx<C4ChatInputDialog, bool>(
                           *this, true, &C4ChatInputDialog::KeyHistoryUpDown),
                       C4CustomKey::PRIO_CtrlOverride);
  pKeyHistoryDown =
      new C4KeyBinding(C4KeyCodeEx(K_DOWN), "ChatHistoryDown", KEYSCOPE_Gui,
                       new C4GUI::DlgKeyCBEx<C4ChatInputDialog, bool>(
                           *this, false, &C4ChatInputDialog::KeyHistoryUpDown),
                       C4CustomKey::PRIO_CtrlOverride);
  pKeyAbort = new C4KeyBinding(
      C4KeyCodeEx(K_F2), "ChatAbort", KEYSCOPE_Gui,
      new C4GUI::DlgKeyCB<C4GUI::Dialog>(*this, &C4GUI::Dialog::KeyEscape),
      C4CustomKey::PRIO_CtrlOverride);
  pKeyNickComplete =
      new C4KeyBinding(C4KeyCodeEx(K_TAB), "ChatNickComplete", KEYSCOPE_Gui,
                       new C4GUI::DlgKeyCB<C4ChatInputDialog>(
                           *this, &C4ChatInputDialog::KeyCompleteNick),
                       C4CustomKey::PRIO_CtrlOverride);
  pKeyPlrControl = new C4KeyBinding(
      C4KeyCodeEx(KEY_Any, KEYS_Control), "ChatForwardPlrCtrl", KEYSCOPE_Gui,
      new C4GUI::DlgKeyCBPassKey<C4ChatInputDialog>(
          *this, &C4ChatInputDialog::KeyPlrControl),
      C4CustomKey::PRIO_Dlg);
  pKeyGamepadControl = new C4KeyBinding(
      C4KeyCodeEx(KEY_Any), "ChatForwardGamepadCtrl", KEYSCOPE_Gui,
      new C4GUI::DlgKeyCBPassKey<C4ChatInputDialog>(
          *this, &C4ChatInputDialog::KeyGamepadControlDown,
          &C4ChatInputDialog::KeyGamepadControlUp,
          &C4ChatInputDialog::KeyGamepadControlPressed),
      C4CustomKey::PRIO_PlrControl);
  pKeyBackClose =
      new C4KeyBinding(C4KeyCodeEx(K_BACK), "ChatBackspaceClose", KEYSCOPE_Gui,
                       new C4GUI::DlgKeyCB<C4ChatInputDialog>(
                           *this, &C4ChatInputDialog::KeyBackspaceClose),
                       C4CustomKey::PRIO_CtrlOverride);
  // free when closed...
  SetDelOnClose();
  // initial team text
  if (fTeam) pEdit->InsertText("/team ", true);
}
C4GameOptionsList::Option::Option(C4GameOptionsList *pForDlg)
		: BaseClass(C4Rect(0,0,0,0)), pPrimarySubcomponent(NULL) { }
Example #26
0
C4Rect C4MapScriptLayer::GetBounds() const
{
	// Return bounding rectangle of surface. Surface always starts at 0,0.
	return fg_surface ? C4Rect(0,0,fg_surface->Wdt,fg_surface->Hgt) : C4Rect();
}
C4MapScriptAlgoRect::C4MapScriptAlgoRect(const C4PropList *props)
{
	// Get MAPALGO_Rect properties
	rect = C4Rect(props->GetPropertyInt(P_X), props->GetPropertyInt(P_Y), props->GetPropertyInt(P_Wdt), props->GetPropertyInt(P_Hgt));
}
C4StartupMainDlg::C4StartupMainDlg() : C4StartupDlg(NULL) // create w/o title; it is drawn in custom draw proc
{
	// ctor
	fFirstShown = true;
	// screen calculations
	int iButtonPadding = 2;
	int iButtonHeight = C4GUI_BigButtonHgt;
	C4GUI::ComponentAligner caMain(rcBounds, 0, 0, true);
	C4GUI::ComponentAligner caRightPanel(caMain.GetFromLeft(rcBounds.Wdt * 2 / 5), rcBounds.Wdt / 26, 40 + rcBounds.Hgt / 5);
	C4GUI::ComponentAligner caButtons(caRightPanel.GetAll(), 0, iButtonPadding);
	//infobox
	C4GUI::TextWindow* instructionsWindow;
	C4Rect rcInstructionsWindow = C4Rect(rcBounds.Wdt / 2, rcBounds.Hgt / 11, rcBounds.Wdt * 5 / 16, rcBounds.Hgt * 5 / 12);
	AddElement(instructionsWindow = new C4GUI::TextWindow(rcInstructionsWindow, 0, 0, 0, 100, 4096, "  ", false, NULL, 0, true));
	instructionsWindow->SetDecoration(true, true, &C4Startup::Get()->Graphics.sfctBookScroll, true);
	instructionsWindow->UpdateHeight();
	instructionsWindow->AddTextLine(FormatString(LoadResStr("GAME_INSTRUCTIONS1")).getData(), &C4Startup::Get()->Graphics.BookFont, 4294967295U, false, false);
//	instructionsWindow->AddTextLine(FormatString(LoadResStr("GAME_INSTRUCTIONS2")).getData(), &C4Startup::Get()->Graphics.BookFont, 4294967295U, false, false);
	instructionsWindow->AddTextLine(FormatString(LoadResStr("GAME_INSTRUCTIONS3")).getData(), &C4Startup::Get()->Graphics.BookFont, 4294967295U, false, false);
	instructionsWindow->AddTextLine(FormatString(LoadResStr("GAME_INSTRUCTIONS4")).getData(), &C4Startup::Get()->Graphics.BookFont, 4294967295U, false, false);
	instructionsWindow->AddTextLine(FormatString(LoadResStr("GAME_INSTRUCTIONS5")).getData(), &C4Startup::Get()->Graphics.BookFont, 4294967295U, false, false);
	// main menu buttons
	C4GUI::CallbackButton<C4StartupMainDlg> *btn;
	AddElement(btn = new C4GUI::CallbackButton<C4StartupMainDlg>(LoadResStr("IDS_BTN_LOCALGAME"), caButtons.GetFromTop(iButtonHeight), &C4StartupMainDlg::OnStartBtn));
	btn->SetToolTip(LoadResStr("IDS_DLGTIP_STARTGAME"));
	btn->SetCustomGraphics(&C4Startup::Get()->Graphics.barMainButtons, &C4Startup::Get()->Graphics.barMainButtonsDown);
	pStartButton = btn;

//	AddElement(btn = new C4GUI::CallbackButton<C4StartupMainDlg>(LoadResStr("IDS_DLG_QUESTIONNAIRE"), caButtons.GetFromTop(iButtonHeight), &C4StartupMainDlg::OnQuestionnaireBtn));
	//	btn->SetToolTip(LoadResStr("IDS_DLGTIP_ABOUT"));
//	btn->SetCustomGraphics(&C4Startup::Get()->Graphics.barMainButtons, &C4Startup::Get()->Graphics.barMainButtonsDown);

	AddElement(btn = new C4GUI::CallbackButton<C4StartupMainDlg>(LoadResStr("IDS_DLG_SURVEY"), caButtons.GetFromTop(iButtonHeight), &C4StartupMainDlg::OnSurveyBtn));
	//	btn->SetToolTip(LoadResStr("IDS_DLGTIP_ABOUT"));
	btn->SetCustomGraphics(&C4Startup::Get()->Graphics.barMainButtons, &C4Startup::Get()->Graphics.barMainButtonsDown);

//	AddElement(btn = new C4GUI::CallbackButton<C4StartupMainDlg>(LoadResStr("IDS_BTN_NETWORKGAME"), caButtons.GetFromTop(iButtonHeight), &C4StartupMainDlg::OnNetJoinBtn));
//	btn->SetToolTip(LoadResStr("IDS_DLGTIP_NETWORKGAME"));
//	btn->SetCustomGraphics(&C4Startup::Get()->Graphics.barMainButtons, &C4Startup::Get()->Graphics.barMainButtonsDown);
	AddElement(btn = new C4GUI::CallbackButton<C4StartupMainDlg>(LoadResStr("IDS_DLG_PLAYERSELECTION"), caButtons.GetFromTop(iButtonHeight), &C4StartupMainDlg::OnPlayerSelectionBtn));
	btn->SetToolTip(LoadResStr("IDS_DLGTIP_PLAYERSELECTION"));
	btn->SetCustomGraphics(&C4Startup::Get()->Graphics.barMainButtons, &C4Startup::Get()->Graphics.barMainButtonsDown);
	AddElement(btn = new C4GUI::CallbackButton<C4StartupMainDlg>(LoadResStr("IDS_DLG_OPTIONS"), caButtons.GetFromTop(iButtonHeight), &C4StartupMainDlg::OnOptionsBtn));
	btn->SetToolTip(LoadResStr("IDS_DLGTIP_OPTIONS"));
	btn->SetCustomGraphics(&C4Startup::Get()->Graphics.barMainButtons, &C4Startup::Get()->Graphics.barMainButtonsDown);
	AddElement(btn = new C4GUI::CallbackButton<C4StartupMainDlg>(LoadResStr("IDS_DLG_ABOUT"), caButtons.GetFromTop(iButtonHeight), &C4StartupMainDlg::OnAboutBtn));
	btn->SetToolTip(LoadResStr("IDS_DLGTIP_ABOUT"));
	btn->SetCustomGraphics(&C4Startup::Get()->Graphics.barMainButtons, &C4Startup::Get()->Graphics.barMainButtonsDown);

	AddElement(btn = new C4GUI::CallbackButton<C4StartupMainDlg>(LoadResStr("IDS_DLG_EXIT"), caButtons.GetFromTop(iButtonHeight), &C4StartupMainDlg::OnExitBtn));
	btn->SetToolTip(LoadResStr("IDS_DLGTIP_EXIT"));
	btn->SetCustomGraphics(&C4Startup::Get()->Graphics.barMainButtons, &C4Startup::Get()->Graphics.barMainButtonsDown);
	// list of selected players
	AddElement(pParticipantsLbl = new C4GUI::Label("test", GetClientRect().Wdt * 39 / 40, GetClientRect().Hgt * 9 / 10, ARight, 0xffffffff, &::GraphicsResource.TitleFont, false));
	pParticipantsLbl->SetToolTip(LoadResStr("IDS_DLGTIP_SELECTEDPLAYERS"));
	// player selection shortcut - to be made optional
	UpdateParticipants();
	pParticipantsLbl->SetContextHandler(new C4GUI::CBContextHandler<C4StartupMainDlg>(this, &C4StartupMainDlg::OnPlayerSelContext));
	// key bindings
	C4CustomKey::CodeList keys;
	keys.push_back(C4KeyCodeEx(K_DOWN)); keys.push_back(C4KeyCodeEx(K_RIGHT));
	if (Config.Controls.GamepadGuiControl)
	{
		keys.push_back(C4KeyCodeEx(KEY_Gamepad(0, KEY_JOY_Down))); // right will be done by Dialog already
	}
	pKeyDown = new C4KeyBinding(keys, "StartupMainCtrlNext", KEYSCOPE_Gui,
		new C4GUI::DlgKeyCBEx<C4StartupMainDlg, bool>(*this, false, &C4StartupMainDlg::KeyAdvanceFocus), C4CustomKey::PRIO_CtrlOverride);
	keys.clear(); keys.push_back(C4KeyCodeEx(K_UP)); keys.push_back(C4KeyCodeEx(K_LEFT));
	if (Config.Controls.GamepadGuiControl)
	{
		keys.push_back(C4KeyCodeEx(KEY_Gamepad(0, KEY_JOY_Up))); // left will be done by Dialog already
	}
	pKeyUp = new C4KeyBinding(keys, "StartupMainCtrlPrev", KEYSCOPE_Gui,
		new C4GUI::DlgKeyCBEx<C4StartupMainDlg, bool>(*this, true, &C4StartupMainDlg::KeyAdvanceFocus), C4CustomKey::PRIO_CtrlOverride);
	keys.clear(); keys.push_back(C4KeyCodeEx(K_RETURN));
	pKeyEnter = new C4KeyBinding(keys, "StartupMainOK", KEYSCOPE_Gui,
		new C4GUI::DlgKeyCB<C4StartupMainDlg>(*this, &C4StartupMainDlg::KeyEnterDown, &C4StartupMainDlg::KeyEnterUp), C4CustomKey::PRIO_CtrlOverride);
}