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 LoadAndDisplaySelectedFile(string fileName, PostImageLoad afterLoadFn)
 {
     DebugLogger.Log("Main", "Loading {0} with afterloader {1}...", fileName, afterLoadFn.Method.Name);
     try
     {
         Images.ImageLoadResult imageload = Images.LoadFile(fileName);
         DebugLogger.Log("Main", "...Image was a {0}", imageload.type.ToString());
         Bitmap image = imageload.image;
         if ((image.Width != CANVAS_WIDTH) || (image.Height != CANVAS_HEIGHT))
         {
             DisplayMsgBox(MessageBoxButtons.OK, MessageBoxIcon.Warning, "'{0}' was loaded, but it's the wrong size {1}. Should be {2}x{3}", Path.GetFileName(fileName), image.Size, CANVAS_WIDTH, CANVAS_HEIGHT);
             image.Dispose();
             return;
         }
         afterLoadFn(fileName, imageload);
     }
     catch (Exception e)
     {
         DisplayMsgBox(MessageBoxButtons.OK, MessageBoxIcon.Error, "Failed to load {0} because of error {1}", fileName, e.Message);
     }
 }
Exemplo n.º 3
0
        private void ProjectLoad()
        {
            string fileName = GetOpenFileName(this, "Open Project file", "GMCreator Project Files|*.gmproj", null);

            if (String.IsNullOrEmpty(fileName))
            {
                return;
            }
            Bitmap      fg, bg;
            List <IBox> boxes;

            GTMP.GMFile.GMMetadata metadata;
            byte[] gmllData = null;
            if (!GMProject.Load(fileName, out bg, out fg, out gmllData, out boxes, out metadata))
            {
                return;
            }
            if (!CloseCurrentFile())
            {
                return;
            }
            if (fg != null)
            {
                ReplaceForegroundImage(gmllData, fg);
            }
            if (bg != null)
            {
                Images.ImageLoadResult imageInfo = new Images.ImageLoadResult(bg);
                BGImageLoad(null, imageInfo);
            }
            allBoxes.Load(boxes);
            metadataPropertyList.SelectedObject = metadata;
            ClearUnsavedChanges();
            SetTitleFileName(fileName);
            currentProjectFileName = fileName;
        }
Exemplo n.º 4
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);
 }