public static void SetAnchor(AnchorType at, RectTransform rt) { Vector2 anchor; Vector2 pivot; if (at == AnchorType.TopLeft) { anchor = new Vector2(0, 1); pivot = new Vector2(0, 1); } else if (at == AnchorType.LeftCenter) { anchor = new Vector2(0, 0.5f); pivot = new Vector2(0.5f, 0.5f); } else if (at == AnchorType.Center) { anchor = new Vector2(0.5f, 0.5f); pivot = new Vector2(0.5f, 0.5f); } else { anchor = new Vector2(1, 1); pivot = new Vector2(1, 1); } rt.anchorMin = anchor; rt.anchorMax = anchor; rt.pivot = pivot; }
public Anchor(String tag, AnchorType type, Int16 look)//, uint min, uint max) { this.tag = tag; this.type = type; this.look = look; this.positions = new ArrayList(); this.positions.Add(new Point(0.5, 0.5)); }
public Anchor(String tag, AnchorType type, Int16 look, ArrayList positions)//, uint min, uint max) { this.tag = tag; this.type = type; this.look = look; this.positions = positions; //this.min = min; //this.max = max; }
/// <summary> /// Determine the initial anchor type. /// </summary> protected virtual void OnEnable () { instance = this; if (serializedObject.isEditingMultipleObjects) { mAnchorType = AnchorType.Advanced; } else ReEvaluateAnchorType(); }
public Anchor(String tag, AnchorType type, Int16 look, PointF position)//, uint min, uint max) { this.tag = tag; this.type = type; this.look = look; this.positions = new ArrayList(); this.positions.Add(new Point(position.X, position.Y)); //this.min = min; //this.max = max; }
public Anchor(AnchorType type, float max_avulsion_force, float max_cut_force, bool is_throughwall, float d, float lenght, Materials[] accepted_material, float max_a, float max_s, float bolt_d) { this.type = type; this.max_avulsion_force = max_avulsion_force; this.max_cut_force = max_cut_force; this.is_throughwall = is_throughwall; this.is_selfdrill = false; this.d = d; this.lenght = lenght; this.accepted_material = accepted_material; this.max_a = max_a; this.max_s = max_s; switch (this.type) { case AnchorType.Driven: this.img_name = "Summer_work.Imgs.Anchors.drivein.png"; break; case AnchorType.Frame: this.img_name = "Summer_work.Imgs.Anchors.frame.png"; break; case AnchorType.Sleeve: this.img_name = "Summer_work.Imgs.Anchors.sleeve.png"; break; case AnchorType.Wedged: this.img_name = "Summer_work.Imgs.Anchors.wedgedt2.png"; break; } if (this.type == AnchorType.Driven) { this.bolt_d = bolt_d; this.bolt_class = this.max_cut_force/100; if(this.bolt_class<=4.8)//it's bad... this.bolt_class = (float)4.8; else if(this.bolt_class<=5.8) this.bolt_class = (float)5.8; else if(this.bolt_class <= 8.8) this.bolt_class = (float)8.8; else if(this.bolt_class <=9.8) this.bolt_class = (float)9.8; else this.bolt_class = (float)12.9; } else { this.bolt_class = 0; this.bolt_d = 0; } }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ public override void TreeUpdate() { base.TreeUpdate(); UpdateLayoutWithFixedSize(); if ( vRectSize == null ) { Controllers.Set(RectAnchorName, this); RectAnchor = AnchorType.MiddleCenter; } vRectSize = null; }
private Vector2 GetAnchoredVector2(AnchorType anchorType) { switch (anchorType) { case AnchorType.TopLeft: return(new Vector2(0, 1)); case AnchorType.TopRight: return(new Vector2(1, 1)); case AnchorType.BottomRight: return(new Vector2(1, 0)); case AnchorType.BottomLeft: return(Vector2.zero); default: return(Vector2.zero); } }
public static string GetJsonName(this AnchorType anchor) { switch (anchor) { case AnchorType.BottomLeft: return("bottom-left"); case AnchorType.BottomRight: return("bottom-right"); case AnchorType.TopLeft: return("top-left"); case AnchorType.topRight: return("top-right"); default: return(Enum.GetName(typeof(AnchorType), anchor).ToLowerInvariant()); } }
public static Anchor Create(AnchorType type, ROI roi) { Anchor anchor = null; switch (type) { case AnchorType.Move: anchor = new CrossAnchor(); break; case AnchorType.Resize: anchor = new RoundAnchor(); break; default: return(null); } Binding binding = new Binding(Anchor.MagnificationProperty.Name); binding.Source = roi; anchor.SetBinding(Anchor.MagnificationProperty, binding); return(anchor); }
public override void Resize(AnchorType anchorType, double x, double y) { switch (anchorType) { case AnchorType.TopLeft: radiusX -= x; radiusY -= y; break; case AnchorType.TopRight: radiusX += x; radiusY -= y; break; case AnchorType.BottomRight: radiusX += x; radiusY += y; break; case AnchorType.BottomLeft: radiusX -= x; radiusY += y; break; case AnchorType.Top: radiusY -= y; break; case AnchorType.Bottom: radiusY += y; break; case AnchorType.Right: radiusX += x; break; case AnchorType.Left: radiusX -= x; break; } }
public PAN1(FileReader reader, BLOHeader header) : base() { byte paramCount = reader.ReadByte(); Visible = reader.ReadBoolean(); reader.ReadUInt16(); Name = reader.ReadString(4, true); Left = reader.ReadUInt16(); Top = reader.ReadUInt16(); Width = reader.ReadUInt16(); Height = reader.ReadInt16(); paramCount -= 6; if (paramCount > 0) { Angle = reader.ReadInt16(); --paramCount; } if (paramCount > 0) { Anchor = (AnchorType)reader.ReadByte(); --paramCount; } if (paramCount > 0) { Alpha = reader.ReadByte(); --paramCount; } if (paramCount > 0) { InfluenceAlpha = reader.ReadBoolean(); --paramCount; } Alpha = 255; Translate = GetPosition(); Scale = new Vector2F(1, 1); Rotate = new Vector3F(0, 0, 0); }
/// <summary> /// /// </summary> /// <param name="reader"></param> public FileShapeAddress(VirtualStreamReader reader, int length) : base(reader, length) { this.spid = this._reader.ReadInt32(); this.xaLeft = this._reader.ReadInt32(); this.yaTop = this._reader.ReadInt32(); this.xaRight = this._reader.ReadInt32(); this.yaBottom = this._reader.ReadInt32(); ushort flag = this._reader.ReadUInt16(); this.fHdr = Tools.Utils.BitmaskToBool(flag, 0x0001); this.bx = (AnchorType)Tools.Utils.BitmaskToInt(flag, 0x0006); this.by = (AnchorType)Tools.Utils.BitmaskToInt(flag, 0x0018); this.wr = (ushort)Tools.Utils.BitmaskToInt(flag, 0x01E0); this.wrk = (ushort)Tools.Utils.BitmaskToInt(flag, 0x1E00); this.fRcaSimple = Tools.Utils.BitmaskToBool(flag, 0x2000); this.fBelowText = Tools.Utils.BitmaskToBool(flag, 0x4000); this.fAnchorLock = Tools.Utils.BitmaskToBool(flag, 0x8000); this.cTxbx = this._reader.ReadInt32(); }
/// <summary> /// Manually re-evaluate the current anchor type. /// </summary> protected void ReEvaluateAnchorType() { UIRect rect = target as UIRect; if (rect.leftAnchor.target == rect.rightAnchor.target && rect.leftAnchor.target == rect.bottomAnchor.target && rect.leftAnchor.target == rect.topAnchor.target) { if (rect.leftAnchor.target == null) { mAnchorType = AnchorType.None; } else { mAnchorType = AnchorType.Unified; } } else { mAnchorType = AnchorType.Advanced; } }
/// <summary> /// Paints this control /// </summary> /// <param name="e"></param> protected override void OnPaint(PaintEventArgs e) { Rectangle rect = new Rectangle(0, 0, this.Width, this.Height); // Fill the background e.Graphics.FillRectangle(Brushes.White, rect); // Shrink the rect to determine the area of the control visualization rect.Inflate(-(mMargin + 2), -(mMargin + 2)); // Quit if it shrank too much if (rect.Width == 0 || rect.Height == 0) { return; } // Draw the inner square representing the control e.Graphics.FillRectangle(Brushes.LightBlue, rect); e.Graphics.DrawRectangle(Pens.DarkBlue, rect); AnchorType type = AnchorType.None; // Top type = (mAnchorFlags & AnchorFlags.Top) == AnchorFlags.Top ? AnchorType.Absolute : ((mAnchorFlags & AnchorFlags.TopRelative) == AnchorFlags.TopRelative ? AnchorType.Relative : AnchorType.None); DrawMarker(e.Graphics, this.Width / 2, mMargin / 2, false, type); // Bottom type = (mAnchorFlags & AnchorFlags.Bottom) == AnchorFlags.Bottom ? AnchorType.Absolute : ((mAnchorFlags & AnchorFlags.BottomRelative) == AnchorFlags.BottomRelative ? AnchorType.Relative : AnchorType.None); DrawMarker(e.Graphics, this.Width / 2, this.Height - mMargin / 2 - 1, false, type); // Left type = (mAnchorFlags & AnchorFlags.Left) == AnchorFlags.Left ? AnchorType.Absolute : ((mAnchorFlags & AnchorFlags.LeftRelative) == AnchorFlags.LeftRelative ? AnchorType.Relative : AnchorType.None); DrawMarker(e.Graphics, mMargin / 2, this.Height / 2, true, type); // Right type = (mAnchorFlags & AnchorFlags.Right) == AnchorFlags.Right ? AnchorType.Absolute : ((mAnchorFlags & AnchorFlags.RightRelative) == AnchorFlags.RightRelative ? AnchorType.Relative : AnchorType.None); DrawMarker(e.Graphics, this.Width - mMargin / 2 - 1, this.Height / 2, true, type); }
/// <summary> /// Construct pathfigure near from object /// </summary> /// <returns></returns> protected virtual PathFigure DrawFrom() { PathFigure pathFigure = new PathFigure(); PathSegmentCollection collection = new PathSegmentCollection(); AnchorType from = FromAnchor; if (FromAnchor == AnchorType.Auto) { from = GetAnchor(From, To); } switch (from) { case AnchorType.Left: pathFigure.StartPoint = new Point(From.X, From.Y + From.Height / 2f); collection.Add(new LineSegment(new Point(pathFigure.StartPoint.X - Delta / 2f, pathFigure.StartPoint.Y), true)); break; case AnchorType.Top: pathFigure.StartPoint = new Point(From.X + From.Width / 2f, From.Y); collection.Add(new LineSegment(new Point(pathFigure.StartPoint.X, pathFigure.StartPoint.Y - Delta / 2f), true)); break; case AnchorType.Right: pathFigure.StartPoint = new Point(From.X + From.Width, From.Y + From.Height / 2f); collection.Add(new LineSegment(new Point(pathFigure.StartPoint.X + Delta / 2f, pathFigure.StartPoint.Y), true)); break; case AnchorType.Bottom: pathFigure.StartPoint = new Point(From.X + From.Width / 2f, From.Y + From.Height); collection.Add(new LineSegment(new Point(pathFigure.StartPoint.X, pathFigure.StartPoint.Y + Delta / 2f), true)); break; } pathFigure.Segments = collection; return(pathFigure); }
/// <summary> /// Returns the min anchor value for the specified anchor type. /// </summary> public static Vector2 GetMinAnchor(AnchorType anchor) { switch (anchor) { case AnchorType.TopLeft: return(new Vector2(0f, 1f)); case AnchorType.Top: return(new Vector2(0.5f, 1f)); case AnchorType.TopRight: return(new Vector2(1f, 1f)); case AnchorType.Left: return(new Vector2(0f, 0.5f)); case AnchorType.Center: return(new Vector2(0.5f, 0.5f)); case AnchorType.Right: return(new Vector2(1f, 0.5f)); case AnchorType.BottomLeft: return(new Vector2(0f, 0f)); case AnchorType.Bottom: return(new Vector2(0.5f, 0f)); case AnchorType.BottomRight: return(new Vector2(1f, 0f)); case AnchorType.TopStretch: return(new Vector2(0f, 1f)); case AnchorType.MiddleStretch: return(new Vector2(0f, 0.5f)); case AnchorType.BottomStretch: return(new Vector2(0f, 0f)); case AnchorType.LeftStretch: return(new Vector2(0f, 0f)); case AnchorType.CenterStretch: return(new Vector2(0.5f, 0f)); case AnchorType.RightStretch: return(new Vector2(1f, 0f)); case AnchorType.Fill: return(new Vector2(0f, 0f)); } throw new ArgumentException($"Unknown anchor type: {anchor}"); }
void OnGUI() { GUILayout.Label("Settings", EditorStyles.boldLabel); _texture = (Texture)EditorGUILayout.ObjectField("Texture", _texture, typeof(Texture), false); _shaderType = (ShaderType)EditorGUILayout.EnumPopup("Shader Type", _shaderType); _anchorType = (AnchorType)EditorGUILayout.EnumPopup("Anchor Type", _anchorType); _scaleBy = (ScaleBy)EditorGUILayout.EnumPopup("Scale By", _scaleBy); _size = EditorGUILayout.FloatField("Size", _size); _isCreateAsset = EditorGUILayout.Toggle("Create Asset", _isCreateAsset); EditorGUILayout.Separator(); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUI.enabled = (_texture != null); if (GUILayout.Button("Process")) { _Process(); } GUI.enabled = true; EditorGUILayout.EndHorizontal(); }
/// <summary> /// Draw the inspector properties. /// </summary> public override void OnInspectorGUI() { if (serializedObject.isEditingMultipleObjects) { mAnchorType = AnchorType.Advanced; } else { ReEvaluateAnchorType(); } NGUIEditorTools.SetLabelWidth(80f); EditorGUILayout.Space(); serializedObject.Update(); EditorGUI.BeginDisabledGroup(!ShouldDrawProperties()); DrawCustomProperties(); EditorGUI.EndDisabledGroup(); DrawFinalProperties(); serializedObject.ApplyModifiedProperties(); }
private bool doesAnchorMatch(AnchorType anchorType, ArrayConsList <char> currentPos, int afterLastMatchIndex) { switch (anchorType) { case AnchorType.StartOfString: return(currentPos.IsStartOfArray); case AnchorType.StartOfLine: return(currentPos.IsStartOfArray || currentPos.Prev == '\n'); case AnchorType.EndOfString: return(currentPos.IsEmpty); case AnchorType.EndOfLine: return(currentPos.IsEmpty || currentPos.Head == '\n'); case AnchorType.EndOfStringOrBeforeEndingNewline: return(currentPos.DropWhile(c => c == '\n').IsEmpty); case AnchorType.ContiguousMatch: return(currentPos.ArrayIndex == afterLastMatchIndex); case AnchorType.WordBoundary: return(isWordBoundary(currentPos)); case AnchorType.NonWordBoundary: return(!isWordBoundary(currentPos)); default: throw new ApplicationException( string.Format("BacktrackingMatcher: illegal anchor type ({0}).", anchorType.ToString())); } }
public AnchorData(AnchorType type, int count, int start) { this.type = type; this.tileCount = count; this.checkStart = start; }
public WorldUIAnchor(int topLeftX, int topLeftY, int width, int height) { type = AnchorType.Tile; pos = new Vector2((float)topLeftX + (float)width / 2f, (float)topLeftY + (float)height / 2f) * 16f; size = new Vector2(width, height) * 16f; }
public WorldUIAnchor(Entity anchor) { type = AnchorType.Entity; entity = anchor; }
public void SetAnchorPickerSelectionType(AnchorType anchorType) { AnchorPicker.CurrentAnchorTypeSelection = anchorType; }
public WorldUIAnchor(int topLeftX, int topLeftY, int width, int height) { type = AnchorType.Tile; pos = new Vector2((float)topLeftX + (float)width / 2f, (float)topLeftY + (float)height / 2f) * 16f; size = new Vector2((float)width, (float)height) * 16f; }
public AnchorData(AnchorType type, int count, int start) { this.type = type; tileCount = count; checkStart = start; }
/// <summary> /// Calculates the distance between an old anchor point and a new anchor point. /// </summary> /// <param name="oldType"></param> /// <param name="newType"></param> /// <param name="size"></param> /// <returns></returns> public static XSize CalcDistance(AnchorType oldType, AnchorType newType, XSize size) { if (oldType == newType) return XSize.Empty; XSize result = XSize.Empty; Delta delta = CodeBase.deltas[(int)oldType, (int)newType]; result = new XSize(size.width / 2 * delta.x, size.height / 2 * delta.y); return result; }
public static bool CheckTileAnchors(int sx, int sy, int w, int h, int mode, AnchorType anchor) { if ((mode & 1) == 1) { for (int i = sy; i < sy + h; i++) { if (!WorldGen.AnchorValid(Framing.GetTileSafely(sx - 1, i), anchor)) { return false; } if (!WorldGen.AnchorValid(Framing.GetTileSafely(sx + w, i), anchor)) { return false; } } } if ((mode & 2) == 2) { for (int j = sx; j < sx + w; j++) { if (!WorldGen.AnchorValid(Framing.GetTileSafely(j, sy - 1), anchor)) { return false; } if (!WorldGen.AnchorValid(Framing.GetTileSafely(j, sy + h), anchor)) { return false; } } } return true; }
public static bool AnchorValid(Tile tileCache, AnchorType anchor) { bool flag = false; if (tileCache.nactive()) { if ((anchor & AnchorType.SolidTile) == AnchorType.SolidTile && Main.tileSolid[(int)tileCache.type] && !Main.tileSolidTop[(int)tileCache.type] && !Main.tileNoAttach[(int)tileCache.type] && tileCache.blockType() == 0) { flag = true; } if ((anchor & AnchorType.SolidBottom) == AnchorType.SolidBottom && !Main.tileNoAttach[(int)tileCache.type] && ((Main.tileSolid[(int)tileCache.type] && (!Main.tileSolidTop[(int)tileCache.type] || (tileCache.type == 19 && (tileCache.halfBrick() || tileCache.topSlope())))) || tileCache.topSlope() || tileCache.halfBrick()) && !TileID.Sets.NotReallySolid[(int)tileCache.type] && !tileCache.bottomSlope()) { flag = true; } if (!flag && ((anchor & AnchorType.SolidWithTop) == AnchorType.SolidWithTop || (anchor & AnchorType.Table) == AnchorType.Table)) { if (tileCache.type == 19) { int num = (int)tileCache.frameX / TileObjectData.PlatformFrameWidth(); if ((!tileCache.halfBrick() && num >= 0 && num <= 7) || (num >= 12 && num <= 16) || (num >= 25 && num <= 26)) { flag = true; } } else if (Main.tileSolid[(int)tileCache.type] && Main.tileSolidTop[(int)tileCache.type]) { flag = true; } } if (!flag && (anchor & AnchorType.Table) == AnchorType.Table && tileCache.type != 19 && Main.tileTable[(int)tileCache.type] && tileCache.blockType() == 0) { flag = true; } if (!flag && (anchor & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[(int)tileCache.type] && !Main.tileSolidTop[(int)tileCache.type]) { switch (tileCache.blockType()) { case 4: case 5: flag = true; break; } } } else if (!flag && (anchor & AnchorType.EmptyTile) == AnchorType.EmptyTile) { flag = true; } return flag; }
/// <summary> /// Draw the "Anchors" property block. /// </summary> protected virtual void DrawFinalProperties () { if (NGUIEditorTools.DrawHeader("Anchors")) { NGUIEditorTools.BeginContents(); NGUIEditorTools.SetLabelWidth(62f); GUILayout.BeginHorizontal(); AnchorType type = (AnchorType)EditorGUILayout.EnumPopup("Type", mAnchorType); GUILayout.Space(18f); GUILayout.EndHorizontal(); SerializedProperty[] tg = new SerializedProperty[4]; for (int i = 0; i < 4; ++i) tg[i] = serializedObject.FindProperty(FieldName[i] + ".target"); if (mAnchorType == AnchorType.None && type != AnchorType.None) { if (mTarget[0] == null && mTarget[1] == null && mTarget[2] == null && mTarget[3] == null) { UIRect rect = target as UIRect; UIRect parent = NGUITools.FindInParents<UIRect>(rect.cachedTransform.parent); if (parent != null) for (int i = 0; i < 4; ++i) mTarget[i] = parent.cachedTransform; } for (int i = 0; i < 4; ++i) { tg[i].objectReferenceValue = mTarget[i]; mTarget[i] = null; } serializedObject.ApplyModifiedProperties(); serializedObject.Update(); } if (type == AnchorType.Advanced) { if (mAnchorType == AnchorType.None) UpdateAnchors(false, true, true); DrawAnchor(0, true); DrawAnchor(1, true); DrawAnchor(2, true); DrawAnchor(3, true); } else if (type == AnchorType.Unified) { if (mAnchorType == AnchorType.None) UpdateAnchors(false, true, true); DrawSingleAnchorSelection(false); DrawAnchor(0, false); DrawAnchor(1, false); DrawAnchor(2, false); DrawAnchor(3, false); } else if (type == AnchorType.None && mAnchorType != type) { // Save values to make it easy to "go back" for (int i = 0; i < 4; ++i) { mTarget[i] = tg[i].objectReferenceValue as Transform; tg[i].objectReferenceValue = null; } serializedObject.FindProperty("leftAnchor.relative").floatValue = 0f; serializedObject.FindProperty("bottomAnchor.relative").floatValue = 0f; serializedObject.FindProperty("rightAnchor.relative").floatValue = 1f; serializedObject.FindProperty("topAnchor.relative").floatValue = 1f; } mAnchorType = type; OnDrawFinalProperties(); NGUIEditorTools.EndContents(); } }
public AnchorData(AnchorType t, int count, int start) { type = t; tileCount = count; checkStart = start; }
/ Math.Sqrt(2)); // 3mm bán kính, 0.5mm độ rộng nét public Spot this[AnchorType anchorType] { get { return(anchors[(int)anchorType]); } }
public bool Detect(AnchorType anchorType) { int dx, dy; int startX, startY, endX, endY, stepX, stepY; dx = dy = startX = startY = endX = endY = stepX = stepY = 0; bool hasTry = false; // Giới hạn detect lại for (; !hasTry;) { switch (anchorType) { #region Khởi tạo các giá trị dx,dy, ... case AnchorType.TopLeft: dx = -1; dy = -1; startX = 1; endX = SearchAnchorBoxSize; startY = 1; endY = SearchAnchorBoxSize; stepX = 1; stepY = 1; break; case AnchorType.BottomLeft: dx = -1; dy = 1; startX = 1; endX = SearchAnchorBoxSize; startY = acq.Height - 1; endY = acq.Height - SearchAnchorBoxSize; stepX = 1; stepY = -1; break; case AnchorType.BottomRight: dx = 1; dy = 1; startX = acq.Width - 1; endX = acq.Width - SearchAnchorBoxSize; startY = acq.Height - 1; endY = acq.Height - SearchAnchorBoxSize; stepX = -1; stepY = -1; break; case AnchorType.TopRight: dx = 1; dy = -1; startX = acq.Width - 1; startY = 1; endX = acq.Width - SearchAnchorBoxSize; endY = SearchAnchorBoxSize; stepX = -1; stepY = 1; break; #endregion } for (int y = startY; (y - endY) * stepY < 0; y += stepY) { for (int x = startX; (x - endX) * stepX < 0; x += stepX) { if (// Ô hiện tại và 3 ô hướng khác gần kín ((acq.IsBlack(x, y) + acq.IsBlack(x + dx, y + dy) + acq.IsBlack(x + dx, y) + acq.IsBlack(x, y + dy)) >= 3) // Hướng ngược lại là trắng && ((acq.IsBlack(x - dx, y - dy) + acq.IsBlack(x - dx, y) + acq.IsBlack(x, y - dy)) == 0) // Tâm hướng chéo trên phải đậm && (acq.CaculateBlackArea(x + dDiagonal * dx / 2, y + dDiagonal * dy / 2) >= 9 * 0.7) // Điểm xa chéo là trống. && (acq.IsBlack(x + 2 * dDiagonal * dx, y + 2 * dDiagonal * dy) == 0)) { this.anchors[(int)anchorType].X = x; this.anchors[(int)anchorType].Y = y; return(true); } } } if (!hasTry) { hasTry = true; dDiagonal = dDiagonal - 2; } else { Inform(this, "{0}: không tìm thấy!!!", anchorType.ToString()); return(false); } } return(false); }
private bool doesAnchorMatch(AnchorType anchorType, ArrayConsList<char> currentPos, int afterLastMatchIndex) { switch (anchorType) { case AnchorType.StartOfString: return currentPos.IsStartOfArray; case AnchorType.StartOfLine: return currentPos.IsStartOfArray || currentPos.Prev == '\n'; case AnchorType.EndOfString: return currentPos.IsEmpty; case AnchorType.EndOfLine: return currentPos.IsEmpty || currentPos.Head == '\n'; case AnchorType.EndOfStringOrBeforeEndingNewline: return currentPos.DropWhile(c => c == '\n').IsEmpty; case AnchorType.ContiguousMatch: return currentPos.ArrayIndex == afterLastMatchIndex; case AnchorType.WordBoundary: return isWordBoundary(currentPos); case AnchorType.NonWordBoundary: return !isWordBoundary(currentPos); default: throw new ApplicationException( string.Format("BacktrackingMatcher: illegal anchor type ({0}).", anchorType.ToString())); } }
/// <summary> /// Draw the "Anchors" property block. /// </summary> protected virtual void DrawFinalProperties() { if (NGUIEditorTools.DrawHeader("Anchors")) { NGUIEditorTools.BeginContents(); NGUIEditorTools.SetLabelWidth(62f); GUILayout.BeginHorizontal(); AnchorType type = (AnchorType)EditorGUILayout.EnumPopup("Type", mAnchorType); GUILayout.Space(18f); GUILayout.EndHorizontal(); SerializedProperty[] tg = new SerializedProperty[4]; for (int i = 0; i < 4; ++i) { tg[i] = serializedObject.FindProperty(FieldName[i] + ".target"); } if (mAnchorType == AnchorType.None && type != AnchorType.None) { if (type == AnchorType.Unified) { if (mTarget[0] == null && mTarget[1] == null && mTarget[2] == null && mTarget[3] == null) { UIRect rect = target as UIRect; UIRect parent = NGUITools.FindInParents <UIRect>(rect.cachedTransform.parent); if (parent != null) { for (int i = 0; i < 4; ++i) { mTarget[i] = parent.cachedTransform; } } } } for (int i = 0; i < 4; ++i) { tg[i].objectReferenceValue = mTarget[i]; mTarget[i] = null; } UpdateAnchors(); } if (type == AnchorType.Advanced) { DrawAnchor(0, true); DrawAnchor(1, true); DrawAnchor(2, true); DrawAnchor(3, true); } else if (type == AnchorType.Unified) { DrawSingleAnchorSelection(); DrawAnchor(0, false); DrawAnchor(1, false); DrawAnchor(2, false); DrawAnchor(3, false); } else if (type == AnchorType.None && mAnchorType != type) { // Save values to make it easy to "go back" for (int i = 0; i < 4; ++i) { mTarget[i] = tg[i].objectReferenceValue as Transform; tg[i].objectReferenceValue = null; } serializedObject.FindProperty("leftAnchor.relative").floatValue = 0f; serializedObject.FindProperty("bottomAnchor.relative").floatValue = 0f; serializedObject.FindProperty("rightAnchor.relative").floatValue = 1f; serializedObject.FindProperty("topAnchor.relative").floatValue = 1f; } mAnchorType = type; OnDrawFinalProperties(); NGUIEditorTools.EndContents(); } }
public WorldUIAnchor(Vector2 anchor) { type = AnchorType.Pos; pos = anchor; }
/// <summary> /// Calculates the distance between an old anchor point and a new anchor point. /// </summary> /// <param name="oldType"></param> /// <param name="newType"></param> /// <param name="size"></param> public static XVector CalcDistance(AnchorType oldType, AnchorType newType, XSize size) { if (oldType == newType) return new XVector(); XVector result; Delta delta = Deltas[(int)oldType, (int)newType]; result = new XVector(size.Width / 2 * delta.X, size.Height / 2 * delta.Y); return result; }
public WorldUIAnchor() { type = AnchorType.None; }
public static void SetAnchorType(this RectTransform RT, AnchorType type) { switch (type) { case AnchorType.TopCenter: RT.anchorMin = new Vector2(0.5f, 1); RT.anchorMax = new Vector2(0.5f, 1); break; case AnchorType.LeftCenter: RT.anchorMin = new Vector2(0, 0.5f); RT.anchorMax = new Vector2(0, 0.5f); break; case AnchorType.RightCenter: RT.anchorMin = new Vector2(1, 0.5f); RT.anchorMax = new Vector2(1, 0.5f); break; case AnchorType.BottomCenter: RT.anchorMin = new Vector2(0.5f, 0); RT.anchorMax = new Vector2(0.5f, 0); break; case AnchorType.TopLeft: RT.anchorMin = new Vector2(0, 1); RT.anchorMax = new Vector2(0, 1); break; case AnchorType.TopRight: RT.anchorMin = new Vector2(1, 1); RT.anchorMax = new Vector2(1, 1); break; case AnchorType.BottomLeft: RT.anchorMin = new Vector2(0, 0); RT.anchorMax = new Vector2(0, 0); break; case AnchorType.BottomRight: RT.anchorMin = new Vector2(1, 0); RT.anchorMax = new Vector2(1, 0); break; case AnchorType.Center: RT.anchorMin = new Vector2(0.5f, 0.5f); RT.anchorMax = new Vector2(0.5f, 0.5f); break; default: //Center RT.anchorMin = new Vector2(0.5f, 0.5f); RT.anchorMax = new Vector2(0.5f, 0.5f); break; } }
/// <summary> /// Calculates the distance between an old anchor point and a new anchor point. /// </summary> /// <param name="oldType"></param> /// <param name="newType"></param> /// <param name="size"></param> public static XVector CalcDistance(AnchorType oldType, AnchorType newType, XSize size) { if (oldType == newType) return new XVector(); XVector result; Delta delta = CodeBase.deltas[(int)oldType, (int)newType]; result = new XVector(size.width / 2 * delta.x, size.height / 2 * delta.y); return result; }
public AnchorVerifierSourceData(HashSet <string> entries, AnchorType anchorType) { _entries = entries; _type = anchorType; }
public override void Resize(AnchorType anchorType, double x, double y) { double xmin1, xmin2; double xmax1, xmax2; double ymin1, ymin2; double ymax1, ymax2; xmin1 = xmin2 = Math.Min(start.X, end.X); xmax1 = xmax2 = Math.Max(start.X, end.X); ymin1 = ymin2 = Math.Min(start.Y, end.Y); ymax1 = ymax2 = Math.Max(start.Y, end.Y); switch (anchorType) { case AnchorType.TopLeft: xmin1 += x; ymin1 += y; break; case AnchorType.Top: ymin1 += y; break; case AnchorType.TopRight: xmax1 += x; ymin1 += y; break; case AnchorType.Right: xmax1 += x; break; case AnchorType.BottomRight: xmax1 += x; ymax1 += y; break; case AnchorType.Bottom: ymax1 += y; break; case AnchorType.BottomLeft: xmin1 += x; ymax1 += y; break; case AnchorType.Left: xmin1 += x; break; } if (start.X == xmin2) { start.X = xmin1; end.X = xmax1; } else { end.X = xmin1; start.X = xmax1; } if (start.Y == ymin2) { start.Y = ymin1; end.Y = ymax1; } else { start.Y = ymax1; end.Y = ymin1; } }
static void FixAnchors(AnchorType type, GameObject[] gameObjs = null) { Undo.RecordObjects(gameObjs, "Anchors objects"); if (gameObjs == null || gameObjs.Length == 0) { gameObjs = Selection.gameObjects; } foreach (GameObject go in gameObjs) { RectTransform rectTransform = go.GetComponent <RectTransform>(); if (rectTransform == null) { continue; } Vector3[] corners = new Vector3[4]; Vector3[] parentCorners = new Vector3[4]; RectTransform parentRectTransform = rectTransform.parent.GetComponent <RectTransform>(); if (parentRectTransform == null) { Debug.Log(string.Format("Selected element {0} has no RectTransform Component.GameObject is skipped", go.name)); continue; } bool hasAspectRatio = false; if (go.GetComponent <AspectRatioFitter>() != null && go.GetComponent <AspectRatioFitter>().enabled == true) { hasAspectRatio = true; go.GetComponent <AspectRatioFitter>().enabled = false; } Canvas canvas = rectTransform.GetComponentInParent <Canvas>(); rectTransform.GetWorldCorners(corners); parentRectTransform.GetWorldCorners(parentCorners); float rectUIWidth = canvas.transform.localScale.x * rectTransform.rect.width; float rectUIHeight = canvas.transform.localScale.y * rectTransform.rect.height; float parentUIWidth = parentRectTransform.rect.width * canvas.transform.localScale.x; float parentUIHeight = parentRectTransform.rect.height * canvas.transform.localScale.y; Vector2 parentZeroCorner = parentCorners[0]; float parent_x = parentZeroCorner.x + ((parentCorners[3].x - parentZeroCorner.x) / 2); float parent_y = parentZeroCorner.y + ((parentCorners[1].y - parentZeroCorner.y) / 2); float parentXMin = parent_x - (parentUIWidth / 2); float parentYMin = parent_y - (parentUIHeight / 2); float minX = corners[0].x; float maxY = corners[3].y; Vector2 anchorMinPoint = new Vector2(minX - parentXMin, maxY - parentYMin); Vector2 anchorMaxPoint = Vector2.zero; Vector2 offsetMin = Vector2.zero; Vector2 offsetMax = Vector2.zero; switch (type) { case AnchorType.Strech: anchorMaxPoint.x = anchorMinPoint.x + rectUIWidth; anchorMaxPoint.y = anchorMinPoint.y + rectUIHeight; break; case AnchorType.Top: anchorMinPoint.y += rectUIHeight; anchorMaxPoint.x = anchorMinPoint.x + rectUIWidth; anchorMaxPoint.y = anchorMinPoint.y; offsetMax = Vector2.zero; offsetMin = new Vector2(0f, -rectTransform.rect.height); break; case AnchorType.Middle: anchorMinPoint.y += rectUIHeight / 2; anchorMaxPoint.x = anchorMinPoint.x + rectUIWidth; anchorMaxPoint.y = anchorMinPoint.y; offsetMax = new Vector2(0f, +rectTransform.rect.height / 2); offsetMin = new Vector2(0f, -rectTransform.rect.height / 2); break; case AnchorType.Bottom: anchorMaxPoint.x = anchorMinPoint.x + rectUIWidth; anchorMaxPoint.y = anchorMinPoint.y; offsetMax = new Vector2(0f, rectTransform.rect.height); offsetMin = Vector2.zero; break; case AnchorType.Left: anchorMaxPoint.x = anchorMinPoint.x; anchorMaxPoint.y = anchorMinPoint.y + rectUIHeight; offsetMax = new Vector2(rectTransform.rect.width, 0f); offsetMin = Vector2.zero; break; case AnchorType.Center: anchorMinPoint.x += rectUIWidth / 2; anchorMaxPoint.x = anchorMinPoint.x; anchorMaxPoint.y = anchorMinPoint.y + rectUIHeight; offsetMax = new Vector2(rectTransform.rect.width / 2, 0f); offsetMin = new Vector2(-rectTransform.rect.width / 2, 0f); break; case AnchorType.Right: anchorMinPoint.x += rectUIWidth; anchorMaxPoint.x = anchorMinPoint.x; anchorMaxPoint.y = anchorMinPoint.y + rectUIHeight; offsetMax = Vector2.zero; offsetMin = new Vector2(-rectTransform.rect.width, 0f); break; case AnchorType.TopLeft: anchorMinPoint.y += rectUIHeight; anchorMaxPoint = anchorMinPoint; offsetMax = new Vector2(rectTransform.rect.width, 0f); offsetMin = new Vector2(0f, -rectTransform.rect.height); break; case AnchorType.TopCenter: anchorMinPoint.x += rectUIWidth / 2; anchorMinPoint.y += rectUIHeight; anchorMaxPoint = anchorMinPoint; offsetMax = new Vector2(rectTransform.rect.width / 2, 0f); offsetMin = new Vector2(-rectTransform.rect.width / 2, -rectTransform.rect.height); break; case AnchorType.TopRight: anchorMinPoint.x += rectUIWidth; anchorMinPoint.y += rectUIHeight; anchorMaxPoint = anchorMinPoint; offsetMax = Vector2.zero; offsetMin = new Vector2(-rectTransform.rect.width, -rectTransform.rect.height); break; case AnchorType.MiddleLeft: anchorMinPoint.y += rectUIHeight / 2; anchorMaxPoint = anchorMinPoint; offsetMax = new Vector2(rectTransform.rect.width, rectTransform.rect.height / 2); offsetMin = new Vector2(0f, -rectTransform.rect.height / 2); break; case AnchorType.MiddleCenter: anchorMinPoint.x += rectUIWidth / 2; anchorMinPoint.y += rectUIHeight / 2; anchorMaxPoint = anchorMinPoint; offsetMax = new Vector2(rectTransform.rect.width / 2, rectTransform.rect.height / 2); offsetMin = new Vector2(-rectTransform.rect.width / 2, -rectTransform.rect.height / 2); break; case AnchorType.MiddleRight: anchorMinPoint.x += rectUIWidth; anchorMinPoint.y += rectUIHeight / 2; anchorMaxPoint = anchorMinPoint; offsetMax = new Vector2(0f, rectTransform.rect.height / 2); offsetMin = new Vector2(-rectTransform.rect.width, -rectTransform.rect.height / 2); break; case AnchorType.BottomLeft: anchorMaxPoint = anchorMinPoint; offsetMax = new Vector2(rectTransform.rect.width, rectTransform.rect.height); offsetMin = Vector2.zero; break; case AnchorType.BottomCenter: anchorMinPoint.x += rectUIWidth / 2; anchorMaxPoint = anchorMinPoint; offsetMax = new Vector2(rectTransform.rect.width / 2, rectTransform.rect.height); offsetMin = new Vector2(-rectTransform.rect.width / 2, 0f); break; case AnchorType.BottomRight: anchorMinPoint.x += rectUIWidth; anchorMaxPoint = anchorMinPoint; offsetMax = new Vector2(0f, rectTransform.rect.height); offsetMin = new Vector2(-rectTransform.rect.width, 0f); break; } //Convert to relative anchor coordinates anchorMinPoint.x /= parentUIWidth; anchorMinPoint.y /= parentUIHeight; anchorMaxPoint.x /= parentUIWidth; anchorMaxPoint.y /= parentUIHeight; //apply new anchors rectTransform.anchorMin = anchorMinPoint; rectTransform.anchorMax = anchorMaxPoint; rectTransform.offsetMax = offsetMax; rectTransform.offsetMin = offsetMin; if (hasAspectRatio) { go.GetComponent <AspectRatioFitter>().enabled = true; } } }
public static void AnchorEx(RectTransform rect, AnchorType type, Vector2 offset, Vector2 p, Vector2 psize) { AnchorEx(rect, Anchors[(int)type], offset, p, psize); }
public static Vector2 AntiAnchorEx(Vector2 tp, AnchorType type, Vector2 p, Vector2 psize) { return(AntiAnchorEx(tp, Anchors[(int)type], p, psize)); }
public static void SetAnchor(AnchorType at, Image image) { SetAnchor(at, image.GetComponent<RectTransform>()); }
private void AddPopup(Currency currency, double amount, TransactionReasons transactionReason, string reason, Transform referencePosition, AnchorType anchorType, bool isDelta, bool isFacility = false) { Popup popup = new Popup(); popup.currency = currency; popup.amount = amount; popup.transactionReason = transactionReason; popup.reason = reason; popup.anchorType = anchorType; popup.referencePosition = referencePosition; popup.isFacility = isFacility; popup.isDelta = isDelta; // Special stuff if (isFacility) { popup.initialized = false; } // Attempt to combine duplicates Popup last = popups.LastOrDefault(); if (last != null && last.currency == currency && last.transactionReason == transactionReason && last.reason == reason) { last.amount += amount; } else { popups.Add(popup); } }
public static void SetAnchor(AnchorType at, Button button) { SetAnchor(at, button.GetComponent<RectTransform>()); }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ public static Vector2 GetRelativeAnchorPosition(AnchorType pAnchor) { return(GetRelativeAnchorPosition((AnchorTypeWithCustom)pAnchor)); }
/// <summary> /// Draws the marker /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="bHorizontal"></param> /// <param name="anchorType"></param> private void DrawMarker(Graphics g, int x, int y, bool bHorizontal, AnchorType anchorType) { Pen pen = (anchorType == AnchorType.None) ? Pens.LightGray : Pens.Black; if (bHorizontal) { g.DrawLine(pen, x - mMargin / 2, y, x + mMargin / 2, y); g.DrawLine(pen, x - mMargin / 2, y - 2, x - mMargin / 2, y + 2); g.DrawLine(pen, x + mMargin / 2, y - 2, x + mMargin / 2, y + 2); } else { g.DrawLine(pen, x, y - mMargin / 2, x, y + mMargin / 2); g.DrawLine(pen, x - 2, y - mMargin / 2, x + 2, y - mMargin / 2); g.DrawLine(pen, x - 2, y + mMargin / 2, x + 2, y + mMargin / 2); } if (anchorType == AnchorType.Relative) { string str = "%"; SizeF dim = g.MeasureString(str, this.Font); g.FillRectangle(Brushes.White, x - dim.Width / 2, y - dim.Height / 2, dim.Width, dim.Height); g.DrawString(str, this.Font, Brushes.Black, x - dim.Width / 2, y - dim.Height / 2); } }
public void DrawAnchorTransform () { if (NGUIEditorTools.DrawHeader("Anchors")) { NGUIEditorTools.BeginContents(); NGUIEditorTools.SetLabelWidth(NGUISettings.minimalisticLook ? 69f : 62f); EditorGUI.BeginDisabledGroup(!((target as UIRect).canBeAnchored)); GUILayout.BeginHorizontal(); AnchorType type = (AnchorType)EditorGUILayout.EnumPopup("Type", mAnchorType); NGUIEditorTools.DrawPadding(); GUILayout.EndHorizontal(); SerializedProperty[] tg = new SerializedProperty[4]; for (int i = 0; i < 4; ++i) tg[i] = serializedObject.FindProperty(FieldName[i] + ".target"); if (mAnchorType == AnchorType.None && type != AnchorType.None) { if (type == AnchorType.Unified) { if (mTarget[0] == null && mTarget[1] == null && mTarget[2] == null && mTarget[3] == null) { UIRect rect = target as UIRect; UIRect parent = NGUITools.FindInParents<UIRect>(rect.cachedTransform.parent); if (parent != null) for (int i = 0; i < 4; ++i) mTarget[i] = parent.cachedTransform; } } for (int i = 0; i < 4; ++i) { tg[i].objectReferenceValue = mTarget[i]; mTarget[i] = null; } UpdateAnchors(true); } if (type != AnchorType.None) { NGUIEditorTools.DrawPaddedProperty("Execute", serializedObject, "updateAnchors"); } if (type == AnchorType.Advanced) { DrawAnchor(0, true); DrawAnchor(1, true); DrawAnchor(2, true); DrawAnchor(3, true); } else if (type == AnchorType.Unified) { DrawSingleAnchorSelection(); DrawAnchor(0, false); DrawAnchor(1, false); DrawAnchor(2, false); DrawAnchor(3, false); } else if (type == AnchorType.None && mAnchorType != type) { // Save values to make it easy to "go back" for (int i = 0; i < 4; ++i) { mTarget[i] = tg[i].objectReferenceValue as Transform; tg[i].objectReferenceValue = null; } serializedObject.FindProperty("leftAnchor.relative").floatValue = 0f; serializedObject.FindProperty("bottomAnchor.relative").floatValue = 0f; serializedObject.FindProperty("rightAnchor.relative").floatValue = 1f; serializedObject.FindProperty("topAnchor.relative").floatValue = 1f; } mAnchorType = type; OnDrawFinalProperties(); EditorGUI.EndDisabledGroup(); NGUIEditorTools.EndContents(); } }
public LayoutCellInfo(GUILayouterType t, AnchorType a, Rect r) { type = t; anchor = a; cellRect = r; }
/// <summary> /// Manually re-evaluate the current anchor type. /// </summary> protected void ReEvaluateAnchorType () { UIRect rect = target as UIRect; if (rect.leftAnchor.target == rect.rightAnchor.target && rect.leftAnchor.target == rect.bottomAnchor.target && rect.leftAnchor.target == rect.topAnchor.target) { if (rect.leftAnchor.target == null) { mAnchorType = AnchorType.None; } else { mAnchorType = AnchorType.Unified; } } else mAnchorType = AnchorType.Advanced; }
/// <summary> /// create the anchor /// </summary> /// <param name="dx1"></param> /// <param name="dy1"></param> /// <param name="dx2"></param> /// <param name="dy2"></param> /// <param name="col1"></param> /// <param name="row1"></param> /// <param name="col2"></param> /// <param name="row2"></param> /// <param name="anchorType"></param> /// <returns></returns> private static HSSFClientAnchor CreateClientAnchor(int dx1, int dy1, int dx2, int dy2, int col1, int row1, int col2, int row2, AnchorType anchorType) { HSSFClientAnchor anchor; anchor = new HSSFClientAnchor(dx1, dy1, dx2, dy2, col1, row1, col2, row2); anchor.AnchorType = anchorType; return(anchor); }