Jump to content

  • Log In with Google      Sign In   
  • Create Account


Now a simple GUI


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
14 replies to this topic

#1 QwertyKey   Members   -  Reputation: 122

Like
0Likes
Like

Posted 02 July 2011 - 10:42 AM

So I have something preliminary for a game, in C++. It is in the console but it's really clumsy to actually try to use it, and I don't like it.

I want to design a simple GUI. It would just be 2D, I would want to be able to use a mouse to click on different parts of a game screen, and I want it to display different colors. If I could import simple graphics that would be nice but I think text and clickable grids (like if I can get boxes, like a button but not the typical button graphic) should be sufficient. I want it to be able to respond to different keyboard clicks too (like say I hit F1, I want that to do something specific). I want this to be able to run on Windows.

I have a specific game in mind and some functionality. If more information will help let me know.

What do I need to learn to make this happen the easiest way possible? I was thinking of learning C# and XNA but that seems more advanced than I need.

I know C++ but nothing else.

Sponsor:

#2 KazenoZ   Members   -  Reputation: 152

Like
3Likes
Like

Posted 02 July 2011 - 01:05 PM

Well, I'm not quite sure what you intend to with your program in general, and that makes this a little hard to answer, but there are a couple of options that come to mind.

First, and a very easy method, actually, is .NET, you can simply make a .NET Windows Forms Projects in Visual Studio, making the GUI is pretty much the simplest thing you'll have to do in your entire programming career, it's just a simple drag and drop interface to make it and implement Windows controls such as buttons, drop boxes and list containers, as well as picture and sound support.
However, this has 2 drawbacks, the primary being that it's a WINDOWS Form Project, and as such, I don't think it's crosscompatible, but seeing by your question that you intend it for Windows only, that's probably not too big of a deal for you.
And the 2nd being that this sort of project uses a more advanced form of C++ that is far less supported by the community, it uses Managed C++, whileas what you have probably done up until now had been Native C++.

The difference is not _too_ drastic when you get used to it, but there are a number of things that you'll have to overcome, such as MC++ being an Event-Driven language, having some data types that aren't compatible between Native and Managed C++(I.E. 'string's and 'list's that are now 'String^'s and 'List^'s, and pointers that now use ^ instead of * and aren't interchangable), classes that need to have a different design, making native classes need to be wrapped, and native libraries that basically aren't supported(Though thankfully, a large number of which can automatically be wrapped by VS's IJW(It Just Works) system).

While all of the above can be solved, it does take a while to get used to and learn how to do everything, though like I said, you don't get much support for it over the net, and that is because that most people that use .NET, prefer to use the C# .NET, which is more advanced and easier to use, but would require you to pick up on C# now.

So, going down this path, you need either learn how to program in Managed C++, or C#, neigther are complicated, but that's still something you'll have to do.



The other option, is just making your own GUI using existing graphic libraries, like SFML or SDL, I'm not gonna lie, these are gonna be alot harder to do, even if you're already familiar with the libraries, since you'll need to manage all your keyboard and mouse events on your own, as well as their effect on the GUI.
The benefit in going this way, however, is bigger, since you get your support for Native C++ back, and get cross platform abilities.



So, to sum it up:
.NET:
Positive - Easy to use, implement and design, has a very large number of ready controls, powerful,
Negative - Not widely supported, doesn't support crossplatforms(And in your case will need you to take up a new language to learn).

SDL/SFML/etc.:
Positive - Crossplatform, simple library, very customizble in comparison, widely supported.
Negative - Harder to make, time consuming, and only as powerful as you make it.


Now, lastly, getting back to my main problem with your post, you didn't specify what exactly you want to do, if all you need is button support and no real code being it, but .NET is certainly the best for you, but if you're planning on an actual game, that probably won't be using Managed C++, or .NET, for that matter, code in it, and as such you can't even run it in the same program, so if you're planning on using the GUI's buttons DURING the game's run, to effect the game itself, you'll have to go with a native library.



Sorry for the long post, but just trying to do my best to help here :)
If you have any more questions, feel free to ask.

#3 JoeCooper   Members   -  Reputation: 338

Like
1Likes
Like

Posted 02 July 2011 - 01:15 PM

There's also toolkits for use with C and C++ like Qt and GTK as well as ones designed to jive with things like SDL and SFML.
And I'd like to add, just in case the OP was thinking of writing his own toolkit (e.g. using basic SDL paint code) that I had a far easier time doing this after I had been exposed to a few like Swing.

Working with toolkits built by the masters gives a clear impression of how they're typically put together.

After having worked with other kits include Swing and Gtk, I had no trouble throwing one together for use on top of OpenGL in my last project.

#4 QwertyKey   Members   -  Reputation: 122

Like
0Likes
Like

Posted 02 July 2011 - 01:19 PM

Hey KazenoZ,

I appreciate all the information. You are a big help! I think I will try to learn C# and use the .NET. Will this allow me to for instance switch views as well (something I meant to mention but forgot)? By this I mean, can I have a "normal" game screen, and then have different screens which display information related to the game? I guess by that, can the form "change?"

Thanks,
QwertyKey

By the way, thank you as well JoeCooper.

#5 KazenoZ   Members   -  Reputation: 152

Like
1Likes
Like

Posted 02 July 2011 - 02:26 PM

Unfortunately, as I mentioned, there's no way to run a game using a Form Project, you can make a seperate executable that will take entry point arguments(Using argc and argv from your main function), and open it through your Form Project, in a way that you'll be able to change settings before running the game(Using Process:Start()), but there's no real way, that I know of atleast, to use a Form Project to interact with another open application after its' initial starting point, so no, you can't draw information from your running game to draw on a Windows form, since the 2 are 2 different programs.

For your cause, you'll probably have to make your own GUI.
But by how you described it just now, most of what you need is just a HUD, right? Buttons to change settigns are simple too, if you don't want to go to ability extensive and just stick to basic click to activate it's very easy to do.

Let me direct you to these couple of tutorials by Lazy Foo', dealing with mouse events and graphic and text drawing with SDL:
Graphic drawing
Text
Mouse events

For your HUD, you can simply draw pictures that have the info you need, like a compass, a minimap or your health, and, if needed, draw text onto parts of the screen to signify things like objectives, ammo, etc.
Look at the mouse events tutorial to see how simple it is to make a functional button with custom graphics in your game.

Unless you need more advanced options like dropboxes, checkboxes, or anything else that is not covered in Lazy's tuts, I suggest you stick to them, since they are really fairly easy to follow =)


Also Joe, I very much agree with your view on this, but I don't have any experience with the 2 toolkits you suggested, so I can't really say much more about that.
Also, about what you said about learning how to make your own by using someone else's ready kit, I just have to say, that's pretty much true for anything in programming, it's always better to use someone else's work before making your own in every single aspect of programming, that's why it's always good to send the new people around here to try programs like RPG Maker, Game Maker and Phantasya before sending them off on their own to learn C++ and start there. Wouldn't you agree?
I just know that my years with RM taught me a whole lot of techniques in game making and project managing, before even starting to learn to program, that I still use often.

#6 JoeCooper   Members   -  Reputation: 338

Like
1Likes
Like

Posted 02 July 2011 - 03:00 PM

Yessir, that's generally the case, and of course I'd second the C# suggestion.

About Windows Forms for a second, I don't know enough to speak with certainty but I think you can use it for games.

What I've done both in Java+Swing and on iPad was have a modified UI widget that had the game's paint code (in the latter case it was an OpenGL display widget).

Such kits also provide timers which can trigger repaints at regular intervals.

So Windows Forms is OK too and you can actually use it to build a UI around your game and use regular widgets like labels to display game state information.

There's also XNA and Unity which might include some UI features.

#7 KazenoZ   Members   -  Reputation: 152

Like
2Likes
Like

Posted 02 July 2011 - 03:28 PM

The problem in making a game with Windows Forms is that they don't support alpha transparency for images, you can stack images, and you can move them around, but if you use an alpha color to become transparent, it'll show the bottommost layer below the color, deleting all images below it as well. I had a very hard time with this part when I needed to use a transparent panel to select a part of an image below it.

Also, I'm not sure how keyboard buttons will work in affecting the sprites, considering that Forms projects are Event Driven, and don't have a main loop to check for presses that don't relate to a specific control.

But, I don't really know many libraries that build off this, so you might be right, it might be possible, but wether it is, or not, I honestly don't think it's worth the effort, with the low support it gets both from the community and extension libraries.

#8 JoeCooper   Members   -  Reputation: 338

Like
2Likes
Like

Posted 02 July 2011 - 05:35 PM

What I did was actually decouple it a tad; use the event driven inputs to alter the game state (or just control state) and then do the actual work in the timer's callback.

Regarding the images, this is now 100% out of my knowledge, but it sounds like you're dealing with UI widgets as game elements rather than a single UI widget with overridden, custom paint code. If Windows Forms has anything like the Java Graphics component than you're set.

But it occurs to me as I write this that the OP would be digging a bit into esoteric knowledge that would be less useful than just going with SFML, Unity or XNA...

So uhh, nevermind.

#9 KazenoZ   Members   -  Reputation: 152

Like
1Likes
Like

Posted 02 July 2011 - 10:31 PM

Unfortunately, no. There's no way to manipulate the drawing of several graphics into a single pictureBox at one time, as far as I know.

And yea, I think it'd be best to stick to his own code here for the GUI too =P

#10 QwertyKey   Members   -  Reputation: 122

Like
0Likes
Like

Posted 03 July 2011 - 02:54 AM

Okay, so I should use C++ with SDL (that linked site has a lot of tutorials)?

#11 JoeCooper   Members   -  Reputation: 338

Like
1Likes
Like

Posted 03 July 2011 - 04:36 AM

Sure, go for it. I used it when I was new and learning C.

#12 KazenoZ   Members   -  Reputation: 152

Like
1Likes
Like

Posted 03 July 2011 - 08:46 AM

Seems like the easiest way for you right now, so sure =)
Don't hesitate to post questions if you get stuck too.

#13 SuperVGA   Members   -  Reputation: 1118

Like
0Likes
Like

Posted 03 July 2011 - 09:32 AM

Unfortunately, no. There's no way to manipulate the drawing of several graphics into a single pictureBox at one time, as far as I know.

And yea, I think it'd be best to stick to his own code here for the GUI too =P

Its weird. Using GDI back in 2000, i could easily draw multiple alpha-blended sprites to a double buffered picturebox (alpha blending in GDI was introduced with Windows 98) without much trouble. You'd probably rather set up a d3d render context in your picturebox, though... -I suggest you use wpf for forms,real-time graphics and platform support outside windows. You design forms in WPF the same way KatenoZ explained, still in MVS, still C#.

Just my 2 cents.

EDIT: "Doublebuffered" meaning having multiple hDCs, and copying from one to another. (The picturebox didn't have a doublebuffered property, maybe it does now, dunno. ;) )

#14 KazenoZ   Members   -  Reputation: 152

Like
0Likes
Like

Posted 03 July 2011 - 11:06 AM

Think you can dig up some articles about this? This really got me interested.

As for your question, no, pictureBoxes don't have a doublebuffer property now either =\

#15 SuperVGA   Members   -  Reputation: 1118

Like
1Likes
Like

Posted 04 July 2011 - 03:59 AM

Think you can dig up some articles about this? This really got me interested.

Sure, Kaze, this is the demo i originally got the technique from back when I used VB6 as my primary language: :P
http://www.freevbcode.com/ShowCode.asp?ID=2987

I'm sure it'll work with other languages capable of using Windows GDI.
I found some more language neutral (C++, really) articles:
http://msdn.microsoft.com/en-us/library/dd183353(v=vs.85).aspx
http://www.codeproject.com/KB/GDI/pxalphablend.aspx

As for your question, no, pictureBoxes don't have a doublebuffer property now either =\

Bummer, :/, oh well, it's just two handles and frame copying. Would be cool, though.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS