window.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 1,263 行 · 第 1/3 页
C
1,263 行
height = (float)pix_height / Height * Win_height;
return( _min( height, Win_height ) );
}
float _ptextheightsize(
/*********************/
int pt_size,
text_def *text
) {
int old_size;
float height;
old_size = text->size;
text->size = pt_size;
height = _ptextheight( text );
text->size = old_size;
return( height );
}
float _wtextwidth(
/****************/
/* return text width in window coords of text line. If text_line
is NULL, assume 1 character */
char *text_line,
text_def *text
) {
int pix_width;
int pix_height;
float width;
textdim( text_line, text, &pix_width, &pix_height );
width = (float)pix_width / Width * Win_width;
return( _min( width, Win_width ) );
}
extern float _wtextwidth_font(
/****************************/
/* return text width in window coords of text line. If text_line
is NULL, assume 1 character */
char *text_line,
WPI_FONT font
) {
int pix_width;
int pix_height;
float width;
if( Text_path == TEXT_VERTICAL ) {
textdim_font( NULL, font, &pix_width, &pix_height );
} else {
textdim_font( text_line, font, &pix_width, &pix_height );
}
width = (float)pix_width / Width * Win_width;
return( _min( width, Win_width ) );
}
float _wtextmaxwidth(
/*******************/
int num_chars,
text_def *text
) {
char *ptr;
float width;
_new( ptr, num_chars + 1 );
memset( ptr, 'M', num_chars );
ptr[num_chars] = '\0';
width = _wtextwidth( ptr, text );
_free( ptr );
return( width );
}
void _wsetpath(
/*************/
/* path for text */
text_dir dir
) {
Text_path = dir;
}
void _wtextout(
/*************/
char *text,
float x,
float y,
int hor_align,
int ver_align,
void *wfont
) {
WORD horiz_flags;
WORD vert_flags;
WPI_FONT old_font;
int dx;
int dy;
WPI_TEXTMETRIC font_info;
int len;
int bk_mode;
int px1;
int py1;
int px2;
int py2;
int width;
int height;
WPI_FONT font;
font = (WPI_FONT) wfont;
bk_mode = _wpi_getbackmode( Win_dc );
_wpi_setbackmode( Win_dc, TRANSPARENT );
len = strlen( text );
convert_pt( x, y, &dx, &dy );
old_font = _wpi_selectfont( Win_dc, font );
if( Text_path == TEXT_VERTICAL ) {
_wpi_gettextmetrics( Win_dc, &font_info );
width = _wpi_metricmaxcharwidth( font_info );
height = len * _wpi_metricheight( font_info );
} else {
_wpi_gettextextent( Win_dc, text, len, &width, &height );
}
px1 = px2 = dx;
py1 = py2 = dy;
switch( hor_align ) {
case TEXT_H_LEFT:
horiz_flags = TA_LEFT;
px2 += width;
break;
case TEXT_H_CENTER:
horiz_flags = TA_CENTER;
px1 -= width / 2;
px2 += width / 2;
break;
case TEXT_H_RIGHT:
horiz_flags = TA_RIGHT;
px2 -= width;
break;
}
switch( ver_align ) {
case TEXT_V_TOP:
py2 += height * WPI_VERT_MULT;
break;
case TEXT_V_CENTER:
py1 -= height / 2 * WPI_VERT_MULT;
py2 += height / 2 * WPI_VERT_MULT;
break;
case TEXT_V_BOTTOM:
py2 -= height * WPI_VERT_MULT;
break;
}
rgn_rectangle( px1, py1, px2, py2 );
if( Text_path == TEXT_HORIZONTAL ) {
/* normal right path */
switch( ver_align ) {
case TEXT_V_TOP:
#ifdef PLAT_OS2
/* OS/2 has problems with TA_LEFT && TA_TOP aligned text */
/* This is a messy solution until we actually figure out */
/* what the problem is. */
vert_flags = TA_BOTTOM;
_wpi_gettextmetrics( Win_dc, &font_info );
dy += _wpi_metricheight( font_info ) * WPI_VERT_MULT;
#else
vert_flags = TA_TOP;
#endif
break;
case TEXT_V_CENTER:
#ifdef PLAT_OS2
vert_flags = TA_HALF;
#else
/* OS/2 has a much cleverer way of doing this */
/* but Windows apparently doesn't */
vert_flags = TA_TOP;
_wpi_gettextmetrics( Win_dc, &font_info );
dy -= _wpi_metricheight( font_info ) / 2 * WPI_VERT_MULT;
#endif
break;
case TEXT_V_BOTTOM:
vert_flags = TA_BOTTOM;
break;
}
_wpi_settextalign( Win_dc, horiz_flags, vert_flags );
_wpi_textout( Win_dc, dx, dy, text, len );
} else {
/* must display text vertically... do it by hand */
vert_flags = TA_TOP;
_wpi_settextalign( Win_dc, horiz_flags, vert_flags );
switch( ver_align ) {
case TEXT_V_BOTTOM:
dy -= _wpi_metricheight( font_info ) * len * WPI_VERT_MULT;
break;
case TEXT_V_CENTER:
dy -= (_wpi_metricheight( font_info ) * len) / 2 * WPI_VERT_MULT;
break;
}
_wpi_settextalign( Win_dc, horiz_flags, vert_flags );
for( ; len > 0; --len, dy += _wpi_metricheight( font_info )
* WPI_VERT_MULT, ++text ) {
_wpi_textout( Win_dc, dx, dy, text, 1 );
}
}
_wpi_getoldfont( Win_dc, old_font );
_wpi_setbackmode( Win_dc, bk_mode );
}
extern void _wsetlinewidth(
/*************************/
line_width width
) {
switch( width ) {
case WIDTH_SINGLE:
Set_wl_width = LW_SINGLE;
break;
case WIDTH_NARROW:
Set_wl_width = LW_NARROW;
break;
case WIDTH_MEDIUM:
Set_wl_width = LW_MEDIUM;
break;
}
}
void _wsetlinestyle(
/******************/
line_style style
) {
switch( style ) {
case LINE_NONE:
Set_pen_style = PS_NULL;
Set_wl_style = LS_NONE;
break;
case LINE_SOLID:
Set_pen_style = PS_SOLID;
Set_wl_style = LS_SOLID;
break;
case LINE_DASHED:
Set_pen_style = PS_DASH;
Set_wl_style = LS_DASH;
break;
case LINE_DOTTED:
Set_pen_style = PS_DOT;
Set_wl_style = LS_DOT;
break;
case LINE_MIXED:
Set_pen_style = PS_DASHDOT;
Set_wl_style = LS_DASH_DOT;
break;
}
}
void _wsetfillstyle(
/******************/
fill_style style
) {
Set_fill_style = style;
}
void APIENTRY cgr_delete_brush(
/*****************************/
HBRUSH brush_hld
) {
_wpi_deletebrush( brush_hld );
}
HBRUSH WINEXP cgr_make_brush(
/***************************/
WPI_COLOUR color,
fill_style fill
) {
LOGBRUSH brush;
HBRUSH new_brush;
_wpi_setlogbrushcolour( &brush, color );
if( fill == FILL_SOLID ) {
_wpi_setlogbrushsolid( &brush );
} else if( fill == FILL_HOLLOW ) {
_wpi_setlogbrushhollow( &brush );
} else {
_wpi_setlogbrushstyle( &brush, BS_HATCHED );
switch( fill ) {
case FILL_HATCH_LD:
_wpi_setlogbrushsymbol( &brush, HS_BDIAGONAL );
break;
case FILL_HATCH_RD:
_wpi_setlogbrushsymbol( &brush, HS_FDIAGONAL );
break;
case FILL_HATCH_HC:
_wpi_setlogbrushsymbol( &brush, HS_CROSS );
break;
case FILL_HATCH_DC:
_wpi_setlogbrushsymbol( &brush, HS_DIAGCROSS );
break;
case FILL_HATCH_H:
_wpi_setlogbrushsymbol( &brush, HS_HORIZONTAL );
break;
case FILL_HATCH_V:
_wpi_setlogbrushsymbol( &brush, HS_VERTICAL );
break;
}
}
new_brush = _wpi_createbrush( &brush );
return( new_brush );
}
void _wsetcolor(
/**************/
int color
) {
if( color < 0 ) {
/* indicates that real BLACK is desired */
Set_color = _wpi_getrgb( 0, 0, 0 );
} else {
Set_color = get_palette_color( color );
}
}
void _wsetrgbcolor(
/*****************/
WPI_COLOUR rgb
) {
Set_color = rgb;
}
static void get_obj_settings(
/***************************/
/* set brush and pen based on fill type, for normal objects (polys, pies) */
int fill_type,
HPEN *pen,
HBRUSH *brush
) {
switch( fill_type ) {
case FILL_BORDER: // border only: interior not touched (pen)
*pen = _wpi_createpen( Set_pen_style, 1, Set_color );
*brush = _wpi_createnullbrush();
Old_pen = _wpi_selectpen( Win_dc, *pen );
Old_brush = _wpi_selectbrush( Win_dc, *brush );
break;
case FILL_INTERIOR: // interior only: border not touched (brush)
/* Windows has a nasty bug. NULL_PEN generates a 'non-written'
border. 'Width' = 0 doesn't help either. With NULL_PEN,
behaviour depends on the primitive: rectangles goof, polygons
are OK. Anyway, gist is that we gotta live with it! */
//*pen = CreatePen( PS_SOLID, 0, _wpi_getrgb( 0, 0, 0 ) );
*pen = _wpi_createnullpen();
*brush = cgr_make_brush( Set_color, Set_fill_style );
Old_pen = _wpi_selectpen( Win_dc, *pen );
Old_brush = _wpi_selectbrush( Win_dc, *brush );
break;
case FILL_BORDER_CLEAR: // border WITH interior erased to bkgd (pen)
*pen = _wpi_createpen( Set_pen_style, 1, Set_color );
*brush = cgr_make_brush( GetBkColor( Win_dc ), FILL_SOLID );
Old_pen = _wpi_selectpen( Win_dc, *pen );
Old_brush = _wpi_selectbrush( Win_dc, *brush );
break;
case FILL_BORDER_FILL: // border and interior (pen & brush)
*pen = _wpi_createpen( Set_pen_style, 1, Set_color );
*brush = cgr_make_brush( Set_color, Set_fill_style );
Old_pen = _wpi_selectpen( Win_dc, *pen );
Old_brush = _wpi_selectbrush( Win_dc, *brush );
break;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?