Changeset 649


Ignore:
Timestamp:
May 14, 2011, 3:06:19 AM (9 years ago)
Author:
Sam Hocevar
Message:

imlib: some refactoring in JWindow.

Location:
abuse/trunk/src/imlib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • abuse/trunk/src/imlib/jwindow.cpp

    r644 r649  
    4747int WindowManager::window_in_area(int x1, int y1, int x2, int y2)
    4848{
    49   for (Jwindow *f=first; f; f=f->next)
     49  for (Jwindow *f=m_first; f; f=f->next)
    5050    if (f->x<=x2 && f->y<=y2 && f->x+f->l-1>=x1 && f->y+f->h-1>=y1)
    5151      return 1;
     
    5454
    5555void WindowManager::grab_focus(Jwindow *j)
    56 { grab=j; }
     56{ m_grab=j; }
    5757
    5858void WindowManager::release_focus()
    59 { grab=NULL; }
     59{ m_grab=NULL; }
    6060
    6161
     
    6767void WindowManager::hide_windows()
    6868{
    69     for (Jwindow *p = first; p; p = p->next)
     69    for (Jwindow *p = m_first; p; p = p->next)
    7070    {
    7171        if (!p->is_hidden())
     
    8080{
    8181  Jwindow *p;
    82   for (p=first; p; p=p->next)
     82  for (p=m_first; p; p=p->next)
    8383    if (p->is_hidden())
    8484      show_window(p);
     
    8787void WindowManager::hide_window(Jwindow *j)
    8888{
    89     if (j == first)
    90         first = first->next;
     89    if (j == m_first)
     90        m_first = m_first->next;
    9191    else
    9292    {
    9393        Jwindow *k;
    94         for (k = first; k->next != j; k = k->next)
     94        for (k = m_first; k->next != j; k = k->next)
    9595            k->m_surf->AddDirty(j->x - k->x, j->y - k->y,
    9696                                  j->x + j->l - k->x, j->y + j->h - k->y);
     
    124124  {
    125125    Jwindow *j;
    126     for (ev.window=NULL,j=first; j; j=j->next)
     126    for (ev.window=NULL,j=m_first; j; j=j->next)
    127127      if (!j->is_hidden() && ev.mouse_move.x>=j->x && ev.mouse_move.y>=j->y &&
    128128          ev.mouse_move.x<j->x+j->l && ev.mouse_move.y<j->y+j->h)
    129129        ev.window=j;
    130130
    131     if (!ev.window && grab) ev.window=grab;
     131    if (!ev.window && m_grab) ev.window=m_grab;
    132132
    133133    if (ev.window)
     
    141141    if (ev.mouse_move.x-ev.window->x<11) closew=1;
    142142    else if (ev.window->is_moveable()) movew=1;
    143       } else if (grab)
    144         ev.window=grab;
     143      } else if (m_grab)
     144        ev.window=m_grab;
    145145
    146146      if (ev.type==EV_KEY && ev.key==JK_ESC)
     
    154154      {
    155155    int red=0;
    156     if (ev.window==first)       // see if we need to raise the window
    157     {
    158       first=first->next;
    159       if (first)
     156    if (ev.window==m_first)       // see if we need to raise the window
     157    {
     158      m_first=m_first->next;
     159      if (m_first)
    160160        red=1;
    161161    }
    162162    else
    163163    {
    164       Jwindow *last=first;
     164      Jwindow *last=m_first;
    165165      for (; last->next!=ev.window; last=last->next);
    166166      if (ev.window->next)
     
    168168      last->next=ev.window->next;
    169169    }
    170     if (!first)
    171       first=ev.window;
     170    if (!m_first)
     171      m_first=ev.window;
    172172    else
    173173    {
    174       Jwindow *last=first;
     174      Jwindow *last=m_first;
    175175      for (; last->next; last=last->next);
    176176      last->next=ev.window;
     
    181181      Jwindow *j=ev.window;
    182182/*      m_surf->AddDirty(j->x,j->y,j->x+j->l,j->y+j->h);
    183       for (p=first; p!=j; p=p->next)
     183      for (p=m_first; p!=j; p=p->next)
    184184        p->m_surf->AddDirty(j->x-p->x,j->y-p->y,j->x+j->l-p->x,j->y+j->h-p->y); */
    185185      j->m_surf->AddDirty(0, 0, j->l, j->h);
     
    213213  if (ev.type == EV_REDRAW)
    214214  {
    215     for (Jwindow *j = first; j; j = j->next)
     215    for (Jwindow *j = m_first; j; j = j->next)
    216216       j->m_surf->AddDirty(ev.redraw.x1 - j->x, ev.redraw.y1 - j->y,
    217217                             ev.redraw.x2 + 1 - j->x, ev.redraw.y2 + 1 - j->y);
     
    232232  Jwindow *p;
    233233  m_surf->AddDirty(j->x, j->y, j->x + j->l, j->y + j->h);
    234   for (p=first; p!=j; p=p->next)
     234  for (p=m_first; p!=j; p=p->next)
    235235    p->m_surf->AddDirty(j->x - p->x, j->y - p->y, j->x + j->l - p->x, j->y + j->h - p->y);
    236236  j->resize(l,h);
     
    242242{
    243243    m_surf->AddDirty(j->x, j->y, j->x + j->l, j->y + j->h);
    244     for(Jwindow *p = first; p != j; p = p->next)
     244    for(Jwindow *p = m_first; p != j; p = p->next)
    245245        p->m_surf->AddDirty(j->x - p->x, j->y - p->y,
    246246                              j->x + j->l - p->x, j->y + j->h - p->y);
     
    256256    wm = this;
    257257    m_surf = screen;
    258     hi = Hi; low = Low; med = Med; first = NULL; m_pal = pal; grab = NULL;
     258    hi = Hi; low = Low; med = Med; m_first = NULL; m_pal = pal; m_grab = NULL;
    259259    bk = pal->find_closest(0, 0, 0);
    260260    state = inputing; fnt = Font;  wframe_fnt = Font;
     
    265265WindowManager::~WindowManager()
    266266{
    267     while(first)
    268         close_window(first);
     267    while(m_first)
     268        close_window(m_first);
    269269    wm = NULL;
    270270}
     
    272272void WindowManager::add_window(Jwindow *win)
    273273{
    274     if(!first)
    275         first = win;
     274    if(!m_first)
     275        m_first = win;
    276276    else
    277277    {
    278         Jwindow *tmp = first;
     278        Jwindow *tmp = m_first;
    279279        while(tmp->next)
    280280            tmp = tmp->next;
     
    286286void WindowManager::remove_window(Jwindow *win)
    287287{
    288     if(grab == win)
    289         grab = NULL;
     288    if(m_grab == win)
     289        m_grab = NULL;
    290290
    291291    // close the window we were dragging
     
    293293        state = inputing;
    294294
    295     if(first == win)
    296         first = first->next;
     295    if(m_first == win)
     296        m_first = m_first->next;
    297297    else
    298298    {
    299299        Jwindow * search;
    300         for(search = first; search->next != win; search = search->next)
     300        for(search = m_first; search->next != win; search = search->next)
    301301            search->m_surf->AddDirty(win->x - search->x,
    302302                                       win->y - search->y,
     
    346346    }
    347347
    348     for(p = first; p; p = p->next)
     348    for(p = m_first; p; p = p->next)
    349349        if(!p->is_hidden())
    350350            m_surf->delete_dirty(p->x, p->y, p->x + p->l, p->y + p->h);
     
    354354        m_surf->PutImage(mouse_save, mx, my);
    355355
    356     for(p = first; p; p = p->next)
     356    for(p = m_first; p; p = p->next)
    357357    {
    358358        if(p->is_hidden())
     
    466466    l = 2;
    467467    h = 2;
    468     for(i = inm->first; i; i = i->next)
     468    for(i = inm->m_first; i; i = i->next)
    469469    {
    470470        i->set_owner(this);
     
    559559ifield *InputManager::unlink(int id)     // unlinks ID from fields list and return the pointer to it
    560560{
    561   for (ifield *i=first,*last=NULL; i; i=i->next)
     561  for (ifield *i=m_first,*last=NULL; i; i=i->next)
    562562  {
    563563    if (i->id==id)
    564564    {
    565       if (i==first)
    566     first=first->next;
     565      if (i==m_first)
     566    m_first=m_first->next;
    567567      else
    568568        last->next=i->next;
    569       if (active==i)
    570         active=first;
     569      if (m_active==i)
     570        m_active=m_first;
    571571      return i;
    572572    }
     
    580580InputManager::~InputManager()
    581581{ ifield *i;
    582   while (first)
    583   { i=first;
    584     first=first->next;
     582  while (m_first)
     583  { i=m_first;
     584    m_first=m_first->next;
    585585    delete i;
    586586  }
     
    589589void InputManager::clear_current()
    590590{
    591     if(owner)
    592         m_surf = owner->m_surf;
    593     if(active)
    594         active->draw(0, m_surf);
    595     active = NULL;
     591    if(m_owner)
     592        m_surf = m_owner->m_surf;
     593    if(m_active)
     594        m_active->draw(0, m_surf);
     595    m_active = NULL;
    596596}
    597597
     
    601601  int x1,y1,x2,y2;
    602602
    603   if(owner)
    604       m_surf = owner->m_surf;
     603  if(m_owner)
     604      m_surf = m_owner->m_surf;
    605605
    606606  if (j)
     
    608608    ev.mouse_move.x-=j->x;
    609609    ev.mouse_move.y-=j->y;
    610     cur=j;
    611   }
    612 
    613   if (!grab)
     610    m_cur=j;
     611  }
     612
     613  if (!m_grab)
    614614  {
    615615    if ((ev.type==EV_MOUSE_BUTTON && ev.mouse_button==1) || ev.type==EV_MOUSE_MOVE)
    616616    {
    617       for (i=first; i; i=i->next)
     617      for (i=m_first; i; i=i->next)
    618618      {
    619619    i->area(x1,y1,x2,y2);
     
    622622        in_area=i;
    623623      }
    624       if (in_area!=active && (no_selections_allowed || (in_area && in_area->selectable())))
     624      if (in_area!=m_active && (no_selections_allowed || (in_area && in_area->selectable())))
    625625      {
    626     if (active)
    627           active->draw(0,m_surf);
    628 
    629     active=in_area;
    630 
    631     if (active)
    632       active->draw(1,m_surf);
     626    if (m_active)
     627          m_active->draw(0,m_surf);
     628
     629    m_active=in_area;
     630
     631    if (m_active)
     632      m_active->draw(1,m_surf);
    633633      }
    634634    }
    635     if (ev.type==EV_KEY && ev.key==JK_TAB && active)
    636     {
    637       active->draw(0,m_surf);
     635    if (ev.type==EV_KEY && ev.key==JK_TAB && m_active)
     636    {
     637      m_active->draw(0,m_surf);
    638638      do
    639639      {
    640     active=active->next;
    641     if (!active) active=first;
    642       } while (active && !active->selectable());
    643       active->draw(1,m_surf);
    644     }
    645   } else active=grab;
    646 
    647   if (active)
     640    m_active=m_active->next;
     641    if (!m_active) m_active=m_first;
     642      } while (m_active && !m_active->selectable());
     643      m_active->draw(1,m_surf);
     644    }
     645  } else m_active=m_grab;
     646
     647  if (m_active)
    648648  {
    649649    if (ev.type!=EV_MOUSE_MOVE && ev.type!=EV_MOUSE_BUTTON)
    650       active->handle_event(ev,m_surf,this);
     650      m_active->handle_event(ev,m_surf,this);
    651651    else
    652652    {
    653       active->area(x1,y1,x2,y2);
    654       if (grab || (ev.mouse_move.x>=x1 && ev.mouse_move.y>=y1 &&
     653      m_active->area(x1,y1,x2,y2);
     654      if (m_grab || (ev.mouse_move.x>=x1 && ev.mouse_move.y>=y1 &&
    655655          ev.mouse_move.x<=x2 && ev.mouse_move.y<=y2))
    656656      {
    657657    if (j)
    658       active->handle_event(ev,m_surf,j->inm);
    659     else active->handle_event(ev,m_surf,this);
     658      m_active->handle_event(ev,m_surf,j->inm);
     659    else m_active->handle_event(ev,m_surf,this);
    660660      }
    661661    }
     
    671671void InputManager::allow_no_selections()
    672672{
    673   no_selections_allowed=1;
     673    no_selections_allowed=1;
    674674}
    675675
     
    677677{
    678678    ifield *i;
    679     if(owner)
    680         m_surf = owner->m_surf;
    681     for(i = first; i; i = i->next)
     679    if(m_owner)
     680        m_surf = m_owner->m_surf;
     681    for(i = m_first; i; i = i->next)
    682682        i->draw_first(m_surf);
    683     if(active)
    684         active->draw(1, m_surf);
    685 }
    686 
    687 InputManager::InputManager(image *screen, ifield *First)
     683    if(m_active)
     684        m_active->draw(1, m_surf);
     685}
     686
     687InputManager::InputManager(image *screen, ifield *first)
    688688{
    689689    no_selections_allowed = 0;
    690     cur = NULL;
    691     grab = NULL;
    692     owner = NULL;
     690    m_cur = NULL;
     691    m_grab = NULL;
     692    m_owner = NULL;
    693693    m_surf = screen;
    694     active = first = First;
    695     while(active && !active->selectable())
    696         active = active->next;
     694    m_active = m_first = first;
     695    while(m_active && !m_active->selectable())
     696        m_active = m_active->next;
    697697    if(m_surf)
    698698        redraw();
    699699}
    700700
    701 InputManager::InputManager(Jwindow *Owner, ifield *First)
     701InputManager::InputManager(Jwindow *owner, ifield *first)
    702702{
    703703    no_selections_allowed = 0;
    704     cur = NULL;
    705     grab = NULL;
    706     owner = Owner;
     704    m_cur = NULL;
     705    m_grab = NULL;
     706    m_owner = owner;
    707707    m_surf = NULL;
    708     active = first = First;
    709     while(active && !active->selectable())
    710         active = active->next;
     708    m_active = m_first = first;
     709    while(m_active && !m_active->selectable())
     710        m_active = m_active->next;
    711711}
    712712
    713713void InputManager::grab_focus(ifield *i)
    714 { grab=i;
    715   if (cur)
    716     wm->grab_focus(cur);
     714{
     715    m_grab = i;
     716    if (m_cur)
     717        wm->grab_focus(m_cur);
    717718}
    718719
    719720void InputManager::release_focus()
    720 { grab=NULL;
    721   if (cur)
    722     wm->release_focus();
     721{
     722    m_grab = NULL;
     723    if (m_cur)
     724        wm->release_focus();
    723725}
    724726
    725727void InputManager::remap(Filter *f)
    726728{
    727   for (ifield *i=first; i; i=i->next)
    728    i->remap(f);
    729   redraw();
     729    for (ifield *i = m_first; i; i = i->next)
     730        i->remap(f);
     731    redraw();
    730732}
    731733
    732734void InputManager::add(ifield *i)
    733 { ifield *f=first;
     735{ ifield *f=m_first;
    734736  if (i->selectable())
    735737  {
    736738    if (!f)
    737       first=i;
     739      m_first=i;
    738740    else
    739741    {
     
    747749{
    748750  ifield *f;
    749   for (f=first; f; f=f->next)
     751  for (f=m_first; f; f=f->next)
    750752  {
    751753    ifield *ret=f->find(id);
  • abuse/trunk/src/imlib/jwindow.h

    r644 r649  
    4343    void add(ifield *i);
    4444    void remap(Filter *f);
    45     ifield *unlink(int id);     // unlinks ID from fields list and return the pointer to it
     45    ifield *unlink(int id); // unlink ID from list and return field pointer
    4646    void clear_current();
    4747    void grab_focus(ifield *i);
     
    5151private:
    5252    image *m_surf;
    53     ifield *first, *active, *grab;
    54     Jwindow *cur, *owner;
     53    ifield *m_first, *m_active, *m_grab;
     54    Jwindow *m_cur, *m_owner;
    5555    int no_selections_allowed;
    5656};
     
    147147    ~WindowManager();
    148148
    149     Jwindow *first, *grab;
     149    Jwindow *m_first, *m_grab;
    150150    image *mouse_pic, *mouse_save;
    151151    int hi, med, low, bk; // bright, medium, dark and black colors
Note: See TracChangeset for help on using the changeset viewer.