예제 #1
0
파일: BUIEdit.cpp 프로젝트: czbreborn/BUI
	SizeF BUIEdit::getTextSize(const bstring text)
	{
		m_textDesc.content = text;
		RectF rcf(getContentRect().left, getContentRect().top, getContentRect().right - getContentRect().left + 100, getContentRect().bottom - getContentRect().top);
		return BRenderEngineManager::GetInstance()->RenderEngine()->GetTextSize(m_pUIManager->GetPaintDC(), rcf, m_textDesc);
		//return BRenderEngineManager::GetInstance()->RenderEngine()->GetTextSize(text, m_textDesc.fontFamily, m_textDesc.fontSize, m_textDesc.style);
	}
예제 #2
0
파일: BUIEdit.cpp 프로젝트: czbreborn/BUI
	UINT BUIEdit::locateCaretPlace(LONG mouseXPos)
	{
		UINT caretPlace = m_beginDrawPlace;
		LONG caretXPos = getContentRect().left;
		if (m_strText.length() == 0) {
			return caretPlace;
		}

		SizeF szText = getTextSize(m_strText);
		// 鼠标在最左侧
		if (szText.Width < getContentRect().right - getContentRect().left &&
			mouseXPos < caretXPos) {
			return caretPlace;
		} else {
			LONG lastPointx  = caretXPos;
			LONG leftTextLength = m_strText.length() - m_beginDrawPlace;

			LONG low = 0;
			LONG hight = leftTextLength - 1;
			while (low <= hight) {
				LONG mid = (low + hight) / 2;
				bstring leftString = m_strText.substr(m_beginDrawPlace, mid);
				szText = getTextSize(leftString);
				caretXPos = m_rcItem.left + m_rcPadding.left + szText.Width;
				if (caretXPos > mouseXPos) {
					hight = mid - 1;
				} else if (caretXPos < mouseXPos) {
					low = mid + 1;
				} else {
					return m_beginDrawPlace + mid;
				}
			}
			if (hight < 0) {
				return m_beginDrawPlace + low;
			}
			bstring hightString = m_strText.substr(m_beginDrawPlace, hight);
			SizeF szTextHight = getTextSize(hightString);
			bstring lowString = m_strText.substr(m_beginDrawPlace, low);
			SizeF szTextLow = getTextSize(lowString);
			if (mouseXPos > (szTextLow.Width + szTextHight.Width) / 2) {
				return m_beginDrawPlace + low;
			} else {
				return m_beginDrawPlace + hight;
			}
		}
		return caretPlace;
	}
예제 #3
0
파일: BUIEdit.cpp 프로젝트: czbreborn/BUI
	void BUIEdit::PaintText(HDC hDC)
	{
		RECT rcPaint;
		if (IntersectRect(&rcPaint, &m_rcPaint, &getContentRect())) {
			m_textDesc.content = m_strText.substr(m_beginDrawPlace);
			m_textDesc.selectedBegin = m_selectedBeginPalce - m_beginDrawPlace;
			m_textDesc.selectedCount = m_selectedEndPlace - m_selectedBeginPalce;
			RectF rcf(rcPaint.left, rcPaint.top, rcPaint.right - rcPaint.left, rcPaint.bottom - rcPaint.top);
			m_textDesc.selectedBkColor = 0xAACC6600;
			BRenderEngineManager::GetInstance()->RenderEngine()->DrawText(hDC, rcf, m_textDesc);
		}
	}
예제 #4
0
QRectF ZoomHelper::toTilesArea(const QRectF& windowArea,
                               const QSize& tilesSurface) const
{
    const auto contentRect = getContentRect();

    // Map window visibleArea to content space for tiles origin at (0,0)
    const auto visibleContentArea =
        windowArea.translated(-contentRect.x(), -contentRect.y());
    // Scale content area to tiles area size
    const auto xScale = tilesSurface.width() / contentRect.width();
    const auto yScale = tilesSurface.height() / contentRect.height();
    const auto visibleTilesArea =
        QRectF{visibleContentArea.x() * xScale, visibleContentArea.y() * yScale,
               visibleContentArea.width() * xScale,
               visibleContentArea.height() * yScale};
    return visibleTilesArea;
}
예제 #5
0
파일: Button.cpp 프로젝트: jvaemape/SDL2Gui
bool Button::draw(SDL_Renderer* renderer) {

    /*if(label->isDirty()) {
        label->draw();
    }*/
    SDL_Texture *oldTarget = SDL_GetRenderTarget(renderer);
    SDL_SetRenderTarget(renderer, _texture);
    SDL_SetRenderDrawColor(renderer, 0,0,0,0);
    SDL_RenderClear(renderer);
    SDL_SetRenderDrawColor(renderer, 0,0,0,255);
    SDL_Rect extents = {0, 0, frame.w, frame.h};
    _theme->draw(renderer, &extents);
    SDL_Rect contentRect;
    getContentRect(&contentRect);
    //printf("Content rect: %dx%d%+d%+d\n", contentRect.w, contentRect.h, contentRect.x, contentRect.y);
    //contentRect.x = padding.x;
    //contentRect.y = padding.y;
    //contentRect.w += padding.x + padding.w;
    //contentRect.h += padding.y + padding.h;
    //-- SDL_RenderCopy(renderer, label->getTexture(), NULL, &contentRect);
    /*printf("contentRect.w: %d\n", contentRect.w);
    int w;
    SDL_QueryTexture(label->getTexture(), NULL, NULL, &w, NULL);
    printf("label with: %d\n", w);*/
#if 0
    SDL_Point srcPoints[] = {
        {0, 0},
        {padding.x, padding.y},
        {w - padding.w, h - padding.h},
        {w, h}
    };
    SDL_Point dstPoints[] = {
        {frame->x, frame->y},
        {frame->x + padding.x, frame->y + padding.y},
        {frame->x + frame->w - padding.w, frame->y + frame->h - padding.h},
        {frame->x + frame->w, frame->y + frame->h}
    };
    for (int y = 0; y < 3; y++ ) {
        for (int x = 0; x < 3; x++) {
            SDL_Rect src = {
                srcPoints[x].x,
                srcPoints[y].y,
                srcPoints[x+1].x,
                srcPoints[y+1].y
            };
            src.w -= src.x;
            src.h -= src.y;

            SDL_Rect dst = {
                dstPoints[x].x,
                dstPoints[y].y,
                dstPoints[x+1].x,
                dstPoints[y+1].y
            };
            dst.w -= dst.x;
            dst.h -= dst.y;
            //printf("%d,%d\n", x, y);
            //printf("src: %dx%d%+d%+d\n", src.w, src.h, src.x, src.y);
            //printf("dst: %dx%d%+d%+d\n\n", dst.w, dst.h, dst.x, dst.y);
            /*printf("src: %d+%d+%dx%d dst: %d+%d+%dx%d\n",
                src.x, src.y, src.w, src.h,
                dst.x, dst.y, dst.w, dst.h);*/
            SDL_RenderCopy(texture, &src, &dst);
            //SDL_SetRenderDrawColor(renderer, 32+x*32, 32+y*32, 0, 127);
            //SDL_RenderFillRect(renderer, &dst);
        }
    }
#endif
    dirty = false;
    SDL_SetRenderTarget(renderer, oldTarget);
    return true;
}
예제 #6
0
파일: BUIEdit.cpp 프로젝트: czbreborn/BUI
	void BUIEdit::onChar(TCHAR chKey)
	{
		if (m_caretState) {
			switch (chKey) {
			case VK_BACK:
				{
					if (m_caretPlace == 0) {
						if (m_beginDrawPlace == 0) {
							return;
						}
					} else {
						m_strText.erase(m_caretPlace - 1, 1);
						m_caretPlace--;
					}
					SizeF szText = getTextSize(m_strText.substr(m_beginDrawPlace, m_caretPlace - m_beginDrawPlace));
					if (szText.Width < getContentRect().right - getContentRect().left) {
						m_pUIManager->SetCaretPos(getContentRect().left + ceil(szText.Width), getContentRect().top);
					} else {
						m_pUIManager->SetCaretPos(getContentRect().right, getContentRect().top);
					}
				}
				break;

			case VK_TAB:
				break;

			default:
				{
					if (m_caretPlace == m_strText.length()) {
						m_strText.append(1, chKey);
					} else {
						m_strText.insert(m_caretPlace, 1, chKey);
					}
					m_caretPlace++;
					SizeF szText = getTextSize(m_strText.substr(m_beginDrawPlace, m_caretPlace - m_beginDrawPlace));
					if (szText.Width > getContentRect().right - getContentRect().left) {
						if (m_caretPlace == m_strText.length()) {
							m_beginDrawPlace++;
						} else {
							m_beginDrawPlace += (m_strText.length() - m_caretPlace < 5) ? m_strText.length() - m_caretPlace : 5;
						}
					}

					szText = getTextSize(m_strText.substr(m_beginDrawPlace, m_caretPlace - m_beginDrawPlace));
					if (szText.Width < getContentRect().right - getContentRect().left) {
						m_pUIManager->SetCaretPos(getContentRect().left + ceil(szText.Width), getContentRect().top);
					} else {
						m_pUIManager->SetCaretPos(getContentRect().right, getContentRect().top);
					}
				}
				break;
			}
		}
	}
예제 #7
0
파일: BUIEdit.cpp 프로젝트: czbreborn/BUI
	void BUIEdit::onKeyDown(TCHAR chKey)
	{
		bstringstream woss;
		woss << L"buiedit::onKeyDown --" << chKey << endl;
		::OutputDebugString(woss.str().c_str());
		switch (chKey) {
		case VK_DELETE:
			{
				if (m_caretPlace != m_strText.length()) {
					m_strText.erase(m_caretPlace, 1);
					SizeF szText = getTextSize(m_strText);
					if (szText.Width > getContentRect().right - getContentRect().left) {
						SizeF szDrawText = getTextSize(m_strText.substr(m_beginDrawPlace, m_strText.length() - m_beginDrawPlace));
						if (szDrawText.Width > getContentRect().right - getContentRect().left) {
							m_beginDrawPlace--;
							szDrawText = getTextSize(m_strText.substr(m_beginDrawPlace, m_caretPlace - m_beginDrawPlace));
							if (szDrawText.Width < getContentRect().right - getContentRect().left) {
								m_pUIManager->SetCaretPos(getContentRect().left + ceil(szDrawText.Width), getContentRect().top);
							} else {
								m_pUIManager->SetCaretPos(getContentRect().right, getContentRect().top);
							}
						}
					}
				}
			}
			break;

		case VK_LEFT:
			{
				// 选择内容
				if ((GetKeyState(VK_SHIFT) & 0x8000) != 0) {
					if (m_selectedEndPlace == 0) {
						if (m_caretPlace != 0) {
							m_selectedEndPlace = m_caretPlace;
							m_selectedBeginPalce = m_caretPlace - 1;
						}
					} else {
						if (m_selectedBeginPalce == m_caretPlace) {
							m_selectedEndPlace--;
							if (m_selectedBeginPalce == m_selectedEndPlace) {
								m_selectedBeginPalce = m_selectedEndPlace = 0;
								if (!m_caretState) {
									m_pUIManager->ShowCaret();
									m_caretState = true;
								}
							}
						} else {
							if (m_selectedBeginPalce != 0) {
								if (m_selectedBeginPalce == m_beginDrawPlace) {
									if (m_beginDrawPlace > 5) {
										m_beginDrawPlace -= 5;
									} else {
										m_beginDrawPlace = 0;
									}
								}
								m_selectedBeginPalce--;
							}
						}
					}

					if (m_selectedBeginPalce < m_selectedEndPlace) {
						if (m_caretState) {
							m_pUIManager->HideCaret();
							m_caretState = false;
						}
					}
				} else { // 移动光标
					if (m_selectedBeginPalce < m_selectedEndPlace) {
						if (!m_caretState) {
							m_pUIManager->ShowCaret();
							m_caretState = true;
						}
						m_caretPlace = m_selectedBeginPalce;
					}
					if (m_caretPlace != 0) {
						if (m_beginDrawPlace == m_caretPlace) {
							if (m_beginDrawPlace > 5) {
								m_beginDrawPlace -= 5;
							} else {
								m_beginDrawPlace = 0;
							}
						}
						m_caretPlace--;
					}

					SizeF szText = getTextSize(m_strText.substr(m_beginDrawPlace, m_caretPlace - m_beginDrawPlace));
					if (szText.Width < getContentRect().right - getContentRect().left) {
						m_pUIManager->SetCaretPos(getContentRect().left + ceil(szText.Width), getContentRect().top);
					} else {
						m_pUIManager->SetCaretPos(getContentRect().right, getContentRect().top);
					}

					m_selectedBeginPalce = m_selectedEndPlace = 0;
				}
			}
			break;

		case VK_RIGHT:
			// 选择内容
			if ((GetKeyState(VK_SHIFT) & 0x8000) != 0) {
				if (m_selectedEndPlace == 0) {
					if (m_caretPlace != m_strText.length()) {
						m_selectedEndPlace = m_caretPlace + 1;
						m_selectedBeginPalce = m_caretPlace;
					}
				} else {
					if (m_selectedEndPlace == m_caretPlace) {
						m_selectedBeginPalce++;
						if (m_selectedBeginPalce == m_selectedEndPlace) {
							m_selectedBeginPalce = m_selectedEndPlace = 0;
							if (!m_caretState) {
								m_pUIManager->ShowCaret();
								m_caretState = true;
							}
						}
					} else {
						if (m_selectedEndPlace < m_strText.length()) {
							m_selectedEndPlace++;
							SizeF szDrawText = getTextSize(m_strText.substr(m_beginDrawPlace, m_selectedEndPlace - m_beginDrawPlace + 1));
							if (szDrawText.Width > getContentRect().right - getContentRect().left) {
								if (m_beginDrawPlace + 5 < m_strText.length()) {
									m_beginDrawPlace += 5;
								} else {
									m_beginDrawPlace += m_strText.length() - m_beginDrawPlace;
								}
							}
						}
					}
				}

				if (m_selectedBeginPalce < m_selectedEndPlace) {
					if (m_caretState) {
						m_pUIManager->HideCaret();
						m_caretState = false;
					}
				}
			} else {	// 移动光标
				if (m_selectedBeginPalce < m_selectedEndPlace) {
					if (!m_caretState) {
						m_pUIManager->ShowCaret();
						m_caretState = true;
					}
					m_caretPlace = m_selectedEndPlace;
				}
				if (m_caretPlace < m_strText.length()) {
					SizeF szDrawText = getTextSize(m_strText.substr(m_beginDrawPlace, m_caretPlace - m_beginDrawPlace + 1));
					if (szDrawText.Width > getContentRect().right - getContentRect().left) {
						if (m_caretPlace + 5 <= m_strText.length()) {
							m_beginDrawPlace += 5;
						} else {
							m_beginDrawPlace += m_strText.length() - m_caretPlace;
						}
					}
					m_caretPlace++;
				}

				SizeF szText = getTextSize(m_strText.substr(m_beginDrawPlace, m_caretPlace - m_beginDrawPlace));
				if (szText.Width < getContentRect().right - getContentRect().left) {
					m_pUIManager->SetCaretPos(getContentRect().left + ceil(szText.Width), getContentRect().top);
				} else {
					m_pUIManager->SetCaretPos(getContentRect().right, getContentRect().top);
				}

				m_selectedBeginPalce = m_selectedEndPlace = 0;
			}

			break;

		case VK_TAB:
			//PostMessageW(GetParent(hWnd), WM_NEXTDLGCTL, GetKeyState(VK_SHIFT) & 0x8000, FALSE);
			break;

		default:
			break;
		}
	}
예제 #8
0
파일: BUIEdit.cpp 프로젝트: czbreborn/BUI
	void BUIEdit::Event(TEventUI& event)
	{
		if (event.type == uievent_setfocus) {
			m_pUIManager->CreateCaret(1, getContentRect().bottom - getContentRect().top);
			m_caretState = false;
			m_selectedBeginPalce = 0;
			m_selectedEndPlace = 0;
			Invalidate();
		}

		if (event.type == uievent_killfocus) {
			m_pUIManager->DestroyCaret();
			m_caretState = false;
			m_selectedBeginPalce = 0;
			m_selectedEndPlace = 0;
			Invalidate();
		}

		if (event.type == uievent_buttondown) {
			m_selectedBeginPalce = 0;
			m_selectedEndPlace = 0;
			if (::PtInRect(&m_rcItem, event.ptMouse) && IsEnabled()) {
				m_caretPlace = locateCaretPlace(event.ptMouse.x);
				if (m_caretPlace == m_beginDrawPlace) {
					m_pUIManager->SetCaretPos(getContentRect().left, getContentRect().top);
				} else {
					SizeF szText = getTextSize(m_strText.substr(m_beginDrawPlace, m_caretPlace - m_beginDrawPlace));
					m_pUIManager->SetCaretPos(getContentRect().left + ceil(szText.Width), getContentRect().top);
				}

				if (!m_caretState) {
					m_pUIManager->ShowCaret();
					m_caretState = true;
				}
			} else {
				m_pUIManager->HideCaret();
				m_caretState = false;
			}

			Invalidate();
		}

		if (event.type == uievent_mouseenter) {
			if (!m_mouseState) {
				SetClassLong(m_pUIManager->GetPaintWindow(), GCL_HCURSOR, (LONG)LoadCursor(NULL,IDC_IBEAM));
				m_mouseState = true;
			}
		}

		if (event.type == uievent_mousemove) {
			if (::PtInRect(&m_rcItem, event.ptMouse) && IsEnabled()) {
				if (::GetKeyState(VK_LBUTTON) < 0) {
					m_selectedBeginPalce = m_caretPlace;
					m_selectedEndPlace = locateCaretPlace(event.ptMouse.x);
					if (m_selectedBeginPalce > m_selectedEndPlace) {
						UINT caretPlace = m_selectedBeginPalce;
						m_selectedBeginPalce = m_selectedEndPlace;
						m_selectedEndPlace = caretPlace;
					}

					if (m_selectedBeginPalce < m_selectedEndPlace) {
						if (m_caretState) {
							m_pUIManager->HideCaret();
							m_caretState = false;
						}
					}
				}

				Invalidate();
			}
		}

		if (event.type == uievent_mouseleave) {
			if (m_mouseState) {
				SetClassLong(m_pUIManager->GetPaintWindow(), GCL_HCURSOR, (LONG)LoadCursor(NULL,IDC_ARROW));
				m_mouseState = false;
			}
		}

		if (event.type == uievent_char) {
			onChar(event.chKey);
			Invalidate();
		}

		if (event.type == uievent_keydown) {
			onKeyDown(event.chKey);

			Invalidate();
		}

		BUILabel::Event(event);
	}