How to create a command line simulator GUI for C++ - c++

I'm looking into developing a text based game about cyber security akin to hackRUN or uplink but I have no experience with GUI programming and I doubt anyone in my family would want to learn how to make and run a .cpp file. So I need to create a GUI featuring a custom command-line akin to Linux or windows "cmd". Is there any resources available in that area?

You can create a textbox control that's the size of the entire window, and customize it to make it look like a console. For example, set the background to black, the color of the letters to white, etc.
How you create that textbox depends on what UI framework you're using. For C++ there's MFC or the managed WinForms, or you could create the UI part in C# using WPF and use C++/CLI as a bridge between C++ and C#. But if you want to make it work on both Windows and Linux you can use wxWidgets or Qt.

You can simulate a commandline by reading a line from the user and splitting on the first space (Python/pseudocode*):
for line in raw_input():
command,arguments = line.split(' ',1)
For example read book is the command read with the argument book.
Then you can process the command they gave using your own logic. The advantage of this approach is that you can just run your game via a shortcut on the desktop (whether linux or windows) and the OS console will support the interaction.
There is a class of games called 'text adventure' games, which were popular back when graphics were limited or nonexistent, which you may find particularly relevant. Consider using an existing text adventure engine so that you can concentrate on the game itself rather than the mechanics of text entry and parsing.
* Consider writing this in Python or a similar scripting language, as they provide straightforward handling of strings etc. You are unlikely to need the raw power and complexity of C++ for a commandline-style family game.

Related

SFML vs Qt in C++

I decided to switch from console to windowed programs, so I did a search for the best graphical libraries for C++, and of the many I found, I liked the following ones:
Qt
SFML
I have to decide which one to use, so having some doubts only I ask you the following questions
When to use Qt and when SFML?
Is SFML only suitable for creating vidiogames or can it also be used to create dekstop apps, or is it better to use Qt for this purpose?
Does SFML already include constructs for desktop apps like buttons?
If I created the same desktop app once with Qt and the other with SFML:
which would be faster in execution.
which would be lighter in terms of memory usage.
Imagine a simple programme with an input text and a button, where you enter a path to a file to be encrypted, and clicking the button below the input text starts the encryption process
As far as legal terms are concerned:
If I were to sell my software realised with the SFML library, would I have to pay them anything?
Same question but with Qt
When to use Qt and when SFML?
Qt is for any kind of Desktop app that uses a rather standard GUI. SFML is for creating games with their own non-standard GUI.
Is SFML only suitable for creating vidiogames or can it also be used to create dekstop apps, or is it better to use Qt for this purpose?
While you can create a standard desktop application with SFML, it's kinda like creating a model of the river Kwai bridge from toothpicks. Certainly an interesting hobby, but you will need to invest an extraordinary amount of time and patience to create something people will judge an interesting oddity.
Does SFML already include constructs for desktop apps like buttons?
Not in a way you would expect. Not like Qt.
If I created the same desktop app once with Qt and the other with SFML:
which would be faster in execution.
The SFML app.
which would be lighter in terms of memory usage.
The SFML app.
Please note that programming the SFML app to a standard of the Qt app would also probably take 100 to 1000 times as long and much higher skill. So those questions above do not make sense without this context.
It is a little like asking what is more fuel efficient, flying to Sydney or running to Sydney? Well, since running uses zero kerosene, running is more efficient. Just takes a pretty good runner and a lot of time. Well, assuming you are in Australia, otherwise, good luck. So you are not asking the right question here, nobody would run to Sydney based on how much kerosene they save. That is not the correct measurement to base your decision on.
Imagine a simple programme with an input text and a button, where you enter a path to a file to be encrypted, and clicking the button below the input text starts the encryption process
Yes, that is the job of frameworks like Qt, not full screen renderers like SFML. If you don't want 3d fireballs exploding while you do your encryption, stay with Qt.
If I were to sell my software realised with the SFML library, would I have to pay them anything?
No.
Same question but with Qt
No.

I want to create a DeskBand. Do I have to use C++?

I want to create a DeskBand to display some information on my Windows task bar, but I am struggling with implementing the functionality I need in C++. It's been about 10-15 years since I touched C++. I've been working entirely in .NET for the past 7 years.
Before you say it - I know that DeskBands are deprecated. But the suggested replacement UI element - thumbnail toolbars - don't meet my needs. I need a UI element that is constantly visible to the user no matter which application they switch to, and also that provides enough room to display a line of text - I could get by with room for 30 characters or so.
I've been able to get the DeskBand from the Windows SDK sample to compile and run, but now I need to implement some real functionality - specifically...
Locating the AppData\Local folder (SHGetKnownFolderPath(FOLDERID_LocalAppData...)
Watching an XML file for modifications. I need to parse and repaint whenever the file changes.
Parsing the XML file (I found pugixml)
Displaying some data from the XML file in my DeskBand
Setting a timer to repaint the DeskBand once per minute
... and I am realizing how little I know about C++, and how much I've come to depend on .NET's Base Class Library. This task would be super easy for me if I was writing it in C#. But I've learned elsewhere that you shouldn't write shell extensions in .NET.
What are my options? Is there an easier language to accomplish this in - maybe Python? Or do I have to just bite the bullet and do this in C++? If so, any advice for a .NET developer trying to implement a WinAPI shell extension in C++?
Thank you in advance.
Shell Extensions are COM objects, and C++ is generally the best language to use when developing COM objects because COM was designed primarily for C++, but it is not the only language possible. COM has a standardized architecture, so you can use any language outside of .NET that supports COM object development (Delphi, VB, etc) to develop Shell Extensions (similar to how the Win32 API is primarily designed for C, but any C-compatible language can access it).

QML/D text editor and basic considerations

I am going to code a text/code editor (GUI with QML and the rest in D*). But I have several problems:
I code the GUI with QML and C++ and then I connect it with a D-Backend for formatting etc. purposes. What is the best way to connect different Languages? Pipes, Sockets or in D the ability to use C++ Libraries?
IMHO rich text is used to format the text (in most cases). How is it possible to edit this "markup" in an easy way?? Is the formated code like a background image and the user edits an opaque non-formated-text?
Are there common techniques?
*Because QML is cool, platform indepedent and fast. On the other hand D is powerful and easy to use.
As you might know, there is QtD, Qt binding for D. It's not production ready right now, but it might be some day.
Another option would be connecting C++ and D, through C wrapper. This is the most commonly used way of interacting between C++ and D.
extern(C++) interfaces are specific to DigitalMars C++ compiler on Windows and are very limited, so that probably wouldn't help with your problem.
Also you might want to look at SWIG. It's a tool automatically generating glue code for interaction of other languages with C++. It supports D.
If performance is not an issue communications with D code could work through sockets or pipes.
QML isn't for WebApp. It s QtQuick Markup Language. The 'new' way to do UI at Qt. And QWidget will probably be deprecated in favor of QML in Qt5.
I've try to do the same thing. But i fear that qml isn't ready yet to do things like that. Most element available today are just good enought to draw image, rectangle, listview, one line text input and do transition.
I was trying to achieve that by coloring with python and pygments, too slow, using html3.2 style to do that isn't the right way. But it's the only way to style text in qml textedit. ;(
QtQuick 2.0 should bring better text control.

making a gui editor

For my school project, I would like to build a gui that someone else can use to create a gui. Upon some research I saw lot of gui builders but didn't see anything along the lines of what I am looking for.
But then I did find a tutorial using C# on here
I rather create this gui editor for linux environment.
Any suggestions to where I should start? what tools I can use? Any links to any tutorials?
Any help/direction would be greatly appreciated.
P.S. I would like to add that it only needs to be very simple. like few text input fields and some button type fields that user can arrange in the order desired.
I would recommend that you not try to build your own GUI builder. It is a daunting task that you will not be able to accomplish as a school project. C++ is fully-compiled, which means that it lacks almost every feature that enables people to build meta-tools (like GUI editors) for it. This mainly has to do with the fact that C++ does not have runtime reflection (natively, anyway). Beyond that, there is no "one GUI toolkit and/or paradigm to rule them all." This makes your problem incredibly difficult to deal with.
So: I would recommend Qt, because it works on a ton of platforms, is easy to use and is just plain awesome. You could also look at the billions of other GUI toolkits like Gtk+, Tk, FLTK, YAAF, GLUI, dlib, CLX...
I'm aware that this does not actually answer the question. However, I do not think that the author is aware of how incredibly difficult the task he has set in front of himself is.
I would recommend starting by implementing it like an interpreter. Start with a very simple command line tool that takes commands like window(300, 400, "window1") and button(50,100, "button1") etc and output the code (native or whatever other GUI code you want), to a file. The goal should be to output a file that can be run and show the GUI that was designed. Once you have that, build a GUI that uses the command line functions as a back-end.
I don't have any exact links to this, but here's an example of what you could do. Gtk has the option of loading a GUI by using a class called GtkBuilder. Glade (the usual Gtk gui editor) has support for outputting it's result as an XML file that the GtkBuilder class then reads.
It would be possible for your program to output an equivalently formed XML file that GtkBuilder could read.
I have no clue as to how difficult it would be to target that XML though.
You should use GTK+ or Qt if you are targeting the linux environment. I think the first step is to learn how to program gui, which takes some time considering you are writing c/c++ code wich is different from higher level languages. Don't you think learning to code gui programs and writing a gui builder at the same time is a little bit too much.? First you should master the basics about gui and then go on to harder projects.
Here's a link to an excellent book on gtk. (Foundations of gtk+ development - Andrew Krause)
http://books.google.com/books?id=L1BZZYRrqSgC&printsec=frontcover&dq=foundations+krause&hl=es&cd=1#v=onepage&q=&f=false
And here's a great tutorial/cookbook for gtk+.
http://zetcode.com/tutorials/gtktutorial/
The official documentation is on library.gnome.org
My final advice is learn one thing at a time.

Modifying old Windows program for Mac OS X

This application was written for windows back in 1998,
I loved using this program, Now I want to learn how to make it
work on Mac, And maybe changing and adding functionality,
The problem is I don't know where to start, I Have studied C++ php, javascript, But don't really know how to read this code. or where to start.
Thanks for taking a look
http://github.com/klanestro/textCalc
From http://www.atomixbuttons.com/textcalc/
What is TextCalc?
TextCalc is a combination of an
expression calculator and a text
editor. Being both, it has several
advantages over conventional
calculators.
1) You can evaluate expressions like
9*4-2+95-12 just the way you write
them on paper.
2) You can put comments besides your
answer and expressions.
3) You can save, reload, edit and
print your results and expressions.
4) You do not need to write your
answer down on a paper before
computing another expression, as you
can leave the previous result in the
editor.
5) You can open an existing text data
file and perform calculations on it.
6) You can apply an expression to many
numbers at one go. For example, you
can change the list 1 2 3 4 5 to 2 4
6 8 10 by multiplying each number by
2.
7) You can sum, average, convert into
hex etc. a list of numbers easily.
The editor is capable of parsing
numbers and strings enclosed in double
quotes " ". Numbers will be colored
blue and strings will be colored red.
This makes it ideal for editing files
containing numeric data.
★✩
Based on the screenshots and info on the TextCalc site, I think this is best implemented as a Mac OS X service. You can assign a hot key to trigger your service in the System Preferences -> Keyboard -> Services.
It would actually be rather easy. You don't need to write the text editor portion, it will be available in all text areas in all apps. You will be handed the text the user has selected, and all you need to do is evaluate it. There's a built-in command line tool, bc, that you should be able to delegate this to.
There is a guide to implementing services. You will need to read through the Cocoa intro material to understand it. This is a good first project, though.
I don't think there's any reason to try to read the source of the original app in this case. You just need to know what you want the behavior to be.
Check out the Calculator example from the second chapter of Stroustrup's "The C++ Programming Language".
It looks like this application is written using MFC, which is quite Windows-centric. Translating this program to use a different API such as Cocoa would be a lot of work, and would require good familiarity with both MFC and Cocoa. Not to mention the work involved in translating the C++ to Objective-C, of course.
You may be better off running it as-is in a virtual machine such as VirtualBox, or under Wine. Unfortunately, the free version of Microsoft Visual C++ does not include MFC, so to modify this code you would have to either purchase a non-free version of MSVC, or translate the program to "bare bones" Win32, without using MFC.
The core part of this program (Expression Evaluation) has been taken from this smaller program written by Zoly Farkas.
So I would suggest the following:
Learn Objective C.
As an exercise, port Zoly Farkas' Expression Evaluation to Objective-C, to use as a library or on the command line.
Learn Cocoa.
As an exercise, create a graphical interface for your library using Cocoa. You don't need MFC.
Should be fun! :-)
I would not recommend to "port" such a old program using MFC which you cant use on a Mac anyway.
Rather i would recommend to create the skeleton of a new blank application and then to insert more or less large fragments from the old code. The skeleton may use whatever language is appropriate: C++, Objective-C, real Basic. But as the code to reuse is C++ its probably best to use C++.
If you decide to re-write it, I recommend RealBasic. It has many components that will help shorten the development cycle and you can compile the program for Windows, Mac and Linux.
Easy to learn and very productive platform.
Why not rewrite it in C# .NET and use Mono to compile it on the Mac? You can rewrite the GUI parts in Native Cocoa from c# using a wrapper. Depends on your program but this program doesn't sound like your going to sell it to the public so L+F issues are probably not an issue.
The code looks to be in C++. C++ is available on Macs.
The code relies on MFC, which if course is not available on OS X. So you'll need to pick a framework like WxWidgets, Qt, FLTK, etc. that's available on both the Mac and Windows. Then you need to translate from MFC to your new framework.
In the process you'll learn more about MFC than you intend to.