void regenerateTiles() { clearTiles(); bool prevCreateMipMaps = driver.GetTextureCreationFlag(TextureCreationFlag.CreateMipMaps); driver.SetTextureCreationFlag(TextureCreationFlag.CreateMipMaps, false); bool prevAllowMemoryCopy = driver.GetTextureCreationFlag(TextureCreationFlag.AllowMemoryCopy); driver.SetTextureCreationFlag(TextureCreationFlag.AllowMemoryCopy, true); int y = 0; int x = 0; Dimension2Di d = new Dimension2Di(TileSize); while (y < screen.Height) { tiles.Add(new Tile(x, y, d, driver)); x += TileSize; if (x >= screen.Width) { x = 0; y += TileSize; } } driver.SetTextureCreationFlag(TextureCreationFlag.CreateMipMaps, prevCreateMipMaps); driver.SetTextureCreationFlag(TextureCreationFlag.AllowMemoryCopy, prevAllowMemoryCopy); // sort tiles: closest to center of the screen goes first int swh = screen.Width / 2; int shh = screen.Height / 2; bool b; do { b = false; for (int i = 0; i < tiles.Count - 1; i++) { int tx1 = tiles[i].ScreenPos.X + TileSize / 2; int ty1 = tiles[i].ScreenPos.Y + TileSize / 2; int td1 = Math.Abs(swh - tx1) + Math.Abs(shh - ty1); int tx2 = tiles[i + 1].ScreenPos.X + TileSize / 2; int ty2 = tiles[i + 1].ScreenPos.Y + TileSize / 2; int td2 = Math.Abs(swh - tx2) + Math.Abs(shh - ty2); if (td1 > td2) { Tile t = tiles[i]; tiles[i] = tiles[i + 1]; tiles[i + 1] = t; b = true; } } } while (b); }
private void irrThreadDrawText(Vector2Di p, string s) { Dimension2Di d = irrDevice.GUIEnvironment.BuiltInFont.GetDimension(s); d.Width += 8; d.Height += 6; irrDevice.VideoDriver.Draw2DRectangle(new Recti(p, d), new Color(0x7F000000)); irrDevice.GUIEnvironment.BuiltInFont.Draw(s, p + new Vector2Di(4, 3), new Color(250, 250, 250)); }
static void drawPreviewPlateTooltip() { if (hoveredNode == null || !hoveredNode.Visible) { return; } int k = hoveredNode.ID; Texture t = hoveredNode.GetMaterial(0).GetTexture(0); if (t != null && t.Name.Path != "NoPreviewTexture") { k = hoveredNode.ID & (0xFFFFFFF ^ SelectableNodeIdFlag); } string s = previewPlateInfo.ContainsKey(k) ? previewPlateInfo[k] : "???"; if (s != null) { Vector2Di p = irr.Device.CursorControl.Position + new Vector2Di(16); GUIFont f = irr.GUI.Skin.GetFont(GUIDefaultFont.Default); Dimension2Di d = f.GetDimension(s); d.Inflate(16, 12); Recti r = new Recti(p, d); VideoDriver v = irr.Driver; int ax = r.LowerRightCorner.X - v.ScreenSize.Width; int ay = r.LowerRightCorner.Y - v.ScreenSize.Height; if (ax > 0 || ay > 0) { if (ax < 0) { ax = 0; } if (ay < 0) { ay = 0; } r.Offset(-ax, -ay); } v.Draw2DRectangle(r, new Color(0xbb223355)); v.Draw2DRectangleOutline(r, new Color(0xbb445577)); f.Draw(s, r.UpperLeftCorner + new Vector2Di(8, 6), Color.SolidYellow); } }
static void textureManager_OnTextureLoaded(SceneNode node, Texture texture, Dimension2Di sourceDimension) { if (texture.Size == PreviewTextureSize || texture.Name.Path == "NoPreviewTexture") { float a = (float)sourceDimension.Height / sourceDimension.Width; animationManager.Remove(node); animationManager.Add(node, 400, new Vector3Df(node.Position.X, 0, node.Position.Z), null, new Vector3Df(1, 1, a)); if (texture.Name.Path != "NoPreviewTexture") { previewPlateInfo[node.ID] += "\n" + sourceDimension.ToString(); node.ID |= SelectableNodeIdFlag; } } }
protected override void OnResize(EventArgs e) { base.OnResize(e); if (!IsNotifyResizes) { return; } lock (backgroundCommand) { Dimension2Di newSize = new Dimension2Di(this.Width, this.Height); if (newSize.Area > 0) { backgroundCommand.SetCommand(Command.Kind.Resized, newSize); } } }
void thread_LoadTexture(SceneNode node, string path, Dimension2Di size) { Texture t; Dimension2Di si; Image i = irrDevice.DriverNoCheck.CreateImage(path); if (i != null) { Image j = irrDevice.DriverNoCheck.CreateImage(ColorFormat.A8R8G8B8, size); i.CopyToScaling(j); irrDevice.Lock(); t = irrDevice.Driver.AddTexture(path + "|" + size.ToString(), j); irrDevice.Unlock(); si = i.Dimension; i.Drop(); j.Drop(); lock (loadedTextures) { loadedTextures.Add(t.Name.Path); } } else { t = noPreviewTexture; si = noPreviewTexture.Size; } irrDevice.Lock(); node.SetMaterialTexture(0, t); irrDevice.Unlock(); if (OnTextureLoaded != null) { OnTextureLoaded(node, t, si); } node.Drop(); }
/// <summary> /// Initiates Irrlicht and prepares the scene for rendering /// </summary> /// <param name="renderTo">Control will display the model</param> public MD2Viewer(Control renderTo) { renderingTo = renderTo; Dimension2Di displayDimensions = new Dimension2Di(renderTo.ClientSize.Width, renderTo.ClientSize.Height); IrrlichtCreationParameters creationParams = new IrrlichtCreationParameters(); creationParams.BitsPerPixel = 16; creationParams.DoubleBuffer = false; creationParams.DriverType = DriverType.Software; creationParams.WindowSize = new Dimension2Di(renderingTo.Width, renderingTo.Height); creationParams.WindowID = renderingTo.Handle; creationParams.Fullscreen = false; irrlichtDevice = IrrlichtDevice.CreateDevice(creationParams); ClearScene(); backgroundColour = new Color(150, 150, 150, 0); }
public void LoadTexture(SceneNode node, string path, Dimension2Di size, bool topPriority = false) { node.Grab(); addThreadCommand(ThreadCommandType.LoadTexture, topPriority, node, path, size); }
private void irrThreadProcessCommandQueue() { Command c; lock (commandQueue) { if (commandQueue.Count == 0) return; c = commandQueue.Dequeue(); } switch (c.Type) { case CommandType.Abort: { irrDevice.Close(); break; } case CommandType.Axes: { irrThreadShowAxes((bool)c.Param); break; } case CommandType.Plane: { var n = irrDevice.SceneManager.GetSceneNodeFromID((int)SceneNodeID.Plane); n.Visible = (bool)c.Param; break; } case CommandType.Particle: { var n = irrDevice.SceneManager.GetSceneNodeFromID((int)SceneNodeID.ParticleSystem); n.SetMaterialTexture(0, irrDevice.VideoDriver.GetTexture(((ParticleInfo)c.Param).FileName)); break; } case CommandType.Resize: { int[] i = (int[])c.Param; Dimension2Di d = new Dimension2Di(i[0], i[1]); irrDevice.VideoDriver.ResizeNotify(d); (irrDevice.SceneManager.GetSceneNodeFromID((int)SceneNodeID.Camera) as CameraSceneNode).AspectRatio = i[2] == 1 ? (float)i[0] / i[1] : 1.333333f; break; } case CommandType.Position: { float[] f = (float[])c.Param; var p = irrDevice.SceneManager.GetSceneNodeFromID((int)SceneNodeID.ParticleSystem) as ParticleSystemSceneNode; (p.Emitter as ParticleSphereEmitter).Center = new Vector3Df(f[0], f[1], f[2]); break; } case CommandType.Radius: { float f = (float)c.Param; var p = irrDevice.SceneManager.GetSceneNodeFromID((int)SceneNodeID.ParticleSystem) as ParticleSystemSceneNode; (p.Emitter as ParticleSphereEmitter).Radius = f; break; } case CommandType.CameraView: { float f = (float)c.Param; var p = irrDevice.SceneManager.GetSceneNodeFromID((int)SceneNodeID.Camera) as CameraSceneNode; p.Target = new Vector3Df(p.Target.X, f, p.Target.Z); break; } case CommandType.Rate: { int v = (int)c.Param; var p = irrDevice.SceneManager.GetSceneNodeFromID((int)SceneNodeID.ParticleSystem) as ParticleSystemSceneNode; p.Emitter.MaxParticlesPerSecond = v; p.Emitter.MinParticlesPerSecond = v/2; break; } case CommandType.Size: { int v = (int)c.Param; var p = irrDevice.SceneManager.GetSceneNodeFromID((int)SceneNodeID.ParticleSystem) as ParticleSystemSceneNode; p.Emitter.MaxStartSize = new Dimension2Df(v); p.Emitter.MinStartSize = new Dimension2Df(v/2); break; } case CommandType.Direction: { float[] f = (float[])c.Param; var p = irrDevice.SceneManager.GetSceneNodeFromID((int)SceneNodeID.ParticleSystem) as ParticleSystemSceneNode; p.Emitter.Direction = new Vector3Df(f[0], f[1], f[2]); break; } case CommandType.FadeOut: { affFadeOut.Enabled = (bool)c.Param; break; } case CommandType.Rotation: { affRotation.Enabled = (bool)c.Param; break; } case CommandType.Gravity: { affGravity.Enabled = (bool)c.Param; break; } default: throw new InvalidOperationException("Unexpected command type: " + c.Type.ToString()); } }
public Tile(int screenX, int screenY, Dimension2Di screenDimension, VideoDriver driver) { ScreenPos = new Vector2Di(screenX, screenY); Texture = driver.AddTexture(screenDimension, string.Format("TileTexture({0},{1})", screenX, screenY)); TexturePainter = Texture.Painter; }
public void LoadTexture(SceneNode node, string path, Dimension2Di size, bool topPriority = false) { node.Grab(); addThreadCommand(ThreadCommandType.LoadTexture, topPriority, node, path, size); }
public Tile(int screenX, int screenY, Dimension2Di screenDimension, VideoDriver driver) { ScreenPos = new Vector2Di(screenX, screenY); Texture = driver.AddTexture(screenDimension, string.Format("TileTexture({0},{1})", screenX, screenY)); TexturePainter = Texture.Painter; }
public void CreateDevice(DriverType driverType, Dimension2Di windowSize) { device = IrrlichtDevice.CreateDevice(driverType, windowSize); }
public void CreateDevice(DriverType driverType, Dimension2Di windowSize) { device = IrrlichtDevice.CreateDevice(driverType, windowSize); }
static bool Device_OnEvent(Event evnt) { if (evnt.Type == EventType.GUI && evnt.GUI.Type == GUIEventType.ButtonClicked && evnt.GUI.Caller.ID == ChooseFolderButtonId) { wantChangeFolder = true; return true; } if (evnt.Type == EventType.Mouse && evnt.Mouse.Type == MouseEventType.Wheel && selectedNode == null) { Vector3Df p = irr.Scene.ActiveCamera.Position; Vector3Df t = irr.Scene.ActiveCamera.Target; float s = irr.Scene.ActiveCamera.Position.Z + evnt.Mouse.Wheel * 16; if (s < 0) s = 0; if (s > maxScrollPosition) s = maxScrollPosition; t.Z = t.Z - p.Z + s; p.Z = s; irr.Scene.ActiveCamera.Position = p; irr.Scene.ActiveCamera.Target = t; return true; } if (evnt.Type == EventType.Mouse && evnt.Mouse.Type == MouseEventType.Move && selectedNode == null) { SceneNode n = irr.Scene.SceneCollisionManager.GetSceneNodeFromScreenCoordinatesBB( new Vector2Di(evnt.Mouse.X, evnt.Mouse.Y), 0, irr.Scene.GetSceneNodeFromID(PreviewRootNodeId)); if (hoveredNode != n) { if (hoveredNode != null) { animationManager.Remove(hoveredNode); animationManager.Add( hoveredNode, 500, new Vector3Df(hoveredNode.Position.X, hoveredNode.Position.Y - 15, hoveredNode.Position.Z), new Vector3Df(0), hoveredNode.Scale / 1.5f); } if (n != null) { animationManager.Remove(n); animationManager.Add( n, 40, new Vector3Df(n.Position.X, n.Position.Y + 15, n.Position.Z), new Vector3Df(-20, 0, 0), n.Scale * 1.5f); } hoveredNode = n; } return true; } if (evnt.Type == EventType.Mouse && evnt.Mouse.Type == MouseEventType.LeftUp && hoveredNode != null && (hoveredNode.ID & SelectableNodeIdFlag) == SelectableNodeIdFlag && selectedNode == null) { animationManager.Remove(hoveredNode); Mesh m = irr.Scene.MeshCache.GetMesh(PreviewPlateMeshName); MeshSceneNode n = irr.Scene.AddMeshSceneNode(m); n.SetMaterialFlag(MaterialFlag.Lighting, false); n.Position = hoveredNode.Position; n.Rotation = hoveredNode.Rotation; n.Scale = hoveredNode.Scale; string t = hoveredNode.GetMaterial(0).GetTexture(0).Name.Path.Split('|')[0]; Dimension2Di d = new Dimension2Di(2048); if (d.Area > irr.Driver.MaxTextureSize.Area) d = irr.Driver.MaxTextureSize; n.SetMaterialTexture(0, hoveredNode.GetMaterial(0).GetTexture(0)); textureManager.LoadTexture(n, t, d, true); animationManager.Add( n, 200, irr.Scene.ActiveCamera.AbsolutePosition + new Vector3Df(0, -48, 40), // TODO: this magic numbers should be calculated somehow new Vector3Df(-39.85f, 0, 0), // using current active camera info (like view matrix or projection one) n.Scale * ((irr.Scene.ActiveCamera.FOV - 0.125f) / n.Scale.Z)); selectedNode = n; hoveredNode.Visible = false; irr.GUI.RootElement.GetElementFromID(ChooseFolderButtonId).Enabled = false; return true; } if (evnt.Type == EventType.Mouse && evnt.Mouse.Type == MouseEventType.LeftUp && selectedNode != null && selectedNode.GetMaterial(0).GetTexture(0) != hoveredNode.GetMaterial(0).GetTexture(0)) { if (animationManager.IsAnimated(selectedNode)) return true; Texture t = selectedNode.GetMaterial(0).GetTexture(0); if (t != null) { string s = t.Name.Path; selectedNode.SetMaterialTexture(0, null); textureManager.UnloadTexture(s); } selectedNode.Remove(); selectedNode = null; hoveredNode.Visible = true; irr.GUI.RootElement.GetElementFromID(ChooseFolderButtonId).Enabled = true; return true; } if (evnt.Type == EventType.Log && evnt.Log.Text.StartsWith("Resizing window")) { wantUpdateActiveCameraAspectRatio = true; } return false; }
static void textureManager_OnTextureLoaded(SceneNode node, Texture texture, Dimension2Di sourceDimension) { if (texture.Size == PreviewTextureSize || texture.Name.Path == "NoPreviewTexture") { float a = (float)sourceDimension.Height / sourceDimension.Width; animationManager.Remove(node); animationManager.Add(node, 400, new Vector3Df(node.Position.X, 0, node.Position.Z), null, new Vector3Df(1, 1, a)); if (texture.Name.Path != "NoPreviewTexture") { previewPlateInfo[node.ID] += "\n" + sourceDimension.ToString(); node.ID |= SelectableNodeIdFlag; } } }
protected override void OnResize(EventArgs e) { base.OnResize(e); if (!IsNotifyResizes) return; lock (backgroundCommand) { Dimension2Di newSize = new Dimension2Di(this.Width, this.Height); if (newSize.Area > 0) backgroundCommand.SetCommand(Command.Kind.Resized, newSize); } }
private void irrThreadProcessCommandQueue() { Command c; lock (commandQueue) { if (commandQueue.Count == 0) { return; } c = commandQueue.Dequeue(); } switch (c.Type) { case CommandType.Abort: { irrDevice.Close(); break; } case CommandType.Axes: { irrThreadShowAxes((bool)c.Param); break; } case CommandType.Plane: { var n = irrDevice.SceneManager.GetSceneNodeFromID((int)SceneNodeID.Plane); n.Visible = (bool)c.Param; break; } case CommandType.Particle: { var n = irrDevice.SceneManager.GetSceneNodeFromID((int)SceneNodeID.ParticleSystem); n.SetMaterialTexture(0, irrDevice.VideoDriver.GetTexture(((ParticleInfo)c.Param).FileName)); break; } case CommandType.Resize: { int[] i = (int[])c.Param; Dimension2Di d = new Dimension2Di(i[0], i[1]); irrDevice.VideoDriver.ResizeNotify(d); (irrDevice.SceneManager.GetSceneNodeFromID((int)SceneNodeID.Camera) as CameraSceneNode).AspectRatio = i[2] == 1 ? (float)i[0] / i[1] : 1.333333f; break; } case CommandType.Position: { float[] f = (float[])c.Param; var p = irrDevice.SceneManager.GetSceneNodeFromID((int)SceneNodeID.ParticleSystem) as ParticleSystemSceneNode; (p.Emitter as ParticleSphereEmitter).Center = new Vector3Df(f[0], f[1], f[2]); break; } case CommandType.Radius: { float f = (float)c.Param; var p = irrDevice.SceneManager.GetSceneNodeFromID((int)SceneNodeID.ParticleSystem) as ParticleSystemSceneNode; (p.Emitter as ParticleSphereEmitter).Radius = f; break; } case CommandType.CameraView: { float f = (float)c.Param; var p = irrDevice.SceneManager.GetSceneNodeFromID((int)SceneNodeID.Camera) as CameraSceneNode; p.Target = new Vector3Df(p.Target.X, f, p.Target.Z); break; } case CommandType.Rate: { int v = (int)c.Param; var p = irrDevice.SceneManager.GetSceneNodeFromID((int)SceneNodeID.ParticleSystem) as ParticleSystemSceneNode; p.Emitter.MaxParticlesPerSecond = v; p.Emitter.MinParticlesPerSecond = v / 2; break; } case CommandType.Size: { int v = (int)c.Param; var p = irrDevice.SceneManager.GetSceneNodeFromID((int)SceneNodeID.ParticleSystem) as ParticleSystemSceneNode; p.Emitter.MaxStartSize = new Dimension2Df(v); p.Emitter.MinStartSize = new Dimension2Df(v / 2); break; } case CommandType.Direction: { float[] f = (float[])c.Param; var p = irrDevice.SceneManager.GetSceneNodeFromID((int)SceneNodeID.ParticleSystem) as ParticleSystemSceneNode; p.Emitter.Direction = new Vector3Df(f[0], f[1], f[2]); break; } case CommandType.FadeOut: { affFadeOut.Enabled = (bool)c.Param; break; } case CommandType.Rotation: { affRotation.Enabled = (bool)c.Param; break; } case CommandType.Gravity: { affGravity.Enabled = (bool)c.Param; break; } default: throw new InvalidOperationException("Unexpected command type: " + c.Type.ToString()); } }
static bool Device_OnEvent(Event evnt) { if (evnt.Type == EventType.GUI && evnt.GUI.Type == GUIEventType.ButtonClicked && evnt.GUI.Caller.ID == ChooseFolderButtonId) { wantChangeFolder = true; return(true); } if (evnt.Type == EventType.Mouse && evnt.Mouse.Type == MouseEventType.Wheel && selectedNode == null) { Vector3Df p = irr.Scene.ActiveCamera.Position; Vector3Df t = irr.Scene.ActiveCamera.Target; float s = irr.Scene.ActiveCamera.Position.Z + evnt.Mouse.Wheel * 16; if (s < 0) { s = 0; } if (s > maxScrollPosition) { s = maxScrollPosition; } t.Z = t.Z - p.Z + s; p.Z = s; irr.Scene.ActiveCamera.Position = p; irr.Scene.ActiveCamera.Target = t; return(true); } if (evnt.Type == EventType.Mouse && evnt.Mouse.Type == MouseEventType.Move && selectedNode == null) { SceneNode n = irr.Scene.SceneCollisionManager.GetSceneNodeFromScreenCoordinatesBB( new Vector2Di(evnt.Mouse.X, evnt.Mouse.Y), 0, irr.Scene.GetSceneNodeFromID(PreviewRootNodeId)); if (hoveredNode != n) { if (hoveredNode != null) { animationManager.Remove(hoveredNode); animationManager.Add( hoveredNode, 500, new Vector3Df(hoveredNode.Position.X, hoveredNode.Position.Y - 15, hoveredNode.Position.Z), new Vector3Df(0), hoveredNode.Scale / 1.5f); } if (n != null) { animationManager.Remove(n); animationManager.Add( n, 40, new Vector3Df(n.Position.X, n.Position.Y + 15, n.Position.Z), new Vector3Df(-20, 0, 0), n.Scale * 1.5f); } hoveredNode = n; } return(true); } if (evnt.Type == EventType.Mouse && evnt.Mouse.Type == MouseEventType.LeftUp && hoveredNode != null && (hoveredNode.ID & SelectableNodeIdFlag) == SelectableNodeIdFlag && selectedNode == null) { animationManager.Remove(hoveredNode); Mesh m = irr.Scene.MeshCache.GetMesh(PreviewPlateMeshName); MeshSceneNode n = irr.Scene.AddMeshSceneNode(m); n.SetMaterialFlag(MaterialFlag.Lighting, false); n.Position = hoveredNode.Position; n.Rotation = hoveredNode.Rotation; n.Scale = hoveredNode.Scale; string t = hoveredNode.GetMaterial(0).GetTexture(0).Name.Path.Split('|')[0]; Dimension2Di d = new Dimension2Di(2048); if (d.Area > irr.Driver.MaxTextureSize.Area) { d = irr.Driver.MaxTextureSize; } n.SetMaterialTexture(0, hoveredNode.GetMaterial(0).GetTexture(0)); textureManager.LoadTexture(n, t, d, true); animationManager.Add( n, 200, irr.Scene.ActiveCamera.AbsolutePosition + new Vector3Df(0, -48, 40), // TODO: this magic numbers should be calculated somehow new Vector3Df(-39.85f, 0, 0), // using current active camera info (like view matrix or projection one) n.Scale * ((irr.Scene.ActiveCamera.FOV - 0.125f) / n.Scale.Z)); selectedNode = n; hoveredNode.Visible = false; irr.GUI.RootElement.GetElementFromID(ChooseFolderButtonId).Enabled = false; return(true); } if (evnt.Type == EventType.Mouse && evnt.Mouse.Type == MouseEventType.LeftUp && selectedNode != null && selectedNode.GetMaterial(0).GetTexture(0) != hoveredNode.GetMaterial(0).GetTexture(0)) { if (animationManager.IsAnimated(selectedNode)) { return(true); } Texture t = selectedNode.GetMaterial(0).GetTexture(0); if (t != null) { string s = t.Name.Path; selectedNode.SetMaterialTexture(0, null); textureManager.UnloadTexture(s); } selectedNode.Remove(); selectedNode = null; hoveredNode.Visible = true; irr.GUI.RootElement.GetElementFromID(ChooseFolderButtonId).Enabled = true; return(true); } if (evnt.Type == EventType.Log && evnt.Log.Text.StartsWith("Resizing window")) { wantUpdateActiveCameraAspectRatio = true; } return(false); }
void thread_LoadTexture(SceneNode node, string path, Dimension2Di size) { Texture t; Dimension2Di si; Image i = irrDevice.DriverNoCheck.CreateImage(path); if (i != null) { Image j = irrDevice.DriverNoCheck.CreateImage(ColorFormat.A8R8G8B8, size); i.CopyToScaling(j); irrDevice.Lock(); t = irrDevice.Driver.AddTexture(path + "|" + size.ToString(), j); irrDevice.Unlock(); si = i.Dimension; i.Drop(); j.Drop(); lock (loadedTextures) { loadedTextures.Add(t.Name.Path); } } else { t = noPreviewTexture; si = noPreviewTexture.Size; } irrDevice.Lock(); node.SetMaterialTexture(0, t); irrDevice.Unlock(); if (OnTextureLoaded != null) OnTextureLoaded(node, t, si); node.Drop(); }
static bool device_OnEvent(Event evnt) { if (evnt.Type == EventType.Mouse) { Dimension2Di s = device.VideoDriver.ScreenSize; if (evnt.Mouse.Type == MouseEventType.Wheel) { Rectd r = new Rectd(); if (evnt.Mouse.Wheel > 0) { // zoom in int x1 = evnt.Mouse.X - s.Width / 2 + (int)evnt.Mouse.Wheel * s.Width / 10; int y1 = evnt.Mouse.Y - s.Height / 2 + (int)evnt.Mouse.Wheel * s.Height / 10; r.UpperLeftCorner = fGen.GetWindowCoord(x1, y1); r.LowerRightCorner = fGen.GetWindowCoord(2 * evnt.Mouse.X - x1, 2 * evnt.Mouse.Y - y1); device.CursorControl.Position = new Vector2Di(s.Width / 2, s.Height / 2); } else { // zoom out int x1 = s.Width / 10; int y1 = s.Height / 10; r.UpperLeftCorner = fGen.GetWindowCoord(-x1, -y1); r.LowerRightCorner = fGen.GetWindowCoord(s.Width + x1, s.Height + y1); } fGen.Generate(r); return(true); } if (evnt.Mouse.Type == MouseEventType.LeftDown) { mouseMoveStart = new Vector2Di(evnt.Mouse.X, evnt.Mouse.Y); return(true); } if (evnt.Mouse.Type == MouseEventType.LeftUp) { Vector2Dd p1 = fGen.GetWindowCoord(evnt.Mouse.X, evnt.Mouse.Y); Vector2Dd p2 = fGen.GetWindowCoord(mouseMoveStart.X, mouseMoveStart.Y); Rectd r = fGen.GetWindow() + p2 - p1; fGen.Generate(r); mouseMoveStart = null; return(true); } } if (evnt.Type == EventType.Key) { if (evnt.Key.PressedDown) { if (evnt.Key.Key == KeyCode.Esc) { device.Close(); return(true); } if (evnt.Key.Key == KeyCode.F1) { showHelp = !showHelp; return(true); } switch (evnt.Key.Char) { case '+': fGen.Generate(fGen.GetMaxIterations() + 1); return(true); case '-': fGen.Generate(fGen.GetMaxIterations() - 1); return(true); case '*': fGen.Generate(fGen.GetMaxIterations() + 10); return(true); case '/': fGen.Generate(fGen.GetMaxIterations() - 10); return(true); } } if (evnt.Key.Key == KeyCode.PrintScreen) // PrintScreen never comes with "evnt.Key.PressedDown == true" so we process it without checking that { string n = "Screenshot-" + DateTime.Now.Ticks + ".png"; Image i = device.VideoDriver.CreateScreenShot(); device.VideoDriver.WriteImage(i, n); i.Drop(); device.Logger.Log("Screenshot saved as " + n); return(true); } } return(false); }
void regenerateTiles() { clearTiles(); bool o = driver.GetTextureCreationFlag(TextureCreationFlag.CreateMipMaps); driver.SetTextureCreationFlag(TextureCreationFlag.CreateMipMaps, false); int y = 0; int x = 0; Dimension2Di d = new Dimension2Di(TileSize); while (y < screen.Height) { tiles.Add(new Tile(x, y, d, driver)); x += TileSize; if (x >= screen.Width) { x = 0; y += TileSize; } } driver.SetTextureCreationFlag(TextureCreationFlag.CreateMipMaps, o); // sort tiles: closest to center of the screen goes first int swh = screen.Width / 2; int shh = screen.Height / 2; bool b; do { b = false; for (int i = 0; i < tiles.Count - 1; i++) { int tx1 = tiles[i].ScreenPos.X + TileSize / 2; int ty1 = tiles[i].ScreenPos.Y + TileSize / 2; int td1 = Math.Abs(swh - tx1) + Math.Abs(shh - ty1); int tx2 = tiles[i + 1].ScreenPos.X + TileSize / 2; int ty2 = tiles[i + 1].ScreenPos.Y + TileSize / 2; int td2 = Math.Abs(swh - tx2) + Math.Abs(shh - ty2); if (td1 > td2) { Tile t = tiles[i]; tiles[i] = tiles[i + 1]; tiles[i + 1] = t; b = true; } } } while (b); }