private MiEntity CreatePointer() { RenderWindow window = Manager.Game.Window; MiEntity ptr = new MiEntity("Pointer", window); if (!ptr.AddNewComponent <Sprite>()) { return(Logger.LogReturn <MiEntity>("Failed creating pointer components.", null, LogType.Error)); } Sprite spr = ptr.GetComponent <Sprite>(); spr.Image.Path = Program.Theme.PointerPath; spr.Image.Color = Program.Theme.Color; spr.Image.FlipHorizontal = Program.PointerDirection == Direction.Right; View view = window.GetView(); Vector2f topleft = view.Center - (view.Size / 2.0f); Transform t = ptr.GetComponent <Transform>(); t.Size = new Vector2f(spr.Image.Texture.Size.X * Program.Theme.PointerScale.X, spr.Image.Texture.Size.Y * Program.Theme.PointerScale.Y); switch (Program.PointerDirection) { case Direction.Left: t.Position = topleft + new Vector2f(0, (view.Size.Y / 2.0f) - (t.Size.Y / 2.0f)); break; case Direction.Right: t.Position = topleft + new Vector2f(view.Size.X - t.Size.X, (view.Size.Y / 2.0f) - (t.Size.Y / 2.0f)); break; } return(ptr); }
private MiEntity CreateIcon(string file, uint index) { Theme theme = Program.Theme; Settings settings = Program.FolderSettings; Vector2u cellbord = Program.GetIconBorder(); Vector2u cellsize; { uint csize = Program.GetCellSize(); cellsize.X = csize; cellsize.Y = settings.DisplayType == IconDisplayType.IconOnly ? csize : (uint)((float)(csize / 3.0f) * 4); } MiEntity icongroup = new MiEntity("IconGroup" + index.ToString(), Manager.Game.Window), icon = new MiEntity("Icon", Manager.Game.Window), label = new MiEntity("Label", Manager.Game.Window); label.Visible = settings.DisplayType == IconDisplayType.Default; if (!icongroup.AddChild(icon) || !icongroup.AddChild(label)) { return(Logger.LogReturn <MiEntity>("Failed assembling icon group.", null, LogType.Error)); } string filename = Path.GetFileName(file); if (!icongroup.AddNewComponent <Transform>()) { return(Logger.LogReturn <MiEntity>("Failed creating icon group components.", null, LogType.Error)); } Transform igtran = icongroup.GetComponent <Transform>(); igtran.Size = new Vector2f(cellsize.X, cellsize.Y); switch (Program.PointerDirection) { case Direction.Left: igtran.Position = new Vector2f(theme.PointerSize.X + (cellsize.X / 2.0f), cellsize.Y / 2.0f); break; case Direction.Right: igtran.Position = new Vector2f(cellsize.X / 2.0f, cellsize.Y / 2.0f); break; } igtran.SetOrigin(Allignment.Middle); uint x = index % settings.GridCells.X, y = index / settings.GridCells.X; igtran.Position += new Vector2f((x * cellsize.X) + (cellsize.X / 2), (y * cellsize.Y) + (cellsize.Y / 2)) + new Vector2f(0, Manager.Game.Window.Size.Y); if (!icon.AddNewComponent <Sprite>() || !icon.AddNewComponent <Clickable>()) { return(Logger.LogReturn <MiEntity>("Failed creating icon components.", null, LogType.Error)); } Clickable click = icon.GetComponent <Clickable>(); void OnClick(object sender, EventArgs e) { try { RenderWindow window = Manager.Game.Window; Vector2i pos = Mouse.GetPosition(window); if (pos.X < 0 || pos.X > window.Size.X || pos.Y < 0 || pos.Y > window.Size.Y) { return; } if (file != null && File.Exists(file)) { Process proc = Process.Start(file); Manager.Game.Window.SetVisible(false); proc.WaitForExit(); Manager.Game.Exit(); } } catch (Exception ex) { Logger.Log("Unable to open file \"" + file + "\": " + ex.Message, LogType.Error); } } click.Click += OnClick; Transform itran = icon.GetComponent <Transform>(); itran.Size = new Vector2f(settings.IconSize, settings.IconSize); itran.Origin = Allignment.Middle; itran.Position = igtran.Position; if (settings.DisplayType == IconDisplayType.Default) { itran.Position -= new Vector2f(0, igtran.Size.Y / 8.0f); } Texture tex = IconManager.Manager.Get(Path.Combine(FolderPaths.Executable, file)); if (tex != null) { icon.GetComponent <Sprite>().Image.OverrideTexture = IconManager.Manager.Get(Path.Combine(FolderPaths.Executable, file)); } else { icon.GetComponent <Sprite>().Image.Path = theme.DefaultIconPath; } string displaystring = settings.ShowFileExtention ? filename : Path.GetFileNameWithoutExtension(file); if (!label.AddComponent(new Label(theme.TextStyle, displaystring, Allignment.Middle))) { return(Logger.LogReturn <MiEntity>("Failed creating label components.", null, LogType.Error)); } Label lab = label.GetComponent <Label>(); lab.Refresh(); while (lab.String.Length > 0 && lab.GetTextBounds().Width >= igtran.ScaledSize.X - 4) { lab.String = lab.String.Substring(0, lab.String.Length - 1); lab.Refresh(); } Transform ltran = label.GetComponent <Transform>(); ltran.Size = new Vector2f(settings.IconSize, 24); ltran.Origin = Allignment.Middle; ltran.Position = igtran.Position + new Vector2f(0.0f, igtran.Size.Y / 4.0f); return(icongroup); }
private MiEntity CreateBackground() { RenderWindow window = Manager.Game.Window; MiEntity bg = new MiEntity("Background", window); if (!bg.AddNewComponent <SpriteArray>()) { return(Logger.LogReturn <MiEntity>("Failed creating background components.", null, LogType.Error)); } View view = window.GetView(); Texture ptr = Program.Theme.PointerTexture; Transform trn = bg.GetComponent <Transform>(); trn.Size = new Vector2f(view.Size.X - ((ptr?.Size.X ?? 0) * Program.Theme.PointerScale.X), view.Size.Y); switch (Program.PointerDirection) { case Direction.Left: trn.Position = new Vector2f((ptr?.Size.X ?? 0) * Program.Theme.PointerScale.X, 0.0f); break; case Direction.Right: trn.Position = new Vector2f(0.0f, 0.0f); break; } SpriteArray spr = bg.GetComponent <SpriteArray>(); spr.TexturePath = Program.Theme.BackgroundPath; Vector2u texsize = spr.Texture.Size; float third = texsize.X / 3.0f; FloatRect tl = new FloatRect(0, 0, third, third), t = new FloatRect(third, 0, third, third), tr = new FloatRect(third * 2, 0, third, third), l = new FloatRect(0, third, third, third), m = new FloatRect(third, third, third, third), r = new FloatRect(third * 2, third, third, third), bl = new FloatRect(0, third * 2, third, third), b = new FloatRect(third, third * 2, third, third), br = new FloatRect(third * 2, third * 2, third, third); Settings settings = Program.FolderSettings; Vector2u cellsize; { uint csize = Program.GetCellSize(); cellsize.X = csize; cellsize.Y = settings.DisplayType == IconDisplayType.IconOnly ? csize : (uint)((float)(csize / 3.0f) * 4); } Vector2u cellcount = settings.DisplayType == IconDisplayType.IconOnly ? settings.GridCells * 3 : new Vector2u(settings.GridCells.X * 3, settings.GridCells.Y * 4); Vector2f sprsize = new Vector2f(cellsize.X / 3.0f, cellsize.X / 3.0f); for (int y = 0; y < cellcount.Y; y++) { for (int x = 0; x < cellcount.X; x++) { FloatRect rect; if (x == 0) { if (y == 0) { rect = tl; } else if (y == (cellcount.Y - 1)) { rect = bl; } else { rect = l; } } else if (x == cellcount.X - 1) { if (y == 0) { rect = tr; } else if (y == (cellcount.Y - 1)) { rect = br; } else { rect = r; } } else { if (y == 0) { rect = t; } else if (y == (cellcount.Y - 1)) { rect = b; } else { rect = m; } } spr.Sprites.Add(new SpriteInfo(rect, Program.Theme.Color, new Vector2f(sprsize.X * x, sprsize.Y * y), sprsize)); } } return(bg); }