Monday 10 August 2015

What happened to textattr?

While I was away from console programming they have removed textattr() function from conio.h. Reading some random explanations for why it's a DOS function. No, it's actually a console function. They (reptilians?) did keep printf and even cprintf which I vaguely remember is actually the color version of printf. When you look at conio.h it's not even that big and Microsoft has added bunch of irrelevant "secure" versions of functions in there. They could have kept textattr for sure, because WinAPI does have color actions, they are just more annoying with that WinAPI style.

I've had fun writing the tiny GUI for console. My plan is avoid (most) problems I've previously had. For example the output is strictly limited to Display_Matrix class which defines a rectangular area of CHAR_INFO (Microsoft's struct for letter and color data). It's a simple container where you can write characters and strings with color data. That rectangle is then output to actual console. With Display_Matrix each screen or window is its own area and I'm also including update flag in the Display_Matrix: when the matrix is changed the flag for updating is set. It prevents duplicate or more updates per turn in low level manner.

The usual problem in class programming is that you may start to add some stuff to class which clearly doesn't belong to it. In small projects it does reduce the amount of classes needed, but it's still less modular way to think programming. Classes should always be as modular as possible and do one task using various types of source data.

No comments: