Exemplo n.º 1
0
LONG CSkinItemEdit::GetBorderHelper(LONG clrNormal, LONG clrHover, LONG clrFocus, LONG clrReadOnly, LONG clrDisabled)
{
    LONG color = 0;

    if (IsReadOnly() && m_bReadOnlyBorder) {
        color = clrReadOnly;
    } else if (IsFocused() && m_bFocusBorder) {
        color = clrFocus;
    } else if (IsHot()) {
        color = clrHover;
    } else {
        color = clrNormal;
    }

    if (GetDisabled())
        color = clrDisabled;

    if (color == -1)
        color = clrNormal;

    if (color == -1)
        return -1;

    if (GetColorTransform()) {
        GetEngine()->TransformColor(color, color);
    }

    return color;
}
Exemplo n.º 2
0
void CSkinText::Draw(CDC* pDC, LPRECT lpInvalidRect, CRgn* pInvalidRgn)
{
	//创建字体
	if (m_textStyleNormal.IsFontChanged()) {
		UpdateFont(*pDC);
	}

	//自动调整
	if (m_bAdjustEnable){
		AdjustRect(*pDC);
	}

    //绘制背景色
	CRect drawRect = GetSkinRect();
    if (m_clrBkColorNormal != -1) {
        CRenderEngine::FillRect(*pDC, drawRect, m_clrBkColorNormal);
    }

	//选择颜色
	LONG color = m_textStyleNormal.Getcolor();
    VARIANT_BOOL newUnderline = GetnormalUnderline();
	switch (m_enMouseState)
	{
	case MOUSE_NORMAL:
		color = m_textStyleNormal.Getcolor();
        newUnderline = GetnormalUnderline();
		break;
	case MOUSE_HOVER:
		if (m_textStyleHover.Getcolor() != -1)
			color = m_textStyleHover.Getcolor();
        newUnderline = m_textStyleNormal.Getunderline();
		break;
	case MOUSE_DOWN:
		if (m_textStyleDown.Getcolor() != -1)
			color = m_textStyleDown.Getcolor();
        newUnderline = m_textStyleNormal.Getunderline();
		break;
	default:
		break;
	}
    if (GetColorTransform())
        GetEngine()->TransformColor(color, color);

	CRect oldDrawRect = GetSkinRect();
	CSize textSize;
	GetTextSize(textSize, *pDC);

	if ( (m_uScrollFlag & SKIN_SCROLL_ENABLE) != 0 ){
		int oldScrollOffset = m_nScrollOffset - m_nScrollSpeed;
		if ( (m_uScrollFlag & SKIN_SCROLL_DIRECTION) == 0 ){
			//计算旧的位置
			oldScrollOffset = oldScrollOffset % (drawRect.Width() + textSize.cx);
			if (m_nScrollSpeed >= 0)
				oldDrawRect.OffsetRect(oldScrollOffset - textSize.cx, 0);
			else
				oldDrawRect.OffsetRect(oldScrollOffset + drawRect.Width(), 0);

			//新的位置
			m_nScrollOffset = m_nScrollOffset % (drawRect.Width() + textSize.cx);
			if (m_nScrollSpeed >= 0)
				drawRect.OffsetRect(m_nScrollOffset - textSize.cx, 0);
			else
				drawRect.OffsetRect(m_nScrollOffset + drawRect.Width(), 0);
		}else{
			oldScrollOffset = oldScrollOffset % (drawRect.Height() + textSize.cy);
			//计算旧的位置
			if (m_nScrollSpeed >= 0)
				oldDrawRect.OffsetRect(0, oldScrollOffset);
			else
				oldDrawRect.OffsetRect(0, oldScrollOffset + drawRect.Height());

			//新的位置
			m_nScrollOffset = m_nScrollOffset % (drawRect.Height() + textSize.cy);
			if (m_nScrollSpeed >= 0)
				drawRect.OffsetRect(0, m_nScrollOffset);
			else
				drawRect.OffsetRect(0, m_nScrollOffset + drawRect.Height());
		}
		drawRect.right = drawRect.left + textSize.cx;
	}

    CString strSel = InternalGetSelText();
    if (strSel.IsEmpty()) {
        VARIANT_BOOL oldUnderline = m_textStyleNormal.Getunderline();
        LONG oldColor = m_textStyleNormal.Getcolor();
        m_textStyleNormal.Setunderline(newUnderline);
        m_textStyleNormal.Setcolor(color);
        m_textStyleNormal.DrawText(*pDC, m_strText, &drawRect, &m_rcTextArea);
        m_textStyleNormal.Setcolor(oldColor);
        m_textStyleNormal.Setunderline(oldUnderline);
    } else {
        LONG nStart = min(m_nSelStart, m_nSelEnd);
        nStart = max(nStart, 0);
        LONG nEnd = max(m_nSelStart, m_nSelEnd);
        nEnd = min(nEnd, m_strText.GetLength());

        VARIANT_BOOL oldUnderline = m_textStyleNormal.Getunderline();
        LONG oldColor = m_textStyleNormal.Getcolor();
        m_textStyleNormal.Setunderline(newUnderline);
        m_textStyleNormal.Setcolor(color);

        //绘制选中部分左侧文字
        CString strLeft = m_strText.Left(nStart);
        CRect rcLeft = drawRect;
        CRect rcLeftArea = drawRect;
        m_textStyleNormal.DrawText(*pDC, strLeft, &rcLeft, &rcLeftArea);

        //绘制选中文字
        strSel;
        CRect rcSel = drawRect;
        rcSel.left = rcLeftArea.right;
        CRect rcSelArea = rcSel;
        m_textStyleNormal.DrawTextEx(*pDC, strSel, &rcSel, RGB(255, 255, 255), &rcSelArea);

        //绘制选中文字右侧文字
        CString strRight = m_strText.Right(m_strText.GetLength() - nEnd);
        CRect rcRight = drawRect;
        rcRight.left = rcSelArea.right;
        CRect rcRightArea = drawRect;
        m_textStyleNormal.DrawText(*pDC, strRight, &rcRight, &rcRightArea);

        m_rcTextArea = drawRect;
        m_rcTextArea.right = rcRightArea.right;

        m_textStyleNormal.Setcolor(oldColor);
        m_textStyleNormal.Setunderline(oldUnderline);
    }
}
Exemplo n.º 3
0
/** @brief MEX gateway */
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray*prhs[])
{
    #define	S_IN	     prhs[0]
    #define	A_IN	     prhs[1]
    #define	B_OUT	     plhs[0]
#define IS_REAL_FULL_DOUBLE(P) (!mxIsComplex(P) \
&& !mxIsSparse(P) && mxIsDouble(P))
	num *A, *B;
	char *SBuf;
	const int *Size;
	colortransform Trans;
	int SBufLen, NumPixels, Channel, Channel2;


    /* Parse the input arguments */
    if(nrhs != 2)
        mexErrMsgTxt("Two input arguments required.");
    else if(nlhs > 1)
        mexErrMsgTxt("Too many output arguments.");

	if(!mxIsChar(S_IN))
		mexErrMsgTxt("First argument should be a string.");
    if(!IS_REAL_FULL_DOUBLE(A_IN))
        mexErrMsgTxt("Second argument should be a real full double array.");

	Size = mxGetDimensions(A_IN);

	if(mxGetNumberOfDimensions(A_IN) > 3
		|| Size[mxGetNumberOfDimensions(A_IN) - 1] != 3)
		mexErrMsgTxt("Second argument should be an Mx3 or MxNx3 array.");

	/* Read the color transform from S */
	SBufLen = mxGetNumberOfElements(S_IN)*sizeof(mxChar) + 1;
	SBuf = mxMalloc(SBufLen);
	mxGetString(S_IN, SBuf, SBufLen);

	if(!(GetColorTransform(&Trans, SBuf)))
		mexErrMsgTxt("Invalid syntax or unknown color space.");

	mxFree(SBuf);

	A = (num *)mxGetData(A_IN);
	NumPixels = mxGetNumberOfElements(A_IN)/3;

	/* Create the output image */
	B_OUT = mxCreateDoubleMatrix(0, 0, mxREAL);
	mxSetDimensions(B_OUT, Size, mxGetNumberOfDimensions(A_IN));
	mxSetData(B_OUT, B = mxMalloc(sizeof(num)*mxGetNumberOfElements(A_IN)));

	Channel = NumPixels;
	Channel2 = NumPixels*2;

	/* Apply the color transform */
	while(NumPixels--)
	{
		ApplyColorTransform(Trans, B, B + Channel, B + Channel2,
			A[0], A[Channel], A[Channel2]);
		A++;
		B++;
	}

    return;
}