![]() |
|
GUI, GUI and more GUI... |
jaime barrachina
Member #6,780
January 2006
![]() |
So, nearing the end of my map editor project, I'm met with a problem when i have to "slap on top" of the project the GUI. There's the map on the left, in a bitmap (typical d_bitmap_proc) an there's the tiles on the right (at the moment, no another d_bitmap_proc), which the user presses and then he "paints" them on the map. In earlier versions, this worked out fine by clearing the screen, painting all the possible 256 tiles and then finding out he tile the user selected using the mouse_x / y the moment he clicked. But now the allegro gui does resicing and its quite "dirty "to do it, cause it's not 32 x 32 tiles anymore. So far I've thought of the folowing solutions: - Even if it's dirty, and evil, calculate which tile is the user pressing, even thought the rounding up of numbers may cause a pixel or 2 to be in the wrong tile. - Make a dialog with 256 d_icon_proc's. Not my favorite cause of the ridiculous amount of work for something so simple, and also cause several icons may be pressed at the same time and there fore it would need extra work to make sure its the tile we want. - Make some kind of universal d_icon_proc, using a "For" somewere for the 256 cases. The problem here is that first I'm not sure i could do something like that, and even if it could be done, i have no idea how to do it. I'd love to hear any suggestions and/or explanations on how to do it, cause I'm sure there's been many map editors since the world came to life and most of them must have solved this one way or another. Cheers and thxs!!! "Under the sword lifted high There is hell making you tremble: But go ahead, And you have the land of bliss. - Miyamoto Musahshi" |
CGamesPlay
Member #2,559
July 2002
![]() |
Quote: Make a dialog with 256 d_icon_proc's. Not my favorite cause of the ridiculous amount of work for something so simple, and also cause several icons may be pressed at the same time and there fore it would need extra work to make sure its the tile we want. DIALOG* list_of_icons = malloc(sizeof(DIALOG) * 257); for(int i = 0; i < 256; i++) { // Initialize what you need to here. } list_of_icons[256] = { NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, NULL, NULL }; // Use the dialog now. free(list_of_icons); // I don't actually remember the proper way to initialize a DIALOG.
-- Ryan Patterson - <http://cgamesplay.com/> |
Johan Halmén
Member #1,550
September 2001
|
In my a-maze game I have a maze editor made with allegro gui. I think I had 16 icon_procs that chose the tile I wanted to place out. But I had four or five pages of these procs. The pages could be selected with icon buttons that looked like those tabs at the top of the opera browser. I think the map was a modified bitmap_proc. When the mouse was placed over the bitmap, the mouse sprite was changed into the chosen tile. And clicking on the bitmap caused the proc to calculate which tile was clicked and then the tile was blitted to the bitmap at that coordinate. This would be almost equal to your first option. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest. |
jaime barrachina
Member #6,780
January 2006
![]() |
Txs for the replies, I'm going to try for now CGamesPlay's suggestion, I just didn't know if you could put "for's" and such in a Dialog. I'll post again if I manage anything, in the mean time I'm open to any other suggestions you may have Cheers and txs again!! "Under the sword lifted high There is hell making you tremble: But go ahead, And you have the land of bliss. - Miyamoto Musahshi" |
CGamesPlay
Member #2,559
July 2002
![]() |
Yep. Just make sure you malloc 1 more than the number of DIALOGs that you need, and set the last one to all NULLs or Os. -- Ryan Patterson - <http://cgamesplay.com/> |
jaime barrachina
Member #6,780
January 2006
![]() |
Hummm sorry for being so thick, but i cant get the thing to work, for this code:
I get the folowing errors: Compilador: Default compiler g++.exe -c Main3.cpp -o Main3.o -I"C:/Program Files/devcpp/include/c++" -I"C:/Program Files/devcpp/include/c++/mingw32" -I"C:/Program Files/devcpp/include/c++/backward" -I"C:/Program Files/devcpp/include" -lalleg In file included from Main3.cpp:1: Encabezado.h:400: parse error before `for' make.exe: *** [Main3.o] Error 1 Ejecución Terminada I'm just running around in the dark, bumping off walls, so if you can tell me what's wrong, or give a more specific example, I'll make you a statue... Cheers and hope someone can help! "Under the sword lifted high There is hell making you tremble: But go ahead, And you have the land of bliss. - Miyamoto Musahshi" |
BAF
Member #2,981
December 2002
![]() |
Most of those errors are self explanitory - redeclarations and such. As far as the line 398 error, add (DIALOG *) before the malloc(). |
Wetimer
Member #1,622
November 2001
|
Have you not used malloc before? Do you normally use c++? If so, you can use new instead. <code>if(Windows.State = Crash) Computer.halt();</code> |
jaime barrachina
Member #6,780
January 2006
![]() |
Well, I've started learning how to program 2 months ago and I chose C++ as my language, Allegro as my library and making a 2D game as my project. Having no experience whith programing at all (except html, but that doesn't count), It's not too easy. So yes, my answer is that I haven't used malloc before xD Winston Ewert said: ... If so, you can use new instead. New? Please tell me what you mean. Right now I have the folowing code:
And I get a "parse error before "{" token" in the error line. Can anyone tell me why, and also, if the "BITMAP* Dibu... " line would work. Cheers and txs!! "Under the sword lifted high There is hell making you tremble: But go ahead, And you have the land of bliss. - Miyamoto Musahshi" |
miran
Member #2,407
June 2002
|
Quote: New? Please tell me what you mean. Instead of DIALOG* list_of_icons = (DIALOG *) malloc(sizeof(DIALOG) * 257); you can do DIALOG* list_of_icons = new DIALOG[257]; Quote: And I get a "parse error before "{" token" in the error line. First of all, you should create the DIALOG array inside a function. Declare it globally if you want, but allocate memory inside a function. Like this: I didn't know your code even compiles. list_of_icons[256].x = x1; list_of_icons[256].y = y1; and so on. Quote: Can anyone tell me why, and also, if the "BITMAP* Dibu... " line would work. It's valid syntax but the code doesn't do anything. Quote: Cheers and txs!!
Texas? -- |
Johan Halmén
Member #1,550
September 2001
|
Quote: I'm just running around in the dark, bumping off walls Congratulations, you've made your first Pong. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest. |
jaime barrachina
Member #6,780
January 2006
![]() |
Well, anyhow, I've come up with the folowing piece of code (or rather almost copied it from this forum...):
Almost there... but It doesn't let me call it! I promise to keep quiet a good while afther this, but please, please (*begs on his knees) someone tell me what's wrong, and, more importantly, how to fix it (or is that less important in fact...?). "Under the sword lifted high There is hell making you tremble: But go ahead, And you have the land of bliss. - Miyamoto Musahshi" |
Johan Halmén
Member #1,550
September 2001
|
You've changed it. I'm not sure if it helps if anyone writes this stuff for you. miran wrote a bad example, which you didn't understand. You should get a hang of the basics of Allegro's gui first. Anyway, this would be heading in the correct direction:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest. |
GullRaDriel
Member #3,861
September 2003
![]() |
OK I must put my tip here : Any allegro dialog should end by a NULL line who mean... end of dialog. But correct me if i'm wrong. "Code is like shit - it only smells if it is not yours" |
Tobias Dammers
Member #2,604
August 2002
![]() |
More specifically, the proc member of the struct must be NULL. --- |
jaime barrachina
Member #6,780
January 2006
![]() |
Well, this is about it, thanks everyone for their awesome help, I really don't know if I could make anything work without the splendid people from Allegro c.c. In the end the code looks like this:
And though I'm having problems with my do_dialog(list_of_icons,-1) (It just doesn't show the dialog O.O ) I think the icons function should work fine now. Thank you again everyone!! The map editor is almost done [EDIT] Yust to say everything works OK now. Thanks again everyone! "Under the sword lifted high There is hell making you tremble: But go ahead, And you have the land of bliss. - Miyamoto Musahshi" |
|