Anonymous avatar Anonymous committed 26ff1e3

Added VirtualCanvas reference to widget clicked events
Added multi-widget handling demo to the touchscreen test application

Comments (0)

Files changed (3)

Library/Nwazet.Go.SDT028ATFTLCDTS/Nwazet.Go.SDT028ATFTLCDTS/Imaging/VirtualCanvas.cs

                 foreach (Widget widget in RegisteredWidgets) {
                     widget.OnClickEvent(touchEvent);
                     if (widget.Clicked) {
-                        WidgetClicked(widget, touchEvent);
+                        WidgetClicked(this, widget, touchEvent);
                     }
                 }
             }
         }
         protected void OnWidgetClicked(Widget widget, TouchEvent touchEvent) {
             if (WidgetClicked != null) {
-                WidgetClicked(widget, touchEvent);
+                WidgetClicked(this, widget, touchEvent);
             }
         }
         protected void OnTouch(TouchEvent touchEvent) {

Library/Nwazet.Go.SDT028ATFTLCDTS/Nwazet.Go.SDT028ATFTLCDTS/TouchScreen/Widget.cs

 using Nwazet.Go.Imaging;
 namespace Nwazet.Go.Display.TouchScreen {
-    public delegate void WidgetClickedHandler(Widget widget, TouchEvent touchEvent);
+    public delegate void WidgetClickedHandler(VirtualCanvas canvas, Widget widget, TouchEvent touchEvent);
     public class Widget : IClickable {
         public int ID { get; set; }
         private bool _active;

Samples/DisplayModule/DisplayModuleTest/Program.cs

             CalibrateTouchscreen(canvas);
             BmpImageTest(canvas);
             BasicUITest(canvas);
+            MultiWidgetTest(canvas);
             DisplayRawImageTest(canvas);
             BasicTouchEventTest(canvas);
             TouchscreenAlphanumericDialogTest(canvas);
 
             canvas.Reboot();
+            Thread.Sleep(1000);
+
             canvas.Dispose();
         }
         public static void CalibrateTouchscreen(VirtualCanvas canvas) {
             lastTouchX = touchEvent.X;
             lastTouchY = touchEvent.Y;
         }
-        public static void WidgetClickedHandler(Widget widget, TouchEvent touchEvent) {
+        public static void WidgetClickedHandler(VirtualCanvas canvas, Widget widget, TouchEvent touchEvent) {
         }
         public static void BasicTouchEventTest(VirtualCanvas canvas) {
             var message = "Touch Event Test";
             canvas.Execute();
             canvas.UnRegisterWidget(button);
         }
+        public static void MultiWidgetTest(VirtualCanvas canvas) {
+            canvas.SetOrientation(Orientation.Landscape);
+            canvas.DrawFill(ColorHelpers.GetRGB24toRGB565(255, 255, 255));
+            
+            var fontInfo = new DejaVuSans9().GetFontInfo();
+            
+            var redButton = new ButtonWidget(10, 204, 44, 22, fontInfo, "Red");
+            redButton.FillColor = ColorHelpers.GetRGB24toRGB565(255, 0, 0);
+            redButton.FillColorClicked = ColorHelpers.GetRGB24toRGB565(255, 255, 255);
+            redButton.FontColorClicked = ColorHelpers.GetRGB24toRGB565(255, 0, 0);
+
+            var greenButton = new ButtonWidget(60, 204, 44, 22, fontInfo, "Green");
+            greenButton.FillColor = ColorHelpers.GetRGB24toRGB565(0, 255, 0);
+            greenButton.FillColorClicked = ColorHelpers.GetRGB24toRGB565(255, 255, 255);
+            greenButton.FontColorClicked = ColorHelpers.GetRGB24toRGB565(0, 255, 0);
+
+            var blueButton = new ButtonWidget(110, 204, 44, 22, fontInfo, "Blue");
+            blueButton.FillColor = ColorHelpers.GetRGB24toRGB565(0, 0, 255);
+            blueButton.FillColorClicked = ColorHelpers.GetRGB24toRGB565(255, 255, 255);
+            blueButton.FontColorClicked = ColorHelpers.GetRGB24toRGB565(0, 0, 255);
+
+            var continueButton = new ButtonWidget(247, 204, 64, 22, fontInfo, "Continue");
+            continueButton.FillColor = ColorHelpers.GetRGB24toRGB565(255, 255, 255);
+            continueButton.FontColorClicked = ColorHelpers.GetRGB24toRGB565(0, 0, 0);
+
+            canvas.RegisterWidget(redButton);
+            canvas.RegisterWidget(greenButton);
+            canvas.RegisterWidget(blueButton);
+            canvas.RegisterWidget(continueButton);
+
+            canvas.WidgetClicked += ColorButtonsClickedHandler;
+
+            canvas.RenderWidgets();
+
+            while (!continueButton.Clicked) {
+                canvas.ActivateWidgets(true);
+                canvas.RenderWidgets();
+                canvas.Execute();
+
+                canvas.TouchscreenWaitForEvent();
+
+                canvas.RenderWidgets(Render.All);
+                canvas.Execute();
+            }
+
+            canvas.WidgetClicked -= ColorButtonsClickedHandler;
+
+            continueButton.Dirty = true;
+            continueButton.Draw(canvas);
+            canvas.Execute();
+
+            canvas.UnRegisterAllWidgets();
+        }
+        public static void ColorButtonsClickedHandler(VirtualCanvas canvas, Widget widget, TouchEvent touchEvent) {
+            widget.Dirty = true;
+            canvas.DrawFill(((ButtonWidget)widget).FillColor);
+        }
         public static void DisplayRawImageTest(VirtualCanvas canvas) {
+            canvas.SetOrientation(Orientation.Portrait);
             canvas.DrawFill(ColorHelpers.GetRGB24toRGB565(0, 0, 0));
             canvas.DrawBitmapImageRaw(90, 115, 60, 89, rawBmp);
             canvas.TouchscreenWaitForEvent();
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.