Esempio n. 1
0
        public static System.Windows.Forms.MouseEventArgs ToWinFormArgs(MouseMoveEventArgs e, int x, int y)
        {
#if FAMISTUDIO_MACOS
            // The OpenTK mouse state isnt reliable and often has buttons getting "stuck"
            // especially after things like resizing the window. Bypass it.
            var buttons = MacUtils.GetMouseButtons();
#else
            System.Windows.Forms.MouseButtons buttons = System.Windows.Forms.MouseButtons.None;

            if (e.Mouse.LeftButton == ButtonState.Pressed)
            {
                buttons = System.Windows.Forms.MouseButtons.Left;
            }
            else if (e.Mouse.MiddleButton == ButtonState.Pressed)
            {
                buttons = System.Windows.Forms.MouseButtons.Middle;
            }
            else if (e.Mouse.RightButton == ButtonState.Pressed)
            {
                buttons = System.Windows.Forms.MouseButtons.Right;
            }
#endif

            return(new System.Windows.Forms.MouseEventArgs(buttons, 1, x, y, 0));
        }
Esempio n. 2
0
        private bool RunValidation()
        {
            if (ValidateProperties == null)
            {
                return(true);
            }

#if FAMISTUDIO_MACOS
            MacUtils.RemoveNSWindowAlwaysOnTop(MacUtils.NSWindowFromGdkWindow(GdkWindow.Handle));
#endif
            // Validation might display messages boxes, need to work around z-ordering issues.
            bool valid = ValidateProperties.Invoke(propertyPage);

#if FAMISTUDIO_MACOS
            // This fixes some super weird focus issues.
            if (!valid)
            {
                Hide();
                Show();
            }

            MacUtils.SetNSWindowAlwayOnTop(MacUtils.NSWindowFromGdkWindow(GdkWindow.Handle));
#endif

            return(valid);
        }
Esempio n. 3
0
        public System.Windows.Forms.DialogResult ShowDialog(FamiStudioForm parent)
        {
#if FAMISTUDIO_LINUX
            Run();
            Hide();
#else
            Show();

            if (WindowPosition == WindowPosition.CenterOnParent)
            {
                var mainWinRect = parent.Bounds;
                int x           = mainWinRect.Left + (mainWinRect.Width - Allocation.Width) / 2;
                int y           = mainWinRect.Top + (mainWinRect.Height - Allocation.Height) / 2;
                Move(x, y);
            }

            MacUtils.SetNSWindowAlwayOnTop(MacUtils.NSWindowFromGdkWindow(GdkWindow.Handle));

            while (result == System.Windows.Forms.DialogResult.None)
            {
                Application.RunIteration();
            }

            Hide();

            MacUtils.RestoreMainNSWindowFocus();
#endif

            return(result);
        }
Esempio n. 4
0
        public System.Windows.Forms.DialogResult ShowDialog(FamiStudioForm parent = null)
        {
#if FAMISTUDIO_MACOS
            Show();

            int x = parent.Bounds.Left + (parent.Bounds.Width - Allocation.Width) / 2;
            int y = parent.Bounds.Top + (parent.Bounds.Height - Allocation.Height) / 2;
            Move(x, y);
            MacUtils.SetNSWindowAlwayOnTop(MacUtils.NSWindowFromGdkWindow(GdkWindow.Handle));

            while (result == System.Windows.Forms.DialogResult.None)
            {
                Application.RunIteration();
            }

            Hide();

            MacUtils.RestoreMainNSWindowFocus();
#else
            Run();
            Hide();
#endif

            return(result);
        }
Esempio n. 5
0
        public System.Windows.Forms.DialogResult ShowDialog(FamiStudioForm parent = null)
        {
            Show();

            if (topAlign || leftAlign)
            {
                var pt = initialLocation;
                if (leftAlign)
                {
                    pt.X -= Allocation.Width;
                }
                if (topAlign)
                {
                    pt.Y -= Allocation.Height;
                }
                Move(pt.X, pt.Y);
            }

#if FAMISTUDIO_MACOS
            MacUtils.SetNSWindowAlwayOnTop(MacUtils.NSWindowFromGdkWindow(GdkWindow.Handle));
#endif

            while (result == System.Windows.Forms.DialogResult.None)
            {
                Application.RunIteration();
            }

            Hide();

#if FAMISTUDIO_MACOS
            MacUtils.RestoreMainNSWindowFocus();
#endif

            return(result);
        }
Esempio n. 6
0
        private static void ClearClipboardString()
        {
#if FAMISTUDIO_WINDOWS
            WinUtils.ClearClipboardString();
#elif FAMISTUDIO_MACOS
            MacUtils.ClearPasteboardString();
#endif
        }
Esempio n. 7
0
 public static void Initialize()
 {
     Default    = MacUtils.GetCursorByName("arrowCursor");
     SizeWE     = MacUtils.GetCursorByName("resizeLeftRightCursor");
     SizeNS     = MacUtils.GetCursorByName("resizeUpDownCursor");
     DragCursor = MacUtils.GetCursorByName("closedHandCursor");
     CopyCursor = MacUtils.GetCursorByName("dragCopyCursor");
     Eyedrop    = Default; // CreateCursorFromResource("EyedropCursor", 7, 24); Disabling for now, cant get hotspot to work.
 }
Esempio n. 8
0
        static byte[] linuxClipboardData; // Cant copy between FamiStudio instance on Linux.
#endif

        private static void SetClipboardDataInternal(byte[] data)
        {
#if FAMISTUDIO_WINDOWS
            WinUtils.SetClipboardData(data);
#elif FAMISTUDIO_MACOS
            MacUtils.SetPasteboardData(data);
#else
            linuxClipboardData = data;
#endif
        }
Esempio n. 9
0
        private static string GetClipboardString()
        {
#if FAMISTUDIO_WINDOWS
            return(WinUtils.GetClipboardString());
#elif FAMISTUDIO_MACOS
            return(MacUtils.GetPasteboardString());
#else
            return(null);
#endif
        }
Esempio n. 10
0
        public static void Initialize()
        {
            // When debugging or when in a app package, our paths are a bit different.
            string[] pathsToSearch =
            {
                "./Resources/",
                "../../Resources/",
                "../Resources/Fonts/",
                "."
            };

            string[] fontsToLoad =
            {
                "Quicksand-Regular.ttf",
                "Quicksand-Bold.ttf"
            };

            var appPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            foreach (var path in pathsToSearch)
            {
                var absPath = Path.Combine(appPath, path);

                if (File.Exists(Path.Combine(absPath, fontsToLoad[0])))
                {
                    foreach (var font in fontsToLoad)
                    {
                        var fullpath = Path.Combine(absPath, font);
#if FAMISTUDIO_MACOS
                        MacUtils.CoreTextRegisterFont(fullpath);
#else
                        try
                        {
                            FcConfigAppFontAddFile(IntPtr.Zero, fullpath);
                        }
                        catch
                        {
                            try { FcConfigAppFontAddFile1(IntPtr.Zero, fullpath); } catch { }
                        }
#endif
                    }
                    break;
                }
            }

#if FAMISTUDIO_LINUX
            Toolkit.Init(new ToolkitOptions
            {
                Backend = PlatformBackend.PreferX11,
                EnableHighResolution = false
            });
#endif

            InitializeGtk();
        }
Esempio n. 11
0
        public static string ShowSaveFileDialog(string title, string extensions, ref string defaultPath)
        {
            var extensionList = GetExtensionList(extensions);

            var filename = MacUtils.ShowSaveDialog(title, extensionList, defaultPath);

            if (!string.IsNullOrEmpty(filename))
            {
                defaultPath = Path.GetDirectoryName(filename);
            }
            return(filename);
        }
Esempio n. 12
0
        public static string[] ShowOpenFileDialog(string title, string extensions, ref string defaultPath, bool multiselect, Window parentWindow = null)
        {
            var extensionList = GetExtensionList(extensions);

            var filenames = MacUtils.ShowOpenDialog(title, extensionList, multiselect, defaultPath);

            if (filenames != null && !string.IsNullOrEmpty(filenames[0]))
            {
                defaultPath = Path.GetDirectoryName(filenames[0]);
            }
            return(filenames);
        }
Esempio n. 13
0
        public static string ShowSaveFileDialog(string title, string extensions, ref string defaultPath)
        {
            var extensionList = GetExtensionList(extensions);

#if FAMISTUDIO_MACOS
            var filename = MacUtils.ShowSaveDialog(title, extensionList, defaultPath);
            if (!string.IsNullOrEmpty(filename))
            {
                defaultPath = Path.GetDirectoryName(filename);
            }
            return(filename);
#else
            Gtk.FileChooserDialog filechooser =
                new Gtk.FileChooserDialog(title,
                                          null,
                                          FileChooserAction.Save,
                                          "Cancel", ResponseType.Cancel,
                                          "Save", ResponseType.Accept);

            filechooser.KeepAbove       = true;
            filechooser.Modal           = true;
            filechooser.SkipTaskbarHint = true;
            filechooser.TransientFor    = FamiStudioForm.Instance;
            filechooser.SetCurrentFolder(defaultPath);

            filechooser.Filter = new FileFilter();
            foreach (var ext in extensionList)
            {
                filechooser.Filter.AddPattern($"*.{ext}");
            }

            string filename = null;
            if (filechooser.Run() == (int)ResponseType.Accept)
            {
                filename = filechooser.Filename;

                // GTK file chooser does not add the extension automatically.
                var extension        = Path.GetExtension(filename).ToLower();
                var desiredExtension = $".{extensionList[0]}";

                if (extension != desiredExtension)
                {
                    filename = Path.ChangeExtension(filename, desiredExtension);
                }

                defaultPath = Path.GetDirectoryName(filename);
            }

            filechooser.Destroy();

            return(filename);
#endif
        }
Esempio n. 14
0
        private static IntPtr CreateCursorFromResource(string name, int x, int y)
        {
            var suffix       = GLTheme.MainWindowScaling > 1 ? "@2x" : "";
            var hotSpotScale = GLTheme.MainWindowScaling > 1 ? 2 : 1;

            using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream($"FamiStudio.Resources.{name}{suffix}.png"))
            {
                var buffer = new byte[stream.Length];
                stream.Read(buffer, 0, buffer.Length);

                return(MacUtils.CreateCursorFromImage(buffer, x * hotSpotScale, y * hotSpotScale));
            }
        }
Esempio n. 15
0
        public void UpdateModalEvents()
        {
            if (result != System.Windows.Forms.DialogResult.None)
            {
                Hide();

#if FAMISTUDIO_MACOS
                MacUtils.RestoreMainNSWindowFocus();
#endif
            }

            Application.RunIteration(false);
        }
Esempio n. 16
0
        public static string ShowOpenFileDialog(string title, string extensions, ref string defaultPath, Window parentWindow = null)
        {
            var extensionList = GetExtensionList(extensions);

#if FAMISTUDIO_MACOS
            var filename = MacUtils.ShowOpenDialog(title, extensionList, defaultPath);
            if (!string.IsNullOrEmpty(filename))
            {
                defaultPath = Path.GetDirectoryName(filename);
            }
            return(filename);
#else
            Gtk.Rc.ResetStyles(Gtk.Settings.GetForScreen(Gdk.Screen.Default));
            Gtk.Rc.ReparseAll();

            Gtk.FileChooserDialog filechooser =
                new Gtk.FileChooserDialog(title,
                                          null,
                                          FileChooserAction.Open,
                                          "Cancel", ResponseType.Cancel,
                                          "Open", ResponseType.Accept);

            filechooser.KeepAbove       = true;
            filechooser.Modal           = true;
            filechooser.SkipTaskbarHint = true;
            filechooser.TransientFor    = parentWindow != null ? parentWindow : FamiStudioForm.Instance;
            filechooser.SetCurrentFolder(defaultPath);

            if (extensionList.Length > 0)
            {
                filechooser.Filter = new FileFilter();
                foreach (var ext in extensionList)
                {
                    filechooser.Filter.AddPattern($"*.{ext}");
                }
            }

            string filename = null;
            if (filechooser.Run() == (int)ResponseType.Accept)
            {
                filename    = filechooser.Filename;
                defaultPath = Path.GetDirectoryName(filename);
            }

            filechooser.Destroy();

            return(filename);
#endif
        }
Esempio n. 17
0
        public void ShowModal(FamiStudioForm parent = null)
        {
            Show();

#if FAMISTUDIO_MACOS
            if (WindowPosition == WindowPosition.CenterOnParent)
            {
                var mainWinRect = parent.Bounds;
                int x           = mainWinRect.Left + (mainWinRect.Width - Allocation.Width) / 2;
                int y           = mainWinRect.Top + (mainWinRect.Height - Allocation.Height) / 2;
                Move(x, y);
            }

            MacUtils.SetNSWindowAlwayOnTop(MacUtils.NSWindowFromGdkWindow(GdkWindow.Handle));
#endif
        }
Esempio n. 18
0
        private static unsafe Gdk.Cursor CreateMacOSNamedCursor(string name)
        {
            var nsCursor  = MacUtils.GetCursorByName(name);
            var gdkCursor = new Gdk.Cursor(Gdk.CursorType.Cross);

            // HACK : Patch the Gdk internal struct with our NSCursor.
            // struct is :
            //   - 4 byte type
            //   - 4 byte ref count
            //   - 8 bytes NSCursor pointer.
            IntPtr *p = (IntPtr *)gdkCursor.Handle.ToPointer();

            p[1] = nsCursor;

            return(gdkCursor);
        }
Esempio n. 19
0
        public System.Windows.Forms.DialogResult ShowDialog(FamiStudioForm parent)
        {
            Show();

            if (topAlign || leftAlign)
            {
                Debug.Assert(WindowPosition == WindowPosition.None);

                var pt = initialLocation;
                if (leftAlign)
                {
                    pt.X -= Allocation.Width;
                }
                if (topAlign)
                {
                    pt.Y -= Allocation.Height;
                }
                Move(pt.X, pt.Y);
            }

#if FAMISTUDIO_MACOS
            if (WindowPosition == WindowPosition.CenterOnParent)
            {
                var mainWinRect = parent.Bounds;
                int x           = mainWinRect.Left + (mainWinRect.Width - Allocation.Width) / 2;
                int y           = mainWinRect.Top + (mainWinRect.Height - Allocation.Height) / 2;
                Move(x, y);
            }

            MacUtils.SetNSWindowAlwayOnTop(MacUtils.NSWindowFromGdkWindow(GdkWindow.Handle));
#endif

            while (result == System.Windows.Forms.DialogResult.None)
            {
                Application.RunIteration();
            }

            Hide();

#if FAMISTUDIO_MACOS
            MacUtils.RestoreMainNSWindowFocus();
#endif

            return(result);
        }
Esempio n. 20
0
        public static string ShowBrowseFolderDialog(string title, ref string defaultPath)
        {
            var filename = MacUtils.ShowBrowseFolderDialog(title, ref defaultPath);

            if (!string.IsNullOrEmpty(filename))
            {
                if (Directory.Exists(filename))
                {
                    defaultPath = filename;
                }
                else
                {
                    defaultPath = Path.GetDirectoryName(filename);
                }
                return(defaultPath);
            }
            return(null);
        }
Esempio n. 21
0
        private static byte[] GetClipboardDataInternal(uint magic, int maxSize = int.MaxValue)
        {
            byte[] buffer = null;
#if FAMISTUDIO_WINDOWS
            buffer = WinUtils.GetClipboardData(maxSize);
#elif FAMISTUDIO_MACOS
            buffer = MacUtils.GetPasteboardData();
#else
            buffer = linuxClipboardData;
#endif

            if (buffer == null || BitConverter.ToUInt32(buffer, 0) != magic)
            {
                return(null);
            }

            return(buffer);
        }
Esempio n. 22
0
        public static string ShowBrowseFolderDialog(string title, ref string defaultPath)
        {
#if FAMISTUDIO_MACOS
            var filename = MacUtils.ShowBrowseFolderDialog(title, defaultPath);
            if (!string.IsNullOrEmpty(filename))
            {
                if (Directory.Exists(filename))
                {
                    defaultPath = filename;
                }
                else
                {
                    defaultPath = Path.GetDirectoryName(filename);
                }
                return(defaultPath);
            }
            return(null);
#else
            Gtk.FileChooserDialog filechooser =
                new Gtk.FileChooserDialog("Choose the file to save",
                                          null,
                                          FileChooserAction.Save,
                                          "Cancel", ResponseType.Cancel,
                                          "Save", ResponseType.Accept);

            filechooser.KeepAbove       = true;
            filechooser.Modal           = true;
            filechooser.Action          = FileChooserAction.SelectFolder;
            filechooser.SkipTaskbarHint = true;
            filechooser.TransientFor    = FamiStudioForm.Instance;
            filechooser.SetCurrentFolder(defaultPath);

            string filename = null;
            if (filechooser.Run() == (int)ResponseType.Accept)
            {
                filename    = filechooser.Filename;
                defaultPath = Path.GetDirectoryName(filename);
            }

            filechooser.Destroy();

            return(filename);
#endif
        }
Esempio n. 23
0
        public System.Windows.Forms.DialogResult ShowDialog()
        {
            Show();
#if FAMISTUDIO_MACOS
            MacUtils.SetNSWindowAlwayOnTop(MacUtils.NSWindowFromGdkWindow(GdkWindow.Handle));
#endif

            while (result == System.Windows.Forms.DialogResult.None)
            {
                Application.RunIteration();
            }

            Hide();
#if FAMISTUDIO_MACOS
            MacUtils.RestoreMainNSWindowFocus();
#endif

            return(result);
        }
Esempio n. 24
0
        public static void Initialize()
        {
            // When debugging or when in a app package, our paths are a bit different.
            string[] pathsToSearch =
            {
                "../../Resources/",
                "../Resources/Fonts/"
            };

            string[] fontsToLoad =
            {
                "Quicksand-Regular.ttf",
                "Quicksand-Bold.ttf"
            };

            var appPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            foreach (var path in pathsToSearch)
            {
                var absPath = Path.Combine(appPath, path);

                if (File.Exists(Path.Combine(absPath, fontsToLoad[0])))
                {
                    foreach (var font in fontsToLoad)
                    {
                        var fullpath = Path.Combine(absPath, font);
                        MacUtils.CoreTextRegisterFont(fullpath);
                    }
                    break;
                }
            }

            Gtk.Application.Init();

            using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("FamiStudio.Resources.gtk.rc"))
                using (var reader = new StreamReader(stream))
                {
                    string gtkrc = reader.ReadToEnd();
                    Gtk.Rc.ParseString(gtkrc);
                }
        }
Esempio n. 25
0
        public static string ShowOpenFileDialog(string title, string extensions)
        {
            var extensionList = GetExtensionList(extensions);

#if FAMISTUDIO_MACOS
            return(MacUtils.ShowOpenDialog(title, extensionList));
#else
            Gtk.Rc.ResetStyles(Gtk.Settings.GetForScreen(Gdk.Screen.Default));
            Gtk.Rc.ReparseAll();

            Gtk.FileChooserDialog filechooser =
                new Gtk.FileChooserDialog("Choose the file to open",
                                          null,
                                          FileChooserAction.Open,
                                          "Cancel", ResponseType.Cancel,
                                          "Open", ResponseType.Accept);

            filechooser.KeepAbove       = true;
            filechooser.Modal           = true;
            filechooser.SkipTaskbarHint = true;

            filechooser.Filter = new FileFilter();
            foreach (var ext in extensionList)
            {
                filechooser.Filter.AddPattern($"*.{ext}");
            }

            string filename = null;
            if (filechooser.Run() == (int)ResponseType.Accept)
            {
                filename = filechooser.Filename;
            }

            ProcessPendingEvents();
            filechooser.Destroy();
            ProcessPendingEvents();

            return(filename);
#endif
        }
Esempio n. 26
0
        public static DialogResult MessageBox(string text, string title, MessageBoxButtons buttons, MessageBoxIcon icon = MessageBoxIcon.None)
        {
#if FAMISTUDIO_MACOS
            return(MacUtils.ShowAlert(text, title, buttons));
#else
            if (buttons == MessageBoxButtons.YesNoCancel)
            {
                buttons = MessageBoxButtons.YesNo;
                text   += " (Close or ESC to cancel)";
            }

            MessageDialog md = new MessageDialog(null,
                                                 DialogFlags.Modal | DialogFlags.DestroyWithParent,
                                                 icon == MessageBoxIcon.Error ? MessageType.Error : MessageType.Info,
                                                 buttons == MessageBoxButtons.YesNo ? ButtonsType.YesNo : ButtonsType.Ok, text);

            md.KeepAbove       = true;
            md.Modal           = true;
            md.SkipTaskbarHint = true;
            md.TypeHint        = Gdk.WindowTypeHint.Dialog;
            md.Title           = title;

            int ret = md.Run();

            ProcessPendingEvents();
            md.Destroy();
            ProcessPendingEvents();

            if (buttons == MessageBoxButtons.YesNo)
            {
                return(ret == -8 ? DialogResult.Yes : ret == -9 ? DialogResult.No : DialogResult.Cancel);
            }
            else
            {
                return(DialogResult.OK);
            }
#endif
        }
Esempio n. 27
0
        public static void Initialize()
        {
            mainThread = Thread.CurrentThread;

            // When debugging or when in a app package, our paths are a bit different.
            string[] pathsToSearch =
            {
                "./Resources/",
                "../../Resources/",
                "../Resources/Fonts/",
                "."
            };

            string[] fontsToLoad =
            {
                "Quicksand-Regular.ttf",
                "Quicksand-Bold.ttf"
            };

            var appPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            foreach (var path in pathsToSearch)
            {
                var absPath = Path.Combine(appPath, path);

                if (File.Exists(Path.Combine(absPath, fontsToLoad[0])))
                {
                    foreach (var font in fontsToLoad)
                    {
                        MacUtils.CoreTextRegisterFont(Path.Combine(absPath, font));
                    }
                    break;
                }
            }

            InitializeGtk();
        }
Esempio n. 28
0
        public System.Windows.Forms.DialogResult ShowDialog()
        {
            Show();

            if (topAlign || leftAlign)
            {
                GetPosition(out var x, out var y);
                if (leftAlign)
                {
                    x -= Allocation.Width;
                }
                if (topAlign)
                {
                    y -= Allocation.Height;
                }
                Move(x, y);
            }

#if FAMISTUDIO_MACOS
            MacUtils.SetNSWindowAlwayOnTop(MacUtils.NSWindowFromGdkWindow(GdkWindow.Handle));
#endif

            while (result == System.Windows.Forms.DialogResult.None)
            {
                Application.RunIteration();
            }

            Hide();

#if FAMISTUDIO_MACOS
            MacUtils.RestoreMainNSWindowFocus();
#else
            PlatformUtils.ProcessPendingEvents();
#endif

            return(result);
        }
Esempio n. 29
0
 public static DialogResult MessageBox(string text, string title, MessageBoxButtons buttons, MessageBoxIcon icons = MessageBoxIcon.None)
 {
     return(MacUtils.ShowAlert(text, title, buttons));
 }
Esempio n. 30
0
 public static string ShowSaveFileDialog(string title, string extensions)
 {
     return(MacUtils.ShowSaveDialog(title, GetExtensionList(extensions)));
 }