protected void OnExpose(object sender, ExposeEventArgs args) { using (Context cr = Gdk.CairoHelper.Create(GdkWindow)) { int left = Allocation.Left; int top = Allocation.Top; int width = Allocation.Width; int height = Allocation.Height; TouchGlobal.DrawRoundedRectangle(cr, left + 4, top + 4, width - 1, height - 1, 3); var shadowColor = new TouchColor(backgroundColor); shadowColor.ModifyColor(0.5); shadowColor.A = 0.4; shadowColor.SetSource(cr); cr.Fill(); TouchGlobal.DrawRoundedRectangle(cr, left, top, width, height, 3); backgroundColor.SetSource(cr); cr.FillPreserve(); TouchColor.SetSource(cr, "grey0"); cr.LineWidth = 1; cr.Stroke(); textRender.Render(this, left + 3, top, width - 6, height); } }
protected void OnExpose(object sender, ExposeEventArgs args) { using (Context cr = Gdk.CairoHelper.Create(GdkWindow)) { var left = Allocation.Left; var width = Allocation.Width; var top = Allocation.Top; var bottom = Allocation.Bottom; var height = Allocation.Height; TouchGlobal.DrawRoundedRectangle(cr, left, top, width, height, 4.0); 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(left, top, left, bottom)) { 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(); render.Render(this, left + 3, top, width - 6, height); } }
public TouchProgressBar( TouchColor colorBackground, TouchColor colorProgress, float currentProgress, bool enableTouch, TouchOrientation orientation ) { Visible = true; VisibleWindow = false; this.colorBackground = colorBackground; this.colorProgress = colorProgress; _currentProgress = currentProgress; this.enableTouch = enableTouch; this.orientation = orientation; timerId = 0; clicked = false; if (this.orientation == TouchOrientation.Vertical) { SetSizeRequest(30, 200); } else { SetSizeRequest(200, 30); } ExposeEvent += OnExpose; ButtonPressEvent += OnProgressBarPress; ButtonReleaseEvent += OnProgressBarRelease; }
public TouchColor Blend(TouchColor otherColor, float amount) { double red = (R * (1 - amount)) + (otherColor.R * amount); double green = (G * (1 - amount)) + (otherColor.G * amount); double blue = (B * (1 - amount)) + (otherColor.B * amount); return(new TouchColor(red, green, blue)); }
public TouchColor(TouchColor touchColor) { colorName = touchColor.colorName; R = touchColor.R; G = touchColor.G; B = touchColor.B; A = touchColor.A; }
protected void OnTouchButtonRelease(object o, ButtonReleaseEventArgs args) { if (unmodifiedColor != null) { buttonColor = unmodifiedColor; } QueueDraw(); }
public TouchLayeredProgressBar() : base(new TouchColor("grey4"), new TouchColor("pri"), 0, false, TouchOrientation.Vertical) { colorProgressSecondary = new TouchColor("seca"); currentProgressSecondary = 0; drawPrimaryWhenEqual = true; ExposeEvent -= OnExpose; ExposeEvent += OnExposeSecondary; }
public TouchGraphicalBox(int width, int height) { Visible = true; VisibleWindow = false; SetSizeRequest(width, height); color = "grey2"; transparency = 0.55f; ExposeEvent += OnExpose; }
public static void SetSource(Context cr, string color, double a = 1.0) { TouchColor c; try { c = new TouchColor(color); cr.SetSourceRGBA(c.R, c.G, c.B, a); } catch { cr.SetSourceRGBA(0.0, 0.0, 0.0, a); } }
public static Gdk.Color NewGtkColor(string color) { TouchColor c; try { c = new TouchColor(color); return(new Gdk.Color((byte)(c.R * 255), (byte)(c.G * 255), (byte)(c.B * 255))); } catch { return(new Gdk.Color()); } }
public static Color NewCairoColor(string color, double a = 1.0) { TouchColor c; try { c = new TouchColor(color); return(new Color(c.R, c.G, c.B, a)); } catch { return(new Color(0.0, 0.0, 0.0)); } }
public TouchSelectorSwitch(int id, int selectionCount, int currentSelectedIndex, TouchOrientation orientation) { Visible = true; VisibleWindow = false; this.id = id; this.selectionCount = selectionCount; currentSelected = currentSelectedIndex; this.orientation = orientation; sliderSize = MySliderSize.Large; backgoundTextColorOptions = new TouchColor[this.selectionCount]; for (int i = 0; i < backgoundTextColorOptions.Length; ++i) { backgoundTextColorOptions[i] = new TouchColor("white"); } selectedTextColorOptions = new TouchColor[this.selectionCount]; for (int i = 0; i < backgoundTextColorOptions.Length; ++i) { selectedTextColorOptions[i] = new TouchColor("white"); } sliderColorOptions = new TouchColor[this.selectionCount]; for (int i = 0; i < sliderColorOptions.Length; ++i) { sliderColorOptions[i] = new TouchColor("grey2"); } textOptions = new string[this.selectionCount]; for (int i = 0; i < textOptions.Length; ++i) { textOptions[i] = string.Empty; } clicked = false; clickTimer = 0; click1 = 0; click2 = 0; if (this.orientation == TouchOrientation.Horizontal) { SetSizeRequest(80, 30); } else { SetSizeRequest(30, 80); } ExposeEvent += OnExpose; ButtonPressEvent += OnSelectorPress; ButtonReleaseEvent += OnSelectorRelease; }
protected void DrawProgressBar(Context cr, float progress, TouchColor color) { var left = Allocation.Left; var top = Allocation.Top; var width = Allocation.Width; var height = Allocation.Height; int bottom = top + height; double difference; if (orientation == TouchOrientation.Vertical) { difference = (height - width) * progress; top += height - width - difference.ToInt(); cr.MoveTo(left, bottom - radius); cr.ArcNegative(left + radius, bottom - radius, radius, Math.PI, 0); cr.LineTo(left + width, top + radius); cr.ArcNegative(left + radius, top + radius, radius, 0, Math.PI); cr.ClosePath(); } else { difference = ((width - height) * progress); cr.MoveTo(left + radius, top); cr.ArcNegative(left + radius, top + radius, radius, 3 * Math.PI / 2, Math.PI / 2); cr.LineTo(left + difference + height - radius, bottom); cr.ArcNegative(left + difference + height - radius, top + radius, radius, Math.PI / 2, 3 * Math.PI / 2); cr.ClosePath(); } var outlineColor = new TouchColor(color); outlineColor.ModifyColor(0.5); var highlightColor = new TouchColor(color); highlightColor.ModifyColor(1.4); var lowlightColor = new TouchColor(color); lowlightColor.ModifyColor(0.75); using (var grad = new LinearGradient(left, top, left, bottom)) { grad.AddColorStop(0, highlightColor.ToCairoColor()); grad.AddColorStop(0.2, color.ToCairoColor()); grad.AddColorStop(0.85, lowlightColor.ToCairoColor()); cr.SetSource(grad); cr.FillPreserve(); } outlineColor.SetSource(cr); cr.LineWidth = 1; cr.Stroke(); }
public MyFont() { color = "white"; size = 11; if (Utilites.Utils.ExecutingOperatingSystem == Utilites.Platform.Mac) { fontName = "Liberation Sans"; } else { fontName = "Sans"; } }
public TouchDialog(string msg, Window parent, string[] buttons) : base(string.Empty, parent, DialogFlags.DestroyWithParent) { ModifyBg(StateType.Normal, TouchColor.NewGtkColor("grey0")); KeepAbove = true; #if RPI_BUILD Decorated = false; ExposeEvent += (o, args) => { using (Context cr = Gdk.CairoHelper.Create(GdkWindow)) { cr.MoveTo(Allocation.Left, Allocation.Top); cr.LineTo(Allocation.Right, Allocation.Top); cr.LineTo(Allocation.Right, Allocation.Bottom); cr.LineTo(Allocation.Left, Allocation.Bottom); cr.ClosePath(); cr.LineWidth = 1.8; TouchColor.SetSource(cr, "grey4"); cr.Stroke(); } }; #endif foreach (var button in buttons) { try { var response = (ResponseType)Enum.Parse(typeof(ResponseType), button); var btn = new TouchButton(); btn.text = button; btn.HeightRequest = 30; btn.ButtonReleaseEvent += (o, args) => Respond(response); ActionArea.Add(btn); } catch { // } } var label = new Label(); label.LineWrap = true; label.Text = msg; label.ModifyFg(StateType.Normal, TouchColor.NewGtkColor("white")); label.ModifyFont(Pango.FontDescription.FromString("Sans 11")); VBox.Add(label); label.Show(); }
public static void Show(string msg) { var ms = new Dialog(string.Empty, null, DialogFlags.DestroyWithParent); ms.KeepAbove = true; #if RPI_BUILD ms.Decorated = false; ms.ExposeEvent += (o, args) => { using (Context cr = Gdk.CairoHelper.Create(ms.GdkWindow)) { cr.MoveTo(ms.Allocation.Left, ms.Allocation.Top); cr.LineTo(ms.Allocation.Right, ms.Allocation.Top); cr.LineTo(ms.Allocation.Right, ms.Allocation.Bottom); cr.LineTo(ms.Allocation.Left, ms.Allocation.Bottom); cr.ClosePath(); cr.LineWidth = 1.8; TouchColor.SetSource(cr, "grey4"); cr.Stroke(); } }; #endif ms.ModifyBg(StateType.Normal, TouchColor.NewGtkColor("grey0")); var btn = new TouchButton(); btn.text = "Ok"; btn.HeightRequest = 30; btn.ButtonReleaseEvent += (o, args) => ms.Respond(ResponseType.Ok); ms.ActionArea.Add(btn); var label = new Label(); label.LineWrap = true; label.Text = msg; label.ModifyFg(StateType.Normal, TouchColor.NewGtkColor("white")); label.ModifyFont(Pango.FontDescription.FromString("Sans 11")); ms.VBox.Add(label); label.Show(); ms.Run(); ms.Destroy(); ms.Dispose(); }
public static string ToHTML(string color) { byte r, g, b; try { TouchColor c = new TouchColor(color); r = (byte)(c.R * 255); g = (byte)(c.G * 255); b = (byte)(c.B * 255); } catch { r = 0; g = 0; b = 0; } string html = string.Format("#{0:X2}{1:X2}{2:X2}", r, g, b); return(html); }
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; }
public TouchCurvedProgressBar( TouchColor colorBackground, TouchColor colorProgress, float currentProgress ) { Visible = true; VisibleWindow = false; backgroundColor = colorBackground; progressColor = colorProgress; _progress = currentProgress; barWidth = 20; curveStyle = CurveStyle.HalfCurve; SetSizeRequest(160, 80); ExposeEvent += OnExpose; }
public TouchLayeredProgressBar( TouchColor colorBackground, TouchColor colorProgress, float currentProgress, bool enableTouch, TouchOrientation orientation, TouchColor colorProgressSecondary, float currentProgressSecondary, bool drawPrimaryWhenEqual) : base( colorBackground, colorProgress, currentProgress, enableTouch, orientation) { this.colorProgressSecondary = colorProgressSecondary; this.currentProgressSecondary = currentProgressSecondary; this.drawPrimaryWhenEqual = drawPrimaryWhenEqual; ExposeEvent -= OnExpose; ExposeEvent += OnExposeSecondary; }
protected void OnTouchButtonPress(object o, ButtonPressEventArgs args) { if (args.Event.Type == Gdk.EventType.ButtonPress) { if (clickAction == ButtonClickAction.NoTransparency) { unmodifiedColor = new TouchColor(buttonColor); buttonColor.A = 1; } else if (clickAction == ButtonClickAction.Brighten) { unmodifiedColor = new TouchColor(buttonColor); buttonColor.ModifyColor(1.25); } else if (clickAction == ButtonClickAction.Darken) { unmodifiedColor = new TouchColor(buttonColor); buttonColor.ModifyColor(0.75); } QueueDraw(); } }
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; }
void DrawDownButton(Context cr, int left, int top, int width) { var x = left + (width - height); var radius = height / 2; cr.MoveTo(x, top); cr.LineTo(x + radius, top); if (listDropdown) { cr.Arc(x + radius, top + radius, radius, -Math.PI / 2, 0); cr.LineTo(x + height, top + height); } else { cr.Arc(x + radius, top + radius, radius, -Math.PI / 2, Math.PI / 2); } cr.LineTo(x, top + height); cr.ClosePath(); //TouchColor backgroundColor = listDropdown ? "grey3" : "grey1"; TouchColor backgroundColor = "grey1"; var outlineColor = new TouchColor(backgroundColor); outlineColor.ModifyColor(0.5); var highlightColor = new TouchColor(backgroundColor); highlightColor.ModifyColor(1.4); var lowlightColor = new TouchColor(backgroundColor); lowlightColor.ModifyColor(0.75); using (var grad = new LinearGradient(x, top, x, top + height)) { grad.AddColorStop(0, highlightColor.ToCairoColor()); grad.AddColorStop(0.2, backgroundColor.ToCairoColor()); if (!(listDropdown && includeScrollBar)) { 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 + triOffset; if (listDropdown) { x += height / 2; cr.MoveTo(x, y); cr.LineTo(x + triSize / 2, y + triSize); cr.LineTo(x - triSize / 2, y + triSize); } else { x += (triOffset - 3); cr.MoveTo(x, y); cr.LineTo(x + triSize, y); cr.LineTo(x + triSize / 2, y + triSize); } cr.ClosePath(); TouchColor.SetSource(cr, "seca"); cr.Fill(); }
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; } } }
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); } } }
protected void OnExpose(object sender, ExposeEventArgs args) { using (Context cr = Gdk.CairoHelper.Create(GdkWindow)) { var left = Allocation.Left; var top = Allocation.Top; var width = Allocation.Width; var height = Allocation.Height; var radius = barWidth / 2; int bigRadius; double fudgeFactor = -0.0125 * radius; if (curveStyle == CurveStyle.HalfCurve) { bigRadius = height - radius - 2; int originX = left + (width / 2); int originY = top + height - radius; cr.MoveTo(originX - bigRadius + barWidth, originY); cr.Arc(originX - bigRadius + radius, originY, radius, 0, Math.PI); cr.Arc(originX, originY, bigRadius, Math.PI, 0); cr.Arc(originX + bigRadius - radius, originY, radius, 0, Math.PI); cr.ArcNegative(originX, originY, bigRadius - barWidth + fudgeFactor, 0, Math.PI); cr.ClosePath(); backgroundColor.SetSource(cr); cr.Fill(); double r = ((1 - _progress) * -180.0).ToRadians(); double x2 = TouchGlobal.CalcX(originX, bigRadius - radius, r); double y2 = TouchGlobal.CalcY(originY, bigRadius - radius, r); cr.MoveTo(originX - bigRadius + barWidth, originY); cr.Arc(originX - bigRadius + radius, originY, radius, 0, Math.PI); cr.Arc(originX, originY, bigRadius, Math.PI, r); cr.Arc(x2, y2, radius, r, r + Math.PI); cr.ArcNegative(originX, originY, bigRadius - barWidth + fudgeFactor, r, Math.PI); cr.LineTo(left, originY); cr.ClosePath(); progressColor.SetSource(cr); cr.Fill(); } else if (curveStyle == CurveStyle.ThreeQuarterCurve) { int below = (0.45 * height).ToInt(); bigRadius = height - below - 2; int originX = left + (width / 2); int originY = top + height - below; double x2 = TouchGlobal.CalcX(originX, bigRadius - radius, 3 * Math.PI / 4); double y2 = TouchGlobal.CalcY(originY, bigRadius - radius, 3 * Math.PI / 4); cr.MoveTo(x2, y2); cr.Arc(x2, y2, radius, 7 * Math.PI / 4, 3 * Math.PI / 4); cr.Arc(originX, originY, bigRadius, 3 * Math.PI / 4, Math.PI / 4); x2 = TouchGlobal.CalcX(originX, bigRadius - radius, Math.PI / 4); y2 = TouchGlobal.CalcY(originY, bigRadius - radius, Math.PI / 4); cr.Arc(x2, y2, radius, Math.PI / 4, (-135.0).ToRadians()); cr.ArcNegative(originX, originY, bigRadius - barWidth + fudgeFactor, Math.PI / 4, 3 * Math.PI / 4); cr.ClosePath(); backgroundColor.SetSource(cr); cr.Fill(); double r = (_progress * 270.0 + 135.0).ToRadians(); x2 = TouchGlobal.CalcX(originX, bigRadius - radius, 3 * Math.PI / 4); y2 = TouchGlobal.CalcY(originY, bigRadius - radius, 3 * Math.PI / 4); cr.Arc(x2, y2, radius, 7 * Math.PI / 4, 3 * Math.PI / 4); cr.Arc(originX, originY, bigRadius, 3 * Math.PI / 4, r); x2 = TouchGlobal.CalcX(originX, bigRadius - radius, r); y2 = TouchGlobal.CalcY(originY, bigRadius - radius, r); cr.Arc(x2, y2, radius, r, r + Math.PI); cr.ArcNegative(originX, originY, bigRadius - barWidth + fudgeFactor, r, 3 * Math.PI / 4); var outlineColor = new TouchColor(progressColor); outlineColor.ModifyColor(0.5); var highlightColor = new TouchColor(progressColor); highlightColor.ModifyColor(1.4); var lowlightColor = new TouchColor(progressColor); lowlightColor.ModifyColor(0.75); var colorOriginX = TouchGlobal.CalcX(originX, bigRadius - 5, 11 * Math.PI / 8); var colorOriginY = TouchGlobal.CalcY(originY, bigRadius - 5, 11 * Math.PI / 8); using (var grad = new RadialGradient(colorOriginX, colorOriginY, 0, colorOriginX, colorOriginY, (bigRadius - 5) * 2)) { grad.AddColorStop(0, highlightColor.ToCairoColor()); grad.AddColorStop(0.35, progressColor.ToCairoColor()); grad.AddColorStop(0.75, lowlightColor.ToCairoColor()); cr.SetSource(grad); cr.FillPreserve(); } outlineColor.SetSource(cr); cr.LineWidth = 1; cr.Stroke(); } } }
public TouchNumberInput(bool timeInput = false, Window parent = null) : base("Input", parent, DialogFlags.DestroyWithParent) { Name = "AquaPic.Keyboard.Input"; Title = "Input"; WindowPosition = (WindowPosition)4; DefaultWidth = 205; DefaultHeight = 290; KeepAbove = true; #if RPI_BUILD Decorated = false; ExposeEvent += (o, args) => { using (Context cr = Gdk.CairoHelper.Create(GdkWindow)) { cr.MoveTo(Allocation.Left, Allocation.Top); cr.LineTo(Allocation.Right, Allocation.Top); cr.LineTo(Allocation.Right, Allocation.Bottom); cr.LineTo(Allocation.Left, Allocation.Bottom); cr.ClosePath(); cr.LineWidth = 1.8; TouchColor.SetSource(cr, "grey4"); cr.Stroke(); } }; #endif fix = new Fixed(); fix.WidthRequest = 205; fix.HeightRequest = 290; ModifyBg(StateType.Normal, TouchColor.NewGtkColor("grey0")); entry = new Entry(); entry.WidthRequest = 145; entry.HeightRequest = 30; entry.CanFocus = true; entry.ModifyFont(Pango.FontDescription.FromString("Sans 11")); entry.ModifyBase(StateType.Normal, TouchColor.NewGtkColor("grey4")); entry.ModifyText(StateType.Normal, TouchColor.NewGtkColor("black")); entry.Activated += (sender, e) => { if (entry.Text.IsNotEmpty()) { TextSetEventArgs args = new TextSetEventArgs(entry.Text); TextSetEvent?.Invoke(this, args); if (args.keepText) { Destroy(); } } else { Destroy(); } }; fix.Put(entry, 5, 5); entry.GrabFocus(); var b = new TouchButton(); b.HeightRequest = 30; b.ButtonReleaseEvent += (o, args) => { if (vkb == null) { fix.WidthRequest = 710; fix.QueueDraw(); SetSizeRequest(710, 290); Show(); entry.WidthRequest = 700; entry.QueueDraw(); b.Destroy(); vkb = new VirtualKeyboard(entry, OnButtonRelease); fix.Put(vkb, 205, 60); vkb.Show(); } }; fix.Put(b, 155, 5); b.Show(); int x, y; var buttons = new KeyButton[10]; for (int i = 0; i < buttons.Length; ++i) { buttons[i] = new KeyButton(i.ToString(), OnButtonRelease); if (i == 0) { x = 55; y = 190; } else { if (i <= 3) { x = ((i - 1) * 50) + 5; y = 40; } else if (i <= 6) { x = ((i - 4) * 50) + 5; y = 90; } else { x = ((i - 7) * 50) + 5; y = 140; } } fix.Put(buttons[i], x, y); } KeyButton plusMinus = new KeyButton("-", null); plusMinus.ButtonReleaseEvent += (o, args) => { if (plusMinus.text == "-") { int pos = 0; entry.InsertText("-", ref pos); ++entry.Position; plusMinus.text = "+"; } else { entry.DeleteText(0, 1); plusMinus.text = "-"; } plusMinus.text = plusMinus.text.ToString(); plusMinus.QueueDraw(); }; fix.Put(plusMinus, 5, 190); KeyButton period = new KeyButton(".", OnButtonRelease); fix.Put(period, 105, 190); KeyButton delete = new KeyButton(Convert.ToChar(0x232B).ToString(), null); //02FF, 25C0 delete.ButtonReleaseEvent += (o, args) => { int pos = entry.Position; entry.DeleteText(entry.Position - 1, entry.Position); }; fix.Put(delete, 155, 40); KeyButton clear = new KeyButton("C", null); clear.ButtonReleaseEvent += (o, args) => { plusMinus.text = "-"; entry.Text = string.Empty; }; fix.Put(clear, 155, 90); KeyButton semi; if (timeInput) { semi = new KeyButton(":", OnButtonRelease); } else { semi = new KeyButton(":", null); semi.buttonColor = "grey1"; } fix.Put(semi, 5, 240); KeyButton pm = new KeyButton("PM", null); if (timeInput) { pm.ButtonReleaseEvent += (o, args) => { int len = entry.Text.Length; if (len >= 3) { string last = entry.Text.Substring(len - 2); if (last == "AM") { int pos = entry.Text.Length - 2; entry.DeleteText(pos, pos + 2); entry.InsertText("PM", ref pos); } else if (last == "PM") { int pos = entry.Text.Length - 3; entry.DeleteText(pos, pos + 3); } else { int pos = entry.Text.Length; entry.InsertText(" PM", ref pos); } } else { int pos = entry.Text.Length; entry.InsertText(" PM", ref pos); } }; } else { pm.buttonColor = "grey1"; } fix.Put(pm, 55, 240); KeyButton am = new KeyButton("AM", null); if (timeInput) { am.ButtonReleaseEvent += (o, args) => { int len = entry.Text.Length; if (len >= 3) { string last = entry.Text.Substring(len - 2); if (last == "PM") { int pos = entry.Text.Length - 2; entry.DeleteText(pos, pos + 2); entry.InsertText("AM", ref pos); } else if (last == "AM") { int pos = entry.Text.Length - 3; entry.DeleteText(pos, pos + 3); } else { int pos = entry.Text.Length; entry.InsertText(" AM", ref pos); } } else { int pos = entry.Text.Length; entry.InsertText(" AM", ref pos); } }; } else { am.buttonColor = "grey1"; } fix.Put(am, 105, 240); KeyButton cancel = new KeyButton("Cancel", null); cancel.textSize = 9; cancel.ButtonReleaseEvent += (o, args) => { Destroy(); }; fix.Put(cancel, 155, 240); TouchButton enter = new TouchButton(); enter.text = Convert.ToChar(0x23CE).ToString(); enter.HeightRequest = 95; enter.ButtonReleaseEvent += (o, a) => { var args = new TextSetEventArgs(entry.Text); TextSetEvent?.Invoke(this, args); if (args.keepText) { Destroy(); } }; fix.Put(enter, 155, 140); foreach (Widget w in Children) { Remove(w); w.Dispose(); } Add(fix); fix.ShowAll(); Show(); }
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(); } } } }