cancel
Showing results for 
Search instead for 
Did you mean: 

Is there Gfx interface to get screen/display size ?

ferro
Senior III

Hi,

I cannot find API to get display height/width. Is there any ? I tried to find something like

int16_t touchgfx::HAL::GetDisplayHeight ();
int16_t touchgfx::HAL::GetDisplayWidth ();

 

In GfxDesigner I see 240x320 values:

ferro_0-1718709907284.png

 

In TouchGFXConfiguration.cpp there is display initialisation:

static TouchGFXHAL hal ( dma, display, tc, 240, 320 );

SimConstants.hpp contains

static unsigned short SIM_WIDTH = 240;
static unsigned short SIM_HEIGHT = 320;

 

Thanks

Ferro

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Hello @ferro ,

 

So you need a define?

I have found a few defines but they seem to not be used for every project:

ft5336.h seems to be a driver or a library related to the screen used:
GaetanGodart_0-1718809205455.png

 

stm32746g_discovery_camera.c is clearly related to the mcu:

GaetanGodart_2-1718809344062.png

 

SDL_test_common.h seems the most promising but I don't know what is PSP and why it is not declared there.
Also, SDL is used for the simulator :

GaetanGodart_3-1718809463171.png

 

SimConstants.hpp is generated by TouchGFX and accessible "in his scope" so this might be your best bet.
Since it is a static unsigned short, can you use it in your expression?

GaetanGodart_4-1718809572799.png

 

The value is also available in the .ioc and .touchgfx files:

GaetanGodart_5-1718809757824.png

 

I hope this helps you, I am not sure what you need.

 

Regards,

Gaetan Godart
Software engineer at ST (TouchGFX)

View solution in original post

7 REPLIES 7
GaetanGodart
ST Employee

Hello @ferro ,

 

You can use getScreenHeight() and getScreenWidth() (no need to put anything in front of those methods).
See : classtouchgfx_1_1_screen 

 

Regards,

Gaetan Godart
Software engineer at ST (TouchGFX)

Thanks @GaetanGodart ,

this is close but not enough.

>"no need to put anything in front of those methods"

This is true only when within methods of a gfx::Screen derived class or having an instance of it.

Implementation of Screen::getScreenHeight () looked promissing

ferro_0-1718714986885.png

however, it is a variable

ferro_1-1718715056461.png

So cannot be used with compile-time expressions e.g.

static constexpr int DisplayNumberOfPixels { HAL::DISPLAY_HEIGHT * HAL::DISPLAY_WIDTH };

Best,

Hello @ferro ,

 

So you need a define?

I have found a few defines but they seem to not be used for every project:

ft5336.h seems to be a driver or a library related to the screen used:
GaetanGodart_0-1718809205455.png

 

stm32746g_discovery_camera.c is clearly related to the mcu:

GaetanGodart_2-1718809344062.png

 

SDL_test_common.h seems the most promising but I don't know what is PSP and why it is not declared there.
Also, SDL is used for the simulator :

GaetanGodart_3-1718809463171.png

 

SimConstants.hpp is generated by TouchGFX and accessible "in his scope" so this might be your best bet.
Since it is a static unsigned short, can you use it in your expression?

GaetanGodart_4-1718809572799.png

 

The value is also available in the .ioc and .touchgfx files:

GaetanGodart_5-1718809757824.png

 

I hope this helps you, I am not sure what you need.

 

Regards,

Gaetan Godart
Software engineer at ST (TouchGFX)

Hi @GaetanGodart 

>"So you need a define?"
Good question. Yes, I need defines. I realised I did not say that clearly in my OP. Sorry.

I want to have a widget parameters to be calculated at compile time e.g.:

struct rect_t
{
	int16_t x;
	int16_t y;
	int16_t xw;
	int16_t yh;
};

static constexpr rect_t Position
{
	20,
	20,
	WIDTH_DEFINE_GENERATED_BY_GFX_DESIGNER   - (2*20),
	HEIGHT_DEFINE_GENERATED_BY_GFX_DESIGNER  - (2*20)
};


I hoped that GfxDesigner auto-generates defines I could use in my scenario, but it does not.

I think it should and then use these defines in all auto-generated code as well which, in my case 320x240, looks e.g. like this:

ScreenViewBase
::ScreenViewBase ()
{
    __background.setPosition(0, 0, 320, 240);
    __background.setColor(touchgfx::Color::getColorFromRGB(0, 0, 0));
    add(__background);

    // ...
}

 

 

GaetanGodart
ST Employee

Hello @ferro ,

 

The SimConstants.hpp file does seem to have this information.
It is just unfortunate that we don't clearly refer to a constant for the various generated functions that require the screen size.

Have you tried accessing SIM_WIDTH and height from SimConstants.hpp?
Even if this file seems to only be used for simulation, I expect it to still exist and be accessible when compiling for the target.

You have selected my last comment as best answer. Were you able to solve your problem?

 

Regards,

Gaetan Godart
Software engineer at ST (TouchGFX)

Hi @GaetanGodart 

>"The SimConstants.hpp file does seem to have this information."

Yes it does, however not marked as 'const(expr)' so cannot be used in compile-time calcs.

 

>"You have selected my last comment as best answer. Were you able to solve your problem?"

Yes, I think the answer is what I want is sth specialized and there are many places where screen size is available as you showed. I'll define my own global height&width.

Thanks for help.

My pleasure! :smiling_face_with_smiling_eyes:

Gaetan Godart
Software engineer at ST (TouchGFX)