📄 gfx.inc
字号:
{* ______ ___ ___
* /\ _ \ /\_ \ /\_ \
* \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___
* \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\
* \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \
* \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
* \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
* /\____/
* \_/__/
*
* Graphics inline functions (generic C).
*
* By Shawn Hargreaves.
*
* See readme.txt for copyright information.
*}
{$IFDEF ALLEGRO_INTERFACE}
type
_BMP_BANK_SWITCHER = function(bmp: P_BITMAP; lyne: sint32): p_uint32s; cdecl;
_BMP_UNBANK_SWITCHER = procedure(bmp: P_BITMAP); cdecl;
function bmp_wirte_line(bmp: P_BITMAP; line: sint32): p_uint32s;
function bmp_read_line(bmp: P_BITMAP; line: sint32): p_uint32s;
procedure bmp_unwrite_line(bmp: P_BITMAP);
function is_windowed_mode: Boolean;
procedure clear_to_color(bmp: P_BITMAP; color: sint32);
function bitmap_color_depth(bmp: P_BITMAP): sint32;
function bitmap_mask_color(bmp: P_BITMAP): sint32;
function is_same_bitmap(bmp1, bmp2: P_BITMAP): Boolean;
function is_linear_bitmap(bmp: P_BITMAP): Boolean;
function is_planar_bitmap(bmp: P_BITMAP): Boolean;
function is_memory_bitmap(bmp: P_BITMAP): Boolean;
function is_screen_bitmap(bmp: P_BITMAP): Boolean;
function is_video_bitmap(bmp: P_BITMAP): Boolean;
function is_system_bitmap(bmp: P_BITMAP): Boolean;
function is_sub_bitmap(bmp: P_BITMAP): Boolean;
procedure acquire_bitmap(bmp: P_BITMAP);
procedure release_bitmap(bmp: P_BITMAP);
procedure acquire_screen;
procedure release_screen;
function is_inside_bitmap(bmp: P_BITMAP; x, y: sint32; clip: Boolean): Boolean;
procedure get_clip_rect(bmp: P_BITMAP; var x1, y1, x2, y2: sint32);
procedure set_clip_state(bmp: P_BITMAP; state: sint32);
function get_clip_state(bmp: P_BITMAP): sint32;
{$ENDIF ALLEGRO_INTERFACE}
{$IFDEF ALLEGRO_IMPLEMENTATION}
function bmp_wirte_line(bmp: P_BITMAP; line: sint32): p_uint32s;
var
switcher: _BMP_BANK_SWITCHER;
begin
switcher := bmp^.write_bank;
Result := switcher(bmp, line);
end;
function bmp_read_line(bmp: P_BITMAP; line: sint32): p_uint32s;
var
switcher: _BMP_BANK_SWITCHER;
begin
switcher := bmp^.read_bank;
Result := switcher(bmp, line);
end;
procedure bmp_unwrite_line(bmp: P_BITMAP);
var
switcher: _BMP_UNBANK_SWITCHER;
begin
switcher := bmp^.vtable^.unwrite_bank;
switcher(bmp);
end;
function is_windowed_mode: Boolean;
begin
assert(the_gfx_driver^ <> nil);
Result := the_gfx_driver^^.windowed <> 0;
end;
procedure clear_to_color(bmp: P_BITMAP; color: sint32);
begin
assert(bmp<> nil);
bmp^.vtable^.clear_to_color(bmp, color);
end;
function bitmap_color_depth(bmp: P_BITMAP): sint32;
begin
assert(bmp <> nil);
Result := bmp^.vtable^.color_depth;
end;
function bitmap_mask_color(bmp: P_BITMAP): sint32;
begin
assert(bmp <> nil);
Result := bmp^.vtable^.mask_color;
end;
function is_same_bitmap(bmp1, bmp2: P_BITMAP): Boolean;
var
m1, m2: uint32;
begin
if (bmp1 = nil) or (bmp2 = nil) then
begin
Result := False;
Exit;
end;
if bmp1 = bmp2 then
begin
Result := True;
Exit;
end;
m1 := bmp1^.id and BMP_ID_MASK;
m2 := bmp2^.id and BMP_ID_MASK;
Result := (m1 <> 0) and (m1 = m2);
end;
function is_linear_bitmap(bmp: P_BITMAP): Boolean;
begin
assert(bmp <> nil);
Result := (bmp^.id and BMP_ID_PLANAR) = 0;
end;
function is_planar_bitmap(bmp: P_BITMAP): Boolean;
begin
assert(bmp <> nil);
Result := (bmp^.id and BMP_ID_PLANAR) <> 0;
end;
function is_memory_bitmap(bmp: P_BITMAP): Boolean;
begin
assert(bmp <> nil);
Result := (bmp^.id and (BMP_ID_VIDEO or BMP_ID_SYSTEM)) = 0;
end;
function is_screen_bitmap(bmp: P_BITMAP): Boolean;
begin
assert(bmp <> nil);
Result := is_same_bitmap(bmp, screen^);
end;
function is_video_bitmap(bmp: P_BITMAP): Boolean;
begin
assert(bmp <> nil);
Result := (bmp^.id and BMP_ID_VIDEO) <> 0;
end;
function is_system_bitmap(bmp: P_BITMAP): Boolean;
begin
assert(bmp <> nil);
Result := (bmp^.id and BMP_ID_SYSTEM) <> 0;
end;
function is_sub_bitmap(bmp: P_BITMAP): Boolean;
begin
assert(bmp <> nil);
Result := (bmp^.id and BMP_ID_SUB) <> 0;
end;
procedure acquire_bitmap(bmp: P_BITMAP);
begin
assert(bmp <> nil);
if @bmp^.vtable^.acquire <> nil then
bmp^.vtable^.acquire(bmp);
end;
procedure release_bitmap(bmp: P_BITMAP);
begin
assert(bmp <> nil);
if @bmp^.vtable^.release <> nil then
bmp^.vtable^.release(bmp);
end;
procedure acquire_screen;
begin
acquire_bitmap(screen^);
end;
procedure release_screen;
begin
release_bitmap(screen^);
end;
function is_inside_bitmap(bmp: P_BITMAP; x, y: sint32; clip: Boolean): Boolean;
begin
assert(bmp <> nil);
if clip then
begin
if bmp^.clip <> 0 then // internal clipping is inclusive-exclusive
Result := (x >= bmp^.cl) and (y >= bmp^.ct) and (x < bmp^.cr) and (y < bmp^.cb)
else
Result := True;
end else
// bitmap dimensions are always non-negative
Result := (uint32(x) < uint32(bmp^.w)) and (uint32(y) < uint32(bmp^.h));
end;
procedure get_clip_rect(bmp: P_BITMAP; var x1, y1, x2, y2: sint32);
begin
assert(bmp <> nil);
// internal clipping is inclusive-exclusive
x1 := bmp^.cl;
y1 := bmp^.ct;
x2 := bmp^.cr - 1;
y2 := bmp^.cb - 1;
end;
procedure set_clip_state(bmp: P_BITMAP; state: sint32);
begin
assert(bmp <> nil);
bmp^.clip := state;
end;
function get_clip_state(bmp: P_BITMAP): sint32;
begin
assert(bmp <> nil);
Result := bmp^.clip;
end;
{$ENDIF ALLEGRO_IMPLEMENTATION}
{$IFDEF ALLEGRO_LOADVARIABLE}
{$ENDIF ALLEGRO_LOADVARIABLE}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -