mitk::pa::Volume::Volume(double* data, unsigned int xDim, unsigned int yDim, unsigned int zDim, double spacing) { MITK_INFO << "Initialized by data*"; if (data == nullptr) mitkThrow() << "You may not initialize a mitk::Volume with a nullptr"; m_InternalMitkImage = mitk::Image::New(); auto* dimensions = new unsigned int[NUMBER_OF_SPATIAL_DIMENSIONS]; dimensions[0] = yDim; dimensions[1] = xDim; dimensions[2] = zDim; m_XDim = xDim; m_YDim = yDim; m_ZDim = zDim; mitk::PixelType pixelType = mitk::MakeScalarPixelType<double>(); m_InternalMitkImage->Initialize(pixelType, NUMBER_OF_SPATIAL_DIMENSIONS, dimensions); m_InternalMitkImage->SetImportVolume(data, Image::ImportMemoryManagementType::CopyMemory); SetSpacing(spacing); m_FastAccessDataPointer = GetData(); delete data; }
FileDialog(TYPE t, const char *title): Gui::VBox() { m_type = t; m_title = title; SetTransparency(false); SetSpacing(5.0f); SetSizeRequest(FLT_MAX, FLT_MAX); }
HierTreeCtrl::HierTreeCtrl(wxWindow* parent, const long id) : wxTreeCtrl(parent, id, wxDefaultPosition, wxDefaultSize, wxTR_HAS_BUTTONS|wxTR_LINES_AT_ROOT) { contextMenu = new wxMenu(); dirMenuItem = new wxMenuItem(contextMenu, wxNewId(), _("Create Directory"), _("Create a new file directory."), wxITEM_NORMAL); contextMenu->Append(dirMenuItem); resourceMenuItem = new wxMenuItem(contextMenu, wxNewId(), _("Create Resource"), _("Create a new resource in the project."), wxITEM_NORMAL); contextMenu->Append(resourceMenuItem); fileMenuItem = new wxMenuItem(contextMenu, wxNewId(), _("Add Files"), _("Add external files to the project."), wxITEM_NORMAL); contextMenu->Append(fileMenuItem); editMenuItem = new wxMenuItem(contextMenu, wxNewId(), _("Edit"), _("Edit the file or resource."), wxITEM_NORMAL); contextMenu->Append(editMenuItem); renameMenuItem = new wxMenuItem(contextMenu, wxNewId(), _("Rename"), _("Rename the file or directory."), wxITEM_NORMAL); contextMenu->Append(renameMenuItem); deleteMenuItem = new wxMenuItem(contextMenu, wxNewId(), _("Delete"), _("Delete the file from the project."), wxITEM_NORMAL); contextMenu->Append(deleteMenuItem); filextMenuItem = new wxMenuItem(contextMenu, wxNewId(), _("Show File Extensions"), _("Hide or show the extensions of files."), wxITEM_NORMAL); contextMenu->Append(filextMenuItem); Connect(this->GetId(), wxEVT_COMMAND_TREE_BEGIN_DRAG, (wxObjectEventFunction)&HierTreeCtrl::OnBeginDrag); Connect(this->GetId(), wxEVT_COMMAND_TREE_END_DRAG, (wxObjectEventFunction)&HierTreeCtrl::OnEndDrag); Connect(dirMenuItem->GetId(), wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&HierTreeCtrl::OnCreateDirectory); Connect(fileMenuItem->GetId(), wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&HierTreeCtrl::OnCreateFile); Connect(deleteMenuItem->GetId(), wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&HierTreeCtrl::OnDelete); Connect(renameMenuItem->GetId(), wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&HierTreeCtrl::OnRename); Connect(this->GetId(), wxEVT_RIGHT_UP, wxMouseEventHandler(HierTreeCtrl::OnContextMenu)); SetSpacing(10); }
std::shared_ptr<sfg::Widget> BasicSubmarine::UI::setupUI() { auto navigationBox = sfg::Box::Create(sfg::Box::Orientation::VERTICAL); auto controlsBox = sfg::Box::Create(sfg::Box::Orientation::HORIZONTAL); auto labels = sfg::Box::Create(sfg::Box::Orientation::VERTICAL); auto spinBoxes = sfg::Box::Create(sfg::Box::Orientation::VERTICAL); mHeading = sfg::SpinButton::Create(0.f, 359.f, 1.f); mVelocity = sfg::SpinButton::Create(0.f, 20.f, 1.f); mPitch = sfg::SpinButton::Create(-20, 20.f, 1.f); labels->Pack(sfg::Label::Create("Heading (deg):")); labels->Pack(sfg::Label::Create("Velocity (kts):")); labels->Pack(sfg::Label::Create("Pitch (deg):")); spinBoxes->Pack(mHeading); spinBoxes->Pack(mVelocity); spinBoxes->Pack(mPitch); labels->SetSpacing(20.f); spinBoxes->SetSpacing(20.f); controlsBox->Pack(labels); controlsBox->Pack(spinBoxes); navigationBox->Pack(controlsBox, false, false); navigationBox->SetSpacing(20.f); mLocation = sfg::Label::Create("Location here"); auto locationAndSonar = sfg::Box::Create(sfg::Box::Orientation::HORIZONTAL); locationAndSonar->Pack(mLocation, false, false); mWaterfall = WaterfallDisplay::Create(); locationAndSonar->Pack(mWaterfall); navigationBox->Pack(locationAndSonar); mWaterfall->RequestResize(); return navigationBox; }
LabeledCheckBox::LabeledCheckBox(const char* label, BMessage* message, BMessenger target) : GroupView(B_HORIZONTAL), fCheckBox(new CheckBox(message, target)) { SetSpacing(8, 0); AddChild(fCheckBox); if (label) AddChild(new StringView(label)); }
livre::MemoryUnitPtr sample( const livre::LODNode& node, const livre::VolumeInformation& info ) const { // called from multiple render threads, only have one update running lunchbox::ScopedWrite mutex( _lock ); EventSourcePtr loader = source->getEventSource(); const uint32_t timeStep = node.getNodeId().getTimeStep(); loader->setTime( timeStep ); const vmml::Vector3i& voxels = info.maximumBlockSize; ByteVolume::SizeType vSize; vSize[0] = voxels[0]; vSize[1] = voxels[1]; vSize[2] = voxels[2]; ByteVolume::RegionType region; region.SetSize( vSize ); // Real-world coordinate setup const AABBf& bbox = source->getBoundingBox(); const Vector3f& baseSpacing = ( bbox.getSize() + _borders ) / info.voxels; const int32_t levelFromBottom = info.rootNode.getDepth() - 1 - node.getRefLevel(); const float spacingFactor = 1 << levelFromBottom; ByteVolume::SpacingType spacing; spacing[0] = baseSpacing.find_max() * spacingFactor; spacing[1] = spacing[0]; spacing[2] = spacing[0]; const Vector3f& offset = ( bbox.getMin() - _borders / 2.0f ) + node.getRelativePosition() * Vector3f( bbox.getSize() + _borders ); ByteVolume::PointType origin; origin[0] = offset[0]; origin[1] = offset[1]; origin[2] = offset[2]; auto volume = source->GetOutput(); volume->SetRegions( region ); volume->SetSpacing( spacing ); volume->SetOrigin( origin ); source->Modified(); scaler.Update(); const size_t size = voxels[0] * voxels[1] * voxels[2] * info.compCount * info.getBytesPerVoxel(); return livre::MemoryUnitPtr( new livre::AllocMemoryUnit( scaler.GetOutput()->GetBufferPointer(), size )); }
void GNC::GCS::IStudyContext::RecalibrateImage(const int indice, double spacing[3], double origin[3]) { if (indice == ActiveFileIndex) { Loader->SetOutputOrigin(origin); Loader->SetOutputSpacing(spacing); Viewer->SetupPipeline(); } SetSpacing(indice, spacing[0], spacing[1], spacing[2]); }
LabeledRadioButton::LabeledRadioButton(const char* label, BMessage* message, BMessenger target) : GroupView(B_HORIZONTAL), fRadioButton(new RadioButton(message, target)) { SetSpacing(8, 0); AddChild(fRadioButton); if (label) AddChild(new StringView(label)); }
pawsNumbersPromptWindow::pawsNumbersPromptWindow() { editBox = NULL; scrollBar = NULL; action = NULL; SetBoundaries(0, 0); lastValidText.Clear(); SetSpacing(5); factory = "pawsNumbersPromptWindow"; }
status_t FFont::Unflatten(type_code c, const void *buf, ssize_t size) { if( c != FONT_TYPE ) return B_BAD_TYPE; // Make sure buffer contains all data. If we later want // to add new attributes, we can make a more sophisticated // check to allow partial structures. if( size < sizeof(flat_font_data) ) return B_BAD_VALUE; // Easy reference to the buffer. flat_font_data* fdat = (flat_font_data*)buf; // Initialize from default font, just in case. *this = FFont(); // Set up family and style for font. SetFamilyAndStyle(fdat->family,fdat->style); // This is used as a temporary when byte-swapping floats. // Note that this assumes a float is 4 bytes. union { uint32 aslong; float asfloat; } swap; // Byte-swap size, shear, and rotation out of the flattened // structure. This is written for clarity more than speed, // since the additional overhead will be entirely subsumed // by everything else going on. swap.asfloat = fdat->size; swap.aslong = ntohl(swap.aslong); SetSize(swap.asfloat); swap.asfloat = fdat->shear; swap.aslong = ntohl(swap.aslong); SetShear(swap.asfloat); swap.asfloat = fdat->rotation; swap.aslong = ntohl(swap.aslong); SetRotation(swap.asfloat); // Byte-swap the remaining data from the flattened structure. SetFlags(ntohl(fdat->flags)); SetFace(ntohs(fdat->face)); SetSpacing(fdat->spacing); SetEncoding(fdat->encoding); SetMask(ntohl(fdat->mask)); return B_NO_ERROR; }
static mitk::SlicedGeometry3D::Pointer createSlicedGeometry(const mitk::Point3D &origin, const mitk::Vector3D &spacing, int numberOfSlices) { auto slicedGeometry = mitk::SlicedGeometry3D::New(); slicedGeometry->InitializeSlicedGeometry(static_cast<unsigned int>(numberOfSlices)); slicedGeometry->SetOrigin(origin); slicedGeometry->SetSpacing(spacing); for (int i = 0; i < numberOfSlices; ++i) { auto planeGeometry = createPlaneGeometry(); slicedGeometry->SetPlaneGeometry(planeGeometry, i); } return slicedGeometry; }
vtkSmartPointer<vtkUniformGrid> FlowAnalysis::vtkMakeGrid(){ auto grid=vtkSmartPointer<vtkUniformGrid>::New(); Vector3r cellSize3=Vector3r::Constant(cellSize); // if data are in cells, we need extra items along each axes, and shift the origin by half-cell down if(cellData) { grid->SetDimensions((boxCells+Vector3i::Ones()).eval().data()); Vector3r origin=(box.min()-.5*cellSize3); grid->SetOrigin(origin.data()); } else { grid->SetDimensions(boxCells.data()); grid->SetOrigin(box.min().data()); } grid->SetSpacing(cellSize,cellSize,cellSize); return grid; }
BOOL CCharacterSpacingDialog::OnInitDialog() { // Do default OnInitDialog. CPmwDialog::OnInitDialog(); // Get the rect for our preview window. CWnd* pPreview = GetDlgItem(IDC_PREVIEW); if (pPreview != NULL) { pPreview->GetWindowRect(&m_crFullPreview); pPreview->ScreenToClient(&m_crFullPreview); m_crPreview = m_crFullPreview; m_crPreview.left++; m_crPreview.top++; m_crPreview.right--; m_crPreview.bottom--; } // Limit our text. CEdit* pEdit = (CEdit*)GetDlgItem(IDC_SPACING); if (pEdit != NULL) { pEdit->LimitText(7); } // Show the spacing in the edit. SetSpacing(m_lOriginalSpacing); // Check the radio button that corresponds to this spacing. UINT uID = IDC_CUSTOM; for (int i = 0; i < nStandardSpacings; i++) { if (StandardSpacing[i].m_lSpacing == m_lOriginalSpacing) { uID = StandardSpacing[i].m_uID; break; } } CheckDlgButton(uID, TRUE); return TRUE; }
void InGameContext::checkGoal() { auto data = std::dynamic_pointer_cast<InGameContextData>(_data); Player& currentPlayer = _players[data->currentPlayerId]; int playerId = -1; int points = -1; if (Client::getInstance().getGoal(playerId, points)) { handleGoal(playerId, points); Client::getInstance().sendPaddlePos(currentPlayer.paddle()->x, currentPlayer.paddle()->y); timers.createUntilTimer( TimerFactory::InvokeType::OnRender, 1, true, [this](AbstractTimer *timer, float dt) { auto goalFont = _rm->getFont(FontType::GOAL); //TODO: GOAL string should appear on 'goaler' side const char *goalStr = "GOAL"; float scale = timer->elapsed()*20; goalFont->SetScale(scale); int alpha = 255; if(timer->elapsed() > 0.3) alpha = 255 - timer->elapsed() * 255; goalFont->SetColor(ARGB(alpha, 10, 200, 35)); goalFont->SetSpacing(dt*20); auto strWidth = goalFont->GetStringWidth(goalStr); goalFont->Render(_data->screenWidth/2 - strWidth/2, _data->screenHeight/6 - goalFont->GetHeight()/2*scale, HGETEXT_LEFT, goalStr); }); } }
WebListBox::WebListBox () { miMouseOver = 0; miSelected = 0; mppOption = WEBC_NULL; miNumOptions = 0; mpVScroll = WEBC_NULL; mpHScroll = WEBC_NULL; miSliderWidth = webc_GetDefaultDisplayInt(WEBC_DEFAULT_SLIDER_WIDTH); miTextHeight = miTotalTextHeight = miTotalTextWidth = -1; miLongestOption = 0; mpListener = WEBC_NULL; mStyle = 0; SetFlag(DISPLAY_FLAG_ACCEPTS_FOCUS); SetMargin(LISTBOX_MARGIN); SetPadding(LISTBOX_PADDING); SetBorder(LISTBOX_BORDER); SetSpacing(LISTBOX_SPACING); }
TEST_F(MatricesToVtk_Grid3D_test, read_points_from_vtkImageData) { auto image = vtkSmartPointer<vtkImageData>::New(); image->SetExtent(0, 2, 0, 3, 0, 2); image->SetSpacing(0.1, 0.1, 0.1); image->SetOrigin(-1.0, -2.0, -3.0); io::ReadDataSet readDataSet; readDataSet.type = io::DataSetType::vectorGrid3D; auto & data = readDataSet.data; const vtkIdType numPoints = image->GetNumberOfPoints(); // xyz (tested) + 3-component vector (not tested here) data.resize(6, std::vector<io::t_FP>(static_cast<size_t>(numPoints))); for (vtkIdType i = 0; i < numPoints; ++i) { const auto stdI = static_cast<size_t>(i); vtkVector3d point; image->GetPoint(i, point.GetData()); data[0u][stdI] = point.GetX(); data[1u][stdI] = point.GetY(); data[2u][stdI] = point.GetZ(); } auto parsedImage = MatricesToVtk::loadGrid3D("TestingGrid3D", { readDataSet }); ASSERT_TRUE(parsedImage); ASSERT_TRUE(parsedImage->dataSet()); ASSERT_EQ(numPoints, parsedImage->dataSet()->GetNumberOfPoints()); for (vtkIdType i = 0; i < numPoints; ++i) { vtkVector3d pRef, pParsed; image->GetPoint(i, pRef.GetData()); parsedImage->dataSet()->GetPoint(i, pParsed.GetData()); ASSERT_DOUBLE_EQ(pRef.GetX(), pRef.GetX()); ASSERT_DOUBLE_EQ(pRef.GetY(), pRef.GetY()); ASSERT_DOUBLE_EQ(pRef.GetZ(), pRef.GetZ()); } }
vtkSmartPointer<vtkPolyData> VoxelCarving::createVisualHull( const double isolevel) const { // create vtk visualization pipeline from voxel grid auto spoints = vtkSmartPointer<vtkStructuredPoints>::New(); auto vdim = static_cast<int>(voxel_dim_); spoints->SetDimensions(vdim, vdim, vdim); spoints->SetSpacing(params_.voxel_width, params_.voxel_height, params_.voxel_depth); spoints->SetOrigin(params_.start_x, params_.start_y, params_.start_z); auto farray = vtkSmartPointer<vtkFloatArray>::New(); auto vsize = static_cast<vtkIdType>(voxel_size_); farray->SetNumberOfValues(vsize); farray->SetArray(vox_array_.get(), vsize, 1); spoints->GetPointData()->SetScalars(farray); // create iso surface with marching cubes auto mc_source = vtkSmartPointer<vtkMarchingCubes>::New(); #if VTK_MAJOR_VERSION < 6 mc_source->SetInput(spoints); #else mc_source->SetInputData(spoints); #endif mc_source->SetNumberOfContours(1); mc_source->SetValue(0, isolevel); // calculate surface normals auto surface_normals = vtkSmartPointer<vtkPolyDataNormals>::New(); surface_normals->SetInputConnection(mc_source->GetOutputPort()); surface_normals->SetFeatureAngle(60.0); surface_normals->ComputePointNormalsOn(); surface_normals->Update(); return surface_normals->GetOutput(); }
mitk::SlicedGeometry3D::SlicedGeometry3D(const SlicedGeometry3D& other) : Superclass(other), m_EvenlySpaced( other.m_EvenlySpaced ), m_Slices( other.m_Slices ), m_ReferenceGeometry( other.m_ReferenceGeometry ), m_SliceNavigationController( other.m_SliceNavigationController ) { m_DirectionVector.Fill(0); SetSpacing( other.GetSpacing() ); SetDirectionVector( other.GetDirectionVector() ); if ( m_EvenlySpaced ) { PlaneGeometry::Pointer geometry = other.m_PlaneGeometries[0]->Clone(); assert(geometry.IsNotNull()); SetPlaneGeometry(geometry, 0); } else { unsigned int s; for ( s = 0; s < other.m_Slices; ++s ) { if ( other.m_PlaneGeometries[s].IsNull() ) { assert(other.m_EvenlySpaced); m_PlaneGeometries[s] = nullptr; } else { PlaneGeometry* geometry2D = other.m_PlaneGeometries[s]->Clone(); assert(geometry2D!=nullptr); SetPlaneGeometry(geometry2D, s); } } } }
void EntryExample::Run() { // Create the main SFML window sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Entry Example", sf::Style::Titlebar | sf::Style::Close ); // We have to do this because we don't use SFML to draw. app_window.resetGLStates(); // Create our main SFGUI window auto window = sfg::Window::Create(); window->SetTitle( "Title" ); // Create our box. auto box = sfg::Box::Create( sfg::Box::Orientation::HORIZONTAL ); // Create a button. auto button = sfg::Button::Create(); button->SetLabel( "Set" ); // Connect the button. button->GetSignal( sfg::Widget::OnLeftClick ).Connect( std::bind( &EntryExample::ButtonClick, this ) ); // Create a label. m_label = sfg::Label::Create(); m_label->SetText( "no text yet" ); // Create our entry widget itself. m_entry = sfg::Entry::Create(); // Until now all widgets only expanded to fit the text inside of it. // This is not the case with the entry widget which can be empty // but still has to have a reasonable size. // To disable the automatic sizing of widgets in general you can // use the SetRequisition() method. it takes an sf::Vector as it's // parameter. Depending on which side you want to have a minimum size, // you set the corresponding value in the vector. // Here we chose to set the minimum x size of the widget to 80. m_entry->SetRequisition( sf::Vector2f( 80.f, 0.f ) ); // Setting sizing back to automatic is as easy as setting // x and y sizes to 0. // Pack into box box->Pack( m_entry ); box->Pack( button ); box->Pack( m_label ); // Set box spacing box->SetSpacing( 5.f ); // Add our box to the window window->Add( box ); sf::Clock clock; // Update an initial time to construct the GUI before drawing begins. // This makes sure that there are no frames in which no GUI is visible. window->Update( 0.f ); // Start the game loop while ( app_window.isOpen() ) { // Process events sf::Event event; while ( app_window.pollEvent( event ) ) { // Handle events window->HandleEvent( event ); // Close window : exit if ( event.type == sf::Event::Closed ) { app_window.close(); } } // Update the GUI every 5ms if( clock.getElapsedTime().asMicroseconds() >= 5000 ) { // Update() takes the elapsed time in seconds. window->Update( static_cast<float>( clock.getElapsedTime().asMicroseconds() ) / 1000000.f ); clock.restart(); } // Clear screen app_window.clear(); // Draw the GUI m_sfgui.Display( app_window ); // Update the window app_window.display(); } }
void FontDemoView::MessageReceived(BMessage* msg) { switch (msg->what) { case TEXT_CHANGED_MSG: { const char* text = NULL; if (msg->FindString("_text", &text) == B_OK) { SetString(text); Invalidate(/*&fBoxRegion*/); } break; } case FONTSTYLE_CHANGED_MSG: { BMessage fontMessage; if (msg->FindMessage("_fontMessage", &fontMessage) != B_OK) return; const char* family; const char* style; if (fontMessage.FindString("_family", &family) != B_OK || fontMessage.FindString("_style", &style) != B_OK) return; fFont.SetFamilyAndStyle(family, style); Invalidate(); break; } case FONTFAMILY_CHANGED_MSG: { BMessage fontMessage; if (msg->FindMessage("_fontMessage", &fontMessage) != B_OK) return; const char* family; if (fontMessage.FindString("_family", &family) != B_OK) return; font_style style; if (get_font_style(const_cast<char*>(family), 0, &style) == B_OK) { fFont.SetFamilyAndStyle(family, style); Invalidate(/*&fBoxRegion*/); } break; } case FONTSIZE_MSG: { float size = 0.0; if (msg->FindFloat("_size", &size) == B_OK) { SetFontSize(size); Invalidate(/*&fBoxRegion*/); } break; } case FONTSHEAR_MSG: { float shear = 90.0; if (msg->FindFloat("_shear", &shear) == B_OK) { SetFontShear(shear); Invalidate(/*&fBoxRegion*/); } break; } case ROTATION_MSG: { float rotation = 0.0; if (msg->FindFloat("_rotation", &rotation) == B_OK) { SetFontRotation(rotation); Invalidate(/*&fBoxRegion*/); } break; } case SPACING_MSG: { float space = 0.0; if (msg->FindFloat("_spacing", &space) == B_OK) { SetSpacing(space); Invalidate(/*&fBoxRegion*/); } break; } case OUTLINE_MSG: { int8 outline = 0; if (msg->FindInt8("_outline", &outline) == B_OK) { SetOutlineLevel(outline); Invalidate(/*&fBoxRegion*/); } break; } case ALIASING_MSG: { bool aliased = false; if (msg->FindBool("_aliased", &aliased) == B_OK) { SetAntialiasing(aliased); Invalidate(/*&fBoxRegion*/); } break; } case DRAWINGMODE_CHANGED_MSG: { if (msg->FindInt32("_mode", (int32 *)&fDrawingMode) == B_OK) { Invalidate(/*&fBoxRegion*/); switch (fDrawingMode) { case B_OP_COPY: printf("Drawing mode: B_OP_COPY\n"); break; case B_OP_OVER: printf("Drawing mode: B_OP_OVER\n"); break; case B_OP_ERASE: printf("Drawing mode: B_OP_ERASE\n"); break; case B_OP_INVERT: printf("Drawing mode: B_OP_INVERT\n"); break; case B_OP_ADD: printf("Drawing mode: B_OP_ADD\n"); break; case B_OP_SUBTRACT: printf("Drawing mode: B_OP_SUBTRACT\n"); break; case B_OP_BLEND: printf("Drawing mode: B_OP_BLEND\n"); break; case B_OP_MIN: printf("Drawing mode: B_OP_MIN\n"); break; case B_OP_MAX: printf("Drawing mode: B_OP_MAX\n"); break; case B_OP_SELECT: printf("Drawing mode: B_OP_SELECT\n"); break; case B_OP_ALPHA: printf("Drawing mode: B_OP_ALPHA\n"); break; default: printf("Drawing mode: %d\n", fDrawingMode); } } break; } case BOUNDING_BOX_MSG: { bool boundingbox = false; if (msg->FindBool("_boundingbox", &boundingbox) == B_OK) { SetDrawBoundingBoxes(boundingbox); Invalidate(/*&fBoxRegion*/); } break; } default: BView::MessageReceived(msg); break; } }
FileSelectorWidget::FileSelectorWidget(Type type, const std::string &title) : Gui::VBox(), m_type(type), m_title(title) { SetTransparency(false); SetSpacing(5.0f); SetSizeRequest(FLT_MAX, FLT_MAX); }
void CommodityTradeWidget::ShowAll() { DeleteAllChildren(); m_stockLabels.clear(); m_cargoLabels.clear(); SetTransparency(true); Gui::VScrollBar *scroll = new Gui::VScrollBar(); Gui::VScrollPortal *portal = new Gui::VScrollPortal(450); scroll->SetAdjustment(&portal->vscrollAdjust); //int GetStock(Equip::Type t) const { return m_equipmentStock[t]; } int NUM_ITEMS = 0; const float YSEP = floor(Gui::Screen::GetFontHeight() * 2.5f); for (int i=Equip::FIRST_COMMODITY; i<=Equip::LAST_COMMODITY; i++) { assert(Equip::types[i].slot == Equip::SLOT_CARGO); if (m_seller->DoesSell(Equip::Type(i))) { NUM_ITEMS++; } } Gui::Fixed *innerbox = new Gui::Fixed(450, NUM_ITEMS*YSEP); innerbox->SetTransparency(true); const float iconOffset = 8.0f; for (int i=Equip::FIRST_COMMODITY, num=0; i<=Equip::LAST_COMMODITY; i++) { assert(Equip::types[i].slot == Equip::SLOT_CARGO); if (!m_seller->DoesSell(Equip::Type(i))) continue; int stock = m_seller->GetStock(static_cast<Equip::Type>(i)); std::map<Equip::Type,std::string>::iterator icon_iter = s_iconMap.find(Equip::Type(i)); if (icon_iter != s_iconMap.end()) { Gui::Image *icon = new Gui::Image(("icons/goods/" + (*icon_iter).second + ".png").c_str()); // this forces the on-screen rendering to fit within (rescale) to these dimensions icon->SetRenderDimensions(38.0f, 32.0f); innerbox->Add(icon, 0, num*YSEP); } Gui::Label *l = new Gui::Label(Equip::types[i].name); if (Equip::types[i].description) l->SetToolTip(Equip::types[i].description); innerbox->Add(l,42,num*YSEP+iconOffset); Gui::RepeaterButton *b = new Gui::RepeaterButton(RBUTTON_DELAY, RBUTTON_REPEAT); sigc::slot<void> func = sigc::bind(sigc::mem_fun(this, &CommodityTradeWidget::OnClickBuy), i); b->onClick.connect(sigc::bind(sigc::mem_fun(this, &CommodityTradeWidget::ManageRButton), b, func)); innerbox->Add(b, 380, num*YSEP+iconOffset); b = new Gui::RepeaterButton(RBUTTON_DELAY, RBUTTON_REPEAT); func = sigc::bind(sigc::mem_fun(this, &CommodityTradeWidget::OnClickSell), i); b->onClick.connect(sigc::bind(sigc::mem_fun(this, &CommodityTradeWidget::ManageRButton), b, func)); innerbox->Add(b, 415, num*YSEP+iconOffset); char buf[128]; innerbox->Add(new Gui::Label( format_money(m_seller->GetPrice(static_cast<Equip::Type>(i))) ), 200, num*YSEP+iconOffset); snprintf(buf, sizeof(buf), "%dt", stock*Equip::types[i].mass); Gui::Label *stocklabel = new Gui::Label(buf); m_stockLabels[i] = stocklabel; innerbox->Add(stocklabel, 275, num*YSEP+iconOffset); snprintf(buf, sizeof(buf), "%dt", Pi::player->m_equipment.Count(Equip::SLOT_CARGO, static_cast<Equip::Type>(i))*Equip::types[i].mass); Gui::Label *cargolabel = new Gui::Label(buf); m_cargoLabels[i] = cargolabel; innerbox->Add(cargolabel, 325, num*YSEP+iconOffset); num++; } innerbox->ShowAll(); portal->Add(innerbox); portal->ShowAll(); Gui::Fixed *heading = new Gui::Fixed(470, Gui::Screen::GetFontHeight()); const Color &col = Gui::Theme::Colors::tableHeading; heading->Add((new Gui::Label(Lang::ITEM))->Color(col), 0, 0); heading->Add((new Gui::Label(Lang::PRICE))->Color(col), 200, 0); heading->Add((new Gui::Label(Lang::BUY))->Color(col), 380, 0); heading->Add((new Gui::Label(Lang::SELL))->Color(col), 415, 0); heading->Add((new Gui::Label(Lang::STOCK))->Color(col), 275, 0); heading->Add((new Gui::Label(Lang::CARGO))->Color(col), 325, 0); PackEnd(heading); Gui::HBox *body = new Gui::HBox(); body->PackEnd(portal); body->PackEnd(scroll); PackEnd(body); SetSpacing(YSEP-Gui::Screen::GetFontHeight()); Gui::VBox::ShowAll(); }