Пример #1
0
        protected override bool OnConfigureEvent(EventConfigure ev)
        {
            if (surface != null)
            {
                surface.Dispose();
            }

            surface = ev.Window.CreateSimilarSurface(Cairo.Content.Color, AllocatedWidth, AllocatedHeight);
            ClearSurface();
            return(true);
        }
Пример #2
0
        protected void placeShapes()
        {
            if (_surface != null)
            {
                drawingArea.GdkWindow.Clear();
                _surface.Dispose();
                _surface = null;
            }

            _min = Vertex.CreateMax();
            _max = Vertex.CreateMin();

            foreach (AbstractShape shape in _shapes)
            {
                _min.Minimize(shape.Min);
                _max.Maximize(shape.Max);
                log("фигура {0} расположена на позиции от {1} до {2}", shape, shape.Min.Literal, shape.Max.Literal);
            }

            _min            -= _lineWidthGap;
            _max            += _lineWidthGap;
            _logicCanvasSize = _max - _min;
            log("размер логического холста (с учётом толщины линий) - {0}", _logicCanvasSize.Literal);
            _logicCanvasSize *= _prescale;
            _surface          = new Cairo.ImageSurface(Cairo.Format.Argb32, ( int )_logicCanvasSize.X, ( int )_logicCanvasSize.Y);

            using (var surfaceContext = new Cairo.Context(_surface)) {
                surfaceContext.SetSourceRGB(1.0, 1.0, 1.0);
                surfaceContext.Paint();
                surfaceContext.LineWidth = 1.0;
                surfaceContext.SetSourceRGB(.0, .0, .0);
                surfaceContext.Scale(_prescale, -_prescale);
                surfaceContext.Translate(-_min.X, -_max.Y);

                if (null != _shapes && 0 < _shapes.Count)
                {
                    foreach (AbstractShape shape in _shapes)
                    {
                        shape.Draw(surfaceContext);
                        surfaceContext.Stroke();
                    }
                }
            }
        }
        // Create a new surface of the appropriate size to store our scribbles
        private void ScribbleConfigure(object o, ConfigureEventArgs args)
        {
            Widget widget = o as Widget;

            if (surface != null)
            {
                surface.Dispose();
            }

            var allocation = widget.Allocation;

            surface = widget.Window.CreateSimilarSurface(Cairo.Content.Color, allocation.Width, allocation.Height);
            var cr = new Cairo.Context(surface);

            cr.SetSourceRGB(1, 1, 1);
            cr.Paint();
            ((IDisposable)cr).Dispose();

            // We've handled the configure event, no need for further processing.
            args.RetVal = true;
        }