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

📄 generic.cpp

📁 MicroStation源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
Public void text_stringJustGenericHook
(
DialogItemMessage   *dimP
)
    {
    int		col,row;
    double	partSize;
    
	dimP->msgUnderstood = TRUE;
    
    switch (dimP->messageType)
		{
		case DITEM_MESSAGE_CREATE:
	    	dimP->dialogItemP->attributes.acceptsKeystrokes = FALSE;
			break;

		case DITEM_MESSAGE_BUTTON:
	    	dimP->u.button.motionFunc = text_stringJustButton;//设置鼠标点击函数(不区分左右)
			break;
		    
		case DITEM_MESSAGE_SYNCHRONIZE://响应同步
//			printf("重绘\n");
			break;
	
		case DITEM_MESSAGE_DRAW:
            text_displayFont (dimP, TRUE);
			break;

		default:
	    	dimP->msgUnderstood = FALSE;
			break;
		}
    }


/*----------------------------------------------------------------------+
|                                                                       |
| name          text_stringJustMenuHook  				|
|                                                                       |
| author        BSI                                     8/90            |
|                                                                       |
+----------------------------------------------------------------------*/
Public void text_stringJustMenuHook
(
DialogItemMessage   *dimP
)
    {
    int		col,row;
    double	partSize;
    
    dimP->msgUnderstood = TRUE;
	//通过tcb变量作为传递中介   
    col = tcb->txtjust / 6;
    row = tcb->txtjust - 6*col;

    switch (dimP->messageType)
	{

	case DITEM_MESSAGE_GETSTATE:
	    dimP->u.value.hookHandled = TRUE;

	    if (dimP->dialogItemP->id == OPTIONBUTTONID_TextStringHorJust)
		dimP->u.value.value.sLongFormat = col;
	    else
		dimP->u.value.value.sLongFormat = row;
	    break;
	case DITEM_MESSAGE_SETSTATE:
	    dimP->u.value.hookHandled = TRUE;
	    dimP->u.value.valueChanged = TRUE;

	    if (dimP->dialogItemP->id == OPTIONBUTTONID_TextStringHorJust)
		col = dimP->u.value.value.sLongFormat; 
	    else
		row = dimP->u.value.value.sLongFormat;
	    tcb->txtjust = 6*col + row;//通过tcb变量作为传递中介
	    break;
		    
	case DITEM_MESSAGE_SYNCHRONIZE://强制同步
	    {
	    ValueUnion	value;//ValueUnion是用于向控件传递或获取数据的结构
	    
	    if (dimP->dialogItemP->id == OPTIONBUTTONID_TextStringHorJust)
		value.sLongFormat = col;
	    else
		value.sLongFormat = row;
	    mdlDialog_itemSetValue (NULL, FMT_LONG, &value, NULL, dimP->db,
				    dimP->itemIndex);//设置控件的值
	    }
	    break;

	default:
	    dimP->msgUnderstood = FALSE;
	    break;
	}
    }

/*----------------------------------------------------------------------+
|                                                                       |
| name          text_drawLock    					|
|									|
| author        BSI					8/90            |
|									|
+----------------------------------------------------------------------*/
Public void text_drawLock
(
DialogItemMessage   *dimP,	/* => pointer to current message */
int		    topTextID,	/* => rsc ID to top text field	*/
int		    botTextID	/* => rsc ID to bottom text field */
)
    {
    DialogItem	*xScaleP, *yScaleP;
    Rectangle	*xRectP, *yRectP;
    int		onColor, offColor;
    Point2d	points[3];
    IconRsc	*irP;
    long	lockRscId = RASTERID_SmallClosedLock;

    /*============ 绘制图标 ============*/
    if (!dimP->dialogItemP->rawItemP->userDataP)//获取lockClosed的状态
	lockRscId = RASTERID_SmallOpenLock;
    irP = (IconRsc *)mdlResource_load (NULL, RTYPE_Icon, lockRscId);//载入图标资源

    onColor = mdlWindow_fixedColorIndexGet (dimP->db, BLACK_INDEX);//dimP->db的前景色
    offColor = mdlWindow_fixedColorIndexGet (dimP->db, LGREY_INDEX);//dimP->db的背景色
    mdlWindow_iconDraw (dimP->db, irP, &dimP->dialogItemP->rect, onColor,
			offColor, ICON_STYLE_NORMAL, NULL);//绘制图标

    mdlResource_free (irP);//释放图标资源的内存

    /*======= 画线 ===========*/
    xScaleP = mdlDialog_itemGetByTypeAndId (dimP->db, RTYPE_Text,
	topTextID, 0);	
    xRectP = &(xScaleP->rect);
    yScaleP = mdlDialog_itemGetByTypeAndId (dimP->db, RTYPE_Text, 
	botTextID, 0);
    yRectP = &(yScaleP->rect);
    onColor = mdlWindow_fixedColorIndexGet (dimP->db, BLACK_INDEX);
    mdlWindow_lineStyleSet (dimP->db, 0, onColor, 0, 0); //为dimP->db安置画笔
    
    /* 上面的线 */
    points[0].x = xRectP->corner.x;
    points[0].y = xRectP->origin.y + (xRectP->corner.y - xRectP->origin.y)/2;
    points[1].x = points[0].x + 13;
    points[1].y = points[0].y;
    points[2].x = points[1].x;
    points[2].y = xRectP->corner.y - 6 - 2;
    mdlWindow_lineStringDraw (dimP->db, points, 3, NULL);//画线串为3个点
    
    /* 下面的线 */
    points[0].y = yRectP->corner.y - (yRectP->corner.y - yRectP->origin.y)/2;
    points[1].y = points[0].y;
    points[2].y = yRectP->origin.y + 5 + 2;
    mdlWindow_lineStringDraw (dimP->db, points, 3, NULL);//画线串为3个点
    }

/*----------------------------------------------------------------------+
|									|
| name		text_displayFont					|
|									|
| author	RBB					7/90		|
|									|
+----------------------------------------------------------------------*/
Private void text_displayFont 
(
DialogItemMessage   *dimP,
int		    eraseFirst  /* TRUE to erase item first */
)
    {
    int		    textHeight, x,y,i,j,row,col;
    double	    space, gap;
    Dpoint3d	    textOrigin;
    Rectangle	    rect = dimP->dialogItemP->rect, invertRect;
    TextParam	    textParams;//文本属性结构
    TextSizeParam   textSize;//文本大小结构
    MSElementUnion  textElement;
    
    if (eraseFirst) mdlWindow_rectClear (dimP->db, &rect, NULL);//清除控件的背景色
    
    /* ========== Draw Border =========== */
    mdlDialog_lineStyleSet (dimP->db, 0, BLACK_INDEX, NORMALDRAW, 0); //设置当前画笔模式
    mdlWindow_rectDraw (dimP->db, &dimP->dialogItemP->rect, 
			&dimP->dialogItemP->rect);//画控件的矩形范围
		    
    /* ========== Draw Text ============= */
    textSize.mode = TXT_BY_TILE_SIZE;

    textParams.just = TXTJUST_CB;
    textParams.style = 0;
    textParams.viewIndependent = FALSE;
    textParams.font = tcb->actfont;//设置为当前字体号
	
    textOrigin.x = (double) (rect.corner.x - rect.origin.x)/fc_2;
	
    space = (double)(rect.corner.y - rect.origin.y)/6.0;
    
    x = rect.origin.x;
    y = rect.origin.y;
    
    textOrigin.z = 0;

	/* 绘制文本 */
	textHeight = (rect.corner.y - rect.origin.y)/2;//字高为控件的一半
	textSize.size.height = textSize.size.width = textHeight;//设置字宽字高为控件的一半
	textOrigin.y = (double)(textHeight / 2);//设置字的定位点
	mdlText_create (&textElement, NULL, "AB", &textOrigin,
			&textSize, NULL, &textParams, NULL);//创建文本要素
	textElement.text_2d.dhdr.symb.b.weight = 0;//设置文本的的线宽
	fontDialog_displayElement (dimP->db, &textElement, &rect);//绘制文本要素

	/* 画十字线 */
	mdlDialog_lineStyleSet (dimP->db, 0, BLACK_INDEX, NORMALDRAW, 0);//设置当前画笔模式
	for (i=1; i<6; i+=2)
	    for (j=1; j<6; j+=2)
		text_drawCross (dimP->db, x +(long)(i*space),
				    y +(long)(j*space));
				
	col = tcb->txtjust / 6;
	row = tcb->txtjust - 6*col;
	text_invertPart (dimP->db, &dimP->dialogItemP->rect, row, col);//反转
    }
    
/*----------------------------------------------------------------------+
|									|
| name		text_drawCross  					|
|									|
| author	BSI					8/90		|
|									|
+----------------------------------------------------------------------*/
Private void text_drawCross 
(
DialogBox   *db,
int	    x,
int	    y
)	    
    {
    mdlWindow_lineDraw (db, x, y-1, x, y+1, NULL);//画线
    mdlWindow_lineDraw (db, x-1, y, x+1, y, NULL);
    }
    
/*----------------------------------------------------------------------+
|									|
| name		text_invertPart  					|
|									|
| author	BSI					8/90		|
|									|
+----------------------------------------------------------------------*/
Private void text_invertPart///反转rect的颜色
(
DialogBox   *db,
Rectangle   *rect,
int	    row,
int	    col
)	    
    {
    Rectangle	invertRect;
    double	partSize;
    
    partSize = (double)(rect->corner.y - rect->origin.y)/3.0;
    invertRect.origin.x = rect->origin.x + col * partSize;
    invertRect.origin.y = rect->origin.y + row * partSize;
    invertRect.corner.x = rect->origin.x + (col+1) * partSize;
    invertRect.corner.y = rect->origin.y + (row+1) * partSize;
    mdlDialog_rectInvert (db, &invertRect);///反转db中的invertRect所标识的范围
    }

Public void GenericDialog
(
 DialogMessage   *dimP
)
{
	dimP->msgUnderstood = TRUE;
	if(!dimP->dialogId==DIALOGID_GenericDialog)
		return;
    switch (dimP->messageType)
	{
	case DIALOG_MESSAGE_DESTROY:
		{
			mdlDialog_cmdNumberQueue (FALSE, CMD_MDL_UNLOAD,
				mdlSystem_getCurrTaskID(), TRUE);
		}
	default:
		{
			dimP->msgUnderstood = FALSE;
			break;
		}
	}
}

/*----------------------------------------------------------------------+
|									|
|   main								|
|									|
+----------------------------------------------------------------------*/
int main 
(
int	argc,
char	*argv[]
)
	{
	RscFileHandle	rfHandle;

	Private DialogHookInfo uHooks[] =
		{
		{HOOKGenericDialog	,	    	GenericDialog },
		{HOOKITEMID_ImageItem,	    	imageItem_genericHook },
		{HOOKITEMID_JustHook,	    	text_stringJustGenericHook},
		{HOOKITEMID_JustMenuHook,	text_stringJustMenuHook},
		{HOOKITEMID_ScaleHook,		text_scaleTextHook},
		{HOOKITEMID_LockHook,		text_lockGenericHook},
		};

	mdlResource_openFile (&rfHandle, NULL, FALSE);

	/* Publish the dialog item hooks */
	mdlDialog_hookPublish (sizeof(uHooks)/sizeof(DialogHookInfo), uHooks);
	mdlOutput_error ("Reading raster image file");
	mdlDialog_open (NULL, DIALOGID_GenericDialog);
	mdlOutput_error (" ");
	}   

⌨️ 快捷键说明

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