Results 1 to 9 of 9

Thread: changing the size of CL_Font_Sprite

  1. #1
    Lesser Knight
    Join Date
    Sep 2006
    Location
    Barcelona, Catalonia
    Posts
    30

    Default changing the size of CL_Font_Sprite

    Hi, I'm wondering if I can change at will the size of a CL_Font_Sprite as I did with 0.8 with CL_Font using set_scale method...is there any way to do the same action? Imagine that you want to draw some text with the size of the original font, and change its size to write some new text half the size of the other one...any ideas?

    Thanks for your help;

    Xavi

  2. #2
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Good question.

    I have also thought about this in the past.

    Although you can add "set scale" to the sprite (or other font) API. I could not think of a clean way to program the implementation, without ending up in a mess.
    For example, should font.get_font_metrics() also returned the scaled sizes?

    An alternative method, is to modify the modelview matrix as follows:

    Code:
    int scale = 2;
    gc.push_scale(scale, scale);
    font.draw_text(“Hello World”, 20 / scale, 30 /  scale);
    gc.pop_modelview();
    (Note, this may be gc.push_modelview(), gc.mult_scale(scale, scale);… I cannot remember - the API docs are not that clear)

    Maybe a preferable option would be to add gc.draw_scaled_text(x_scale, y_scale, text, xpos, ypos)

    On a side note, I have noticed the xpos, ypos for draw_text() are integers. Since the implementation uses them as floats (for opengl), maybe draw_text() should accept floats ?

  3. #3
    Lesser Knight
    Join Date
    Sep 2006
    Location
    Barcelona, Catalonia
    Posts
    30

    Default

    Thanks for the reply, I suspected that the answer should be in modifying the graphic context, as you have stated...I understand that ClanLib now has a clean division between the management of resources and the drawing in display, so although the code will be trickier in this case it seems the correct way.

    I will give it a try, thanks

  4. #4
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Ooops,
    "Maybe a preferable option would be to add gc.draw_scaled_text(x_scale, y_scale, text, xpos, ypos)"

    should say "Maybe a preferable option would be to add font.draw_scaled_text(x_scale, y_scale, text, xpos, ypos)"

  5. #5
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    My personal favourite idea for scaled CL_Font_Sprite is as follows:

    1. Add a "set_scale" to set the font scale. (that affects get_font_metrics() etc)
    2. Add a CL_Font_Sprite(CL_Font_Sprite & reference, float scale_x, float scale_y)

    The second point uses the texture from the reference sprite, thus avoiding duplication

  6. #6
    Lesser Knight
    Join Date
    Sep 2006
    Location
    Barcelona, Catalonia
    Posts
    30

    Default

    I can think of another one...overload draw_text with another function that receives a CL_Rect as additional parameter. This method will scale the original pixel image to the new CL_Rect..., and uses the position of the rectangle to set the position with accuracy. What do you think?

    Something like:
    font.draw_text(gc, "hello", CL_Rect(50, 100, 250, 150));

    Xavi

  7. #7
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Good idea

    Implemented in SVN (for ClanLib 2.0.4)

    Code:
    (In CL_Font_Sprite)
    	void draw_text(CL_GraphicContext &gc, int xpos, int ypos, float scale_x, float scale_y, const CL_StringRef &text, const CL_Colorf &color = CL_Colorf::white);
    
    	void draw_text(CL_GraphicContext &gc, const CL_Rect &dest, const CL_StringRef &text, const CL_Colorf &color = CL_Colorf::white);

  8. #8
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    There was a bug in CL_Font_Sprite (In release 2.0.3), where it was not drawing the font relative to the base line.

    This has been fixed in SVN (for 2.0.4)

    Also, I removed
    "void draw_text(CL_GraphicContext &gc, const CL_Rect &dest, const CL_StringRef &text, const CL_Colorf &color = CL_Colorf::white);"

    - It caused problems (depending on what CL_FontMetric's are used)

    If it's required, just use get_text_size() to calculate the scale factor instead.

    Note, I have updated the font documentation (In Documentation/Overview/fonts.html)

    See attached image, showing the Font example correctly displays the sprite font
    Attached Images Attached Images  
    Last edited by rombust; 07-23-2009 at 02:19 PM.

  9. #9
    Lesser Knight
    Join Date
    Sep 2006
    Location
    Barcelona, Catalonia
    Posts
    30

    Default

    Great! Thanks for your assistance

Similar Threads

  1. default window size...
    By harrio in forum Novashell Game Creation System
    Replies: 6
    Last Post: 02-18-2008, 05:38 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •