예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
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());
 }