Author Topic: BearLibTerminal: a pseudo-terminal window library for roguelike  (Read 282560 times)

KM

  • Newcomer
  • Posts: 13
  • Karma: +0/-0
    • View Profile
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #165 on: January 09, 2017, 11:21:48 PM »
Hi; perhaps this is the wrong place for this, but..

I'm done the roguelike tutorial, and I've ported it all into the bearlibterminal for the graphical aspect.  I am simply wondering how to make my window resizeable?

I read the documentation, but it's not working and I don't know why.  Example code plz?

Cfyz

  • Rogueliker
  • ***
  • Posts: 194
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #166 on: January 10, 2017, 12:35:33 AM »
Quote from: KM
I am simply wondering how to make my window resizeable?
Resizing a window may mean a few things.

1. Resizing a window so that there will be more (or less) cells available: you need to set 'window.resizeable' option and then handle TK_RESIZED input event from read(), e. g. assuming Python:
Code: [Select]
terminal.set('window.resizeable=true')
...
while True:
    key = terminal.read()
    if key == terminal.TK_RESIZED:
        new_columns = terminal.state(terminal.TK_WIDTH)
        new_rows = terminal.state(terminal.TK_HEIGHT)
        ...
    elif key == terminal.TK_CLOSE:
        break
    ...
TK_RESIZED is just a notification, though. The scene is already a new size by the time it was read.

2. User scaling the window (and its contents): it is done in some discrete steps by pressing Alt+Plus/Minus. There is no arbitrary scaling like in Caves of Qud, yet.

3. Program scaling the window (and its contents): there is no direct way for this, yet. You can achieve this by setting/resizing a different font size.

quejebo

  • Newcomer
  • Posts: 6
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #167 on: January 10, 2017, 05:31:22 AM »
Hi, I've been checking out bearlibterminal, and I seem to be having trouble with ttf rendering.  Check the attached image, and note the exclamation mark on the left.  Is there something I might be doing wrong?

Thanks!


KM

  • Newcomer
  • Posts: 13
  • Karma: +0/-0
    • View Profile
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #168 on: January 11, 2017, 01:07:08 AM »
Thanks a lot, Cfyz!

So I have it working as per your first example with variable cell sizes; however the whole screen goes black while it's being resized, and only upon movement does it render the screen again.  Is this normal?

Cfyz

  • Rogueliker
  • ***
  • Posts: 194
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #169 on: January 11, 2017, 09:44:32 PM »
Quote from: quejebo
I seem to be having trouble with ttf rendering.  Check the attached image, and note the exclamation mark on the left.  Is there something I might be doing wrong?
Looks like auto-hinter in freetype library produces subpar results for some fonts. I'll look into it and probably release a fix shortly.

Quote from: KM
however the whole screen goes black while it's being resized, and only upon movement does it render the screen again.  Is this normal?
Does it go black while resizing or after you release the mouse button and until some other input? The latter is normal since scene contents are cleared when it is resized, you need to recalculate the layout and redraw the scene for a new size.

tapeworm711

  • Newcomer
  • Posts: 12
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #170 on: January 12, 2017, 09:06:52 PM »
Found an odd issue with   [wrap] / [align] tags.

If you install BearLibTerminal via pip. The tags do NOT function properly. As in they do not no aligning or wrapping at all.

BUT

If you use PyBearLibTerminal and BearLibTerminal.dll from the "blt-samples" master, they work just fine.

Is there an issue with the PIP package? or am I doing something wrong?

P.S. Really close to finishing a python class called "bltColor" that brings all the libtcod color functions to blt and more! (testing this is how I discovered the wrap issue)

Cfyz

  • Rogueliker
  • ***
  • Posts: 194
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #171 on: January 12, 2017, 10:01:29 PM »
Quote from: tapeworm711
If you install BearLibTerminal via pip. The tags do NOT function properly. As in they do not no aligning or wrapping at all.
As I mentioned a few posts above, in the latest update 'wrap' and 'align' tags were removed in favor of proper function arguments. E. g.
Code: [Select]
terminal.print(2, 1, some_str, width=10, height=5, align=terminal.TK_ALIGN_RIGHT);
This actually shuffled things a bit for python print function =|. Originally there was printf because you can't use print identifier in Python 2 and print_ looks weird. So I went with printf as a workaround and obviously had to make it support formatting to match the name. But when I tried to add optional keyword arguments for area and alignment, it did not work with formatting part. Turns out, you can't have a signature like
Code: [Select]
def printf(x, y, s, *args, width=0, height=0, alignment=0):Only **kwargs may come after *args. And making optional arguments nameless hurts the usability.

Since formatting was never an objective (unlike C++, Python has good string formatting out of the box), I changed string output function name to puts. Like put for putting characters/tiles and puts for putting stirngs, with print_ and print (in Python3) aliases. The printf was left for some compatibility (I would mark it as deprecated if I knew how) but for reasons stated above it does not have wrapping and alignment support anymore.

Quote from: tapeworm711
BUT If you use PyBearLibTerminal and BearLibTerminal.dll from the "blt-samples" master, they work just fine.
That's because it is a separate repository and probably has a previous library version. Should do something about it.

tapeworm711

  • Newcomer
  • Posts: 12
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #172 on: January 12, 2017, 10:17:37 PM »
Not sure how I missed that. Thanks.

KM

  • Newcomer
  • Posts: 13
  • Karma: +0/-0
    • View Profile
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #173 on: January 16, 2017, 07:10:42 PM »
Quote from: KM
however the whole screen goes black while it's being resized, and only upon movement does it render the screen again.  Is this normal?
Does it go black while resizing or after you release the mouse button and until some other input? The latter is normal since scene contents are cleared when it is resized, you need to recalculate the layout and redraw the scene for a new size.
[/quote]

Before another input is entered.  Would I be able to make it recalculate and redraw the layout based on releasing the mouse button or somesuch?

Is there a general command to redraw the screen, as I'm also having the same issues after exiting any other screen such as inventory, character class, and etc, that only the objects and items are drawn before I move, not the background tiles at all.

KittyTristy

  • Newcomer
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #174 on: January 18, 2017, 11:34:04 AM »
I've been using BearLibTerminal and I love it (I've extensively used libtcod in the past and BLT is just so much simpler).

Well, I was wondering Cfyz.. do you plan to add support for animated tiles?  I have a game I'm working on with drawn tiles and I'd really love to have them be animated.  I couldn't see any way to do this currently, so do point out if I'm wrong here. :)

Anyways, thanks for the awesome library!
« Last Edit: January 18, 2017, 11:35:54 AM by KittyTristy »

Cfyz

  • Rogueliker
  • ***
  • Posts: 194
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #175 on: January 18, 2017, 02:37:03 PM »
Another small update: 0.15.1 (Windows / Linux / OS X / PyPi)
* TrueType fonts/tilesets use font's native hinting now instead of TrueType's automatic. It is also possible now to choose the hinter manually via 'hinting' tileset attribute.
* Python wrapper searches both module directory and application directory for library binary.

Quote from: quejebo
I seem to be having trouble with ttf rendering.  Check the attached image, and note the exclamation mark on the left.  Is there something I might be doing wrong?
That's what hinting changes are about, should be working correctly now.

Quote from: KM
Before another input is entered.  Would I be able to make it recalculate and redraw the layout based on releasing the mouse button or somesuch?
Is there a general command to redraw the screen, as I'm also having the same issues after exiting any other screen such as inventory, character class, and etc, that only the objects and items are drawn before I move, not the background tiles at all.
This looks like it heavily depends on your code logic. It is hard to say what and when you should call without looking at the code.

The only command to redraw the screen is terminal_refresh() but the problem is after resizing dimensions are different and library cannot just redraw by itself anymore since it has no idea about your application's layout. Once you've received TK_RESIZED, you need to recalculate new positions and sizes of map, objects, UI, etc. accounting for the new viewport size. This may be done in various ways depending on the input and rendering logic. Some applications calculate and redraw everything every frame and then it's enough to make it run a one more cycle. Some applications separate scene in layers/modal dialogs and then you need a method to invalidate and reconstruct everything at any given time. Not every logic incorporates scene resize easily. Usually it is best to design the loops and logic with resizing in mind right from the start.

Quote from: KittyTristy
Well, I was wondering Cfyz.. do you plan to add support for animated tiles?  I have a game I'm working on with drawn tiles and I'd really love to have them be animated.  I couldn't see any way to do this currently, so do point out if I'm wrong here. :)
Yep, there is no support for that right now. If you need animations you have to loop and redraw manually =/.

I've thought (still thinking?) about animated tiles and the biggest obstacle is that library does not know anything about the objects in a scene. It might be okay for something nailed to a screen but if you try to move/scroll things, the mapping is lost. The animation is either twitching (if cell changes restart it) or continuing in the wrong place (if some cells move simultaneously and the new content is indistinguishable from the previous one at the same coordinates). The only one that looked fine in my mockups is a very simple several-frames simultaneous animation like in DawnLike tileset.

KittyTristy

  • Newcomer
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #176 on: January 18, 2017, 10:22:21 PM »
Quote from: KittyTristy
Well, I was wondering Cfyz.. do you plan to add support for animated tiles?  I have a game I'm working on with drawn tiles and I'd really love to have them be animated.  I couldn't see any way to do this currently, so do point out if I'm wrong here. :)
Yep, there is no support for that right now. If you need animations you have to loop and redraw manually =/.

I've thought (still thinking?) about animated tiles and the biggest obstacle is that library does not know anything about the objects in a scene. It might be okay for something nailed to a screen but if you try to move/scroll things, the mapping is lost. The animation is either twitching (if cell changes restart it) or continuing in the wrong place (if some cells move simultaneously and the new content is indistinguishable from the previous one at the same coordinates). The only one that looked fine in my mockups is a very simple several-frames simultaneous animation like in DawnLike tileset.

Thanks for your response!

After reading your reply, much to my own surprise I managed to get animation working with a very minor change to my code.  Basically in the code each object in a scene keeps track of the character that represents itself.  For some of my objects, this is now a list with multiple characters, and in the draw code, if it sees that it's a list instead of a single character, it chooses a random entry in that list and uses that to draw with on the current redraw call.  It allows for only simple two or three frame animation (something like Ultima 5 for example) but that's precisely what I was going for!

I'm going to need to make some tweaks for animations that need to be consistent (such as water tiles) but I definitely wasn't expecting to be able to get animations working so soon, so I'm quite pleased.

Thanks again for your reply because it inspired me to poke at my code and get animation working. :)

tapeworm711

  • Newcomer
  • Posts: 12
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #177 on: January 19, 2017, 02:29:08 PM »
https://github.com/joekane/bltColor


bltColor

A color Class for BearLibTerminal that adds libtcod-like color functions.

Features:
  • Set alpha of a color.
  • Multiply by float.
  • Multiply two colors.
  • Add two colors.
  • Subtract two colors.
  • Blend two colors with a bias.
  • Generate a custom gradient using color_map

This class is fully compatible with any function that BLT wants a color parameter, including [color] formatting tags.

quejebo

  • Newcomer
  • Posts: 6
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #178 on: January 20, 2017, 06:06:10 AM »
Quote from: Cfyz
Quote from: quejebo
I seem to be having trouble with ttf rendering.  Check the attached image, and note the exclamation mark on the left.  Is there something I might be doing wrong?
That's what hinting changes are about, should be working correctly now.

Yeah, looks better now.  Thanks!
« Last Edit: January 20, 2017, 06:08:32 AM by quejebo »

KM

  • Newcomer
  • Posts: 13
  • Karma: +0/-0
    • View Profile
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #179 on: January 22, 2017, 09:33:17 PM »
So I downloaded the new bearlibterminal after seeing your comment in my thread, and now when I import it, I'm getting strange errors. 
Now when I try to run my program I get;

Code: [Select]
Traceback (most recent call last):
  File "gritandsteel.py", line 6, in <module>
    import PyBearLibTerminal as bear
  File "C:\Python27\Grit\PyBearLibTerminal.py", line 70, in <module>
    _wprint = _library.terminal_print16
  File "C:\Python27\lib\ctypes\__init__.py", line 375, in __getattr__
    func = self.__getitem__(name)
  File "C:\Python27\lib\ctypes\__init__.py", line 380, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'terminal_print16' not found

I have no idea what this means, or why your code looks like this.