예제 #1
0
        public TouchLabel()
        {
            this.Visible       = true;
            this.VisibleWindow = false;

            textRender = new TouchText(string.Empty);
            _centered  = false;

            HeightRequest = 30;
            WidthRequest  = 200;

            this.ExposeEvent += OnExpose;
        }
예제 #2
0
        public TouchButton()
        {
            Visible       = true;
            VisibleWindow = false;

            render          = new TouchText();
            buttonColor     = "pri";
            unmodifiedColor = "pri";
            text            = "";
            textColor       = "black";
            HeightRequest   = 45;
            WidthRequest    = 45;
            textAlignment   = TouchAlignment.Center;
            clickAction     = ButtonClickAction.Darken;

            ExposeEvent        += OnExpose;
            ButtonPressEvent   += OnTouchButtonPress;
            ButtonReleaseEvent += OnTouchButtonRelease;
        }
예제 #3
0
        public TouchTextBox()
        {
            Visible       = true;
            VisibleWindow = false;

            SetSizeRequest(100, 30);

            textRender          = new TouchText();
            textRender.textWrap = TouchTextWrap.Shrink;

            text          = string.Empty;
            name          = string.Empty;
            textColor     = new TouchColor("black");
            textAlignment = TouchAlignment.Left;

            backgroundColor = "grey4";

            enableTouch          = false;
            includeTimeFunctions = false;

            ExposeEvent        += OnExpose;
            ButtonReleaseEvent += OnTouchButtonRelease;
        }
        protected void OnExpose(object sender, ExposeEventArgs args)
        {
            using (Context cr = Gdk.CairoHelper.Create(GdkWindow)) {
                int left  = Allocation.Left + 1;
                int top   = Allocation.Top;
                int width = Allocation.Width - 2;

                if (listDropdown)
                {
                    int listHeight;

                    if (comboList.Count > maxListHeight)
                    {
                        listHeight       = (maxListHeight + 1) * height;
                        includeScrollBar = true;
                    }
                    else if (comboList.Count > 0)
                    {
                        listHeight = (comboList.Count + 1) * height;
                    }
                    else
                    {
                        listHeight = 2 * height;
                    }

                    HeightRequest = listHeight + 2;

                    int radius = height / 2;
                    cr.MoveTo(left, top + radius);
                    cr.Arc(left + radius, top + radius, radius, Math.PI, -Math.PI / 2);
                    cr.LineTo(left + width - radius, top);
                    cr.Arc(left + width - radius, top + radius, radius, -Math.PI / 2, 0);
                    cr.LineTo(left + width, top + listHeight);
                    cr.LineTo(left, top + listHeight);
                    cr.ClosePath();
                    TouchColor.SetSource(cr, "grey4");
                    cr.FillPreserve();
                    TouchColor.SetSource(cr, "black");
                    cr.LineWidth = 1;
                    cr.Stroke();

                    DrawDownButton(cr, left, top, width);

                    if (includeScrollBar)
                    {
                        if (listOffset + maxListHeight > comboList.Count)
                        {
                            listOffset = 0;
                        }

                        int x = left + width - height;
                        listHeight -= height;

                        cr.Rectangle(x, top + height, height, listHeight);
                        TouchColor.SetSource(cr, "grey3");
                        cr.Fill();

                        cr.Rectangle(x, top + height, height, height);
                        TouchColor buttonColor  = "grey1";
                        var        outlineColor = new TouchColor(buttonColor);
                        outlineColor.ModifyColor(0.5);
                        var highlightColor = new TouchColor(buttonColor);
                        highlightColor.ModifyColor(1.4);
                        var lowlightColor = new TouchColor(buttonColor);
                        lowlightColor.ModifyColor(0.75);
                        using (var grad = new LinearGradient(x, top + height, x, top + 2 * height)) {
                            grad.AddColorStop(0.0, buttonColor.ToCairoColor());
                            grad.AddColorStop(0.85, lowlightColor.ToCairoColor());
                            cr.SetSource(grad);
                            cr.FillPreserve();
                        }
                        outlineColor.SetSource(cr);
                        cr.LineWidth = 1;
                        cr.Stroke();

                        var buttonTop = top + listHeight;
                        cr.Rectangle(x, buttonTop, height, height);
                        using (var grad = new LinearGradient(x, buttonTop, x, buttonTop + height)) {
                            grad.AddColorStop(0, highlightColor.ToCairoColor());
                            grad.AddColorStop(0.2, buttonColor.ToCairoColor());
                            grad.AddColorStop(0.85, lowlightColor.ToCairoColor());
                            cr.SetSource(grad);
                            cr.FillPreserve();
                        }
                        outlineColor.SetSource(cr);
                        cr.LineWidth = 1;
                        cr.Stroke();

                        scrollBarHeight = (listHeight - 2 * height) / comboList.Count;
                        var scrollBarActualHeight = scrollBarHeight * maxListHeight;
                        var scrollBarTop          = top + (2 * height) + (scrollBarHeight * listOffset);

                        TouchGlobal.DrawRoundedRectangle(cr, x, scrollBarTop, height, scrollBarActualHeight, height / 3);
                        buttonColor  = "grey2";
                        outlineColor = new TouchColor(buttonColor);
                        outlineColor.ModifyColor(0.5);
                        highlightColor = new TouchColor(buttonColor);
                        highlightColor.ModifyColor(1.3);
                        lowlightColor = new TouchColor(buttonColor);
                        lowlightColor.ModifyColor(0.75);
                        using (var grad = new LinearGradient(x, scrollBarTop, x, scrollBarTop + scrollBarActualHeight)) {
                            grad.AddColorStop(0, highlightColor.ToCairoColor());
                            grad.AddColorStop(0.1, buttonColor.ToCairoColor());
                            grad.AddColorStop(0.85, lowlightColor.ToCairoColor());
                            cr.SetSource(grad);
                            cr.FillPreserve();
                        }
                        outlineColor.SetSource(cr);
                        cr.LineWidth = 1;
                        cr.Stroke();

                        int triOffset = 7;
                        int triSize   = height - 12;
                        int y         = top + height + triOffset + triSize;
                        x += (triOffset - 1);

                        cr.MoveTo(x, y);
                        cr.LineTo(x + triSize, y);
                        cr.LineTo(x + (triSize / 2), y - triSize);
                        cr.ClosePath();
                        if (scrollBarUpClicked)
                        {
                            TouchColor.SetSource(cr, "pri");
                        }
                        else
                        {
                            TouchColor.SetSource(cr, "grey2");
                        }
                        cr.Fill();

                        y = top + listHeight + triOffset;
                        cr.MoveTo(x, y);
                        cr.LineTo(x + triSize, y);
                        cr.LineTo(x + triSize / 2, y + triSize);
                        cr.ClosePath();
                        if (scrollBarDownClicked)
                        {
                            TouchColor.SetSource(cr, "pri");
                        }
                        else
                        {
                            TouchColor.SetSource(cr, "grey2");
                        }
                        cr.Fill();
                    }

                    if (highlighted != -1)
                    {
                        var highlightedWidth = width - 2;
                        if (includeScrollBar)
                        {
                            highlightedWidth -= height;
                        }
                        var y = top + height + (height * highlighted);
                        cr.Rectangle(left + 1, y + 1, highlightedWidth, height - 2);
                        TouchColor.SetSource(cr, "pri");
                        cr.Fill();
                    }

                    var textRender = new TouchText();
                    textRender.font.color = "black";
                    if (includeScrollBar)
                    {
                        for (int i = 0; i < maxListHeight; ++i)
                        {
                            textRender.text = comboList[i + listOffset];
                            int y = top + height + 6 + (height * i);
                            textRender.Render(this, left + 10, y, width - height);
                        }
                    }
                    else
                    {
                        for (int i = 0; i < comboList.Count; ++i)
                        {
                            textRender.text = comboList[i];
                            int y = top + height + 6 + (height * i);
                            textRender.Render(this, left + 10, y, width - height);
                        }
                    }
                }
                else
                {
                    HeightRequest = height;

                    TouchGlobal.DrawRoundedRectangle(cr, left, top, width - 2, height, height / 2);
                    TouchColor.SetSource(cr, "grey4");
                    cr.FillPreserve();
                    cr.LineWidth = 1;
                    TouchColor.SetSource(cr, "black");
                    cr.Stroke();

                    DrawDownButton(cr, left, top, width);
                }

                bool writeStringCond1 = nonActiveMessage.IsNotEmpty() && (activeIndex == -1);
                bool writeStringCond2 = (comboList.Count > 0) && (activeIndex >= 0);

                if (writeStringCond1 || writeStringCond2)
                {
                    string text = writeStringCond1 ? nonActiveMessage : comboList[activeIndex];
                    var    t    = new TouchText(text);
                    t.textWrap   = TouchTextWrap.Shrink;
                    t.font.color = "black";
                    var w = width - height - 10;
                    t.Render(this, left + 10, top, w, height);
                }
            }
        }
예제 #5
0
        protected void OnExpose(object sender, ExposeEventArgs args)
        {
            using (Context cr = Gdk.CairoHelper.Create(this.GdkWindow)) {
                int height = Allocation.Height;
                int width  = Allocation.Width;
                int top    = Allocation.Top;
                int left   = Allocation.Left;

                int seperation, sliderWidth, sliderLength, sliderMax, x, y;

                if (orientation == TouchOrientation.Horizontal)
                {
                    if (sliderSize == MySliderSize.Small)
                    {
                        sliderWidth = height;
                    }
                    else
                    {
                        sliderWidth  = width / selectionCount;
                        sliderWidth += (selectionCount - 2) * 8;
                    }

                    sliderLength = width - sliderWidth;
                    sliderMax    = left + sliderLength;

                    seperation = sliderLength / (selectionCount - 1);

                    seperation *= currentSelected;

                    if (clicked)
                    {
                        seperation += (click2 - click1);
                    }

                    x = left + seperation;
                    if (x < left)
                    {
                        x = left;
                    }
                    if (x > sliderMax)
                    {
                        x = sliderMax;
                    }
                    y = top;
                }
                else
                {
                    if (sliderSize == MySliderSize.Small)
                    {
                        sliderWidth = width;
                    }
                    else
                    {
                        sliderWidth  = height / selectionCount;
                        sliderWidth += (selectionCount - 2) * 8;
                    }

                    sliderLength = height - sliderWidth;
                    sliderMax    = top + sliderLength;

                    seperation = sliderLength / (selectionCount - 1);

                    seperation *= currentSelected;

                    if (clicked)
                    {
                        seperation += click2 - click1;
                    }

                    y = top + seperation;
                    if (y < top)
                    {
                        y = top;
                    }
                    if (y > sliderMax)
                    {
                        y = sliderMax;
                    }
                    x = left;
                }

                // Background
                if (orientation == TouchOrientation.Horizontal)
                {
                    TouchGlobal.DrawRoundedRectangle(cr, left, top, width, height, height / 2);
                }
                else
                {
                    TouchGlobal.DrawRoundedRectangle(cr, left, top, width, height, width / 2);
                }
                TouchColor.SetSource(cr, "grey0");
                cr.FillPreserve();

                TouchColor.SetSource(cr, "black");
                cr.LineWidth = 1;
                cr.Stroke();

                // Slider
                double sliderLeft, sliderTop, sliderBottom;
                if (orientation == TouchOrientation.Horizontal)
                {
                    sliderLeft   = x;
                    sliderTop    = y;
                    sliderBottom = y + height;

                    TouchGlobal.DrawRoundedRectangle(cr, x, y, sliderWidth, height, height / 2);
                }
                else
                {
                    sliderLeft   = x;
                    sliderTop    = y;
                    sliderBottom = y + sliderWidth;

                    TouchGlobal.DrawRoundedRectangle(cr, x, y, width, sliderWidth, width / 2);
                }

                var sliderColor  = sliderColorOptions[currentSelected];
                var outlineColor = new TouchColor(sliderColor);
                outlineColor.ModifyColor(0.5);
                var highlightColor = new TouchColor(sliderColor);
                highlightColor.ModifyColor(1.4);
                var lowlightColor = new TouchColor(sliderColor);
                lowlightColor.ModifyColor(0.75);

                using (var grad = new LinearGradient(sliderLeft, sliderTop, sliderLeft, sliderBottom)) {
                    grad.AddColorStop(0, highlightColor.ToCairoColor());
                    grad.AddColorStop(0.2, sliderColor.ToCairoColor());
                    grad.AddColorStop(0.85, lowlightColor.ToCairoColor());
                    cr.SetSource(grad);
                    cr.FillPreserve();
                }

                outlineColor.SetSource(cr);
                cr.LineWidth = 0.9;
                cr.Stroke();

                // Text Labels
                var render = new TouchText();
                render.textWrap  = TouchTextWrap.Shrink;
                render.alignment = TouchAlignment.Center;

                seperation = Allocation.Width / selectionCount;
                x          = Allocation.Left;
                for (int i = 0; i < selectionCount; ++i)
                {
                    if (!string.IsNullOrWhiteSpace(textOptions[i]))
                    {
                        render.font.color = i == currentSelected ? selectedTextColorOptions[i] : backgoundTextColorOptions[i];
                        render.text       = textOptions[i];
                        render.Render(this, x, Allocation.Top + 4, seperation);
                    }

                    x += seperation;
                }
            }
        }
예제 #6
0
        protected void OnExpose(object sender, ExposeEventArgs args)
        {
            using (Context cr = Gdk.CairoHelper.Create(GdkWindow)) {
                int top    = Allocation.Top;
                int left   = Allocation.Left;
                int height = Allocation.Height;
                int bottom = Allocation.Bottom;
                int width  = Allocation.Width;
                var now    = DateTime.Now;

                cr.Rectangle(left + 8, top, graphWidth, height);
                TouchColor.SetSource(cr, "grey3", 0.15f);
                cr.Fill();

                var timeToPoints = PointTimeDifferenceToSeconds();

                //Value points
                if (dataPoints.count > 0)
                {
                    var fullBuffer = dataPoints.ToArray();
                    Array.Reverse(fullBuffer);

                    int maxIndex = fullBuffer.Length - 1;
                    for (var i = 0; i < fullBuffer.Length; ++i)
                    {
                        var maxX = now.Subtract(fullBuffer[i].dateTime).TotalSeconds / timeToPoints * (double)_pointSpacing;
                        if (maxX > graphWidth)
                        {
                            maxIndex = i;
                            break;
                        }
                    }

                    if (maxIndex == 0)
                    {
                        maxIndex = 1;
                    }

                    var valueBuffer = fullBuffer.SubArray(0, maxIndex);

                    var min = valueBuffer.Min(entry => entry.value);
                    var max = valueBuffer.Max(entry => entry.value);

                    if ((max - min) < rangeMargin)
                    {
                        min -= (rangeMargin / 2);
                        max += (rangeMargin / 2);
                    }

                    var    y = valueBuffer[0].value.Map(min, max, bottom - 4, top + 4);
                    double x = left + 8;
                    cr.MoveTo(x, y);
                    var pointDifference = now.Subtract(valueBuffer[0].dateTime).TotalSeconds / timeToPoints;
                    x += pointDifference * (double)_pointSpacing;
                    if (x > (left + width))
                    {
                        x = left + width;
                    }
                    cr.LineTo(x, y);

                    for (var i = 1; i < valueBuffer.Length; ++i)
                    {
                        y = valueBuffer[i].value.Map(min, max, bottom - 4, top + 4);
                        x = left + 8;

                        pointDifference = now.Subtract(valueBuffer[i].dateTime).TotalSeconds / timeToPoints;
                        x += pointDifference * (double)_pointSpacing;

                        cr.LineTo(x, y);
                    }

                    TouchColor.SetSource(cr, "pri");
                    cr.Stroke();

                    var textRender = new TouchText();
                    textRender.alignment  = TouchAlignment.Right;
                    textRender.font.color = "white";

                    if (rangeMargin > 1)
                    {
                        textRender.text = Math.Floor(min).ToString();
                    }
                    else
                    {
                        textRender.text = min.ToString("F1");
                    }
                    textRender.Render(this, left - 9, bottom - 16, 16);

                    if (rangeMargin > 1)
                    {
                        textRender.text = Math.Ceiling(max).ToString();
                    }
                    else
                    {
                        textRender.text = max.ToString("F1");
                    }
                    textRender.Render(this, left - 9, top - 2, 16);
                }

                //Event points
                if (eventPoints.count > 0)
                {
                    var eventBuffer = eventPoints.ToArray();
                    Array.Reverse(eventBuffer);
                    for (int i = 0; i < eventBuffer.Length; i++)
                    {
                        double x = left + 8;
                        x += now.Subtract(eventBuffer[i].dateTime).TotalSeconds / timeToPoints * (double)_pointSpacing;
                        if (x > (left + width))
                        {
                            break;
                        }

                        cr.Rectangle(x - (int)_pointSpacing, top, (int)_pointSpacing * 2, height);

                        if (eventColors.ContainsKey(eventBuffer[i].eventType))
                        {
                            eventColors[eventBuffer[i].eventType].SetSource(cr);
                        }
                        else
                        {
                            TouchColor.SetSource(cr, "seca", .375);
                        }

                        cr.Fill();
                    }
                }
            }
        }