Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » GUI Sliders headache

Credits go to Dennis for helping out!
This thread is locked; no one can reply to it. rss feed Print
GUI Sliders headache
jaime barrachina
Member #6,780
January 2006
avatar

Hello people, I was wondering if you could lend a minute or two to help me out a tight spot (as usual). The problem is as follows, I'm trying to make 2 sliders for my map editor, to move the map and so on. The problem is that it doesn't change the value of any variable, even changing i2 and j2 it should move already. As far as I know it doesn't even use the functions, could anyone tell me why?
Here's the code:

1 
2DIALOG the_dialog[] =
3{
4 /* (dialog proc) (x) (y) (w) (h) (fg)(bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5 { d_box_proc, 0, 0, 1024, 15, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6 { d_box_proc, 0, 728, 1024, 40, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
7 { d_box_proc, 774, 15, 250, 713, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
8 { d_box_proc, 757, 711, 17, 17, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
9 { d_slider_proc, 758, 15, 16, 696, 0, 0, 0, 0, GRID_HEIGHT * WORLD_HEIGHT, GRID_HEIGHT * WORLD_HEIGHT, NULL, (void *)moverse_slider_y, NULL },
10 { d_slider_proc, 0, 712, 757, 16, 0, 0, 0, 0, GRID_WIDTH * WORLD_WIDTH, 0, NULL, (void *)moverse_slider_x, NULL },
11 { d_menu_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, the_menu, NULL, NULL },
12 { d_menu_proc, 774, 15, 0, 0, 0, 0, 0, 0, 0, 0, menu_herramientas, NULL, NULL },
13 { d_yield_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
14 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
15};
16 
17 
18 
19int moverse_slider_x(void *dp3, int d2)
20 {
21
22 i2 = the_dialog[5].d2 - (k2 * 32);
23
24 if(i2 <= 0) {
25 k2--;
26 i2 = the_dialog[5].d2 - (k2 * 32);
27 }
28 else if(i2 >= GRID_WIDTH)
29 {
30 k2++;
31 i2 = the_dialog[5].d2 - (k2 * 32);
32 }
33 return 0;
34 }
35
36int moverse_slider_y(void *dp3, int d2)
37 {
38 j2 = ((WORLD_HEIGHT - l2) * 24) - the_dialog[4].d2;
39 if(j2 <= 0)
40 {
41 l2--;
42 j2 = ((WORLD_HEIGHT - l2) * 24) - the_dialog[4].d2;
43 }
44 else if(j2 >= GRID_HEIGHT)
45 {
46 l2++;
47 j2 = ((WORLD_HEIGHT - l2) * 24) - the_dialog[4].d2;
48 }
49 return 0;
50
51 }

"Under the sword lifted high There is hell making you tremble: But go ahead, And you have the land of bliss. - Miyamoto Musahshi"
"When all else fails, read the manual - Dad"

Dennis
Member #1,090
July 2003
avatar

Quote:

Function Pointers
"Once you've got the pointer, you can assign the address of the right sort of function just by using its name: like an array, a function name is turned into an address when it's used in an expression."

In other words: The "(void*)" piece is wrong, just writing the function name into dp2 should correct the problem that it isn't called.

Why is that?
Since the function name is already an address, dereferencing that address does not result in a pointer(which IS an address)...and dereferencing to 'void' doesn't seem to make any sense at all.

jaime barrachina
Member #6,780
January 2006
avatar

But if I take the (void*) away, it gives the folowing error:

Invalid conversion from `int (*)(void*, int)' to `void*'

Any idea why that is? Txs a bunch for the help. (_ _)

Edit: Hummm oks now it works, but it does funny things xD like not showing the rest of the interface while using the slidebars xD Well, at least it wors, txs for the help.

"Under the sword lifted high There is hell making you tremble: But go ahead, And you have the land of bliss. - Miyamoto Musahshi"
"When all else fails, read the manual - Dad"

Go to: