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); } }
HudTargetInfo::HudTargetInfo(const FRect &target_rect) :HudLayer(target_rect), m_hit_chance(0.0f), m_health(1.0f), m_kills(0), m_deaths(0) { m_anim_speed = 10.0f; FRect rect = this->rect(); FRect icon_rect(s_char_icon_size); icon_rect += float2(rect.width() - icon_rect.width() - layer_spacing, rect.center().y - icon_rect.height() * 0.5f); m_char_icon = make_shared<HudCharIcon>(icon_rect); m_char_icon->setEnabled(true, false); attach(m_char_icon); }
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; }
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()); }