Clean up event handling for the dialog
David Blume

David Blume commited on 2015-12-11 17:35:02
Showing 1 changed files, with 10 additions and 7 deletions.

... ...
@@ -43,6 +43,7 @@ sub main()
43 43
             else if (button = 10)  ' Info button
44 44
                 display_dialog()
45 45
                 ' TODO: Fix a bug where the dialog doesn't go away
46
+                m.screen.DrawScaledObject(0, 0, m.scaleX, m.scaleY, m.currentBitmap)
46 47
             end if
47 48
         end if
48 49
 
... ...
@@ -55,12 +56,13 @@ function display_dialog()
55 56
 
56 57
     ' First, create an roImageCanvas to live behind the dialog
57 58
     canvas = CreateObject("roImageCanvas")
58
-    canvas.SetMessagePort(CreateObject("roMessagePort"))
59
+    message_port = CreateObject("roMessagePort")
60
+    canvas.SetMessagePort(message_port)
59 61
     canvas.SetLayer(0, {Color:"#00000000", CompositionMode:"Source_Over"})  ' Transparent
60 62
     canvas.Show()
61 63
 
62 64
     dialog = CreateObject("roPinEntryDialog")
63
-    dialog.SetMessagePort(CreateObject("roMessagePort"))
65
+    dialog.SetMessagePort(message_port)
64 66
     dialog.EnableOverlay(true)
65 67
     dialog.EnableBackButton(true)
66 68
     dialog.SetNumPinEntryFields(4)
... ...
@@ -70,24 +72,25 @@ function display_dialog()
70 72
     dialog.Show()
71 73
     while True
72 74
         msg = wait(0, dialog.GetMessagePort())
73
-        if msg <> invalid
75
+        if msg <> invalid and type(msg) = "roPinEntryDialogEvent"
74 76
             print "msg is "; msg
75 77
             if msg.isScreenClosed()
76
-                print "msg is isScreenClosed"; msg
78
+                print "msg is isScreenClosed"; msg; type(msg)
77 79
                 exit while
78 80
             else if msg.isButtonPressed()
79 81
                 print "the index of the button pressed is"; msg.GetIndex()
80 82
                 if msg.GetIndex() = 1
81
-                    print "The user entereded PIN "; dialog.Pin()
83
+                    print "The user entered PIN "; dialog.Pin()
84
+                    dialog.Close()
82 85
                 else if msg.GetIndex() = 99
83 86
                     print "The user cancelled."
87
+                    dialog.Close()
84 88
                 endif
85
-                exit while
86 89
             end if
87 90
         end if
88 91
     end while
89
-    dialog.Close()
90 92
     canvas.Close()
93
+    print "After closing the dialog and canvas."
91 94
     
92 95
 end function
93 96
 
94 97