Ensemble Graphics Toolkit: Resource Files

Last modified by Microchip on 2023/11/09 09:10

Introduction

In this training topic you will learn how to add a Resource File to your Ensemble Graphics Toolkit project. A Resource File can be an image, audio or video file or an icon.


Prerequisites

You have prepared the Host PC with all the development software tools and Ensemble Graphics Toolkit source code as explained in:

You have installed and prepared the Eclipse IDE for C/C++ Developers as explained in:

You have performed the exercises in:

Back to Top


Resource File

In this section, you will modify the timer.cpp source code that you entered in the training topic Ensemble Graphics Toolkit: Animation Part 2 to construct an animation sequence by adding a *.png image to your application

In this training topic, you will use EgtProject and its settings you entered in the training topic: Ensemble Graphics Toolkit: Animation Part 2

Modify the timer.cpp source code by adding the following lines of code as shown below:

#include <egt/ui>
#include
<iostream>
using namespace std;
using namespace egt;

int main(int argc, const char ** argv)
{
    Application app;
    TopWindow window;
    Button button(window, "Press Me");
    center(button);

   //One-shot timer
   Timer timer1(std::chrono::seconds(3));
    timer1.on_timeout(
    {
        cout << "One shot timer fired!" << endl;
    });
    timer1.start();

   //periodic timer
   Label CPUlabel("CPU:---", Rect(0, 0, 100, 50));
    window.add(bottom(CPUlabel));
    egt::experimental::CPUMonitorUsage tools;
    PeriodicTimer cputimer(std::chrono::seconds(1));
    cputimer.on_timeout([ & CPUlabel, & tools]() {
        cout << "periodic timer fired!" << endl;
        tools.update();
        ostringstream ss;
        ss << "CPU: " << static_cast < int > (tools.usage()) << "%";
        CPUlabel.text(ss.str());
    });
    cputimer.start();

   //PropertyAnimator
   Label label("Ensemble Graphics Toolkit”, Rect(20, 100, 200, 50), AlignFlag::center);
    label.font(Font(35));
    window.add(label);

    PropertyAnimator animate1(window.width(), 200,
        std::chrono::seconds(5), easing_bounce);
    animate1.on_change([ & label](int value) {
        label.x(value);
    });
//    animate1.start();

   // Animation Sequence
   int min_value = 0 - label.width();
    PropertyAnimator animate2(200, min_value,
        std::chrono::seconds(5), easing_linear);
    animate2.on_change([ & label](int value)
    {
        label.x(value);
    });

    AnimationDelay delay(std::chrono::seconds(1));
    AnimationSequence sequence(true);
    sequence.add(animate1);
    sequence.add(delay);
    sequence.add(animate2);
    sequence.start();

   // Video
   window.background(Image("file:background.png"));

    window.show();
   return app.run();
}

Save your program by selecting File > Save. You may also save by typing CTRL+S.

To build the project, hover over EgtProject, right-click, and select Build Project from the menu. Or you can click on the Build icon.

The Console window (bottom pane) will display the build progress.


Before running the application, we should make sure the *.png file is in the search path.

The source code you entered above will look for the image in the same folder as the executable.

Click on the Run button.

Observe the WVGA Display on the target:

The timer.cpp executable is running remotely on the target.

Observe the animated background.png file.


Animated background.png file on WVGA Display

Resources

From ~/egt/docs/html/annotated.html, click on the Resources.

Here is a detailed discussion on the resource file paths called as respath and different ways you can access the resource file. Resource file can be an image, audio or video file or an icon.

To stop the program, press the Stop button (upper left hand, just below the menu bar).

Before you start another session, be sure to Stop the current session.

Back to Top


Summary

In this training, you learned how to construct add a Resource File to your EGT project. A Resource File can be an image, audio or video file or an icon.

Back to Top

What’s Next?

There’s plenty more to learn. Here are some additional Ensemble Graphics Toolkit training topics to help you gain more knowledge and skills:

Back to Top