dpi reading not updating - page 4

 
Michael Charles Schefe #:

you mean like mine 2560 x 1080 -- aspect 21:9 or ones at work with aspect 32:9? (haha)

Samuel Manoel De Souza #:

he means. if you have two monitors with different specifications the images on the second monitor may not match what you see in the first monitor.

updated the get font size function to carve out a "proper ratio" portion off of any big screens and use that .

still loses some pixels on low resolutions.

   int find_font_size(){
       int this_dpi=TerminalInfoInteger(TERMINAL_SCREEN_DPI);
       int this_wid=TerminalInfoInteger(TERMINAL_SCREEN_WIDTH);
       int this_hei=TerminalInfoInteger(TERMINAL_SCREEN_HEIGHT);
       //do an initial font size estimation
         //to solve for wide and long screens 
         //carve out a portion of the screen that matches
         //the coder's x by y 
         double logical_X=MathMin(this_wid,((double)this_hei)*m_x_by_y);
         double logical_Y=MathMin(this_hei,((double)this_wid)/m_x_by_y);
         double diagonal=MathSqrt(MathPow(logical_X,2.0)+MathPow(logical_Y,2.0));
         double logical_fs=diagonal/m_diag_per_font_size;//
       //now the dpi comes into effect too
         double dpi_ratio=((double)this_dpi)/((double)m_dpi);
       //multiply?
         logical_fs*=dpi_ratio;
       return((int)MathCeil(logical_fs));
       }
Samuel Manoel De Souza #:
My approach has been scale the controls not font size, because font size is set in points, what means it will look same in any screen. what need be adjusted is the controls to match the font size. Just like is in the documentations as  Fernando Carreiro already commented here.

But you have to scale the font size too if you scale the elements in your ui

 
Samuel Manoel De Souza #:
if you try to scale the font size you have another problem which is for proper scaling you would be able to set float value for font size, what is not allowed in MQL for the standard controls/objects.

Thanks 

Having the font size as a base unit is easier for the user though.

The idea basically is this :

You design a panel and it looks proper in proportionality to the chart and the screen for you.

You throw in all your specs in the source code and it will try to make it look proportionally similar

to any screen.

If the user wants to override it you provide a scaling value.

Sort of like this : if you take a thin piece of paper and place it over the screen and trace the edges of your panel , then change dpi and resolution

and the panel should (imo) fit inside that box

 
You are working with font size in pixels. Use font size in points. To set font size in points using TextSetFont just multiply it by -10 and you don't need scale font size anymore. For example for font size 16 use -160. You just need scale the controls sizes not font.
 
Samuel Manoel De Souza #:
You are working with font size in pixels. Use font size in points. To set font size in points using TextSetFont just multiply it by -10 and you don't need scale font size anymore. For example for font size 16 use -160. You just need scale the controls sizes not font.

wow

you solved it in one line of code

Thank you 

 

Just to give you a complete solution. Once you are working with font size in points you can easily calculate the controls size, first convert points to pixels and then use it to calculate the size of your controls.
These is the functions that i have used elsewhere.

int FontPointsToPixels(float points, int dpi = 96) { return((int)(points * dpi / 72)); }
float FontPixelsToPoints(int pixels, int dpi = 96) { return(pixels * 72.0f / dpi); }
here points is not multiplid by -10.
 
Samuel Manoel De Souza #:

Just to give you a complete solution. Once you are working with font size in points you can easily calculate the controls size, first convert points to pixels and then use it to calculate the size of your controls.
These is the functions that i have used elsewhere.

here points is not multiplid by -10.

 so you find the pixels and then you estimate the size for the default elements

 
Lorentzos Roussos #:

 so you find the pixels and then you estimate the size for the default elements

You can use TextGetSize also. Is up to you.

 
Samuel Manoel De Souza #:

You can use TextGetSize also. Is up to you.

thanks , that makes sense

 
Samuel Manoel De Souza #:

Just to give you a complete solution. Once you are working with font size in points you can easily calculate the controls size, first convert points to pixels and then use it to calculate the size of your controls.
These is the functions that i have used elsewhere.

here points is not multiplid by -10.

you are a genius.