Ejemplo n.º 1
0
        private bool OnTimedDraw()
        {
            bool draw = false;


            lock (_window)
            {
                if (!_isDrawing)
                {
                    _isDrawing = true;
                    draw       = true;
                }
            }

            if (draw)
            {
                int w, h;

                _pixmap.GetSize(out w, out h);

                bool screenChanged = w != _oldWidth || h != _oldHeight;

                Gdk.GC gc = new Gdk.GC(_pixmap);
                _pixmap.DrawRectangle(gc, true, 0, 0, w, h);


                using (Context context = Gdk.CairoHelper.Create(_pixmap))
                {
#if DRAWGRID
                    context.Color = _gridColor;

                    int ew = w / 8;
                    int eh = h / 7;

                    for (int i = 0; i < 9; i++)
                    {
                        int x = i * ew + _anime % ew;

                        context.MoveTo(x, 0);
                        context.LineTo(x, h);
                        context.Stroke();
                    }
                    for (int j = 0; j < 8; j++)
                    {
                        int y = j * eh + _anime % eh;

                        context.MoveTo(0, y);
                        context.LineTo(w, y);
                        context.Stroke();
                    }
#endif

                    try
                    {
                        Cairo.Context g = Gdk.CairoHelper.Create(_pixmap);

                        State.Draw(_pixmap, g, w, h, screenChanged);

                        if (MessageBox != null)
                        {
                            MessageBox.Draw(_pixmap, g, w, h, screenChanged);
                        }

                        ((IDisposable)g.Target).Dispose();
                        ((IDisposable)g).Dispose();
                    }
                    catch (Exception e)
                    {
                        HandleFatalException(e, " experienced while attempting to run State.Draw()");
                    }
                }

                lock (_window)
                {
                    _isDrawing = false;
                }
            }

            _window.GetSize(out _oldWidth, out _oldHeight);
            _window.QueueDrawArea(0, 0, _oldWidth, _oldHeight);

            return(true);
        }