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/input.cpp

    r56 r106  
    6060}
    6161
    62 void button_box::area(int &x1, int &y1, int &x2, int &y2, window_manager *wm)
     62void button_box::area(int &x1, int &y1, int &x2, int &y2)
    6363{
    6464  button *b=buttons;
     
    6666  else
    6767  {
    68     b->area(x1,y1,x2,y2,wm);
     68    b->area(x1,y1,x2,y2);
    6969    int xp1,yp1,xp2,yp2;
    7070    for (b=(button *)b->next;b;b=(button *)b->next)
    7171    {
    72       b->area(xp1,yp1,xp2,yp2,wm);
     72      b->area(xp1,yp1,xp2,yp2);
    7373      if (xp1<x1) x1=xp1;
    7474      if (xp2>x2) x2=xp2;
     
    7979}
    8080
    81 void button_box::draw_first(image *screen, window_manager *wm)
     81void button_box::draw_first(image *screen)
    8282{
    8383  for (button *b=buttons;b;b=(button *)b->next)
    84     b->draw_first(screen,wm);
    85 }
    86 
    87 void button_box::draw(int active, image *screen, window_manager *wm)
     84    b->draw_first(screen);
     85}
     86
     87void button_box::draw(int active, image *screen)
    8888{
    8989  return ;
     
    100100}
    101101
    102 void button_box::handle_event(event &ev, image *screen, window_manager *wm, input_manager *im)
     102void button_box::handle_event(event &ev, image *screen, input_manager *im)
    103103{
    104104  switch (ev.type)
     
    110110      for (button *b=buttons;!found && b;b=(button *)b->next)  // see if the user clicked on a button
    111111      {
    112         b->area(x1,y1,x2,y2,wm);
     112        b->area(x1,y1,x2,y2);
    113113        if (ev.mouse_move.x>=x1 && ev.mouse_move.x<=x2 &&
    114114            ev.mouse_move.y>=y1 && ev.mouse_move.y<=y2)
    115115        {
    116           b->handle_event(ev,screen,wm,im);
     116          b->handle_event(ev,screen,im);
    117117
    118118          int total=0;
     
    131131                  total--;
    132132                  b2->push();
    133                   b2->draw_first(screen,wm);
     133                  b2->draw_first(screen);
    134134                }
    135135            }
    136             b->draw_first(screen,wm);
     136            b->draw_first(screen);
    137137          } else if (total==0 && maxdown)
    138138            b->push();    // don't let the user de-press a button if non others are selected.     
     
    154154
    155155
    156 void button_box::arrange_left_right(window_manager *wm)
     156void button_box::arrange_left_right()
    157157{
    158158  button *b=buttons;
     
    160160  for (;b;b=(button *)b->next)
    161161  {
    162     b->area(x1,y1,x2,y2,wm);
     162    b->area(x1,y1,x2,y2);
    163163    b->x=x_on;
    164164    b->y=y;
     
    167167}
    168168
    169 void button_box::arrange_up_down(window_manager *wm)
     169void button_box::arrange_up_down()
    170170
    171171  button *b=buttons;
     
    173173  for (;b;b=(button *)b->next)
    174174  {
    175     b->area(x1,y1,x2,y2,wm);
     175    b->area(x1,y1,x2,y2);
    176176    b->y=y_on;
    177177    b->x=x;
     
    186186}
    187187
    188 void button::area(int &x1, int &y1, int &x2, int &y2, window_manager *wm)
     188void button::area(int &x1, int &y1, int &x2, int &y2)
    189189
    190190  x1=x; y1=y;
     
    237237
    238238void text_field::change_data(char const *new_data, int new_cursor, // cursor==-1, does not change it.
    239                              int active, image *screen, window_manager *wm)
     239                             int active, image *screen)
    240240{
    241241  if (strlen(format)<strlen(new_data))
     
    245245  if (new_cursor!=-1)
    246246    cur=new_cursor;
    247   draw_first(screen,wm);
    248   draw(active,screen,wm);
     247  draw_first(screen);
     248  draw(active,screen);
    249249}
    250250
     
    259259#endif
    260260
    261 void text_field::handle_event(event &ev, image *screen, window_manager *wm, input_manager *im)
     261void text_field::handle_event(event &ev, image *screen, input_manager *im)
    262262{
    263263  int xx;
     
    266266    switch (ev.key)
    267267    {
    268       case JK_LEFT : if (cur) { draw_cur(wm->dark_color(),screen,wm); cur--;
    269                            draw_cur(wm->bright_color(),screen,wm); } break;
    270       case JK_RIGHT : if (cur<(int)strlen(format)-1) { draw_cur(wm->dark_color(),screen,wm); cur++;
    271                            draw_cur(wm->bright_color(),screen,wm); } break;
     268      case JK_LEFT : if (cur) { draw_cur(wm->dark_color(),screen); cur--;
     269                           draw_cur(wm->bright_color(),screen); } break;
     270      case JK_RIGHT : if (cur<(int)strlen(format)-1) { draw_cur(wm->dark_color(),screen); cur++;
     271                           draw_cur(wm->bright_color(),screen); } break;
    272272      case JK_END : if (cur!=last_spot())
    273                           { draw_cur(wm->dark_color(),screen,wm); cur=last_spot();
     273                          { draw_cur(wm->dark_color(),screen); cur=last_spot();
    274274                            if (cur==(int)strlen(format)-1) cur--;
    275                            draw_cur(wm->bright_color(),screen,wm); } break;
     275                           draw_cur(wm->bright_color(),screen); } break;
    276276      case JK_HOME : if (cur)
    277                           { draw_cur(wm->dark_color(),screen,wm); cur=0;
    278                            draw_cur(wm->bright_color(),screen,wm); } break;
     277                          { draw_cur(wm->dark_color(),screen); cur=0;
     278                           draw_cur(wm->bright_color(),screen); } break;
    279279      case JK_BACKSPACE : if (cur)
    280          { draw_cur(wm->dark_color(),screen,wm); cur--;
     280         { draw_cur(wm->dark_color(),screen); cur--;
    281281           for (xx=cur;xx<(int)strlen(format)-1;xx++)
    282282             data[xx]=data[xx+1];
    283283           data[strlen(format)-1]=' ';
    284            draw_text(screen,wm);
    285            draw_cur(wm->bright_color(),screen,wm);
     284           draw_text(screen);
     285           draw_cur(wm->bright_color(),screen);
    286286           wm->push_event(new event(id,(char *)this));
    287287         } break;
    288288      default : if (ev.key>=' ' && ev.key<='~')
    289289         {
    290            draw_cur(wm->dark_color(),screen,wm);
     290           draw_cur(wm->dark_color(),screen);
    291291           for (xx=strlen(format)-1;xx>cur && xx>0;xx--)
    292292             data[xx]=data[xx-1];
     
    295295             cur++;
    296296           data[strlen(format)]=0;
    297            draw_text(screen,wm);
    298            draw_cur(wm->bright_color(),screen,wm);
     297           draw_text(screen);
     298           draw_cur(wm->bright_color(),screen);
    299299           wm->push_event(new event(id,(char *)this));
    300300         } break;
     
    307307#endif
    308308
    309 void text_field::draw(int active, image *screen, window_manager *wm)
     309void text_field::draw(int active, image *screen)
    310310{
    311311  if (active)
    312312  {
    313     screen->rectangle(xstart(wm),y,xend(wm),yend(wm),wm->bright_color());
    314     draw_cur(wm->bright_color(),screen,wm);
     313    screen->rectangle(xstart(),y,xend(),yend(),wm->bright_color());
     314    draw_cur(wm->bright_color(),screen);
    315315  }
    316316  else
    317317  {
    318     screen->rectangle(xstart(wm),y,xend(wm),yend(wm),wm->dark_color());
    319     draw_cur(wm->dark_color(),screen,wm);
    320   }
    321 }
    322 
    323 void text_field::area(int &x1, int &y1, int &x2, int &y2, window_manager *wm)
     318    screen->rectangle(xstart(),y,xend(),yend(),wm->dark_color());
     319    draw_cur(wm->dark_color(),screen);
     320  }
     321}
     322
     323void text_field::area(int &x1, int &y1, int &x2, int &y2)
    324324{
    325325  x1=x; y1=y;
    326   x2=xend(wm);
    327   y2=yend(wm);
     326  x2=xend();
     327  y2=yend();
    328328}
    329329
     
    361361{ up=!up; }
    362362
    363 void button::handle_event(event &ev, image *screen, window_manager *wm, input_manager *im)
     363void button::handle_event(event &ev, image *screen, input_manager *im)
    364364{
    365365  if ((ev.type==EV_KEY && ev.key==13) || (ev.type==EV_MOUSE_BUTTON &&
     
    367367  {
    368368    int  x1,y1,x2,y2;
    369     area(x1,y1,x2,y2,wm);
     369    area(x1,y1,x2,y2);
    370370    up=!up;
    371     draw_first(screen,wm);
    372     draw(act,screen,wm);
     371    draw_first(screen);
     372    draw(act,screen);
    373373    wm->push_event(new event(id,(char *)this));
    374374  }
    375375}
    376376
    377 void button::draw(int active, image *screen, window_manager *wm)
     377void button::draw(int active, image *screen)
    378378{
    379379  int x1,y1,x2,y2,color=(active ? wm->bright_color() : wm->medium_color()); 
    380   area(x1,y1,x2,y2,wm);
     380  area(x1,y1,x2,y2);
    381381  if (active!=act  && act_id!=-1 && active)
    382382    wm->push_event(new event(act_id,NULL));
     
    399399}
    400400
    401 void button::draw_first(image *screen, window_manager *wm)
     401void button::draw_first(image *screen)
    402402{
    403403  if (pressed) 
    404     draw(0,screen,wm);
     404    draw(0,screen);
    405405  else
    406406  {
    407407
    408408    int x1,y1,x2,y2;
    409     area(x1,y1,x2,y2,wm);
     409    area(x1,y1,x2,y2);
    410410   
    411411
     
    439439}
    440440
    441 void text_field::draw_first(image *screen, window_manager *wm)
     441void text_field::draw_first(image *screen)
    442442{
    443443  wm->font()->put_string(screen,x,y+3,prompt);
    444   screen->bar(xstart(wm),y,xend(wm),yend(wm),wm->dark_color());
    445   wm->font()->put_string(screen,xstart(wm)+1,y+3,data);
    446 }
    447 
    448 
    449 void text_field::draw_cur(int color, image *screen, window_manager *wm)
    450 {
    451   screen->bar(xstart(wm)+cur*wm->font()->width()+1,
    452                       yend(wm)-2,
    453                       xstart(wm)+(cur+1)*wm->font()->width(),
    454                       yend(wm)-1,color);
     444  screen->bar(xstart(),y,xend(),yend(),wm->dark_color());
     445  wm->font()->put_string(screen,xstart()+1,y+3,data);
     446}
     447
     448
     449void text_field::draw_cur(int color, image *screen)
     450{
     451  screen->bar(xstart()+cur*wm->font()->width()+1,
     452                      yend()-2,
     453                      xstart()+(cur+1)*wm->font()->width(),
     454                      yend()-1,color);
    455455}
    456456
     
    465465
    466466
    467 void info_field::area(int &x1, int &y1, int &x2, int &y2, window_manager *wm)
     467void info_field::area(int &x1, int &y1, int &x2, int &y2)
    468468{
    469469  if (w==-1)     // if we haven't calculated this yet
     
    509509}
    510510
    511 void info_field::draw_first(image *screen, window_manager *wm)
     511void info_field::draw_first(image *screen)
    512512{
    513513  put_para(screen,text,x+1,y+1,wm->font()->width(),wm->font()->height(),wm->font(),wm->black());
Note: See TracChangeset for help on using the changeset viewer.