source: abuse/trunk/src/imlib/jwindow.cpp @ 659

Last change on this file since 659 was 659, checked in by Sam Hocevar, 11 years ago

imlib: rename Jwindow's x and y members to m_pos.

File size: 18.8 KB
RevLine 
[56]1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
[494]4 *  Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
[56]5 *
6 *  This software was released into the Public Domain. As with most public
[555]7 *  domain software, no warranty is made or implied by Crack dot Com, by
8 *  Jonathan Clark, or by Sam Hocevar.
[56]9 */
10
[555]11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
[56]14
[131]15#include <string.h>
16
[512]17#include "common.h"
18
[481]19#include "video.h"
20#include "image.h"
21#include "input.h"
22#include "event.h"
23#include "filter.h"
24#include "jwindow.h"
[2]25
[111]26static int jw_left = 3, jw_right = 3, jw_top = 2, jw_bottom = 3;
[2]27
28int frame_top() { return jw_top; }
29int frame_bottom() { return jw_bottom; }
30int frame_left() { return jw_left; }
31int frame_right() { return jw_right; }
32
[111]33//
34//  Sets the size of the border around each window
35//
[2]36void set_frame_size(int x)
[124]37{
[111]38    if(x < 1)
39        x = 1;
40    jw_left = x;
41    jw_right = x;
42    jw_top = 2;
43    jw_bottom = x;
[2]44}
45
46 // true if a window lies in this area
[120]47int WindowManager::window_in_area(int x1, int y1, int x2, int y2)
[2]48{
[649]49  for (Jwindow *f=m_first; f; f=f->next)
[659]50    if (f->m_pos.x<=x2 && f->m_pos.y<=y2 && f->m_pos.x+f->l-1>=x1 && f->m_pos.y+f->h-1>=y1)
[2]51      return 1;
52  return 0;
53}
54
[120]55void WindowManager::grab_focus(Jwindow *j)
[649]56{ m_grab=j; }
[2]57
[120]58void WindowManager::release_focus()
[649]59{ m_grab=NULL; }
[2]60
61
[120]62void WindowManager::close_window(Jwindow *j)
[2]63{
[111]64    delete j;
[2]65}
66
[120]67void WindowManager::hide_windows()
[2]68{
[649]69    for (Jwindow *p = m_first; p; p = p->next)
[2]70    {
[518]71        if (!p->is_hidden())
72        {
73            p->hide();
[659]74            m_surf->AddDirty(p->m_pos.x, p->m_pos.y, p->m_pos.x + p->l, p->m_pos.y + p->h);
[518]75        }
[2]76    }
77}
78
[120]79void WindowManager::show_windows()
[2]80{
[120]81  Jwindow *p;
[649]82  for (p=m_first; p; p=p->next)
[109]83    if (p->is_hidden())
[124]84      show_window(p);
[2]85}
86
[120]87void WindowManager::hide_window(Jwindow *j)
[2]88{
[649]89    if (j == m_first)
90        m_first = m_first->next;
[518]91    else
92    {
93        Jwindow *k;
[649]94        for (k = m_first; k->next != j; k = k->next)
[659]95            k->m_surf->AddDirty(j->m_pos.x - k->m_pos.x, j->m_pos.y - k->m_pos.y,
96                                  j->m_pos.x + j->l - k->m_pos.x, j->m_pos.y + j->h - k->m_pos.y);
97        k->m_surf->AddDirty(j->m_pos.x - k->m_pos.x, j->m_pos.y - k->m_pos.y,
98                              j->m_pos.x + j->l - k->m_pos.x, j->m_pos.y + j->h - k->m_pos.y);
[518]99        k->next = j->next;
100    }
[659]101    m_surf->AddDirty(j->m_pos.x, j->m_pos.y, j->m_pos.x + j->l, j->m_pos.y + j->h);
[518]102    j->hide();
[2]103}
104
[120]105void WindowManager::show_window(Jwindow *j)
[2]106{
[518]107    if (j->is_hidden())
108    {
109        j->show();
[644]110        j->m_surf->AddDirty(0, 0, j->l, j->h);
[518]111    }
[2]112}
113
[643]114void WindowManager::get_event(Event &ev)
[2]115{
[643]116  Get(ev);
117
[2]118  if (ev.type==EV_KEY)
119    key_state[ev.key]=1;
120  else if (ev.type==EV_KEYRELEASE)
121    key_state[ev.key]=0;
122
123  if (state==inputing)
124  {
[643]125    Jwindow *j;
[649]126    for (ev.window=NULL,j=m_first; j; j=j->next)
[659]127      if (!j->is_hidden() && ev.mouse_move >= j->m_pos
128                          && ev.mouse_move < j->m_pos + vec2i(j->l, j->h))
[2]129        ev.window=j;
130
[649]131    if (!ev.window && m_grab) ev.window=m_grab;
[2]132
133    if (ev.window)
134    {
135      int closew=0,movew=0;
136
137      if ((ev.type==EV_MOUSE_BUTTON && ev.mouse_button==1 && ev.window &&
[659]138       ev.mouse_move >= ev.window->m_pos &&
139       ev.mouse_move < ev.window->m_pos + vec2i(ev.window->l, ev.window->y1())))
[2]140      {
[659]141    if (ev.mouse_move.x-ev.window->m_pos.x < 11) closew=1;
[124]142    else if (ev.window->is_moveable()) movew=1;
[649]143      } else if (m_grab)
144        ev.window=m_grab;
[2]145
146      if (ev.type==EV_KEY && ev.key==JK_ESC)
147        closew=1;
148
[124]149
150
[2]151      if (closew)
152        ev.type=EV_CLOSE_WINDOW;
153      else if (movew)
[494]154      {
[124]155    int red=0;
[649]156    if (ev.window==m_first)       // see if we need to raise the window
[124]157    {
[649]158      m_first=m_first->next;
159      if (m_first)
[124]160        red=1;
161    }
162    else
163    {
[649]164      Jwindow *last=m_first;
[494]165      for (; last->next!=ev.window; last=last->next);
[124]166      if (ev.window->next)
167        red=1;
168      last->next=ev.window->next;
169    }
[649]170    if (!m_first)
171      m_first=ev.window;
[124]172    else
173    {
[649]174      Jwindow *last=m_first;
[494]175      for (; last->next; last=last->next);
[124]176      last->next=ev.window;
177    }
178    ev.window->next=NULL;
179    if (red)
180    {
181      Jwindow *j=ev.window;
[644]182/*      m_surf->AddDirty(j->x,j->y,j->x+j->l,j->y+j->h);
[649]183      for (p=m_first; p!=j; p=p->next)
[644]184        p->m_surf->AddDirty(j->x-p->x,j->y-p->y,j->x+j->l-p->x,j->y+j->h-p->y); */
185      j->m_surf->AddDirty(0, 0, j->l, j->h);
[124]186      flush_screen();
187    }
[2]188
189        state=dragging;
190        drag_window=ev.window;
[659]191        drag_mousex=ev.window->m_pos.x-ev.mouse_move.x;
192        drag_mousey=ev.window->m_pos.y-ev.mouse_move.y;
[2]193        ev.type=EV_SPURIOUS;
194      } else if (ev.window)
[106]195        ev.window->inm->handle_event(ev,ev.window);
[2]196    }
197  } else if (state==dragging)
198  {
199    ev.window=drag_window;
200    if (ev.type==EV_MOUSE_BUTTON && ev.mouse_button==0)  // user released the mouse
201    {
202      state=inputing;
203      ev.type=EV_SPURIOUS;
204    } else if (ev.type==EV_MOUSE_MOVE)
205    {
206       move_window(drag_window,ev.mouse_move.x+drag_mousex,ev.mouse_move.y+drag_mousey);
207       flush_screen();
208       ev.type=EV_DRAG_WINDOW;
209       ev.window_position.x=ev.mouse_move.x+drag_mousex;
210       ev.window_position.y=ev.mouse_move.y+drag_mousey;
211    }
[124]212  }
[518]213  if (ev.type == EV_REDRAW)
[2]214  {
[649]215    for (Jwindow *j = m_first; j; j = j->next)
[659]216       j->m_surf->AddDirty(ev.redraw.x1 - j->m_pos.x, ev.redraw.y1 - j->m_pos.y,
217                             ev.redraw.x2 + 1 - j->m_pos.x, ev.redraw.y2 + 1 - j->m_pos.y);
[644]218    m_surf->AddDirty(ev.redraw.x1, ev.redraw.y1, ev.redraw.x2 + 1, ev.redraw.y2 + 1);
[2]219    flush_screen();
220    ev.type=EV_SPURIOUS;   // we took care of this one by ourselves.
221  }
222}
223
[120]224void Jwindow::resize(int L, int H)
[2]225{
[644]226  m_surf->SetSize(vec2i(L,H));
[2]227  l=L; h=H;
228}
229
[120]230void WindowManager::resize_window(Jwindow *j, int l, int h)
[2]231{
[120]232  Jwindow *p;
[659]233  m_surf->AddDirty(j->m_pos.x, j->m_pos.y, j->m_pos.x + j->l, j->m_pos.y + j->h);
[649]234  for (p=m_first; p!=j; p=p->next)
[659]235    p->m_surf->AddDirty(j->m_pos.x - p->m_pos.x, j->m_pos.y - p->m_pos.y, j->m_pos.x + j->l - p->m_pos.x, j->m_pos.y + j->h - p->m_pos.y);
[2]236  j->resize(l,h);
237  if (!frame_suppress)
[111]238  j->redraw();
[2]239}
240
[120]241void WindowManager::move_window(Jwindow *j, int x, int y)
[2]242{
[659]243    m_surf->AddDirty(j->m_pos.x, j->m_pos.y, j->m_pos.x + j->l, j->m_pos.y + j->h);
[649]244    for(Jwindow *p = m_first; p != j; p = p->next)
[659]245        p->m_surf->AddDirty(j->m_pos.x - p->m_pos.x, j->m_pos.y - p->m_pos.y,
246                              j->m_pos.x + j->l - p->m_pos.x, j->m_pos.y + j->h - p->m_pos.y);
247    j->m_pos.x = x;
248    j->m_pos.y = y;
[644]249    j->m_surf->AddDirty(0, 0, j->l, j->h);
[2]250}
251
[643]252WindowManager::WindowManager(image *screen, palette *pal, int Hi,
[124]253                             int Med, int Low, JCFont *Font)
[643]254  : EventHandler(screen, pal)
[2]255{
[111]256    wm = this;
[644]257    m_surf = screen;
[649]258    hi = Hi; low = Low; med = Med; m_first = NULL; m_pal = pal; m_grab = NULL;
[111]259    bk = pal->find_closest(0, 0, 0);
260    state = inputing; fnt = Font;  wframe_fnt = Font;
261    memset(key_state, 0, sizeof(key_state));
262    frame_suppress = 0;
[2]263}
264
[120]265WindowManager::~WindowManager()
[2]266{
[649]267    while(m_first)
268        close_window(m_first);
[111]269    wm = NULL;
[2]270}
271
[120]272void WindowManager::add_window(Jwindow *win)
[111]273{
[649]274    if(!m_first)
275        m_first = win;
[111]276    else
277    {
[649]278        Jwindow *tmp = m_first;
[111]279        while(tmp->next)
280            tmp = tmp->next;
281        tmp->next = win;
282        win->next = NULL;
283    }
284}
285
[120]286void WindowManager::remove_window(Jwindow *win)
[111]287{
[649]288    if(m_grab == win)
289        m_grab = NULL;
[111]290
291    // close the window we were dragging
292    if(state == dragging && win == drag_window)
293        state = inputing;
294
[649]295    if(m_first == win)
296        m_first = m_first->next;
[111]297    else
298    {
[120]299        Jwindow * search;
[649]300        for(search = m_first; search->next != win; search = search->next)
[659]301            search->m_surf->AddDirty(win->m_pos.x - search->m_pos.x,
302                                     win->m_pos.y - search->m_pos.y,
303                                     win->m_pos.x + win->l - search->m_pos.x,
304                                     win->m_pos.y + win->h - search->m_pos.y);
305        search->m_surf->AddDirty(win->m_pos.x - search->m_pos.x,
306                                 win->m_pos.y - search->m_pos.y,
307                                 win->m_pos.x + win->l - search->m_pos.x,
308                                 win->m_pos.y + win->h - search->m_pos.y);
[111]309        search->next = win->next;
310    }
311
[659]312    m_surf->AddDirty(win->m_pos.x, win->m_pos.y, win->m_pos.x + win->l, win->m_pos.y + win->h);
[111]313}
314
[120]315Jwindow * WindowManager::new_window(int x, int y, int l, int h,
[111]316                                     ifield * fields, char const *name)
317{
[644]318    if(x > m_surf->Size().x - 4)
319        x = m_surf->Size().x - 25;
320    if(y > m_surf->Size().y - 4)
321        y = m_surf->Size().y - 10;
[124]322
[659]323    Jwindow * j = new Jwindow (vec2i(x, y), l, h, fields, name);
[111]324    j->show();
325
326    return j;
327}
328
[120]329void WindowManager::flush_screen()
[2]330{
[659]331    vec2i m1(0, 0);
[2]332
[652]333    if (has_mouse())
[124]334    {
[659]335        m1 = m_pos - m_center;
336        vec2i m2 = m1 + m_sprite->visual->Size() - vec2i(1, 1);
[2]337
[659]338        m_sprite->save->PutPart(m_surf, 0, 0, m1.x, m1.y, m2.x, m2.y);
339        m_surf->PutImage(m_sprite->visual, m1, 1);
[124]340    }
[2]341
[652]342    for (Jwindow *p = m_first; p; p = p->next)
343        if (!p->is_hidden())
[659]344            m_surf->delete_dirty(p->m_pos.x, p->m_pos.y, p->m_pos.x + p->l, p->m_pos.y + p->h);
[644]345    update_dirty(m_surf);
[2]346
[652]347    if (has_mouse())
[659]348        m_surf->PutImage(m_sprite->save, m1);
[124]349
[652]350    for (Jwindow *p = m_first; p; p = p->next)
[2]351    {
[652]352        if (p->is_hidden())
[124]353            continue;
[2]354
[652]355        if (has_mouse())
[124]356        {
[659]357            m_sprite->save->PutPart(p->m_surf, 0, 0, m1.x - p->m_pos.x, m1.y - p->m_pos.y,
358                                    m1.x - p->m_pos.x + m_sprite->visual->Size().x - 1,
359                                    m1.y - p->m_pos.y + m_sprite->visual->Size().y - 1);
360            p->m_surf->PutImage(m_sprite->visual, m1 - p->m_pos, 1);
[124]361        }
362
[659]363//          m_surf->delete_dirty(p->m_pos.x, p->m_pos.y, p->m_pos.x+p->l, p->m_pos.y+p->h);
[652]364        for (Jwindow *q = p->next; q; q = q->next)
365            if (!q->is_hidden())
[659]366                p->m_surf->delete_dirty(q->m_pos.x - p->m_pos.x, q->m_pos.y - p->m_pos.y,
367                                        q->m_pos.x + q->l - p->m_pos.x,
368                                        q->m_pos.y + q->h - p->m_pos.y);
369        update_dirty(p->m_surf, p->m_pos.x, p->m_pos.y);
[652]370        if (has_mouse())
[659]371            p->m_surf->PutImage(m_sprite->save, m1 - p->m_pos, 0);
[2]372    }
373}
374
[120]375Jwindow::Jwindow(char const *name)
[2]376{
[117]377    _x1 = left_border();
378    _y1 = jw_top + 5;
379    _x2 = _y2 = 0;
380
[111]381    _hidden = true;
382    _moveable = true;
383    // property.flags = JWINDOW_NOAUTOHIDE_FLAG;
[117]384
[120]385    inm = new InputManager(this, NULL);
[116]386    reconfigure();
387
[644]388    m_surf = NULL;
[116]389    next = NULL;
[119]390
[111]391    _name = NULL;
[119]392    if(name)
[131]393        _name = strdup(name);
[111]394    wm->add_window(this);
395}
[2]396
[659]397Jwindow::Jwindow(vec2i pos, int L, int H, ifield *f, char const *name)
[111]398{
399    l = 0;
[124]400    h = 0;
[111]401    _hidden = false;
402    _moveable = true;
[2]403
[111]404    _x1 = left_border();
405    _y1 = name ? top_border() : jw_top + 5;
[2]406
[644]407    m_surf = NULL;
408    inm = new InputManager(m_surf, f);
[111]409    reconfigure(); /* FIXME: TODO */
410
411    l = L >= 0 ? L + left_border() : l - L;
412    h = H >= 0 ? H + top_border() : h - H;
[659]413    m_pos.x = pos.x >= 0 ? pos.x : xres - l + pos.x - left_border() - right_border() - 1;
414    m_pos.y = pos.y >= 0 ? pos.y : yres - h + pos.y - top_border() - bottom_border() - 1;
[111]415
[109]416    backg = wm->medium_color();
[2]417
[111]418    _x2 = l - 1;
419    _y2 = h - 1;
420    l += right_border();
421    h += bottom_border();
422
423    if(L == -1)
424        if(l < 15 + left_border() + right_border())
425            l = 15 + left_border() + right_border();
426    if(H == -1)
427        if(h < top_border() + bottom_border())
428            h = top_border() + bottom_border();
[644]429    m_surf = new image(vec2i(l, h), NULL, 2);
430    m_surf->clear(backg);
[111]431    // Keep this from getting destroyed when image list is cleared
[644]432    image_list.unlink(m_surf);
433    inm->m_surf = m_surf;
[111]434
[109]435    next = NULL;
[111]436
437    _name = NULL;
438    if(name)
[131]439        _name = strdup(name);
[111]440
441    wm->add_window(this);
442    if(!wm->frame_suppress)
443        redraw();
[109]444}
[2]445
[120]446Jwindow::~Jwindow()
[111]447{
448    wm->remove_window(this);
449    local_close();
[644]450    delete m_surf;
[111]451    delete inm;
452    if(_name)
[129]453        free(_name);
[111]454}
455
[120]456void Jwindow::reconfigure()
[111]457{
458    int x1, y1, x2, y2;
459    ifield *i;
460    l = 2;
461    h = 2;
[649]462    for(i = inm->m_first; i; i = i->next)
[111]463    {
464        i->set_owner(this);
465        i->area(x1, y1, x2, y2);
[124]466        if ((int)y2 > (int)h)
[111]467            h = y2;
[124]468        if ((int)x2 > (int)l)
[111]469            l = x2;
470    }
471}
472
[120]473void Jwindow::local_close()
[109]474{
475    ;
[2]476}
477
[120]478void Jwindow::redraw()
[2]479{
[655]480    int hi = wm->bright_color();
481    int med = wm->medium_color();
482    int low = wm->dark_color();
483    JCFont * fnt = wm->frame_font();
[2]484
[111]485    if(_name)
486    {
487        if (right_border() >= 1)
488        {
[655]489            m_surf->WidgetBar(vec2i(0, 0), vec2i(l - 1, h - 1), hi, med, low);
[111]490            if (right_border() >= 3)
[655]491                m_surf->WidgetBar(vec2i(right_border() - 1, top_border() - 1),
492                                  vec2i(l - left_border(), h - bottom_border()),
493                                  low, med, hi);
[124]494
[111]495          else
[655]496            m_surf->Line(vec2i(left_border() - 1, top_border() - 1),
497                         vec2i(right_border() - 1, top_border() - 1), low);
[111]498        }
[655]499      m_surf->Rectangle(vec2i(2, 2), vec2i(top_border() - 2, top_border() - 3),
500                        wm->black());
501      m_surf->WidgetBar(vec2i(3, 3), vec2i(top_border() - 3, top_border() - 4),
502                        hi, med, low); // draws the 'close' button
[111]503    }
[124]504
[111]505  else
506    {
507      if (right_border() >= 1)
508        {
[655]509          m_surf->WidgetBar(vec2i(0, 0), vec2i(l - 1, h - 1), hi, med, low);
[111]510          if (right_border() >= 3)
[655]511            m_surf->WidgetBar(vec2i(right_border() - 1, jw_top + 4),
512                              vec2i(l - left_border(), h - bottom_border()),
513                              low, med, hi);
[111]514          else
[655]515            m_surf->Line(vec2i(left_border() - 1, jw_top + 4),
516                         vec2i(right_border() - 1, jw_top + 4), low);
[111]517        }
[655]518      // Draw the 'close' button
519      m_surf->Rectangle(vec2i(1, 1), vec2i(4, 4), wm->black ());
520      m_surf->WidgetBar(vec2i(2, 2), vec2i(3, 3), hi, med, low);
[111]521    }
522  if (_name && _name[0])
523    {
[655]524      m_surf->Bar(vec2i(top_border(), 1),
525                  vec2i(top_border() + fnt->width() * strlen (_name) + 1,
526                        top_border() - 2),
527                  med);
528      fnt->put_string(m_surf, top_border() + 1, 1, _name, low);
[111]529    }
[655]530  // clear 'client' region
531  m_surf->Bar(vec2i(x1(), y1()), vec2i(x2(), y2()), backg);
[111]532  inm->redraw ();
533}
[2]534
[120]535int Jwindow::left_border()
[111]536{
537    return frame_left();
538}
[2]539
[120]540int Jwindow::right_border()
[111]541{
542    return frame_right();
543}
[2]544
[120]545int Jwindow::top_border()
[111]546{
547    return wm->font()->height() + frame_top();
548}
[2]549
[120]550int Jwindow::bottom_border()
[111]551{
552    return frame_bottom();
[2]553}
554
555
[120]556ifield *InputManager::unlink(int id)     // unlinks ID from fields list and return the pointer to it
[124]557{
[649]558  for (ifield *i=m_first,*last=NULL; i; i=i->next)
[2]559  {
[124]560    if (i->id==id)
[2]561    {
[649]562      if (i==m_first)
563    m_first=m_first->next;
[2]564      else
565        last->next=i->next;
[649]566      if (m_active==i)
567        m_active=m_first;
[2]568      return i;
569    }
570    ifield *x=i->unlink(id);
571    if (x) return x;
572    last=i;
573  }
574  return NULL;   // no such id
575}
576
[124]577InputManager::~InputManager()
578{ ifield *i;
[649]579  while (m_first)
580  { i=m_first;
581    m_first=m_first->next;
[124]582    delete i;
583  }
584}
[2]585
[120]586void InputManager::clear_current()
[2]587{
[649]588    if(m_owner)
589        m_surf = m_owner->m_surf;
590    if(m_active)
591        m_active->draw(0, m_surf);
592    m_active = NULL;
[2]593}
594
[643]595void InputManager::handle_event(Event &ev, Jwindow *j)
[2]596{
597  ifield *i,*in_area=NULL;
598  int x1,y1,x2,y2;
[109]599
[649]600  if(m_owner)
601      m_surf = m_owner->m_surf;
[109]602
[2]603  if (j)
604  {
[659]605    ev.mouse_move -= j->m_pos;
606    m_cur = j;
[2]607  }
608
[649]609  if (!m_grab)
[2]610  {
611    if ((ev.type==EV_MOUSE_BUTTON && ev.mouse_button==1) || ev.type==EV_MOUSE_MOVE)
612    {
[649]613      for (i=m_first; i; i=i->next)
[2]614      {
[124]615    i->area(x1,y1,x2,y2);
616    if (ev.mouse_move.x>=x1 && ev.mouse_move.y>=y1 &&
617        ev.mouse_move.x<=x2 && ev.mouse_move.y<=y2)
[2]618        in_area=i;
619      }
[649]620      if (in_area!=m_active && (no_selections_allowed || (in_area && in_area->selectable())))
[2]621      {
[649]622    if (m_active)
623          m_active->draw(0,m_surf);
[2]624
[649]625    m_active=in_area;
[2]626
[649]627    if (m_active)
628      m_active->draw(1,m_surf);
[2]629      }
[124]630    }
[649]631    if (ev.type==EV_KEY && ev.key==JK_TAB && m_active)
[124]632    {
[649]633      m_active->draw(0,m_surf);
[2]634      do
635      {
[649]636    m_active=m_active->next;
637    if (!m_active) m_active=m_first;
638      } while (m_active && !m_active->selectable());
639      m_active->draw(1,m_surf);
[2]640    }
[649]641  } else m_active=m_grab;
[2]642
[649]643  if (m_active)
[2]644  {
645    if (ev.type!=EV_MOUSE_MOVE && ev.type!=EV_MOUSE_BUTTON)
[649]646      m_active->handle_event(ev,m_surf,this);
[2]647    else
648    {
[649]649      m_active->area(x1,y1,x2,y2);
650      if (m_grab || (ev.mouse_move.x>=x1 && ev.mouse_move.y>=y1 &&
[2]651          ev.mouse_move.x<=x2 && ev.mouse_move.y<=y2))
652      {
[124]653    if (j)
[649]654      m_active->handle_event(ev,m_surf,j->inm);
655    else m_active->handle_event(ev,m_surf,this);
[2]656      }
657    }
658  }
659
660  if (j)
[659]661    ev.mouse_move += j->m_pos;
[2]662}
663
[120]664void InputManager::allow_no_selections()
[2]665{
[649]666    no_selections_allowed=1;
[2]667}
668
[120]669void InputManager::redraw()
[2]670{
[109]671    ifield *i;
[649]672    if(m_owner)
673        m_surf = m_owner->m_surf;
674    for(i = m_first; i; i = i->next)
[644]675        i->draw_first(m_surf);
[649]676    if(m_active)
677        m_active->draw(1, m_surf);
[2]678}
679
[649]680InputManager::InputManager(image *screen, ifield *first)
[2]681{
[109]682    no_selections_allowed = 0;
[649]683    m_cur = NULL;
684    m_grab = NULL;
685    m_owner = NULL;
[644]686    m_surf = screen;
[649]687    m_active = m_first = first;
688    while(m_active && !m_active->selectable())
689        m_active = m_active->next;
[644]690    if(m_surf)
[109]691        redraw();
[2]692}
693
[649]694InputManager::InputManager(Jwindow *owner, ifield *first)
[109]695{
696    no_selections_allowed = 0;
[649]697    m_cur = NULL;
698    m_grab = NULL;
699    m_owner = owner;
[644]700    m_surf = NULL;
[649]701    m_active = m_first = first;
702    while(m_active && !m_active->selectable())
703        m_active = m_active->next;
[109]704}
705
[120]706void InputManager::grab_focus(ifield *i)
[649]707{
708    m_grab = i;
709    if (m_cur)
710        wm->grab_focus(m_cur);
[2]711}
712
[120]713void InputManager::release_focus()
[649]714{
715    m_grab = NULL;
716    if (m_cur)
717        wm->release_focus();
[2]718}
719
[579]720void InputManager::remap(Filter *f)
[2]721{
[649]722    for (ifield *i = m_first; i; i = i->next)
723        i->remap(f);
724    redraw();
[2]725}
726
[124]727void InputManager::add(ifield *i)
[649]728{ ifield *f=m_first;
[2]729  if (i->selectable())
730  {
731    if (!f)
[649]732      m_first=i;
[2]733    else
734    {
735      while (f->next) f=f->next;
[124]736      f->next=i;
[2]737    }
738  }
739}
740
[120]741ifield *InputManager::get(int id)
[2]742{
743  ifield *f;
[649]744  for (f=m_first; f; f=f->next)
[2]745  {
746    ifield *ret=f->find(id);
747    if (ret) return ret;
748  }
749  return NULL;
750}
751
[109]752ifield::ifield()
753{
754    owner = NULL;
[659]755    m_pos = vec2i(0, 0);
[109]756    next = NULL;
757    id = 0;
758}
[2]759
[109]760ifield::~ifield()
761{
762    ;
763}
[2]764
[109]765/* re-position the control with respect to the "client" area of the window */
[120]766void ifield::set_owner(Jwindow * newowner)
[109]767{
768    if(owner)
[659]769        Move(m_pos - vec2i(owner->x1(), owner->y1()));
[109]770    owner = newowner;
771    if(owner)
[659]772        Move(m_pos + vec2i(owner->x1(), owner->y1()));
[109]773}
774
Note: See TracBrowser for help on using the repository browser.