Ejemplo n.º 1
0
        public RenderGameState2(/*CanvasControl canvas,*/ IZoomer zoomer, TextBlock leftScore, TextBlock rightScore)
        {
            //this.canvas = canvas ?? throw new ArgumentNullException(nameof(canvas));
            this.zoomer     = new Smoother(zoomer) ?? throw new ArgumentNullException(nameof(zoomer));
            this.leftScore  = leftScore ?? throw new ArgumentNullException(nameof(leftScore));
            this.rightScore = rightScore ?? throw new ArgumentNullException(nameof(rightScore));


            //bell = new MediaPlayer();
            //bell.Source = MediaSource.CreateFromUri(new Uri($"ms-appx:///Assets/bell.wav"));

            //var random = new Random();
            //for (int i = 0; i < 10; i++)
            //{
            //    var player = new MediaPlayer();
            //    player.Source = MediaSource.CreateFromUri(new Uri($"ms-appx:///Assets/hit{random.Next(1, 4)}.wav"));
            //    collisionSounds.AddLast(player);
            //}
        }
Ejemplo n.º 2
0
    /** BLOCKING - startup dir latency */
    public Filezoo(string dirname)
    {
        Selection = new Dictionary<string, bool> ();
        Renderer = new FSDraw ();

        clipboard = Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", true));

        SortField = SortFields[0];
        SizeField = SizeFields[0];
        Zoomer = new FlatZoomer ();

        Gdk.Colormap cm = Screen.RgbaColormap;
        if (cm != null && Screen.IsComposited) {
          Widget.DefaultColormap = cm;
          Colormap = cm;
          UseRgbaVisuals = true;
        }

        SetCurrentDir (dirname);

        Helpers.StartupProfiler.Time ("SetCurrentDir");

        CanFocus = true;
        KeyPressEvent += delegate (object o, KeyPressEventArgs args) {
          Cancelled = true;
          Gdk.ModifierType state = args.Event.State;
          switch (args.Event.Key) {
        case Gdk.Key.Control_L:
        case Gdk.Key.Control_R:
          state |= Gdk.ModifierType.ControlMask;
          break;
        case Gdk.Key.Shift_L:
        case Gdk.Key.Shift_R:
          state |= Gdk.ModifierType.ShiftMask;
          break;
        case Gdk.Key.Alt_L:
        case Gdk.Key.Alt_R:
          state |= Gdk.ModifierType.Mod1Mask;
          break;
          }
          SetCursor (state);
        };

        KeyReleaseEvent += delegate (object o, KeyReleaseEventArgs args) {
          Cancelled = true;
          if (args.Event.Key == Gdk.Key.Escape && Selection.Count > 0) {
        ClearSelection ();
        args.RetVal = true;
          } else if ((args.Event.State & Gdk.ModifierType.ControlMask) == Gdk.ModifierType.ControlMask) {
        switch (args.Event.Key) {
          case Gdk.Key.x:
            CutSelection(CurrentDirPath);
            break;
          case Gdk.Key.c:
            CopySelection(CurrentDirPath);
            break;
          case Gdk.Key.v:
            PasteSelection(CurrentDirPath);
            break;
        }
          } else {
        switch (args.Event.Key) {
          case Gdk.Key.Delete:
            TrashSelection ();
            break;
          case Gdk.Key.BackSpace:
            GoToParent ();
            break;
          case Gdk.Key.Home:
            SetCurrentDir (Helpers.HomeDir);
            break;
        }
          }
          Gdk.ModifierType state = args.Event.State;
          switch (args.Event.Key) {
        case Gdk.Key.Control_L:
        case Gdk.Key.Control_R:
          state &= ~Gdk.ModifierType.ControlMask;
          break;
        case Gdk.Key.Shift_L:
        case Gdk.Key.Shift_R:
          state &= ~Gdk.ModifierType.ShiftMask;
          break;
        case Gdk.Key.Alt_L:
        case Gdk.Key.Alt_R:
          state &= ~Gdk.ModifierType.Mod1Mask;
          break;
          }
          SetCursor (state);
        };

        DragDataGet += delegate (object o, DragDataGetArgs args) {
          string items = "file://" + DragSourcePath;
          if (Selection.Count > 0 && Selection.ContainsKey(DragSourcePath))
        items = GetSelectionData ();
          args.SelectionData.Set(args.SelectionData.Target, 8, System.Text.Encoding.UTF8.GetBytes(items));
          args.SelectionData.Text = items;
        };

        DragEnd += delegate {
          GetSelectionData ();
          Cancelled = true;
          dragInProgress = false;
          DragSourceEntry = null;
          DragSourcePath = null;
        };

        /** DESCTRUCTIVE */
        DragDataReceived += delegate (object sender, DragDataReceivedArgs e) {
          Cancelled = true;
          string targetPath = FindHit (Width, Height, e.X, e.Y, 8).Target.FullName;
          HandleSelectionData (e.SelectionData, e.Context.SuggestedAction, targetPath);
        };

        Gtk.Drag.DestSet (this, DestDefaults.All, target_table,
        Gdk.DragAction.Move
          | Gdk.DragAction.Copy
          | Gdk.DragAction.Ask
        );

        AddEvents((int)(
        Gdk.EventMask.ButtonPressMask
          | Gdk.EventMask.ButtonReleaseMask
          | Gdk.EventMask.ScrollMask
          | Gdk.EventMask.PointerMotionMask
          | Gdk.EventMask.EnterNotifyMask
          | Gdk.EventMask.KeyPressMask
          | Gdk.EventMask.KeyReleaseMask
          | Gdk.EventMask.LeaveNotifyMask
        ));

        ThreadStart ts = new ThreadStart (PreDrawCallback);
        Thread t = new Thread(ts);
        t.IsBackground = true;
        t.Start ();

        System.Timers.Timer t1 = new System.Timers.Timer(50);
        t1.Elapsed += new ElapsedEventHandler (CheckUpdates);
        System.Timers.Timer t2 = new System.Timers.Timer(1000);
        t2.Elapsed += new ElapsedEventHandler (LongMonitor);
        t1.Enabled = true;
        t2.Enabled = true;
        GLib.Timeout.Add (10, new GLib.TimeoutHandler(CheckRedraw));
        Helpers.StartupProfiler.Total ("Pre-drawing startup");
    }