summaryrefslogtreecommitdiff
path: root/menuApp/src/ofxTextBlock.h
blob: 7455c70ba1e4e9fe9ad186b7194da8f03ef7f298 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
            /***********************************************************************

 Copyright (c) 2009, Luke Malcolm, www.lukemalcolm.com

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.

 ***********************************************************************/

#ifndef OFXTEXTBLOCK_H
#define OFXTEXTBLOCK_H

#include "ofMain.h"
#include <iterator>

class wordBlock {
    public:
        string          rawWord;
        float           width;
        float           height;
        ofColor         color;

};


class lineBlock {
    public:
        vector<int>   wordsID;

        float   width;
        float   height;

};

//Just a helpful set of enumerated constants.
enum TextBlockAlignment { OF_TEXT_ALIGN_LEFT, OF_TEXT_ALIGN_RIGHT, OF_TEXT_ALIGN_JUSTIFIED, OF_TEXT_ALIGN_CENTER };

class ofxTextBlock
{
    public:
        ofxTextBlock();
        virtual ~ofxTextBlock();

        string          rawText;
        ofTrueTypeFont  defaultFont;
        wordBlock       blankSpaceWord;
        float           scale;

        vector<wordBlock>   words;
        vector<lineBlock>   lines;

        void    init(string fontLocation, float fontSize,const char spacechar='x');

        void    setText(string _inputText);

        int     wrapTextX(float lineWidth);                 //Returns the number of lines it formed.
        void    wrapTextArea(float rWidth, float rHeight);
        bool    wrapTextForceLines(int linesN);

        void    setLineHeight(float lineHeight);
        void    setColor(int r, int g, int b, int a);

        void    draw(float x, float y);                    //Draws left align.
        void    drawLeft(float x, float y, int numlines=9999);
        void    drawRight(float x, float y, int numlines=9999);
        void    drawCenter(float x, float y, int numlines=9999);
        void    drawJustified(float x, float y, float boxWidth, int numlines=9999);


        void    forceScale(float _scale);

        float   getWidth();
        float   getHeight();

    protected:

        void    _loadWords();

        void    _trimLineSpaces();
        float   _getWidthOfWords();
        int     _getLinedWords();

    private:
};

#endif // OFXTEXTBLOCK_H