示例#1
0
        // Load a PanelAnimation from disk.
        private static void LoadSavedAnimationType(int pad, SMX.SMX.LightsType type)
        {
            byte[] gif = ReadSavedAnimationType(pad, type);
            string error;

            SMX.SMX.LightsAnimation_Load(gif, pad, type, out error);
        }
示例#2
0
        public static void SaveAnimationToDisk(int pad, SMX.SMX.LightsType type, byte[] data)
        {
            string filename = LightsTypeNames[type] + ".gif";
            string path     = "Animations/Pad" + (pad + 1) + "/" + filename;

            Helpers.SaveFileToSettings(path, data);
        }
示例#3
0
        // Read a saved PanelAnimation.
        //
        // Data will always be returned.  If the user hasn't saved anything, we'll return
        // our default animation.
        private static byte[] ReadSavedAnimationType(int pad, SMX.SMX.LightsType type)
        {
            string filename = LightsTypeNames[type] + ".gif";
            string path     = "Animations/Pad" + (pad + 1) + "/" + filename;

            byte[] gif = Helpers.ReadFileFromSettings(path);
            if (gif == null)
            {
                // If the user has never loaded a file, load our default.
                Uri url = new Uri("pack://application:,,,/Resources/" + filename);
                StreamResourceInfo info = Application.GetResourceStream(url);
                gif = new byte[info.Stream.Length];
                info.Stream.Read(gif, 0, gif.Length);
            }
            return(gif);
        }
        private void LoadGIF(object sender, RoutedEventArgs e)
        {
            // If the "load idle GIF" button was pressed, load the released animation.
            // Otherwise, load the pressed animation.
            bool pressed = sender == this.LoadPressed;

            // Prompt for a file to read.
            Microsoft.Win32.OpenFileDialog dialog = new Microsoft.Win32.OpenFileDialog();
            dialog.FileName   = "Select an animated GIF";
            dialog.DefaultExt = ".gif";
            dialog.Filter     = "Animated GIF (.gif)|*.gif";
            bool?result = dialog.ShowDialog();

            if (result == null || !(bool)result)
            {
                return;
            }

            byte[]             buf  = Helpers.ReadBinaryFile(dialog.FileName);
            SMX.SMX.LightsType type = pressed ? SMX.SMX.LightsType.LightsType_Pressed : SMX.SMX.LightsType.LightsType_Released;

            foreach (Tuple <int, SMX.SMXConfig> activePad in ActivePad.ActivePads())
            {
                int pad = activePad.Item1;

                // Load the animation.
                string error;
                if (!SMX.SMX.LightsAnimation_Load(buf, pad, type, out error))
                {
                    // Any errors here are problems with the GIF, so there's no point trying
                    // to load it for the second pad if the first returns an error.  Just show the
                    // error and stop.
                    MessageBox.Show(error, "Error", MessageBoxButton.OK, MessageBoxImage.Warning);

                    // Return without saving to settings on error.
                    return;
                }

                // Save the GIF to disk so we can load it quickly later.
                Helpers.SaveAnimationToDisk(pad, type, buf);

                // Refresh after loading a GIF to update the "Leave this application running" text.
                CurrentSMXDevice.singleton.FireConfigurationChanged(null);
            }

            // For firmwares that support it, upload the animation to the pad now.  Otherwise,
            // we'll run the animation directly.
            foreach (Tuple <int, SMX.SMXConfig> activePad in ActivePad.ActivePads())
            {
                int pad = activePad.Item1;

                SMX.SMXConfig config;
                if (!SMX.SMX.GetConfig(pad, out config))
                {
                    continue;
                }

                if (config.masterVersion >= 4)
                {
                    UploadLatestGIF();
                }

                break;
            }
        }