Character Pixels



  • On 12/10/2016 at 11:21, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   14 
    Platform:   Windows  ;   
    Language(s) :     C++  ;

    ---------
    Hello,

    In my plugin I have a GeUserArea that will vary in width based on how large the user makes its dialog window. The GeUserArea has an image inside it with a string of static text beneath it. This static text is meant to be centered beneath the image unless the GeUserArea is too small for the text to completely fit. If this happens the static text is supposed to justify to the left and I set the width of the static text so that it doesn't go beyond the image.

    I can set the size of the text and justify it to the left correctly, my problem is that I can't determine the size of the string so that I can tell when it cannot be completely displayed. I set the size of the GeUserArea and its relevant GroupBegins with SizePix which correctly changes the size of GeUserArea and its image.

    Does anyone know of a way to get the length of a string in pixels or how many characters can be displayed given a set area? I've tried using SizeChr and SizePixChr but both of these claimed that the static text needed a much larger area than it actually did to display.

    Any help would be greatly appreciated.

    Johan. H



  • On 13/10/2016 at 01:55, xxxxxxxx wrote:

    Hello,

    what exactly do you mean with "a string of static text beneath it"? Do you draw the string inside the GeUserArea?

    Using GeUserArea you can get the width or the rendered string with DrawGetTextWidth(). Alternatively one can draw text into a BaseBitmap using a GeClipMap. With a GeClipMap you can use GetTextWidth().

    best wishes,
    Sebastian



  • On 13/10/2016 at 09:27, xxxxxxxx wrote:

    Thanks for the reply Sebastian, sorry I wasn't very clear.

    I have the GeUserArea within its own group, beneath that group is a separate group that contains the static text.

      
    GroupBegin((STARTID_USERGROUP + dataHolderArray[index].originalID), BFH_CENTER, 0, 2, "", 0);  
    {  
      GroupBegin(BITMAP_STARTID + dataHolderArray[index].originalID, BFH_CENTER, 0, 0, "", 0);  
          {                     
                  C4DGadget* userarea = AddUserArea(dataHolderArray[index].originalID + MATERIALIDSTART_LOCATION, BFH_CENTER | BFV_CENTER, 50, 50);  
                  AttachUserArea(imageAreaArray[geuserareaLocations.GetLong(dataHolderArray[index].originalID)], userarea, USERAREA_TABSTOP);  
          }  
          GroupEnd();  
          GroupBegin(10000000 + index, 0, 1, 0, "", 0, 0);  
      {  
              AddStaticText(ID_STATICTEXT, BFV_TOP, SizePix(size), 0, dataHolderArray[index].materialName, 0);  
          }  
          GroupEnd();   
    }  
    GroupEnd();  
    

    I'm trying to get the size of string that will be displayed by the AddStaticText so that I can compare it to the size of the GeUserArea which I already know.

    Johan. H



  • On 14/10/2016 at 01:50, xxxxxxxx wrote:

    Hello,

    there is no build-in function to get the width of the displayed text in that gadget. Right now I don't see a way to achieve the desired behaviour.

    best wishes,
    Sebastian


Log in to reply