2024-06-18 04:34 AM
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:
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
Solved! Go to Solution.
2024-06-19 08:10 AM
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:
stm32746g_discovery_camera.c is clearly related to the mcu:
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 :
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?
The value is also available in the .ioc and .touchgfx files:
I hope this helps you, I am not sure what you need.
Regards,
2024-06-18 05:38 AM
Hello @ferro ,
You can use getScreenHeight() and getScreenWidth() (no need to put anything in front of those methods).
See : classtouchgfx_1_1_screen
Regards,
2024-06-18 06:02 AM
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
however, it is a variable
So cannot be used with compile-time expressions e.g.
static constexpr int DisplayNumberOfPixels { HAL::DISPLAY_HEIGHT * HAL::DISPLAY_WIDTH };
Best,
2024-06-19 08:10 AM
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:
stm32746g_discovery_camera.c is clearly related to the mcu:
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 :
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?
The value is also available in the .ioc and .touchgfx files:
I hope this helps you, I am not sure what you need.
Regards,
2024-06-19 08:59 AM
>"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);
// ...
}
2024-06-20 01:08 AM
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,
2024-06-20 01:25 AM
>"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.
2024-06-20 02:27 AM
My pleasure! :smiling_face_with_smiling_eyes: