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

📄 workwin.c

📁 This source code has been tested under OpenWindows 2.0, Sun s X11/NeWS server. For Xlib programs th
💻 C
字号:
/*************************************************************************                                                                    ****  workwin.c                                                         ****                                                                    ****  Doodle -- Work Window Module                                      ****                                                                    *************************************************************************/#include <Xm/DrawingA.h>#include "doodle.h"/*************************************************************************                                                                    ****               F O R W A R D   D E F I N I T I O N S                ****                                                                    *************************************************************************/static	void	InitGC();static	void	DrawEvt();/*************************************************************************                                                                    ****                    L O C A L   V A R I A B L E S                   ****                                                                    *************************************************************************/static	GC	    the_gc;		/* Current GC for drawing     */static	XGCValues   gc_values;		/* Values for allocating GCs  */static	XtGCMask    gc_mask;		/* Mask for allocating GCs    */static	int	    last_x, last_y;	/* Last pointer position      *//*************************************************************************                                                                    ****  InitWorkWindow()                                                  ****                                                                    ****  This function creates the drawing area used as the work window.   ****  It also allocates the initial (default) GC for drawing in that    ****  window, and attaches callbacks and event handlers.                ****                                                                    *************************************************************************/void InitWorkWindow(){    workwin = XmCreateDrawingArea( mainwin, "WorkWin", NULL, 0 );    XtManageChild( workwin );    InitGC();    XtAddEventHandler( workwin, (ButtonPressMask | ButtonMotionMask),                                FALSE, DrawEvt, NULL );}/*************************************************************************                                                                    ****  InitGC()                                                          ****                                                                    ****  Initializes the graphics context used for drawing. This function  ****  stores default values in the variable "gc_values", which is used  ****  to tell the server about the GC we want. It also sets bits in     ****  "gc_mask", which is used to tell the server what values we have   ****  set. Finally, it gets the work window's color scheme, sets the    ****  line width to 1, and allocates a GC.                              ****                                                                    *************************************************************************/static void InitGC(){    Pixel	foreground,		background;    XtSetArg( arglist[0], XmNforeground, &foreground );    XtSetArg( arglist[1], XmNbackground, &background );    XtGetValues( workwin, arglist, 2 );    gc_values.foreground = foreground;    gc_values.background = background;    gc_values.line_width = 1;    gc_values.line_style = LineSolid;    gc_values.cap_style  = CapRound;    gc_values.join_style = JoinRound;    gc_mask = GCForeground | GCBackground | GCLineWidth |              GCLineStyle  | GCCapStyle   | GCJoinStyle;    the_gc = XtGetGC( workwin, gc_mask, &gc_values );}/*************************************************************************                                                                    ****  DrawEvt( w, client_data, event )                                  ****                                                                    ****  This function is attached to button-press and button-motion       ****  events. On button press, it initializes the stored position       ****  variables. On buttton-motion, it draws a line from the stored     ****  position to the new position, then stores the new position.       ****                                                                    *************************************************************************/static void DrawEvt( w, client_data, event )    Widget	w;    caddr_t	client_data;    XEvent	*event;{    int		new_x, new_y;    switch (event->type)        {	case ButtonPress :		last_x = event->xbutton.x;		last_y = event->xbutton.y;		break;	case MotionNotify :		new_x = event->xmotion.x;		new_y = event->xmotion.y;		XDrawLine( XtDisplay(w), XtWindow(w), the_gc,			   last_x, last_y, new_x, new_y );		last_x = new_x;		last_y = new_y;		break;	default :		break;	}}/*************************************************************************                                                                    ****  ClearWin()                                                        ****                                                                    ****  This function clears the work window. It is attached to the       ****  File/New menu choice.                                             ****                                                                    *************************************************************************/void ClearWin(){    XClearWindow( XtDisplay(workwin), XtWindow(workwin) );}/*************************************************************************                                                                    ****  PenColorCB( w, client_data, call_data )                           ****                                                                    ****  This function is attached to each of the buttons in the Pen       ****  menu's Color submenu. It takes the foreground color from the      ****  invoking button, and allocates a GC using that color.             ****                                                                    *************************************************************************/void PenColorCB( w, client_data, call_data )    Widget	w;    caddr_t	client_data;    caddr_t	call_data;{    Pixel	new_color;    XtReleaseGC( workwin, the_gc );    XtSetArg( arglist[0], XmNbackground, &new_color );    XtGetValues( w, arglist, 1 );    gc_values.foreground = new_color;    the_gc = XtGetGC( workwin, gc_mask, &gc_values );}/*************************************************************************                                                                    ****  PenSizeCB( w, client_data, call_data )                            ****                                                                    ****  This function is attached to each of the buttons in the Pen       ****  menu's Size submenu. It is passed a string as its client data,    ****  which specifies the new pen width. It then allocates a GC         ****  that uses that width.                                             ****                                                                    ****  Note: A more elegant approach to line widths would use the        ****        button's labelString resource to specify the width.         ****                                                                    *************************************************************************/void PenSizeCB( w, client_data, call_data )    Widget	w;    char	*client_data;    caddr_t	call_data;{    XtReleaseGC( workwin, the_gc );    if (!strcmp(client_data, "1"))        gc_values.line_width = 1;    else if (!strcmp(client_data, "2"))        gc_values.line_width = 2;    else if (!strcmp(client_data, "3"))        gc_values.line_width = 3;    else if (!strcmp(client_data, "4"))        gc_values.line_width = 4;    else if (!strcmp(client_data, "8"))        gc_values.line_width = 8;    the_gc = XtGetGC( workwin, gc_mask, &gc_values );}

⌨️ 快捷键说明

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