Old 12-12-2018, 10:02 PM   #1
clepsydrae
Human being with feelings
 
clepsydrae's Avatar
 
Join Date: Nov 2011
Posts: 2,236
Default proper use of flags with gfx_drawstr to center text? (FIXED)

If I want to center text on the screen, I'm trying:
Code:
gfx_x=gfx_w/2;
gfx_y=gfx_h/2;
gfx_drawstr("hello world", 1|4|256, 0, 0);
...but I'm clearly misinterpreting the docs. Any help? Thanks!
clepsydrae is offline   Reply With Quote
Old 12-13-2018, 04:43 AM   #2
DarkStar
Human being with feelings
 
DarkStar's Avatar
 
Join Date: May 2006
Location: Surrey, UK
Posts: 17,633
Default

I cannot get it to work either
__________________
DarkStar ... interesting, if true. Inspired by ...
DarkStar is offline   Reply With Quote
Old 12-13-2018, 08:00 AM   #3
wwwmaze
Human being with feelings
 
Join Date: Oct 2009
Posts: 115
Default

I dont know if its intended behavior but it works if I add gfx_x/gfx_y to "right" and "bottom".

PHP Code:
@gfx
gfx_set
(1,1,1);

p1.x=0;
p1.y=0;
p2.x=gfx_w/2;
p2.y=gfx_h;

gfx_x=p1.x;
gfx_y=p1.y;
gfx_drawstr("hello world"1|4p2.x+gfx_xp2.y+gfx_y); 
EDIT: use flags|256 for no clipping at smaller sizes
__________________
Video processor programming: (1) How inputs work: https://forum.cockos.com/showthread....26#post2057426 (2) YV12 colorspace: https://forum.cockos.com/showthread....54#post2059354 (3) EEL documentation: https://www.cockos.com/EEL2/

Last edited by wwwmaze; 12-13-2018 at 08:17 AM.
wwwmaze is offline   Reply With Quote
Old 12-13-2018, 01:12 PM   #4
clepsydrae
Human being with feelings
 
clepsydrae's Avatar
 
Join Date: Nov 2011
Posts: 2,236
Default

Ah, thanks, this seems to do the trick:

Code:
gfx_x=gfx_y=0;
gfx_drawstr("hello world", 1|4, gfx_w, gfx_h);
...so it seems like there are some bugs in there? E.g. it treats gfx_x an gfx_y as the top-left point and right/bottom as the bottom-right point of where it actually decides to center and draw. It also seems to ignore an |256 if you put it in there.

But I know better than to shout 'bug' so readily when it comes to JSFX so I will await word from others. :-)
clepsydrae is offline   Reply With Quote
Old 12-13-2018, 05:11 PM   #5
wwwmaze
Human being with feelings
 
Join Date: Oct 2009
Posts: 115
Default

Quote:
Originally Posted by clepsydrae View Post
It also seems to ignore an |256 if you put it in there.
Hmm it works here. Downsize the window to see how clipping takes effect if bit 256 isnt set. The only (imo) unexpected thing is that we need to add gfx_x/y to right/bottom.
__________________
Video processor programming: (1) How inputs work: https://forum.cockos.com/showthread....26#post2057426 (2) YV12 colorspace: https://forum.cockos.com/showthread....54#post2059354 (3) EEL documentation: https://www.cockos.com/EEL2/
wwwmaze is offline   Reply With Quote
Old 12-13-2018, 06:15 PM   #6
clepsydrae
Human being with feelings
 
clepsydrae's Avatar
 
Join Date: Nov 2011
Posts: 2,236
Default

Ah, ok. So the confusion for me was the docs that say:

Code:
Draws a string at gfx_x, gfx_y
...
In REAPER 5.30+, flags,right,bottom can be specified to control alignment:

    flags&1: center horizontally
I assumed "center horizontally" meant "center around gfx_x".

That is, when flags,right,bottom are specified, it's no longer the case that it "draws a string at gfx_x, gfx_y", but instead draws centered within the rectangle described by x,y right,bottom.

And yeah I guess the gfx_x/y addition being required is a bug? -- not required, not a bug

Last edited by clepsydrae; 12-14-2018 at 02:32 PM.
clepsydrae is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 07:41 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.