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

Author Topic: Bitmap font -> Chatbox (with scrollbar)  (Read 3009 times)

0 Members and 1 Guest are viewing this topic.

deadmau5

  • Newbie
  • *
  • Posts: 24
    • View Profile
Bitmap font -> Chatbox (with scrollbar)
« on: February 14, 2013, 05:40:46 pm »
Hello all,

How would I go about creating a chatbox using nothing but a bitmap font.

The problem is creating the actual box with scrollable text (vertical scrollbar).
Can this be created with a view or are there better solutions?

Don't have any idea how to begin approaching this, any help is appreciated.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Bitmap font -> Chatbox (with scrollbar)
« Reply #1 on: February 14, 2013, 06:48:30 pm »
First off we are not here to code for you, that's your job to do the work. We are here just to provide some help with problems. First off try to make a box using just normal text and fonts. Then add the bitmap font. Using a view for scrolling the text will probably (for you since you say you have no idea how to even start this) will prove to be more complicated than just moving the position of the text. Then the next part is to display the text. What about text wrapping? Your need to use a prexisting library for text formatting or write code yourself to wrap text to the next line when you run out of width in the chat box. Just some things to think about.

Once you get a basic chat box working then you can think about bitmap fonts. Your probably want to write a wrapper for taking a string and then displaying it using a bitmap font. Once you got that working combine it into your chat box.

And, I am at work at the moment and so I'm just writing some things that I thought of off the top of my head. There is still more to it than what I wrote, but you get the idea. Try to write something, then post your code so we can see where you are and then we can maybe give some more detailed help.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

deadmau5

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Bitmap font -> Chatbox (with scrollbar)
« Reply #2 on: February 14, 2013, 07:12:51 pm »
Thank you for replying. I don't think I've stated anywhere that I needed code. I simply need some help on this subject since I haven't done this before.
I am able to draw the glyphs using a function that takes an std::string as parameter at specified coordinates.
This is not the problem. (no idea if this is the most efficient solution)

Wrapping the text up should not be a problem also.

My question is therefore (which I should have stated previously): is a sf::View suitable/efficient for scrolling and what would the calculations/position for the scrollbar/view be (thumb size and position)?

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Bitmap font -> Chatbox (with scrollbar)
« Reply #3 on: February 14, 2013, 08:16:30 pm »
My question is therefore (which I should have stated previously): is a sf::View suitable/efficient for scrolling and what would the calculations/position for the scrollbar/view be (thumb size and position)?
Actually you didn't state that clearly before, it sounded more like a general question  ;) Anyways a quick search on google brought up this in the #1 result.
Quote
thumb size = scroll bar size * page size / scroll bar range

Quite simple actually.  ;D
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

deadmau5

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Bitmap font -> Chatbox (with scrollbar)
« Reply #4 on: February 14, 2013, 09:10:46 pm »
Thank you, then only one question remains: is the sf::View suitable/efficient for this or is there a different (perhaps better) approach?

Oh and would rendering the glyphs one by one a good solution in terms of performance or should I look for storing the text inside a texture somehow and render it at once?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Bitmap font -> Chatbox (with scrollbar)
« Reply #5 on: February 14, 2013, 10:50:25 pm »
Thank you, then only one question remains: is the sf::View suitable/efficient for this or is there a different (perhaps better) approach?
This can't really be answered unless one has both version and can compare them. For the use of a sf::View would only make things more complicated and I'd probably rather use a sf::RenderTexture and logically determine what should be displayed and what not.

Oh and would rendering the glyphs one by one a good solution in terms of performance or should I look for storing the text inside a texture somehow and render it at once?
The theoretically most efficient way I can think of, would be to use a sf::VertexArray (or std::vector<sf::Vertex>) and one texture. Additionally you could store the quads of each letter separately and provide a simple character to glyph conversion, thus it should be easy to fill the vector with the wanted text.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything