Using Bitmap Label object as Edit,TEXT or LABEL object. - page 2

 

here's a quick example

//---
  //0.The text
    string text="EverETHing";
  //1.Set text properties 
    TextSetFont("Verdana",50,FW_BLACK|FW_BOLD,0);//orientation is degrees x 100  
  //2.Get the text size 
    uint w,h;//these will receive the size 
    TextGetSize(text,w,h);
  //3.These have an offset usually , of course they do so apply padding around the text
    double text_padding_x_pct=20.0;//%
    double text_padding_y_pct=10.0;//%
    /*
    if the padding + the text size are 100% and you know the padding 
    then you find the full size with this foremula
    */
    double fullX=((double)w);//we get the size of the text , alleged size
    //and this is a % , which % ? 100-padding
      fullX=(fullX/((100.0-text_padding_x_pct)))*100.0;
    //same for y
    double fullY=((double)h);
      fullY=(fullY/((100.0-text_padding_y_pct)))*100.0;  
    //now you have the full size you need the padding size 
    double paddingX=(fullX/100.0)*text_padding_x_pct;
    double paddingY=(fullY/100.0)*text_padding_y_pct;
    //good , if your text is centered you wont need the padding
    //as you will place the text in the center of the bitmap
    //if it is not centered you will place it at "padding" coordinates
    //so 
  //4.create the array of pixels 
    int sizeX=(int)MathCeil(fullX);
    int sizeY=(int)MathCeil(fullY);
    int paddX=(int)MathFloor(paddingX);
    int paddY=(int)MathFloor(paddingY);
    uint pixels[];
    ArrayResize(pixels,sizeX*sizeY,0);
    ArrayFill(pixels,0,ArraySize(pixels),0);
  //5.write the text to the array of pixels 
    bool centered=false;
    uint theColor=ColorToARGB(clrRoyalBlue,255);
    //centered
      if(centered){
      TextOut(text,sizeX/2,sizeY/2,ANCHOR_CENTER,pixels,sizeX,sizeY,theColor,COLOR_FORMAT_ARGB_NORMALIZE);
      }else{
      TextOut(text,paddX,paddY,ANCHOR_LEFT_UPPER,pixels,sizeX,sizeY,theColor,COLOR_FORMAT_ARGB_NORMALIZE);
      }
  //6.create the object (you do this once)
    ObjectCreate(ChartID(),"THEDISPLAY",OBJ_BITMAP_LABEL,0,0,0);
    ObjectSetInteger(ChartID(),"THEDISPLAY",OBJPROP_XSIZE,sizeX);
    ObjectSetInteger(ChartID(),"THEDISPLAY",OBJPROP_YSIZE,sizeY);
  //7.create the resource
    ResourceCreate("RESOURCE1",pixels,sizeX,sizeY,0,0,sizeX,COLOR_FORMAT_ARGB_NORMALIZE);
  //8.link to bitmap
    ObjectSetString(ChartID(),"THEDISPLAY",OBJPROP_BMPFILE,"::RESOURCE1");
  //9.update
    ChartRedraw();
 
Lorentzos Roussos #:

here's a quick example

Wooow, That is the answer, thank you. It works.

Do you think if it is possible to create a button or rectangle label and then turn it to bitmap label with same method?

 
Fatemeh Ameri #:

Wooow, That is the answer, thank you. It works.

Do you think if it is possible to create a button or rectangle label and then turn it to bitmap label with same method?

The above example only shows how to display the text, not how to read the string entered by a user.

I suggest you to read the series of articles about GUI written by Artyom Trishkin and/or Anatoli Kazharski. There you can alse learn how to create the other elements that you are asking.

 
Samuel Manoel De Souza #:

The above example only shows how to display the text, not how to read the string entered by a user.

I suggest you to read the series of articles about GUI written by Artyom Trishkin and/or Anatoli Kazharski. There you can alse learn how to create the other elements that you are asking.

That's what i thought he wanted first too 

Fatemeh Ameri #:

Wooow, That is the answer, thank you. It works.

Do you think if it is possible to create a button or rectangle label and then turn it to bitmap label with same method?

You fill the pixels of another bitmap object and leave it in the back.

Then the fun starts .

You can have a resource for when the mouse moves over the button and one for when it is not over it creating a hover effect.

You group the background and the text together , on your own , and you have a mini gui system.

You may also do the opposite .

For example, you want the text to fit inside a button with specific size .

you start a loop which gradually adjusts the font size until the text fills the button "the best way" 

If you want a background color try altering the ArrayFill(pixels,0,ArraySize(pixels),0) to fill with ColorToARGB(clrGoldenrod,255) .

Lastly 255 means 100% opaquenness .

opaquenness means the opposite of transparency .

So if you draw with ColorToARGB(clrRoyalBlue,125) it will be semi transparent

 
Samuel Manoel De Souza #:

The above example only shows how to display the text, not how to read the string entered by a user.

I suggest you to read the series of articles about GUI written by Artyom Trishkin and/or Anatoli Kazharski. There you can alse learn how to create the other elements that you are asking.

Thanks,I'll take a look.

 
Lorentzos Roussos #:

That's what i thought he wanted first too 

You fill the pixels of another bitmap object and leave it in the back.

Then the fun starts .

You can have a resource for when the mouse moves over the button and one for when it is not over it creating a hover effect.

You group the background and the text together , on your own , and you have a mini gui system.

You may also do the opposite .

For example, you want the text to fit inside a button with specific size .

you start a loop which gradually adjusts the font size until the text fills the button "the best way" 

If you want a background color try altering the ArrayFill(pixels,0,ArraySize(pixels),0) to fill with ColorToARGB(clrGoldenrod,255) .

Lastly 255 means 100% opaquenness .

opaquenness means the opposite of transparency .

So if you draw with ColorToARGB(clrRoyalBlue,125) it will be semi transparent

I think I got the idea, thank you, you help me a lot.

 

https://www.mql5.com/ru/forum/92113/page22#comment_5092654


Here is an example, but this example is very old and primitive.

 
Nikolai Semko #:

https://www.mql5.com/ru/forum/92113/page22#comment_5092654


Here is an example, but this example is very old and primitive.

It seems like it is in Russion language and unfortanly I don't know any Russion.

 
Fatemeh Ameri #:

It seems like it is in Russion language and unfortanly I don't know any Russion.

Use the translate button.

https://www.mql5.com/en/forum/13348

Automatic Translation of MQL5.com Forum Messages from Any Language - MQ5.Com Forum Now features automatic translation of any messages
Automatic Translation of MQL5.com Forum Messages from Any Language - MQ5.Com Forum Now features automatic translation of any messages
  • 2013.08.09
  • www.mql5.com
Com forum now features automatic translation of any messages. Thus, you can translate forum messages from any language. So, you will also be able to understand anyone. The editor of forum messages has also obtained some new features
 
Fatemeh Ameri #:

It seems like it is in Russion language and unfortanly I don't know any Russion.

Even if it’s Japanese, what difference does it make when the browser translates everything?  Moreover, the text is not the main thing, but the main thing is the code that is attached to this message.