Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Hide overflown contents from a set boundary  (Read 4053 times)

0 Members and 1 Guest are viewing this topic.

ErikPerik

  • Newbie
  • *
  • Posts: 19
    • View Profile
Hide overflown contents from a set boundary
« on: September 23, 2010, 06:51:25 pm »
I'm currently writing a tiny GUI library, and in my text-input fields I want the text that is longer than the input field boundaries to not be displayed. The example illustrates it:



I have looked around a lot in the forum and the solution as I see it: Use sf::View in some way. (And this is SFML 1.6) I don't really know how it works, but it appears to be RenderWindow-only. Maybe I can swap the view when drawing the input field?

AFAIK sf::String, nor sf::Drawable has a BoundingRect-property or something the like. What do you think?

NoIdea

  • Full Member
  • ***
  • Posts: 149
    • View Profile
Hide overflown contents from a set boundary
« Reply #1 on: September 23, 2010, 07:10:41 pm »
If I understand right, you want to be able to delimit a part of the screen in which the drawables must be drawn ?

There are to simple ways of achieving this :
-using glScissor. This method is perfect if you are working in screen coordinates. If not, use the second one :
-using glClipPlane. There is an example on the french forum doing exactly what you want. I'll try to get the link.

Here is the link.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Hide overflown contents from a set boundary
« Reply #2 on: September 23, 2010, 07:13:45 pm »
The easiest way would be to remove the part of the string which isn't displayed from the sf::String object, and pass that cut object to sf::Text. You can get the character's length using sf::Glyph.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

NoIdea

  • Full Member
  • ***
  • Posts: 149
    • View Profile
Hide overflown contents from a set boundary
« Reply #3 on: September 23, 2010, 08:00:16 pm »
The only problem with your solution in this case is that it can't "cut" letters.
Furthermore, if he ever needs to be able to draw shapes or PostFx, he might want to be able to delimit them too. This works with the system I proposed.

ErikPerik

  • Newbie
  • *
  • Posts: 19
    • View Profile
Hide overflown contents from a set boundary
« Reply #4 on: September 23, 2010, 08:21:27 pm »
Yes, that is exactly what I want. Is this the "recommended" way of dealing with it? As I don't know french I can't really decipher everything in the linked thread by NoIdea, but see the gist of it.

Code: [Select]

glEnable(GL_SCISSOR_TEST);
...
// Draw code
...
glDisable(GL_SCISSOR_TEST);


Is this what's recommended?

NoIdea

  • Full Member
  • ***
  • Posts: 149
    • View Profile
Hide overflown contents from a set boundary
« Reply #5 on: September 23, 2010, 08:45:26 pm »
Yes, but as I said, glScissor requires screen coordinates which you usually dont have. Thats why there is a solution with glClipPlane on the same thread.
If necessary, you might want to use google translation... as I am not going to translate my entire thread into english.

Lupinius

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Hide overflown contents from a set boundary
« Reply #6 on: September 23, 2010, 09:10:02 pm »
You could render the text to a RenderImage and use subrect to only draw one part of the text.

ErikPerik

  • Newbie
  • *
  • Posts: 19
    • View Profile
Hide overflown contents from a set boundary
« Reply #7 on: September 23, 2010, 09:16:25 pm »
Quote from: "Lupinius"
You could render the text to a RenderImage and use subrect to only draw one part of the text.


But RenderImage is 2.0 and I'm using 1.6 (because I like stability).

Lynix

  • Sr. Member
  • ****
  • Posts: 403
    • View Profile
Hide overflown contents from a set boundary
« Reply #8 on: September 24, 2010, 05:21:53 pm »
SFML 2 is stable

ErikPerik

  • Newbie
  • *
  • Posts: 19
    • View Profile
Hide overflown contents from a set boundary
« Reply #9 on: September 24, 2010, 05:25:08 pm »
From what I've read in recent thread it has problems with ATI-cards?

NoIdea

  • Full Member
  • ***
  • Posts: 149
    • View Profile
Hide overflown contents from a set boundary
« Reply #10 on: September 24, 2010, 05:54:12 pm »
Whatever you do with RenderImage, glClipPlane will be faster. Just copy/paste the code...

ErikPerik

  • Newbie
  • *
  • Posts: 19
    • View Profile
Hide overflown contents from a set boundary
« Reply #11 on: September 24, 2010, 06:00:40 pm »
I am currently using this:

Code: [Select]

void drawBoundary(sf::RenderWindow &window, sf::Drawable *d, const sf::FloatRect &boundary)
{
GLdouble eq1[] = {1, 0, 0, 0x0};
GLdouble eq2[] = {-1, 0, 0, 0x0};
GLdouble eq3[] = {0, 1, 0, 0x0};
GLdouble eq4[] = {0, -1, 0, 0x0};

eq1[3] = -boundary.Left;
eq2[3] = boundary.Right;
eq3[3] = -boundary.Top;
eq4[3] = boundary.Bottom;

glEnable(GL_CLIP_PLANE0);
glEnable(GL_CLIP_PLANE1);
glEnable(GL_CLIP_PLANE2);
glEnable(GL_CLIP_PLANE3);
glClipPlane(GL_CLIP_PLANE0, eq1);
glClipPlane(GL_CLIP_PLANE1, eq2);
glClipPlane(GL_CLIP_PLANE2, eq3);
glClipPlane(GL_CLIP_PLANE3, eq4);

window.Draw(*d);

glDisable(GL_CLIP_PLANE1);
glDisable(GL_CLIP_PLANE0);
glDisable(GL_CLIP_PLANE2);
glDisable(GL_CLIP_PLANE3);
}


Edit: Fixed the function

 

anything