Ignore:
Timestamp:
Mar 6, 2006, 9:32:40 AM (14 years ago)
Author:
Sam Hocevar
Message:
  • All output plugins should now work again.
  • Renamed caca_refresh() into caca_display() which makes more sense.
  • Optimised gl_bgpal by directly storing floats instead of doing the conversion at runtime.
  • Handle resizing in cucul_set_size() and try to keep as much information as possible from the previous canvas.
  • Moved most global variables into cucul_t or caca_t contexts.
  • Moved time.c into libcaca.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/src/event.c

    r524 r527  
    11/*
    22 *  libcaca       ASCII-Art library
    3  *  Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org>
     3 *  Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
    44 *                All Rights Reserved
    55 *
     
    5555#include <GL/glut.h>
    5656#include <GL/freeglut_ext.h>
    57 extern int gl_special_key;
    58 extern unsigned char gl_key;
    59 extern unsigned char gl_resized;
    60 extern float gl_font_width;
    61 extern float gl_font_height;
    62 extern int gl_new_width;
    63 extern int gl_new_height;
    64 extern unsigned char gl_mouse_changed, gl_mouse_clicked;
    65 extern unsigned int gl_mouse_x, gl_mouse_y;
    66 extern unsigned int gl_mouse_button, gl_mouse_state;
    67 #endif
     57#endif
     58
    6859#include "cucul.h"
    6960#include "cucul_internals.h"
     
    190181{
    191182#if defined(USE_SLANG) || defined(USE_NCURSES)
    192     static struct caca_timer key_timer = CACA_TIMER_INITIALIZER;
    193     static unsigned int last_key_ticks = 0;
    194     static unsigned int autorepeat_ticks = 0;
    195     static unsigned int last_key = 0;
    196183    unsigned int ticks;
    197184#endif
     
    210197#if defined(USE_SLANG) || defined(USE_NCURSES)
    211198    /* Simulate long keypresses using autorepeat features */
    212     ticks = _caca_getticks(&key_timer);
    213     last_key_ticks += ticks;
    214     autorepeat_ticks += ticks;
     199    ticks = _caca_getticks(&kk->events.key_timer);
     200    kk->events.last_key_ticks += ticks;
     201    kk->events.autorepeat_ticks += ticks;
    215202
    216203    /* Handle autorepeat */
    217     if(last_key && autorepeat_ticks > AUTOREPEAT_TRIGGER
    218                 && autorepeat_ticks > AUTOREPEAT_THRESHOLD
    219                 && autorepeat_ticks > AUTOREPEAT_RATE)
     204    if(kk->events.last_key
     205           && kk->events.autorepeat_ticks > AUTOREPEAT_TRIGGER
     206           && kk->events.autorepeat_ticks > AUTOREPEAT_THRESHOLD
     207           && kk->events.autorepeat_ticks > AUTOREPEAT_RATE)
    220208    {
    221209        _push_event(event);
    222         autorepeat_ticks -= AUTOREPEAT_RATE;
    223         return CACA_EVENT_KEY_PRESS | last_key;
     210        kk->events.autorepeat_ticks -= AUTOREPEAT_RATE;
     211        return CACA_EVENT_KEY_PRESS | kk->events.last_key;
    224212    }
    225213
    226214    /* We are in autorepeat mode and the same key was just pressed, ignore
    227215     * this event and return the next one by calling ourselves. */
    228     if(event == (CACA_EVENT_KEY_PRESS | last_key))
    229     {
    230         last_key_ticks = 0;
     216    if(event == (CACA_EVENT_KEY_PRESS | kk->events.last_key))
     217    {
     218        kk->events.last_key_ticks = 0;
    231219        return _get_next_event(kk);
    232220    }
     
    234222    /* We are in autorepeat mode, but key has expired or a new key was
    235223     * pressed - store our event and return a key release event first */
    236     if(last_key && (last_key_ticks > AUTOREPEAT_THRESHOLD
    237                      || (event & CACA_EVENT_KEY_PRESS)))
     224    if(kk->events.last_key
     225          && (kk->events.last_key_ticks > AUTOREPEAT_THRESHOLD
     226               || (event & CACA_EVENT_KEY_PRESS)))
    238227    {
    239228        _push_event(event);
    240         event = CACA_EVENT_KEY_RELEASE | last_key;
    241         last_key = 0;
     229        event = CACA_EVENT_KEY_RELEASE | kk->events.last_key;
     230        kk->events.last_key = 0;
    242231        return event;
    243232    }
     
    246235    if(event & CACA_EVENT_KEY_PRESS)
    247236    {
    248         last_key_ticks = 0;
    249         autorepeat_ticks = 0;
    250         last_key = event & 0x00ffffff;
     237        kk->events.last_key_ticks = 0;
     238        kk->events.autorepeat_ticks = 0;
     239        kk->events.last_key = event & 0x00ffffff;
    251240    }
    252241
     
    281270            if(xevent.type == Expose)
    282271            {
    283                 XCopyArea(kk->x11.dpy, kk->x11.pixmap, kk->x11.window, kk->x11.gc, 0, 0,
     272                XCopyArea(kk->x11.dpy, kk->x11.pixmap,
     273                          kk->x11.window, kk->x11.gc, 0, 0,
    284274                          kk->qq->width * kk->x11.font_width,
    285275                          kk->qq->height * kk->x11.font_height, 0, 0);
     
    303293                kk->x11.new_height = h;
    304294
     295                /* If we are already resizing, ignore the new signal */
    305296                if(kk->resize)
    306297                    continue;
     
    739730        glutMainLoopEvent();
    740731
    741         if(gl_resized && !kk->resize)
     732        if(kk->gl.resized && !kk->resize)
    742733        {
    743734            kk->resize = 1;
    744             gl_resized = 0;
     735            kk->gl.resized = 0;
    745736            return CACA_EVENT_RESIZE;
    746737        }
    747738
    748         if(gl_mouse_changed)
    749         {
    750             if(gl_mouse_clicked)
     739        if(kk->gl.mouse_changed)
     740        {
     741            if(kk->gl.mouse_clicked)
    751742            {
    752                 event|= CACA_EVENT_MOUSE_PRESS | gl_mouse_button;
    753                 gl_mouse_clicked=0;
     743                event|= CACA_EVENT_MOUSE_PRESS | kk->gl.mouse_button;
     744                kk->gl.mouse_clicked=0;
    754745            }
    755             mouse_x = gl_mouse_x;
    756             mouse_y = gl_mouse_y;
     746            mouse_x = kk->gl.mouse_x;
     747            mouse_y = kk->gl.mouse_y;
    757748            event |= CACA_EVENT_MOUSE_MOTION | (mouse_x << 12) | mouse_y;
    758             gl_mouse_changed = 0;
    759         }
    760 
    761         if(gl_key != 0)
     749            kk->gl.mouse_changed = 0;
     750        }
     751
     752        if(kk->gl.key != 0)
    762753        {
    763754            event |= CACA_EVENT_KEY_PRESS;
    764             event |= gl_key;
    765             gl_key = 0;
     755            event |= kk->gl.key;
     756            kk->gl.key = 0;
    766757            return event;
    767758        }
    768759
    769         if(gl_special_key != 0)
     760        if(kk->gl.special_key != 0)
    770761        {
    771762            event |= CACA_EVENT_KEY_PRESS;
    772763     
    773             switch(gl_special_key)
     764            switch(kk->gl.special_key)
    774765            {
    775                 case GLUT_KEY_F1 : gl_special_key = 0; return event | CACA_KEY_F1;
    776                 case GLUT_KEY_F2 : gl_special_key = 0; return event | CACA_KEY_F2;
    777                 case GLUT_KEY_F3 : gl_special_key = 0; return event | CACA_KEY_F3;
    778                 case GLUT_KEY_F4 : gl_special_key = 0; return event | CACA_KEY_F4;
    779                 case GLUT_KEY_F5 : gl_special_key = 0; return event | CACA_KEY_F5;
    780                 case GLUT_KEY_F6 : gl_special_key = 0; return event | CACA_KEY_F6;
    781                 case GLUT_KEY_F7 : gl_special_key = 0; return event | CACA_KEY_F7;
    782                 case GLUT_KEY_F8 : gl_special_key = 0; return event | CACA_KEY_F8;
    783                 case GLUT_KEY_F9 : gl_special_key = 0; return event | CACA_KEY_F9;
    784                 case GLUT_KEY_F10: gl_special_key = 0; return event | CACA_KEY_F10;
    785                 case GLUT_KEY_F11: gl_special_key = 0; return event | CACA_KEY_F11;
    786                 case GLUT_KEY_F12: gl_special_key = 0; return event | CACA_KEY_F12;
    787                 case GLUT_KEY_LEFT : gl_special_key = 0; return event | CACA_KEY_LEFT;
    788                 case GLUT_KEY_RIGHT: gl_special_key = 0; return event | CACA_KEY_RIGHT;
    789                 case GLUT_KEY_UP   : gl_special_key = 0; return event | CACA_KEY_UP;
    790                 case GLUT_KEY_DOWN : gl_special_key = 0; return event | CACA_KEY_DOWN;
     766                case GLUT_KEY_F1 : kk->gl.special_key = 0; return event | CACA_KEY_F1;
     767                case GLUT_KEY_F2 : kk->gl.special_key = 0; return event | CACA_KEY_F2;
     768                case GLUT_KEY_F3 : kk->gl.special_key = 0; return event | CACA_KEY_F3;
     769                case GLUT_KEY_F4 : kk->gl.special_key = 0; return event | CACA_KEY_F4;
     770                case GLUT_KEY_F5 : kk->gl.special_key = 0; return event | CACA_KEY_F5;
     771                case GLUT_KEY_F6 : kk->gl.special_key = 0; return event | CACA_KEY_F6;
     772                case GLUT_KEY_F7 : kk->gl.special_key = 0; return event | CACA_KEY_F7;
     773                case GLUT_KEY_F8 : kk->gl.special_key = 0; return event | CACA_KEY_F8;
     774                case GLUT_KEY_F9 : kk->gl.special_key = 0; return event | CACA_KEY_F9;
     775                case GLUT_KEY_F10: kk->gl.special_key = 0; return event | CACA_KEY_F10;
     776                case GLUT_KEY_F11: kk->gl.special_key = 0; return event | CACA_KEY_F11;
     777                case GLUT_KEY_F12: kk->gl.special_key = 0; return event | CACA_KEY_F12;
     778                case GLUT_KEY_LEFT : kk->gl.special_key = 0; return event | CACA_KEY_LEFT;
     779                case GLUT_KEY_RIGHT: kk->gl.special_key = 0; return event | CACA_KEY_RIGHT;
     780                case GLUT_KEY_UP   : kk->gl.special_key = 0; return event | CACA_KEY_UP;
     781                case GLUT_KEY_DOWN : kk->gl.special_key = 0; return event | CACA_KEY_DOWN;
    791782                default: return CACA_EVENT_NONE;
    792783            }
Note: See TracChangeset for help on using the changeset viewer.