void UISystem::AddWidgetInParent(GroupWidget* parent, const TiXmlNode* data) { const char* widgetType = data->ToElement()->Value(); const char* styleName = data->ToElement()->Attribute("style"); if (!styleName) styleName = "Default"; //Construct the basic styled widget. No properties will be applied WidgetBase* wb = CreateWidget(widgetType, data); //Apply the general (All state) style level properties wb->ApplyGeneralStyleToAll(s_styles[styleName][widgetType]); //Apply the general (All state) widget level properties WidgetStyle style = WidgetStyle(data); wb->ApplyGeneralStyleToAll(&style); //Apply the state specific style level properties wb->ApplyStyle(s_styles[styleName][widgetType]); //Apply the state specific widget level properties wb->ApplyStyle(&style); const char* widgetName = data->ToElement()->Attribute("name"); std::string nameAsString; if (widgetName) { nameAsString = std::string(widgetName); wb->AddPropertyForState("name", UI_STATE_ALL, nameAsString); } else { wb->GetPropertyForCurrentState("name", nameAsString); } wb->m_parentWidget = parent; parent->m_children.push_back(wb); s_widgets[nameAsString] = wb; }
int32 FSlateTextHighlightRunRenderer::OnPaint( const FPaintArgs& Args, const FTextLayout::FLineView& Line, const TSharedRef< ISlateRun >& Run, const TSharedRef< ILayoutBlock >& Block, const FTextBlockStyle& DefaultStyle, const FGeometry& AllottedGeometry, const FSlateRect& MyClippingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled ) const { FVector2D Location( Block->GetLocationOffset() ); Location.Y = Line.Offset.Y; // The block size and offset values are pre-scaled, so we need to account for that when converting the block offsets into paint geometry const float InverseScale = Inverse(AllottedGeometry.Scale); // Draw the actual highlight rectangle FSlateDrawElement::MakeBox( OutDrawElements, ++LayerId, AllottedGeometry.ToPaintGeometry(TransformVector(InverseScale, FVector2D( Block->GetSize().X, Line.Size.Y )), FSlateLayoutTransform(TransformPoint(InverseScale, Location))), &DefaultStyle.HighlightShape, MyClippingRect, bParentEnabled ? ESlateDrawEffect::None : ESlateDrawEffect::DisabledEffect, InWidgetStyle.GetColorAndOpacityTint() * DefaultStyle.HighlightColor ); FLinearColor InvertedHighlightColor = FLinearColor::White - DefaultStyle.HighlightColor; InvertedHighlightColor.A = InWidgetStyle.GetForegroundColor().A; FWidgetStyle WidgetStyle( InWidgetStyle ); WidgetStyle.SetForegroundColor( InvertedHighlightColor ); return Run->OnPaint( Args, Line, Block, DefaultStyle, AllottedGeometry, MyClippingRect, OutDrawElements, LayerId, WidgetStyle, bParentEnabled ); }
void UISystem::ReadStyleFile(const std::string& filePath) { TiXmlDocument doc(filePath.c_str()); doc.LoadFile(); TiXmlHandle docHandle(&doc); //Get the style name and insert it into the named properties TiXmlHandle styleNameHandle = docHandle.FirstChild("Style"); TiXmlElement* styleNameElement = styleNameHandle.ToElement(); const std::string styleName = styleNameElement->Attribute("name"); FATAL_ASSERT(styleName != ""); const TiXmlNode* global = styleNameElement->FirstChild("Global"); bool hasGlobal = global != nullptr; WidgetStyle tempStyle; if (hasGlobal) { tempStyle = WidgetStyle(global); } for (const TiXmlNode* widgetDefinition = styleNameElement->FirstChild(); widgetDefinition; widgetDefinition = widgetDefinition->NextSibling()) { const char* widgetName = widgetDefinition->ToElement()->Value(); if (strcmp(widgetName, "Global") != 0) { WidgetStyle ws = tempStyle; WidgetStyle* newWs = new WidgetStyle(widgetDefinition); ws.MergeStyle(newWs); WidgetStyle* mergedWS = new WidgetStyle(ws); delete newWs; s_styles[styleName][widgetName] = mergedWS; } } auto styleMap = s_styles[styleName]; for (auto& it : s_widgetFactory) { std::string widgetName = it.first; auto found = styleMap.find(widgetName); if (found == styleMap.end()) { s_styles[styleName][widgetName] = new WidgetStyle(tempStyle); } } }
int32 FSlateSimpleRunHighlighter::OnPaint( const FTextLayout::FLineView& Line, const TSharedRef< ISlateRun >& Run, const TSharedRef< ILayoutBlock >& Block, const FTextBlockStyle& DefaultStyle, const FGeometry& AllottedGeometry, const FSlateRect& MyClippingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled ) const { FVector2D Location( Block->GetLocationOffset() ); Location.Y = Line.Offset.Y; // Draw the actual highlight rectangle FSlateDrawElement::MakeBox( OutDrawElements, ++LayerId, FPaintGeometry( AllottedGeometry.AbsolutePosition + Location, FVector2D( Block->GetSize().X, Line.Size.Y ), AllottedGeometry.Scale ), &DefaultStyle.HighlightShape, MyClippingRect, bParentEnabled ? ESlateDrawEffect::None : ESlateDrawEffect::DisabledEffect, InWidgetStyle.GetColorAndOpacityTint() * DefaultStyle.HighlightColor ); FLinearColor InvertedForeground = FLinearColor::White - InWidgetStyle.GetForegroundColor(); InvertedForeground.A = InWidgetStyle.GetForegroundColor().A; FWidgetStyle WidgetStyle( InWidgetStyle ); WidgetStyle.SetForegroundColor( InvertedForeground ); return Run->OnPaint( Line, Block, DefaultStyle, AllottedGeometry, MyClippingRect, OutDrawElements, LayerId, WidgetStyle, bParentEnabled ); }
static std::shared_ptr<GUIHorizontalLine> Create(int thickness = 1, const WidgetStyle& style = WidgetStyle()) { return std::make_shared<GUIHorizontalLine>(thickness, style); }
/// <summary> /// スライダーウィジェットを作成します。 /// </summary> /// <param name="left"> /// 一番左の値 /// </param> /// <param name="right"> /// 一番右の値 /// </param> /// <param name="initial"> /// 初期状態の値 /// </param> /// <param name="enabled"> /// 有効かどうか /// </param> /// <param name="style"> /// スタイル /// </param> /// <returns> /// スライダーウィジェット /// </returns> static std::shared_ptr<GUISlider> Create(double left, double right, double initial, bool enabled = true, const WidgetStyle& style = WidgetStyle()) { return Create(left, right, initial, style.font.height * 5, enabled, style); }
/// <summary> /// スライダーウィジェットを作成します。 /// </summary> /// <param name="left"> /// 一番左の値 /// </param> /// <param name="right"> /// 一番右の値 /// </param> /// <param name="initial"> /// 初期状態の値 /// </param> /// <param name="width"> /// スライダーのサイズ(ピクセル) /// </param> /// <param name="enabled"> /// 有効かどうか /// </param> /// <param name="style"> /// スタイル /// </param> /// <returns> /// スライダーウィジェット /// </returns> static std::shared_ptr<GUISlider> Create(double left, double right, double initial, int width, bool enabled = true, const WidgetStyle& style = WidgetStyle()) { double position = 0.0; if (right - left != 0.0) { const double current = Clamp(initial, s3d::Min(left, right), s3d::Max(left, right)); position = width * (current - left) / (right - left); } return std::make_shared<GUISlider>(left, right, width, position, enabled, style); }
static std::shared_ptr<GUIColorPalette> Create(const HSV& color, int32 paletteHeight, int32 svPaletteWidth, int32 paletteMarginWidth, int32 huePaletteWidth, bool enabled = true, const WidgetStyle& style = WidgetStyle()) { return std::make_shared<GUIColorPalette>(color, paletteHeight, svPaletteWidth, paletteMarginWidth, huePaletteWidth, enabled, style); }
static std::shared_ptr<GUIColorPalette> Create(const HSV& color = HSV(30.0, 0.9, 0.9), bool enabled = true, const WidgetStyle& style = WidgetStyle()) { return std::make_shared<GUIColorPalette>(color, 240, 160, 15, 20, enabled, style); }
static std::shared_ptr<GUIButton> Create(const s3d::String& label, bool enabled, const WidgetStyle& style = WidgetStyle()) { return std::make_shared<GUIButton>(label, enabled, style); }
static std::shared_ptr<GUITexture> Create(const s3d::Texture& texture, const WidgetStyle& style = WidgetStyle()) { return std::make_shared<GUITexture>(texture, style); }