public Label(gfx.Graphics graphics, string text, int fontSize, string fontType, Color fontColor, prim.Point point, prim.Size size) : base(graphics, "label", text, point, size) { SizeF textSize = new SizeF(); Bitmap somebitmap = new Bitmap(32, 32); Font font = new Font(graphics.fonts[fontType].Families[0], fontSize, FontStyle.Regular); if (text == "") { text = " "; } using (Graphics g = Graphics.FromImage(somebitmap)) { textSize = g.MeasureString(text, font); } Bitmap bitmap = new Bitmap((int)textSize.Width, (int)textSize.Height); GraphicsPath fontText = new GraphicsPath(); bitmap.MakeTransparent(); using (Graphics g = Graphics.FromImage(bitmap)) { //textSize = g.MeasureString(text, font); using (Brush brush = new SolidBrush(fontColor)) { g.SmoothingMode = SmoothingMode.HighQuality; g.CompositingQuality = CompositingQuality.HighQuality; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit; g.DrawString(text, font, brush, new PointF(0, 0)); } } //bitmap.RotateFlip(RotateFlipType.Rotate180FlipX); size.w = bitmap.Width / (float)graphics.size.w; size.h = bitmap.Height / (float)graphics.size.h; point.x = point.cx ? getCenter(size.w) : point.x; point.y = point.cy ? getCenter(size.h) : point.y; float[] vertices = { point.x + size.w, point.y + size.h, 0.0f, 1.0f, 1.0f, // top right point.x + size.w, point.y, 0.0f, 1.0f, 0.0f, // bottom right point.x, point.y, 0.0f, 0.0f, 0.0f, // bottom left point.x, point.y + size.h, 0.0f, 0.0f, 1.0f // top left }; uint[] indices = // note that we start from 0! { 0, 1, 3, // first triangle 1, 2, 3 // second triangle }; labelTexture = new gfx.ImageTexture(graphics, bitmap, vertices, indices); }
public ArrowButton(gfx.Graphics graphics, string dir, Color bgColor, prim.Point point, prim.Size size) : base(graphics, "arrow button", "", point, size) { mouseOverState = new prim.MouseOverStateMachine(); activated = false; float[] lVertices = { point.x + size.w, point.y + size.h, 0.0f, 1.0f, 1.0f, point.x + size.w, point.y, 0.0f, 1.0f, 0.0f, point.x, point.y + (size.h / 2.0f), 0.0f, 0.0f, 0.5f }; float[] rVertices = { point.x, point.y, 0.0f, 1.0f, 1.0f, point.x, point.y + size.h, 0.0f, 1.0f, 0.0f, point.x + size.w, point.y + (size.h / 2.0f), 0.0f, 0.0f, 0.5f }; uint[] indices = { 0, 1, 2 }; if (dir == "right") { texture = new gfx.ColorTexture(graphics, bgColor, rVertices, indices); } else { texture = new gfx.ColorTexture(graphics, bgColor, lVertices, indices); } }
//private gfx.Texture labelTexture; //private gfx.Texture boxTexture; public ToggleBox(gfx.Graphics graphics, string bind, string value, Color checkBoxColor, Color borderColor, prim.Size borderSize, string text, int fontSize, string fontType, Color fontColor, prim.Point point, prim.Size size) : base(graphics, "label", text, point, size) { this.bind = bind; this.value = value; isChecked = this.value == "true" ? true : false; label = new Label(graphics, text, fontSize, fontType, fontColor, point, new prim.Size(size.w, size.h)); size.h = label.size.h; size.w = graphics.getWSquareSize(label.size.h); pane = new Pane(graphics, checkBoxColor, borderColor, borderSize, new prim.Point(point.x, point.y), new prim.Size(size.w, size.h)); prim.Size sPaneSize = pane.size.Scale(0.8f); prim.Point sPanePnt = pane.point.GetTransPnt(sPaneSize.w * 0.1f, sPaneSize.h * 0.1f); selectedPane = new Pane(graphics, borderColor, borderColor, borderSize, sPanePnt, sPaneSize); label.point.x += pane.size.w; this.Update(); //pane = new Pane(graphics, checkBoxColor, borderColor, borderSize, new prim.Point(point.x, point.y), new prim.Size(size.w, size.h)); }
public Texture(gfx.Graphics graphics, string shaderName, float[] vertices, uint[] indices) { this.vertices = vertices; this.indices = indices; this.graphics = graphics; this.shader = new Shader(shaderName, graphics.shaders); }
public MapEditor(gfx.Graphics graphics) { this.prevCursorName = "cursor"; this.signal = ""; this.graphics = graphics; this.path = ""; process = new Process(); initState = new prim.InitStateMachine(); process.StartInfo.FileName = Directory.GetCurrentDirectory() + "/res/editor/HJCompanion.exe"; cursors = new Dictionary <string, gfx.Cursor>(); cursors.Add("locked", new gfx.Cursor(graphics, "locked")); cursors.Add("edit", new gfx.Cursor(graphics, "edit")); cursors.Add("remove", new gfx.Cursor(graphics, "remove")); cursors.Add("move", new gfx.Cursor(graphics, "move")); cursors.Add("details", new gfx.Cursor(graphics, "details")); cursors.Add("shape", new gfx.Cursor(graphics, "shape")); defaultCursor = new gfx.Cursor(graphics); cursor = defaultCursor; mode = "cursor"; prevMode = ""; map = new gfx.GameMap(graphics); scroll = new prim.Point(0, 0); scrollVelocity = 0.025f; }
public CollisionDemo(gfx.Graphics graphics) { this.graphics = graphics; initState = new prim.InitStateMachine(); map = new gfx.GameMap(graphics); map.LoadMap(graphics, "res/maps/CollisionDemo.hjm"); map.AddControlEntity(graphics, "test"); }
public ControlEntity(World world, MapInterface.ObjectTemplate template, gfx.Graphics graphics) { this.active = true; this.graphics = graphics; controlObject = new ObjectEntity(world, template, graphics, new prim.Point(0f, 0f), true); vx = 0.5f; vy = 0.5f; }
public Cursor(gfx.Graphics graphics, string name = "cursor") { this.graphics = graphics; this.name = name; string cursorPath = Directory.GetCurrentDirectory() + "/res/img/" + name + ".png"; Bitmap cursorBmp = new Bitmap(cursorPath); NewTexture(cursorBmp); }
public Button(gfx.Graphics graphics, string text, int fontSize, string fontType, Color fontColor, prim.Point point, prim.Size size, string action, string link) : base(graphics, "button", text, point, size) { activated = false; mouseState = new prim.MouseOverStateMachine(); label = new Label(graphics, text, fontSize, fontType, fontColor, point, size); this.link = link; this.action = action; }
public ColorTexture(gfx.Graphics graphics, Color fillColor, Color borderColor, Vector2 borderSize, float[] vertices, uint[] indices) : base(graphics, "triangle", vertices, indices) { this.texHandle = GL.GenTexture(); this.fillColor = fillColor; this.borderSize = borderSize; this.borderColor = borderColor; brightness = 1f; ToVAO(); }
public ColorTexture(gfx.Graphics graphics, Color fillColor, float[] vertices, uint[] indices) : base(graphics, "triangle", vertices, indices) { this.texHandle = GL.GenTexture(); this.fillColor = fillColor; borderSize = new Vector2(0, 0); borderColor = Color.FromArgb(0); brightness = 1f; ToVAO(); }
public ValueBox(gfx.Graphics graphics, string bind, string value, Color borderColor, prim.Size borderSize, int fontSize, string fontType, Color fontColor, prim.Point point, prim.Size size) : base(graphics, "select", "", point, size) { this.bind = bind; this.value = value; LAmouseOverState = new prim.MouseOverStateMachine(); RAmouseOverState = new prim.MouseOverStateMachine(); boxes = new List <Pane>(); float triH = size.h; float triW = graphics.getWSquareSize(triH); float[] lVertices = { point.x + triW, point.y + triH, 0.0f, 1.0f, 1.0f, point.x + triW, point.y, 0.0f, 1.0f, 0.0f, point.x, point.y + (triH / 2.0f), 0.0f, 0.0f, 0.5f }; //Remember to add size.x to point.x float[] rVertices = { point.x + size.w, point.y, 0.0f, 1.0f, 1.0f, point.x + size.w, point.y + triH, 0.0f, 1.0f, 0.0f, point.x + triW + size.w, point.y + (triH / 2.0f), 0.0f, 0.0f, 0.5f }; uint[] indices = { 0, 1, 2 }; //leftArrow = new gfx.ColorTexture(graphics, borderColor, lVertices, indices); //rightArrow = new gfx.ColorTexture(graphics, borderColor, rVertices, indices); leftArrow = new ArrowButton(graphics, "left", fontColor, new prim.Point(point), new prim.Size(triW, triH)); rightArrow = new ArrowButton(graphics, "right", fontColor, new prim.Point(point.x + size.w, point.y), new prim.Size(triW, triH)); selectPane = new Pane(graphics, Color.FromArgb(0, 0, 0, 0), borderColor, borderSize, new prim.Point(point.x + triW, point.y), new prim.Size(size.w - triW, size.h)); for (int i = 0; i < 10; i++) { prim.Size paneSize = new prim.Size((this.size.w + this.leftArrow.size.w) * 0.1f, this.size.h); prim.Point panePoint = new prim.Point(leftArrow.size.w + point.x + paneSize.w * i, point.y); Pane curPane = new Pane(graphics, borderColor, borderColor, borderSize, panePoint, paneSize); boxes.Add(curPane); } }
public StarField(gfx.Graphics graphics) : base(graphics, "starfield", new float[] { }, new uint[] { }) { vertexState = new prim.VertexStateMachine(); this.counter = 0; this.texHandle = GL.GenTexture(); prim.Size size = new prim.Size(graphics.getWSquareSize(0.05f), 0.05f); prim.Point pnt = new prim.Point(0.0f, 0.0f - size.h); LoadStarfield(); ToVAO(); }
public TextField(gfx.Graphics graphics, string text, int fontSize, string fontType, Color fontColor, prim.Point point) : base(graphics, "text field", "", point, new prim.Size()) { this.text = text; this.fontColor = fontColor; this.fontSize = fontSize; this.fontType = fontType; UpdateText(); prim.Size cSize = new prim.Size(textLines[0].size); cSize.w = graphics.getWSquareSize(cSize.h) / 8; prim.Point cPoint = new prim.Point(point.x + textLines[0].size.w, textLines[0].point.y); this.cursorPane = new Pane(graphics, fontColor, Color.Transparent, new prim.Size(), cPoint, cSize); }
public Component(gfx.Graphics graphics, string type, string text, prim.Point point, prim.Size size) { this.graphics = graphics; this.type = type; this.text = text; this.bind = ""; this.value = ""; this.signal = ""; this.point = point; this.size = size; this.subComponents = new List <Component>(); }
public MenuFactory(gfx.Graphics graphics) { signal = ""; menus = new Dictionary <string, Menu>(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("config/menu.xml"); XmlNodeList menuNodes = xmlDoc.SelectNodes("//menu"); foreach (XmlNode node in menuNodes) { string name = node.Attributes["name"].Value; menus.Add(name, new Menu(name, graphics)); } this.graphics = graphics; this.cursor = new gfx.Cursor(graphics); }
public Pane(gfx.Graphics graphics, Color paneColor, Color borderColor, prim.Size borderSize, prim.Point point, prim.Size size) : base(graphics, "pane", "", point, size) { float[] vertices = { point.x + size.w, point.y + size.h, 0.0f, 1.0f, 1.0f, // top right point.x + size.w, point.y, 0.0f, 1.0f, 0.0f, // bottom right point.x, point.y, 0.0f, 0.0f, 0.0f, // bottom left point.x, point.y + size.h, 0.0f, 0.0f, 1.0f // top left }; uint[] indices = // note that we start from 0! { 0, 1, 3, // first triangle 1, 2, 3 // second triangle }; Vector2 borderVec = graphics.normalizeSize(borderSize, this.size); paneTexture = new gfx.ColorTexture(graphics, paneColor, borderColor, borderVec, vertices, indices); }
public Texture(gfx.Graphics graphics, string shaderName) { uint[] defaultIndices = // note that we start from 0! { 0, 1, 3, // first triangle 1, 2, 3 // second triangle }; float[] defaultVertices = { 0f, 0f, 0f, 1f, 1f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 1f }; this.indices = defaultIndices; this.vertices = defaultVertices; this.graphics = graphics; this.shader = new Shader(shaderName, graphics.shaders); }
public ImageTexture(gfx.Graphics graphics, Bitmap bitmap) : base(graphics, "texture") { InitTexture(bitmap); }
public ImageTexture(gfx.Graphics graphics, Bitmap bitmap, float[] vertices, uint[] indices) : base(graphics, "texture", vertices, indices) { InitTexture(bitmap); }
public Menu(string menuName, gfx.Graphics graphics) { starfield = new gfx.StarField(graphics); configValues = graphics.GetConfigValues(); components = new List <Component>(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("config/menu.xml"); XmlNode menuNode = xmlDoc.SelectSingleNode(string.Format("//menu[@name='{0}']", menuName)); string fontType = menuNode.Attributes["font"].Value; Color fontColor = stringToColor(menuNode.Attributes["font_color"].Value); Color bgColor = stringToColor(menuNode.Attributes["bg_color"].Value); Color borderColor = stringToColor(menuNode.Attributes["border_color"].Value); int fontSize = int.Parse(menuNode.Attributes["font_size"].Value); foreach (XmlNode itemNode in menuNode.ChildNodes) { if (itemNode.Name == "item") { string type = itemNode.Attributes["type"].Value; string name = itemNode.Attributes["name"].Value; string text = itemNode.Attributes["text"].Value; float w = float.Parse(itemNode.Attributes["w"].Value); float h = float.Parse(itemNode.Attributes["h"].Value); string strX = itemNode.Attributes["x"].Value; string strY = itemNode.Attributes["y"].Value; float x = strX == "center" ? getCenter(w) : float.Parse(strX); float y = strY == "center" ? getCenter(h) : float.Parse(strY); if (type == "button") { string action = itemNode.Attributes["action"].Value; string link = itemNode.Attributes["link"].Value; components.Add(new Button(graphics, text, fontSize, fontType, fontColor, new prim.Point(x, y, strX == "center", strY == "center"), new prim.Size(w, h), action, link)); } else if (type == "label") { components.Add(new Label(graphics, text, fontSize, fontType, fontColor, new prim.Point(x, y, strX == "center", strY == "center"), new prim.Size(0, 0))); } else if (type == "pane") { Color paneColor = stringToColor(itemNode.Attributes["pane_color"].Value); float borderSize = float.Parse(itemNode.Attributes["border_size"].Value); prim.Size borderSizeObj = new prim.Size(borderSize, borderSize); components.Add(new Pane(graphics, paneColor, borderColor, borderSizeObj, new prim.Point(x, y, strX == "center", strY == "center"), new prim.Size(w, h))); } else if (type == "toggle box") { string bind = itemNode.Attributes["bind"].Value; string value = configValues[bind]; float borderSize = float.Parse(itemNode.Attributes["border_size"].Value); prim.Size borderSizeObj = new prim.Size(borderSize, borderSize); components.Add(new ToggleBox(graphics, bind, value, bgColor, borderColor, borderSizeObj, text, fontSize, fontType, fontColor, new prim.Point(x, y, strX == "center", strY == "center"), new prim.Size(w, h))); } else if (type == "select box") { string bind = itemNode.Attributes["bind"].Value; string value = configValues[bind]; float borderSize = float.Parse(itemNode.Attributes["border_size"].Value); int selectFontSize = int.Parse(itemNode.Attributes["label_font_size"].Value); prim.Size borderSizeObj = new prim.Size(borderSize, borderSize); XmlNodeList choiceNodes = itemNode.ChildNodes; components.Add(new Select(graphics, bind, value, borderColor, borderSizeObj, selectFontSize, fontType, fontColor, new prim.Point(x, y), new prim.Size(w, h), choiceNodes)); } else if (type == "value box") { string bind = itemNode.Attributes["bind"].Value; string value = configValues[bind]; float borderSize = float.Parse(itemNode.Attributes["border_size"].Value); int selectFontSize = int.Parse(itemNode.Attributes["label_font_size"].Value); prim.Size borderSizeObj = new prim.Size(borderSize, borderSize); XmlNodeList choiceNodes = itemNode.ChildNodes; components.Add(new ValueBox(graphics, bind, value, borderColor, borderSizeObj, selectFontSize, fontType, fontColor, new prim.Point(x, y), new prim.Size(w, h))); } else if (type == "text field") { components.Add(new TextField(graphics, text, fontSize, fontType, fontColor, new prim.Point(x, y, strX == "center", strY == "center"))); } } } }
public Select(gfx.Graphics graphics, string bind, string value, Color borderColor, prim.Size borderSize, int fontSize, string fontType, Color fontColor, prim.Point point, prim.Size size, XmlNodeList choiceNodes) : base(graphics, "select", "", point, size) { this.bind = bind; choices = new List <Choice>(); choiceLabels = new List <Label>(); selectIndex = 0; LAmouseOverState = new prim.MouseOverStateMachine(); RAmouseOverState = new prim.MouseOverStateMachine(); float triH = size.h; float triW = graphics.getWSquareSize(triH); float[] lVertices = { point.x + triW, point.y + triH, 0.0f, 1.0f, 1.0f, point.x + triW, point.y, 0.0f, 1.0f, 0.0f, point.x, point.y + (triH / 2.0f), 0.0f, 0.0f, 0.5f }; //Remember to add size.x to point.x float[] rVertices = { point.x + size.w, point.y, 0.0f, 1.0f, 1.0f, point.x + size.w, point.y + triH, 0.0f, 1.0f, 0.0f, point.x + triW + size.w, point.y + (triH / 2.0f), 0.0f, 0.0f, 0.5f }; uint[] indices = { 0, 1, 2 }; //leftArrow = new gfx.ColorTexture(graphics, borderColor, lVertices, indices); //rightArrow = new gfx.ColorTexture(graphics, borderColor, rVertices, indices); leftArrow = new ArrowButton(graphics, "left", fontColor, new prim.Point(point), new prim.Size(triW, triH)); rightArrow = new ArrowButton(graphics, "right", fontColor, new prim.Point(point.x + size.w, point.y), new prim.Size(triW, triH)); foreach (XmlNode choiceNode in choiceNodes) { Choice choice = new Choice(choiceNode.Attributes["text"].Value, choiceNode.Attributes["value"].Value); choices.Add(choice); Label choiceLabel = new Label(graphics, choice.name, fontSize, fontType, fontColor, new prim.Point(point), new prim.Size(0, 0)); choiceLabel.point.x = triW + (point.x + ((size.w - triW) / 2)) - (choiceLabel.size.w / 2); choiceLabel.point.y = (point.y + (size.h / 2)) - (choiceLabel.size.h / 2); choiceLabel.Update(); choiceLabels.Add(choiceLabel); } SetValue(value); selectPane = new Pane(graphics, Color.FromArgb(0, 0, 0, 0), borderColor, borderSize, new prim.Point(point.x + triW, point.y), new prim.Size(size.w - triW, size.h)); }