Step 3: Build Display Screen Using MPLAB® Harmony Graphics Composer (MHGC)

Last modified by Microchip on 2024/02/06 14:34

Open MHGC and Set Up the Initial Display Screen

Open the MPLAB® Harmony Graphics Composer (MHGC) utility.

To do this, expand the MHC > Tools selection and click on Graphics Composer.

Tools - Graphics Composer

A Welcome Dialog screen will appear. Click Use design loaded from current MHC configuration or just close the screen to start.

Graphics composer opens

The MPLAB Harmony Graphics Composer screen will be displayed as shown in the accompanying image.

Graphics composer screen

Back to Top


Change the screen name.

In the Screens window, double-click on the Name field and replace the name with "MchpMainScreen".

Screens pane

Import Graphic Images

Copy the Icons folder from this folder:
apps/training/solutions/audio_player/audio_player_lab5/dev_files
to this one:
apps/training/solutions/dev/audio_player/audio_player_lab5.

Back to Top


In MHGC, open the Image Assets screen by clicking the Asset tab and selecting Images.

Asset tag drop down menu

Back to Top


Select each image individually by clicking on the file name from the Icons folder. Add all three images to assets.

Image Assets pane

Back to Top


Keep the default settings for each image except for MCHP_LOGO.bmp. For this image, we want to mask the background color that is not part of the logo design. Check the Color Masking box and set the RGB values of the Mask Color to 29,46,60. This happens to be the RGB values of the background in the image.

Image Assets pane

Back to Top

Import Fonts

In this step, we will add two system fonts, Arial14pt and Arial18pt.

In MHGC, open the Font Assets screen by clicking the Asset tab and selecting Fonts.

Asset tag drop down menu

Back to Top


Select the icon to Add Installed Font. This will bring up a screen that allows you to select a font installed in your system. Select the Arial font and press Ok.

add Arial font

Back to Top


This will bring up a screen that allows you to configure different properties of the font. Select the Style tab and choose a size of 14.

choose font size 14

Back to Top


Now, select the Glyphs tab and click the add icon to add a glyph range. For Arial14pt, we want the Basic Latin range of characters, number 32 to 127. Then press the Ok button.

add a glyph range

Back to Top


Finally, we want to rename this font from the default name to Arial14pt. Click on the font and select the Rename Selected Font icon. Then input Arial14pt and press Ok.

rename this font from the default name to Arial14pt

Back to Top


Similarly, repeat the above steps to add the Arial18pt font. Except for the range values, we only want to add one character, a caret. This will be used by the ScrollUpButton.

repeat the above steps to add the Arial18pt font

Select size of 18.

​ Select size of 18.    ​

Select a starting and ending character of 94. This is the caret character (^).

Select a starting and ending character of 94

Rename the font to Arial18pt.

​ Rename the font to Arial18pt.    ​

Back to Top

Create Color Schemes

Create color schemes to standardize the look and feel of the user interface. These will be used for the display widgets created in the following steps on this page. You can add color schemes in the Schemes window by clicking on the Add icon.

Schemes pane

Add the color schemes listed below. Change the name field by typing over the existing name field. The color can be changed by clicking the icon to the right. This will bring up a color selection screen that will allow you to enter the RGB values.

Add the color schemes

Add the color schemes

Add the color schemes

Add the color schemes

Add Text Strings

In MHGC, open the String Assets screen by clicking the Asset tab and selecting Strings.

Asset tag drop down menu

Back to Top


Select the icon to Add New String. This will bring up the Add String Dialog box. Enter the name of the string. This is a name used to reference the string and not the string value itself.

Add String Dialog

Back to Top


Now, we can enter the actual string text. Click in the value field to enter the text. Then click in the font field to get a dropdown menu of available fonts.

string assets pane

Back to Top


Do this for each of the strings listed in the table. Make sure that the ScrollUp string has the Arial18pt font.

NameValueFont
GroupBoxTitleModeArial14pt
NoFilesMessageNo Audio Files Found. Please Select Reader Mode to Load.Arial14pt
RadioButtonPlayerPlayerArial14pt
RadioButtonReaderReaderArial14pt
ScrollDownvArial14pt
ScrollUp^Arial18pt
TitleStringHarmony SD Card Audio Player / ReaderArial14pt

Back to Top


Once complete, you should have all of the strings listed in the accompanying image.

string assets pane

Back to Top

Create Static Logo and Title Fields

In MHGC, click on Layer0 in the Tree View window.

click on Layer0 in the Tree View window.

This should bring up the properties for Layer0 in the Properties Editor window. Change the color scheme to BackgroundScheme and check the Transparency Enabled box.

Properties Editor

Back to Top


Add a gradient box to highlight the logo image. Click and drag the Gradient widget from the Widget Tool Box window onto the screen image. Then, use the Properties Editor window to specify the detail placement and properties of the widget.

Screen Designer - MchpMainScreen drag gradient widget
Properties Editor

Back to Top


Add an image box to display the logo image. Click and drag the Image widget onto the screen. Change the properties as specified in the accompanying image. In the Image field, select the graphics image imported from the previous step.

Screen Designer - MchpMainScreen drag image widget
Properties Editor

Back to Top


Add a text box to display the application title. Click and drag a Text Field widget onto the display screen. Change the properties as specified in the accompanying image.

Screen Designer - MchpMainScreen drag text field widget
Properties Editor

Back to Top


Add a text box to provide the ability to display an error message. Click and drag a Text Field widget onto the display screen. Change the properties as specified in the accompanying image.

Screen Designer - MchpMainScreen drag text field widget
Properties Editor

Back to Top

Create Radio Button Group Box

Add a group box for the radio buttons. Click and drag a Group Box widget onto the display screen. Change the properties as specified in the accompanying image.

Screen Designer - MchpMainScreen drag box widget
Properties Editor

Back to Top


Add a Radio button for Player mode. Click and drag a Radio Button widget onto the display screen. Change the properties as specified in the accompanying image.

Screen Designer - MchpMainScreen drag radio button widget
Properties Editor

For this widget, we need to add action code that will be executed when the button is selected. Click on the icon next to the Selected field. This will bring up a screen where you can add the action code text shown in the accompanying image.

Action Edit Dialog

laWidget_SetEnabled(&(TrackListBox->widget), true);
laWidget_SetEnabled(&(ScrollUpButton->widget), true);
laWidget_SetEnabled(&(ScrollDownButton->widget), true);
laWidget_SetEnabled(&(MessageTextBox->editWidget.widget), true);
laWidget_SetEnabled(&(VolButton->widget), true);
laWidget_SetEnabled(&(VolSlider->widget), true);

APP_DISPLAY_ModeSet(0);

Back to Top


Add another Radio button for Reader mode. Click and drag a Radio Button widget onto the display screen. Change the properties as specified in the accompanying image.

Screen Designer - MchpMainScreen drag radio button widget
Properties Editor

Similar to the previous radio button, add the action code shown in the accompanying image to the Selected field.

Action Edit Dialog

laWidget_SetEnabled(&(TrackListBox->widget), false);
laWidget_SetEnabled(&(ScrollUpButton->widget), false);
laWidget_SetEnabled(&(ScrollDownButton->widget), false);
laWidget_SetEnabled(&(MessageTextBox->editWidget.widget), false);
laWidget_SetEnabled(&(VolButton->widget), false);
laWidget_SetEnabled(&(VolSlider->widget), false);

APP_DISPLAY_ModeSet(1);

Back to Top

Create Play List Box

Add a list box to display the list of files from the SD card. Click and drag a List widget onto the display screen. Change the properties as specified in the accompanying image.

Screen Designer - MchpMainScreen drag list widget
Properties Editor

Click on the icon next to the Selection Changed field. This will allow you to add action code when the list box selection changes.

Action Edit Dialog

if (selected && idx <= laListWidget_GetItemCount(img))
{
    APP_SDCARD_AUDIO_RandomTrackSet(APP_DISPLAY_XlatListIdx(idx));
}

Back to Top


Add a ScrollUp button for the list box. Click and drag a Button widget onto the display screen. Change the properties as specified in the accompanying image.

Screen Designer - MchpMainScreen drag button widget
Properties Editor

Add action code for the button Released action.

Action Edit Dialog

APP_DISPLAY_ScrollUp();

Back to Top


Add a ScrollDown button for the list box. Click and drag a Button widget onto the display screen. Change the properties as specified in the accompanying image.

Screen Designer - MchpMainScreen drag button widget
Properties Editor

Add action code for the button Released action.

Action Edit Dialog

APP_DISPLAY_ScrollDown();

Back to Top

Create Volume Control Items

Add a rectangle border to go around the volume slider. Click and drag a Rectangle widget onto the display screen. Change the properties as specified in the accompanying image.

Screen Designer - MchpMainScreen drag rectangle widget
Properties Editor

Back to Top


Add the volume slider to change the output volume from minimum to maximum. Click and drag a Slider widget onto the display screen. Change the properties as specified in the accompanying image.

Screen Designer - MchpMainScreen drag slider widget
Properties Editor

Add action code to control input from the volume slider as shown in the accompanying image.

add action code

APP_DISPLAY_VolumeMuteChange(2);

Back to Top


Add volume button that can mute and unmute the sound. Click and drag a Button widget onto the display screen. Change the properties as specified in the accompanying image.

Screen Designer - MchpMainScreen dragging button widget
Properties Editor

Add action code to unmute the sound (button pressed) as shown in the accompanying image.

Action Edit Dialog unmute

Add action code to mute the sound (button released) as shown in the accompanying image.

Action Edit Dialog mute

APP_DISPLAY_VolumeMuteChange(1);
APP_DISPLAY_VolumeMuteChange(0);

Back to Top


The final screen image should appear as shown in the accompanying image.

The final screen image

Back to Top