Наследование: IDisposable
Пример #1
0
        public static void Main(string[] args)
        {
            using (var nav = new Navigator ())
            using (var ctx = Context.GetInstance (ContextType.Application))
            using (var win = new Window (ctx, WindowType.SCREEN_APPLICATION_WINDOW)) {
                win.AddBuffers (10);
                win.Identifier = "bla";
                var r = new Random();
                foreach (var b in win.Buffers) {
                    b.Fill ((uint)r.Next ());
                    win.Render (b);
                    System.Threading.Thread.Sleep (200);
                }
                //nav.AddUri ("", "Browser", "default", "http://google.com/");
                //nav.AddUri ("", "Messages", "default", "messages://");
                //return;

                var run = true;
                while (run) {
                    Dialog.Alert ("CLOSE ME!", "jpo1jo1j1oj1oj1",
                                  //new Button ("Timer", Timer),
                                  //new Button ("Camera", Cam),
                                  //new Button ("Messages", () => nav.Invoke ("messages://")),
                                  new Button ("Badge", () => nav.HasBadge = true),
                                  new Button ("Browser", () => nav.Invoke ("http://google.com/")),
                                  new Button ("Close", () => run = false));
                }
            }
        }
Пример #2
0
        public static void Main(string[] args)
        {
            using (var nav = new Navigator ())
            using (var ctx = new Context ())
            using (var win = new Window (ctx)) {
                win.Usage = Usage.SCREEN_USAGE_NATIVE;
                win.AddBuffers (2);
                var bufs = win.Buffers;
                var pic = bufs[0];
                var brush = bufs[1];

                pic.Fill (0xffff0000);
                brush.Fill (0xff000000);
                win.Render (pic);

                //nav.OnSwipeDown = () => Dialog.Alert ("#MonoBerry", "Another Event Loop", new Button ("Ack"));
                ctx.OnFingerTouch = (x,y) => {
                    pic.Blit (brush, 0, 0, 10, 10, Math.Max (x - 5, 0), Math.Max (y - 5, 0));
                    win.Render (pic);
                };
                ctx.OnFingerMove = ctx.OnFingerTouch;
                ctx.OnFingerRelease = ctx.OnFingerTouch;

                PlatformServices.Run ();
            }
        }
Пример #3
0
        public void Run()
        {
            using (var nav = new Navigator ()) {
                try {
                    nav.SetOrientation (Navigator.ScreenOrientation.Landscape);
                } catch (Exception e) {
                    Console.WriteLine ("ScreenOrientation Error: {0}\n{1}", e.Message, e.StackTrace);
                }
                try {
                    nav.SetOrientation (Navigator.ApplicationOrientation.TopUp);
                } catch (Exception e) {
                    Console.WriteLine ("ApplicationOrientation Error: {0}\n{1}", e.Message, e.StackTrace);
                }
                try {
                    nav.OrientationLock = true;
                } catch (Exception e) {
                    Console.WriteLine ("OrientationLock Error: {0}\n{1}", e.Message, e.StackTrace);
                }
                using (var ctx = Context.GetInstance (ContextType.Application))
                using (window = new Window (ctx)) {
                    window.KeepAwake = true;
                    window.AddBuffer ();
                    buffer = window.Buffers [0];
                    width = window.Width;
                    height = window.Height;
                    graphics = Graphics.FromImage (buffer.Bitmap);

                    SoundPlayer.Prepare (SoundPlayer.SystemSound.AlarmBattery);

                    msecsLeft = LIGHTNING_TALK_TIME;
                    timer = new System.Timers.Timer ();
                    timer.AutoReset = true;
                    timer.Interval = 100;
                    timer.Elapsed += (sender, e) => {
                        msecsLeft -= 100;
                        if (msecsLeft <= 0) {
                            timer.Enabled = false;
                            SoundPlayer.Play (SoundPlayer.SystemSound.AlarmBattery);
                        }
                        RenderSlide ();
                    };

                    nav.OnSwipeDown = () =>
                        Dialog.Alert ("Lightning Talk",
                            "Add slides as *.jpg files to your ‘documents’ folder or a subdirectory. " +
                            "Touch screen or use a bluetooth remote to switch slides.\n\n" +
                            "©2013 by @roblillack.\nLicensed under the MIT license.",
                            new Button ("Countdown 5 mins", () => {
                      			msecsLeft = LIGHTNING_TALK_TIME;
                                timer.Enabled = true;
                            }),
                            new Button ("Show Source Code", () =>
                                nav.Invoke ("http://github.com/roblillack/lightning-talk")));

                    ctx.OnFingerTouch = (x, y) => {
                        if (x < window.Width / 2) {
                            PreviousSlide ();
                        } else {
                            NextSlide ();
                        }
                    };
                    ctx.OnKeyDown = (code, _) => {
                        if (code == KeyCode.Up) {
                            PreviousSlide ();
                        } else {
                            NextSlide ();
                        }
                    };

                    nav.OnExit = () => {
                        PlatformServices.Shutdown (0);
                    };

                    renderThread = new Thread (RenderLoop);
                    renderThread.Start ();

                    DirectoryInfo dirInfo = new DirectoryInfo ("shared/documents");
                    images = new ImageCache (dirInfo.GetFiles ("*.jpg", SearchOption.AllDirectories), new Size (width, height));
                    if (images.Length == 0) {
                        Dialog.Alert ("Lightning Talk",
                                      "No presentation slides found! Please add *.jpg files to your ‘documents’ folder or a subdirectory!",
                                      new Button ("Quit", () => PlatformServices.Shutdown (0)));
                    }

                    RenderSlide ();

                    PlatformServices.Run ();
                    System.Console.WriteLine ("Event handler stopped. WTH?");
                    PlatformServices.Shutdown (1);
                }
            }
        }
Пример #4
0
 public Buffer(Context ctx, Window win, IntPtr hndl)
 {
     context = ctx;
     window = win;
     handle = hndl;
 }
Пример #5
0
 internal void UnregisterWindow(Window win)
 {
     windows.Remove (win.Handle);
 }
Пример #6
0
 internal void RegisterWindow(Window win)
 {
     windows.Add (win.Handle, win);
 }
Пример #7
0
        public static void Main(string[] args)
        {
            using (var nav = new Navigator ())
            using (var ctx = Context.GetInstance (ContextType.Application))
            using (var win = new Window (ctx)) {
                win.AddBuffers (2);
                var bufs = win.Buffers;
                var buffer = bufs [0];
                var brush = bufs [1];
                var queue = new BlockingCollection<Point> ();

                buffer.Fill (WHITE);
                brush.Fill (BLACK);
                win.Render (buffer);

                var paintThread = new Thread (() => {
                    for (;;) {
                        Point point;
                        Rectangle dirty;
                        int taken;
                        for (taken = 0; taken < 10 && queue.TryTake (out point); taken++) {
                            var dst_x = Math.Min (win.Width - 10, point.X);
                            var dst_y = Math.Min (win.Height - 10, point.Y);
                            try {
                                buffer.Blit (brush, 0, 0, 10, 10, dst_x, dst_y);
                            } catch (Exception e) {
                                Console.WriteLine (e.Message);
                            }
                            if (taken == 0) {
                                dirty = new Rectangle (dst_x, dst_y, 10, 10);
                            } else {
                                dirty.X = Math.Min (dirty.Left, dst_x);
                                dirty.Width = Math.Max (dirty.Width, (dst_x + 10) - dirty.X);
                                dirty.Y = Math.Min (dirty.Top, dst_y);
                                dirty.Height = Math.Max (dirty.Height, (dst_y + 10) - dirty.Y);
                            }
                        }
                        if (taken < 1) {
                            continue;
                        }
                        //Console.WriteLine ("Blitted {0} times before rendering", taken);
                        try {
                            win.Render (buffer, dirty, Flushing.SCREEN_WAIT_IDLE);
                        } catch (Exception e) {
                            Console.WriteLine (e.Message);
                        }
                    }
                });
                paintThread.Start ();

                nav.OnSwipeDown = () => Dialog.Alert ("#MonoBerry", "Mem: " + GC.GetTotalMemory (false),
                                                      new Button ("White", () => {
                    try {
                        buffer.Fill (WHITE);
                        win.Render (buffer);
                    } catch (Exception e) {
                        Console.WriteLine (e.Message);
                    }
                }),
                                                      new Button ("Red", () => {
                    try {
                        buffer.Fill (RED);
                        win.Render (buffer);
                    } catch (Exception e) {
                        Console.WriteLine (e.Message);
                    }
                }));
                win.OnCreate = () => Console.WriteLine ("win created.");
                win.OnClose = () => Console.WriteLine ("win closed.");
                ctx.OnFingerTouch = (x,y) => {
                    queue.Add (new Point (x, y));
                };
                ctx.OnFingerMove = ctx.OnFingerTouch;
                ctx.OnFingerRelease = ctx.OnFingerTouch;

                nav.OnExit = () => {
                    Console.WriteLine ("I am asked to shutdown!?!");
                    PlatformServices.Shutdown (0);
                };
                PlatformServices.Run ();
                Console.WriteLine ("Event handler stopped. WTH?");
                PlatformServices.Shutdown (1);
            }
        }