Ejemplo n.º 1
0
	const FRect align(const FRect &rect, const FRect &relative_to, Alignment mode, float spacing) {
		DASSERT(mode >= align_top && mode <= align_down_right);

		if(mode >= align_top_left) {
			if(mode == align_top_left)
				return align(align(rect, relative_to, align_left, spacing), relative_to, align_top, spacing);
			else if(mode == align_top_right)
				return align(align(rect, relative_to, align_right, spacing), relative_to, align_top, spacing);
			else if(mode == align_down_left)
				return align(align(rect, relative_to, align_left, spacing), relative_to, align_down, spacing);
			else /*if(mode == align_down_right)*/
				return align(align(rect, relative_to, align_right, spacing), relative_to, align_down, spacing);
		}

		if(mode == align_top) {
			float top = relative_to.min.y - spacing;
			return FRect(rect.min.x, top - rect.height(), rect.max.x, top);
		}
		else if(mode == align_down) {
			float bottom = relative_to.max.y + spacing;
			return FRect(rect.min.x, bottom, rect.max.x, bottom + rect.height());
		}
		else if(mode == align_left) {
			float left = relative_to.min.x - spacing;
			return FRect(left - rect.width(), rect.min.y, left, rect.max.y);
		}
		else /*if(mode == align_right)*/ {
			float right = relative_to.max.x + spacing;
			return FRect(right, rect.min.y, right + rect.width(), rect.max.y);
		}
	}
Ejemplo n.º 2
0
	HudMainPanel::HudMainPanel(const FRect &rect) :HudLayer(rect) {
		float2 bottom_left(spacing, rect.height() - spacing);

		FRect char_rect(s_hud_char_icon_size);
		char_rect += bottom_left - float2(0, char_rect.height());

		FRect weapon_rect(s_hud_weapon_size);
		weapon_rect += float2(char_rect.max.x + spacing, bottom_left.y - weapon_rect.height());

		m_hud_char_icon = make_shared<HudCharIcon>(char_rect);
		m_hud_weapon = make_shared<HudWeapon>(weapon_rect);

		{
			FRect stance_rect(s_hud_stance_size);
			stance_rect += float2(weapon_rect.max.x + spacing, bottom_left.y - s_hud_stance_size.y);

			for(int n = 0; n < arraySize(s_stance_buttons); n++) {
				PHudButton stance(new HudRadioButton(stance_rect, (int)s_stance_buttons[n].stance_id, 1));
				stance->setIcon(s_stance_buttons[n].icon_id);
				m_hud_stances.push_back(std::move(stance));

				stance_rect += float2(0.0f, -s_hud_stance_size.y - spacing);
			}
		}

		{
			FRect button_rect = align(FRect(s_hud_button_size), char_rect, align_top, spacing);
			button_rect += float2(char_rect.min.x - button_rect.min.x, 0.0f);

			for(int n = 0; n < arraySize(s_buttons); n++) {
				PHudButton button(new HudToggleButton(button_rect, s_buttons[n].layer_id));
				button->setLabel(s_buttons[n].name);
				m_hud_buttons.emplace_back(std::move(button));
				button_rect += float2(button_rect.width() + spacing, 0.0f);
			}
		}

		attach(m_hud_weapon);
		attach(m_hud_char_icon);
		for(int n = 0; n < (int)m_hud_buttons.size(); n++)
			attach(m_hud_buttons[n]);
		for(int n = 0; n < (int)m_hud_stances.size(); n++)
			attach(m_hud_stances[n]);
	}
Ejemplo n.º 3
0
PageItem* CreateMode::doCreateNewObject(void)
{
	int z = -1;
	double rot, len;

	double wSize = canvasCurrCoord.x() - createObjectPos.x();
	double hSize = canvasCurrCoord.y() - createObjectPos.y();
	bool   skipOneClick = (modifiers == Qt::ShiftModifier);
	if ((createObjectMode == modeDrawLine) || (createObjectMode == modeDrawTable2) ||
		(createObjectMode == modeInsertPDFButton) || (createObjectMode == modeInsertPDFTextfield) ||
		(createObjectMode == modeInsertPDFTextfield) || (createObjectMode == modeInsertPDFCheckbox) ||
		(createObjectMode == modeInsertPDFCombobox) || (createObjectMode == modeInsertPDFListbox) ||
		(createObjectMode == modeInsertPDFTextAnnotation) || (createObjectMode == modeInsertPDFLinkAnnotation) ||
		(createObjectMode == modeInsertPDF3DAnnotation) || (createObjectMode == modeInsertPDFRadioButton))
	{
		skipOneClick = false;
	}
	if (!skipOneClick)
	{
		if ((!m_view->moveTimerElapsed()) || ((fabs(wSize) < 2.0) && (fabs(hSize) < 2.0)))
		{
			if (!doOneClick(createObjectPos, canvasCurrCoord))
			{
				return NULL;
			}
		}
	}

	wSize = canvasCurrCoord.x() - createObjectPos.x();
	hSize = canvasCurrCoord.y() - createObjectPos.y();
	//Lock Height to Width for Control Modifier for final item creation
	if (createObjectMode != modeDrawLine)
	{
		if (modifiers == Qt::ControlModifier)
			hSize = wSize;
	}

	PageItem *newObject = NULL, *currItem = NULL;
	// FIXME for modeDrawLine
	QRectF createObjectRect(createObjectPos.x(), createObjectPos.y(), wSize, hSize);
	if (createObjectMode != modeDrawLine)
	{
		createObjectRect = createObjectRect.normalized();
		if (modifiers==Qt::ControlModifier)
		{
			//bottom right and upper left are ok
			//upper right
			if (canvasCurrCoord.y() < createObjectPos.y() && createObjectPos.x()<canvasCurrCoord.x())
				createObjectRect.translate(0.0, -createObjectRect.height());
			//bottom left
			if (canvasCurrCoord.x()<createObjectPos.x() && canvasCurrCoord.y()>createObjectPos.y())
				createObjectRect.translate(0.0, createObjectRect.height());
		}
	}
	double Rxp  = createObjectRect.x();
	double Ryp  = createObjectRect.y();
	double Rxpd = createObjectRect.width();
	double Rypd = createObjectRect.height();

	switch (createObjectMode)
	{
	case modeDrawShapes:
		switch (createObjectSubMode)
		{
			case 0:
				if (modifiers == Qt::ShiftModifier)
					z = m_doc->itemAddArea(PageItem::Polygon, PageItem::Rectangle, Rxp, Ryp, m_doc->itemToolPrefs().shapeLineWidth, m_doc->itemToolPrefs().shapeFillColor, m_doc->itemToolPrefs().shapeLineColor);
				else
					z = m_doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, Rxp, Ryp, Rxpd, Rypd, m_doc->itemToolPrefs().shapeLineWidth, m_doc->itemToolPrefs().shapeFillColor, m_doc->itemToolPrefs().shapeLineColor);
				m_doc->Items->at(z)->FrameType = 0;
				break;
			case 1:
				if (modifiers == Qt::ShiftModifier)
					z = m_doc->itemAddArea(PageItem::Polygon, PageItem::Ellipse, Rxp, Ryp, m_doc->itemToolPrefs().shapeLineWidth, m_doc->itemToolPrefs().shapeFillColor, m_doc->itemToolPrefs().shapeLineColor);
				else
					z = m_doc->itemAdd(PageItem::Polygon, PageItem::Ellipse, Rxp, Ryp, Rxpd, Rypd, m_doc->itemToolPrefs().shapeLineWidth, m_doc->itemToolPrefs().shapeFillColor, m_doc->itemToolPrefs().shapeLineColor);
				m_doc->Items->at(z)->FrameType = 1;
				break;
			default:
				if (modifiers == Qt::ShiftModifier)
					z = m_doc->itemAddArea(PageItem::Polygon, PageItem::Unspecified, Rxp, Ryp, m_doc->itemToolPrefs().shapeLineWidth, m_doc->itemToolPrefs().shapeFillColor, m_doc->itemToolPrefs().shapeLineColor);
				else
					z = m_doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, Rxp, Ryp, Rxpd, Rypd, m_doc->itemToolPrefs().shapeLineWidth, m_doc->itemToolPrefs().shapeFillColor, m_doc->itemToolPrefs().shapeLineColor);
				m_doc->Items->at(z)->SetFrameShape(m_doc->ValCount, m_doc->ShapeValues);
				m_doc->adjustItemSize(m_doc->Items->at(z));
				m_doc->setRedrawBounding(m_doc->Items->at(z));
				m_doc->Items->at(z)->FrameType = createObjectSubMode + 2;
				break;
		}
		break;
	case modeDrawLine:
		Rxp = createObjectPos.x();
		Ryp = createObjectPos.y();
		m_doc->ApplyGuides(&Rxp, &Ryp);
		m_doc->ApplyGuides(&Rxp, &Ryp,true);
		rot = xy2Deg(Rxpd, Rypd);
		if (rot < 0.0) 
			rot += 360;
		len = qMax(0.01, distance(Rxpd, Rypd));
		z = m_doc->itemAdd(PageItem::Line, PageItem::Unspecified, Rxp, Ryp, len, 1, m_doc->itemToolPrefs().lineWidth, CommonStrings::None, m_doc->itemToolPrefs().lineColor);
		m_doc->Items->at(z)->setRotation(rot);
		m_doc->Items->at(z)->setRedrawBounding();
		break;
	case modeDrawLatex:
		if (modifiers == Qt::ShiftModifier)
			z = m_doc->itemAddArea(PageItem::LatexFrame, PageItem::Unspecified, Rxp, Ryp, 1, m_doc->itemToolPrefs().imageFillColor, m_doc->itemToolPrefs().imageStrokeColor);
		else
			z = m_doc->itemAdd(PageItem::LatexFrame, PageItem::Unspecified, Rxp, Ryp, Rxpd, Rypd, m_doc->itemToolPrefs().shapeLineWidth, m_doc->itemToolPrefs().imageFillColor, m_doc->itemToolPrefs().imageStrokeColor);
		break;
	case modeDrawImage:
		if (modifiers == Qt::ShiftModifier)
			z = m_doc->itemAddArea(PageItem::ImageFrame, PageItem::Unspecified, Rxp, Ryp, 1, m_doc->itemToolPrefs().imageFillColor, m_doc->itemToolPrefs().imageStrokeColor);
		else
			z = m_doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified, Rxp, Ryp, Rxpd, Rypd, m_doc->itemToolPrefs().shapeLineWidth, m_doc->itemToolPrefs().imageFillColor, m_doc->itemToolPrefs().imageStrokeColor);
		break;
	case modeDrawText:
		if (modifiers == Qt::ShiftModifier)
			z = m_doc->itemAddArea(PageItem::TextFrame, PageItem::Unspecified, Rxp, Ryp, m_doc->itemToolPrefs().shapeLineWidth, CommonStrings::None, m_doc->itemToolPrefs().textFont);
		else
			z = m_doc->itemAdd(PageItem::TextFrame, PageItem::Unspecified, Rxp, Ryp, Rxpd, Rypd, m_doc->itemToolPrefs().shapeLineWidth, CommonStrings::None, m_doc->itemToolPrefs().textFont);
		break;
	case modeDrawRegularPolygon:
		if (modifiers == Qt::ShiftModifier)
			z = m_doc->itemAddArea(PageItem::RegularPolygon, PageItem::Unspecified, Rxp, Ryp, m_doc->itemToolPrefs().shapeLineWidth, m_doc->itemToolPrefs().shapeFillColor, m_doc->itemToolPrefs().lineColor);
		else
			z = m_doc->itemAdd(PageItem::RegularPolygon, PageItem::Unspecified, Rxp, Ryp, Rxpd, Rypd, m_doc->itemToolPrefs().shapeLineWidth, m_doc->itemToolPrefs().shapeFillColor, m_doc->itemToolPrefs().lineColor);
		break;
	case modeDrawArc:
		if (modifiers == Qt::ShiftModifier)
			z = m_doc->itemAddArea(PageItem::Arc, PageItem::Unspecified, Rxp, Ryp, m_doc->itemToolPrefs().shapeLineWidth, m_doc->itemToolPrefs().shapeFillColor, m_doc->itemToolPrefs().lineColor);
		else
			z = m_doc->itemAdd(PageItem::Arc, PageItem::Unspecified, Rxp, Ryp, Rxpd, Rypd, m_doc->itemToolPrefs().shapeLineWidth, m_doc->itemToolPrefs().shapeFillColor, m_doc->itemToolPrefs().lineColor);
		m_doc->setRedrawBounding(m_doc->Items->at(z));
		break;
	case modeDrawSpiral:
		if (modifiers == Qt::ShiftModifier)
			z = m_doc->itemAddArea(PageItem::Spiral, PageItem::Unspecified, Rxp, Ryp, m_doc->itemToolPrefs().shapeLineWidth, CommonStrings::None, m_doc->itemToolPrefs().lineColor);
		else
			z = m_doc->itemAdd(PageItem::Spiral, PageItem::Unspecified, Rxp, Ryp, Rxpd, Rypd, m_doc->itemToolPrefs().shapeLineWidth, CommonStrings::None, m_doc->itemToolPrefs().lineColor);
		m_doc->adjustItemSize(m_doc->Items->at(z));
		m_doc->setRedrawBounding(m_doc->Items->at(z));
		break;
	case modeInsertPDFButton:
	case modeInsertPDFRadioButton:
	case modeInsertPDFTextfield:
	case modeInsertPDFCheckbox:
	case modeInsertPDFCombobox:
	case modeInsertPDFListbox:
	case modeInsertPDFTextAnnotation:
	case modeInsertPDFLinkAnnotation:
		z = m_doc->itemAdd(PageItem::TextFrame, PageItem::Unspecified, Rxp, Ryp, Rxpd, Rypd, m_doc->itemToolPrefs().shapeLineWidth, CommonStrings::None, m_doc->itemToolPrefs().textColor);
		currItem = m_doc->Items->at(z);
		currItem->setIsAnnotation(true);
		currItem->AutoName = false;
		switch (m_doc->appMode)
		{
		case modeInsertPDFButton:
			currItem->annotation().setType(Annotation::Button);
			currItem->annotation().setFlag(Annotation::Flag_PushButton);
			currItem->setItemName( CommonStrings::itemName_PushButton + QString("%1").arg(m_doc->TotalItems));
			break;
		case modeInsertPDFRadioButton:
			currItem->annotation().setType(Annotation::RadioButton);
			currItem->annotation().setFlag(Annotation::Flag_Radio | Annotation::Flag_NoToggleToOff);
			currItem->setItemName( CommonStrings::itemName_RadioButton + QString("%1").arg(m_doc->TotalItems));
			break;
		case modeInsertPDFTextfield:
			currItem->annotation().setType(Annotation::Textfield);
			currItem->setItemName( CommonStrings::itemName_TextField + QString("%1").arg(m_doc->TotalItems));
			break;
		case modeInsertPDFCheckbox:
			currItem->annotation().setType(Annotation::Checkbox);
			currItem->setItemName( CommonStrings::itemName_CheckBox + QString("%1").arg(m_doc->TotalItems));
			break;
		case modeInsertPDFCombobox:
			currItem->annotation().setType(Annotation::Combobox);
			currItem->annotation().setFlag(Annotation::Flag_Combo);
			currItem->setItemName( CommonStrings::itemName_ComboBox + QString("%1").arg(m_doc->TotalItems));
			break;
		case modeInsertPDFListbox:
			currItem->annotation().setType(Annotation::Listbox);
			currItem->setItemName( CommonStrings::itemName_ListBox + QString("%1").arg(m_doc->TotalItems));
			break;
		case modeInsertPDFTextAnnotation:
			currItem->annotation().setType(Annotation::Text);
			currItem->setItemName( CommonStrings::itemName_TextAnnotation + QString("%1").arg(m_doc->TotalItems));
			break;
		case modeInsertPDFLinkAnnotation:
			currItem->annotation().setType(Annotation::Link);
			currItem->annotation().setZiel(m_doc->currentPage()->pageNr());
			currItem->annotation().setAction("0 0");
			currItem->setItemName( CommonStrings::itemName_LinkAnnotation + QString("%1").arg(m_doc->TotalItems));
			currItem->setTextFlowMode(PageItem::TextFlowDisabled);
			break;
		}
		break;
	case modeDrawTable2:
		// TODO: Figure out what these conditions actually do.
		if ((m_doc->m_Selection->count() == 0) && (m_view->HaveSelRect) && (!m_view->MidButt))
		{
			m_view->HaveSelRect = false;
			// Calculate table rectangle.
			FRect tableRect = adjustedRect(canvasPressCoord, canvasCurrCoord);
			if (tableRect.width() < 6 || tableRect.height() < 6)
			{
				// Ignore tiny tables.
				m_view->requestMode(submodePaintingDone);
				break;
			}
			// Show table insert dialog.
		//	qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
			InsertTable *dia = new InsertTable(m_view, static_cast<int>(tableRect.height()/6), static_cast<int>(tableRect.width()/6));
			if (!dia->exec())
			{
				m_view->requestMode(submodePaintingDone);
				delete dia;
				dia = 0;
				break;
			}
			int numRows = dia->Rows->value();
			int numColumns = dia->Cols->value();
			delete dia;
			dia = 0;
			// Add the table item.
			// TODO: This should be done in an undo transaction.
			m_doc->dontResize = true;
			z = m_doc->itemAdd(PageItem::Table, PageItem::Unspecified,
						   tableRect.x(),
						   tableRect.y(),
						   tableRect.width(),
						   tableRect.height(),
						   0,                    // Unused.
						   CommonStrings::None,  // Unused.
						   CommonStrings::None); // Unused.
			PageItem_Table *table = m_doc->Items->at(z)->asTable();
			table->insertRows(0, numRows - 1);
			table->insertColumns(0, numColumns - 1);
			table->adjustTableToFrame();
			table->adjustFrameToTable();
			m_doc->dontResize = false;
			m_doc->setRedrawBounding(table);
		}
		break;
	case modeInsertPDF3DAnnotation:
		if (modifiers == Qt::ShiftModifier)
		{
			z = m_doc->itemAddArea(PageItem::OSGFrame, PageItem::Unspecified, Rxp, Ryp, 1, m_doc->itemToolPrefs().imageFillColor, m_doc->itemToolPrefs().imageStrokeColor);
		}
		else
		{
			z = m_doc->itemAdd(PageItem::OSGFrame, PageItem::Unspecified, Rxp, Ryp, Rxpd, Rypd, m_doc->itemToolPrefs().shapeLineWidth, m_doc->itemToolPrefs().imageFillColor, m_doc->itemToolPrefs().imageStrokeColor);
		}
		currItem = m_doc->Items->at(z);
		currItem->setIsAnnotation(true);
		currItem->AutoName = false;
		currItem->annotation().setType(Annotation::Annot3D);
		currItem->setItemName( tr("3DAnnot") + QString("%1").arg(m_doc->TotalItems));
		break;
	}
	if (z >= 0)
	{
		SetupDrawNoResize(z);
		newObject = m_doc->Items->at(z);
		newObject->ContourLine = newObject->PoLine.copy();
	}
	return newObject;
}
Ejemplo n.º 4
0
	MultiPlayerMenu::MultiPlayerMenu(const FRect &rect, int2 window_size)
		:HudLayer(rect, HudLayer::slide_top), m_please_refresh(true), m_window_size(window_size) {
		enum { spacing = layer_spacing };

		setTitle("Connecting to server:");
		m_visible_time = 0.0f;

		m_waiting_for_refresh = false;
		m_waiting_to_connect = false;

		m_last_refresh_time = -1.0;
		m_last_connect_time = -1.0;

		FRect button_rect(s_button_size);
		button_rect += float2(rect.width() - spacing, rect.height() - spacing) - button_rect.size();

		PHudButton button_close = make_shared<HudClickButton>(button_rect);
		button_close->setIcon(HudIcon::close);

		button_rect -= float2(s_button_size.x + spacing * 2, 0.0f);
		PHudButton button_down = make_shared<HudClickButton>(button_rect);
		button_down->setIcon(HudIcon::down_arrow);
		button_down->setAccelerator(InputKey::pagedown);

		button_rect -= float2(s_button_size.x + spacing * 2, 0.0f);
		PHudButton button_up = make_shared<HudClickButton>(button_rect);
		button_up->setIcon(HudIcon::up_arrow);
		button_up->setAccelerator(InputKey::pageup);

		button_rect -= float2(s_button_size.x + spacing * 2, 0.0f);
		button_rect = button_rect.enlarge({50, 0}, {});
		PHudButton button_refresh = make_shared<HudClickButton>(button_rect);
		button_refresh->setLabel("refresh");
		
		button_rect -= float2(button_rect.width() + spacing * 2, 0.0f);
		button_rect = button_rect.enlarge({20, 0}, {});
		PHudButton button_connect = make_shared<HudClickButton>(button_rect);
		button_connect->setLabel("connect");
		button_connect->setAccelerator(InputKey::enter);

		button_rect = FRect(float2(185, s_button_size.y));
		button_rect += float2(rect.width() - button_rect.width() - spacing, spacing + topOffset());
		m_password = make_shared<HudEditBox>(button_rect, net::limits::max_password_size);
		m_password->setLabel("Pass: "******"Nick: ");
		m_nick_name->setText("random_dude");

		FRect sub_rect(rect.size());
		sub_rect = sub_rect.inset(float2(spacing, spacing * 2 + topOffset() + s_button_size.y),
						 		  float2(spacing, spacing * 2 + s_button_size.y));
		m_grid = make_shared<HudGrid>(sub_rect);
		
		m_grid->addColumn("Server name",	150.0f);
		m_grid->addColumn("Map name",	150.0f);
		m_grid->addColumn("Num players",	80.0f);
		m_grid->addColumn("Game mode",	80.0f);
		m_grid->addColumn("Ping",		50.0f);
		attach(m_grid);

		m_buttons.push_back(button_close);
		m_buttons.push_back(button_up);
		m_buttons.push_back(button_down);
		m_buttons.push_back(button_refresh);
		m_buttons.push_back(button_connect);
		m_buttons.push_back(m_password);
		m_buttons.push_back(m_nick_name);

		for(auto &button : m_buttons) {
			button->setButtonStyle(HudButtonStyle::small);
			attach(button);
		}

		m_client.reset(new net::Client());
	}