📄 sma_swim.c
字号:
* Purpose:
* Place a box with corners (X1, Y1) and (X2, Y2)
*
* Processing:
* See function.
*
* Parameters:
* win : Window identifier
* x1 : Virtual left position of box
* y1 : Virtual upper position of box
* x2 : Virtual right position of box
* y2 : Virtual lower position of box
*
* Outputs:
* None
*
* Returns:
* Nothing
*
* Notes:
* None
*
**********************************************************************/
void swim_put_box (INT_32 win, INT_32 x1, INT_32 y1, INT_32 x2,
INT_32 y2)
{
INT_32 xinc, yinc;
INT_32 ysave;
if (x1 > x2)
{
xinc = x1;
x1 = x2;
x2 = xinc;
}
// Swap y1 and y2 if y1 is larger than y2
if (y1 > y2)
{
yinc = y1;
y1 = y2;
y2 = yinc;
}
// Convert virtual coordinates to physical coordinates
x1 = x1 + window [win].xpvmin;
x2 = x2 + window [win].xpvmin;
y1 = y1 + window [win].ypvmin;
y2 = y2 + window [win].ypvmin;
// Clip boxes to window sizes
if (x1 < window [win].xpvmin)
{
x1 = window [win].xpvmin;
}
if (y1 < window [win].ypvmin)
{
y1 = window [win].ypvmin;
}
if (x2 > window [win].xpvmax)
{
x2 = window [win].xpvmax;
}
if (y2 > window [win].ypvmax)
{
y2 = window [win].ypvmax;
}
// Get X and Y differences
xinc = x2 - x1;
yinc = y2 - y1;
// Make outer edge of box in pen color
swim_put_line_raw (win, x1, y1, x2, y1);
swim_put_line_raw (win, x2, y1, x2, y2);
swim_put_line_raw (win, x2, y2, x1, y2);
swim_put_line_raw (win, x1, y2, x1, y1);
// Increment X, Y values so they won't overwrite the edge
x1++;
y1++;
// Draw the box inside with the fill color
ysave = y1;
while (x1 < x2)
{
y1 = ysave;
while (y1 < y2)
{
* (window [win].fb + x1 + (y1 * window [win].xpsize)) =
window [win].fill;
y1++;
}
x1++;
}
}
/***********************************************************************
*
* Function: swim_window_open
*
* Purpose:
* Initializes a window and the default values for the window.
*
* Processing:
* See function.
*
* Parameters:
* xsize : Physical horizontal dimension of the display
* ysize : Physical vertical dimension of the display
* fbaddr : Address of the display's frame buffer
* xwin_min : Physical window left coordinate
* ywin_min : Physical window top coordinate
* xwin_max : Physical window right coordinate
* ywin_max : Physical window bottom coordinate
* border_width : Width of the window border in pixels
* pcolor : Pen color
* bkcolor : Background color
* fcolor : Fill color
* override : If 0, window overlap will be checked
*
* Outputs:
* None
*
* Returns:
* A new window value, or (-1) if an error occurred.
*
* Notes:
* This function must be called prior to any other window function.
*
**********************************************************************/
INT_32 swim_window_open (INT_32 xsize, INT_32 ysize, color_type *fbaddr,
INT_32 xwin_min, INT_32 ywin_min, INT_32 xwin_max, INT_32 ywin_max,
INT_32 border_width, color_type pcolor, color_type bkcolor,
color_type fcolor, INT_32 override)
{
INT_32 i;
INT_32 nextwin = -1;
// Find next available window
i = 0;
while (i < WINDOWSMAX)
{
if (window [i].winused != 0xbadd)
{
// Window is available, set to used
nextwin = i;
window [nextwin].winused = 0xbadd;
i = WINDOWSMAX;
}
i++;
}
// Window size validity check
if ((nextwin != -1) && (override == 0))
{
// Before continuing, check to see that the window size is
// in the physical dimensions of the display
if ((xwin_min >= 0) && (ywin_min >= 0) &&
(xwin_max < xsize) && (ywin_max < ysize))
{
// Check for overlapping windows
i = 0;
while (i < WINDOWSMAX)
{
// Only check valid windows
if ((nextwin != i) &&
(window [i].winused == 0xbadd))
{
// Does this window overlap another window?
if (((xwin_min >= window [i].xpmin) &&
(xwin_min <= window [i].xpmax) &&
(ywin_min >= window [i].ypmin) &&
(ywin_min <= window [i].ypmax)) ||
((xwin_max >= window [i].xpmin) &&
(xwin_max <= window [i].xpmax) &&
(ywin_max >= window [i].ypmin) &&
(ywin_max <= window [i].ypmax)))
{
// Window overlaps, invalidate it
window [nextwin].winused = 0x0;
nextwin = -1;
// Force exit from the loop
i = WINDOWSMAX;
}
}
i++;
}
}
else
{
// Window size is out of the physical display size, so it
// should be invalidated
window [nextwin].winused = 0x0;
nextwin = -1;
}
}
if (nextwin != -1)
{
// Save physical display dimensions
window [nextwin].xpsize = xsize;
window [nextwin].ypsize = ysize;
// Save frame buffer address
window [nextwin].fb = fbaddr;
// Save physical window dimensions and default colors
window [nextwin].xpmin = xwin_min;
window [nextwin].ypmin = ywin_min;
window [nextwin].xpmax = xwin_max;
window [nextwin].ypmax = ywin_max;
window [nextwin].pen = pcolor;
window [nextwin].bkg = bkcolor;
window [nextwin].fill = fcolor;
// Compute physical window dimensions of draw area only
window [nextwin].xpvmin = xwin_min + border_width;
window [nextwin].ypvmin = ywin_min + border_width;
window [nextwin].xpvmax = xwin_max - border_width;
window [nextwin].ypvmax = ywin_max - border_width;
// Compute virtual window size of draw area
window [nextwin].xvsize = xwin_max - xwin_min -
2 * border_width;
window [nextwin].yvsize = ywin_max - ywin_min -
2 * border_width;
// Fill in any unused border padding between draw area and border
// will fill color
for (i = 0; i < border_width; i++)
{
swim_put_line_raw (nextwin, (xwin_min + i),
(ywin_min + i), (xwin_max - i), (ywin_min + i));
swim_put_line_raw (nextwin, (xwin_max - i),
(ywin_min + i), (xwin_max - i), (ywin_max - i));
swim_put_line_raw (nextwin, (xwin_max - i),
(ywin_max - i), (xwin_min + i), (ywin_max - i));
swim_put_line_raw (nextwin, (xwin_min + i),
(ywin_max - i), (xwin_min + i), (ywin_min + i));
}
// Clear draw area with background color
swim_clear_screen (nextwin, bkcolor);
// Use the default font
window [nextwin].font = (font_type *) fonts [DEFAULT];
// Set starting text position in upper left of window
window [nextwin].xvpos = window [nextwin].xpvmin;
window [nextwin].yvpos = window [nextwin].ypvmin;
}
return nextwin;
}
/***********************************************************************
*
* Function: swim_window_close
*
* Purpose:
* Reallocates a window for use.
*
* Processing:
* For the passed window ID, clear the window used flag.
*
* Parameters:
* win : Window identifier
*
* Outputs:
* None
*
* Returns:
* Nothing
*
* Notes:
* None
*
**********************************************************************/
void swim_window_close (INT_32 win)
{
window [win].winused = 0x0;
}
/***********************************************************************
*
* Function: swim_set_pen_color
*
* Purpose:
* Sets the pen color.
*
* Processing:
* For the passed window ID, update to the passed pen color.
*
* Parameters:
* win : Window identifier
* pen_color : New pen color
*
* Outputs:
* None
*
* Returns:
* Nothing
*
* Notes:
* None
*
**********************************************************************/
void swim_set_pen_color (INT_32 win, color_type pen_color)
{
window [win].pen = pen_color;
}
/***********************************************************************
*
* Function: swim_set_fill_color
*
* Purpose:
* Sets the fill color.
*
* Processing:
* For the passed window ID, update to the passed fill color.
*
* Parameters:
* win : Window identifier
* fill_color : New fill color
*
* Outputs:
* None
*
* Returns:
* Nothing
*
* Notes:
* None
*
**********************************************************************/
void swim_set_fill_color (INT_32 win, color_type fill_color)
{
window [win].fill = fill_color;
}
/***********************************************************************
*
* Function: swim_set_bkg_color
*
* Purpose:
* Sets the color used for backgrounds.
*
* Processing:
* For the passed window ID, update to the passed background color.
*
* Parameters:
* win : Window identifier
* tbkg_color : New background color
*
* Outputs:
* None
*
* Returns:
* Nothing
*
* Notes:
* None
*
**********************************************************************/
void swim_set_bkg_color (INT_32 win, color_type bkg_color)
{
window [win].bkg = bkg_color;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -