HRESULT ui::UIListBox::Render(graphics::D3DInteropHelper *pD3DInteropHelper, ID2D1RenderTarget *pRenderTarget) { #ifdef DEBUG_UILISTBOX LOG_ENTER(SEVERITY_LEVEL_DEBUG); #endif m_rectFigure->Render(pD3DInteropHelper, pRenderTarget, 1.0f); FLOAT frameThick = static_cast<FLOAT>(m_colorSet->GetNumberOfColors()); D2D1_RECT_F clipRect = D2D1::RectF(frameThick, frameThick, GetWidth() - frameThick, GetHeight() - frameThick); pRenderTarget->PushAxisAlignedClip(clipRect, D2D1_ANTIALIAS_MODE_PER_PRIMITIVE); if (m_scrollDirection == SCROLL_DIRECTION_HORIZONTAL) { pD3DInteropHelper->PushMatrix(pRenderTarget, D2D1::Matrix3x2F::Translation(-m_displayPositionOffset, 0.0f)); FLOAT x = 0.0f; FLOAT y = m_marginBetweenItems; for (size_t i = 0; i < GetNumberOfElements(); ++i) { auto element = GetElement(i); auto listBoxItem = std::dynamic_pointer_cast<UIListBoxItem>(element); if (listBoxItem.get() != nullptr) { x += m_marginBetweenItems; pD3DInteropHelper->PushMatrix(pRenderTarget, D2D1::Matrix3x2F::Translation(x, y)); listBoxItem->Render(pD3DInteropHelper, pRenderTarget); x += listBoxItem->GetWidth(); pD3DInteropHelper->PopMatrix(pRenderTarget); } } pD3DInteropHelper->PopMatrix(pRenderTarget); } else { pD3DInteropHelper->PushMatrix(pRenderTarget, D2D1::Matrix3x2F::Translation(0.0f, -m_displayPositionOffset)); FLOAT x = m_marginBetweenItems; FLOAT y = 0.0f; for (size_t i = 0; i < GetNumberOfElements(); ++i) { auto element = GetElement(i); auto listBoxItem = std::dynamic_pointer_cast<UIListBoxItem>(element); if (listBoxItem.get() != nullptr) { y += m_marginBetweenItems; pD3DInteropHelper->PushMatrix(pRenderTarget, D2D1::Matrix3x2F::Translation(x, y)); listBoxItem->Render(pD3DInteropHelper, pRenderTarget); y += listBoxItem->GetHeight(); pD3DInteropHelper->PopMatrix(pRenderTarget); } } pD3DInteropHelper->PopMatrix(pRenderTarget); } pRenderTarget->PopAxisAlignedClip(); pD3DInteropHelper->PushMatrix(pRenderTarget, D2D1::Matrix3x2F::Translation(m_scrollBar->GetX(), m_scrollBar->GetY())); CHK_WARN_HRESULT(m_scrollBar->Render(pD3DInteropHelper, pRenderTarget)); pD3DInteropHelper->PopMatrix(pRenderTarget); #ifdef DEBUG_UILISTBOX LOG_LEAVE(SEVERITY_LEVEL_DEBUG); #endif return S_OK; }
void AUScope::AddElementNamesToDict (CFMutableDictionaryRef & inNameDict) { if (HasElementWithName()) { static char string[32]; CFMutableDictionaryRef elementDict = CFDictionaryCreateMutable (NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); CFStringRef str; for (UInt32 i = 0; i < GetNumberOfElements(); ++i) { AUElement * el = GetElement (i); if (el && el->HasName()) { snprintf (string, sizeof(string), "%d", int(i)); str = CFStringCreateWithCString (NULL, string, kCFStringEncodingASCII); CFDictionarySetValue (elementDict, str, el->GetName()); CFRelease (str); } } snprintf (string, sizeof(string), "%d", int(mScope)); str = CFStringCreateWithCString (NULL, string, kCFStringEncodingASCII); CFDictionarySetValue (inNameDict, str, elementDict); CFRelease (str); CFRelease (elementDict); } }
//_____________________________________________________________________________ // bool AUScope::HasElementWithName () const { for (UInt32 i = 0; i < GetNumberOfElements(); ++i) { AUElement * el = const_cast<AUScope*>(this)->GetElement (i); if (el && el->HasName()) { return true; } } return false; }
/** * Implements the picking process */ std::pair<mitk::TubeGraph::TubeDescriptorType, mitk::TubeElement *> mitk::TubeGraphPicker::GetPickedTube( const Point3D pickedPosition) { if (!m_TubeGraph) { MITK_ERROR << "mitk::TubeGraphPicker: No tube graph available. Please set an input!" << std::endl; mitk::TubeElement *nullPointer = nullptr; return std::pair<mitk::TubeGraph::TubeDescriptorType, mitk::TubeElement *>(TubeGraph::ErrorId, nullPointer); } m_WorldPosition = pickedPosition; Point3D currentPosition; ScalarType closestDistance = itk::NumericTraits<ScalarType>::max(); ScalarType currentDistance = itk::NumericTraits<ScalarType>::max(); float currentRadius = 0; TubeGraph::TubeDescriptorType currentTubeId(TubeGraph::ErrorId); TubeGraph::TubeDescriptorType tubeId(TubeGraph::ErrorId); TubeElement *tubeElement; // iterate over all edges and find the edge, which element is near by the clicked point std::vector<mitk::TubeGraphEdge> allEdges = m_TubeGraph->GetVectorOfAllEdges(); for (auto edge = allEdges.begin(); edge != allEdges.end(); ++edge) { std::pair<mitk::TubeGraphVertex, mitk::TubeGraphVertex> soureTargetPair = m_TubeGraph->GetVerticesOfAnEdge(m_TubeGraph->GetEdgeDescriptor(*edge)); currentTubeId = TubeGraph::TubeDescriptorType(m_TubeGraph->GetVertexDescriptor(soureTargetPair.first), m_TubeGraph->GetVertexDescriptor(soureTargetPair.second)); // check if the tube is visible, if not pass this tube. User can not choose a tube, which he can't see if (m_TubeGraphProperty->IsTubeVisible(currentTubeId)) { std::vector<mitk::TubeElement *> allElements = edge->GetElementVector(); for (unsigned int index = 0; index < edge->GetNumberOfElements(); index++) { currentPosition = allElements[index]->GetCoordinates(); if (dynamic_cast<mitk::CircularProfileTubeElement *>(allElements[index])) currentRadius = ((dynamic_cast<mitk::CircularProfileTubeElement *>(allElements[index]))->GetDiameter()) / 2; else currentRadius = 0; // calculate point->point distance currentDistance = m_WorldPosition.EuclideanDistanceTo(currentPosition); if (currentDistance < closestDistance && (currentDistance - currentRadius) < 1.0) { closestDistance = currentDistance; tubeId = currentTubeId; tubeElement = allElements[index]; } } } } std::pair<mitk::TubeGraph::TubeDescriptorType, mitk::TubeElement *> pickedTubeWithElement(tubeId, tubeElement); return pickedTubeWithElement; }
void ui::UIRadioButtonGroup::NotifyFocusObtained(const std::shared_ptr<UIBase> &uiBase) { for (size_t i = 0; i < GetNumberOfElements(); ++i) { auto child = GetElement(i); if (uiBase != child) { child->LostFocus(); } } if (!GetParentContainer().expired()) { GetParentContainer().lock()->NotifyFocusObtained(shared_from_this()); } }
void ui::UIListBox::NotifyScrollPositionChanged(FLOAT position) { if (0.0f <= position && position <= (GetNumberOfElements() - 1.0f)) { switch (m_scrollDirection) { case ui::UIListBox::SCROLL_DIRECTION_HORIZONTAL: m_displayPositionOffset = (m_itemWidth + m_marginBetweenItems) * position; break; case ui::UIListBox::SCROLL_DIRECTION_VERTICAL: m_displayPositionOffset = (m_itemHeight + m_marginBetweenItems) * position; break; } } }
ui::UIRadioButtonGroup::UIRadioButtonGroup(void) { AddBeforeAddElementCallback([&](std::shared_ptr<UIBase> element) -> bool { auto radioButton = std::dynamic_pointer_cast<UIRadioButton>(element); if (radioButton != nullptr) { radioButton->SetIndex(GetNumberOfElements()); radioButton->SetRadioButtonGroup(shared_from_this()); return true; } else { return false; } }); SetFocusable(true); }
HRESULT ui::UIRadioButtonGroup::Render(graphics::D3DInteropHelper *pD3DInteropHelper, ID2D1RenderTarget *pRenderTarget) { for (size_t i = 0; i < GetNumberOfElements(); ++i) { auto element = std::dynamic_pointer_cast<UIRadioButton>(GetElement(i)); D2D1_MATRIX_3X2_F origMatrix; pRenderTarget->GetTransform(&origMatrix); D2D1_MATRIX_3X2_F matrix = origMatrix * D2D1::Matrix3x2F::Translation(element->GetX(), element->GetY()); pRenderTarget->SetTransform(matrix); HRESULT hr = element->Render(pD3DInteropHelper, pRenderTarget); if (FAILED(hr)) { LOG(SEVERITY_LEVEL_ERROR) << L"render a child element failed, index = " << i << L", hr = " << hr; } pRenderTarget->SetTransform(origMatrix); } return S_OK; }
void Value::ManagedAllocate() { assert(needsManagedAllocation() && "Does not need managed allocation"); void* dtorFunc = 0; clang::QualType DtorType = getType(); // For arrays we destruct the elements. if (const clang::ConstantArrayType* ArrTy = llvm::dyn_cast<clang::ConstantArrayType>(DtorType.getTypePtr())) { DtorType = ArrTy->getElementType(); } if (const clang::RecordType* RTy = DtorType->getAs<clang::RecordType>()) dtorFunc = m_Interpreter->compileDtorCallFor(RTy->getDecl()); const clang::ASTContext& ctx = getASTContext(); unsigned payloadSize = ctx.getTypeSizeInChars(getType()).getQuantity(); char* alloc = new char[AllocatedValue::getPayloadOffset() + payloadSize]; AllocatedValue* allocVal = new (alloc) AllocatedValue(dtorFunc, payloadSize, GetNumberOfElements()); m_Storage.m_Ptr = allocVal->getPayload(); }
void Value::ManagedAllocate(Interpreter* interp) { assert(interp && "This type requires the interpreter for value allocation"); void* dtorFunc = 0; clang::QualType DtorType = getType(); // For arrays we destruct the elements. if (const clang::ConstantArrayType* ArrTy = llvm::dyn_cast<clang::ConstantArrayType>(DtorType.getTypePtr())) { DtorType = ArrTy->getElementType(); } if (const clang::RecordType* RTy = DtorType->getAs<clang::RecordType>()) dtorFunc = GetDtorWrapperPtr(RTy->getDecl(), *interp); const clang::ASTContext& ctx = interp->getCI()->getASTContext(); unsigned payloadSize = ctx.getTypeSizeInChars(getType()).getQuantity(); char* alloc = new char[AllocatedValue::getPayloadOffset() + payloadSize]; AllocatedValue* allocVal = new (alloc) AllocatedValue(dtorFunc, payloadSize, GetNumberOfElements()); m_Storage.m_Ptr = allocVal->getPayload(); }
HRESULT ui::UIRadioButtonGroup::CreateDeviceDependentResources(graphics::D3DInteropHelper *pD3DInteropHelper, ID2D1RenderTarget *pRenderTarget) { CHK_WARN_HRESULT(UIContainer::CreateDeviceDependentResources(pD3DInteropHelper, pRenderTarget)); FLOAT y = 0.0f; for (size_t i = 0; i < GetNumberOfElements(); ++i) { auto radioButton = std::dynamic_pointer_cast<UIRadioButton>(GetElement(i)); UISize size = radioButton->GetPreferredSize(); #ifdef DEBUG_UIRADIOBUTTONGROUP LOG(SEVERITY_LEVEL_DEBUG) << L"preferred size = " << size; #endif radioButton->SetBounds(0.0f, y, GetWidth(), size.height); y += radioButton->GetHeight() + MARGIN_BUTTONS; } ui::UIRectangle bounds = GetBounds(); if (bounds.height < y) { bounds.height = y; SetBounds(bounds); } return S_OK; }
//_____________________________________________________________________________ // bool AUScope::RestoreElementNames (CFDictionaryRef& inNameDict) { static char string[32]; //first we have to see if we have enough elements and if not create them bool didAddElements = false; unsigned int maxElNum = 0; int dictSize = CFDictionaryGetCount(inNameDict); CFStringRef * keys = (CFStringRef*)CA_malloc (dictSize * sizeof (CFStringRef)); CFDictionaryGetKeysAndValues (inNameDict, reinterpret_cast<const void**>(keys), NULL); for (int i = 0; i < dictSize; i++) { unsigned int intKey; CFStringGetCString (keys[i], string, 32, kCFStringEncodingASCII); sscanf (string, "%u", &intKey); if (UInt32(intKey) > maxElNum) maxElNum = intKey; } if (maxElNum >= GetNumberOfElements()) { SetNumberOfElements (maxElNum+1); didAddElements = true; } // OK, now we have the number of elements that we need - lets restate their names for (int i = 0; i < dictSize; i++) { CFStringRef elName = reinterpret_cast<CFStringRef>(CFDictionaryGetValue (inNameDict, keys[i])); int intKey; CFStringGetCString (keys[i], string, 32, kCFStringEncodingASCII); sscanf (string, "%d", &intKey); GetElement (intKey)->SetName (elName); } free (keys); return didAddElements; }
unsigned int GetSize() { return GetNumberOfElements(); }
HRESULT ui::UIListBox::Initialize(graphics::D3DInteropHelper *pD3DInteropHelper) { #ifdef DEBUG_UILISTBOX LOG_ENTER(SEVERITY_LEVEL_DEBUG); #endif assert(GetWidth() > 0.0f); assert(GetHeight() > 0.0f); ui::UIListBoxItem::LAYOUT_DIRECTION layoutDirection = ui::UIListBoxItem::LAYOUT_DIRECTION_VERTICAL; switch (m_scrollDirection) { case ui::UIListBox::SCROLL_DIRECTION_HORIZONTAL: layoutDirection = ui::UIListBoxItem::LAYOUT_DIRECTION_VERTICAL; m_itemHeight = GetHeight(); if (m_preferredTextAreaSize.height == 0.0f) { m_preferredTextAreaSize.height = GetHeight() - m_preferredBitmapSize.height - m_marginBetweenBitmapAndText; } if (m_preferredTextAreaSize.width == 0.0f) { m_preferredTextAreaSize.width = m_preferredBitmapSize.width * 3.0f; } m_itemWidth = m_preferredTextAreaSize.width; break; case ui::UIListBox::SCROLL_DIRECTION_VERTICAL: layoutDirection = ui::UIListBoxItem::LAYOUT_DIRECTION_HORIZONTAL; m_itemWidth = GetWidth(); if (m_preferredTextAreaSize.width == 0.0f) { m_preferredTextAreaSize.width = GetWidth() - m_preferredBitmapSize.width - m_marginBetweenBitmapAndText; } if (m_preferredTextAreaSize.height == 0.0f) { m_preferredTextAreaSize.height = m_preferredBitmapSize.height; } m_itemHeight = m_preferredTextAreaSize.height; break; } for (size_t i = 0; i < GetNumberOfElements(); ++i) { auto element = GetElement(i); auto listBoxItem = std::dynamic_pointer_cast<UIListBoxItem>(element); if (listBoxItem.get() != nullptr) { listBoxItem->SetLayoutDirection(layoutDirection); listBoxItem->SetPreferredBitmapSize(m_preferredBitmapSize); listBoxItem->SetPreferredTextAreaSize(m_preferredTextAreaSize); listBoxItem->SetBounds(0.0f, 0.0f, m_itemWidth, m_itemHeight); } } CHK_WARN_HRESULT(UIContainer::Initialize(pD3DInteropHelper)); auto frameDecorator = std::make_shared<graphics::decorator::FrameDecorator>(); frameDecorator->SetColorSet(m_colorSet); for (size_t i = 0; i < m_colorSet->GetNumberOfColors(); ++i) { frameDecorator->AddFrame(graphics::decorator::Frame(i)); } m_rectFigure->AddDecorator(frameDecorator); m_rectFigure->SetX(0.0f); m_rectFigure->SetY(0.0f); m_rectFigure->SetWidth(GetWidth()); m_rectFigure->SetHeight(GetHeight()); m_rectFigure->SetColor(graphics::color::ColorValue(graphics::color::ColorValue::COLOR_TYPE_RGBA, 0x222222, 1.0f), graphics::color::COLOR_PATTERN_FLAT); CHK_WARN_HRESULT(m_rectFigure->Initialize(pD3DInteropHelper)); m_scrollBar->SetParentContainer(shared_from_this()); m_scrollBar->SetMinValue(0.0f); m_scrollBar->SetMaxValue(GetNumberOfElements() - 1.0f); m_scrollBar->SetPageSize(1.0f); if (m_scrollBar->GetCurrentValue() < m_scrollBar->GetMinValue() || m_scrollBar->GetCurrentValue() > m_scrollBar->GetMaxValue() - m_scrollBar->GetPageSize()) { m_scrollBar->SetCurrentValue(0.0f); } FLOAT frameThick = static_cast<FLOAT>(m_colorSet->GetNumberOfColors()); if (m_scrollDirection == ui::UIListBox::SCROLL_DIRECTION_HORIZONTAL) { m_scrollBar->SetDirection(ui::UIScrollBar::SCROLLBAR_DIRECTION_HORIZONTAL); m_scrollBar->SetBounds(frameThick + m_scrollBarMarginFromSide, GetHeight() - m_scrollBarThick - frameThick - m_scrollBarMarginFromSide, GetWidth() - (frameThick + m_scrollBarMarginFromSide) * 2, m_scrollBarThick); } else { m_scrollBar->SetDirection(ui::UIScrollBar::SCROLLBAR_DIRECTION_VERTICAL); m_scrollBar->SetBounds(GetWidth() - m_scrollBarThick - frameThick - m_scrollBarMarginFromSide, frameThick + m_scrollBarMarginFromSide, m_scrollBarThick, GetHeight() - (frameThick + m_scrollBarMarginFromSide) * 2); } m_scrollBar->AddPositionChangedCallback([&](FLOAT position) { NotifyScrollPositionChanged(position); }); CHK_FATAL_HRESULT(m_scrollBar->Initialize(pD3DInteropHelper)); #ifdef DEBUG_UILISTBOX LOG_LEAVE(SEVERITY_LEVEL_DEBUG); #endif return S_OK; }