Changeset 541 for libcaca/trunk/caca
- Timestamp:
- Mar 7, 2006, 11:37:59 AM (15 years ago)
- Location:
- libcaca/trunk/caca
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/caca/caca.c
r540 r541 83 83 kk->timer.last_usec = 0; 84 84 kk->lastticks = 0; 85 86 kk->mouse_x = kk->qq->width / 2; 87 kk->mouse_y = kk->qq->height / 2; 85 88 86 89 kk->resize = 0; -
libcaca/trunk/caca/caca_internals.h
r540 r541 46 46 #endif 47 47 48 #if !defined(_DOXYGEN_SKIP_ME) 49 # define EVENTBUF_LEN 10 50 #endif 51 48 52 /* Graphics driver */ 49 53 enum caca_driver … … 114 118 } driver; 115 119 116 unsigned int width, height; 120 //unsigned int width, height; 121 unsigned int mouse_x, mouse_y; 117 122 118 123 int resize; … … 125 130 struct events 126 131 { 132 #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) 133 unsigned int buf[EVENTBUF_LEN]; 134 int queue; 135 #endif 127 136 #if defined(USE_SLANG) || defined(USE_NCURSES) 128 137 struct caca_timer key_timer; -
libcaca/trunk/caca/event.c
r540 r541 56 56 #include "caca_internals.h" 57 57 58 static unsigned int _get_next_event(caca_t * kk);59 static unsigned int _lowlevel_event(caca_t * kk);58 static unsigned int _get_next_event(caca_t *); 59 static unsigned int _lowlevel_event(caca_t *); 60 60 #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) 61 static void _push_event(unsigned int); 62 static unsigned int _pop_event(void); 63 #endif 64 65 #if !defined(_DOXYGEN_SKIP_ME) 66 #define EVENTBUF_LEN 10 67 #endif 68 #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) 69 static unsigned int eventbuf[EVENTBUF_LEN]; 70 static int events = 0; 71 #endif 72 73 static unsigned int mouse_x = 0, mouse_y = 0; 61 static void _push_event(caca_t *, unsigned int); 62 static unsigned int _pop_event(caca_t *); 63 #endif 74 64 75 65 #if !defined(_DOXYGEN_SKIP_ME) … … 145 135 unsigned int caca_get_mouse_x(caca_t *kk) 146 136 { 147 if( mouse_x >= kk->qq->width)148 mouse_x = kk->qq->width - 1;149 150 return mouse_x;137 if(kk->mouse_x >= kk->qq->width) 138 kk->mouse_x = kk->qq->width - 1; 139 140 return kk->mouse_x; 151 141 } 152 142 … … 162 152 unsigned int caca_get_mouse_y(caca_t *kk) 163 153 { 164 if( mouse_y >= kk->qq->height)165 mouse_y = kk->qq->height - 1;166 167 return mouse_y;154 if(kk->mouse_y >= kk->qq->height) 155 kk->mouse_y = kk->qq->height - 1; 156 157 return kk->mouse_y; 168 158 } 169 159 … … 201 191 && kk->events.autorepeat_ticks > AUTOREPEAT_RATE) 202 192 { 203 _push_event( event);193 _push_event(kk, event); 204 194 kk->events.autorepeat_ticks -= AUTOREPEAT_RATE; 205 195 return CACA_EVENT_KEY_PRESS | kk->events.last_key; … … 220 210 || (event & CACA_EVENT_KEY_PRESS))) 221 211 { 222 _push_event( event);212 _push_event(kk, event); 223 213 event = CACA_EVENT_KEY_RELEASE | kk->events.last_key; 224 214 kk->events.last_key = 0; … … 243 233 244 234 #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) 245 event = _pop_event( );235 event = _pop_event(kk); 246 236 247 237 if(event) … … 307 297 newy = kk->qq->height - 1; 308 298 309 if( mouse_x == newx &&mouse_y == newy)299 if(kk->mouse_x == newx && kk->mouse_y == newy) 310 300 continue; 311 301 312 mouse_x = newx;313 mouse_y = newy;314 315 return CACA_EVENT_MOUSE_MOTION | ( mouse_x << 12) |mouse_y;302 kk->mouse_x = newx; 303 kk->mouse_y = newy; 304 305 return CACA_EVENT_MOUSE_MOTION | (kk->mouse_x << 12) | kk->mouse_y; 316 306 } 317 307 … … 395 385 { 396 386 case BUTTON1_PRESSED: 397 _push_event( CACA_EVENT_MOUSE_PRESS | 1);387 _push_event(kk, CACA_EVENT_MOUSE_PRESS | 1); 398 388 break; 399 389 case BUTTON1_RELEASED: 400 _push_event( CACA_EVENT_MOUSE_RELEASE | 1);390 _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 1); 401 391 break; 402 392 case BUTTON1_CLICKED: 403 _push_event( CACA_EVENT_MOUSE_PRESS | 1);404 _push_event( CACA_EVENT_MOUSE_RELEASE | 1);393 _push_event(kk, CACA_EVENT_MOUSE_PRESS | 1); 394 _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 1); 405 395 break; 406 396 case BUTTON1_DOUBLE_CLICKED: 407 _push_event( CACA_EVENT_MOUSE_PRESS | 1);408 _push_event( CACA_EVENT_MOUSE_RELEASE | 1);409 _push_event( CACA_EVENT_MOUSE_PRESS | 1);410 _push_event( CACA_EVENT_MOUSE_RELEASE | 1);397 _push_event(kk, CACA_EVENT_MOUSE_PRESS | 1); 398 _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 1); 399 _push_event(kk, CACA_EVENT_MOUSE_PRESS | 1); 400 _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 1); 411 401 break; 412 402 case BUTTON1_TRIPLE_CLICKED: 413 _push_event( CACA_EVENT_MOUSE_PRESS | 1);414 _push_event( CACA_EVENT_MOUSE_RELEASE | 1);415 _push_event( CACA_EVENT_MOUSE_PRESS | 1);416 _push_event( CACA_EVENT_MOUSE_RELEASE | 1);417 _push_event( CACA_EVENT_MOUSE_PRESS | 1);418 _push_event( CACA_EVENT_MOUSE_RELEASE | 1);403 _push_event(kk, CACA_EVENT_MOUSE_PRESS | 1); 404 _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 1); 405 _push_event(kk, CACA_EVENT_MOUSE_PRESS | 1); 406 _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 1); 407 _push_event(kk, CACA_EVENT_MOUSE_PRESS | 1); 408 _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 1); 419 409 break; 420 410 case BUTTON1_RESERVED_EVENT: … … 422 412 423 413 case BUTTON2_PRESSED: 424 _push_event( CACA_EVENT_MOUSE_PRESS | 2);414 _push_event(kk, CACA_EVENT_MOUSE_PRESS | 2); 425 415 break; 426 416 case BUTTON2_RELEASED: 427 _push_event( CACA_EVENT_MOUSE_RELEASE | 2);417 _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 2); 428 418 break; 429 419 case BUTTON2_CLICKED: 430 _push_event( CACA_EVENT_MOUSE_PRESS | 2);431 _push_event( CACA_EVENT_MOUSE_RELEASE | 2);420 _push_event(kk, CACA_EVENT_MOUSE_PRESS | 2); 421 _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 2); 432 422 break; 433 423 case BUTTON2_DOUBLE_CLICKED: 434 _push_event( CACA_EVENT_MOUSE_PRESS | 2);435 _push_event( CACA_EVENT_MOUSE_RELEASE | 2);436 _push_event( CACA_EVENT_MOUSE_PRESS | 2);437 _push_event( CACA_EVENT_MOUSE_RELEASE | 2);424 _push_event(kk, CACA_EVENT_MOUSE_PRESS | 2); 425 _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 2); 426 _push_event(kk, CACA_EVENT_MOUSE_PRESS | 2); 427 _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 2); 438 428 break; 439 429 case BUTTON2_TRIPLE_CLICKED: 440 _push_event( CACA_EVENT_MOUSE_PRESS | 2);441 _push_event( CACA_EVENT_MOUSE_RELEASE | 2);442 _push_event( CACA_EVENT_MOUSE_PRESS | 2);443 _push_event( CACA_EVENT_MOUSE_RELEASE | 2);444 _push_event( CACA_EVENT_MOUSE_PRESS | 2);445 _push_event( CACA_EVENT_MOUSE_RELEASE | 2);430 _push_event(kk, CACA_EVENT_MOUSE_PRESS | 2); 431 _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 2); 432 _push_event(kk, CACA_EVENT_MOUSE_PRESS | 2); 433 _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 2); 434 _push_event(kk, CACA_EVENT_MOUSE_PRESS | 2); 435 _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 2); 446 436 break; 447 437 case BUTTON2_RESERVED_EVENT: … … 449 439 450 440 case BUTTON3_PRESSED: 451 _push_event( CACA_EVENT_MOUSE_PRESS | 3);441 _push_event(kk, CACA_EVENT_MOUSE_PRESS | 3); 452 442 break; 453 443 case BUTTON3_RELEASED: 454 _push_event( CACA_EVENT_MOUSE_RELEASE | 3);444 _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 3); 455 445 break; 456 446 case BUTTON3_CLICKED: 457 _push_event( CACA_EVENT_MOUSE_PRESS | 3);458 _push_event( CACA_EVENT_MOUSE_RELEASE | 3);447 _push_event(kk, CACA_EVENT_MOUSE_PRESS | 3); 448 _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 3); 459 449 break; 460 450 case BUTTON3_DOUBLE_CLICKED: 461 _push_event( CACA_EVENT_MOUSE_PRESS | 3);462 _push_event( CACA_EVENT_MOUSE_RELEASE | 3);463 _push_event( CACA_EVENT_MOUSE_PRESS | 3);464 _push_event( CACA_EVENT_MOUSE_RELEASE | 3);451 _push_event(kk, CACA_EVENT_MOUSE_PRESS | 3); 452 _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 3); 453 _push_event(kk, CACA_EVENT_MOUSE_PRESS | 3); 454 _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 3); 465 455 break; 466 456 case BUTTON3_TRIPLE_CLICKED: 467 _push_event( CACA_EVENT_MOUSE_PRESS | 3);468 _push_event( CACA_EVENT_MOUSE_RELEASE | 3);469 _push_event( CACA_EVENT_MOUSE_PRESS | 3);470 _push_event( CACA_EVENT_MOUSE_RELEASE | 3);471 _push_event( CACA_EVENT_MOUSE_PRESS | 3);472 _push_event( CACA_EVENT_MOUSE_RELEASE | 3);457 _push_event(kk, CACA_EVENT_MOUSE_PRESS | 3); 458 _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 3); 459 _push_event(kk, CACA_EVENT_MOUSE_PRESS | 3); 460 _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 3); 461 _push_event(kk, CACA_EVENT_MOUSE_PRESS | 3); 462 _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 3); 473 463 break; 474 464 case BUTTON3_RESERVED_EVENT: … … 476 466 477 467 case BUTTON4_PRESSED: 478 _push_event( CACA_EVENT_MOUSE_PRESS | 4);468 _push_event(kk, CACA_EVENT_MOUSE_PRESS | 4); 479 469 break; 480 470 case BUTTON4_RELEASED: 481 _push_event( CACA_EVENT_MOUSE_RELEASE | 4);471 _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 4); 482 472 break; 483 473 case BUTTON4_CLICKED: 484 _push_event( CACA_EVENT_MOUSE_PRESS | 4);485 _push_event( CACA_EVENT_MOUSE_RELEASE | 4);474 _push_event(kk, CACA_EVENT_MOUSE_PRESS | 4); 475 _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 4); 486 476 break; 487 477 case BUTTON4_DOUBLE_CLICKED: 488 _push_event( CACA_EVENT_MOUSE_PRESS | 4);489 _push_event( CACA_EVENT_MOUSE_RELEASE | 4);490 _push_event( CACA_EVENT_MOUSE_PRESS | 4);491 _push_event( CACA_EVENT_MOUSE_RELEASE | 4);478 _push_event(kk, CACA_EVENT_MOUSE_PRESS | 4); 479 _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 4); 480 _push_event(kk, CACA_EVENT_MOUSE_PRESS | 4); 481 _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 4); 492 482 break; 493 483 case BUTTON4_TRIPLE_CLICKED: 494 _push_event( CACA_EVENT_MOUSE_PRESS | 4);495 _push_event( CACA_EVENT_MOUSE_RELEASE | 4);496 _push_event( CACA_EVENT_MOUSE_PRESS | 4);497 _push_event( CACA_EVENT_MOUSE_RELEASE | 4);498 _push_event( CACA_EVENT_MOUSE_PRESS | 4);499 _push_event( CACA_EVENT_MOUSE_RELEASE | 4);484 _push_event(kk, CACA_EVENT_MOUSE_PRESS | 4); 485 _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 4); 486 _push_event(kk, CACA_EVENT_MOUSE_PRESS | 4); 487 _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 4); 488 _push_event(kk, CACA_EVENT_MOUSE_PRESS | 4); 489 _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 4); 500 490 break; 501 491 case BUTTON4_RESERVED_EVENT: … … 506 496 } 507 497 508 if( mouse_x == (unsigned int)mevent.x &&509 mouse_y == (unsigned int)mevent.y)510 return _pop_event( );511 512 mouse_x = mevent.x;513 mouse_y = mevent.y;514 515 return CACA_EVENT_MOUSE_MOTION | ( mouse_x << 12) |mouse_y;498 if(kk->mouse_x == (unsigned int)mevent.x && 499 kk->mouse_y == (unsigned int)mevent.y) 500 return _pop_event(kk); 501 502 kk->mouse_x = mevent.x; 503 kk->mouse_y = mevent.y; 504 505 return CACA_EVENT_MOUSE_MOTION | (kk->mouse_x << 12) | kk->mouse_y; 516 506 } 517 507 … … 587 577 unsigned int x = SLang_getkey() - '!'; 588 578 unsigned int y = SLang_getkey() - '!'; 589 _push_event( CACA_EVENT_MOUSE_PRESS | button);590 _push_event( CACA_EVENT_MOUSE_RELEASE | button);591 592 if( mouse_x == x &&mouse_y == y)593 return _pop_event( );594 595 mouse_x = x;596 mouse_y = y;597 598 return CACA_EVENT_MOUSE_MOTION | ( mouse_x << 12) |mouse_y;579 _push_event(kk, CACA_EVENT_MOUSE_PRESS | button); 580 _push_event(kk, CACA_EVENT_MOUSE_RELEASE | button); 581 582 if(kk->mouse_x == x && kk->mouse_y == y) 583 return _pop_event(kk); 584 585 kk->mouse_x = x; 586 kk->mouse_y = y; 587 588 return CACA_EVENT_MOUSE_MOTION | (kk->mouse_x << 12) | kk->mouse_y; 599 589 } 600 590 … … 640 630 641 631 event = getch(); 642 _push_event( CACA_EVENT_KEY_RELEASE | event);632 _push_event(kk, CACA_EVENT_KEY_RELEASE | event); 643 633 return CACA_EVENT_KEY_PRESS | event; 644 634 } … … 683 673 COORD pos = rec.Event.MouseEvent.dwMousePosition; 684 674 685 if( mouse_x == (unsigned int)pos.X &&686 mouse_y == (unsigned int)pos.Y)675 if(kk->mouse_x == (unsigned int)pos.X && 676 kk->mouse_y == (unsigned int)pos.Y) 687 677 continue; 688 678 689 mouse_x = pos.X;690 mouse_y = pos.Y;691 692 return CACA_EVENT_MOUSE_MOTION | ( mouse_x << 12) |mouse_y;679 kk->mouse_x = pos.X; 680 kk->mouse_y = pos.Y; 681 682 return CACA_EVENT_MOUSE_MOTION | (kk->mouse_x << 12) | kk->mouse_y; 693 683 } 694 684 #if 0 … … 738 728 kk->gl.mouse_clicked=0; 739 729 } 740 mouse_x = kk->gl.mouse_x;741 mouse_y = kk->gl.mouse_y;742 event |= CACA_EVENT_MOUSE_MOTION | ( mouse_x << 12) |mouse_y;730 kk->mouse_x = kk->gl.mouse_x; 731 kk->mouse_y = kk->gl.mouse_y; 732 event |= CACA_EVENT_MOUSE_MOTION | (kk->mouse_x << 12) | kk->mouse_y; 743 733 kk->gl.mouse_changed = 0; 744 734 } … … 789 779 790 780 #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) 791 static void _push_event( unsigned int event)781 static void _push_event(caca_t *kk, unsigned int event) 792 782 { 793 if(!event || events== EVENTBUF_LEN)783 if(!event || kk->events.queue == EVENTBUF_LEN) 794 784 return; 795 eventbuf[events] = event;796 events++;785 kk->events.buf[kk->events.queue] = event; 786 kk->events.queue++; 797 787 } 798 788 799 static unsigned int _pop_event( void)789 static unsigned int _pop_event(caca_t *kk) 800 790 { 801 791 int i; 802 792 unsigned int event; 803 793 804 if( events== 0)794 if(kk->events.queue == 0) 805 795 return CACA_EVENT_NONE; 806 796 807 event = eventbuf[0];808 for(i = 1; i < events; i++)809 eventbuf[i - 1] = eventbuf[i];810 events--;797 event = kk->events.buf[0]; 798 for(i = 1; i < kk->events.queue; i++) 799 kk->events.buf[i - 1] = kk->events.buf[i]; 800 kk->events.queue--; 811 801 812 802 return event;
Note: See TracChangeset
for help on using the changeset viewer.