12-12-2018, 10:02 PM | #1 |
Human being with feelings
Join Date: Nov 2011
Posts: 3,440
|
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); |
12-13-2018, 04:43 AM | #2 |
Human being with feelings
Join Date: May 2006
Location: Surrey, UK
Posts: 19,702
|
I cannot get it to work either
__________________
DarkStar ... interesting, if true. . . . Inspired by ... |
12-13-2018, 08:00 AM | #3 |
Human being with feelings
Join Date: Oct 2009
Posts: 99
|
I dont know if its intended behavior but it works if I add gfx_x/gfx_y to "right" and "bottom".
PHP Code:
Last edited by wwwmaze; 12-13-2018 at 08:17 AM. |
12-13-2018, 01:12 PM | #4 |
Human being with feelings
Join Date: Nov 2011
Posts: 3,440
|
Ah, thanks, this seems to do the trick:
Code:
gfx_x=gfx_y=0; gfx_drawstr("hello world", 1|4, gfx_w, gfx_h); But I know better than to shout 'bug' so readily when it comes to JSFX so I will await word from others. :-) |
12-13-2018, 05:11 PM | #5 |
Human being with feelings
Join Date: Oct 2009
Posts: 99
|
|
12-13-2018, 06:15 PM | #6 |
Human being with feelings
Join Date: Nov 2011
Posts: 3,440
|
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 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.
__________________
Free blind ABX testing software | Audio illusions / psychoacoustics video series Music Theory Distilled -- a rapid crash course | How to do a portable install Last edited by clepsydrae; 12-14-2018 at 02:32 PM. |
12-14-2018, 01:03 PM | #7 |
Human being with feelings
Join Date: May 2015
Location: Québec, Canada
Posts: 5,265
|
I think this is intended. gfx_x/gfx_y/right/bottom sets the absolute position of the bounding rectangle. I'd expect it to be named width/height if it was relative to gfx_x/y.
__________________
🎁 Donate (PayPal) | Sponsor (GitHub) | The Endless Journey (Keyboard Ensemble) ReaPack, a package manager for REAPER | SWS 2.14 is now available in ReaPack [new!] Developer tools: Lua profiler | Interactive ReaScript | ReaPack Editor | ReaImGui |
12-14-2018, 02:32 PM | #8 |
Human being with feelings
Join Date: Nov 2011
Posts: 3,440
|
I'm not as dumb as this thread makes me look, I swear. :-)
Thanks -- it's working as you describe. I was just confused about the expected usage / documentation. |
12-14-2018, 06:57 PM | #9 | |
Human being with feelings
Join Date: Oct 2009
Posts: 99
|
Quote:
Imagine I'd like to center at the right half of the screen. By intuition I would set gfx_x to gfx_w/2 and "Right" to gfx_w. But to make it work I need to set "Right" to 1.5*gfx_w (gfx_w + gfx_x) PHP Code:
|
|
12-14-2018, 07:10 PM | #10 |
Human being with feelings
Join Date: Nov 2011
Posts: 3,440
|
Aha!
I think this code will demonstrate that something is amiss, or at least that we're seriously misunderstanding the use of the function: Code:
slider1:0<-1000,1000,1>x slider2:0<-1000,1000,1>y slider3:500<-1000,1000,1>right slider4:500<-1000,1000,1>bottom @gfx gfx_set(1,1,1); gfx_x=slider1; gfx_y=slider2; gfx_drawstr("hello world", 1|4, slider3, slider4); gfx_x=slider1; gfx_y=slider2; gfx_set(0,1,0); gfx_lineto(slider3,slider2); gfx_lineto(slider3,slider4); gfx_lineto(slider1,slider4); gfx_lineto(slider1,slider2); |
12-14-2018, 07:37 PM | #11 | |
Human being with feelings
Join Date: Oct 2009
Posts: 99
|
Quote:
PHP Code:
EDIT: nope, now it seems clipping doesn't work correctly. Last edited by wwwmaze; 12-14-2018 at 07:43 PM. |
|
12-14-2018, 07:42 PM | #12 |
Human being with feelings
Join Date: Nov 2011
Posts: 3,440
|
Actually the clipping doesn't work right against right/bottom when you do that, but the centering does. Seems we can't have both, as it stands. Hopefully it can be fixed, whether it's changed or we get a new function or option or whatever.
|
12-14-2018, 08:13 PM | #13 |
Administrator
Join Date: Jan 2005
Location: NYC
Posts: 16,117
|
Oops those flags only work right when using a font other than the builtin bitmapped font, perhaps? Adding gfx_setfont(1,"Arial"); seems to fix. Anyway, fixing!
Last edited by Justin; 12-14-2018 at 08:23 PM. |
12-14-2018, 11:12 PM | #14 |
Human being with feelings
Join Date: Nov 2011
Posts: 3,440
|
Super, thanks for looking in to it!
|
Thread Tools | |
Display Modes | |
|
|