Author Topic: blinking cursor in Libtcod  (Read 7936 times)

puddinhead

  • Newcomer
  • Posts: 9
  • Karma: +0/-0
    • View Profile
    • Email
blinking cursor in Libtcod
« on: May 24, 2014, 10:57:52 PM »
hi, so the title pretty much says it all. I am using C++ with Libtcod and I really want that classic look with the blinking cursor under the player.
So if any of you guys know if there is a way to do that inside libtcod or another way to simulate it that would be great.
thanks

mushroom patch

  • Rogueliker
  • ***
  • Posts: 554
  • Karma: +0/-0
    • View Profile
Re: blinking cursor in Libtcod
« Reply #1 on: May 25, 2014, 02:12:44 AM »
I think your options are to animate it yourself or use curses.

chooseusername

  • Rogueliker
  • ***
  • Posts: 329
  • Karma: +0/-0
    • View Profile
    • Email
Re: blinking cursor in Libtcod
« Reply #2 on: May 25, 2014, 04:21:12 AM »
hi, so the title pretty much says it all. I am using C++ with Libtcod and I really want that classic look with the blinking cursor under the player.
So if any of you guys know if there is a way to do that inside libtcod or another way to simulate it that would be great.
thanks
If you think libtcod has built-in cursor handling, you misunderstand what libtcod is.  libtcod has no concept of cursor position, or cursors.  The screen is just a grid of character locations, and you can print text character by character in each of those locations.  That's pretty much it.  The rest is up to you.  It handles providing input events, and opening the display, and some other low level stuff.

I do cursor blinking myself (link to code):
  • Have a main loop that does not block waiting for input (poll instead).
  • Track the cursor position any time you print text.
  • Every first blink period draw a space (' ') with the colour of the background the colour you want the cursor to be, at the cursor coordinates.  Every second blink period replace the character that is supposed to be there, with it's fore and background colours.
Really, the biggest amount of work is structuring your game so it polls for input so that you can modify the screen when the player is not doing anything.  When you've got this done, and added cursor blinking, you can do other animations as well (which cursor blinking is just a special case of).

puddinhead

  • Newcomer
  • Posts: 9
  • Karma: +0/-0
    • View Profile
    • Email
Re: blinking cursor in Libtcod
« Reply #3 on: May 31, 2014, 06:55:48 PM »
I've used curses before and it is definitely out of the question.
My game loop is actually just like that. I have been using it for stuff like animated water and fire. However if I wanted to have the blinking cursor under the player I would have to alternate between '@' and '_' and the player would disappear half the time. I could also create my own symbol that is the '@' with the '_' combined which would work, but if I wanted to say use the blinking cursor to move around and "look" at things then that would not work at all
http://doryen.eptalys.net/demos/
at the link above you can find a demo called "Tile Engine" that proves you CAN layer things with Libtcod.
however I cant make much sense of it and it may be a little much to implement for just an aesthetics problem.

chooseusername

  • Rogueliker
  • ***
  • Posts: 329
  • Karma: +0/-0
    • View Profile
    • Email
Re: blinking cursor in Libtcod
« Reply #4 on: May 31, 2014, 11:32:31 PM »
Alright, let me be even more specific, although this is alluded to in my previous answer.

You can combine a cursor into a character, by simply making the cursor the background colour.  The tile changing it's background colour from green to black under the '@' which is present there, is a fairly common way of doing a cursor.  You don't even need to change the background colour, you can modify it by some factor which makes it obvious it's cursorified.  And the same approach can be done for selection of regions via highlighting.

If you wish to do layering and have a special cursor character, then download the tile engine and do what it does.