cancel
Showing results for 
Search instead for 
Did you mean: 

Can not call Interactions when using Screen1View::handleClickEvent function.

HPham.1590
Senior

Hello, I'm working with TouchGFX on STM32F7.

after added Screen1View::handleClickEvent function in Screen1View fiile, I can't call the ButtonCallbackHandle function in Screen1ViewBase file. In my ViewBase file, it has 2 callback function, 1 for Toggle Button and 1 for Slider.

Below is my function, anyone can tell me how to use both of them?

Many thanks.

My Screen1View.cpp file

void Screen1View::handleClickEvent(const ClickEvent& evt)
{
    if (color_wheel.getRect().intersect(Rect(evt.getX(), evt.getY(), 1, 1)))
    {
    	touchgfx_printf("\ncolor_wheel_x = %d",color_wheel.getX());
    	touchgfx_printf(", color_wheel_y = %d",color_wheel.getY());
    	touchgfx_printf("\nevt_x = %d", evt.getX());
    	touchgfx_printf(", evt_y = %d", evt.getY());
        int offsetX = evt.getX() - color_center_x;
        int offsetY = evt.getY() - color_center_y;
        touchgfx_printf("\n offsetX: %d",offsetX);
        touchgfx_printf(" - offsetY: %d",offsetY);
        if (evt.getType() == ClickEvent::PRESSED)
        {
            const uint32_t dist = colorDistancesq(offsetX, offsetY);
            touchgfx_printf("\ndist = %d",dist);
            if (dist < MAX_DIST)
            {
                selectColor(offsetX, offsetY);
//            	selectColor(evt.getX(), evt.getY());
                isDown = true;
            }
        }
    }
    if (evt.getType() == ClickEvent::RELEASED)
    {
        isDown = false;
    }
    if (OnOff.getRect().intersect(Rect(evt.getX(), evt.getY(), 1, 1)))
    {
    	Screen1View::OnOffBtn_Function();
    }
//    Screen1View::handleClickEvent(evt);
}
 
void Screen1View::handleDragEvent(const DragEvent& evt)
{
    if (isDown)
    {
        int offsetX = evt.getNewX() - color_center_x;
        int offsetY = evt.getNewY() - color_center_y;
        const uint32_t dist = colorDistancesq(offsetX, offsetY);
        if (dist < MAX_DIST)
        {
            selectColor(offsetX, offsetY);
        }
        else
        {
            //calculate rim
            float angle = float(atan2(float(offsetY - color_center_y), float(offsetX - color_center_x)));
            selectColor(uint32_t(MAX_RADIUS * cosf(angle) + color_center_x), uint32_t(MAX_RADIUS * sinf(angle) + color_center_y));
        }
    }
//    Screen1View::handleDragEvent(evt);
}

My Screen1ViewBase.cpp file

void Screen1ViewBase::setupScreen()
{
 
}
 
void Screen1ViewBase::buttonCallbackHandler(const touchgfx::AbstractButton& src)
{
    if (&src == &OnOff)
    {
        //Interaction_OnOffBtn
        //When OnOff clicked call virtual function
        //Call OnOffBtn_Function
        OnOffBtn_Function();
    }
}
 
void Screen1ViewBase::sliderValueChangedCallbackHandler(const touchgfx::Slider& src, int value)
{
    if (&src == &slider1)
    {
        //Interaction_Slider
        //When slider1 value changed call virtual function
        //Call Slider_Function
        Slider_Function(value);
    }
}

1 ACCEPTED SOLUTION

Accepted Solutions
Alexandre RENOUX
Principal

Hello,

You should call the handleClickEvent of the Base class at the end of your implementation of handleClickEvent() in your Screen1View.cpp.

Screen1ViewBase::handleClickEvent(evt)

/Alexandre

View solution in original post

3 REPLIES 3
Alexandre RENOUX
Principal

Hello,

You should call the handleClickEvent of the Base class at the end of your implementation of handleClickEvent() in your Screen1View.cpp.

Screen1ViewBase::handleClickEvent(evt)

/Alexandre

Many thanks for your reply.

Can you give me an explanation about this way?

I'm new in touchgfx and although I know that handleClickEvent function is available at ViewBase class (follow official touchgfx documents) but when I entered Screen1ViewBase.hpp and Screen1ViewBase.cpp, both of them dont define this function. Moreover, Screen1ViewBase.cpp is auto generated by TouchGfx Designer, so should I edit this file to define handleClickEvent? In case I can use this function without definition in these files, I want to know about the way this function call buttonCallbackHandler and sliderValueChangedCallbackHandler.

Hieu

Hello,

HandleClickEvent function is not directly implemented in the View Base Class but in Screen.hpp and the View Base inherits the Screen class.

You should never have a need to change Screen1ViewBase.hpp and Screen1ViewBase.cpp as Screen1View inherits the View Base class so you can do everything in Screen1View.hpp and Screen1View.cpp.

Regarding the handleClickEvent propagation, this is done by the Screen class. It basically go through all the drawables that you added to your screen and executes their handleClickEvent() function if it's implemented in them.

/Alexandre