Adding Event to a Graphics Application
This topic provides a step-by-step guide to adding simple event. For this guide we will use the Aria Quickstart demonstration project.
Description This Quick Start tutorial shows how to add a simple event to the Aria Quickstart demonstration’s button. For details on how to load, build, program, and run this project, see MPLAB Harmony Graphics Library Help > Graphics Demonstrations > Demonstrations > aria_quickstart.
The steps are as follows:
- Launch the MPLAB Harmony Configurator:
- Open the project’s default saved state:
When the Configuration Database Setup dialog appears, just hit Launch.
- Select the Graphics Composer from the MHC Pull-Down Menu which will open a new window for the MPLAB Harmony Graphics Composer:
- In step 8, below, we will change the behavior of the screen’s button by adding Pressed and Released events. The Pressed event will change the text of the button. First, we must add the needed text. Select the Asset menu and click Strings.
- Click the Add icon, ), and name the new string “Ouch_String” and then select Create.
- Enter the string value of Ouch! Ouch! Ouch!. Next, Select TimesNewRoman12 as the font . On completion, the screen should show:
When finished, close the String Asset dialog.
- Select the Composer Screen Designer panel and select the **ButtonWidget1 **(“Make changes. Generate. Run”).
- Under the Properties Editor panel on the right side of the screen, the properties of ButtonWidget1 should appear. Enable the Pressed and Released events:
- Click the () button on the right side to bring up the Events Editor for the Pressed event and create a new action.
When the Action Edit dialog appears. Enter the name ButtonPressed and click Next.
- Now select which widget the ButtonPressed event of ButtonWidget1 affects. This event can affect any of the display's widgets. However, the objective is for the ButtonPressed event to change the text of its own widget. Therefore, select ButtonWidget1 and click Next.
- The next dialog window provides instructions to select the action associated with this event. There are many choices, from Adjust Position to Set Y Position, all of which are related to properties of the button widget. Select Set Text as the action, and then click Next.
- In the next Action Edit Dialog window select the Ouch_String from steps 5 and 6, and then click Finish. This action resurfaces the Event Editor - Pressed dialog. Click OK to close this dialog.
- Follow the same steps for the Released event, but instead create a new event named ButtonReleased. Use the same Set Text action as before, but use the Instructions string instead.
- Examine the events the has been created by the Window:Event Manager menu. The Event Manager dialog is an alternative way of creating and managing graphics events for the application.
- Close the Graphics Composer window and save the new design.
In the MPLAB Harmony Configurator (MHC) window save the new configuration, since it has been modified. Generate code for this new project configuration by selecting the Generate icon ( ). Select Overwrite as the Merging Strategy, since we don't need to review all the changes made to the graphics design. The select the Generate button to generate the new code that implements the events that have just been added.
Select the Run Main Project icon ( ) to build, load, and run this new configuration.
After the project has loaded, click the “Make changes. Generate. Run.” button. The button’s text should change to Ouch! Ouch! Ouch! when pressed and revert back to the original text when released.