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

📄 gui.inc

📁 著名的游戏开发库Allegro4.2.0 for DELPHI
💻 INC
字号:
{*         ______   ___    ___
 *        /\  _  \ /\_ \  /\_ \
 *        \ \ \L\ \\//\ \ \//\ \      __     __   _ __   ___
 *         \ \  __ \ \ \ \  \ \ \   /'__`\ /'_ `\/\`'__\/ __`\
 *          \ \ \/\ \ \_\ \_ \_\ \_/\  __//\ \L\ \ \ \//\ \L\ \
 *           \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
 *            \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
 *                                           /\____/
 *                                           \_/__/
 *
 *      GUI routines.
 *
 *      By Shawn Hargreaves.
 *
 *      See readme.txt for copyright information.
 *}
{$IFDEF ALLEGRO_INTERFACE}

type
  P_DIALOG = ^DIALOG;

  P_DIALOG_PROC = ^DIALOG_PROC;
  DIALOG_PROC = function(msg: sint32; d: P_DIALOG; c: sint32): sint32; cdecl;

  DIALOG = record
    proc          : DIALOG_PROC;
    x, y, w, h    : sint32;           // position and size of the object
    fg, bg        : sint32;           // foreground and background colors
    key           : sint32;           // keyboard shortcut (ASCII code)
    flags         : sint32;           // flags about the object state
    d1, d2        : sint32;           // any data the object might require
    dp, dp2, dp3  : Pointer;          // pointers to more object data
  end;

  guiproc_ptr = function: sint32; cdecl;
  // a popup menu
  P_MENU = ^MENU;
  MENU = record
    text          : PChar;            // menu item text
    proc          : guiproc_ptr;      // callback function
    child         : P_MENU;           // to allow nested menus
    flags         : sint32;           // flags about the menu state
    dp            : Pointer;          // any data the menu might require
  end;

  // stored information about the state of an active GUI dialog
  P_DIALOG_PLAYER = ^DIALOG_PLAYER;
  DIALOG_PLAYER = record
    obj         : sint32;
    res         : sint32;
    mouse_obj   : sint32;
    focus_obj   : sint32;
    joy_on      : sint32;
    click_wait  : sint32;
    mouse_ox    : sint32;
    mouse_oy    : sint32;
    mouse_oz    : sint32;
    mouse_b     : sint32;
    dialog      : P_DIALOG;
  end;

  // stored information about the state of an active GUI menu */
  P_MENU_PLAYER = ^MENU_PLAYER;
  MENU_PLAYER = record
    menu                     : P_MENU;     // the menu itself
    bar                      : sint32;     // set if it is a top level menu bar
    size                     : sint32;     // number of items in the menu
    sel                      : sint32;     // selected item
    x, y, w, h               : sint32;     // screen position of the menu
    proc                     : guiproc_ptr; // callback function
    saved                    : P_BITMAP;   // saved what was underneath it

    mouse_button_was_pressed : sint32;     // set if mouse button pressed on last iteration
    back_from_child          : sint32;     // set if a child was activated on last iteration
    timestamp                : sint32;     // timestamp for gui_timer events
    mouse_sel                : sint32;     // item the mouse is currently over
    redraw                   : sint32;     // set if redrawing is required
    auto_open                : sint32;     // set if menu auto-opening is activated
    ret                      : sint32;     // return value

    dialog                   : P_DIALOG;   // d_menu_proc() parent dialog (if any)

    parent                   : P_MENU_PLAYER; // the parent menu, or NULL for root
    child                    : P_MENU_PLAYER; // the child menu, or NULL for none
  end;


const
  // bits for the flags field
  D_EXIT                     = 1;        // object makes the dialog exit
  D_SELECTED                 = 2;        // object is selected
  D_GOTFOCUS                 = 4;        // object has the input focus
  D_GOTMOUSE                 = 8;        // mouse is on top of object
  D_HIDDEN                   = 16;       // object is not visible
  D_DISABLED                 = 32;       // object is visible but inactive
  D_DIRTY                    = 64;       // object needs to be redrawn
  D_INTERNAL                 = 128;      // reserved for internal use
  D_USER                     = 256;      // from here on is free for your own use

  // return values for the dialog procedures
  D_O_K          = 0;        // normal exit status
  D_CLOSE        = 1;        // request to close the dialog
  D_REDRAW       = 2;        // request to redraw the dialog
  D_REDRAWME     = 4;        // request to redraw this object
  D_WANTFOCUS    = 8;        // this object wants the input focus
  D_USED_CHAR    = 16;       // object has used the keypress
  D_REDRAW_ALL   = 32;       // request to redraw all active dialogs
  D_DONTWANTMOUSE = 64;      // this object does not want mouse focus


  // messages for the dialog procedures
  MSG_START      = 1;        // start the dialog, initialise
  MSG_END        = 2;        // dialog is finished - cleanup
  MSG_DRAW       = 3;        // draw the object
  MSG_CLICK      = 4;        // mouse click on the object
  MSG_DCLICK     = 5;        // double click on the object
  MSG_KEY        = 6;        // keyboard shortcut
  MSG_CHAR       = 7;        // other keyboard input
  MSG_UCHAR      = 8;        // unicode keyboard input
  MSG_XCHAR      = 9;        // broadcast character to all objects
  MSG_WANTFOCUS  = 10;       // does object want the input focus?
  MSG_GOTFOCUS   = 11;       // got the input focus
  MSG_LOSTFOCUS  = 12;       // lost the input focus
  MSG_GOTMOUSE   = 13;       // mouse on top of object
  MSG_LOSTMOUSE  = 14;       // mouse moved away from object
  MSG_IDLE       = 15;       // update any background stuff
  MSG_RADIO      = 16;       // clear radio buttons
  MSG_WHEEL      = 17;       // mouse wheel moved
  MSG_LPRESS     = 18;       // mouse left button pressed
  MSG_LRELEASE   = 19;       // mouse left button released
  MSG_MPRESS     = 20;       // mouse middle button pressed
  MSG_MRELEASE   = 21;       // mouse middle button released
  MSG_RPRESS     = 22;       // mouse right button pressed
  MSG_RRELEASE   = 23;       // mouse right button released
  MSG_WANTMOUSE  = 24;       // does object want the mouse?
  MSG_USER       = 25;       // from here on are free... 

type
  draw_menu_ptr = procedure (x, y, w, h: sint32); cdecl;
  draw_menu_item_ptr = procedure (m: P_MENU; x, y, w, h, bar, sel: sint32); cdecl;
  filter_ptr = function(card, w, h, color_depth: sint32): sint32; cdecl;

var
  // some dialog procedures
  d_yield_proc: function(msg: sint32; d: P_DIALOG; c: sint32): sint32; cdecl;
  d_clear_proc: function(msg: sint32; d: P_DIALOG; c: sint32): sint32; cdecl;
  d_box_proc: function(msg: sint32; d: P_DIALOG; c: sint32): sint32; cdecl;
  d_shadow_box_proc: function(msg: sint32; d: P_DIALOG; c: sint32): sint32; cdecl;
  d_bitmap_proc: function(msg: sint32; d: P_DIALOG; c: sint32): sint32; cdecl;
  d_text_proc: function(msg: sint32; d: P_DIALOG; c: sint32): sint32; cdecl;
  d_ctext_proc: function(msg: sint32; d: P_DIALOG; c: sint32): sint32; cdecl;
  d_rtext_proc: function(msg: sint32; d: P_DIALOG; c: sint32): sint32; cdecl;
  d_button_proc: function(msg: sint32; d: P_DIALOG; c: sint32): sint32; cdecl;
  d_check_proc: function(msg: sint32; d: P_DIALOG; c: sint32): sint32; cdecl;
  d_radio_proc: function(msg: sint32; d: P_DIALOG; c: sint32): sint32; cdecl;
  d_icon_proc: function(msg: sint32; d: P_DIALOG; c: sint32): sint32; cdecl;
  d_keyboard_proc: function(msg: sint32; d: P_DIALOG; c: sint32): sint32; cdecl;
  d_edit_proc: function(msg: sint32; d: P_DIALOG; c: sint32): sint32; cdecl;
  d_list_proc: function(msg: sint32; d: P_DIALOG; c: sint32): sint32; cdecl;
  d_text_list_proc: function(msg: sint32; d: P_DIALOG; c: sint32): sint32; cdecl;
  d_textbox_proc: function(msg: sint32; d: P_DIALOG; c: sint32): sint32; cdecl;
  d_slider_proc: function(msg: sint32; d: P_DIALOG; c: sint32): sint32; cdecl;
  d_menu_proc: function(msg: sint32; d: P_DIALOG; c: sint32): sint32; cdecl;

  gui_shadow_box_proc: P_DIALOG_PROC;
  gui_ctext_proc: P_DIALOG_PROC;
  gui_button_proc: P_DIALOG_PROC;
  gui_edit_proc: P_DIALOG_PROC;
  gui_list_proc: P_DIALOG_PROC;
  gui_text_list_proc: P_DIALOG_PROC;

  gui_menu_draw_menu: ^draw_menu_ptr;
  gui_menu_draw_menu_item: ^draw_menu_item_ptr;

  active_dialog: ^P_DIALOG;
  active_menu: ^P_MENU;

  gui_mouse_focus: p_sint32;

  gui_fg_color: p_sint32;
  gui_mg_color: p_sint32;
  gui_bg_color: p_sint32;

  gui_font_baseline: p_sint32;

  gui_mouse_x: ^guiproc_ptr;
  gui_mouse_y: ^guiproc_ptr;
  gui_mouse_z: ^guiproc_ptr;
  gui_mouse_b: ^guiproc_ptr;

  gui_set_screen: procedure(bmp: P_BITMAP); cdecl;
  gui_get_screen: function: P_BITMAP; cdecl;
  gui_textout_ex: function(bmp: P_BITMAP; const s: PChar; x, y, color, bg, centre: sint32): sint32; cdecl;
  gui_strlen: function(const s: PChar): sint32; cdecl;
  position_dialog: procedure(dialog: P_DIALOG; x, y: sint32); cdecl;
  centre_dialog: procedure(dialog: P_DIALOG); cdecl;
  set_dialog_color: procedure(dialog: P_DIALOG; fg, bg: sint32); cdecl;
  find_dialog_focus: function(dialog: P_DIALOG): sint32; cdecl;
  offer_focus: function(dialog: P_DIALOG; obj: sint32; focus_obj: p_sint32; force: sint32): sint32; cdecl;
  object_message: function(dialog: P_DIALOG; msg, c: sint32): sint32; cdecl;
  dialog_message: function(dialog: P_DIALOG; msg, c: sint32; obj: p_sint32): sint32; cdecl;
  broadcast_dialog_message: function(msg, c: sint32): sint32; cdecl;
  do_dialog: function(dialog: P_DIALOG; focus_obj: sint32): sint32; cdecl;
  popup_dialog: function(dialog: P_DIALOG; focus_obj: sint32): sint32; cdecl;
  init_dialog: function(dialog: P_DIALOG; focus_obj: sint32): P_DIALOG_PLAYER; cdecl;
  update_dialog: function(player: P_DIALOG_PLAYER): sint32; cdecl;
  shutdown_dialog: function(player: P_DIALOG_PLAYER): sint32; cdecl;
  do_menu: function(menu: P_MENU; x, y: sint32): sint32; cdecl;
  init_menu: function(menu: P_MENU; x, y: sint32): P_MENU_PLAYER; cdecl;
  update_menu: function(player: P_MENU_PLAYER): sint32; cdecl;
  shutdown_menu: function(player: P_MENU_PLAYER): sint32; cdecl;

  alert: function(const s1, s2, s3, b1, b2: PChar; c1, c2: sint32): sint32; cdecl;
  alert3: function(const s1, s2, s3, b1, b2, b3: PChar; c1, c2, c3: sint32): sint32; cdecl;

  file_select_ex: function(const messages: PChar; path: PChar; const ext: PChar; size, w, h: sint32): sint32; cdecl;

  gfx_mode_select: function(var card, w, h: sint32): sint32; cdecl;
  gfx_mode_select_ex: function(var card, w, h, color_depth: sint32): sint32; cdecl;
  gfx_mode_select_filter: function(var card, w, h, color_depth: sint32; filter: filter_ptr): sint32; cdecl;
{$ENDIF ALLEGRO_INTERFACE}
{$IFDEF ALLEGRO_IMPLEMENTATION}
{$ENDIF ALLEGRO_IMPLEMENTATION}
{$IFDEF ALLEGRO_LOADVARIABLE}
  d_yield_proc            := LoadDLL('d_yield_proc');
  d_clear_proc            := LoadDLL('d_clear_proc');
  d_box_proc              := LoadDLL('d_box_proc');
  d_shadow_box_proc       := LoadDLL('d_shadow_box_proc');
  d_bitmap_proc           := LoadDLL('d_bitmap_proc');
  d_text_proc             := LoadDLL('d_text_proc');
  d_ctext_proc            := LoadDLL('d_ctext_proc');
  d_rtext_proc            := LoadDLL('d_rtext_proc');
  d_button_proc           := LoadDLL('d_button_proc');
  d_check_proc            := LoadDLL('d_check_proc');
  d_radio_proc            := LoadDLL('d_radio_proc');
  d_icon_proc             := LoadDLL('d_icon_proc');
  d_keyboard_proc         := LoadDLL('d_keyboard_proc');
  d_edit_proc             := LoadDLL('d_edit_proc');
  d_list_proc             := LoadDLL('d_list_proc');
  d_text_list_proc        := LoadDLL('d_text_list_proc');
  d_textbox_proc          := LoadDLL('d_textbox_proc');
  d_slider_proc           := LoadDLL('d_slider_proc');
  d_menu_proc             := LoadDLL('d_menu_proc');
  gui_shadow_box_proc     := LoadDLL('gui_shadow_box_proc');
  gui_ctext_proc          := LoadDLL('gui_ctext_proc');
  gui_button_proc         := LoadDLL('gui_button_proc');
  gui_edit_proc           := LoadDLL('gui_edit_proc');
  gui_list_proc           := LoadDLL('gui_list_proc');
  gui_text_list_proc      := LoadDLL('gui_text_list_proc');
  gui_menu_draw_menu      := LoadDLL('gui_menu_draw_menu');
  gui_menu_draw_menu_item := LoadDLL('gui_menu_draw_menu_item');
  active_dialog           := LoadDLL('active_dialog');
  active_menu             := LoadDLL('active_menu');
  gui_mouse_focus         := LoadDLL('gui_mouse_focus');
  gui_fg_color            := LoadDLL('gui_fg_color');
  gui_mg_color            := LoadDLL('gui_mg_color');
  gui_bg_color            := LoadDLL('gui_bg_color');
  gui_font_baseline       := LoadDLL('gui_font_baseline');
  gui_mouse_x             := LoadDLL('gui_mouse_x');
  gui_mouse_y             := LoadDLL('gui_mouse_y');
  gui_mouse_z             := LoadDLL('gui_mouse_z');
  gui_mouse_b             := LoadDLL('gui_mouse_b');
  gui_set_screen          := LoadDLL('gui_set_screen');
  gui_get_screen          := LoadDLL('gui_get_screen');
  gui_textout_ex          := LoadDLL('gui_textout_ex');
  gui_strlen              := LoadDLL('gui_strlen');
  position_dialog         := LoadDLL('position_dialog');
  centre_dialog           := LoadDLL('centre_dialog');
  set_dialog_color        := LoadDLL('set_dialog_color');
  find_dialog_focus       := LoadDLL('find_dialog_focus');
  offer_focus             := LoadDLL('offer_focus');
  object_message          := LoadDLL('object_message');
  dialog_message          := LoadDLL('dialog_message');
  broadcast_dialog_message:= LoadDLL('broadcast_dialog_message');
  do_dialog               := LoadDLL('do_dialog');
  popup_dialog            := LoadDLL('popup_dialog');
  init_dialog             := LoadDLL('init_dialog');
  update_dialog           := LoadDLL('update_dialog');
  shutdown_dialog         := LoadDLL('shutdown_dialog');
  do_menu                 := LoadDLL('do_menu');
  init_menu               := LoadDLL('init_menu');
  update_menu             := LoadDLL('update_menu');
  shutdown_menu           := LoadDLL('shutdown_menu');
  alert                   := LoadDLL('alert');
  alert3                  := LoadDLL('alert3');
  file_select_ex          := LoadDLL('file_select_ex');
  gfx_mode_select         := LoadDLL('gfx_mode_select');
  gfx_mode_select_ex      := LoadDLL('gfx_mode_select_ex');
  gfx_mode_select_filter  := LoadDLL('gfx_mode_select_filter');
{$ENDIF ALLEGRO_LOADVARIABLE}

⌨️ 快捷键说明

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