void DrawGifValue(IGifValue value, Vector2 pos, Vector2 size) { if (value is GifCursor) { GifCursor cursor = (GifCursor)value; DrawCell(cursor.cube, cursor.position.R16, cursor.position.G16, cursor.position.B16, pos, size); } else { DrawColorBlock(value.Read(), pos, size); } }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected void Draw() { if (!needsRedraw) { return; } needsRedraw = false; context = canvas.GetContext(CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D); context.Font = "9px arial"; DrawRectangle(new Rectangle(0, 0, 1024, 720), new Color(94, 54, 54)); DrawCube(showingCube, showingPosition.B16, showingPosition, new Vector2(30, 30), blockSize); DrawString("Current color: ", new Vector2(850, 20), Color.Black); IGifValue currentValue = gifScriptState.current; DrawGifValue(currentValue, new Vector2(850, 40), blockSize); DrawString("Registers: ", new Vector2(850, 100), Color.Black); DrawString("Name", new Vector2(850, 120), Color.Black); DrawString("Pos", new Vector2(900, 120), Color.Black); DrawString("Value", new Vector2(950, 120), Color.Black); Vector2 registerDrawPos = registersScreenPos; foreach (ColorRGB register in interestingRegisters) { DrawColorBlock(register, registerDrawPos, blockSize); ColorRGB registerPos = gifScriptState.GetRegisterPosition(register); DrawColorBlock(registerPos, new Vector2(registerDrawPos.X + blockSize.X + 1, registerDrawPos.Y), blockSize); DrawCell(gifScriptState.GetRegisterTarget(register), registerPos.R16, registerPos.G16, registerPos.B16, new Vector2(registerDrawPos.X + blockSize.X * 2 + 2, registerDrawPos.Y), blockSize); if (gifScriptState.runningRegister == register) { DrawImage(runningTexture, new Vector2(registerDrawPos.X + 17, registerDrawPos.Y + 18)); } registerDrawPos.Y += registersScreenSpacing; } Global.RequestAnimationFrame(e => Draw()); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(new Color(94, 54, 54)); // TODO: Add your drawing code here spriteBatch.Begin(); DrawCube(showingCube, showingPosition.B16, showingPosition, new Vector2(30, 30), blockSize); spriteBatch.DrawString(font, "Current color: ", new Vector2(850, 20), Color.Black); IGifValue currentValue = gifScriptState.current; DrawGifValue(currentValue, new Vector2(850, 40), blockSize); spriteBatch.DrawString(font, "Registers: ", new Vector2(850, 100), Color.Black); spriteBatch.DrawString(font, "Name", new Vector2(850, 120), Color.Black); spriteBatch.DrawString(font, "Pos", new Vector2(900, 120), Color.Black); spriteBatch.DrawString(font, "Value", new Vector2(950, 120), Color.Black); Vector2 registerDrawPos = registersScreenPos; foreach (ColorRGB register in interestingRegisters) { DrawColorBlock(register, registerDrawPos, blockSize); ColorRGB registerPos = gifScriptState.GetRegisterPosition(register); DrawColorBlock(registerPos, new Vector2(registerDrawPos.X + blockSize.X + 1, registerDrawPos.Y), blockSize); DrawCell(gifScriptState.GetRegisterTarget(register), registerPos.R16, registerPos.G16, registerPos.B16, new Vector2(registerDrawPos.X + blockSize.X * 2 + 2, registerDrawPos.Y), blockSize); if (gifScriptState.runningRegister == register) { spriteBatch.Draw(runningTexture, new Vector2(registerDrawPos.X + 17, registerDrawPos.Y + 18), Color.White); } registerDrawPos.Y += registersScreenSpacing; } ui.Draw(spriteBatch); // spriteBatch.Draw(whiteTexture, new Rectangle(100, 100, 100, 100), Color.Red); spriteBatch.End(); base.Draw(gameTime); }
void DoReturn(IGifValue returnValue) { if (stack.Count == 0) { halted = true; return; } else { GifStackFrame returnFrame = stack.Pop(); runningRegister = returnFrame.runningRegister; switch (returnFrame.RHSInstruction) { case 0xCCC: // Assign bool failure; returnValue.Write(returnFrame.LHSValue.Read(), out failure); if (failure) { DoReturn(returnValue); } break; case 0xC8C: // Call stack.Push(new GifStackFrame(returnFrame.runningRegister)); current = returnFrame.LHSValue; runningRegister = returnValue.Read(); break; case 0xCC4: // Retarget ColorRGB lhsColor = returnFrame.LHSValue.Read(); ColorRGB rhsColor = returnValue.Read(); registerTargets[rhsColor.R16, rhsColor.G16, rhsColor.B16] = registerTargets[lhsColor.R16, lhsColor.G16, lhsColor.B16]; current = new GifCursor(rhsColor, GetRegisterPosition(rhsColor), GetRegisterTarget(rhsColor)); break; default: break; } } }
public GifStackFrame(IGifValue LHSValue, int RHSInstruction, ColorRGB runningRegister) { this.LHSValue = LHSValue.Copy(); this.RHSInstruction = RHSInstruction; this.runningRegister = runningRegister; }