void gwinSetVisible(GHandle gh, bool_t visible) { if (visible) { if (!(gh->flags & GWIN_FLG_VISIBLE)) { gh->flags |= (GWIN_FLG_VISIBLE|GWIN_FLG_SYSVISIBLE|GWIN_FLG_NEEDREDRAW|GWIN_FLG_BGREDRAW); RedrawPending |= DOREDRAW_VISIBLES; TriggerRedraw(); } } else { if ((gh->flags & GWIN_FLG_VISIBLE)) { gh->flags &= ~(GWIN_FLG_VISIBLE|GWIN_FLG_SYSVISIBLE); gh->flags |= (GWIN_FLG_NEEDREDRAW|GWIN_FLG_BGREDRAW); RedrawPending |= DOREDRAW_INVISIBLES; TriggerRedraw(); } } }
const Vec2I& ImageBox::SetTextureAtlasRegion(const char* atlas, const char* region) { mTextureAtlas = Renderer::GetInstance().GetTextureAtlas(atlas); if (mTextureAtlas) { if (mImageFixedSize) { DrawAsFixedSize(); } SAMPLER_DESC sdesc; sdesc.Filter = TEXTURE_FILTER_MIN_MAG_MIP_POINT; TriggerRedraw(); mAtlasRegion = mTextureAtlas->GetRegion(region); if (!mAtlasRegion) { mTexture = 0; mUIObject->GetMaterial()->SetTexture(TexturePtr(), BINDING_SHADER_PS, 0, sdesc); mUIObject->ClearTexCoord(); Error("Cannot find the region %s in the atlas %s", region, atlas); return Vec2I::ZERO; } // need to set to material. matarial will hold its reference counter mTexture = mTextureAtlas->GetTexture(); mUIObject->GetMaterial()->SetTexture(mTexture, BINDING_SHADER_PS, 0, sdesc); Vec2 texcoords[4]; mAtlasRegion->GetQuadUV(texcoords); mUIObject->SetTexCoord(texcoords, 4); DWORD colors[4] = {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}; mUIObject->SetColors(colors, 4); mAtlasRegions.clear(); return mAtlasRegion->GetSize(); } return Vec2I::ZERO; }
void TextBox::SetText(const wchar_t* szText) { __super::SetText(szText); if (mMatchHeight) { unsigned height = GetTextBoxHeight(); ChangeSizeY(height); } TriggerRedraw(); }
void _gwinUpdate(GHandle gh) { // Only redraw if visible if (!(gh->flags & GWIN_FLG_SYSVISIBLE)) return; // Mark for redraw gh->flags |= GWIN_FLG_NEEDREDRAW; RedrawPending |= DOREDRAW_VISIBLES; // Asynchronous redraw TriggerRedraw(); }
void gwinSetVisible(GHandle gh, bool_t visible) { if (visible) { // Mark us as visible gh->flags |= GWIN_FLG_VISIBLE; } else { // Mark us as not visible gh->flags &= ~GWIN_FLG_VISIBLE; } // Fix everything up _gwinRippleVisibility(); if (RedrawPending) TriggerRedraw(); }
void TextField::OnFocusLost() { UIManager::GetInstance().DirtyRenderList(mHwndId); auto mani = UIManager::GetInstance().GetTextManipulator(); auto propertyList = IsInPropertyList(); if (propertyList) { auto parent = GetParent(); assert(parent && parent->GetType() == ComponentType::ListItem); ListItem* valueItem = (ListItem*)parent.get(); auto index = valueItem->GetRowIndex(); propertyList->RemoveHighlight(index); auto uiEditor = UIManager::GetInstance().GetUIEditor(); auto editingUI = uiEditor->GetCurSelected(); std::string key, value; propertyList->GetCurKeyValue(key, value); if (editingUI) { char buf[UIManager::PROPERTY_BUF_SIZE] = { 0 }; auto prop = UIProperty::IsUIProperty(key.c_str()); if (prop != UIProperty::COUNT) { auto got = editingUI->GetProperty(prop, buf, UIManager::PROPERTY_BUF_SIZE, false); if (got) SetText(AnsiToWide(buf)); } else { auto e = UIEvents::IsUIEvents(key.c_str()); if (e != UIEvents::EVENT_NUM) { auto szEvent = editingUI->GetEvent(e); editingUI->SetEvent(e, szEvent); } } } } mani->SetText(0); mani->RemoveObserver(ITextManipulatorObserver::Default, std::dynamic_pointer_cast<ITextManipulatorObserver>(mSelfPtr.lock())); TriggerRedraw(); }
/** * Triggers thread shutdown. Call join() after this to wait * synchronously for the thread to exit. */ void BeginStop() { SuspensibleThread::BeginStop(); TriggerRedraw(); }
void _gwinFlushRedraws(GRedrawMethod how) { GHandle gh; // Do we really need to do anything? if (!RedrawPending) return; // Obtain the drawing lock if (how == REDRAW_WAIT) gfxSemWait(&gwinsem, TIME_INFINITE); else if (how == REDRAW_NOWAIT && !gfxSemWait(&gwinsem, TIME_IMMEDIATE)) // Someone is drawing - They will do the redraw when they are finished return; // Do loss of visibility first while ((RedrawPending & DOREDRAW_INVISIBLES)) { RedrawPending &= ~DOREDRAW_INVISIBLES; // Catch new requests for(gh = gwinGetNextWindow(0); gh; gh = gwinGetNextWindow(gh)) { if ((gh->flags & (GWIN_FLG_NEEDREDRAW|GWIN_FLG_SYSVISIBLE)) != GWIN_FLG_NEEDREDRAW) continue; // Do the redraw #if GDISP_NEED_CLIP gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height); _GWINwm->vmt->Redraw(gh); gdispGUnsetClip(gh->display); #else _GWINwm->vmt->Redraw(gh); #endif // Postpone further redraws #if !GWIN_REDRAW_IMMEDIATE && !GWIN_REDRAW_SINGLEOP if (how == REDRAW_NOWAIT) { RedrawPending |= DOREDRAW_INVISIBLES; TriggerRedraw(); goto releaselock; } #endif } } // Do the visible windows next while ((RedrawPending & DOREDRAW_VISIBLES)) { RedrawPending &= ~DOREDRAW_VISIBLES; // Catch new requests for(gh = gwinGetNextWindow(0); gh; gh = gwinGetNextWindow(gh)) { if ((gh->flags & (GWIN_FLG_NEEDREDRAW|GWIN_FLG_SYSVISIBLE)) != (GWIN_FLG_NEEDREDRAW|GWIN_FLG_SYSVISIBLE)) continue; // Do the redraw #if GDISP_NEED_CLIP gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height); _GWINwm->vmt->Redraw(gh); gdispGUnsetClip(gh->display); #else _GWINwm->vmt->Redraw(gh); #endif // Postpone further redraws (if there are any and the options are set right) #if !GWIN_REDRAW_IMMEDIATE && !GWIN_REDRAW_SINGLEOP if (how == REDRAW_NOWAIT) { while((gh = gwinGetNextWindow(gh))) { if ((gh->flags & (GWIN_FLG_NEEDREDRAW|GWIN_FLG_SYSVISIBLE)) == (GWIN_FLG_NEEDREDRAW|GWIN_FLG_SYSVISIBLE)) { RedrawPending |= DOREDRAW_VISIBLES; TriggerRedraw(); break; } } goto releaselock; } #endif } } #if !GWIN_REDRAW_IMMEDIATE && !GWIN_REDRAW_SINGLEOP releaselock: #endif // Release the lock if (how == REDRAW_WAIT || how == REDRAW_NOWAIT) gfxSemSignal(&gwinsem); }
bool TextField::OnInputFromHandler(IInputInjectorPtr injector) { if (!mEnable) return false; bool mouseIn = __super::OnInputFromHandler(injector); if (!mVisibility.IsVisible() || !GetFocus(false)) return mouseIn; if (injector->IsValid(InputDevice::Keyboard)) { auto ch = injector->GetChar(); if (ch == VK_TAB) { if (IsKeyboardFocused()) { auto listbox = IsInListBox(); if (listbox) { injector->PopChar(); if (injector->IsKeyDown(VK_SHIFT)) { listbox->IterateItem(false, true); } else { listbox->IterateItem(true, true); } } else { OnEvent(UIEvents::EVENT_ENTER); } } } else if (ch == VK_RETURN) { bool succ = false; if (OnEvent(UIEvents::EVENT_ENTER)) { succ = true; } else { auto listbox = IsInListBox(); if (listbox) { auto eventHandler = dynamic_cast<EventHandler*>(listbox.get()); if (eventHandler) { if (eventHandler->OnEvent(UIEvents::EVENT_ENTER)) { succ = true; } } } } if (succ) { injector->PopChar(); injector->Invalidate(InputDevice::Keyboard); TriggerRedraw(); } } else if (ch == VK_ESCAPE) { auto prop = IsInPropertyList(); if (prop) { prop->MoveFocusToKeyItem(); injector->PopChar(); injector->Invalidate(InputDevice::Keyboard); } } else { UIManager::GetInstance().GetTextManipulator()->ConsumeInput(injector, mouseIn); } } return mouseIn; }
void TextField::SelectAll() { UIManager::GetInstance().GetTextManipulator()->SelectAll(); TriggerRedraw(); }
void TextField::OnTextChanged(TextManipulator* mani) { TriggerRedraw(); SetText(mTextw.c_str()); mTextBeforeTranslated.clear(); }
void TextField::OnCursorPosChanged(TextManipulator* mani) { TriggerRedraw(); int cursorPos = mani->GetCursorPos(); Vec2I textStartWPos = mUIObject->GetTextStartWPos(); textStartWPos.x += mCursorOffset; if (mani->IsHighlighting()) { auto start = mani->GetHighlightStart(); auto end = cursorPos; if (start > end) { std::swap(start, end); } if (end - start > 0) { auto font = Renderer::GetInstance().GetFontWithHeight(mTextSize); if (font) { float width = font->GetTextWidth( ((const char*)mTextw.c_str()) + (start * 2), (end - start) * 2); float leftGap = font->GetTextWidth( (const char*)mTextw.c_str(), start * 2); KeyboardCursor::GetInstance().SetSize(Vec2I((int)width, (int)mTextSize)); KeyboardCursor::GetInstance().SetPos( Vec2I(textStartWPos.x + (int)leftGap, textStartWPos.y - Round(mTextSize)) ); } } else { auto font = Renderer::GetInstance().GetFontWithHeight(mTextSize); float aWidth = font->GetTextWidth((const char*)AnsiToWide("A", 1), 2); Vec2I cursorSize(Round(aWidth), 2); KeyboardCursor::GetInstance().SetSize(Vec2I((int)1, (int)mTextSize)); KeyboardCursor::GetInstance().SetPos( Vec2I(textStartWPos.x, textStartWPos.y - Round(mTextSize)) ); } } else { auto font = Renderer::GetInstance().GetFontWithHeight(mTextSize); float aWidth = font->GetTextWidth((const char*)AnsiToWide("A", 1), 2); Vec2I cursorSize(Round(aWidth), 2); KeyboardCursor::GetInstance().SetSize(cursorSize); float width = font->GetTextWidth( (const char*)mTextw.c_str(), cursorPos * 2); Vec2I visualCursorPos(textStartWPos.x + Round(width), textStartWPos.y - WinBase::BOTTOM_GAP - 2); KeyboardCursor::GetInstance().SetPos(visualCursorPos); // check region // right Rect region = GetScissorRegion(); if (region.right - mTextGap.y < visualCursorPos.x + cursorSize.x) { int offset = visualCursorPos.x + cursorSize.x - (region.right - mTextGap.y); mCursorOffset -= offset; mUIObject->SetTextOffsetForCursorMovement(Vec2I(mCursorOffset, 0)); KeyboardCursor::GetInstance().SetPos(Vec2I(visualCursorPos.x - offset, visualCursorPos.y)); } else { if (region.left + mTextGap.x > visualCursorPos.x) { int offset = region.left + mTextGap.x - visualCursorPos.x; mCursorOffset += offset; mUIObject->SetTextOffsetForCursorMovement(Vec2I(mCursorOffset, 0)); KeyboardCursor::GetInstance().SetPos(Vec2I(visualCursorPos.x + offset, visualCursorPos.y)); } } } }