Beispiel #1
0
        static public void PerformSplit(int scaleCoeff)
        {
            int size = CellSize / scaleCoeff;

            System.IO.Directory.CreateDirectory(OutSubdir);

            foreach (KeyValuePair <string, PicDescriptor> kvp in AllObjects)
            {
                string        name = OutSubdir + "\\" + NamePrefix[scaleCoeff] + kvp.Key;
                PicDescriptor pd   = kvp.Value;

                int minX = Math.Min(pd.P1.X, pd.P2.X), maxX = Math.Max(pd.P1.X, pd.P2.X);
                int minY = Math.Min(pd.P1.Y, pd.P2.Y), maxY = Math.Max(pd.P1.Y, pd.P2.Y);
                int cX = pd.Corner.X != FarAwayCoord ? pd.Corner.X : minX;
                int cY = pd.Corner.Y != FarAwayCoord ? pd.Corner.Y : minY;

                // switch off .info file writing for now

                /*  System.IO.StreamWriter sw = new System.IO.StreamWriter(name + ".info");
                 * sw.WriteLine((cX - minX).ToString() + " " + (cY - minY).ToString());
                 * sw.Close();
                 */

                Bitmap b = new Bitmap((maxX - minX + 1) * size, (maxY - minY + 1) * size, PixelFormat.Format24bppRgb);
                Graphics.FromImage(b).DrawImage(mOriginalImage,
                                                new Rectangle(0, 0, b.Width, b.Height),
                                                new Rectangle(minX * size, minY * size, b.Width, b.Height),
                                                GraphicsUnit.Pixel);
                b.Save(name + ".bmp", ImageFormat.Bmp);
            }
        }
Beispiel #2
0
        static public void ToggleCell(int i, int j, bool isLeftButton, bool isMiddleButton, string objName)
        {
            PicDescriptor pd = AllObjects[objName];

            if (!isMiddleButton)
            {
                if (isLeftButton)
                {
                    pd.P1 = new Coords(i, j);
                }
                else
                {
                    pd.P2 = new Coords(i, j);
                }
                if (pd.P1.X == FarAwayCoord)
                {
                    pd.P1 = pd.P2;
                }
                if (pd.P2.X == FarAwayCoord)
                {
                    pd.P2 = pd.P1;
                }
            }
            else
            {
                if (pd.Corner.X == FarAwayCoord)
                {
                    pd.Corner = new Coords(i, j);
                }
                else
                {
                    pd.Corner = new Coords(FarAwayCoord, FarAwayCoord);
                }
            }
        }
Beispiel #3
0
            static public PicDescriptor FromString(string s)
            {
                string[]      spl = s.Split(' ');
                PicDescriptor pd  = new PicDescriptor();

                pd.P1.X     = Convert.ToInt32(spl[0]); pd.P1.Y = Convert.ToInt32(spl[1]);
                pd.P2.X     = Convert.ToInt32(spl[2]); pd.P2.Y = Convert.ToInt32(spl[3]);
                pd.Corner.X = Convert.ToInt32(spl[4]); pd.Corner.Y = Convert.ToInt32(spl[5]);

                return(pd);
            }
Beispiel #4
0
        static public Bitmap CreateUpdatedScreen(string objName)
        {
            Bitmap        b  = (Bitmap)mGrayBitmap.Clone();
            PicDescriptor pd = AllObjects[objName];

/*            for (int i = Math.Min(pd.P1.X, pd.P2.X); i <= Math.Max(pd.P1.X, pd.P2.X); ++i)
 *              for (int j = Math.Min(pd.P1.Y, pd.P2.Y); j <= Math.Max(pd.P1.Y, pd.P2.Y); ++j)
 *              {
 *                  if (i == FarAwayCoord || j == FarAwayCoord)
 *                      continue;
 *
 *                  // make yellow background
 *                  for (int x = 0; x < CellSize; ++x)
 *                      for (int y = 0; y < CellSize; ++y)
 *                      {
 *                          int c = b.GetPixel(i * CellSize + x, j * CellSize + y).ToArgb();
 *                          if (c == MyBackColor.ToArgb() || c == GridColor.ToArgb())
 *                              b.SetPixel(i * CellSize + x, j * CellSize + y, SelColor);
 *                      }
 *              }
 */

            int minI = Math.Min(pd.P1.X, pd.P2.X), maxI = Math.Max(pd.P1.X, pd.P2.X);
            int minJ = Math.Min(pd.P1.Y, pd.P2.Y), maxJ = Math.Max(pd.P1.Y, pd.P2.Y);

            // make a yellow frame
            Graphics.FromImage(b).DrawRectangle(new Pen(SelColor, 2), minI * CellSize, minJ * CellSize, (maxI - minI + 1) * CellSize, (maxJ - minJ + 1) * CellSize);


            if (pd.Corner.X != FarAwayCoord)
            {
                // make small green triangle
                int px = pd.Corner.X * CellSize, py = pd.Corner.Y * CellSize;
                for (int i = 0; i <= CornerOffset; ++i)
                {
                    for (int j = 0; j <= CornerOffset - i; ++j)
                    {
                        b.SetPixel(px + i, py + j, CornerColor);
                    }
                }
            }

            return(b);
        }
Beispiel #5
0
        static public string[] LoadObjects(string fileName)
        {
            System.IO.StreamReader sr = new System.IO.StreamReader(fileName);
            ClearObjects();

            string        line;
            List <string> result = new List <string>();

            while ((line = sr.ReadLine()) != null)
            {
                string name = line.Substring(0, line.IndexOf(' '));
                string tail = line.Substring(line.IndexOf(' ') + 1);

                AllObjects[name] = PicDescriptor.FromString(tail);
                result.Add(name);
            }

            sr.Close();

            return(result.ToArray());
        }