Exemple #1
0
        void NRenderStatus::DrawStatus()
        {
            DWORD currentTime = ::GetTickCount();

            Base::NString status;
            if(currentTime <= lastTime_)
                status.Format(_T("Index: %d\r\nFPS: MAX"), ++ index_);
            else
                status.Format(_T("Index: %d\r\nFPS: %.2f"), ++ index_, (double)1000 / (currentTime - lastTime_));

            lastTime_ = currentTime;

            Base::NRect rcClient;
            ::GetClientRect(hWnd_, rcClient);

            HDC hDc = ::GetDC(hWnd_);

            Base::NRect rcText(rcClient);
            ::DrawText(hDc, status.GetData(), status.GetLength(), rcText, DT_EDITCONTROL | DT_CALCRECT);
            rcText.Offset(rcClient.Width() - rcText.Width() - 8, 8);

            CAlphaDC alphaDc;
            if(alphaDc.Init(hDc, rcText, rcClient.GetSize(), true))
            {
                ::SetBkColor(alphaDc, RGB(255, 255, 0));
                ::SetBkMode(alphaDc, OPAQUE);
                ::DrawText(alphaDc, status.GetData(), status.GetLength(), rcText, DT_EDITCONTROL);

                alphaDc.EndDraw(255);
            }
            ::ReleaseDC(hWnd_, hDc);
        }
Exemple #2
0
        void NWndUi::OnWindowChanged(NWindow* window)
        {
            __super::OnWindowChanged(window);
            if(window == NULL || realWindow_ != NULL)
                return;

            Base::NString wndClassName;
            DWORD style;
            DWORD exStyle;
            if(!GetWndData(wndClassName, style, exStyle))
                return;

            Base::NRect rcWnd = GetRootRect();
            HWND hWnd = ::CreateWindowEx(exStyle,
                wndClassName,
                GetText().GetData(),
                WS_TABSTOP | WS_CHILD | (IsVisible() ? WS_VISIBLE : 0) | style,
                rcWnd.Left, rcWnd.Top,
                rcWnd.Width(), rcWnd.Height(),
                window->GetNative(),
                NULL,
                ::GetModuleHandle(NULL),
                0);
            AttachWnd(hWnd);
            ::SendMessage(hWnd, WM_SETFONT, ::SendMessage(window->GetNative(), WM_GETFONT, 0, 0), TRUE);
        }
Exemple #3
0
 bool NWndUi::SetSizeImpl(int width, int height, bool force)
 {
     if(!__super::SetSizeImpl(width, height, force) || realWindow_ == NULL)
         return false;
     Base::NRect rcWnd = GetRect();
     ::SetWindowPos(realWindow_, NULL, 0, 0, rcWnd.Width(), rcWnd.Height(), SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
     return false;
 }
Exemple #4
0
 Base::NRect NFrameBase::GetRootRect() const
 {
     Base::NRect result = frameRect_;
     if(parentFrame_ != NULL)
     {
         Base::NRect parentRect = parentFrame_->GetRootRect();
         result.Offset(parentRect.Left, parentRect.Top);
     }
     return result;
 }
Exemple #5
0
 Base::NRect NFrameBase::GetScreenRect() const
 {
     if(window_ == NULL)
         return GetRootRect();
     Base::NRect windowRect;
     if(!window_->GetRect(windowRect))
         return GetRootRect();
     Base::NRect rootRect = GetRootRect();
     rootRect.Offset(windowRect.Left, windowRect.Top);
     return rootRect;
 }
Exemple #6
0
 NRichFrame* NWindow::GetRootFrame()
 {
     if(rootFrame_ == NULL)
     {
         Base::NInstPtr<NRichFrame> rootFrame(MemToolParam);
         rootFrame_ = (NRichFrame*)rootFrame;
         rootFrame_->SetId(_T("rootFrame"));
         rootFrame_->window_ = this;
         rootFrame->SetLayout(NFrame::LayoutHFill | NFrame::LayoutVFill);
         Base::NRect rect;
         GetRect(rect);
         rootFrame_->SetSize(rect.Width(), rect.Height());
     }
     return rootFrame_;
 }
Exemple #7
0
        void NWindow::OnDraw(NRender* render, const Base::NRect& clipRect)
        {
            renderStatus_.BeforeDraw();

            Base::NRect rcClient;
            GetRect(rcClient);
            rcClient.Offset(-rcClient.Left, -rcClient.Top);

            if(drawCallback_ && drawCallback_(this, render, clipRect))
            {
                renderStatus_.DrawStatus(render, rcClient);
                return;
            }

            if(rootFrame_ != NULL)
            {
                Base::NPoint pt;
                rootFrame_->Draw(render, pt, clipRect);
                renderStatus_.DrawStatus(render, rcClient);
            }
        }
Exemple #8
0
        void NEdit::OnRealWindowCreated()
        {
            __super::OnRealWindowCreated();

            NTextAttr* textAttr = GetTextAttr();
            if(textAttr && textAttr->IsSingleLine())
            {
                Base::NSize textSize;
                if(!GetText().IsEmpty() && window_->GetRender())
                {
                    window_->GetRender()->GetTextSize(GetText(), GetTextAttr(), GetFont(), textSize, maxSize_.Width);

                    UINT flags = textAttr->GetAlignFlags();
                    if(flags != 0)
                    {
                        int left = 0;
                        int top = 0;

                        if(flags & NTextAttr::TextAlignRight)
                            left = frameRect_.Width() - textSize.Width;
                        else if(flags & NTextAttr::TextAlignHCenter)
                            left = (frameRect_.Width() - textSize.Width) / 2;

                        if(flags & NTextAttr::TextAlignBottom)
                            top = frameRect_.Height() - textSize.Height;
                        else if(flags & NTextAttr::TextAlignHCenter)
                            top = (frameRect_.Height() - textSize.Height) / 2;

                        Base::NRect rcText;
                        rcText.SetPos(left, top);
                        rcText.SetSize(textSize.Width, textSize.Height);
                        ::SendMessage(realWindow_, EM_SETRECT, 0, reinterpret_cast<LPARAM>((RECT*)rcText));
                    }
                }
            }
            ::SendMessage(realWindow_, EM_SETCUEBANNER, TRUE, (LPARAM)hintText_.GetData());
            // fixme: multiple line edit should use nui's scrollbar
            ::SetFocus(realWindow_);
            Edit_SetSel(realWindow_, 0, -1);
        }
Exemple #9
0
        void NFrameBase::ReLayout()
        {
            if(layout_ == LayoutNone)
                return;

            int width = 0;
            int height = 0;

            if(GetParent() != NULL)
            {
                Base::NRect rcParent = GetParent()->GetRect();
                width = rcParent.Width();
                height = rcParent.Height();
            }
            else if(window_ != NULL)
            {
                Base::NRect rcWnd;
                window_->GetRect(rcWnd);
                width = rcWnd.Width();
                height = rcWnd.Height();
            }
            else
            {
                return;
            }

            Base::NSize size = GetAutoSize();

            Base::NRect rcNew;

            if(layout_ & LayoutLeft)
            {
                rcNew.Left = margin_.Left;
                rcNew.Right = rcNew.Left + size.Width;
            }
            else if(layout_ & LayoutRight)
            {
                rcNew.Right = width - margin_.Right;
                rcNew.Left = rcNew.Right - size.Width;
            }
            else if(layout_ & LayoutHCenter)
            {
                rcNew.Left = (width - margin_.Width() - size.Width) / 2;
                rcNew.Right = rcNew.Left + size.Width;
            }
            else if(layout_ & LayoutHFill)
            {
                rcNew.Left = margin_.Left;
                rcNew.Right = width - margin_.Right;
            }

            if(layout_ & LayoutTop)
            {
                rcNew.Top = margin_.Top;
                rcNew.Bottom = rcNew.Top + size.Height;
            }
            else if(layout_ & LayoutBottom)
            {
                rcNew.Bottom = height - margin_.Bottom;
                rcNew.Top = rcNew.Bottom - size.Height;
            }
            else if(layout_ & LayoutVCenter)
            {
                rcNew.Top = (height - margin_.Height() - size.Height) / 2;
                rcNew.Bottom = rcNew.Top + size.Height;
            }
            else if(layout_ & LayoutVFill)
            {
                rcNew.Top = margin_.Top;
                rcNew.Bottom = height - margin_.Bottom;
            }

            SetPosImpl(rcNew.Left, rcNew.Top, true);
            SetSizeImpl(rcNew.Width(), rcNew.Height(), true);
        }
Exemple #10
0
        void NFrameBase::ReLayout()
        {
            if(layout_ == LayoutNone || !IsLayoutable())
                return;

            int width = 0;
            int height = 0;

            if(GetParent() != NULL)
            {
                Base::NRect rcParent = GetParent()->GetRect();
                width = rcParent.Width();
                height = rcParent.Height();
            }
            else if(window_ != NULL)
            {
                Base::NRect rcWnd;
                window_->GetRect(rcWnd);
                width = rcWnd.Width();
                height = rcWnd.Height();
            }
            else
            {
                return;
            }

            Base::NSize size = IsAutoSize() ? GetAutoSize() : frameRect_.GetSize();

            Base::NRect rcNew(frameRect_.Left, frameRect_.Top, frameRect_.Left + size.Width, frameRect_.Top + size.Height);

            if(layout_ & LayoutHFill)
            {
                rcNew.Left = margin_.Left;
                rcNew.Right = width - margin_.Right;
            }
            else if(layout_ & LayoutHCenter)
            {
                size.Width = (minSize_.Width <= 0 || size.Width > minSize_.Width) ? size.Width : minSize_.Width;
                size.Width = (maxSize_.Width <= 0 || size.Width < maxSize_.Width) ? size.Width : maxSize_.Width;
                rcNew.Left = (width - margin_.Width() - size.Width) / 2;
                rcNew.Right = rcNew.Left + size.Width;
            }
            else if(layout_ & LayoutLeft)
            {
                rcNew.Left = margin_.Left;
                rcNew.Right = rcNew.Left + size.Width;
            }
            else if(layout_ & LayoutRight)
            {
                rcNew.Right = width - margin_.Right;
                rcNew.Left = rcNew.Right - size.Width;
            }

            if(layout_ & LayoutVFill)
            {
                rcNew.Top = margin_.Top;
                rcNew.Bottom = height - margin_.Bottom;
            }
            else if(layout_ & LayoutVCenter)
            {
                size.Height = (minSize_.Height <= 0 || size.Height > minSize_.Height) ? size.Height : minSize_.Height;
                size.Height = (maxSize_.Height <= 0 || size.Height < maxSize_.Height) ? size.Height : maxSize_.Height;
                rcNew.Top = (height - margin_.Height() - size.Height) / 2;
                rcNew.Bottom = rcNew.Top + size.Height;
            }
            else if(layout_ & LayoutTop)
            {
                rcNew.Top = margin_.Top;
                rcNew.Bottom = rcNew.Top + size.Height;
            }
            else if(layout_ & LayoutBottom)
            {
                rcNew.Bottom = height - margin_.Bottom;
                rcNew.Top = rcNew.Bottom - size.Height;
            }

            SetPosImpl(rcNew.Left, rcNew.Top, true);
            SetSizeImpl(rcNew.Width(), rcNew.Height(), true);
        }