Esempio n. 1
0
        /// <summary>
        /// Assigns a LEM to the window.  If AssignKeyboard is true, it will search for a keyboard
        /// in the given CPU and assign it to this window as well.
        /// </summary>
        public LEM1802Window(LEM1802 LEM1802, DCPU CPU, bool AssignKeyboard)
            : base()
        {
            InitializeComponent();
            this.iad = new InvalidateAsyncDelegate(InvalidateAsync);
            startRecordingToolStripMenuItem.Tag = false;
            // Set up drawing
            this.SetStyle(ControlStyles.AllPaintingInWmPaint |
              ControlStyles.UserPaint | ControlStyles.Opaque, true);

            // Take a screen
            this.CPU = CPU;
            Screen = LEM1802;
            managedDevices = new Device[] { Screen };
            ScreenIndex = CPU.Devices.IndexOf(Screen);

            Keyboard = null;

            // Take a keyboard
            if (AssignKeyboard)
            {
                for (int i = 0; i < CPU.Devices.Count; i++)
                {
                    if (AssignedKeyboards.Contains(i))
                        continue;
                    if (CPU.Devices[i] is GenericKeyboard)
                    {
                        Keyboard = CPU.Devices[i] as GenericKeyboard;
                        managedDevices = managedDevices.Concat(new Device[] { Keyboard }).ToArray();
                        AssignedKeyboards.Add(i);
                        KeyboardIndex = i;
                        this.detatchKeyboardToolStripMenuItem.Visible = true;
                        break;
                    }
                }
            }
            this.KeyDown += new KeyEventHandler(LEM1802Window_KeyDown);
            this.KeyUp += new KeyEventHandler(LEM1802Window_KeyUp);
            if (this.Keyboard == null)
            {
                this.DragEnter += new DragEventHandler(LEM1802Window_DragEnter);
                this.DragDrop += new DragEventHandler(LEM1802Window_DragDrop);
                this.AllowDrop = true;
            }
            timer = new System.Threading.Timer(delegate(object o)
                {
                    InvalidateAsync();
                }, null, 16, 16); // 60 Hz
            InitClientSize();
        }
Esempio n. 2
0
 private void InvalidateAsync()
 {
     if (this.InvokeRequired)
     {
         try
         {
             InvalidateAsyncDelegate iad = new InvalidateAsyncDelegate(InvalidateAsync);
             this.Invoke(iad);
         }
         catch { }
     }
     else
     {
         this.Invalidate();
         this.Update();
     }
 }