Example #1
0
        public Graphics(prim.Size size, util.Config config)
        {
            quit            = false;
            reload          = false;
            fps             = 0;
            t_fps           = 60;
            actionKeyBuffer = new List <uint>();
            this.config     = config;
            configValues    = config.GetSettingCopy();
            leftClick       = new prim.ClickStateMachine();
            rightClick      = new prim.ClickStateMachine();
            middleClick     = new prim.ClickStateMachine();
            mousePoint      = new prim.Point(0, 0);
            shaders         = new ShaderFactory();

            this.size = size;
            fonts     = new Dictionary <string, PrivateFontCollection>();

            foreach (string fname in Directory.GetFiles("res/fonts"))
            {
                PrivateFontCollection curFonts = new PrivateFontCollection();
                curFonts.AddFontFile(fname);
                fonts.Add(Path.GetFileNameWithoutExtension(fname), curFonts);
            }
        }
Example #2
0
        public Vector2 normalizeSize(prim.Size childSize, prim.Size parentSize)
        {
            Vector2 parentPixelSize = this.getPixelSize(parentSize);

            return(new Vector2(childSize.w / parentPixelSize[0],
                               childSize.h / parentPixelSize[1]));
        }
Example #3
0
 public Vector2 getPixelSize(prim.Size curSize)
 {
     return(new Vector2(
                curSize.w * this.size.w,
                curSize.h * this.size.h
                ));
 }
Example #4
0
        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);
        }
Example #5
0
        //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));
        }
Example #6
0
 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;
 }
Example #7
0
        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);
            }
        }
Example #8
0
        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();
        }
Example #9
0
 public WallEntity(World world, MapInterface.ObjectTemplate temp, Graphics graphics, prim.Point point, prim.Size size, bool isDynamic = false)
     : base()
 {
     this.point       = point;
     this.x           = point.x;
     this.y           = point.y;
     this.dx          = 0f;
     this.dy          = 0f;
     this.colEntities = new List <CollisionEntity>();
     this.instance    = temp;
     this.size        = size;
     wallStrategy     = new WallStrategy();
     wallStrategy.InitTexture(ref world, ref body, this.point, ref this.size, ref texture, ref instance, graphics, isDynamic);
 }
Example #10
0
 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);
 }
Example #11
0
        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>();
        }
Example #12
0
        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);
        }
Example #13
0
        protected void SetPoints(Graphics graphics, Bitmap bitmap, ref ImageTexture texture, prim.Point point, ref prim.Size size)
        {
            if (size == null)
            {
                size = new prim.Size(bitmap.Width / graphics.size.w, bitmap.Height / graphics.size.h);
            }
            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
            };

            texture = new ImageTexture(graphics, bitmap, vertices, indices);
        }
Example #14
0
        private void InitTexture(Bitmap bitmap)
        {
            size = new prim.Size(bitmap.Width / (float)graphics.size.w,
                                 bitmap.Height / (float)graphics.size.h);
            bitmapSize     = new prim.Size(size);
            this.texHandle = GL.GenTexture();
            this.Use();
            GL.BindTexture(TextureTarget.Texture2D, texHandle);
            BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0,
                                                                  bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly,
                                                    System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bitmapData.Width,
                          bitmapData.Height, 0, OpenTK.Graphics.OpenGL4.PixelFormat.Bgra, PixelType.UnsignedByte, bitmapData.Scan0);
            bitmap.UnlockBits(bitmapData);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);
            GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
            ToVAO();
        }
Example #15
0
        public void NewTexture(Bitmap cursorBmp)
        {
            size = new prim.Size(cursorBmp.Width / (float)graphics.size.w,
                                 cursorBmp.Height / (float)graphics.size.h);
            point = graphics.mousePoint;

            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
            };

            cursorTexture = new gfx.ImageTexture(graphics, cursorBmp, vertices, indices);
        }
Example #16
0
 public override void Update(prim.Point point, prim.Size newSize, bool repeat = true)
 {
     this.size = newSize;
     if (repeat)
     {
         float nx = size.w / bitmapSize.w;
         float ny = size.h / bitmapSize.h;
         Console.WriteLine(nx.ToString() + " , " + ny.ToString());
         float[] newVertices =
         {
             point.x + size.w, point.y + size.h, 0.0f, nx, ny,     // top right
             point.x + size.w, point.y,          0.0f, nx, 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, ny    // top left
         };
         this.vertices = newVertices;
         this.size     = new prim.Size(size.w / (float)graphics.size.w,
                                       size.h / (float)graphics.size.h);
     }
     else
     {
         Update(point);
     }
 }
Example #17
0
        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")));
                    }
                }
            }
        }
Example #18
0
 public Vector2 normalizeSize(prim.Size curSize)
 {
     //float aspect = this.size.w / this.size.h;
     return(new Vector2(curSize.w / this.size.w, curSize.h / this.size.h));
 }
Example #19
0
        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));
        }
Example #20
0
        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);
            }
        }
Example #21
0
        public override void InitTexture(ref World world, ref Body body, prim.Point point, ref prim.Size size, ref ImageTexture texture, ref MapInterface.ObjectTemplate temp, Graphics graphics, bool isDynamic = false)
        {
            Bitmap bitmap = temp.images["default"][0].image;

            SetPoints(graphics, bitmap, ref texture, point, ref size);
            BodyDef    bodyDef = new BodyDef();
            PolygonDef polyBox = new PolygonDef();
            PolygonDef polyDef = new PolygonDef();

            bodyDef.Position.Set(point.x, point.y);
            polyDef.Density     = 1f;
            polyBox.Density     = 1f;
            bodyDef.Angle       = 0f;
            polyDef.VertexCount = temp.images["default"][0].collisionVectors.Count;
            polyBox.SetAsBox(size.w / 2, size.h / 2);
            List <prim.Point> points = new List <prim.Point>();

            foreach (MapInterface.Line line in temp.images["default"][0].collisionVectors)
            {
                float nx1 = ((float)line.x1 / bitmap.Width) * (float)size.w;
                float nx2 = ((float)line.x2 / bitmap.Width) * (float)size.w;
                float ny1 = ((float)line.y1 / bitmap.Height) * (float)size.h;
                float ny2 = ((float)line.y2 / bitmap.Height) * (float)size.h;
                points.Add(new prim.Point(nx1, ny1));
                points.Add(new prim.Point(nx2, ny2));
            }

            AddCollisionPoints(ref world, ref temp, bodyDef, polyDef, points, ref body);

            if (isDynamic)
            {
                body.SetMassFromShapes();
            }
        }
Example #22
0
 public virtual void Update(prim.Point point, prim.Size size, bool repeat = true)
 {
 }
Example #23
0
        protected void LoadStarfield()
        {
            int numStars = 2000;

            List <Vector4> colors = new List <Vector4>();

            colors.Add(graphics.ColorToVec4(Color.FromArgb(255, 255, 61, 61)));
            colors.Add(graphics.ColorToVec4(Color.FromArgb(255, 249, 255, 84)));
            colors.Add(graphics.ColorToVec4(Color.FromArgb(255, 84, 92, 255)));
            for (int i = 0; i < 7; i++)
            {
                colors.Add(graphics.ColorToVec4(Color.White));
            }

            List <float> data     = new List <float>();
            List <uint>  indices  = new List <uint>();
            GaussianList sizeList = new GaussianList(0.008, 0.002, 10000);
            GaussianList velList  = new GaussianList(0.1, 0.03, 10000);
            Random       rand     = new Random();

            this.counter = rand.NextDouble() * 5000;

            for (int i = 0; i < numStars; i++)
            {
                float gSize = (float)sizeList.GetValue(rand);
                float x     = (float)rand.NextDouble();
                float v     = (float)velList.GetValue(rand);

                Vector4   color = colors[rand.Next() % colors.Count];
                prim.Size size  = new prim.Size(graphics.getWSquareSize(gSize), gSize);

                //Vertices
                data.Add(x + size.w);
                data.Add(0.0f);
                data.Add(0.0f);
                //Tex Coord
                data.Add(1.0f);
                data.Add(1.0f);
                //Color
                data.Add(color[0]);
                data.Add(color[1]);
                data.Add(color[2]);
                data.Add(1.0f);
                //Velocity
                data.Add(v);


                //Vertices
                data.Add(x + size.w);
                data.Add(0.0f - size.h);
                data.Add(0.0f);
                //Tex Coord
                data.Add(1.0f);
                data.Add(0.0f);
                //Color
                data.Add(color[0]);
                data.Add(color[1]);
                data.Add(color[2]);
                data.Add(1.0f);
                //Velocity
                data.Add(v);


                //Vertices
                data.Add(x);
                data.Add(0.0f - size.h);
                data.Add(0.0f);
                //Tex Coord
                data.Add(0.0f);
                data.Add(0.0f);
                //Color
                data.Add(color[0]);
                data.Add(color[1]);
                data.Add(color[2]);
                data.Add(1.0f);
                //Velocity
                data.Add(v);


                //Vertices
                data.Add(x);
                data.Add(0.0f);
                data.Add(0.0f);
                //Tex Coord
                data.Add(0.0f);
                data.Add(1.0f);
                //Color
                data.Add(color[0]);
                data.Add(color[1]);
                data.Add(color[2]);
                data.Add(1.0f);
                //Velocity
                data.Add(v);

                indices.Add((uint)(4 * i));
                indices.Add((uint)(4 * i + 1));
                indices.Add((uint)(4 * i + 3));
                indices.Add((uint)(4 * i + 1));
                indices.Add((uint)(4 * i + 2));
                indices.Add((uint)(4 * i + 3));
            }
            this.vertices = data.ToArray();
            this.indices  = indices.ToArray();
        }
Example #24
0
 public void Update()
 {
     Pan();
     if (initState.currentState == "init")
     {
         Launch();
         initState.TransitionState("non init");
     }
     else
     {
         ipc.PollMessage();
         if (ipc.signal != "")
         {
             try
             {
                 string[] allParams = ipc.signal.Split(',');
                 if (allParams[0] == "exit")
                 {
                     this.signal = "exit";
                     ipc.Stop();
                 }
                 if (allParams[0] == "remove instance")
                 {
                     cursor = cursors["remove"];
                     mode   = "remove";
                 }
                 if (allParams[0] == "shape instance")
                 {
                     cursor = cursors["shape"];
                     string objKey = allParams[1];
                     curObj = map.mapInterface.objectTemplates[objKey];
                     Bitmap curTexture = map.mapInterface.objectTemplates[objKey].images["default"][0].image;
                     shapeTexture = new gfx.ImageTexture(this.graphics, curTexture);
                     mode         = "shape";
                 }
                 if (allParams[0] == "move instance")
                 {
                     cursor = cursors["move"];
                     mode   = "move";
                 }
                 if (allParams[0] == "instance details")
                 {
                     cursor = cursors["details"];
                     mode   = "details";
                 }
                 if (allParams[0] == "lock")
                 {
                     prevMode       = mode;
                     prevCursorName = cursor.name;
                     cursor         = cursors["locked"];
                     mode           = "locked";
                 }
                 if (allParams[0] == "unlock")
                 {
                     cursor = cursors[prevCursorName];
                     mode   = prevMode;
                 }
                 if (allParams[0] == "load map")
                 {
                     //TODO: Load Map
                     this.path = Directory.GetCurrentDirectory() + "/res/maps/" + allParams[1];
                     map.LoadMap(this.graphics, this.path);
                     Console.WriteLine("LOAD MAP");
                 }
                 if (allParams[0] == "save instances")
                 {
                     SaveInstances();
                 }
                 if (allParams[0] == "remove all instances")
                 {
                     LockClient();
                     map.mapInterface.objectInstances = new List <MapInterface.ObjectInstance>();
                     map.mapInterface.Save();
                     UnlockClient();
                     //Client must have the latest
                     ipc.SendMessage("reload map");
                 }
                 if (allParams[0] == "reload map")
                 {
                     Console.WriteLine("RELOAD MAP");
                 }
                 if (allParams[0] == "load instances")
                 {
                     //ipc.SendMessage("lock");
                     map.LoadMap(this.graphics);
                     //ipc.SendMessage("unlock");
                     //ipc.SendMessage("reload map");
                 }
                 if (allParams[0] == "save instances async")
                 {
                     map.mapInterface.Save();
                 }
                 if (allParams[0] == "place")
                 {
                     SaveInstances();
                     map.LoadMap(this.graphics);
                     string objKey = allParams[1];
                     curObj = map.mapInterface.objectTemplates[objKey];
                     Bitmap newImage = curObj.images["default"][0].image;
                     cursors["edit"].ChangeTexture(newImage);
                     cursor    = cursors["edit"];
                     this.mode = "place";
                 }
                 if (allParams[0] == "cursor")
                 {
                     cursor    = defaultCursor;
                     this.mode = "cursor";
                 }
             }
             catch (Exception ie)
             {
                 this.signal = "exit";
                 ipc.Stop();
             }
         }
         if (graphics.leftClick.currentState == "clicked")
         {
             if (this.mode == "place")
             {
                 prim.Point       pnt         = AbsMouse();
                 gfx.ObjectEntity objInstance = new gfx.ObjectEntity(map.world, curObj, graphics, AbsMouse());
                 map.mapInterface.objectInstances.Add(objInstance);
                 SaveInstances();
             }
             else if (this.mode == "remove")
             {
                 List <gfx.ObjectEntity> insts = getCursorAdjInstances();
                 if (insts.Count > 0)
                 {
                     map.mapInterface.objectInstances.Remove(insts[0]);
                 }
                 SaveInstances();
             }
             else if (this.mode == "move progress")
             {
                 this.mode = "move";
                 SaveInstances();
             }
             else if (this.mode == "shape progress")
             {
                 this.mode = "shape";
                 prim.Size      wallSize    = new prim.Size(shapeTexture.size);
                 prim.Point     wallPoint   = new prim.Point(startShapePoint);
                 gfx.WallEntity objInstance = new gfx.WallEntity(map.world, curObj, graphics, wallPoint, wallSize);
                 map.mapInterface.objectWalls.Add(objInstance);
                 shapeTexture = null;
             }
             else if (this.mode == "details")
             {
                 List <gfx.ObjectEntity> insts = getCursorAdjInstances();
                 if (insts.Count > 0)
                 {
                     SaveInstances();
                     int index = map.mapInterface.objectInstances.IndexOf(insts[0]);
                     ipc.SendMessage("launch details," + index.ToString());
                 }
             }
         }
         if (graphics.leftClick.currentState == "mouse down")
         {
             if (this.mode == "move")
             {
                 List <gfx.ObjectEntity> insts = getCursorAdjInstances();
                 if (insts.Count > 0)
                 {
                     heldObject = insts[0];
                     this.mode  = "move progress";
                 }
             }
             if (this.mode == "shape")
             {
                 this.mode       = "shape progress";
                 startShapePoint = new prim.Point(graphics.mousePoint);
             }
             if (this.mode == "shape progress")
             {
                 prim.Size newSize = new prim.Size(Math.Abs(startShapePoint.x - this.graphics.mousePoint.x),
                                                   Math.Abs(startShapePoint.y - this.graphics.mousePoint.y));
                 shapeTexture.Update(startShapePoint, newSize);
             }
             if (this.mode == "move progress")
             {
                 heldObject.UpdatePoint(AbsMouse());
                 heldObject.Update();
                 map.mapInterface.Save();
             }
         }
     }
     cursor.Update(AbsMouse());
 }
Example #25
0
        public virtual void InitTexture(ref World world, ref Body body, prim.Point point, ref prim.Size size, ref ImageTexture texture, ref MapInterface.ObjectTemplate temp, Graphics graphics, bool isDynamic = false)
        {
            Bitmap bitmap = temp.images["default"][0].image;

            SetPoints(graphics, bitmap, ref texture, point, ref size);

            BodyDef    bodyDef = new BodyDef();
            PolygonDef polyBox = new PolygonDef();
            PolygonDef polyDef = new PolygonDef();

            bodyDef.Position.Set(point.x, point.y);
            polyDef.Density     = 1f;
            polyBox.Density     = 1f;
            bodyDef.Angle       = 0f;
            polyDef.VertexCount = temp.images["default"][0].collisionVectors.Count;
            polyBox.SetAsBox(size.w / 2, size.h / 2);
            List <prim.Point> points = new List <prim.Point>();

            foreach (MapInterface.Line line in temp.images["default"][0].collisionVectors)
            {
                float nx1 = ((float)line.x1 / bitmap.Width) * (float)size.w;
                float nx2 = ((float)line.x2 / bitmap.Width) * (float)size.w;
                float ny1 = ((float)line.y1 / bitmap.Height) * (float)size.h;
                float ny2 = ((float)line.y2 / bitmap.Height) * (float)size.h;
                points.Add(new prim.Point(nx1, ny1));
                points.Add(new prim.Point(nx2, ny2));
            }
            //TODO: Sort vertices in CCW order
            //Example. Top triangle point -> bottom right -> bottem left
            //points = GetDistinctPoints(points);
            //foreach (prim.Point curPoint in points)
            //{
            //    vCnt += 1;
            //    polyDef.Vertices[vCnt].Set(curPoint.x, curPoint.y);
            //}

            //bodyDef.FixedRotation = true;
            //body = world.CreateBody(bodyDef);
            //body.CreateShape(polyDef);

            AddCollisionPoints(ref world, ref temp, bodyDef, polyDef, points, ref body);

            if (isDynamic)
            {
                body.SetMassFromShapes();
            }
        }