C TUI Developement - Help / Tutorials? - c

I have been looking through previous questions regarding this topic and so far none of them answer my question. I am looking for a way (without libraries) to build my own TUI from the ground up. I want to start off with a simple program that reads a directory and displays the contents with the ability to use arrow keys to move up and down highlighting one item. As simple as this may seem this would be all the help I need to get started on the rest of my project.
All I need is for someone to point me in the right direction for clearing and printing to the screen and not using a print statement or external library. Any help would be greatly appreciated.

Well, to be honest, you can. But as others will tell you, curses is the right tool for the job.
That said, this isn't the 80s anymore. <overgeneralization>Everybody uses Xterm.</overgeneralization> Xterm uses ANSI VT100 control codes, mimicking the classic DEC VT-100. If you target this, you should be reasonably ok and portable.
But curses is really nice. It does a lot of the hard work for you (and there's plenty of hard work left to keep you busy).

Related

Can You Still Achieve MS-DOS like GUI In CLI?

It's been many years since I've looked into this. Maybe when I was just getting into C++. But is it still possible to achieve MS-DOS like graphics on a command line interface? Obviously with some small hacks that you can achieve the color scheme. However I'm looking more into menu options. I.e. radio controls menu select.
And yes I know you can also achieve this probably a little bit easier using SDL. But I was just curious if anyone else has accomplish this and has some details posted on the Internet or can possibly point me in the right direction. If this is not as easy to achieve anymore on windows 10 I'll just go on and find something else to do for fun.
Thanks.
Yes, absolutely. You can either use functions such as Set/GetConsoleScreenBufferInformationEx or you can enable VT-100 escape sequences and use those (you'll remember this as ANSI.sys in DOS).
That's the more portable method, as the only windows-specific part should be enabling VT-100 mode, everything else should be the same on Linux.
SetConsoleMode: https://msdn.microsoft.com/en-us/library/windows/desktop/ms686033(v=vs.85).aspx
Or to read and write the console buffer directly:
Console APIs: https://msdn.microsoft.com/en-us/library/windows/desktop/ms682073(v=vs.85).aspx

Is it possible to program a "selectable" number of devices without actually hardcoding every possible scenario?

I have been working on a project over the past 6 months creating a program to control some machinery. The software controls some servos, and other bits mostly via serial communication.
It is currently programmed in ANSI C99 in the Lab Windows IDE, along with some of its included libraries. As the project continues, there are many different variations on "how many" servos are needed for each build. This ends up requiring custom coding for each one. I feel the core logic could still be programmed this way, and just put into a dll if need be, and the rest programmed in something else like C++ if need be.
Due to the fact that each servo needs to be individually controllable, is there really a way to allow a user to select how many they want during an initial setup?
I know it is simple to create a UI element to allow a selection, but how would you go about dynamically creating new UI elements, and variables associated with that UI element for individual control? I think this could work in an interpreted language, where you could have a function literally write out new code after the user makes a selection, but I don't know how to achieve this in a compiled language.
I am currently just researching the feasibility of moving this direction at all, and would greatly appreciate any thoughts or input. If it is possible, I think I just need a basic example of how to go about this sort of problem.
The only way I can personally think of achieving this is to literally program out every possible scenario, but we are talking potentially about 50 variations, so I am really hoping there is a more efficient way to go about this.
If you have any questions for me in order to better answer, please feel free to ask! Thanks in advance!

Conio2.h in CodeBlocks

first I want to apologize for my bad English and second for this topic, I didnt find anything like this so I create it.
My problem is:
I want to create a game where I want to use conio2.h, but problem is, that I cant find it on the internet. Still I find something with Linux, but I need it on windows. Im using CodeBlocks, it is good program but it doesnt have this library
Can you help me guys?
Conio is an old MS-DOS header. You will not find it in modern compilers. For Unix/Linux systems, you can use curses, Windows Systems have their own libraries and functions.
You may want to ask a question on how to do something specific you are having problems with and posting some code.
For example, setting the cursor position can be done with SetConsoleCursorPosition .

SDL writing text

I'm having a problem for a SDL project, I'd like to show text on the window and allow the user to input text. As much as I know, there is no simple way to achieve that. Do you hava any suggestion?
Note: I use C programming langage. I know there is a library called SDL_ttf which doesn't seems to make the job I want.
I have to be honest, as I was reading your question, SDL_ttf immediately sprang to mind. It's not too hard to use and there are plenty of docs available.
What it sounds like you are looking for, is a library that provides a simple console interface, where your main programming interaction is to write(...) and read(...) text and it handles display, scrolling and so on.
This project has a lot of code showing how to implement a simple 'console' in SDL, and it does use SDL_ttf to do so.
I'm not convinced you are going to avoid it, unless you grab someone's library that hides it away from you like this one but you are going to have less control over the display and interactivity this provides.
I must go with benosteen, SDL_ttf is a really good option. For my part, I used this tutorial to make it work in my project. It's really simple and straightforward.
EDIT:
I had some troubles with the Blending functionality of SDL_ttf, but I managed to make it work after QuasarDonkey found the problem in this question.
Have a look for a straight forward example on how to use it and create text surface.

2D game development basics

I would like to write some simple Mario-like game from scratch using language C. But honestly I have no idea how to do so, and I canĀ“t find any good tutorial for this, which is for free.
But to the actuall question, I have only written WinAPI programs so far, so all event handling and user input was handled by OS, with minimum work, But to develope game, with for example menus with non-rectangular buttons, animations, and so, I guess, there is no such thing in WinAPI taht could help me with this more than just some basic routines mouse pointer location and keypresses.
So, is the right way to write your game to write entire draw part of game engine by manipulating objects for player, enemies, and even background yourself, and than just use directdraw for output to screen?
EDIT:
I actually want to learn how to write games from scratch, becouse it must be great programming experience, and if you consider games like Commander Keen on DOS, created with no framework or libraries, but still so great.
A good approach to this would be to have a look at the SDL library. I'm not saying it's necessarily the best library for 2D games, but it's easy to get started with and the web is flooded with tutorials and open source code samples for simple homebrew 2D games written using SDL.
I do recommand the SDL too, but you should definitely have a look on lazyfoo tutorial, which is just great.
When I started programming I started doing it with Allegro, back in the good old DOS days. It was the first usable library which worked with SVGA libraries, and had a good sprite support. Then version3 came and they added support for windows (using GDI and Directy X, you could choose at runtime which engine to use). The linux port came to life, and all is good.
It's a very basic 2D library, and it will teach you the very basics of graphics and animations. Now it even contains audio support which is a very needed addition (well, I still remember V 2.9X...). They are in betas for version 5, and I think this is an interesting project for you to look into.
http://www.talula.demon.co.uk/allegro/
What are you guys talking about, the WinAPI has low level drawing routines.
Although using an established library like SDL is probably a better idea you could create your own abstractions to the WinAPI drawing routines without too much difficulty.
Then it's just a matter of creating the while loop that has all the drawing instructions and interpreting input. For 2D games this isn't too difficult.
I also used SDL, but try to look at HGE. It requires at least DirectX 8.0 so your applications will work only on Windows but on their forum you will find many topics on how to port it to OpenGL. In my opinion HGE will be easier to learn than SDL, because SDL is a low level library and you will have to learn how to handle many things by yourself. HGE is more ready to start just out of the box.
In short, yes - there's nothing in the WinAPI that will help you much. However, there are dozens of game engines that you could build your game on that would take a huge amount of gruntwork out of creating the game itself. A bit of Googling will help you.
(Personal recommendation: although it's technically a 3D engine, something like Unity is an excellent engine that includes tutorials for creating 2D games. Unity isn't C, but it does make your life a lot easier...)
EDIT: I actually want to learn how to write games from scratch, becouse it must be great programming experience, and if you consider games like Commander Keen on DOS, created with no framework or libraries, but still so great.
This is actually not quite right. Commander Keen (and any DOS games) do use libraries: the ones provided by DOS, BIOS, etc. Without libraries of one form or another, you wouldn't be able to do anything useful with C. For game programming, you really do want to leave all the low level details to someone else.
I'd recommend Allegro as a beginning game programming library.
Check out this one Game dev starting
They have realy a big resource related to game programming and a lot of beginner stuff. SDL is good, but you should consider about learning basic game techniques before start coding and even before start thinking about the api/libs you use.
Clear out how much "intelligence" you need (Ki), consider about loading/Saving a an early time, ... so much things that you should keep in mind if you want to finish your project.
Do you need a game editor? (Also..work) What about sound/graphics? Writing all this stuff on your own will take a lot of time (if you do not have experience). Creating the content is another big issue which can consume a lot of time, if you make it at all.
Maybe it will help you to have a look on some dev kids, because that will give you the idea how their engine works. Like this one (outdated) Dev kid
I've just started a similar project a few days ago, you can check it out over at GitHub.
It should give you some ideas about how the game is structured. As well as some details on a scrolling 2D map with collision (which turns out to be quite complicated if you want to get it 100% bug free). Oh, and it's using SDL as many here have already suggested.
As for me, this is my first C project. But I'll have to admit that I've done similar stuff in Java and Python before, so this was a good way for me to quickly learn C. And since it's learning and not any productive stuff, I'm using plain C99, which makes the task even "funnier".
But back to the game, you really need to think about your design before you start coding, write it down on a sheet of paper, or if you're like me and you don't have tree stuff in reach write it in pseudocode.
Think about as many possible game states as you can, nothing's worse than having to re-implement the whole player/map/whatever stuff from scratch just because you did not think about feature XYZ before.
Design is very important, if you don't have a goal to begin with, your project will reach a point where it fails, just like my Tuff did, well it also failed due to missing music and somebody who would have designed enemies, etc.
Speaking of graphics and such, bear in mind that the game will consist of much more than just the plain code. If you aren't good in graphics then take that into account while designing. Because you will quickly lose your motivation when the only things on the screen are colored rectangles.
Action Arcade Adventure Set (originally published as a book) is probably one of the most complete tutorials on how to write a 2D side-scrolling game. Although an older reference, many fundamentals for developing a 2D side-scroller have not changed.
Full source code examples and some tools to develop a side-scroller are provided as downloads. There is only one external library used to handle graphics primitives. As this is an older DOS program, you may have to use a DOS emulator like DOSBox or modify the examples for more modern environments.
I suggest you skim chapters 1 to 9 and focus on chapters 10 to 17.

Resources