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

📄 window.c

📁 SEAL是DOS 下的32位保护模式的GUI程序
💻 C
📖 第 1 页 / 共 2 页
字号:

      /* check if mouse is in the caption */
      if (  m.x > r.a.x + 2 && m.x < r.b.x -2 && m.y > r.a.y + 2 && m.y < r.a.y + s.a.y -2 )
      {

           l_word dm = (VIEW(o)->is_top_view(VIEW(o)) && VIEW(o)->drag_mode & DM_DRAGCONTEXT)?DM_DRAGCONTEXT:0;

           /* move window */
           VIEW(o)->drag_view(VIEW(o), DM_DRAGMOVE+dm, event);

           /* clear event, now event->type is EV_NOTHING, etc... */
           clear_event(event);
      };

    } /*else

    // right mouse button was pressed
      if ( OBJECT(mouse)->state & MO_SF_MOUSERDOWN ) { // dragging

      l_word dm = (VIEW(o)->is_top_view(VIEW(o)) && VIEW(o)->drag_mode & DM_DRAGCONTEXT)?DM_DRAGCONTEXT:0;

      // move window
      VIEW(o)->drag_view(VIEW(o), DM_DRAGMOVE+dm, event);

      // clear event, now event->type is EV_NOTHING, etc...

      clear_event(event);

    };*/

  };


  /* event comes from keyboard */
  if ( event->type & EV_KEYBOARD ) { /* keyboard event */

    /* ALT+TAB was pressed */
    if ( keyb->code == TO_KEY(KB_TAB) ) { /* select next view */

        p_object v = NULL;

        /* exist preferable object */
        if ( o->prefer )

           /* find next object placed in window, that's selectable and visible */
           v = o->prefer->find_match_view(o->prefer, OB_SF_VISIBLE, OB_OF_SELECTABLE, true);

        /* clear event -> we want only one to make this */
  	     clear_event(event);

        /* select previous found object */
        if ( v ) v->select(v);

    };

    /* ALT+F4 was pressed */
    if ( keyb->code == TO_ALT(KB_F4) ) {

      /* ok.... we are going to close the window */
      set_event(event, EV_MESSAGE, MSG_CLOSE, o);
      /* set program queue to event -> start in the next process */
      o->put_event(o, event);
      /* current process clear */
      clear_event(event);

    };
  };

  if ( event->type & EV_MESSAGE ) { /* message event */

    switch ( event->message ) {

      /* messages MSG_OK, or MSG_CLOSE occured */
      case MSG_OK :
      case MSG_CLOSE : {

        if ( !o->is_state(o, OB_SF_MODAL) )
           /* done (hide) the window and free memory of the window and of all
              subobjects, see "object.h"
           */
           dispose(o);

        else
        /* if object is modal = others wait for ending this one.
           see "object.h" l_dword t_object.execute(t_object *) +
               "view.h" l_dword execute_view(t_view *, t_view *)
        */
           o->end_state = event->message;

        /* clear current process */

        clear_event(event);

      }; break;

    };
  };

};


/*
  draws window title. The default form of drawing will find in file "view.h"
*/
void  win_draw_title ( p_window o )
{

  t_rect  r = rect_assign(2, 2, rect_sizex(VIEW(o)->bounds)-2,
                          FONT_GETHEIGHT(VIEW(o)->font)+2);
  t_point p;

  /* start to draw in rect (r) and return delta (p.x,p.y) from 0,0 of the screen
     return output for the drawing ( default : t_view.draw_buffer - virtual_screen ).
     When last end_of_paint is called, it's drawn to t_view.draw_out ( screen )
  */
  BITMAP *out = VIEW(o)->begin_paint(VIEW(o), &p, r);

  if ( out ) {
//    /* get 4th color from the palette t_view.palette = window_passive_caption */
    l_color fcolor = color_window_pass_title_text;
//    /* get 2th color from the palette t_view.palette = window_passive_title */
    l_color bcolor = color_window_pass_title_face;
    l_color bcolorg = color_window_pass_title_face_gardient;
//    /* return formated text */
    //l_text  caption = set_format_text(NULL, "  %s  ", o->caption);
//
//    /* find the center of the title in (y) */
    l_int dy = (rect_sizey(r) - FONT_GETHEIGHT(VIEW(o)->font)) / 2;
//
//    /* window is selected ? */
    if ( OBJECT(o)->state & OB_SF_SELECTED ) {
//
//      /* get 2th color from the palette t_view.palette = window_active_title */
      fcolor = color_window_act_title_text;
//      /* get 1th color from the palette t_view.palette = window_active_caption */
      bcolor = color_window_act_title_face;
      bcolorg = color_window_act_title_face_gardient;
//
    };

    /* draw filled rectangle by the color (bcolor) ...see above */

    fade_rect(out, r.a.x+p.x, r.a.y+p.y, r.b.x+p.x, r.b.y+p.y, bcolor, bcolorg, FR_HOR);

    /* draw text by the font t_view.font, text (caption), length -1 = strlen, ... you know */
    textout_draw_rect(out, VIEW(o)->font, o->caption, -1, r.a.x+p.x, r.a.y+p.y+1,
                           r.b.x+p.x, r.b.y+p.y, TX_ALIGN_CENTER, fcolor, CO_NOCOLOR, 0);

    /* free memory last allocated by function set_format_text ...see above */
    //sf_free(caption);

  };

  /* end of drawing. if this is the last call of end_of_paint, it draws context to
     t_view.draw_out, from (out)... by default t_view.draw_buffer.
  */
  VIEW(o)->end_of_paint(VIEW(o), r);

};


/*
  init t_window class and return (o). (o) is previous allocated memory in size

  sizeof(t_window). (r) are bounds of the window ( where is placed ). (caption) is

  the title of the window. Please not use new memory for this title such by the

  function _strdup, becouse win_init function make it by the self. (flags) are flags of

  the window. These flags are used later ...in objects (t_appwin), what's inherited

  object from object t_window ( see app.h ).

  Example :

  t_rect   r   = rect_assign(100, 100, 300, 300);
  p_window win = win_init(_malloc(sizeof(t_window)), r, "Hello Mr. Stencl", 0);
  OBJECT(desktop)->insert(OBJECT(desktop), OBJECT(win));

  Insert new (win) to the (desktop) ...(for object (desktop) see program.h)

  ...you must use OBJECT(), becouse (insert) function is the function of the class

  t_object, and arguments are : (p_object own, p_object sub)
*/
p_window  _win_init ( p_window o, t_rect r, l_text caption, l_int flags )
{
  if ( !o ) return NULL;

  /* set memory of pointer to ZERO */
  clear_type(o, sizeof(t_window));

  /* call old initialization function */
  view_init(VIEW(o), r);

  /* object's declarations */

  OBJECT(o)->tag |= TAG_WINDOW;


  /* view's declarations */

  /* enable dragmove, and dragcontext only if move_window_context is set to non-zero
     in seal.ini file in section [optimalization]...see "view.h" function
     view_ini ( void )
  */
  VIEW(o)->drag_mode |=  DM_DRAGMOVE+drag_context_ok*DM_DRAGCONTEXT;
  VIEW(o)->draw_mode &= ~(DWM_CANTACCELMOVE*accel_moving_ok);


  /* window's declarations */

  /* allocate memory for (caption) and copy string from (caption) to new place */
  o->caption = (l_text)_strdup((char*)caption);

  o->flags = flags;


  /* object's functions */

  /* set old functions to new */
  OBJECT(o)->set_state = &win_set_state;
  OBJECT(o)->translate_event = &win_translate_event;
  OBJECT(o)->done = &win_done;

  /* view's functions */

  VIEW(o)->draw = &win_draw;
  VIEW(o)->size_limits = &win_size_limits;
  VIEW(o)->size_minimum = &win_size_minimum;
  VIEW(o)->set_mouse_cursor = &win_set_mouse_cursor;


  /* window functions */

  o->draw_title = &win_draw_title;


  /* function calling */

  /* object can be selected on the top */
  OBJECT(o)->set_options(OBJECT(o), OB_OF_TOPSELECT, true);

  /* set palette of the window from standard window palette */
//  VIEW(o)->set_palette(VIEW(o), pal_window);

  /* set font of "caption" to bold system font. declaration is in "driver.c" file */
  VIEW(o)->font = get_font_in_size("ARIAL",8,8);

  /* set background color of window to first palette (pal_window) color.
     this is used when function "t_view.background(t_view*, r)" is used in draw function.
  */
  VIEW(o)->brush.color = color_3d_face;

  return o;

};

⌨️ 快捷键说明

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