Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

text_painter

The text_painter draws a text into his drawing-rectangle so that it best fits. You can pass a maximum and a minimum font height and the text_painter iterates through all the heights, starting with the maximum. If the text fits vertically it will be drawn. If the text doesn't even fit into the drawing-rect with the minimum font height it will nevertheless be drawn.

namespace win32 { namespace gui {

     class text_painter : public painter_base
     {
     public:
          // info structure needed to load the text_painter
          struct font_info;
               
          typedef const std::string& param0;
          typedef const font_info& param1;
               
          // c'tor
          text_painter(const std::string& str, const font_info& info);
          
          // virtual functions of painter_base
          text_painter* clone() const;
          void draw(HDC hDC, int cx, int cy);
                    
          // own functions
          void text(const std::string& str);
          std::string text() const;
          void info(const font_info& info); 
          font_info info() const;
          void draw_text_options(unsigned flags);
          unsigned draw_text_options() const;
          unsigned last_used_text_height() const; 

          struct font_info
          {    
               font_info(LOGFONT lf, unsigned min_font_height, unsigned max_font_height, COLORREF cr = RGB(0, 0, 0));
               
               LOGFONT lf_;
               unsigned min_font_height_;
               unsigned max_font_height_;
               COLORREF cr_;
          };
     };

} }  // namespace win32::gui

Note:


Example:
// create colored rectangle behind the text
COLORREF cr_blue = RGB(0, 0, 150);      
rectangle rc(0, 0, 150, 30);
unsigned idx_color = add_painter<color_painter> (color_painter::make_brush(cr_blue));
drawing_rect(idx_color, rc);

// create the font information
LOGFONT lf;
memset(&lf, 0, sizeof(lf));
lf.lfWeight = FW_NORMAL;      
lf.lfQuality = PROOF_QUALITY;      
strcpy(lf.lfFaceName, "Arial");                        
COLORREF cr_white = RGB(255, 255, 255);
const unsigned max_size = ...;
const unsigned min_size = ...;

// add the text_painter and set its drawing_rect to the same as the text_painter's
std::string text = "hello world!";
unsigned idx_text = add_painter<text_painter> (text, text_painter::font_info(lf, min_size, max_size, cr_white));          
drawing_rect(idx_text, rc);   

The result is as follows
text_painter_0_140.jpg
text_painter_80_140.jpg
min_size = 0, max_size = 140
(last_used_text_height() returns 51)
min_size = 80, max_size = 140
(last_used_text_height() returns 80)



by Steven Weiss. You can contact me at steven11@gmx.de.