Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // gcc -Wall 4.c -o 4 $(pkg-config --libs allegro-5.0 allegro_image-5.0 allegro_primitives-5.0)
- #define ALLEGRO_STATICLINK
- #include <allegro5/allegro.h>
- #include <allegro5/allegro_primitives.h>
- int main() {
- ALLEGRO_DISPLAY *display;
- ALLEGRO_EVENT_QUEUE *event_queue = NULL;
- if(!al_init()) {
- return -1;
- }
- int win_x = 400;
- int win_y = 400;
- display = al_create_display(win_x, win_y);
- if(!display) {
- return -1;
- }
- al_init_primitives_addon();
- al_install_mouse();
- event_queue = al_create_event_queue();
- al_register_event_source(event_queue, al_get_mouse_event_source());
- al_register_event_source(event_queue, al_get_display_event_source(display));
- bool user_exit = false;
- while(!user_exit) {
- ALLEGRO_EVENT ev;
- al_wait_for_event(event_queue, &ev);
- // to close the program with 'x' button of window, need to initialize al_register_event_source
- if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
- user_exit = true;
- }
- int pos_x;
- int pos_y;
- bool draw = true;
- if(ev.type == ALLEGRO_EVENT_MOUSE_AXES) {
- pos_x = ev.mouse.x;
- pos_y = ev.mouse.y;
- } else if(ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) {
- if(ev.mouse.button) {
- draw = !draw;
- }
- }
- if(draw) {
- al_hide_mouse_cursor(display);
- al_draw_filled_circle(pos_x, pos_y, 10, al_map_rgb(0, 255,0));
- } else {
- al_show_mouse_cursor(display);
- }
- al_flip_display();
- al_clear_to_color(al_map_rgb(24, 24, 24));
- }
- al_destroy_event_queue(event_queue);
- al_uninstall_keyboard();
- al_destroy_display(display);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement