Ejemplo n.º 1
0
void CPicShowCtrl::OnPaint()
{
	CPaintDC dc(this); // device context for painting
	// TODO: 在此处添加消息处理程序代码
	common::ui::CClientRect rcThis(this);
	if (m_hBmp == NULL)
	{
		//还没有选择图片,则绘制白色背景
		HBRUSH bgBrush = ::CreateSolidBrush(RGB(255,255,255));
		CRect rect;
		GetWindowRect(&rcThis);
		ScreenToClient(&rcThis);
		FillRect(dc,&rcThis,bgBrush);
		::DeleteObject(bgBrush);
	}
	else
	{
		int width=180;
		int height=180;

		CxImage img;
		img.CreateFromHBITMAP(m_hBmp);

		CBitmap bitmapmem;          
		CBitmap *pOldBit;
		CDC m_pMemDC;
		m_pMemDC.CreateCompatibleDC(&dc); 
		bitmapmem.CreateCompatibleBitmap(&dc, width, height);
		pOldBit=m_pMemDC.SelectObject(&bitmapmem);

		CRect rect(0,0,width,height);
		HBRUSH bgBrush = ::CreateSolidBrush(RGB(255,255,255));
		FillRect(m_pMemDC,&rect,bgBrush);
		DeleteObject(bgBrush);

		img.Draw(m_pMemDC,m_iStartx,m_iStarty,img.GetWidth(),img.GetHeight(),&rect);
		dc.SetStretchBltMode(HALFTONE);
		dc.StretchBlt(rcThis.left,rcThis.top,rcThis.Width(),rcThis.Height(),&m_pMemDC,0,0,width,height,SRCCOPY);
		m_pMemDC.SelectObject(pOldBit);
		m_pMemDC.DeleteDC();
		bitmapmem.DeleteObject();
	}
}
Ejemplo n.º 2
0
void C4RectList::ClipByRect(const C4Rect &rClip) {
  // split up all rectangles
  for (int32_t i = 0; i < GetCount(); ++i) {
    C4Rect *pTarget = &Get(i);
    // any overlap?
    if (rClip.x + rClip.Wdt <= pTarget->x) continue;
    if (rClip.y + rClip.Hgt <= pTarget->y) continue;
    if (rClip.x >= pTarget->x + pTarget->Wdt) continue;
    if (rClip.y >= pTarget->y + pTarget->Hgt) continue;
    // okay; split up rectangle
    // first split will just reduce the target rectangle size
    // if more splits are done, additional rectangles need to be added
    int32_t iSplitCount = 0, iOver;
    C4Rect rcThis(*pTarget);
    // clipped by right side
    if ((iOver = rcThis.x + rcThis.Wdt - rClip.x - rClip.Wdt) > 0) {
      pTarget->x += pTarget->Wdt - iOver;
      pTarget->Wdt = iOver;
      rcThis.Wdt -= iOver;
      ++iSplitCount;
    }
    // clipped by obttom side
    if ((iOver = rcThis.y + rcThis.Hgt - rClip.y - rClip.Hgt) > 0) {
      if (iSplitCount) {
        AddRect(rcThis);
        pTarget = &Get(GetCount() - 1);
      }
      pTarget->y += pTarget->Hgt - iOver;
      pTarget->Hgt = iOver;
      rcThis.Hgt -= iOver;
      ++iSplitCount;
    }
    // clipped by left side
    if ((iOver = rClip.x - rcThis.x) > 0) {
      if (iSplitCount) {
        AddRect(rcThis);
        pTarget = &Get(GetCount() - 1);
      }
      pTarget->Wdt = iOver;
      rcThis.Wdt -= iOver;
      rcThis.x = rClip.x;
      ++iSplitCount;
    }
    // clipped by top side
    if ((iOver = rClip.y - rcThis.y) > 0) {
      if (iSplitCount) {
        AddRect(rcThis);
        pTarget = &Get(GetCount() - 1);
      } else
        ++iSplitCount;
      pTarget->Hgt = iOver; /* rcThis.Hgt -= iOver; rcThis.y = rClip.y; not
                               needed, since rcThis is no longer used */
    }
    // nothing split? This means this rectnagle is completely contained
    if (!iSplitCount) {
      // make it vanish
      RemoveIndexedRect(i);
      --i;
    }
  }
  // concat rectangles if possible
  bool fDone = false;
  while (!fDone) {
    fDone = true;
    for (int32_t i = 0, cnt = GetCount(); i < cnt && fDone; ++i) {
      C4Rect &rc1 = Get(i);
      for (int32_t j = i + 1; j < cnt; ++j) {
        C4Rect &rc2 = Get(j);
        if (rc1.y == rc2.y && rc1.Hgt == rc2.Hgt) {
          if (rc1.x + rc1.Wdt == rc2.x) {
            rc1.Wdt += rc2.Wdt;
            RemoveIndexedRect(j);
            fDone = false;
            break;
          } else if (rc2.x + rc2.Wdt == rc1.x) {
            rc2.Wdt += rc1.Wdt;
            RemoveIndexedRect(i);
            fDone = false;
            break;
          }
        } else if (rc1.x == rc2.x && rc1.Wdt == rc2.Wdt) {
          if (rc1.y + rc1.Hgt == rc2.y) {
            rc1.Hgt += rc2.Hgt;
            RemoveIndexedRect(j);
            fDone = false;
            break;
          } else if (rc2.y + rc2.Hgt == rc1.y) {
            rc2.Hgt += rc1.Hgt;
            RemoveIndexedRect(i);
            fDone = false;
            break;
          }
        }
      }
    }
  }
}
Ejemplo n.º 3
0
QPoint GLDMaskBox::calcPosOfOwner()
{
    QPoint pt(0, 0);

    do
    {
        // 计算owner位置对应屏幕中心的象限
        if (!m_oTipBoxParam.m_wgtOwner)
        {
            break;
        }

        QPoint ptGlobalOwnerCenter = m_oTipBoxParam.m_wgtOwner->mapToGlobal(
            m_oTipBoxParam.m_wgtOwner->rect().center());
        QPoint ptGlobalScreen = QApplication::desktop()->screenGeometry().center();
        QPoint ptDelta = ptGlobalOwnerCenter - ptGlobalScreen;

        if (ptDelta.x() >= 0 && ptDelta.y() <= 0)
        {
            // 第一象限
            pt = QPoint(ptGlobalOwnerCenter.x() - m_oTipBoxParam.m_wgtOwner->width()/2,
                            ptGlobalOwnerCenter.y() + m_oTipBoxParam.m_wgtOwner->height()/2);
            pt += QPoint(-this->width()/2, 0);
        }
        else if (ptDelta.x() <= 0 && ptDelta.y() <= 0)
        {
            // 第二象限
            pt = QPoint(ptGlobalOwnerCenter.x() + m_oTipBoxParam.m_wgtOwner->width()/2,
                            ptGlobalOwnerCenter.y() + m_oTipBoxParam.m_wgtOwner->height()/2);
            pt += QPoint(-this->width()/2, 0);
        }
        else if (ptDelta.x() <= 0 && ptDelta.y() >= 0)
        {
            // 第三象限
            pt = QPoint(ptGlobalOwnerCenter.x() + m_oTipBoxParam.m_wgtOwner->width()/2,
                            ptGlobalOwnerCenter.y() - m_oTipBoxParam.m_wgtOwner->height()/2);
            pt += QPoint(-this->width()/2, -this->height());
        }
        else if (ptDelta.x() >= 0 && ptDelta.y() >= 0)
        {
            // 第四象限
            pt = QPoint(ptGlobalOwnerCenter.x() - m_oTipBoxParam.m_wgtOwner->width()/2,
                        ptGlobalOwnerCenter.y() - m_oTipBoxParam.m_wgtOwner->height()/2);
            pt += QPoint(-this->width()/2, -this->height());
        }

        // 超出屏幕范围的校准
        QRect rcThis(pt, pt + QPoint(this->width(), this->height()));
        QRect rcScreen = QApplication::desktop()->screenGeometry();

        if (!rcScreen.contains(rcThis.topLeft()))
        {
            int nXOffset = rcThis.topLeft().x() - rcScreen.topLeft().x();
            int nYOffset = rcThis.topLeft().y() - rcScreen.topLeft().y();

            if (nXOffset < 0)
            {
                pt.setX(pt.x() - nXOffset);
            }

            if (nYOffset < 0)
            {
                pt.setY(pt.y() - nYOffset);
            }
        }
        else if (!rcScreen.contains(rcThis.topRight()))
        {
            int nXOffset = rcThis.topRight().x() - rcScreen.topRight().x();
            int nYOffset = rcThis.topRight().y() - rcScreen.topRight().y();

            if (nXOffset > 0)
            {
                pt.setX(pt.x() - nXOffset);
            }

            if (nYOffset < 0)
            {
                pt.setY(pt.y() - nYOffset);
            }
        }
        else if (!rcScreen.contains(rcThis.bottomLeft()))
        {
            int nXOffset = rcThis.bottomLeft().x() - rcScreen.bottomLeft().x();
            int nYOffset = rcThis.bottomLeft().y() - rcScreen.bottomLeft().y();

            if (nXOffset < 0)
            {
                pt.setX(pt.x() - nXOffset);
            }

            if (nYOffset > 0)
            {
                pt.setY(pt.y() - nYOffset);
            }
        }
        else if (!rcScreen.contains(rcThis.bottomRight()))
        {
            int nXOffset = rcThis.bottomRight().x() - rcScreen.bottomRight().x();
            int nYOffset = rcThis.bottomRight().y() - rcScreen.bottomRight().y();

            if (nXOffset > 0)
            {
                pt.setX(pt.x() - nXOffset);
            }

            if (nYOffset > 0)
            {
                pt.setY(pt.y() - nYOffset);
            }
        }

    } while(0);

    return pt;
}