/// <summary> /// Render /// </summary> public void Render() { Vector2i labelSize = RB.PrintMeasure(mLabel); int yPos; if (mLabelBottomAligned) { yPos = mRect.y + mRect.height - labelSize.y - 4; } else { yPos = mRect.y + (mRect.height / 2) - (labelSize.y / 2); } if (mPressed) { RB.DrawRectFill(new Rect2i(mRect.x + 2, mRect.y + 2, mRect.width - 2, mRect.height - 2), Color.gray); RB.Print(new Vector2i(mRect.x + (mRect.width / 2) - (labelSize.x / 2) + 1, yPos + 1), Color.black, mLabel); } else { RB.DrawRectFill(mRect, Color.gray); RB.Print(new Vector2i(mRect.x + (mRect.width / 2) - (labelSize.x / 2), yPos), Color.black, mLabel); RB.DrawRect(mRect, Color.white); } mHitRect = new Rect2i(-RB.CameraGet().x + mHotZone.x, -RB.CameraGet().y + mHotZone.y, mHotZone.width, mHotZone.height); }
/// <summary> /// Constructor /// </summary> public Paddle() { var game = (BrickBustGame)RB.Game; // If mobile then we want to leave a bigger gap on the bottom of the screen as a touch space if (Application.isMobilePlatform) { Rect = new Rect2i((RB.DisplaySize.width / 2) - 12, RB.DisplaySize.height - (game.assets.spriteSheet.grid.cellSize.height * 6), game.assets.spriteSheet.grid.cellSize.width * 3, game.assets.spriteSheet.grid.cellSize.height); } else { Rect = new Rect2i((RB.DisplaySize.width / 2) - 12, RB.DisplaySize.height - (game.assets.spriteSheet.grid.cellSize.height * 3), game.assets.spriteSheet.grid.cellSize.width * 3, game.assets.spriteSheet.grid.cellSize.height); } mBaseRect = Rect; mExtendedRect = new Rect2i(Rect.x - 10, Rect.y, Rect.width + 20, Rect.height); mPos = new Vector2i((int)Rect.center.x, (int)Rect.center.y); int frameOffset = 0; mNSFrame.Add(new NineSlice(new Rect2i(0 + frameOffset, 10, 6, 10), new Rect2i(6 + frameOffset, 10, 18, 10), new Rect2i(24 + frameOffset, 10, 6, 10), new Rect2i(), new Rect2i(), new Rect2i(), new Rect2i(), new Rect2i(), new Rect2i())); frameOffset += 30; mNSFrame.Add(new NineSlice(new Rect2i(0 + frameOffset, 10, 6, 10), new Rect2i(6 + frameOffset, 10, 18, 10), new Rect2i(24 + frameOffset, 10, 6, 10), new Rect2i(), new Rect2i(), new Rect2i(), new Rect2i(), new Rect2i(), new Rect2i())); frameOffset += 30; mNSFrame.Add(new NineSlice(new Rect2i(0 + frameOffset, 10, 6, 10), new Rect2i(6 + frameOffset, 10, 18, 10), new Rect2i(24 + frameOffset, 10, 6, 10), new Rect2i(), new Rect2i(), new Rect2i(), new Rect2i(), new Rect2i(), new Rect2i())); frameOffset += 30; mNSFrame.Add(new NineSlice(new Rect2i(0 + frameOffset, 10, 6, 10), new Rect2i(6 + frameOffset, 10, 18, 10), new Rect2i(24 + frameOffset, 10, 6, 10), new Rect2i(), new Rect2i(), new Rect2i(), new Rect2i(), new Rect2i(), new Rect2i())); }
/// <summary> /// Render /// </summary> public void Render() { if (mAlpha <= 0) { return; } RB.TintColorSet(ColorTint); byte prevAlpha = RB.AlphaGet(); RB.AlphaSet((byte)(mAlpha * prevAlpha)); int LifeFrame = 5 - (int)(((float)Life / (float)MaxLife) * 5); if (Type != BrickType.Block) { LastSpriteRect = new Rect2i(Global.BRICK_WIDTH * LifeFrame, 0, Rect.width, Rect.height); } else { LastSpriteRect = new Rect2i(120, 0, 20, 10); } RB.DrawCopy(LastSpriteRect, Rect); for (int i = 0; i < FlashFrame; i++) { RB.DrawRect(new Rect2i(Rect.x + i, Rect.y + i, Rect.width - (i * 2), Rect.height - (i * 2)), Color.white); } RB.TintColorSet(Color.white); RB.AlphaSet(prevAlpha); }
private static void RenderMouseHover() { var tilePos = SceneGame.GetMouseTilePos(); if (tilePos.x == -1) { return; } EntityFunctions.GetEntitiesStringAtTile(tilePos, C.FSTR); if (C.FSTR.Length > 0) { // Preserve camera location var cameraPos = RB.CameraGet(); RB.CameraReset(); var mousePos = RB.PointerPos(); var anchorPos = new Vector2i(mousePos.x + 4, mousePos.y + 12); var textSize = RB.PrintMeasure(C.FONT_SMALL, C.FSTR); var textRect = new Rect2i(anchorPos.x, anchorPos.y, textSize.width, textSize.height); var textFrameRect = new Rect2i(textRect.x - 4, textRect.y - 4, textRect.width + 8, textRect.height + 8); RB.DrawRectFill(textFrameRect, C.COLOR_MENU_BACKGROUND); RB.DrawRect(textFrameRect, Color.white); RB.Print(C.FONT_SMALL, textRect, Color.white, 0, C.FSTR); RB.CameraSet(cameraPos); } }
/// <summary> /// Render /// </summary> public void Render() { var demo = (DemoReel)RB.Game; Vector2i labelSize = RB.PrintMeasure(mLabel); int yPos; if (mLabelBottomAligned) { yPos = mRect.y + mRect.height - labelSize.y - 4; } else { yPos = mRect.y + (mRect.height / 2) - (labelSize.y / 2); } if (mPressed) { RB.DrawRectFill(new Rect2i(mRect.x + 2, mRect.y + 2, mRect.width - 2, mRect.height - 2), DemoUtil.IndexToRGB(5)); RB.Print(new Vector2i(mRect.x + (mRect.width / 2) - (labelSize.x / 2) + 1, yPos + 1), DemoUtil.IndexToRGB(mLabelColor), mLabel); } else { RB.DrawRectFill(mRect, DemoUtil.IndexToRGB(mFaceColor)); RB.Print(new Vector2i(mRect.x + (mRect.width / 2) - (labelSize.x / 2), yPos), DemoUtil.IndexToRGB(mLabelColor), mLabel); RB.DrawRect(mRect, DemoUtil.IndexToRGB(5)); } mHitRect = new Rect2i(-RB.CameraGet().x + mHotZone.x, -RB.CameraGet().y + mHotZone.y, mHotZone.width, mHotZone.height); }
/// <summary> /// Return a random position along the perimeter of the rect /// </summary> /// <param name="rect">Rect</param> /// <returns>Random position</returns> public static Vector2i RandomRectPerimeterPos(Rect2i rect) { int pLen = (rect.width * 2) + (rect.height * 2) - 4; int rand = Random.Range(0, pLen); if (rand < rect.width) { return(new Vector2i(rect.x + rand, rect.y)); } rand -= rect.width; if (rand < rect.width) { return(new Vector2i(rect.x + rand, rect.y + rect.height - 1)); } rand -= rect.width; if (rand < rect.height - 2) { return(new Vector2i(rect.x, rect.y + rand + 1)); } rand -= rect.height - 2; return(new Vector2i(rect.x + rect.width - 1, rect.y + rand + 1)); }
public Rect2i(Rect2i r) { left = r.left; top = r.top; right = r.right; bottom = r.bottom; }
/// <summary> /// Simple nine-slice constructor, all corners and sides are mirrored and rotated /// </summary> /// <param name="topLeftCorner">Top left corner PackedSprite</param> /// <param name="topSide">Top side PackedSprite</param> /// <param name="middle">Middle PackedSprite</param> public NineSlice(PackedSprite topLeftCorner, PackedSprite topSide, PackedSprite middle) { TopLeftCornerID = topLeftCorner.id; TopSideID = topSide.id; TopRightCornerID = topLeftCorner.id; LeftSideID = topSide.id; MiddleID = middle.id; RightSideID = topSide.id; BottomLeftCornerID = topLeftCorner.id; BottomSideID = topSide.id; BottomRightCornerID = topLeftCorner.id; FlagsTopLeftCorner = 0; FlagsTopSide = 0; FlagsTopRightCorner = RB.FLIP_H; FlagsLeftSide = RB.ROT_90_CCW; FlagsRightSide = RB.ROT_90_CW; FlagsBottomLeftCorner = RB.FLIP_V; FlagsBottomSide = RB.FLIP_V; FlagsBottomRightCorner = RB.FLIP_H | RB.FLIP_V; TopLeftCornerRect = Rect2i.zero; TopSideRect = Rect2i.zero; TopRightCornerRect = Rect2i.zero; LeftSideRect = Rect2i.zero; MiddleRect = Rect2i.zero; RightSideRect = Rect2i.zero; BottomLeftCornerRect = Rect2i.zero; BottomSideRect = Rect2i.zero; BottomRightCornerRect = Rect2i.zero; IsRectBased = false; }
/// <summary> /// Simple nine-slice constructor, all corners and sides are mirrored and rotated /// </summary> /// <param name="topLeftCornerName">Top left corner sprite name</param> /// <param name="topSideName">Top side rect sprite name</param> /// <param name="middleName">Middle rect sprite name</param> public NineSlice(FastString topLeftCornerName, FastString topSideName, FastString middleName) { TopLeftCornerID = RB.PackedSpriteID(topLeftCornerName); TopSideID = RB.PackedSpriteID(topSideName); TopRightCornerID = RB.PackedSpriteID(topLeftCornerName); LeftSideID = RB.PackedSpriteID(topSideName); MiddleID = RB.PackedSpriteID(middleName); RightSideID = RB.PackedSpriteID(topSideName); BottomLeftCornerID = RB.PackedSpriteID(topLeftCornerName); BottomSideID = RB.PackedSpriteID(topSideName); BottomRightCornerID = RB.PackedSpriteID(topLeftCornerName); FlagsTopLeftCorner = 0; FlagsTopSide = 0; FlagsTopRightCorner = RB.FLIP_H; FlagsLeftSide = RB.ROT_90_CCW; FlagsRightSide = RB.ROT_90_CW; FlagsBottomLeftCorner = RB.FLIP_V; FlagsBottomSide = RB.FLIP_V; FlagsBottomRightCorner = RB.FLIP_H | RB.FLIP_V; TopLeftCornerRect = Rect2i.zero; TopSideRect = Rect2i.zero; TopRightCornerRect = Rect2i.zero; LeftSideRect = Rect2i.zero; MiddleRect = Rect2i.zero; RightSideRect = Rect2i.zero; BottomLeftCornerRect = Rect2i.zero; BottomSideRect = Rect2i.zero; BottomRightCornerRect = Rect2i.zero; IsRectBased = false; }
public virtual void Render() { var display = RB.DisplaySize; var menuRect = new Rect2i(display.width / 2 - MENU_WIDTH / 2, display.height / 2, MENU_WIDTH, 24); var summarySize = RB.PrintMeasure(menuRect, RB.ALIGN_H_CENTER | RB.TEXT_OVERFLOW_WRAP, Summary); menuRect.height += summarySize.height; // header var headerSize = RB.PrintMeasure(Header); headerSize.width += 8; var headerRect = new Rect2i(menuRect.x + menuRect.width / 2 - headerSize.width / 2, menuRect.y - 6, headerSize.width, MIN_HEADER_HEIGHT); var summaryRect = new Rect2i(menuRect.x + BORDER_PADDING, menuRect.y + BORDER_PADDING + 8, menuRect.width - BORDER_PADDING, menuRect.height - BORDER_PADDING); RB.DrawRectFill(menuRect, C.MenuBG); RB.DrawRect(menuRect, Color.white); RB.DrawRectFill(headerRect, Color.black); RB.DrawRect(headerRect, Color.white); RB.Print(headerRect, Color.white, RB.ALIGN_H_CENTER | RB.ALIGN_V_CENTER, Header); RB.Print(summaryRect, Color.white, SummaryPrintFlags, Summary); }
/// <summary> /// Simple nine-slice constructor, all corners and sides are mirrored and rotated /// </summary> /// <param name="topLeftCornerRect">Top left corner rect</param> /// <param name="topSideRect">Top side rect</param> /// <param name="middleRect">Middle rect</param> public NineSlice(Rect2i topLeftCornerRect, Rect2i topSideRect, Rect2i middleRect) { TopLeftCornerRect = topLeftCornerRect; TopSideRect = topSideRect; TopRightCornerRect = topLeftCornerRect; LeftSideRect = topSideRect; MiddleRect = middleRect; RightSideRect = topSideRect; BottomLeftCornerRect = topLeftCornerRect; BottomSideRect = topSideRect; BottomRightCornerRect = topLeftCornerRect; FlagsTopLeftCorner = 0; FlagsTopSide = 0; FlagsTopRightCorner = RB.FLIP_H; FlagsLeftSide = RB.ROT_90_CCW; FlagsRightSide = RB.ROT_90_CW; FlagsBottomLeftCorner = RB.FLIP_V; FlagsBottomSide = RB.FLIP_V; FlagsBottomRightCorner = RB.FLIP_H | RB.FLIP_V; PackedSpriteID empty = new PackedSpriteID(0); TopLeftCornerID = empty; TopSideID = empty; TopRightCornerID = empty; LeftSideID = empty; MiddleID = empty; RightSideID = empty; BottomLeftCornerID = empty; BottomSideID = empty; BottomRightCornerID = empty; IsRectBased = true; }
/// <summary> /// Update /// </summary> public virtual void Update() { if (mDead) { return; } mPos.y += 1.0f; mRect = new Rect2i((int)mPos.x, (int)mPos.y, 19, 10); if (mPos.y > RB.DisplaySize.height) { mDead = true; } BrickBustGame game = (BrickBustGame)RB.Game; var level = game.Level; var paddleRect = level.Paddle.Rect; if (paddleRect.Intersects(mRect)) { level.Particles.Explode(new Rect2i(40, 20, mRect.width, mRect.height), new Vector2i((int)mPos.x, (int)mPos.y), mColorTint); Activate(); mDead = true; } }
public Vec2i GetDistanceTo(Rect2i rect) { int vecX; int vecY; if (rect.br.X < this.tl.X) { vecX = rect.br.X - this.tl.X; } else if (rect.tl.X > this.br.X) { vecX = rect.tl.X - this.br.X; } else { vecX = 0; } if (rect.br.Y > this.tl.Y) { vecY = rect.br.Y - this.tl.Y; } else if (rect.tl.Y < this.br.Y) { vecY = rect.tl.Y - this.br.Y; } else { vecY = 0; } return(new Vec2i(vecX, vecY)); }
public bool IsTouching(Rect2i rect) { return((this.tl.X == rect.br.X && this.tl.X > rect.tl.X) || (this.br.X == rect.tl.X && this.br.X < rect.br.X) || (this.tl.Y == rect.br.Y && this.tl.Y < rect.tl.Y) || (this.br.Y == rect.tl.Y && this.br.Y > rect.br.Y)); }
public void Set(Rect2i src) { this.left = src.left; this.top = src.top; this.right = src.right; this.bottom = src.bottom; }
/// <summary> /// Constructor /// </summary> public Paddle() { // If mobile then we want to leave a bigger gap on the bottom of the screen as a touch space if (UnityEngine.Application.isMobilePlatform) { Rect = new Rect2i((RB.DisplaySize.width / 2) - 12, RB.DisplaySize.height - (RB.SpriteSize(0).height * 6), RB.SpriteSize(0).width * 3, RB.SpriteSize(0).height); } else { Rect = new Rect2i((RB.DisplaySize.width / 2) - 12, RB.DisplaySize.height - (RB.SpriteSize(0).height * 3), RB.SpriteSize(0).width * 3, RB.SpriteSize(0).height); } mBaseRect = Rect; mExtendedRect = new Rect2i(Rect.x - 10, Rect.y, Rect.width + 20, Rect.height); mPos = new Vector2i((int)Rect.center.x, (int)Rect.center.y); int frameOffset = 0; mNSFrame.Add(new NineSlice(new Rect2i(0 + frameOffset, 10, 6, 10), new Rect2i(6 + frameOffset, 10, 18, 10), new Rect2i(24 + frameOffset, 10, 6, 10), new Rect2i(), new Rect2i(), new Rect2i(), new Rect2i(), new Rect2i(), new Rect2i())); frameOffset += 30; mNSFrame.Add(new NineSlice(new Rect2i(0 + frameOffset, 10, 6, 10), new Rect2i(6 + frameOffset, 10, 18, 10), new Rect2i(24 + frameOffset, 10, 6, 10), new Rect2i(), new Rect2i(), new Rect2i(), new Rect2i(), new Rect2i(), new Rect2i())); frameOffset += 30; mNSFrame.Add(new NineSlice(new Rect2i(0 + frameOffset, 10, 6, 10), new Rect2i(6 + frameOffset, 10, 18, 10), new Rect2i(24 + frameOffset, 10, 6, 10), new Rect2i(), new Rect2i(), new Rect2i(), new Rect2i(), new Rect2i(), new Rect2i())); frameOffset += 30; mNSFrame.Add(new NineSlice(new Rect2i(0 + frameOffset, 10, 6, 10), new Rect2i(6 + frameOffset, 10, 18, 10), new Rect2i(24 + frameOffset, 10, 6, 10), new Rect2i(), new Rect2i(), new Rect2i(), new Rect2i(), new Rect2i(), new Rect2i())); }
public override void Render() { Rect2i rect = new Rect2i(pos, size); RB.DrawRectFill(rect, boxBackgroundColor); RB.DrawRect(rect, boxOutlineColor); rect.Expand(-4); if ((effect & Shadow) == Shadow) { RB.Print(rect.Offset(new Vector2i(1, 1)), Color.black, RB.NO_INLINE_COLOR | flags, text); } else if ((effect & Outline) == Outline) { for (int dx = -1; dx <= 1; dx++) { for (int dy = -1; dy <= 1; dy++) { RB.Print(rect.Offset(new Vector2i(dx, dy)), Color.black, RB.NO_INLINE_COLOR | flags, text); } } } RB.Print(rect, color, flags, text); foreach (TextButton button in buttons) { button.Render(); } }
public GpuTexture(ReadOnlySpan <byte> Data, ReadOnlyRect2i Size, EPixelFormat Format) { this.Size = new Rect2i(Size); #if ENABLE_HEADLESS == false Push_Frame(Data, Size, Format); #endif }
/// <summary> /// Constructor /// </summary> /// <remarks> /// Constructor. Most often <see cref="RB.PackedSpriteGet"/> should be used instead of created PackedSprite manually. /// <seedoc>Features:Sprite Packs</seedoc> /// </remarks> /// <param name="id">SpriteID of the sprite</param> /// <param name="size">Size of the sprite, untrimmed</param> /// <param name="sourceRect">Source rectangle from within packed texture, may be trimmed</param> /// <param name="trimOffset">Trim offset</param> /// <seealso cref="SpriteSheetAsset"/> /// <seealso cref="RB.PackedSpriteGet"/> public PackedSprite(PackedSpriteID id, Vector2i size, Rect2i sourceRect, Vector2i trimOffset) { mID = id; mSize = size; mSourceRect = sourceRect; mTrimOffset = trimOffset; }
public void RecursiveCalcFinalPos(Group group, Size2i size) { // Compute the LayoutResult.FinalPos for all children group.group_layout_info.Sizer.CalcChildrenFinalPos(group, size); Point2i org = group.DriverGroup.Origin; foreach (Widget w in group.Children) { //position each child before laying out is child controls, since this might be needed //for the layout logic of the childs (for example splitter, needs to access size of splitter panels) if (w.DriverObject != null && group.DriverGroup != null) { Rect2i bounds = w.LayoutResult.FinalPos; if (org != Point2i.Origin) { //the normal case org is Origin, but forexample winforms frame need another origin bounds = bounds.Translate(org.X, org.Y); } w.DriverControl.Bounds = bounds; } //and now compute final pos for each child Group subgrp = w as Group; if (subgrp != null) { RecursiveCalcFinalPos(subgrp, subgrp.LayoutResult.FinalPos.Size); } } }
/// <summary> /// Render /// </summary> public void Render() { for (int i = 0; i < mBlobs.Count; i++) { mBlobs[i].Render(); } Rect2i titleRect = new Rect2i(0, 50, 93, 17); int bob = (int)(Math.Sin(RB.Ticks / 10.0f) * 6); RB.ShaderSet(C.SHADER_SHADOW); RB.ShaderColorSet(C.SHADER_SHADOW, "_ShadowColor", new Color32(0, 0, 0, 196)); RB.DrawCopy(titleRect, new Rect2i((RB.DisplaySize.width / 2) - (titleRect.width / 2) + 3, 32 + bob + 3, titleRect.width, titleRect.height)); RB.ShaderReset(); RB.DrawCopy(titleRect, new Rect2i((RB.DisplaySize.width / 2) - (titleRect.width / 2), 32 + bob, titleRect.width, titleRect.height)); RB.DrawCopy(new Rect2i(38, 68, 199, 188), new Rect2i(11, 96, 199, 188)); RB.ShaderSet(C.SHADER_SHADOW); RB.ShaderColorSet(C.SHADER_SHADOW, "_ShadowColor", new Color32(255, 255, 255, 128)); int highlightOffset = (int)((Math.Sin(RB.Ticks / 50.0f) * RB.DisplaySize.width) + (RB.DisplaySize.width / 2)); int highlightWidth = 20; RB.DrawCopy(new Rect2i(38 + (highlightOffset - 11), 68, highlightWidth, 188), new Rect2i(highlightOffset, 96, highlightWidth, 188)); RB.ShaderReset(); mString.Set("@w244").Append(C.ACTION_VERB).Append(" TO PLAY!"); RB.Print(new Rect2i(0, RB.DisplaySize.height - 80 + 1, RB.DisplaySize.width, 100 + 1), Color.black, RB.ALIGN_H_CENTER | RB.ALIGN_V_CENTER, mString); RB.Print(new Rect2i(0, RB.DisplaySize.height - 80, RB.DisplaySize.width, 100), Color.white, RB.ALIGN_H_CENTER | RB.ALIGN_V_CENTER, mString); }
private void DrawClip(int x, int y) { var demo = (DemoReel)RB.Game; RB.CameraSet(new Vector2i(-x, -y - 25)); mDialogStr.Set("You there!\nThat's a nice\ngolden sword,\nand dragon\nhide armor!\nYou look like\nyou could use a\nfew coppers,\nhow about you\nclean out\nthe @dbab7710@- rats in\nmy basement?"); var size = (int)(Mathf.Sin(RB.Ticks / 20.0f) * 22) * 2; var textRect = new Rect2i(32 - (size / 2), 45, 80 + size, 128); DrawTextFrame(textRect, null); RB.Print(textRect, DemoUtil.IndexToRGB(4), RB.ALIGN_H_CENTER | RB.ALIGN_V_CENTER | RB.TEXT_OVERFLOW_CLIP, mDialogStr); textRect = new Rect2i(32 - (size / 2) + 140, 45, 80 + size, 128); DrawTextFrame(textRect, null); RB.Print(textRect, DemoUtil.IndexToRGB(4), RB.ALIGN_H_CENTER | RB.ALIGN_V_CENTER | RB.TEXT_OVERFLOW_WRAP | RB.TEXT_OVERFLOW_CLIP, mDialogStr); textRect = new Rect2i(32 - (size / 2) + 70, 180, 80 + size, 128); DrawTextFrame(textRect, null); RB.Print(textRect, DemoUtil.IndexToRGB(4), RB.ALIGN_H_CENTER | RB.ALIGN_V_CENTER | RB.TEXT_OVERFLOW_WRAP, mDialogStr); mFormatStr.Set("@C// Clip and wrap text in a text rectangle\n").Append("@Kint@N center = @[email protected]_H_CENTER | @[email protected]_V_CENTER;\n"); mFormatStr.Append("@[email protected](@Knew@N Rect2i(@L20@N, @L20@N, @L").Append(80 + size).Append("@N, @L128@N),\n center | @[email protected]_OVERFLOW_CLIP, myText);\n"); mFormatStr.Append("@[email protected](@Knew@N Rect2i(@L160@N, @L20@N, @L").Append(80 + size).Append("@N, @L128@N),\n center | @[email protected]_OVERFLOW_WRAP | @[email protected]_OVERFLOW_CLIP, myText);\n"); mFormatStr.Append("@[email protected](@Knew@N Rect2i(@L90@N, @L155@N, @L").Append(80 + size).Append("@N, @L128@N),\n center | @[email protected]_OVERFLOW_WRAP, myText);\n"); RB.CameraReset(); RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr)); }
public static void CopyToImage( this BitArray arr, Rect2i rect, int channel, Image4ub im ) { int i = 0; int x0 = rect.Origin.x; int y0 = rect.Origin.y; for( int y = 0; y < rect.Height; ++y ) { for( int x = 0; x < rect.Width; ++x ) { if( arr[ i ] ) { var color = im.GetPixelFlipped( x0 + x, y0 + y ); if( channel == 0 ) { color.x = 255; } else if( channel == 1 ) { color.y = 255; } else { color.z = 255; } im.SetPixelFlipped( x0 + x, y0 + y, color ); } ++i; } } }
/// <summary> /// Render /// </summary> public void Render() { Rect2i blobRect = new Rect2i(191, 0, 65, 65); RB.TintColorSet(mColorTint); RB.DrawCopy(blobRect, new Rect2i((int)mPos.x - (blobRect.width / 2), (int)mPos.y - (blobRect.height / 2), blobRect.width, blobRect.height)); RB.TintColorSet(Color.white); }
virtual public void Refresh() { RefreshChildren(); var oldbounds = Bounds; Rect2i newbounds = new Rect2i(oldbounds.X, oldbounds.Y, LayoutResult.MinSize.Width, LayoutResult.MinSize.Height); Bounds = newbounds; }
public GpuTextureFrame(ReadOnlySpan <byte> Data, Rect2i Size, EPixelFormat Format, float Duration = 0f) { this.Format = Format; this.Duration = Duration; #if ENABLE_HEADLESS == false this.Data = new ReadOnlyMemory <byte>(Data.ToArray()); #endif }
private void DrawTMX() { var demo = (DemoReel)RB.Game; int spriteFrame = (RB.Ticks % 40) > 20 ? 1 : 0; Rect2i clipRect = new Rect2i(0, 0, 0, 0); int cameraYOffset = 0; int cameraXOffset = 0; int cameraYRange = 16; if (mStyle == RB.PixelStyle.Wide) { clipRect = new Rect2i((RB.DisplaySize.width / 2) - 100, RB.DisplaySize.height - 220, 200, 200); } else if (mStyle == RB.PixelStyle.Tall) { clipRect = new Rect2i((RB.DisplaySize.width / 2) - 200, RB.DisplaySize.height - 110, 400, 100); cameraYOffset = 150; cameraXOffset = -120; cameraYRange = 8; } if (mMap != null) { int scrollPos = -(int)RB.Ticks % (mMapSize.width * RB.SpriteSize().width); Vector2i cameraPos = new Vector2i((int)((Mathf.Sin(RB.Ticks / 100.0f) * 420) + 450 + cameraXOffset), (int)((Mathf.Sin(RB.Ticks / 10.0f) * cameraYRange) + cameraYOffset)); RB.ClipSet(clipRect); RB.DrawRectFill(clipRect, DemoUtil.IndexToRGB(22)); RB.CameraSet(cameraPos); RB.DrawMapLayer(0, new Vector2i(scrollPos, 0)); RB.DrawMapLayer(0, new Vector2i(scrollPos + (mMapSize.width * RB.SpriteSize().width), 0)); RB.DrawMapLayer(1); RB.DrawMapLayer(2); RB.DrawSprite(0 + spriteFrame, new Vector2i(13 * 16, 16 * 16)); RB.DrawSprite(RB.SpriteIndex(6, 10) + spriteFrame, new Vector2i(67 * 16, 14 * 16)); RB.CameraReset(); } else { RB.Print(new Vector2i(clipRect.x + 2, clipRect.y + 2), DemoUtil.IndexToRGB(14), "Failed to load TMX map.\nPlease try re-importing the map\nDemos/DemoReel/Tilemap.tmx in Unity"); } RB.DrawRect(clipRect, DemoUtil.IndexToRGB(21)); RB.ClipReset(); mFormatStr.Set("@C// Use ").Append(mStyle == RB.PixelStyle.Wide ? "wide" : "tall").Append(" pixel format\n"); mFormatStr.Append("@Kpublic @MHardwareSettings @NQueryHardware() {\n"); mFormatStr.Append(" @Kvar @Nhw = @Knew @MHardwareSettings@N();\n"); mFormatStr.Append(" @Nhw.DisplaySize = @Knew @MVector2i@N(@L").Append(RB.DisplaySize.width).Append("@N, @L").Append(RB.DisplaySize.height).Append("@N);\n"); mFormatStr.Append(" @Nhw.PixelStyle = @KRetroBlit@N.@EPixelStyle@N.").Append(mStyle == RB.PixelStyle.Wide ? "Wide" : "Tall").Append(";\n"); mFormatStr.Append(" @Kreturn @Nhw;\n"); mFormatStr.Append("}"); RB.Print(new Vector2i(4, 4), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr)); }
public KeyboardKey(Rect2i rect, string label, KeyCode code1, KeyCode code2 = KeyCode.F15) { Rect = rect; Code1 = code1; // Using F15 as an undefined default key, if set then make code2 same as code1 Code2 = code2 == KeyCode.F15 ? code1 : code2; Label = label; }
private Rect2i RectBetweenKeys(string key1, string key2) { Rect2i keyboardRect = mKeys[key1].Rect; keyboardRect.width = (mKeys[key2].Rect.x + mKeys[key2].Rect.width) - mKeys[key1].Rect.x; keyboardRect.height = (mKeys[key2].Rect.y + mKeys[key2].Rect.height) - mKeys[key1].Rect.y; return(keyboardRect); }
/// <summary> /// Get a copy of the rect offset by given position. /// </summary> /// <remarks> /// Returns a copy of the rectangle offset by given position. Does not change the original rectangle. /// </remarks> /// <code> /// void Update() { /// var newPlayerRect = playerRect.Offset(playerPos - oldPlayerPos); /// } /// </code> /// <param name="pos">Position to offset by</param> /// <returns>An offset rect</returns> public Rect2i Offset(Vector2i pos) { Rect2i offsetRect = this; offsetRect.x += pos.x; offsetRect.y += pos.y; return(offsetRect); }
/// <summary> /// Interpolate a <see cref="Rect2i"/> value from the <paramref name="start"/> value to the <paramref name="end"/> value by time <paramref name="t"/> /// where at t = 0.0 the value is <paramref name="start"/> and at t = 1.0 the value is <paramref name="end"/> /// </summary> /// <param name="func">Easing function</param> /// <param name="start">Starting value</param> /// <param name="end">End value</param> /// <param name="t">Time from 0.0 to 1.0</param> /// <returns>Interpolated value</returns> public static Rect2i Interpolate(Func func, Rect2i start, Rect2i end, float t) { t = Value(func, t); return(new Rect2i( Clamp(Mathf.RoundToInt(start.x + ((end.x - start.x) * t)), int.MinValue, int.MaxValue), Clamp(Mathf.RoundToInt(start.y + ((end.y - start.y) * t)), int.MinValue, int.MaxValue), Clamp(Mathf.RoundToInt(start.width + ((end.width - start.width) * t)), int.MinValue, int.MaxValue), Clamp(Mathf.RoundToInt(start.height + ((end.height - start.height) * t)), int.MinValue, int.MaxValue))); }
public static void SavePNG( this BitArray arr, Rect2i rect, Vector2i imageSize, string filename ) { Image1ub im = new Image1ub( imageSize ); int i = 0; int x0 = rect.Origin.x; int y0 = rect.Origin.y; for( int y = 0; y < rect.Height; ++y ) { for( int x = 0; x < rect.Width; ++x ) { if( arr[ i ] ) { im.SetPixelFlipped( x0 + x, y0 + y, 255 ); } ++i; } } im.SavePNG( filename ); }
// BUGBUG: overly conservative: seems to have the same problem at acute angles as triangle offsets // BUGBUG: vertices must be specified in ccw order public static void Rasterize( float tileSize, BitArray mask, Rect2i maskRect, params Vector2f[] vertices ) { // set up edges Vector2f e0 = vertices[ 1 ] - vertices[ 0 ]; Vector2f e1 = vertices[ 2 ] - vertices[ 1 ]; Vector2f e2 = vertices[ 0 ] - vertices[ 2 ]; // get edge normals Vector2f n0 = e0.OrthogonalVector(); Vector2f n1 = e1.OrthogonalVector(); Vector2f n2 = e2.OrthogonalVector(); int i = 0; int x0 = maskRect.Origin.x; int y0 = maskRect.Origin.y; int sx = maskRect.Width; int sy = maskRect.Height; for( int y = 0; y < sy; ++y ) { for( int x = 0; x < sx; ++x ) { Vector2f p = new Vector2f( x0 + x + 0.5f, y0 + y + 0.5f ); float t0 = EdgeTest( tileSize, n0, vertices[ 0 ], p ); float t1 = EdgeTest( tileSize, n1, vertices[ 1 ], p ); float t2 = EdgeTest( tileSize, n2, vertices[ 2 ], p ); if( ( ( t0 > 0 ) && ( t1 > 0 ) && ( t2 > 0 ) ) || ( ( t0 < 0 ) && ( t1 < 0 ) && ( t2 < 0 ) ) ) { mask[ i ] = true; } else { mask[ i ] = false; } ++i; } } }
public void Union(Rect2i r) { Union(r.left, r.top, r.right, r.bottom); }
public static bool Intersects(Rect2i a, Rect2i b) { return a.left < b.right && b.left < a.right && a.top < b.bottom && b.top < a.bottom; }
public bool Contains(Rect2i r) { return this.left < this.right && this.top < this.bottom && left <= r.left && top <= r.top && right >= r.right && bottom >= r.bottom; }
public bool Intersect(Rect2i r) { return Intersect(r.left, r.top, r.right, r.bottom); }
// TODO: if it's not ub4 or float4 public void UpdateRectangle( Image4ub im, Rect2i source, Rect2i target ) { // TODO: check boundaries if( source.Width != target.Width || source.Height != target.Height ) { throw new ArgumentException( "Mismatched rectangle sizes." ); } var rect = Texture.Map( 0, MapMode.Write, MapFlags.None ); // find the byte array offsets and the count for the rectangles int sourceOffset = 4 * ( source.Origin.y * im.Width + source.Origin.x ); int sourceCount = 4 * source.Area; int targetOffset = 4 * ( target.Origin.y * im.Width + target.Origin.x ); rect.Data.Position = targetOffset; rect.Data.Write( im.Pixels, sourceOffset, sourceCount ); rect.Data.Close(); Texture.Unmap( 0 ); }
public bool SetIntersect(Rect2i a, Rect2i b) { if (a.left < b.right && b.left < a.right && a.top < b.bottom && b.top < a.bottom) { left = Math.Max(a.left,b.left); top = Math.Max(a.top,b.top); right = Math.Min(a.right,b.right); bottom = Math.Min(a.bottom,b.bottom); return true; } return false; }