Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Unresponsive dialogs

This thread is locked; no one can reply to it. rss feed Print
Unresponsive dialogs
Raf Vermeulen
Member #7,166
April 2006

I've been trying to figure out what's wrong with these... I did the exact same thing as in the code of another project of mine, where it works like a charm, but here, it doesn't.

I got a text-field and a button in a dialog. The problem with them, is that they're both static. You can't put a cursor in the text-field, let alone edit the text in it, and the button simply doesn't respond at all either. Doesn't do anything when you click it or so.

This's the code:

1void compare_score() {
2 char name[100] = "Player";
3 int end_score;
4 int end_lvl;
5 long pos;
6 bool done = false;
7 int count = 1;
8 FILE * file;
9 file = fopen("High.txt","r+");
10 if (file == NULL) create_file();
11 file = fopen("High.txt","r+");
12 
13 while (!feof(file) && done == false) {
14 pos = ftell(file);
15 fscanf(file, "%s", name);
16 fscanf(file, "%d", &end_score);
17 fscanf(file, "%d", &end_lvl);
18 if (score > end_score) done = true;
19 count++;
20 }
21 if (done == true) {
22 cout << "DONE\n";
23 
24// Naam dialoog ding...
25 DIALOG the_dialog[] = {
26 { d_agup_edit_proc, 15, 75, 125, 8, 0, 0, 0, 0, 100, 0, name, NULL, name },
27 { d_agup_push_proc, 90, 115, 100, 18, 0, 0, 0, 0, 0, 0, (void*)"Done", 0, (void*)edit_high },
28 /* the next two elements don't draw anything */
29 { d_yield_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
30 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
31 };
32 
33 /* Dialog box colour */
34 gui_fg_color = agup_fg_color;
35 gui_bg_color = agup_bg_color;
36 gui_mg_color = agup_mg_color;
37 gui_shadow_box_proc = d_agup_shadow_box_proc;
38 gui_button_proc = d_agup_button_proc;
39 gui_ctext_proc = d_agup_ctext_proc;
40 gui_text_list_proc = d_agup_text_list_proc;
41 /* End of dialog box colour */
42 
43 
44 
45/* set up colors */
46 gui_fg_color = makecol(0, 0, 0);
47 gui_mg_color = makecol(128, 128, 128);
48 gui_bg_color = makecol(200, 240, 200);
49 set_dialog_color (the_dialog, gui_fg_color, gui_bg_color);
50 
51/* white color for d_clear_proc and the d_?text_procs */
52 the_dialog[0].bg = makecol(255, 255, 255);
53 for (int i = 4; the_dialog<i>.proc; i++)
54 if (the_dialog<i>.proc == d_text_proc ||
55 the_dialog<i>.proc == d_ctext_proc ||
56 the_dialog<i>.proc == d_rtext_proc)
57 the_dialog<i>.bg = the_dialog[0].bg;
58
59 position_dialog (the_dialog, 2, 2);
60 do_dialog(the_dialog, -1);
61 }
62 fclose(file);
63}
64 
65 
66 
67void edit_high(long pos, char name[100], int count) {
68 int end_score;
69 int end_lvl;
70 
71 
72 FILE * file;
73 file = fopen("High.txt","r+");
74 
75
76 
77 fseek(file, pos, SEEK_SET);
78 fprintf(file, "NEW\n");
79 fprintf(file,"%d\n", score);
80 fprintf(file,"%d\n", lvl_nr+1);
81 if (count < 10) {
82 fprintf(file, "%s\n", name);
83 fprintf(file,"%d\n", end_score);
84 fprintf(file,"%d\n", end_lvl);
85 }
86 
87 
88 for (int i = (count+1); i <= 10; i++) {
89 cout << "I: " << i << "\n";
90 cout << "Count: " << count << "\n";
91 pos = ftell(file);
92 fseek(file, pos-1, SEEK_SET);
93 cout << "POS before: " << pos << "\n";
94 fscanf(file, "%s", name);
95 fscanf(file, "%d", &end_score);
96 fscanf(file, "%d", &end_lvl);
97 fseek(file, pos, SEEK_SET);
98 fprintf(file, "%s\n", name);
99 fprintf(file,"%d\n", end_score);
100 fprintf(file,"%d\n", end_lvl);
101 cout << "POS after: " << pos << "\n";
102 }
103 fclose(file);
104}

Dustin Dettmer
Member #3,935
October 2003
avatar

Start with a simple version that works and slowly add features, testing periodically.

Raf Vermeulen
Member #7,166
April 2006

I've done that a few times. I'm now reconstructing the code to a new file, independant of the project, and'm seeing if it works there or not.

Finished that. This is the result (based on the example code for GUIs, and parts of my initialization code of the project):

1#include <stdio.h>
2#include <iostream>
3#include <allegro.h>
4using namespace std;
5 
6extern "C" {
7 #include "agup.h"
8}
9 
10void dialog() {
11#define MAX_BYTES_PER_CHAR 6
12#define LEN 32
13char the_string[(LEN + 1) * MAX_BYTES_PER_CHAR] = "Change Me!";
14 
15/* here it comes - the big bad ugly DIALOG array for our main dialog */
16DIALOG the_dialog[] =
17{
18 /* (dialog proc) (x) (y) (w) (h) (fg)(bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
19
20 /* this element just clears the screen, therefore it should come before the others */
21 { d_clear_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
22
23 /* some more GUI elements, all of which require you to specify their dimensions */
24 { d_edit_proc, 160, 130, 160, 8, 0, 0, 0, 0, LEN, 0, the_string, NULL, NULL },
25
26 /* the next two elements don't draw anything */
27 { d_yield_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
28 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
29};
30 
31 
32 
33 
34 
35 
36 /* Dialog box colour */
37 gui_fg_color = agup_fg_color;
38 gui_bg_color = agup_bg_color;
39 gui_mg_color = agup_mg_color;
40 gui_shadow_box_proc = d_agup_shadow_box_proc;
41 gui_button_proc = d_agup_button_proc;
42 gui_ctext_proc = d_agup_ctext_proc;
43 gui_text_list_proc = d_agup_text_list_proc;
44 /* End of dialog box colour */
45 
46 
47 
48/* set up colors */
49 gui_fg_color = makecol(0, 0, 0);
50 gui_mg_color = makecol(128, 128, 128);
51 gui_bg_color = makecol(200, 240, 200);
52 set_dialog_color (the_dialog, gui_fg_color, gui_bg_color);
53 
54/* white color for d_clear_proc and the d_?text_procs */
55 the_dialog[0].bg = makecol(255, 255, 255);
56 for (int i = 4; the_dialog<i>.proc; i++)
57 if (the_dialog<i>.proc == d_text_proc ||
58 the_dialog<i>.proc == d_ctext_proc ||
59 the_dialog<i>.proc == d_rtext_proc)
60 the_dialog<i>.bg = the_dialog[0].bg;
61
62 position_dialog (the_dialog, 2, 2);
63 do_dialog(the_dialog, -1);
64}
65 
66 
67 
68int main(int argc, char *argv[])
69{
70 
71 allegro_init();
72 install_keyboard();
73 
74 LOCK_VARIABLE(counter);
75 LOCK_FUNCTION(timer_handler);
76 
77 /* Install handler when user presses X at the topright corner */
78 LOCK_VARIABLE(exit_application);
79 LOCK_FUNCTION(exit_button);
80 
81 set_color_depth(16);
82 if(set_gfx_mode( GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0)) exit(1);
83
84 agup_init(agtk_theme);
85 
86 dialog();
87
88 return 0;
89}
90END_OF_MAIN()

It has the same problem, so I think something's wrong with the initialization somewhere.

I just changed the initialization to the initialization from that old project I used as reference, the one in which things worked. The test works fine now. Time to go through each initialization part step by step.

WOOHOOHOOW! Found it;D I had to initiaze the mouse too, using install_mouse(); Problem solved;D

Go to: