Why text from OBJ_LABEL can have different size on different computers ?

To add comments, please log in or register
Dorian Baranes
23028
Dorian Baranes  

Hi,

I have displayed from the chart a text via OBJ_LABEL:

           ObjectCreate(0,name, OBJ_LABEL, 0, 0, 0);
           ObjectSetInteger(0,name, OBJPROP_CORNER, CORNER_LEFT_UPPER);
           ObjectSetInteger(0,name, OBJPROP_XDISTANCE, x_pos);
           ObjectSetInteger(0,name, OBJPROP_YDISTANCE, y_pos);
           ObjectSetString(0,name,OBJPROP_FONT,"Courier New"); 
           ObjectSetInteger(0,name,OBJPROP_FONTSIZE,8);
	   ObjectSetInteger(0,name,OBJPROP_COLOR,color); 

And I have added a background via the OBJ_RECTANGLE_LABEL

      ObjectCreate(name,OBJ_RECTANGLE_LABEL,0,0,0);
      ObjectSet(name, OBJPROP_CORNER, CORNER_LEFT_UPPER);
      ObjectSetInteger(0,name,OBJPROP_STYLE,STYLE_SOLID);
      ObjectSetInteger(0,name,OBJPROP_WIDTH,10);
      ObjectSet(name, OBJPROP_XDISTANCE, 0);
      ObjectSet(name, OBJPROP_YDISTANCE, 110);
      ObjectSetInteger(0,name,OBJPROP_XSIZE,100);
      ObjectSetInteger(0,name,OBJPROP_YSIZE,100);
      ObjectSetInteger(0,name,OBJPROP_BGCOLOR,clrNavy);

After testing this code in different computers I notice that the background keeps the same size however the text can have different sizes. How is possible and how to resize the background based on the current text size ?

Thanks for your help


Regards,

Dorian

Bartlomiej Gorski
11322
Bartlomiej Gorski  
Its because different resolution. This text has the same size programatically but if you look at it on full hd monitor it will have relatelively bigger size than on 4k monitor. Either you need to adjust zoom in windows or add inputs in indicator so user can adjust font size to fit his screen
Demos Stogios
213
Demos Stogios  
Dorian Baranes:

Hi,

I have displayed from the chart a text via OBJ_LABEL:

And I have added a background via the OBJ_RECTANGLE_LABEL

After testing this code in different computers I notice that the background keeps the same size however the text can have different sizes. How is possible and how to resize the background based on the current text size ?

Thanks for your help


Regards,

Dorian

Hello,

Text is subject to screen DPI, as set in Windows. In MQL5 there is TERMINAL_SCREEN_DPI to get you going; maybe there is for MQL4 as well, but I can not recall.

Dorian Baranes
23028
Dorian Baranes  
Demos Stogios:

Hello,

Text is subject to screen DPI, as set in Windows. In MQL5 there is TERMINAL_SCREEN_DPI to get you going; maybe there is for MQL4 as well, but I can not recall.

thank you. Do you have an example of code to scale font size based on DPI ?

Regards,

Dorian

Demos Stogios
213
Demos Stogios  
Dorian Baranes:

thank you. Do you have an example of code to scale font size based on DPI ?

Regards,

Dorian

Hello,

TerminalInfoInteger(TERMINAL_SCREEN_DPI) will return the number (or close to) set on Windows/Settings/System/Display. So, e.g. it could be 144 if we have set 150 in Windows.

Another point to have in mind is that the text that MQL outputs with the OBJ_LABEL is scaled. That means that if we specify a font size of 8, it will have a size of 12 pixels. So, we have to alter the size of OBJ_RECTANGLE_LABEL our selves, e.g.


ObjectSetInteger(0, name, OBJPROP_YSIZE, (int)100*TerminalInfoInteger(TERMINAL_SCREEN_DPI)*.01);

regards

To add comments, please log in or register