Post Reply 
Question about displaying strings
10-23-2019, 04:11 PM
Post: #14
RE: Question about displaying strings
I had a need for something like this also, here is what I ended up doing. I decided that G9 was a GROB that I don't really use so in my program I initialize G9 on startup to a size of 320x30 pixels, and then have a routine that calculates the half width of a string. The use is that I usually know the center X coordinate where I want the string to be, if I know half the width, then I simply subtract that value to get the starting point for TEXTOUT_P.

I added my method into the timer code previously shared for comparison. Because the width of a string varies based on text height, the second parameter of the routine is the text height as per the TEXTOUT_P documentation.

Code:
StringHalfWidth();

EXPORT CENTER_TEST()
BEGIN

  LOCAL nCounter,i,nX;
  LOCAL sString:="Some string less than 320px wide"; 

  PRINT();
  PRINT(sString);

  DIMGROB(G9,320,30,#FFFFFFh);
  nCounter:=TICKS();
  FOR i FROM 0 TO 10000 DO
    nX:=StringHalfWidth(sString,3);
  END;
  nCounter:=TICKS()-nCounter;
  PRINT("\nTime: "+nCounter+", Half Width: "+nX);
END;

StringHalfWidth(text,txtsz)
BEGIN
  RETURN IP(TEXTOUT_P(text,G9,0,0,txtsz,#000000h,320)/2);
END;
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Question about displaying strings - Jacob Wall - 10-23-2019 04:11 PM



User(s) browsing this thread: 1 Guest(s)