in Education by
I am working on a game in allegro 5 in which I want to create rectangular objects dynamically on screen and make them clickable with mouse buttons al_register_event_source( event_queue, al_get_timer_event_source(timer)); al_register_event_source( event_queue, al_get_mouse_event_source()); al_clear_to_color(al_map_rgb(0, 0, 0)); al_flip_display(); al_start_timer(timer); while ( !exit ) { ALLEGRO_EVENT ev; al_wait_for_event( event_queue, &ev); if (ev.type == ALLEGRO_EVENT_TIMER) ; else if ( ev.type == ALLEGRO_EVENT_MOUSE_AXES ) { x = ev.mouse.x; y = ev.mouse.y; } else if ( ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN ) { if ( x >= rect.x && x <= rect.maxx && y >= rect.y && y <= rect.maxy ) destory ( rect ); } else if ( ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE ) break; if ( redraw && al_event_queue_is_empty(event_queue)){ redraw = false; al_draw_rectangle ( rect.x, rect.y, rect.maxx, rect.maxy, blue, 1 ); al_flip_display(); al_clear_to_color(al_map_rgb(0, 0, 0)); } } But this is hardcoded for only one rectangle. How can I make an event for this which can handle rectangles like button. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
User events aren't needed to respond to button presses. Rather, you should approach this from a different angle. Pass the ALLEGRO_EVENT to your button class and have it return whether it was clicked or not. bool Button::ButtonPressed(ALLEGRO_EVENT ev) { if (ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN && ev.mouse.button == 1) { if (our_area.Contains(ev.mouse.x , ev.mouse.y)) {return true;} } return false; } BUT, you asked how to create user events in Allegro 5 so I will answer that as well. See https://liballeg.org/a5docs/trunk/events.html#allegro_user_event for details and a code example. Basically, you create and initialize an ALLEGRO_EVENT_SOURCE, register it with your event queue, and then listen for messages you emit with al_emit_user_event.

Related questions

0 votes
    I am a complete beginner in allegro and i just installed allegro correctly and this is my code(my first ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 22, 2022 in Education by JackTerrance
0 votes
    The current user defined objects like lists, vectors, etc. is referred to as __________ in the R language. ( ... of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    #include struct A { bool f( int a ) { std::cout...
asked Feb 21, 2022 in Education by JackTerrance
0 votes
    A die is thrown three times. Events A and B are defined as below:A : 4 on the third throwB : 6 on the ... that B has already occurred. Select the correct answer from above options...
asked Nov 13, 2021 in Education by JackTerrance
0 votes
    I see many user interface control libraries for .NET, but where can I get similar stuff for win32 using ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
0 votes
    According to my understanding of QDateEdit's API documentation it creates a widget for editing dates. The ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 22, 2022 in Education by JackTerrance
0 votes
    According to my understanding of QDateEdit's API documentation it creates a widget for editing dates. The ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 11, 2022 in Education by JackTerrance
0 votes
    According to my understanding of QDateEdit's API documentation it creates a widget for editing dates. The ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    How do you create log linear models in R language? (a) loglm() (b) logmn() (c) logfn() (d) ... and Debugging of R Programming Select the correct answer from above options...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    I have created a set of multi-platform C++ components to load and manage various types of digitally signed ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    What will be the output of log (-5.8) when executed on R console? (a) NAN (b) NA (c) Error ... Functions and Debugging of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    _____________ will produce a sequential vector c( (1,2,3,4,5,6,7,8,9)). (a) Seq(9) (b) Seq ... Functions and Debugging of R Programming Select the correct answer from above options...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    Which function is used to create a histogram for visualisation in R programming language? (a) Library (b) Hist ... of R Programming Select the correct answer from above options...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    Which of the following code create a n item vector of random normal deviates? (a) x1...
asked Feb 12, 2022 in Education by JackTerrance
...