Exemplo n.º 1
0
void
Grid::AllocateGridSegments (int row_count, int col_count)
{
	// First allocate the heights of the RowDefinitions, then allocate
	// the widths of the ColumnDefinitions.
	for (int i = 0; i < 2; i ++) {
		Segment **matrix = i == 0 ? row_matrix : col_matrix;
		int count = i == 0 ? row_count : col_count;

		for (int row = count - 1; row >= 0; row--) {
			for (int col = row; col >= 0; col--) {
					bool spans_star = false;
					for (int j = row; j >= col; j --)
						spans_star |= matrix [j][j].type == GridUnitTypeStar;
			
				// This is the amount of pixels which must be available between the grid rows
				// at index 'col' and 'row'. i.e. if 'row' == 0 and 'col' == 2, there must
				// be at least 'matrix [row][col].size' pixels of height allocated between
				// all the rows in the range col -> row.
				double current = matrix [row][col].size;

				// Count how many pixels have already been allocated between the grid rows
				// in the range col -> row. The amount of pixels allocated to each grid row/column
				// is found on the diagonal of the matrix.
				double total_allocated = 0;
				for (int i = row; i >= col; i--)
					total_allocated += matrix [i][i].size;

				// If the size requirement has not been met, allocate the additional required
				// size between 'pixel' rows, then 'star' rows, finally 'auto' rows, until all
				// height has been assigned.
				if (total_allocated < current) {
					double additional = current - total_allocated;
					if (spans_star) {
						AssignSize (matrix, col, row, &additional, GridUnitTypeStar);
					} else {
						AssignSize (matrix, col, row, &additional, GridUnitTypePixel);
						AssignSize (matrix, col, row, &additional, GridUnitTypeAuto);
					}
				}
			}
		}
	}
}
Exemplo n.º 2
0
void
Grid::ExpandStarCols (Size availableSize)
{
	ColumnDefinitionCollection *columns = GetColumnDefinitionsNoAutoCreate ();
	int columns_count = columns ? columns->GetCount () : 0;

	for (int i = 0; i < col_matrix_dim; i++) {
		if (col_matrix [i][i].type == GridUnitTypeStar)
			col_matrix [i][i].size = 0;
		else
			availableSize.width = MAX (availableSize.width - col_matrix [i][i].size, 0);
	}

	AssignSize (col_matrix, 0, col_matrix_dim - 1, &availableSize.width, GridUnitTypeStar);
		
	if (columns_count > 0) {
		for (int i = 0; i < col_matrix_dim; i++)
			if (col_matrix [i][i].type == GridUnitTypeStar)
				columns->GetValueAt (i)->AsColumnDefinition ()->SetActualWidth (col_matrix [i][i].size);
	}
}
Exemplo n.º 3
0
bool GameWindow::AutoSetupWindow(Application* _parent)
{
    Parent = _parent;

    glfwSetErrorCallback(glfwError);

    // todo: enum modes
    if (!glfwInit())
    {
        Log::Logf("Failure to initialize glfw.\n");
        return false; // std::exception("glfw failed initialization!"); // don't do shit
    }

    AssignSize();
    matrixSize.x = ScreenWidth;
    matrixSize.y = ScreenHeight;

    IsFullscreen = Configuration::GetConfigf("Fullscreen") != 0;

    doFlush = Configuration::GetConfigf("VideoFlush") != 0;
    VSync = Configuration::GetConfigf("VSync") != 0;

    if (!(wnd = glfwCreateWindow(size.x, size.y, RAINDROP_WINDOWTITLE RAINDROP_VERSIONTEXT, IsFullscreen ? glfwGetPrimaryMonitor() : NULL, NULL)))
    {
        Log::Logf("Failure to initialize window.\n");
        return false;
    }

#ifdef DARWIN
    // This is a temporary hack for OS X where our size isn't getting initialized to the correct values.
    int outx = 0;
    int outy = 0;
    glfwGetWindowSize(wnd, &outx, &outy);
    ResizeFunc(wnd, outx, outy);
#endif

    SetVisibleCursor(Configuration::GetSkinConfigf("ShowCursor") != 0);

    return SetupWindow();
}
Exemplo n.º 4
0
void
Grid::ExpandStarRows (Size availableSize)
{
	RowDefinitionCollection *rows = GetRowDefinitionsNoAutoCreate ();
	int row_count = rows ? rows->GetCount () : 0;

	// When expanding star rows, we need to zero out their height before
	// calling AssignSize. AssignSize takes care of distributing the 
	// available size when there are Mins and Maxs applied.
	for (int i = 0; i < row_matrix_dim; i++) {
		if (row_matrix [i][i].type == GridUnitTypeStar)
			row_matrix [i][i].size = 0.0;
		else
			availableSize.height = MAX (availableSize.height - row_matrix [i][i].size, 0);
	}

	AssignSize (row_matrix, 0, row_matrix_dim - 1, &availableSize.height, GridUnitTypeStar);
	if (row_count > 0) {
		for (int i = 0; i < row_matrix_dim; i++)
			if (row_matrix [i][i].type == GridUnitTypeStar)
				rows->GetValueAt (i)->AsRowDefinition ()->SetActualHeight (row_matrix [i][i].size);
	}
}
Exemplo n.º 5
0
void GameWindow::SwapBuffers()
{
	if (doFlush)
		glFlush();

	glfwSwapBuffers(wnd);
	glfwPollEvents();

	int buttonArraySize = 0;
	if (JoystickEnabled) {
		const unsigned char *buttonArray = glfwGetJoystickButtons(GLFW_JOYSTICK_1, &buttonArraySize);
		if (buttonArraySize > 0) {
			for (int i = 0; i < buttonArraySize; i++) {
				for (uint32 j = 0; j < SpecialKeys.size(); j++) {
					/* Matches the pressed button to its entry in the SpecialKeys vector. */
					int thisKeyNumber = SpecialKeys[j].boundkey - 1000;
					if (i + 1 == thisKeyNumber) {
						/* Only processes the button push/release if the state has changed. */
						if ((buttonArray[i] != 0) != controllerButtonState[thisKeyNumber]) {
							WindowFrame.Parent->HandleInput(SpecialKeys[j].boundkey, ToKeyEventType(buttonArray[i]), false);
							controllerButtonState[thisKeyNumber] = !controllerButtonState[thisKeyNumber];
						}
					}
				}
			}
		}
	}

	/* Fullscreen switching */
	if (FullscreenSwitchbackPending)
	{
		if (IsFullscreen)
		{
			glfwDestroyWindow(wnd);
			wnd = glfwCreateWindow(size.x, size.y, RAINDROP_WINDOWTITLE RAINDROP_VERSIONTEXT, NULL, NULL);
		}
		else
		{
			AssignSize();

			glfwDestroyWindow(wnd);
			wnd = glfwCreateWindow(size.x, size.y, RAINDROP_WINDOWTITLE RAINDROP_VERSIONTEXT, glfwGetPrimaryMonitor(), NULL);
		}

		AttribLocs.clear();
		UniformLocs.clear();
		SetupWindow();
		ImageLoader::InvalidateAll();

		/* This revalidates all VBOs and fonts */
		for (std::vector<VBO*>::iterator i = VBOList.begin(); i != VBOList.end(); i++)
		{
			(*i)->Invalidate();
			(*i)->Validate();
		}

		for (std::vector<TruetypeFont*>::iterator i = TTFList.begin(); i != TTFList.end(); i++)
		{
			(*i)->Invalidate();
		}

		IsFullscreen = !IsFullscreen;
		FullscreenSwitchbackPending = false;
	}

}