How does get object from point work? - c++

I'm new to programming. I want to make a card game with C++ / Allegro. The graphics api is irrelevant though. I want it to have many buttons you can click. I'm wondering the proper way this is done. For instance, how does windows know which control you click on from your cursor. I would use an array of rectangles and check each rectangle to ee if my mouse is is 1 of their bounds, but this doesn't seem very good. What about if I draw a line from 2 points and want to be able to drag any part of the line? I doubt i'm doing this right either. Any insight on this would be very helpful. Thanks

Basically, you want to make a mouse-driven user interface.
This is very difficult to do from scratch, that's why Allegro has a built-in GUI system. If you don't like it, you'd better use a GUI library than doing it yourself.
I'd recommand MasKing, it's an add-on for Allegro, to write graphical interfaces in C++.

Related

Mouse events on a cairo context

I'm developing an application with C++ and GTK3 but I'm stucked. I've created a visual application with glade which has three columns and one of them, the middle one, is a DrawingArea. In that DrawingArea I want to draw some circles at the point I want to after pressing a button and have different mouse events on that circles (like drag and drop, double click, right click...). I've made the first thing (draw a circle after pressing a button) following the official documentation, but the problem is that I don't know how to do the mouse events, but I thought about it and I have some different solutions (I don't know if they are the bests solutions or maybe there are better):
I think the best way is to create a signal to the cairomm context, but I didn't see anything to do that. Maybe the way would be to create a cairo surface or something like that.
Every time I click to create a circle, I would have to create a gtk widget in which I can handle mouse events. The problem here is that the widget needs to have circular shape and need to be drawable. Is it possible to create a circular DrawingArea? It could be the best. I saw the way to create custom widgets here.
Use goocanvasmm. The problem here is that goocanvasmm has a little documentation (I'm sorry I can not post more than two links because of my reputation) and I think this is not the best solution, I prefer to use cairomm.
This application was written in C using GTK2, and the circles were drawn using gnomecanvas, adding signals in an easy way to each circle; and now I'm moving this application to C++ and GTK3 to renew it.
I'm very new to GTK (and graphical interfaces in general), but I looked for solutions for hours and I don't know what is the best way in order to continue my work.
Thank you for your help :)
It's best to use a canvas library for this such as GooCanvas. Doing it with cairo alone would require you to listen to mouse events on the whole drawing area, and keep track of where the circles were in order to decide which circle the mouse event belongs to - exactly the problem which the canvas library has already solved for you.
If you are having trouble with goocanvasmm documentation, a look at the documentation for GooCanvas' C API combined with knowledge of how the C API translates into C++ will usually suffice. Although the GooCanvasmm documentation seems fairly extensive to me.

Simple library to display 2D images in C++ on Linux

I would like to have a tool to debug 2D planar meshes. I would like to be able to display them and debug to be able to debug certain things.
Is there a widget (for any toolkit on Linux - QT, GTK+Cairo, ...) which would display the images, scroll them and zoom it. Is there any widget which would handle it (without need to implement zooming, scrolling etc. by hand)?
Side requirements:
Needs to work on CentOS 6
I need it for C++. Unfortunately changing the build system in my situation is harder then it sounds.
The Qt Graphics View is certainly a useful tool, it gives you scrolling, zooming, rotating easily. You probably want to learn the basics of Qt before. (and Qt is in C++).
Here's an off the wall suggestion.
This would be fairly easy to implement in a web browser. Web browser engines already have the base functionality for resizing and scrolling over images. You may need a little JavaScript to bind it together, of course.
So why not use WebKit? There are bindings for many of the leading toolkits (e.g. QWebView for Qt), so you could take your pick of which one you're most comfortable with.
Yes, it's overkill. But it's code you don't have to write, and time is money.

Is there a way to customize what a button looks like in C++?

I have programmed in HTML, Java, CSS, C++, VB, an Python.
I'm looking to make button that looks completely the way I want it to look!
Like in HTML+Java+CSS, I can do that very thing!
I'm using Netbeans IDE. I was about to just use OpenGL to do the GUI programming for my programs, since it is so hard to find information on customized GUIs.
I just want to learn how to make the image and give button functionality to it. I want to be able to make the shape, color, and effects (when clicked, hovered over, etc).
Oh, and I program in Ubuntu Linux!
Any help would be appreciated!
Qt is a good idea, but you won't learn how it works, though it's not really important and far easier like that. Using C++ you will have libraries that respect the encapsulation principle, so you won't know at the first sight how do is work, just how to use it.
If you really want to code a button yourself, you can take a 2D drawing library such as SFML, with which you'll draw your button and handle events on it.
When I wrote a custom button class for my app, we (the C++ developers) were given PNG images from the designer department. They are much better with tools like Photoshop then we developers. We just showed image1.PNG by default, image2.PNG when the mouse was over the button ("hover"), and image3.PNG when the mouse was over the button and pressed. Drawing? Not necessary.
Color is trivial for designers. Shape isn't hard either. PNGs are rectangular, but can be transparent. So rounded edges are just a matter of a few transparent pixels there.

How to create custom skin like WinAmp

I guess this question has been ask before, but I have not found sufficient answer to even start poking around. Most answer refers to catching WM_PAINT method directly and do custom rendering, or use a onwer draw object. However, I did not see a centralized place that has the info. to start researching. Hence, the question.
My goal is to create a very simple GUI program with custom look into it. I prefer the way winamp does their custom look that is customizable through "skins". However, I am not interested in using some cross-platform library like GTK+, QT or wxWidget.
I have some experience in system programming, but not much for GUI. I spent most of my time developing console applications, and I just started doing some QT development. If you can point me in the right direction, I'd be very appreciated.
PS: I am interested in both windows and linux environment.
Everybody,
Sorry for the late reply. I had a chance to have a quick talk with the original developer for winamp, and this is the quick answers I have:
Using skins: Artists create skins, developer will render the skins
To the OS (Windows), winamp is just one pretty box, nothing else. There is a container windows, and that's about it
All controls (button, label, list, etc) are implemented by winamp team themselves. All messages and stuffs are passed as relative position to the container window. WinAmp and the GUI engine has to decide if a button is clicked or if the label next to it is the target, etc.
Rendering artists skins created in XML
I do not have the details on if they use any libraries to do all that, but I am suspecting they do hook a window call directly, and do custom rendering themselves.
GUI skin usually using plug-in mechanism
I guess this is exactly what you are looking for:
https://www.linux.com/learn/tutorials/428800:weekend-project-creating-qt-interfaces-with-gimp?utm_medium=twitter&utm_source=twitterfeed
I also interested in creating custom look of window and widgets.
Speaking about widgets it's not hard, just need to create subclass (if you are using C++) or some widget and implement some methods like draw, handle etc. But this solution is good only if you use some high-level library like GTK, QT, etc. If you want to implement all controls by your own, you may get any graphics library, which can create window and do any graphics inside. For example, SDL2 + Cairo. SDL2 for creating window, Cairo for vector rendering controls/widgets. Both of this libraries are for win and linux. Another option is take opengl/vulkan + some lib for rendering window. It could be SDL2, SFML, GLFW.
If you really interested how it works on low level, then search Windows API for Windows and XLib or XCB for Linux/X.Org.
Speaking about window, I still investigate it. However I have one thought: you may create an empty window and then draw whatever you want. Then you need to add handlers for resizing window on the borders. But I am not sure if it's good solution, and if it won't freezes.

Common game controls/ User interface libraries or source code?

Sorry for the ackward title, but i don't know what to call it exactly. I'm looking for code or libraries that allow easy creation of commonly used user input devices, and code/libs that make gaming controls easy to set up (i'm using SFML and Box2D at the moment)
I don't want to re-invent things like buttons, arrows being placed wherever the mouse is located, and more game specific items such as "controls settings" or even being able to drag objects around with the mouse.
More specifically i want source code for interfaces that....
Makes Buttons and Textboxes easy to create
allows mouse input to press buttons or drag objects in games
has "Focuses" (like a textbox being able to gain focus and be typed in)
Is compatable with SFML/Box2D
and code for common game mechanics/controls that....
Allows easy setup of controls for a game
Makes events like clicking and holding on an object easy to setup, as so objects can be dragged around afterward
Are there any simple libraries or resources out there that i can use to avoid spending much of my time coding these now standard input devices/tecniques?
I think CEGUI is the type of thing you are looking for:
http://www.cegui.org.uk/wiki/index.php/Main_Page
It is a GUI framework to work with OpenGL. Some others can be found in this list.
Still, if I were you, I would just use a major toolkit, such as GTK, Qt, or wxWidgets combined with SFML instead of dealing with CEGUI.
SFML has guides for Qt and wxWidgets with the rest of them at http://www.sfml-dev.org/tutorials/1.6/.
I have created my own little guide for GTK here: http://lalaland.github.com/gtkGuide.html