⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 menus.c

📁 SEAL是DOS 下的32位保护模式的GUI程序
💻 C
📖 第 1 页 / 共 3 页
字号:
                  i != o->menu->current || !o->inside )  { /* not selected item */

               vo->background(vo, out, rect_move(r, p.x, p.y));
               if ( !i->enable ) /* disabled item */
                 fcolor = color_3d_light;

            } else

            { /* selected item */

               fcolor = color_menu_selected_text;

               vo->background(vo, out, rect_move(r, p.x, p.y));
               fade_rect(out, r.a.x+p.x+1, r.a.y+p.y, r.b.x+p.x-1, r.b.y+p.y, color_menu_selected_face, color_menu_selected_face_gardient, FR_HOR);

               if ( !i->enable ) /* disabled item */
                 fcolor = color_3d_shadow;

            };

            if ( !i->message || i->submenu ) { /* it's sub-menu item */

               textout_draw_rect(out, get_font_in_size("Symbols", 10, 10), "b", -1,
                                 t.a.x+p.x, t.a.y+p.y, t.b.x+p.x-8, t.b.y+p.y,
                                 TX_ALIGN_CENTERY|TX_ALIGN_RIGHT, fcolor, TX_NOCOLOR, 0);
            };

            if ( i->flags & MIF_CHECKOK ) { /* draw ok item */

               textout_draw_rect(out, get_font_in_size("Symbols", 12, 12), "O", -1,
                                 f.a.x+p.x, f.a.y+p.y, f.b.x+p.x, f.b.y+p.y,
                                 TX_ALIGN_CENTER, fcolor, TX_NOCOLOR, 0);

            } else

            if ( i->icon ) { /* draw icon if some is occurs */

               l_rect dy = (rect_sizey(f)-icon_size(o))/2;
               l_rect dx = (rect_sizex(f)-icon_size(o))/2;

               stretch_sprite(out, i->icon, f.a.x+p.x+dx, f.a.y+p.y+dy, icon_size(o), icon_size(o));

            } else

            if ( i->font_symbol && i->char_symbol > 0 ) { /* if some symbol before text */

               l_char s[2] = {0, '\0'};
               s[0] = i->char_symbol;

               textout_draw_rect(out, i->font_symbol, s, -1,
                                 f.a.x+p.x, f.a.y+p.y, f.b.x, f.b.y+p.y,
                                 TX_ALIGN_CENTER, fcolor, TX_NOCOLOR, 0);
            };


            if ( i->param ) { /* print param of item f.e. : ALT+X ... */


               textout_draw_rect(out, i->font, i->param, -1, t.a.x+p.x, t.a.y+p.y,
                                 t.b.x+p.x-8, t.b.y+p.y, TX_ALIGN_CENTERY|TX_ALIGN_RIGHT, fcolor, TX_NOCOLOR, 0);

            };


            /* print name of item */

            textout_draw_rect(out, i->font, i->name, -1, t.a.x+p.x, t.a.y+p.y,
                              t.b.x+p.x, t.b.y+p.y, TX_ALIGN_CENTERY|TX_ALIGN_LEFT, fcolor, TX_NOCOLOR, 0);
            if ( !i->enable ) /* disable item */
              if ( !o->is_one_of_subs_state(o, OB_SF_SELECTED) ||
                  i != o->menu->current || !o->inside )
              textout_draw_rect(out, i->font, i->name, -1, t.a.x+p.x-1, t.a.y+p.y-1,
                                t.b.x+p.x-1, t.b.y+p.y-1, TX_ALIGN_CENTERY|TX_ALIGN_LEFT, color_3d_shadow, TX_NOCOLOR, 0);

          }; /* end of item or sub-menu drawing */
       };

    };

  };

};


void  menuview_draw_item ( p_menuview o, p_menuitem item )
{

  p_menuitem i = item;

  if ( i ) {

    t_rect r = o->get_item_box(o, item);

    if ( !rect_check_empty(r) ) {

       p_view  vo = VIEW(o);
       t_point p;
       BITMAP *out;

       t_rect safe = rect_assign(r.a.x, r.a.y, r.b.x, r.b.y);

       out = vo->begin_paint(vo, &p, safe);

       if ( out ) {

         menuview_draw_item_ex(o,i,out,p);

       };

       vo->end_of_paint(vo, safe);

    };

  };

};


void        menuview_draw_current_item ( p_menuview o )
{

  if ( o->menu )

     o->draw_item(o, o->menu->current);
};


t_rect  menuview_get_item_box_ex ( p_menuview o, p_menuitem item, t_rect r )
{

  p_menuitem i = o->menu?o->menu->items:NULL;

  t_rect     s   = VIEW(o)->size_limits(VIEW(o));
  t_rect     sr  = r;
  l_int      hy  = 0;
  l_int      dy  = 0;

  while ( i && i != item ) {

    dy = s.a.y-sr.a.y;

    if ( i->name ) /* if item or sub-menu */

      r.a.y += o->item_size;

    else /* if line */

      r.a.y += STANDARD_MENULINE_SIZE+1;

    i = i->next;

    if ( !i ) /* last item */

       hy = sr.b.x-s.b.y;

  };

  if ( i )

    if ( i->name )

       return rect_assign(r.a.x, r.a.y+dy, r.b.x, r.a.y+dy+o->item_size+hy);

    else /* return line */

       return rect_assign(r.a.x, r.a.y+dy, r.b.x, r.a.y+dy+STANDARD_MENULINE_SIZE+hy);


  return rect_empty;

};


t_rect  menuview_get_item_box ( p_menuview o, p_menuitem item )
{

  return o->get_item_box_ex(o, item, VIEW(o)->size_limits(VIEW(o)));

};


t_rect  menuview_get_mouseitem_box ( p_menuview o, p_menuitem item )
{

  return o->get_item_box_ex(o, item, VIEW(o)->get_local_extent(VIEW(o)));

};


l_dword     menuview_run_new_menu ( p_menuview o, t_rect r, l_int *action, p_menu menu )
{

  l_dword msg = MSG_NOTHING;
  p_view  ow = VIEW(OBJECT(o)->owner_view(OBJECT(o)));

  if ( o && ow ) {

    p_object mv;

    o->sub_menu = MENUVIEW(menuview_init(MENUVIEW(_malloc(sizeof(t_menuview))),
                           r,
                           menu));

    mv = OBJECT(ow)->insert(OBJECT(ow), OBJECT(o->sub_menu));

    if ( mv ) {

       MENUVIEW(mv)->action = MA_IAMSUBMENU;
       MENUVIEW(mv)->parent_menu = o;

    };

    msg = ow->execute_view(ow, VIEW(mv));

    if ( action && mv ) *(action) = MENUVIEW(mv)->action;

    dispose(OBJECT(mv));

    o->sub_menu = NULL;

    MENUVIEW(o)->draw_current_item(MENUVIEW(o));

  };

  return msg;

};



/* horizontal menu */

l_dword     hormenu_execute ( p_object o )
{
   p_view vo = VIEW(o);
   p_menuview mo = MENUVIEW(o);

   l_int  action = MA_NONE;
   l_bool iamsub = false;
   l_bool autosub = false;
   l_dword message = MSG_NOTHING;

   p_menuitem current = mo->menu->current;

   if ( mo->action == MA_IAMSUBMENU ) iamsub = true;

   mo->inside = true;

   mo->draw_current_item(mo);

   do {

      action = MA_NONE;

      o->get_event(o, &event_main);

      if ( event_main.type & EV_KEYBOARD )
      {

         if ( OBJECT(keyb)->state & KB_SF_KEYDOWN ) {

         l_dword msg;

         switch ( keyb->code >> 8 ) {

           case KB_RIGHT :  current = mo->get_next_item(mo, current, true); break;
           case KB_LEFT  :  current = mo->get_next_item(mo, current, false); break;
           case KB_ESC   :  action = MA_ESC; break;
           case KB_ENTER :  action = MA_ENTER; break;
           case KB_DOWN  :  action = MA_SUBMENU; break;

         };

         msg = menu_get_hotkey_message(mo->top_menuview(mo)->menu, keyb->code);

         if ( msg != MSG_NOTHING ) {

             message = msg;
             action = MA_END;

         } else if ( KEYCTRL(KB_F1) ) /* help info */

                    _show_info_board(vo, current?current->info_text:NULL);

         };

      } else

      if ( event_main.type & EV_MOUSE ) {

         if ( OBJECT(mouse)->state & MO_SF_MOUSEPRESS ) {

           if ( vo->is_mouse_in_view(vo) ) { /* mouse is in view */

               p_menuitem cur = mo->get_item_from_mouse(mo, mouse->where);

               if ( cur ) current = cur;

               action = MA_SUBMENU;

           } else

           if ( OBJECT(mouse)->state & MO_SF_MOUSEDOWN )

              if ( !mo->is_mouse_in_one_of_parent_menu(mo, mouse->where) ) {

                 action = MA_END;

              };

        };

        if ( OBJECT(mouse)->state & MO_SF_MOUSEUP )  { /* */

           if ( vo->is_mouse_in_view(vo) ) /* mouse is in view */

              action = MA_ENTER;

        };

      };


      if ( current != mo->menu->current ) { /* redraw items */

         p_menuitem old_current = mo->menu->current;

         mo->menu->current = current; /* set current item */

         if ( old_current != mo->menu->current ) { /* check if not same */

           mo->draw_item(mo, old_current);
           mo->draw_item(mo, mo->menu->current);

           if ( autosub ) action = MA_SUBMENU;

         };

      };


      if ( current ) { /* is some item selected */


         if ( action == MA_ENTER && current->enable ) { /* action is command */

            if ( current->message || current->flags & MIF_CHECK ) { /* it's command item */

               action = MA_COMMAND;
               message = current->message;
               current->lastcall = true;

               if ( current->flags & MIF_CHECK )

                  if ( current->flags & MIF_CHECKOK ) current->flags &= ~MIF_CHECKOK;

                  else current->flags |= MIF_CHECKOK;

            } else  /* it's menu item */

               action = MA_SUBMENU;

         };

         if ( action == MA_SUBMENU || action == MA_FORWARD ) { /* make new sub-menu */

            if ( current->submenu ) { /* has some submenu */

               t_rect r = mo->get_item_box(mo, current);

               r.a.y = rect_sizey(vo->bounds);

               r = rect_move(r, vo->bounds.a.x, vo->bounds.a.y);

               message = mo->run_new_menu(mo, r, &action, current->submenu);

               if ( action == MA_OTHER ||      /* automatic sub-menu opening */
                    action == MA_BACKWARD ||
                    action == MA_HMFORWARD ) autosub = true; else autosub = false;

               if ( action == MA_BACKWARD ) /* key - left was pressed in sub-menu */

                  current = mo->get_next_item(mo, current, false); /* set to prev item */

               if ( action == MA_HMFORWARD ) /* key - right was pressed in sub-menu */

                  current = mo->get_next_item(mo, current, true); /* set to next item */

               if ( action == MA_ESC ) /* in sub-menu ESC so hor-menu is escaped too */

                  action = MA_END;

               if ( action == MA_HMFORWARD ||
                    action == MA_BACKWARD ||
                    action == MA_OTHER )  action = MA_NONE;

            };

         };

      };


      if ( action > 0 ) clear_event(&event_main);

   } while ( action > 0 );

   if ( action == MA_END ) o->put_event(o, &event_main);

   mo->action = action;

   mo->inside = false;

   return message;
};


void    hormenu_save_desktop ( p_menuview o )
{
};


t_rect  hormenu_get_item_box_ex ( p_menuview o, p_menuitem item, t_rect r )
{

  p_menuitem i = o->menu?o->menu->items:NULL;

  t_rect     s  = VIEW(o)->size_limits(VIEW(o));
  t_rect     sr  = r;
  l_int      wx = 0;
  l_int      dx = 0;

  while ( i && i != item ) {

    dx = s.a.x-sr.a.x;

    if ( i->name ) /* if item or sub-menu */

      r.a.x += FONT_GETSTRWIDTH(i->font, i->name, -1)+
               FONT_GETSTRWIDTH(i->font, i->param, -1)+
               icon_size(o)+5;

    else /* if line */

      r.a.x += STANDARD_MENULINE_WIDTH+1;

    if ( !i->next ) wx = sr.b.x-s.b.x;

    i = i->next;

  };

  if ( i )

    if ( i->name )

       return rect_assign(r.a.x+dx+8, r.a.y, r.a.x+FONT_GETSTRWIDTH(i->font, i->name, -1)+
                                                   FONT_GETSTRWIDTH(i->font, i->param, -1)+
                                                   icon_size(o)+5+dx+wx+8, r.b.y);

    else /* return line */

       return rect_assign(r.a.x+dx+8, r.a.y, r.a.x+dx+wx+8, r.b.y);


  return rect_empty;

};


void  hormenu_draw ( p_view o )
{
  t_rect  r = o->get_local_extent(o);
  t_point p;

  BITMAP *out = o->begin_paint(o, &p, r);

  if ( out ) {

    p_menuitem item = MENUVIEW(o)->menu?MENUVIEW(o)->menu->items:NULL;

    o->background(o, out, rect_move(r, p.x, p.y));
    //rectfill(out, r.a.x+p.x, r.a.y+p.y, r.b.x+p.x, r.b.y+p.y, o->get_color(o, 0));
    //button(out, r.a.x+p.x, r.a.y+p.y, r.b.x+p.x, r.b.y+p.y, color_3d_light, color_3d_shadow);
    //button(out, r.a.x+p.x+2, r.a.y+p.y+2, r.a.x+p.x+4, r.b.y+p.y-2, color_3d_light, color_3d_shadow);
    //button(out, r.a.x+p.x+5, r.a.y+p.y+2, r.a.x+p.x+7, r.b.y+p.y-2, color_3d_light, color_3d_shadow);

    while ( item ) {

      MENUVIEW(o)->draw_item(MENUVIEW(o), item);

      item = item->next;

    };

  };

  o->end_of_paint(o, r);
};


void  hormenu_draw_item ( p_menuview o, p_menuitem item )
{

  p_menuitem i = item;

  if ( i ) {

    t_rect r = o->get_item_box(o, item);

    if ( !rect_check_empty(r) ) {

       p_view  vo = VIEW(o);
       t_point p;
       BITMAP *out;
       t_rect  safe;
       int dawn = 0;

       safe = rect_assign(r.a.x, r.a.y, r.b.x, r.b.y);

       if ( i == o->menu->items ) /* is the first item ? */

          safe.a.x--;

       out = vo->begin_paint(vo, &p, r);

       if ( out ) {

          t_rect  t = rect_assign(r.a.x+o->between.x+2, r.a.y, r.b.x, r.b.y);
          t_rect  f = rect_assign(r.a.x, r.a.y, t.a.x, r.b.y);

          l_color fcolor = color_menu_text;

          if ( !i->name ) { /* draw LINE */

//            vo->background(vo, out, rect_move(r, p.x, p.y));
            rectfill(out, r.a.x+p.x, r.a.y+p.y, r.b.x+p.x, r.b.y+p.y, color_menu_face);
            //hline(out, r.a.x+p.x, r.a.y+p.y, r.b.x+p.x, color_3d_light);
            //hline(out, r.a.x+p.x, r.b.y+p.y, r.b.x+p.x, color_3d_shadow);

          } else { /* draw ITEM or SUB-MENU */


            if ( !o->is_one_of_subs_state(o, OB_SF_SELECTED) ||
                  item != o->menu->current || !o->inside ) /* not selected item */ {

//              vo->background(vo, out, rect_move(r, p.x, p.y));
            if (!use_skins) // OCR - 02/04/2002
               rectfill(out, r.a.x+p.x, r.a.y+p.y, r.b.x+p.x, r.b.y+p.y, color_menu_face);
            //hline(out, r.a.x+p.x, r.a.y+p.y, r.b.x+p.x, color_3d_light);
            //hline(out, r.a.x+p.x, r.b.y+p.y, r.b.x+p.x, color_3d_shadow);

            } else { /* selected item */

               rectfill(out, r.a.x+p.x, r.a.y+p.y, r.b.x+p.x, r.b.y+p.y, color_menu_face);
               //hline(out, r.a.x+p.x, r.a.y+p.y, r.b.x+p.x, color_3d_light);
               //hline(out, r.a.x+p.x, r.b.y+p.y, r.b.x+p.x, color_3d_shadow);
               button(out, r.a.x+p.x+1, r.a.y+p.y+1, r.b.x+p.x-1, r.b.y+p.y-1, color_3d_shadow, color_3d_light);
               dawn = 1;
            };

            if ( !i->enable ) /* disable item */

               fcolor = color_3d_shadow;


            if ( !i->message || i->submenu ) { /* it's sub-menu item */

//               textout_draw_rect(out, get_font_in_size("Symbols", 10, 10), "b", -1,
  //                               t.a.x+p.x, t.a.y+p.y, t.b.x+p.x-8, t.b.y+p.y,
    //                             TX_ALIGN_CENTERY|TX_ALIGN_RIGHT, fcolor, TX_NOCOLOR, 0);
            };

            if ( i->flags & MIF_CHECKOK ) { /* draw ok item */

  //             textout_draw_rect(out, get_font_in_size("Symbols", 12, 12), "O", -1,
//                                 f.a.x+p.x, f.a.y+p.y, f.b.x+p.x, f.b.y+p.y,
//                                 TX_ALIGN_CENTER, fcolor, TX_NOCOLOR, 0);

            } else

            if ( i->icon ) { /* draw icon if some is occurs */

               l_rect dy = (rect_sizey(f)-icon_size(o))/2;
               l_rect dx = (rect_sizex(f)-icon_size(o))/2;

//               stretch_sprite(out, i->icon, f.a.x+p.x+dx, f.a.y+p.y+dy, icon_size(o), icon_size(o));

            } else

            if ( i->font_symbol && i->char_symbol > 0 ) { /* if some symbol before text */

               l_char s[2] = {0, '\0'};
               s[0] = i->char_symbol;

               textout_draw_rect(out, i->font_symbol, s, -1,
                                 r.a.x+dawn, r.a.y+dawn, r.b.x+dawn, r.b.y+dawn,
                                 TX_ALIGN_CENTER, fcolor, TX_NOCOLOR, 0);
            };


            if ( i->param ) { /* print param of item f.e. : ALT+X ... */


//               textout_draw_rect(out, i->font, i->param, -1, t.a.x+p.x, t.a.y+p.y,
//                                 t.b.x+p.x-8, t.b.y+p.y, TX_ALIGN_CENTERY|TX_ALIGN_RIGHT, fcolor, TX_NOCOLOR, 0);

            };


            /* print name of item */

            textout_draw_rect(out, i->font, i->name, -1, t.a.x+p.x-12+dawn, t.a.y+p.y+dawn+5, t.b.x+p.x, t.b.y+p.y, TX_ALIGN_TOP|TX_ALIGN_LEFT, fcolor, TX_NOCOLOR, 0);

          }; /* end of item or sub-menu drawing */
       };

       vo->end_of_paint(vo, safe);

    };

  };

};


/* t_menu and t_menuitem functions */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -