Ignore:
Timestamp:
Mar 15, 2008, 12:55:44 AM (11 years ago)
Author:
Sam Hocevar
Message:
  • Rename the "eh" variable to "wm" because it's a window manager, not an event handler.
  • No longer pass the window manager to functions, there's only one.

Inspired by Win32 Abuse changelog for January 28, 2001:

  • Starting work on singleton code; will get rid of all

references to an arbitrary window_manager* because
there's only going to be one, and it's not ever
going to change.

File:
1 edited

Legend:

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

    r56 r106  
    1717}
    1818
    19 pmenu::pmenu(int X, int Y, pmenu_item *first, image *screen, window_manager *wmanager)
     19pmenu::pmenu(int X, int Y, pmenu_item *first, image *screen)
    2020{
    2121  top=first;
    2222  active=NULL;
    23   wm=wmanager;
    2423
    2524  short cx1,cy1,cx2,cy2;
     
    4645
    4746  for (p=top;p;p=p->next,tx+=tw)
    48     p->draw_self(bar,itemx(p,wm),1,itemw(p,wm),1,wm,p==active);     
     47    p->draw_self(bar,itemx(p),1,itemw(p),1,p==active);     
    4948/*  }
    5049  else
    5150  {
    5251    for (p=top;p;p=p->next,tx+=tw)
    53       p->draw(bar,itemx(p,wm),1,itemw(p,wm),1,wm,p==active);
     52      p->draw(bar,itemx(p),1,itemw(p),1,p==active);
    5453  }*/
    5554 
     
    139138
    140139
    141 void psub_menu::hide(jwindow *parent, int x, int y, window_manager* wm)
     140void psub_menu::hide(jwindow *parent, int x, int y)
    142141{
    143142  int w,h;
    144   calc_size(w,h,wm);
     143  calc_size(w,h);
    145144  short cx1,cy1,cx2,cy2;
    146145  screen->get_clip(cx1,cy1,cx2,cy2);
     
    154153    {
    155154      int w,h;
    156       calc_size(w,h,wm);
    157       item_num(active)->draw(win,x+3,y+3+active*(wm->font()->height()+1),w-6,0,wm,0);
     155      calc_size(w,h);
     156      item_num(active)->draw(win,x+3,y+3+active*(wm->font()->height()+1),w-6,0,0);
    158157    }
    159158    wm->close_window(win);
     
    162161}
    163162
    164 void psub_menu::calc_size(int &w, int &h, window_manager *wm)
     163void psub_menu::calc_size(int &w, int &h)
    165164{
    166165  int tw=wm->font()->width(),th=wm->font()->height();
     
    179178}
    180179
    181 void psub_menu::draw(jwindow *parent, int x, int y, window_manager *wmanager)
     180void psub_menu::draw(jwindow *parent, int x, int y)
    182181{
    183182  if (win) wm->close_window(win);
    184   wm=wmanager;
    185 
    186183
    187184  int w,h,i=0;
    188   calc_size(w,h,wm);
     185  calc_size(w,h);
    189186  short cx1,cy1,cx2,cy2;
    190187  screen->get_clip(cx1,cy1,cx2,cy2);
     
    210207 
    211208  for (p=first;p;p=p->next,i++,y+=wm->font()->height()+1)
    212     p->draw(win,x,y,w-6,0,wm,i==active);
    213 
    214 }
    215 
    216 void pmenu_item::draw_self(jwindow *parent, int x, int y, int w, int top, window_manager *wm, int active)
     209    p->draw(win,x,y,w-6,0,i==active);
     210
     211}
     212
     213void pmenu_item::draw_self(jwindow *parent, int x, int y, int w, int top, int active)
    217214{
    218215  int bx=x;
     
    250247
    251248void pmenu_item::draw(jwindow *parent, int x, int y, int w, int top,
    252                       window_manager *wm, int active)
     249                      int active)
    253250
    254251  if (n)
     
    256253    if (active)
    257254    {     
    258       draw_self(parent,x,y,w,top,wm,active);
     255      draw_self(parent,x,y,w,top,active);
    259256      if (sub)
    260257      {
    261258        if (top)
    262           sub->draw(parent,x,y+wm->font()->height()+2,wm);
     259          sub->draw(parent,x,y+wm->font()->height()+2);
    263260        else
    264           sub->draw(parent,x+w,y,wm);
     261          sub->draw(parent,x+w,y);
    265262      }
    266263    }
     
    270267      {
    271268        if (top)
    272           sub->hide(parent,x,y+wm->font()->height()+2,wm);
     269          sub->hide(parent,x,y+wm->font()->height()+2);
    273270        else
    274           sub->hide(parent,x+w,y,wm);
    275       }
    276       draw_self(parent,x,y,w,top,wm,active);
    277 
    278     }
    279 
    280   } else draw_self(parent,x,y,w,top,wm,active);
    281 }
    282 
    283 int pmenu::itemx(pmenu_item *p, window_manager *wm)
     271          sub->hide(parent,x+w,y);
     272      }
     273      draw_self(parent,x,y,w,top,active);
     274
     275    }
     276
     277  } else draw_self(parent,x,y,w,top,active);
     278}
     279
     280int pmenu::itemx(pmenu_item *p)
    284281{
    285282  if (p->xp!=-1) return p->xp;
     
    299296
    300297
    301 void pmenu::draw(image *screen, window_manager *wm, int top_only)
    302 {
    303 
    304 }
    305 
    306 
    307 int psub_menu::handle_event(jwindow *parent, int x, int y, window_manager *wm, event &ev)
     298void pmenu::draw(image *screen, int top_only)
     299{
     300
     301}
     302
     303
     304int psub_menu::handle_event(jwindow *parent, int x, int y, event &ev)
    308305{
    309306  int w,h;
    310   calc_size(w,h,wm);
     307  calc_size(w,h);
    311308  short cx1,cy1,cx2,cy2;
    312309  screen->get_clip(cx1,cy1,cx2,cy2);
     
    328325    {
    329326      if (active!=-1)
    330         item_num(active)->draw(win,dx,3+active*(th+1),w-6,0,wm,0);
     327        item_num(active)->draw(win,dx,3+active*(th+1),w-6,0,0);
    331328      active=new_active;
    332329      if (active!=-1)
    333         item_num(active)->draw(win,dx,3+active*(th+1),w-6,0,wm,1);
     330        item_num(active)->draw(win,dx,3+active*(th+1),w-6,0,1);
    334331    }
    335332    if (ev.type==EV_MOUSE_BUTTON)
    336333    {
    337334      if (active!=-1)
    338         return item_num(active)->handle_event(win,dx,3+active*(th+1),w-6,0,wm,ev);
     335        return item_num(active)->handle_event(win,dx,3+active*(th+1),w-6,0,ev);
    339336      else return 0;
    340337    } else return 1;
    341338  } else if (active!=-1)
    342     return item_num(active)->handle_event(win,win->x+dx,win->y+3+active*(th+1),w-6,0,wm,ev);
     339    return item_num(active)->handle_event(win,win->x+dx,win->y+3+active*(th+1),w-6,0,ev);
    343340  else return 0;
    344341
     
    347344
    348345int pmenu_item::handle_event(jwindow *parent, int x, int y, int w, int top,
    349                              window_manager *wm, event &ev)
     346                             event &ev)
    350347{
    351348  x+=parent->x;
     
    364361  {
    365362    if (top)
    366       return sub->handle_event(parent,x,y+wm->font()->height()+2,wm,ev);
    367     else return sub->handle_event(parent,x+w,y,wm,ev);
     363      return sub->handle_event(parent,x,y+wm->font()->height()+2,ev);
     364    else return sub->handle_event(parent,x+w,y,ev);
    368365  } else return 0;
    369366}
    370367
    371 pmenu_item *pmenu::inarea(int mx, int my, image *screen, window_manager *wm)
     368pmenu_item *pmenu::inarea(int mx, int my, image *screen)
    372369{
    373370  short cx1,cy1,cx2,cy2;
     
    381378    {
    382379      if (!p->next) return p;
    383       else if (itemx(p->next,wm)>mx) return p;
     380      else if (itemx(p->next)>mx) return p;
    384381    }
    385382    return NULL;
     
    407404}
    408405
    409 int pmenu::handle_event(event &ev, image *screen, window_manager *wm)
     406int pmenu::handle_event(event &ev, image *screen)
    410407{
    411408  if (!active && ev.window!=bar) return 0;
     
    438435    case EV_MOUSE_MOVE :
    439436    {
    440       pmenu_item *new_selection=inarea(ev.mouse_move.x,ev.mouse_move.y,screen,wm);
     437      pmenu_item *new_selection=inarea(ev.mouse_move.x,ev.mouse_move.y,screen);
    441438      if (!new_selection && active &&
    442           active->handle_event(bar,itemx(active,wm),1,itemw(active,wm),1,wm,ev))
     439          active->handle_event(bar,itemx(active),1,itemw(active),1,ev))
    443440        return 1;
    444441      else if (active!=new_selection)
    445442      {
    446443        if (active)
    447           active->draw(bar,itemx(active,wm),1,itemw(active,wm),1,wm,0);
     444          active->draw(bar,itemx(active),1,itemw(active),1,0);
    448445        active=new_selection;
    449446        if (active)
    450           active->draw(bar,itemx(active,wm),1,itemw(active,wm),1,wm,1);
     447          active->draw(bar,itemx(active),1,itemw(active),1,1);
    451448      }
    452449      if (active) return 1;
     
    457454      if (active)
    458455      {
    459         if (active->handle_event(bar,itemx(active,wm),1,itemw(active,wm),1,wm,ev))
     456        if (active->handle_event(bar,itemx(active),1,itemw(active),1,ev))
    460457        {
    461           active->draw(bar,itemx(active,wm),1,itemw(active,wm),1,wm,0);
     458          active->draw(bar,itemx(active),1,itemw(active),1,0);
    462459          active=NULL;
    463460          return 1;
Note: See TracChangeset for help on using the changeset viewer.