Author Topic: Mastering InForm: Click Response for Controls and for Screen Incompatibility  (Read 16552 times)

0 Members and 1 Guest are viewing this topic.

Offline Qwerkey

  • Forum Resident
  • Posts: 755
I am creating an InForm Mahjong Game (an Update of my existing program to InForm), and using hardware images put to the Form to display the Mahjong board and tiles.  So the game requires that you can click on the screen (as normal) to manipulate the tiles and also to click on the buttons to get other functions.  What I am finding is that you can either click on the screen or click on the buttons, but not both.  Running the program “QB64Mahjong.bas”, first you have to click on the button labelled “Start” and then click on the displayed Mouse with normal and then opposite mouse buttons (this is a routine that will set the program to know which buttons to react to in the running program – this routine is not yet implemented).  Then the tiles are displayed and you can click on appropriate tiles to match them.  However, none of the Buttons (Save/NewGame/Exit) are clickable until Esc is pressed.  Then the buttons are clickable but then the Mahjong game has stopped.

Am I able to allow both types of clicking at the same time?  Richard
* QB64 Mahjong.zip (Filesize: 510.35 KB, Downloads: 258)

FellippeHeitor

  • Guest
You should not be polling mouse data yourself, as InForm already does that in the background.

Your clicks should be processed in the __UI_Click event, reacting to the form's ID. Then you read __UI_MouseLeft and __UI_MouseTop.

Try running this example code. It's an empty form and each click on the form's surface will create a new button:

Code: QB64: [Select]
  1. ': This program uses
  2. ': InForm - GUI library for QB64 - Beta version 7
  3. ': Fellippe Heitor, 2016-2018 - fellippe@qb64.org - @fellippeheitor
  4. ': https://github.com/FellippeHeitor/InForm
  5. '-----------------------------------------------------------
  6.  
  7. ': Controls' IDs: ------------------------------------------------------------------
  8. DIM SHARED ClickMEform AS LONG
  9.  
  10. ': External modules: ---------------------------------------------------------------
  11. '$INCLUDE:'InForm\InForm.ui'
  12. '$INCLUDE:'InForm\xp.uitheme'
  13.  
  14. ': Form: ---------------------------------------------------------------------------
  15. SUB __UI_LoadForm
  16.  
  17.     DIM __UI_NewID AS LONG
  18.  
  19.     __UI_NewID = __UI_NewControl(__UI_Type_Form, "ClickMEform", 392, 478, 0, 0, 0)
  20.     SetCaption __UI_NewID, "ClickMEform"
  21.     Control(__UI_NewID).Font = SetFont("segoeui.ttf", 12)
  22.  
  23.  
  24. SUB __UI_AssignIDs
  25.     ClickMEform = __UI_GetID("ClickMEform")
  26.  
  27. ': Event procedures: ---------------------------------------------------------------
  28. SUB __UI_BeforeInit
  29.  
  30.  
  31. SUB __UI_OnLoad
  32.  
  33.  
  34. SUB __UI_BeforeUpdateDisplay
  35.     'This event occurs at approximately 30 frames per second.
  36.     'You can change the update frequency by calling SetFrameRate DesiredRate%
  37.  
  38.  
  39. SUB __UI_BeforeUnload
  40.     'If you set __UI_UnloadSignal = False here you can
  41.     'cancel the user's request to close.
  42.  
  43.  
  44. SUB __UI_Click (id AS LONG)
  45.     SELECT CASE id
  46.         CASE ClickMEform
  47.             temp = __UI_NewControl(__UI_Type_Button, "", 20, 20, __UI_MouseLeft, __UI_MouseTop, 0)
  48.     END SELECT
  49.  
  50. SUB __UI_MouseEnter (id AS LONG)
  51.     SELECT CASE id
  52.         CASE ClickMEform
  53.  
  54.     END SELECT
  55.  
  56. SUB __UI_MouseLeave (id AS LONG)
  57.     SELECT CASE id
  58.         CASE ClickMEform
  59.  
  60.     END SELECT
  61.  
  62. SUB __UI_FocusIn (id AS LONG)
  63.     SELECT CASE id
  64.     END SELECT
  65.  
  66. SUB __UI_FocusOut (id AS LONG)
  67.     'This event occurs right before a control loses focus.
  68.     'To prevent a control from losing focus, set __UI_KeepFocus = True below.
  69.     SELECT CASE id
  70.     END SELECT
  71.  
  72. SUB __UI_MouseDown (id AS LONG)
  73.     SELECT CASE id
  74.         CASE ClickMEform
  75.  
  76.     END SELECT
  77.  
  78. SUB __UI_MouseUp (id AS LONG)
  79.     SELECT CASE id
  80.         CASE ClickMEform
  81.  
  82.     END SELECT
  83.  
  84. SUB __UI_KeyPress (id AS LONG)
  85.     'When this event is fired, __UI_KeyHit will contain the code of the key hit.
  86.     'You can change it and even cancel it by making it = 0
  87.     SELECT CASE id
  88.     END SELECT
  89.  
  90. SUB __UI_TextChanged (id AS LONG)
  91.     SELECT CASE id
  92.     END SELECT
  93.  
  94. SUB __UI_ValueChanged (id AS LONG)
  95.     SELECT CASE id
  96.     END SELECT
  97.  
  98. SUB __UI_FormResized
  99.  
  100.  
« Last Edit: September 20, 2018, 03:31:23 pm by FellippeHeitor »

Offline Qwerkey

  • Forum Resident
  • Posts: 755
Oh, I hadn't appreciated that you can't do normal Mouse polling as well as InForm's Mouse control.  As you can use INKEY$ as well as __UI_KeyHit, I was assuming a similar thing for the Mouse.

My program requires sampling the cursor position continuously without any Click events, to get and use _MOUSEX & _MOUSEY.  The only InForm Mouse procedures (?) are __UI_MouseUp/Down & __UI_MouseEnter/Leave.  Am I allowed to sample _MOUSEINPUT and get _MOUSEX & _MOUSEY?  What are __UI_MouseLeft & __UI_MouseTop? This would imply MouseWidth & MouseHeight???

Also, the program (as is) uses opposite Mouse Button Click for an Undo routine.  Is this allowed in InForm (I don't see any Wiki on it)?  If not allowed, I'd have to have another Button Control for Undo which would be acceptable.

Please forgive the level of ignorance!  Richard

Offline Qwerkey

  • Forum Resident
  • Posts: 755
Am I allowed to sample _MOUSEINPUT and get _MOUSEX & _MOUSEY?  What are __UI_MouseLeft & __UI_MouseTop? This would imply MouseWidth & MouseHeight???

Oops! I've answered that myself.  Just tried commenting out all WHILE _MOUSEINPUT loops and getting __UI_MouseLeft & __UI_MouseTop directly - they're exactly equivalent to _MOUSEX & _MOUSEY and the program no longer latches up the ButtonControls.

So, all I need now is Opposite Mouse Button Click.  Richard

FellippeHeitor

  • Guest
Use __UI_MouseButton1 and __UI_MouseButton2.

Try this: Left click to add a button, Right click to add a ToggleSwitch:

Code: QB64: [Select]
  1. ': This program uses
  2. ': InForm - GUI library for QB64 - Beta version 7
  3. ': Fellippe Heitor, 2016-2018 - fellippe@qb64.org - @fellippeheitor
  4. ': https://github.com/FellippeHeitor/InForm
  5. '-----------------------------------------------------------
  6.  
  7. ': Controls' IDs: ------------------------------------------------------------------
  8. DIM SHARED ClickMEform AS LONG
  9.  
  10. ': External modules: ---------------------------------------------------------------
  11. '$INCLUDE:'InForm\InForm.ui'
  12. '$INCLUDE:'InForm\xp.uitheme'
  13.  
  14. ': Form: ---------------------------------------------------------------------------
  15. SUB __UI_LoadForm
  16.  
  17.     DIM __UI_NewID AS LONG
  18.  
  19.     __UI_NewID = __UI_NewControl(__UI_Type_Form, "ClickMEform", 392, 478, 0, 0, 0)
  20.     SetCaption __UI_NewID, "ClickMEform"
  21.     Control(__UI_NewID).Font = SetFont("segoeui.ttf", 12)
  22.  
  23.  
  24. SUB __UI_AssignIDs
  25.     ClickMEform = __UI_GetID("ClickMEform")
  26.  
  27. ': Event procedures: ---------------------------------------------------------------
  28. SUB __UI_BeforeInit
  29.  
  30.  
  31. SUB __UI_OnLoad
  32.  
  33.  
  34. SUB __UI_BeforeUpdateDisplay
  35.     'This event occurs at approximately 30 frames per second.
  36.     'You can change the update frequency by calling SetFrameRate DesiredRate%
  37.  
  38.     IF __UI_MouseButton1 THEN
  39.         temp = __UI_NewControl(__UI_Type_Button, "", 20, 20, __UI_MouseLeft, __UI_MouseTop, 0)
  40.         DO WHILE __UI_MouseButton1: _LIMIT 30: LOOP
  41.         Caption(__UI_FormID) = STR$(temp)
  42.     ELSEIF __UI_MouseButton2 THEN
  43.         temp = __UI_NewControl(__UI_Type_ToggleSwitch, "", 20, 20, __UI_MouseLeft, __UI_MouseTop, 0)
  44.         DO WHILE __UI_MouseButton2: _LIMIT 30: LOOP
  45.         Caption(__UI_FormID) = STR$(temp)
  46.     END IF
  47.  
  48.  
  49. SUB __UI_BeforeUnload
  50.     'If you set __UI_UnloadSignal = False here you can
  51.     'cancel the user's request to close.
  52.  
  53.  
  54. SUB __UI_Click (id AS LONG)
  55.     SELECT CASE id
  56.         CASE ClickMEform
  57.  
  58.     END SELECT
  59.  
  60. SUB __UI_MouseEnter (id AS LONG)
  61.     SELECT CASE id
  62.         CASE ClickMEform
  63.  
  64.     END SELECT
  65.  
  66. SUB __UI_MouseLeave (id AS LONG)
  67.     SELECT CASE id
  68.         CASE ClickMEform
  69.  
  70.     END SELECT
  71.  
  72. SUB __UI_FocusIn (id AS LONG)
  73.     SELECT CASE id
  74.     END SELECT
  75.  
  76. SUB __UI_FocusOut (id AS LONG)
  77.     'This event occurs right before a control loses focus.
  78.     'To prevent a control from losing focus, set __UI_KeepFocus = True below.
  79.     SELECT CASE id
  80.     END SELECT
  81.  
  82. SUB __UI_MouseDown (id AS LONG)
  83.     SELECT CASE id
  84.         CASE ClickMEform
  85.  
  86.     END SELECT
  87.  
  88. SUB __UI_MouseUp (id AS LONG)
  89.     SELECT CASE id
  90.         CASE ClickMEform
  91.  
  92.     END SELECT
  93.  
  94. SUB __UI_KeyPress (id AS LONG)
  95.     'When this event is fired, __UI_KeyHit will contain the code of the key hit.
  96.     'You can change it and even cancel it by making it = 0
  97.     SELECT CASE id
  98.     END SELECT
  99.  
  100. SUB __UI_TextChanged (id AS LONG)
  101.     SELECT CASE id
  102.     END SELECT
  103.  
  104. SUB __UI_ValueChanged (id AS LONG)
  105.     SELECT CASE id
  106.     END SELECT
  107.  
  108. SUB __UI_FormResized
  109.  
  110.  
« Last Edit: September 21, 2018, 08:54:40 am by FellippeHeitor »

FellippeHeitor

  • Guest
BTW, these are automatically detected as left/right if you're using Windows.

Offline Qwerkey

  • Forum Resident
  • Posts: 755
Fellippe, thanks.  You're too late, I couldn't wait - have implemented an Undo Button.  Will remember mouse buttons for the future.  Richard