Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

Drawing variable string to be multiline and centered on each line

$
0
0

@Trevor_Seymour wrote:

I am certainly a beginner with openFrameworks and coding with C++ in general (have been trying to watch Youtube tutorials non-stop) so apologies if this doesn’t make sense or doesn’t provide the information that you need to actually help me.

I am trying to allow multilines of text (after pressing the return key) to be centered on each line. I have figured out how to allow for multiple lines:

else if(key == OF_KEY_RETURN){
        str += "\n";
    }

However, when the return is pressed, the text goes to the left edge of whatever the longest line is. In short, it is as if each line is grouped and centered to the one that is the longest.

The method I am using to center it is this:

font.drawString(str, ofGetWidth() / 2 - font.stringWidth(str) / 2, ofGetHeight() / 2 - font.stringHeight(str) / 2);

Is there another way to center lines vertically and horizontally that would allow for each line to be centered to the window, rather than all of the lines (grouped together) being centered?

Here are some quick screen captures showing this.

What I am currently doing (but don’t want):
https://www.screencast.com/t/p0rty2gDAyk

What I want to do but am unable to achieve via openFrameworks (this was recorded from Adobe InDesign):
https://www.screencast.com/t/2qxl38b7gN

Is this possible without addons? I did find one addon, ofxParagraph, but that seems to be out of date and I was unable to get it to actually run as I was wanting. There wouldn’t be any errors, but it wouldn’t register what I was typing.

Thanks all for your help! Let me know if I can answer any questions that may clarify any confusion

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles