Exemplo n.º 1
0
        private void BGImageLoad(string fileName, Images.ImageLoadResult info)
        {
            Image origBG = canvasBgImage;

            DebugLogger.Log("Main", "Loaded BG of type {0} from {1}", info.type.ToString(), fileName);
            if (DebugLogger.DoDebugActions())
            {
                string newBGName = Globals.MakeDebugSaveName(true, Path.GetFileName(fileName));
                File.Copy(fileName, newBGName, true);
                string newConvertedBG = Globals.MakeDebugSaveName(false, "newconvertedbg.png");
                info.image.Save(newConvertedBG, System.Drawing.Imaging.ImageFormat.Png);
            }
            layerState.On(LayerStateManager.Layers.Background);
            canvasBgImage = info.image;
            RecompositeCanvasImage();
            if (origBG != null)
            {
                if (DebugLogger.DoDebugActions())
                {
                    string previousBG = Globals.MakeDebugSaveName(false, "previousbg.png");
                    origBG.Save(previousBG, System.Drawing.Imaging.ImageFormat.Png);
                }
                origBG.Dispose();
            }
        }
Exemplo n.º 2
0
        private void RecompositeCanvasImage()
        {
            Bitmap bm = new Bitmap(CANVAS_WIDTH, CANVAS_HEIGHT, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            LayerStateManager.Layers fgbg = layerState.Query(LayerStateManager.Layers.Background | LayerStateManager.Layers.Foreground);
            using (Graphics g = Graphics.FromImage(bm))
            {
                g.Clear(Color.Black);
                if ((canvasBgImage != null) && ((fgbg & LayerStateManager.Layers.Background) != 0))
                {
                    g.Clear(Globals.App.TransparentBackgroundAreasColour);
                    g.DrawImage(canvasBgImage, Point.Empty);
                }
                if ((canvasFgImage != null) && ((fgbg & LayerStateManager.Layers.Foreground) != 0))
                {
                    g.DrawImage(canvasFgImage, Point.Empty);
                }
            }
            if (DebugLogger.DoDebugActions())
            {
                string compositedName = Globals.MakeDebugSaveName(false, "newcanvas.png");
                bm.Save(compositedName, System.Drawing.Imaging.ImageFormat.Png);
            }
            Image oldImage = canvas.Image;

            canvas.Image = bm;
            if (oldImage != null)
            {
                oldImage.Dispose();
            }
        }
Exemplo n.º 3
0
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (!CloseCurrentFile())
     {
         e.Cancel = true;
     }
     else
     {
         Rectangle winBounds;
         if (WindowState == FormWindowState.Normal)
         {
             winBounds = Bounds;
         }
         else
         {
             winBounds = RestoreBounds;
         }
         Globals.Save(Application.StartupPath, winBounds);
         if (DebugLogger.DoDebugActions())
         {
             string debugFile = Globals.MakeDebugSaveName(true, "log.txt");
             System.IO.File.WriteAllText(debugFile, DebugLogger.GetContents());
         }
     }
 }
Exemplo n.º 4
0
        public static void Save(
            string fileName,
            Image bg,
            byte[] fgGMLL,
            List <IBox> boxes,
            GTMP.GMFile.GMMetadata metadata,
            IconImgType fileVersion
            )
        {
            Debug.Assert(fileVersion != IconImgType.Invalid);
            DebugLogger.Log("Project", "Saving project to {0}", fileName);
            GMSerializedProject gmp = new GMSerializedProject();

            gmp.foreground = (fgGMLL != null) ? Convert.ToBase64String(fgGMLL) : String.Empty;
            byte[] imageData = Images.GetBytes(bg, System.Drawing.Imaging.ImageFormat.Png);
            gmp.background    = Convert.ToBase64String(imageData);
            gmp.fileMetadata  = metadata;
            gmp.gt2BoxVersion = fileVersion;
            SeparateBoxes(boxes, out gmp.boxes, out gmp.iconBoxes);
            string projectFile = Json.Serialize(gmp);

#if DEBUG
            File.WriteAllText(@"T:\gmpproj.txt", projectFile);
#endif
            MemoryStream compProj = Compress.ZipCompressString(projectFile);
            File.WriteAllBytes(fileName, compProj.ToArray());
            if (DebugLogger.DoDebugActions())
            {
                string projectCopy = Globals.MakeDebugSaveName(true, Path.GetFileName(fileName));
                File.WriteAllBytes(projectCopy, compProj.ToArray());
            }
        }
Exemplo n.º 5
0
 private void toggleLoggingToolStripMenuItem_Click(object sender, EventArgs e)
 {
     // turning it off
     if (DebugLogger.DoDebugActions())
     {
         string debugFile = Globals.MakeDebugSaveName(true, "log.txt");
         System.IO.File.WriteAllText(debugFile, DebugLogger.GetContents());
     }
     // turning it on
     else
     {
         string dir = Path.Combine(Application.StartupPath, "logged");
         Globals.RestartLoggingDir(dir);
     }
     DebugLogger.ToggleDebugActions();
 }
Exemplo n.º 6
0
        private void ReplaceForegroundImage(byte[] foregroundGMLL, Bitmap image)
        {
            Image origFG = canvasFgImage;

            if (DebugLogger.DoDebugActions())
            {
                string origImageName = Globals.MakeDebugSaveName(false, "newFG.png");
                image.Save(origImageName, System.Drawing.Imaging.ImageFormat.Png);
            }
            canvasFgImage = image;
            RecompositeCanvasImage();
            if (origFG != null)
            {
                if (DebugLogger.DoDebugActions())
                {
                    string saveFile = Globals.MakeDebugSaveName(false, "origFG.png");
                    origFG.Save(saveFile, System.Drawing.Imaging.ImageFormat.Png);
                }
                origFG.Dispose();
            }
            currentForegroundGMLLData = foregroundGMLL;
        }
Exemplo n.º 7
0
 private void FGImageLoad(string fileName, Images.ImageLoadResult info)
 {
     if (DebugLogger.DoDebugActions())
     {
         string fgImageName = Globals.MakeDebugSaveName(true, Path.GetFileName(fileName));
         File.Copy(fileName, fgImageName, true);
     }
     if (info.type != Images.ImageType.GM)
     {
         byte[] newForegroundData;
         if (info.type != Images.ImageType.GMLL)
         {
             newForegroundData = Tools.CheckConvertImageTo(info.image, Tools.ConvertType.GM);
             if (newForegroundData == null)
             {
                 info.image.Dispose();
                 return;
             }
         }
         else
         {
             newForegroundData = File.ReadAllBytes(fileName);
         }
         DebugLogger.Log("Main", "Got {0} bytes of non-GM GMLL data", newForegroundData.Length);
         if (DebugLogger.DoDebugActions())
         {
             string nonGMDataFile = Globals.MakeDebugSaveName(false, "{0}nongm-fg.gmll", Path.GetFileNameWithoutExtension(fileName));
             File.WriteAllBytes(nonGMDataFile, newForegroundData);
         }
         layerState.On(LayerStateManager.Layers.Foreground);
         ReplaceForegroundImage(newForegroundData, info.image);
     }
     else // (info.type == Images.ImageType.GM)
     {
         // This is a hack since CloseCurrentFile() resets everything
         // and disposes the images, but when we're reloading the foreground
         // only, we should preserve the background, so lets do this
         // rather than bool-ing it up just for this one case
         Image bgBackup = null;
         if (canvasBgImage != null)
         {
             bgBackup = (Image)canvasBgImage.Clone();
         }
         if (!CloseCurrentFile())
         {
             // didn't need it anyway
             if (bgBackup != null)
             {
                 bgBackup.Dispose();
             }
             info.image.Dispose();
             return;
         }
         canvasBgImage = bgBackup;
         layerState.On(LayerStateManager.Layers.Foreground);
         byte[] gmllData = Images.LoadGMLLData(fileName);
         ReplaceForegroundImage(gmllData, info.image);
         GTMP.GMFile.GMFileInfo fileInf = info.gmInfo;
         DebugLogger.Log("Main", "Got {0} bytes of GM-GMLL data from {1}, file had {2} boxes", gmllData.Length, fileName, fileInf.Boxes == null ? -1 : fileInf.Boxes.Count);
         if (fileInf.Boxes != null)
         {
             boxList.BeginUpdate();
             try
             {
                 allBoxes.Clear();
                 List <IBox> boxes = ConvertGMFileBoxes(fileInf.Boxes);
                 allBoxes.Load(boxes);
             }
             finally
             {
                 boxList.EndUpdate();
             }
         }
         metadataPropertyList.SelectedObject = fileInf.Metadata;
     }
     SetTitleFileName(fileName);
 }
Exemplo n.º 8
0
        public static bool Load(string fileName, out Bitmap bg, out Bitmap fg, out byte[] fgGMLL, out List <IBox> boxes, out GTMP.GMFile.GMMetadata metadata)
        {
            fg       = bg = null;
            fgGMLL   = null;
            boxes    = null;
            metadata = null;
            DebugLogger.Log("Project", "Loading file at {0}", fileName);
            if (DebugLogger.DoDebugActions())
            {
                string projectCopy = Globals.MakeDebugSaveName(true, Path.GetFileName(fileName));
                File.Copy(fileName, projectCopy, true);
            }
            byte[] projectBytes;
            using (FileStream fs = File.OpenRead(fileName))
            {
                projectBytes = Compress.DecompressStream(fs).ToArray();
            }
            string jsonText = Encoding.UTF8.GetString(projectBytes);
            GMSerializedProject projectData = Json.Parse <GMSerializedProject>(jsonText);
            IconImgType         projType    = projectData.gt2BoxVersion;
            IconImgType         currentType = Globals.App.GT2Version;

            Debug.Assert(projType != IconImgType.Invalid);
            if (projType != currentType)
            {
                System.Windows.Forms.DialogResult res = MainForm.DisplayMsgBox(
                    System.Windows.Forms.MessageBoxButtons.YesNoCancel,
                    System.Windows.Forms.MessageBoxIcon.Question,
                    "{0} was saved with GT2 Version {1} which is different from the current version {2}. Change the current version?",
                    fileName,
                    projType,
                    currentType
                    );
                if (res != System.Windows.Forms.DialogResult.Yes)
                {
                    return(false);
                }
                Globals.App.GT2Version = projType;
                Hardcoded.Refresh(System.Windows.Forms.Application.StartupPath);
            }
            byte[] imageData;
            if (!String.IsNullOrEmpty(projectData.background))
            {
                imageData = Convert.FromBase64String(projectData.background);
                bg        = Images.FromBytes(imageData);
            }
            else
            {
                bg = null;
            }
            if (!String.IsNullOrEmpty(projectData.foreground))
            {
                fgGMLL = Convert.FromBase64String(projectData.foreground);
                fg     = Images.FromBytes(fgGMLL);
            }
            metadata = projectData.fileMetadata;
            boxes    = new List <IBox>();
            foreach (IconImgBox img in projectData.iconBoxes)
            {
                boxes.Add(img);
            }
            foreach (Box box in projectData.boxes)
            {
                boxes.Add(box);
            }
            return(true);
        }