Beispiel #1
0
        /// <summary>
        /// Creates a bitmap for each character in the font.
        /// Characters that the font does not include will not be assigned a bitmap.
        /// </summary>
        private void CreateBitmaps()
        {
            characters = new Dictionary <char, PixelSet>();
            ImageSurface surface = new ImageSurface(Format.RGB24, 1, 1);
            Context      context = new Context(surface);

            context.SelectFontFace(FontName, FontSlant.Normal, FontWeight.Normal);
            context.SetFontSize(Font.Size);
            TextExtents ext   = context.TextExtents("@");
            int         charW = (int)Math.Ceiling(ext.Width);
            int         charH = (int)Math.Ceiling(ext.Height);

            context.Dispose();
            surface.Dispose();

            surface = new ImageSurface(Format.RGB24, charW, charH);
            context = new Context(surface);
            PixelSet missingChar = null;

            for (int i = 0; i < asciiString.Length; i++)
            {
                // Render one character into a PixelSet
                string asciiChar = string.Empty + asciiString[i];
                context.SelectFontFace(FontName, FontSlant.Normal, FontWeight.Normal);
                context.SetFontSize(Font.Size);
                context.SetSourceRGB(0.067, 0.067, 0.067);
                context.Paint();
                context.SetSourceRGB(1, 1, 1);
                ext = context.TextExtents(asciiChar);
                context.MoveTo(ext.XBearing, ext.YBearing * -1);
                context.ShowText(asciiChar);
                PixelSet ch = new PixelSet(surface);

                // Filter out characters the font doesn't include
                // The first character is always unprintable, and serves as
                // a reference for what unprintable characters look like in this font
                if (i == 0)
                {
                    missingChar = ch;
                    continue;
                }
                else if (ch == missingChar)
                {
                    continue;
                }
                characters.Add(asciiString[i], ch);
            }
            context.Dispose();
            surface.Dispose();

            // Add the space manually if it wasn't included
            if (!characters.ContainsKey(' '))
            {
                var en = characters.Values.GetEnumerator();
                en.MoveNext();
                characters.Add(' ', new PixelSet(en.Current.Width, en.Current.Height));
            }
        }
Beispiel #2
0
        public override void Draw(Cairo.Context surface, int x, int y)
        {
            X = x;
            Y = y;
            int waveTops    = Radius / 3;
            int waveBottoms = Radius / 2;
            int waveDepths  = Radius / 6;

            WaterTemperature = CurrentData.GetCurrentValueByIdFloat(XIVELY_DATA_STREAM_ID);
            //WaterTemperature = WaterTemperature / 100;


            // CIRCLE
            surface.SetSourceRGBA(1, 1, 1, 0.3);
            surface.Arc(X, Y, Radius, 0, Math.PI * 2);
            surface.Fill();

            surface.SetSourceRGBA(1, 1, 1, WaterLight);
            surface.Arc(X, Y, Radius + 5, 0, Math.PI * 2);
            surface.Stroke();
            surface.Fill();

            // WAVEFORMED CIRCLE
            surface.CurveTo(X - Radius, Y - waveDepths, X - waveBottoms, Y + waveDepths, X - waveTops, Y - waveDepths);
            surface.CurveTo(X - waveTops, Y - waveDepths, X, Y + waveDepths, X + waveTops, Y - waveDepths);
            surface.CurveTo(X + waveTops, Y - waveDepths, X + waveBottoms, Y + waveDepths, X + Radius, Y - waveDepths);
            surface.SetSourceRGBA(colorWater[0], colorWater[1], colorWater[2], alphaChannel);
            surface.Arc(X, Y, Radius, 0, Math.PI * 1);
            surface.Fill();

            // TEXT
            surface.SetSourceRGBA(1, 1, 1, 0.1);
            surface.MoveTo(X, Y);
            surface.SetFontSize(Radius / 2);
            string widgetText = Convert.ToString(WaterTemperature);

            Cairo.TextExtents text = surface.TextExtents(widgetText);
            surface.MoveTo(X - (text.Width / 2), Y + (text.Height / 2));
            surface.ShowText(widgetText);
            surface.Fill();
        }
Beispiel #3
0
        public override void Draw(Cairo.Context surface, int x, int y)
        {
            _humidityValue = CurrentData.GetCurrentValueByIdString(XIVELY_DATA_STREAM_ID);

            GraphContainer.AssignXivelyDatastreamStringById(_graphId, XIVELY_DATA_STREAM_ID);

            GraphContainer.SetGraphColorById(_graphId, G, R, 0.4f);

            X = x;
            Y = y;

            surface.SetSourceRGBA(R, B, G, Alpha);
            surface.Arc(X, Y, Radius, 0, Math.PI * 2);
            surface.Fill();

            surface.SetSourceRGB(R, G, B);
            surface.Arc(X, Y, Radius + 5, 0, Math.PI * 2);
            surface.Stroke();

            string widgetText = _humidityValue + "%";

            surface.SetFontSize(15);
            Cairo.TextExtents text = surface.TextExtents(widgetText);

            surface.SetSourceRGBA(1, 1, 1, Alpha);
            surface.MoveTo(X - (text.Width / 2), Y + (text.Height / 2));

            surface.ShowText(widgetText);

            widgetText = "Humidity";
            surface.SetFontSize(13);
            text = surface.TextExtents(widgetText);

            surface.SetSourceRGBA(0.98f, 0.5f, 0.4f, Alpha);
            surface.MoveTo(X - (text.Width / 2), Y + (text.Height / 2) + 15);

            surface.ShowText(widgetText);
        }
Beispiel #4
0
        /// <summary>
        /// Draw on specified surface.
        /// </summary>
        /// <param name="surface">Surface.</param>
        /// <param name="x">The x coordinate.</param>
        /// <param name="y">The y coordinate.</param>
        public override void Draw(Cairo.Context surface, int x, int y)
        {
            X = x;
            Y = y;

            surface.SetSourceRGB(R, G, B);
            surface.Arc(X, Y, Radius, 0, Math.PI * 2);
            surface.Fill();

            surface.SetSourceRGBA(0, 0, 0, 0.5f);
            surface.Arc(X, Y, Radius + 5, 0, Math.PI * 2);
            surface.Stroke();

            string widgetText = "Preferences";

            surface.SetFontSize(15);
            Cairo.TextExtents text = surface.TextExtents(widgetText);

            surface.SetSourceRGBA(1, 1, 1, _textAlpha);
            surface.MoveTo(X - (text.Width / 2), Y + (text.Height / 2));

            surface.ShowText(widgetText);
        }
        public override void Draw(Cairo.Context surface, int x, int y)
        {
            X = x;
            Y = y;

            string widgetText = "";

            if (Connection.IsAlive)
            {
                widgetText = "Online";
                surface.SetSourceRGB(R, G, B);
            }
            else
            {
                widgetText = "Offline";
                surface.SetSourceRGB(G, R, B);
            }

            surface.Arc(X, Y, Radius, 0, Math.PI * 2);
            surface.Fill();

            if (!UserSettings.UserSetupCompleted)
            {
                surface.SetSourceRGB(1, 0, 0);
            }
            else
            {
                surface.SetSourceRGB(R, G, 0);
            }
            surface.Arc(X, Y, Radius + 5, 0, Math.PI * 2);
            surface.Stroke();

            surface.SetFontSize(15);
            Cairo.TextExtents text = surface.TextExtents(widgetText);
            surface.SetSourceRGBA(0, 0, 0, _textAlpha);
            surface.MoveTo(X - (text.Width / 2), Y + (text.Height / 2));
            surface.ShowText(widgetText);


            if (!UserSettings.UserSetupCompleted)
            {
                widgetText = "Settings Incomplete";
                surface.SetFontSize(10);
                text = surface.TextExtents(widgetText);
                surface.SetSourceRGBA(0, 0, 0, Alpha);
                surface.MoveTo(X - (text.Width / 2), Y + (text.Height));
                surface.ShowText(widgetText);
            }
            if (!UserSettings.CorrectKey && UserSettings.UserSetupCompleted)
            {
                widgetText = "Settings Incomplete";
                surface.SetFontSize(10);
                text = surface.TextExtents(widgetText);
                surface.SetSourceRGBA(0, 0, 0, Alpha);
                surface.MoveTo(X - (text.Width / 2), Y + (text.Height) + 10);
                surface.ShowText(widgetText);
                widgetText = "Wrong Key";
                surface.SetFontSize(10);
                text = surface.TextExtents(widgetText);
                surface.SetSourceRGBA(0.4f, 0, 0, Alpha);
                surface.MoveTo(X - (text.Width / 2), Y + (text.Height) + (text.Height) + 10);
                surface.ShowText(widgetText);
            }
            if (UserSettings.CorrectKey && UserSettings.UserSetupCompleted)
            {
                widgetText = "Settings OK!";
                surface.SetFontSize(10);
                text = surface.TextExtents(widgetText);
                surface.SetSourceRGBA(0, 0, 0, _textAlpha);
                surface.MoveTo(X - (text.Width / 2), Y + (text.Height) + 10);
                surface.ShowText(widgetText);
            }
        }
Beispiel #6
0
        static Size Measure(object backend)
        {
            LayoutBackend la   = (LayoutBackend)backend;
            var           ctx  = la.Context.Context;
            var           text = la.Text;

            if (la.Font != null)
            {
                ctx.SelectFont(la.Font);
                ctx.SetFontSize(la.Font.Size);
            }

            if (la.Width == -1)
            {
                var te = ctx.TextExtents(text);
                return(new Size(te.Width, te.Height));
            }

            // Measure word by word

            double totalHeight   = 0;
            double currentWidth  = 0;
            double currentHeight = 0;

            la.LineBreaks.Clear();

            double spaceWidth   = ctx.TextExtents(" ").XAdvance;
            double spaceHeight  = ctx.FontExtents.Height;
            var    spaceExtents = new Cairo.TextExtents()
            {
                Width    = spaceWidth,
                Height   = spaceHeight,
                XAdvance = spaceWidth
            };

            int    pos         = 0;
            bool   inLineStart = true;
            int    prevPos     = 0;
            string word        = NextWord(text, ref pos);

            for (; word != null; prevPos = pos, word = NextWord(text, ref pos))
            {
                if (word.Length == 1 && word [0] == '\n')
                {
                    if (inLineStart)
                    {
                        // Empty line
                        currentHeight = spaceHeight;
                    }
                    totalHeight += currentHeight;
                    la.LineBreaks.Add(pos);
                    la.LineHeights.Add(currentHeight);
                    currentHeight = 0;
                    currentWidth  = 0;
                    inLineStart   = true;
                    continue;
                }

                inLineStart = false;
                bool isSpace = word.Length == 1 && word[0] == ' ';

                Cairo.TextExtents te;
                if (isSpace)
                {
                    te = spaceExtents;
                }
                else
                {
                    te = ctx.TextExtents(word);
                }

                if (currentWidth + te.Width > la.Width)
                {
                    la.LineHeights.Add(currentHeight);
                    la.LineBreaks.Add(isSpace ? pos : prevPos);                      // If a space causes a line break, we can ignore that space
                    totalHeight  += currentHeight;
                    currentHeight = te.Height;
                    if (isSpace)
                    {
                        currentWidth = 0;
                    }
                    else
                    {
                        currentWidth = te.Width;
                    }
                }
                else
                {
                    currentWidth += te.XAdvance;
                    if (te.Height > currentHeight)
                    {
                        currentHeight = te.Height;
                    }
                }
            }

            la.Measured = true;
            return(new Size(la.Width, totalHeight));
        }
        static Size Measure(object backend)
        {
            LayoutBackend la = (LayoutBackend) backend;
            var ctx = la.Context.Context;
            var text = la.Text;

            if (la.Font != null) {
                ctx.SelectFont (la.Font);
                ctx.SetFontSize (la.Font.Size);
            }

            if (la.Width == -1) {
                var te = ctx.TextExtents (text);
                return new Size (te.Width, te.Height);
            }

            // Measure word by word

            double totalHeight = 0;
            double currentWidth = 0;
            double currentHeight = 0;
            la.LineBreaks.Clear ();

            double spaceWidth = ctx.TextExtents (" ").XAdvance;
            double spaceHeight = ctx.FontExtents.Height;
            var spaceExtents = new Cairo.TextExtents () {
                Width = spaceWidth,
                Height = spaceHeight,
                XAdvance = spaceWidth
            };

            int pos = 0;
            bool inLineStart = true;
            int prevPos = 0;
            string word = NextWord (text, ref pos);

            for (; word != null; prevPos=pos, word = NextWord (text, ref pos))
            {
                if (word.Length == 1 && word [0] == '\n') {
                    if (inLineStart) {
                        // Empty line
                        currentHeight = spaceHeight;
                    }
                    totalHeight += currentHeight;
                    la.LineBreaks.Add (pos);
                    la.LineHeights.Add (currentHeight);
                    currentHeight = 0;
                    currentWidth = 0;
                    inLineStart = true;
                    continue;
                }

                inLineStart = false;
                bool isSpace = word.Length == 1 && word[0] == ' ';

                Cairo.TextExtents te;
                if (isSpace)
                    te = spaceExtents;
                else
                    te = ctx.TextExtents (word);

                if (currentWidth + te.Width > la.Width) {
                    la.LineHeights.Add (currentHeight);
                    la.LineBreaks.Add (isSpace ? pos : prevPos); // If a space causes a line break, we can ignore that space
                    totalHeight += currentHeight;
                    currentHeight = te.Height;
                    if (isSpace)
                        currentWidth = 0;
                    else
                        currentWidth = te.Width;
                }
                else {
                    currentWidth += te.XAdvance;
                    if (te.Height > currentHeight)
                        currentHeight = te.Height;
                }
            }

            la.Measured = true;
            return new Size (la.Width, totalHeight);
        }
Beispiel #8
0
        public override void Draw(Cairo.Context surface, int x, int y)
        {
            //PHValue = CurrentData.GetCurrentValueByIdFloat("ph");

            PHValue = CurrentData.GetCurrentValueByIdFloat(XIVELY_DATA_STREAM_ID);
            PHValue = PHValue % 14;

            X = x;
            Y = y;
            int barHeight = Radius / 2;
            //int barLength = Radius + (Radius / 2);
            int sectionSize      = Radius / 5;
            int pushLength       = sectionSize + 1;
            int amountOfSections = 8;

            int selectwidth  = Radius / 10;
            int selectHeight = Radius / 2;

            float phSelect      = (((float)sectionSize * (float)amountOfSections) / 14.0f) * PHValue;
            int   distanceOnBar = X - ((sectionSize * amountOfSections) / 2) + (int)phSelect;

            // CIRCLE
            surface.SetSourceRGBA(1, 1, 1, 0.3);
            surface.Arc(X, Y, Radius, 0, Math.PI * 2);
            surface.Fill();

            surface.SetSourceRGBA(1, 1, 1, PHLight);
            surface.Arc(X, Y, Radius + 5, 0, Math.PI * 2);
            surface.Stroke();
            surface.Fill();

            // WAVEFORMED CIRCLE
            surface.SetSourceRGB(0.8, 0.0, 0.0);
            surface.Rectangle(X - ((1 + sectionSize) * amountOfSections / 2), Y - (barHeight / 2), (sectionSize), barHeight);
            surface.Fill();

            surface.SetSourceRGB(0.6, 0.0, 0.0);
            surface.Rectangle(X - ((1 + sectionSize) * amountOfSections / 2) + (pushLength), Y - (barHeight / 2), (sectionSize), barHeight);
            surface.Fill();

            surface.SetSourceRGB(0.4, 0.0, 0.0);
            surface.Rectangle(X - ((1 + sectionSize) * amountOfSections / 2) + (pushLength * 2), Y - (barHeight / 2), (sectionSize), barHeight);
            surface.Fill();

            surface.SetSourceRGB(0.3, 0.0, 0.0);
            surface.Rectangle(X - ((1 + sectionSize) * amountOfSections / 2) + (pushLength * 3), Y - (barHeight / 2), (sectionSize), barHeight);
            surface.Fill();

            surface.SetSourceRGB(0.0, 0.0, 0.3);
            surface.Rectangle(X - ((1 + sectionSize) * amountOfSections / 2) + (pushLength * 4), Y - (barHeight / 2), (sectionSize), barHeight);
            surface.Fill();

            surface.SetSourceRGB(0.0, 0.0, 0.4);
            surface.Rectangle(X - ((1 + sectionSize) * amountOfSections / 2) + (pushLength * 5), Y - (barHeight / 2), (sectionSize), barHeight);
            surface.Fill();

            surface.SetSourceRGB(0.0, 0.0, 0.6);
            surface.Rectangle(X - ((1 + sectionSize) * amountOfSections / 2) + (pushLength * 6), Y - (barHeight / 2), (sectionSize), barHeight);
            surface.Fill();

            surface.SetSourceRGB(0.0, 0.0, 0.8);
            surface.Rectangle(X - ((1 + sectionSize) * amountOfSections / 2) + (pushLength * 7), Y - (barHeight / 2), (sectionSize), barHeight);
            surface.Fill();

            // TEXT
            surface.SetSourceRGBA(1, 1, 1, 0.5);
            surface.MoveTo(X, Y);
            surface.SetFontSize(Radius / 2);
            string widgetText = Convert.ToString(PHValue);

            Cairo.TextExtents text = surface.TextExtents(widgetText);
            surface.MoveTo(distanceOnBar - (text.Width / 2), Y + (text.Height / 2) - barHeight);
            surface.ShowText(widgetText);
            surface.Fill();

            surface.SetSourceRGB(1, 1, 1);
            surface.Rectangle(distanceOnBar - (selectwidth / 2), Y - barHeight / 2, selectwidth, selectHeight);
            surface.Stroke();
            surface.Fill();
        }