Changeset 109


Ignore:
Timestamp:
Mar 15, 2008, 10:19:47 PM (10 years ago)
Author:
Sam Hocevar
Message:
  • Started cleaning up jwindow.cpp, preparing everything for future Abuse Win32 merges.
Location:
abuse/trunk/src/imlib
Files:
5 edited

Legend:

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

    r107 r109  
    8888{
    8989  return ;
     90}
     91
     92void button_box::move(int newx, int newy)
     93{
     94    for(button * b = buttons; b; b = (button *)b->next)
     95        b->move(newx + b->x, newy + b->y);
     96    x = newx;
     97    y = newy;
    9098}
    9199
  • abuse/trunk/src/imlib/input.hpp

    r106 r109  
    4343  button *buttons;
    4444  int maxdown;
    45   public :
     45public :
    4646  button_box(int X, int Y, int ID, int MaxDown, button *Buttons, ifield *Next);
    4747  void add_button(button *b);
    4848  void press_button(int id);      // if button box doesn't contain id, nothing happens
    4949  virtual void remap(filter *f);
     50  virtual void move(int newx, int newy);
    5051  virtual void area(int &x1, int &y1, int &x2, int &y2);
    5152  virtual void draw_first(image *screen);
  • abuse/trunk/src/imlib/jwindow.cpp

    r106 r109  
    2525int frame_right() { return jw_right; }
    2626
    27 ifield::~ifield() { ; }
    28 
    2927void set_frame_size(int x)
    3028
     
    7977  for (p=first;p;p=p->next)
    8078  {
    81     if (!p->property.hidden)
    82     {
    83       p->property.hidden=1;
     79    if (!p->is_hidden())
     80    {
     81      p->hide();
    8482      screen->add_dirty(p->x,p->y,p->x+p->l-1,p->y+p->h-1);
    8583    }
     
    9189  jwindow *p;
    9290  for (p=first;p;p=p->next)
    93     if (p->property.hidden)
     91    if (p->is_hidden())
    9492      show_window(p);     
    9593}
     
    110108  }
    111109  screen->add_dirty(j->x,j->y,j->x+j->l-1,j->y+j->h-1);
    112   j->property.hidden=1;
     110  j->hide();
    113111}
    114112
    115113void window_manager::show_window(jwindow *j)
    116114{
    117   if (j->property.hidden)
    118   {
    119     j->property.hidden=0;
     115  if (j->is_hidden())
     116  {
     117    j->show();
    120118    j->screen->add_dirty(0,0,j->l-1,j->h-1);
    121119  }
     
    134132  {
    135133    for (ev.window=NULL,j=first;j;j=j->next)
    136       if (!j->property.hidden && ev.mouse_move.x>=j->x && ev.mouse_move.y>=j->y &&
     134      if (!j->is_hidden() && ev.mouse_move.x>=j->x && ev.mouse_move.y>=j->y &&
    137135          ev.mouse_move.x<j->x+j->l && ev.mouse_move.y<j->y+j->h)
    138136        ev.window=j;
     
    149147      {
    150148        if (ev.mouse_move.x-ev.window->x<11) closew=1;
    151         else if (ev.window->property.moveable) movew=1;
     149        else if (ev.window->is_moveable()) movew=1;
    152150      } else if (grab)
    153151        ev.window=grab;
     
    276274 
    277275  jwindow *j=new jwindow(x,y,l,h,fields,Name),*k;
    278   j->property.hidden=0;
     276  j->show();
    279277  if (!first)
    280278    first=j;
     
    310308 
    311309  for (p=first;p;p=p->next)
    312     if (!p->property.hidden)
     310    if (!p->is_hidden())
    313311       screen->delete_dirty(p->x,p->y,p->x+p->l-1,p->y+p->h-1);
    314312  update_dirty(screen);
     
    320318  for (p=first;p;p=p->next)
    321319  {
    322     if (!p->property.hidden)
     320    if (!p->is_hidden())
    323321    {
    324322      if (has_mouse())
     
    334332//      screen->delete_dirty(p->x,p->y,p->x+p->l-1,p->y+p->h-1);
    335333      for (q=p->next;q;q=q->next)
    336         if (!q->property.hidden)
     334        if (!q->is_hidden())
    337335          p->screen->delete_dirty(q->x-p->x,
    338336                              q->y-p->y,
     
    346344}
    347345
    348 void jwindow::set_moveability(int x)
    349 {
    350   property.moveable=x;
    351 }
    352 
    353346jwindow::jwindow(int X, int Y, int L, int H, ifield *fields, char const *Name)
    354347{
    355   ifield *i;
    356   int x1,y1,x2,y2;
    357   l=0; h=0;
    358   property.moveable=1;
    359   if (fields)
    360     for (i=fields;i;i=i->next)
    361     {
    362       i->area(x1,y1,x2,y2);
    363       if ((int)y2>(int)h)
    364         h=y2+1;
    365       if ((int)x2>(int)l)
    366         l=x2+1;
    367     }
    368   else { l=2; h=2; }
    369 
    370   if (L<=0) { l=l-L; } else l=L+jw_left;
    371   if (H<=0) { h=h-H; } else h=H+jw_top;
    372 
    373  if (Y<0) y=yres-h+Y-WINDOW_FRAME_TOP-WINDOW_FRAME_BOTTOM-1; else y=Y;
    374  if (X<0) x=xres-l+X-WINDOW_FRAME_LEFT-WINDOW_FRAME_RIGHT-1; else x=X;
    375 
    376   backg=wm->medium_color();
    377   l+=WINDOW_FRAME_RIGHT; h+=WINDOW_FRAME_BOTTOM;
    378 //  if (!fields) { l+=WINDOW_FRAME_LEFT; h+=WINDOW_FRAME_TOP; }
    379 
    380   if (l<18) l=18;
    381   if (h<12) h=12;
    382   screen=new image(l,h,NULL,2);
    383   l=screen->width();
    384   h=screen->height();
    385   screen->clear(backg);
    386   next=NULL;
    387   inm=new input_manager(screen,fields);
    388   if (Name==NULL)
    389     name=strcpy((char *)jmalloc(strlen(" ")+1,"jwindow::window name")," "); 
    390   else
    391     name=strcpy((char *)jmalloc(strlen(Name)+1,"jwindow::window name"),Name);
    392 }
    393 
    394 void jwindow::local_close() { ; }
     348    ifield *i;
     349    int x1, y1, x2, y2;
     350
     351    l = 0; h = 0;
     352    hidden = false;
     353    moveable = true;
     354    if(fields)
     355        for(i = fields; i; i = i->next)
     356        {
     357            i->area(x1, y1, x2, y2);
     358            if ((int)y2 > (int)h)
     359                h = y2 + 1;
     360            if ((int)x2 > (int)l)
     361                l = x2 + 1;
     362        }
     363    else
     364    {
     365        l = 2;
     366        h = 2;
     367    }
     368
     369    l = L > 0 ? L + jw_left : l - L;
     370    l += WINDOW_FRAME_RIGHT;
     371    if(l < 18)
     372        l = 18;
     373    h = H > 0 ? H + jw_top : h - h;
     374    h += WINDOW_FRAME_BOTTOM;
     375    if(h < 12)
     376        h = 12;
     377    //if (!fields) { l+=WINDOW_FRAME_LEFT; h+=WINDOW_FRAME_TOP; }
     378    y = Y >= 0 ? Y : yres - h + Y - WINDOW_FRAME_TOP - WINDOW_FRAME_BOTTOM - 1;
     379    x = X >= 0 ? X : xres - l + X - WINDOW_FRAME_LEFT - WINDOW_FRAME_RIGHT - 1;
     380
     381    backg = wm->medium_color();
     382
     383    screen=new image(l,h,NULL,2);
     384    l = screen->width();
     385    h = screen->height();
     386    screen->clear(backg);
     387    next = NULL;
     388    inm = new input_manager(screen, fields);
     389    if(Name == NULL)
     390        name = strcpy((char *)jmalloc(strlen(" ") + 1, "jwindow::window name"), " "); 
     391    else
     392        name = strcpy((char *)jmalloc(strlen(Name) + 1, "jwindow::window name"), Name);
     393}
     394
     395void jwindow::local_close()
     396{
     397    ;
     398}
    395399
    396400void jwindow::redraw(int hi, int med, int low, JCFont *fnt)
     
    469473void input_manager::clear_current()
    470474{
    471   if (active)
    472     active->draw(0,screen);
    473 
    474   active=NULL;
     475    if(owner)
     476        screen = owner->screen;
     477    if(active)
     478        active->draw(0, screen);
     479    active = NULL;
    475480}
    476481
     
    479484  ifield *i,*in_area=NULL;
    480485  int x1,y1,x2,y2;
     486
     487  if(owner)
     488      screen = owner->screen;
     489
    481490  if (j)
    482491  {
     
    551560void input_manager::redraw()
    552561{
    553   ifield *i;
    554   for (i=first;i;i=i->next)
    555     i->draw_first(screen);
    556   if (active)
    557     active->draw(1,screen);
     562    ifield *i;
     563    if(owner)
     564        screen = owner->screen;
     565    for(i = first; i; i = i->next)
     566        i->draw_first(screen);
     567    if(active)
     568        active->draw(1, screen);
    558569}
    559570
    560571input_manager::input_manager(image *Screen, ifield *First)
    561572{
    562   no_selections_allowed=0;
    563   cur=NULL;
    564   grab=NULL;
    565   screen=Screen;
    566   active=first=First;
    567   while (active && !active->selectable()) active=active->next;
    568   redraw();
     573    no_selections_allowed = 0;
     574    cur = NULL;
     575    grab = NULL;
     576    owner = NULL;
     577    screen = Screen;
     578    active = first = First;
     579    while(active && !active->selectable())
     580        active = active->next;
     581    if(screen)
     582        redraw();
     583}
     584
     585input_manager::input_manager(jwindow *Owner, ifield *First)
     586{
     587    no_selections_allowed = 0;
     588    cur = NULL;
     589    grab = NULL;
     590    owner = Owner;
     591    screen = NULL;
     592    active = first = First;
     593    while(active && !active->selectable())
     594        active = active->next;
    569595}
    570596
     
    613639}
    614640
    615 
    616 
     641ifield::ifield()
     642{
     643    owner = NULL;
     644    x = 0;
     645    y = 0;
     646    next = NULL;
     647    id = 0;
     648}
     649
     650ifield::~ifield()
     651{
     652    ;
     653}
     654
     655/* re-position the control with respect to the "client" area of the window */
     656void ifield::set_owner(jwindow * newowner)
     657{
     658    if(owner)
     659        move(x - owner->x1(), y - owner->y1());
     660    owner = newowner;
     661    if(owner)
     662        move(x + owner->x1(), y + owner->y1());
     663}
     664
  • abuse/trunk/src/imlib/jwindow.hpp

    r106 r109  
    3333#define WINDOW_FRAME_RIGHT frame_right()
    3434
    35 
    3635class input_manager
    3736{
     37  friend class jwindow;
     38
     39private:
    3840  image *screen;
    39   ifield *first,*active,*grab;
    40   jwindow *cur;
     41  ifield *first, *active, *grab;
     42  jwindow *cur, *owner;
    4143  int no_selections_allowed;
    42 public :
     44
     45public:
    4346  input_manager(image *Screen, ifield *First);
     47  input_manager(jwindow *owner, ifield *First);
    4448  void handle_event(event &ev, jwindow *j);
    4549  ifield *get(int id);
     
    5862class ifield
    5963{
     64    friend class jwindow;
     65    friend class input_manager;
     66
     67protected:
     68    jwindow *owner;
     69
    6070public :
    61   int x,y;
     71    ifield();
     72    int x, y;
    6273
    63   int id;
    64   ifield *next;
    65   virtual void area(int &x1, int &y1, int &x2, int &y2) = 0;
    66   virtual void draw_first(image *screen)              = 0;
    67   virtual void draw(int active, image *screen)        = 0;
    68   virtual void handle_event(event &ev, image *screen, input_manager *im) = 0;
    69   virtual int selectable() { return 1; }
    70   virtual void remap(filter *f) { ; }
    71   virtual char *read() = 0;
    72   virtual ifield *find(int search_id) { if (id==search_id) return this; else return NULL; }
    73   virtual ifield *unlink(int id) { return NULL; }
    74   virtual ~ifield();
     74    int id;
     75    ifield *next;
     76    virtual void set_owner(jwindow *owner);
     77    virtual void move(int newx, int newy) { x = newx; y = newy; }
     78    virtual void area(int &x1, int &y1, int &x2, int &y2) = 0;
     79    virtual void draw_first(image *screen) = 0;
     80    virtual void draw(int active, image *screen) = 0;
     81    virtual void handle_event(event &ev, image *screen, input_manager *im) = 0;
     82    virtual int selectable() { return 1; }
     83    virtual void remap(filter *f) { ; }
     84    virtual char *read() = 0;
     85    virtual ifield *find(int search_id) { if (id==search_id) return this; else return NULL; }
     86    virtual ifield *unlink(int id) { return NULL; }
     87    virtual ~ifield();
    7588} ;
    7689
    7790struct jwindow_properties
    7891{
    79   uint8_t moveable,
    80           hidden;
    81 } ;
    82 
     92    bool moveable, hidden;
     93};
    8394
    8495class jwindow
    8596{
    86 public :
    87   jwindow_properties property;
    88   jwindow *next;
    89   char *name;
    90   int x,y,l,h,backg;
    91   image *screen;
    92   input_manager *inm;
    93   void *local_info;     // pointer to info block for local system (may support windows)
    94   jwindow(int X, int Y, int L, int H, ifield *fields, char const *Name=NULL);
    95   void redraw(int hi, int med, int low, JCFont *fnt);
    96   void resize(int L, int H);
    97   void clear(int color=0) { screen->bar(x1(),y1(),x2(),y2(),color); }
    98   int x1() { return WINDOW_FRAME_LEFT; }
    99   int y1() { return WINDOW_FRAME_TOP; }
    100   int x2() { return l-WINDOW_FRAME_RIGHT-1; }
    101   int y2() { return h-WINDOW_FRAME_BOTTOM-1; }
    102   void clip_in() { screen->set_clip(x1(),y1(),x2(),y2()); }
    103   void clip_out() { screen->set_clip(0,0,l-1,h-1); }
    104   char *read(int id) { return inm->get(id)->read(); } 
    105   void local_close();
    106   void set_moveability(int x);
    107   ~jwindow() { local_close(); delete screen; delete inm; jfree(name); }
     97    friend class input_manager;
     98
     99private:
     100    bool hidden;
     101    bool moveable;
     102
     103protected:
     104    jwindow *owner;
     105
     106public:
     107    jwindow *next;
     108    char *name;
     109    int x, y, l, h, backg;
     110    image *screen;
     111    input_manager *inm;
     112    void *local_info;  // pointer to info block for local system (may support windows)
     113    jwindow(int X, int Y, int L, int H, ifield *fields, char const *Name = NULL);
     114    void redraw(int hi, int med, int low, JCFont *fnt);
     115    void resize(int L, int H);
     116    void clear(int color = 0) { screen->bar(x1(), y1(), x2(), y2(), color); }
     117    void show() { hidden = false; }
     118    void hide() { hidden = true; }
     119    bool is_hidden() { return hidden; }
     120    void freeze() { moveable = false; }
     121    void thaw() { moveable = true; }
     122    bool is_moveable() { return moveable; }
     123    int x1() { return WINDOW_FRAME_LEFT; }
     124    int y1() { return WINDOW_FRAME_TOP; }
     125    int x2() { return l-WINDOW_FRAME_RIGHT-1; }
     126    int y2() { return h-WINDOW_FRAME_BOTTOM-1; }
     127    void clip_in() { screen->set_clip(x1(),y1(),x2(),y2()); }
     128    void clip_out() { screen->set_clip(0,0,l-1,h-1); }
     129    char *read(int id) { return inm->get(id)->read(); } 
     130    void local_close();
     131    ~jwindow() { local_close(); delete screen; delete inm; jfree(name); }
    108132} ;
    109133
    110134class window_manager
    111135{
    112 public :
     136  friend class jwindow;
     137
     138public:
    113139  event_handler *eh;
    114140  jwindow *first,*grab;
  • abuse/trunk/src/imlib/pmenu.cpp

    r106 r109  
    3131  bar=wm->new_window(X,Y,w-WINDOW_FRAME_LEFT-WINDOW_FRAME_RIGHT,
    3232                     h-WINDOW_FRAME_TOP-WINDOW_FRAME_BOTTOM,NULL);
    33   bar->set_moveability(0);  // can't drag this window
     33  bar->freeze();  // can't drag this window
    3434  bar->screen->wiget_bar(0,0,w-1,h-1,wm->bright_color(),wm->medium_color(),
    3535                    wm->dark_color());
     
    197197                     w-WINDOW_FRAME_LEFT-WINDOW_FRAME_RIGHT,
    198198                     h-WINDOW_FRAME_TOP-WINDOW_FRAME_BOTTOM,NULL);
    199   win->set_moveability(0);
     199  win->freeze();
    200200  win->screen->wiget_bar(0,0,w-1,h-1,wm->bright_color(),wm->medium_color(),wm->dark_color());
    201201
Note: See TracChangeset for help on using the changeset viewer.