📄 rw_imp.pas
字号:
{----------------------------------------------------------------------------}
{ }
{ File(s): rw_Imp.h }
{ }
{ Initial conversion by : Avatar.dx(Avatar.dx@libertysurf.fr) }
{ Initial conversion on : 23-Jan-2002 }
{ }
{ This File contains part of convertion of Quake2 source to ObjectPascal. }
{ More information about this project can be found at: }
{ http://www.sulaco.co.za/quake2/ }
{ }
{ Copyright (C) 1997-2001 Id Software, Inc. }
{ }
{ This program is free software; you can redistribute it and/or }
{ modify it under the terms of the GNU General Public License }
{ as published by the Free Software Foundation; either version 2 }
{ of the License, or (at your option) any later version. }
{ }
{ This program is distributed in the hope that it will be useful, }
{ but WITHOUT ANY WARRANTY; without even the implied warranty of }
{ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. }
{ }
{ See the GNU General Public License for more details. }
{ }
{----------------------------------------------------------------------------}
{ Updated on : 9-August-2002 }
{ Updated by : CodeFusion(Michael@Skovslund.dk) }
{ }
{----------------------------------------------------------------------------}
{ * Still dependent (to compile correctly) on: }
{ ? }
{----------------------------------------------------------------------------}
{ * TODO: }
{ ? }
{----------------------------------------------------------------------------}
(*
**
** RW_IMP.C
**
** This file contains ALL Win32 specific stuff having to do with the
** software refresh. When a port is being made the following functions
** must be implemented by the port:
**
** SWimp_EndFrame
** SWimp_Init
** SWimp_SetPalette
** SWimp_Shutdown
*)
unit rw_Imp;
interface
uses
Windows,
q_shared,
rw_Win,
SysUtils,
r_Local;
procedure VID_CreateWindow(Width, Height, StyleBits : Integer); cdecl;
function SWimp_Init( hInstance : Pointer; wndProc : Pointer ) : QBoolean; cdecl;
function SWimp_InitGraphics(FullScreen : Boolean) : QBoolean; cdecl;
procedure SWimp_EndFrame; cdecl;
function SWimp_SetMode(pWidth,pHeight : PInteger; Mode : Integer; FullScreen : QBoolean): rserr_t; cdecl;
procedure SWimp_SetPalette(Palette : PByteArray); cdecl;
procedure SWimp_ShutDown; cdecl;
procedure SWimp_AppActivate(Active : qBoolean); cdecl;
procedure Sys_MakeCodeWriteable(StartAddr, Length : Double); cdecl;
// Console variables that we need to access from this module
// CodeFusion: Removed as it is defined in rw_win.
//var
// sww_state : swwstate_t;
const
WINDOW_CLASS_NAME = 'Quake2';
WINDOW_STYLE = (WS_OVERLAPPED or WS_BORDER or WS_CAPTION or WS_VISIBLE);
implementation
uses
rw_dib,
rw_ddraw,
Directdraw,
r_main;
(*
** VID_CreateWindow
*)
procedure VID_CreateWindow(Width, Height, StyleBits : Integer);
var
wc : WNDCLASS;
r : TRect;
x,y,w,h : Integer;
exStyle : Integer;
vid_xPos, vid_yPos , vid_FullScreen : cvar_p;
Begin
vid_xPos := ri.Cvar_Get('Vid_xPos', '0', 0);
vid_yPos := ri.Cvar_Get('Vid_yPos', '0', 0);
vid_FullScreen := ri.Cvar_Get('Vid_Fullscreen','0', CVAR_ARCHIVE);
if (vid_FullScreen.Value <> 0) then
exstyle := WS_EX_TOPMOST
else
exstyle := 0;
(* Register the frame class *)
wc.Style := 0;
wc.lpfnWndProc := sww_state.wndProc;
wc.cbClsExtra := 0;
wc.cbWndExtra := 0;
wc.HInstance := sww_state.h_Inst;
wc.hIcon := 0;
wc.hCursor := LoadCursor(0,IDC_ARROW);
wc.hbrBackground := Windows.COLOR_GRAYTEXT;
wc.lpszMenuName := NIL;
wc.lpszClassName := WINDOW_CLASS_NAME;
if RegisterClass(wc) = 0 then
ri.Sys_Error(ERR_FATAL, 'Couldn''t register window class');
r.Left :=0;
r.Top := 0;
r.Right := Width;
r.Bottom := Height;
AdjustWindowRect(r, stylebits, FALSE);
w := r.right - r.left;
h := r.bottom - r.top;
x := Round(vid_xpos.value);
y := Round(vid_ypos.value);
sww_state.h_Wnd := CreateWindowEx(exStyle,
WINDOW_CLASS_NAME,
'Quake2',
stylebits,
x,y,w,h,
0,
0,
sww_state.h_Inst,
nil);
if sww_state.h_Wnd = 0 then
ri.Sys_Error(ERR_FATAL, 'Couldn''t create device window');
ShowWindow(sww_state.h_Wnd, SW_SHOWNORMAL);
UpdateWindow(sww_state.h_Wnd);
SetForegroundWindow(sww_state.h_Wnd);
SetFocus(sww_state.h_Wnd);
// let the sound and input subsystems know about the new window
ri.Vid_NewWindow(width, height);
end;
(*
** SWimp_Init
**
** This routine is responsible for initializing the implementation
** specific stuff in a software rendering subsystem.
*)
function SWimp_Init( hInstance : Pointer; wndProc : Pointer ) : QBoolean;
Begin
sww_state.h_Inst := Cardinal(hInstance);
sww_state.wndproc := wndProc;
Result := True;
end;
(*
** SWimp_InitGraphics
**
** This initializes the software refresh's implementation specific
** graphics subsystem. In the case of Windows it creates DIB or
** DDRAW surfaces.
**
** The necessary width and height parameters are grabbed from
** vid.width and vid.height.
*)
function SWimp_InitGraphics(FullScreen : Boolean) : QBoolean;
Begin
// free resources in use
SWimp_ShutDown;
// create a new window
VID_CreateWindow(vid.width, vid.height,WINDOW_STYLE);
// initialize the appropriate subsystem
if not Fullscreen then
Begin
if not Dib_Init(@vid.Buffer, @vid.rowBytes) then
Begin
vid.Buffer := nil;
vid.RowBytes := 0;
Result := False;
Exit;
end;
end
else
Begin
if not DDraw_Init(@vid.Buffer, @vid.RowBytes) then
Begin
vid.Buffer := nil;
vid.RowBytes := 0;
Result := False;
Exit;
end;
end;
Result := true;
end;
(*
** SWimp_EndFrame
**
** This does an implementation specific copy from the backbuffer to the
** front buffer. In the Win32 case it uses BitBlt or BltFast depending
** on whether we're using DIB sections/GDI or DDRAW.
*)
procedure SWimp_EndFrame; cdecl;
var
{$IFDEF DIRECTX_WINDOWMODE}
RS : TRect;
p : TPoint;
{$ENDIF}
r : TRect;
rVal : HResult;
ddsd : TDDsurfaceDesc;
Begin
if not sw_state.FullScreen then
Begin
if sww_state.palettized then
Begin
// holdpal = SelectPalette(hdcScreen, hpalDIB, FALSE);
// RealizePalette(hdcScreen);
end;
BitBlt(sww_state.h_DC, 0, 0,
vid.Width, vid.Height,
sww_state.hdcDIBSection,
0, 0,
SRCCOPY);
if sww_state.palettized then
Begin
// SelectPalette(hdcScreen, holdpal, FALSE);
end;
end
else
Begin
r.Left := 0;
r.Top := 0;
r.Right := vid.Width;
r.Bottom := vid.Height;
sww_state.lpddsOffScreenBuffer.Unlock(vid.buffer);
// sww_state.lpddsOffScreenBuffer.lpVtbl.Unlock( sww_state.lpddsOffScreenBuffer, vid.buffer);
{$IFDEF DIRECTX_WINDOWMODE}
p.x := 0;
p.y := 0;
ClientToScreen(sww_state.h_Wnd, p);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -