// Private member functions:
// Call this function after declare a CollageBasic instance.
// This function will create a non-fixed aspect ratio image collage.
bool CollageBasic::CreateCollage() {
  image_num_ = static_cast<int>(image_vec_.size());
  if (image_num_ == 0) {
    std::cout << "Error: CreateCollage 1" << std::endl;
    return false;
  }
  if (canvas_width_ <= 0) {
    std::cout << "Error: CreateCollage 2" << std::endl;
    return false;
  }
  
  // A: generate a full balanced binary tree with image_num_ leaves.
  GenerateInitialTree();
  // B: recursively calculate aspect ratio.
  canvas_alpha_ = CalculateAlpha(tree_root_);
  canvas_height_ = static_cast<int>(canvas_width_ / canvas_alpha_);
  // C: set the position for all the tile images in the collage.
  tree_root_->position_.x_ = 0;
  tree_root_->position_.y_ = 0;
  tree_root_->position_.height_ = canvas_height_;
  tree_root_->position_.width_ = canvas_width_;
  if (tree_root_->left_child_)
    CalculatePositions(tree_root_->left_child_);
  if (tree_root_->right_child_)
    CalculatePositions(tree_root_->right_child_);
  return true;
};
Esempio n. 2
0
void LetterChooser::LevelLoaded()
{
	LetterManager::LevelLoaded();
	mGameLogic = static_cast<GameLogic*>(mGame.GetTaggedObject(mGameLogicTag));
	CalculatePositions();
	PlaceLetters();
}
Esempio n. 3
0
void EMSlimLabel::SetFrame(EMRect p_oFrame)
{
	if(m_oFrame == p_oFrame)
		return;
		
	m_oFrame = p_oFrame;
	CalculatePositions();
}
Esempio n. 4
0
EMSlimLabel::EMSlimLabel(EMView* p_opView, EMRect p_oFrame, string* p_opLabel, EMColor p_oBackgroundColor, bool p_vCenterText) :
m_eMode(EM_SLIM_LABEL_DRAW_NORMAL),
m_oBackgroundColor(p_oBackgroundColor),
m_oFrame(p_oFrame),
m_opLabel(p_opLabel),
m_opView(p_opView),
m_vCenterText(p_vCenterText)
{
	CalculatePositions();
}
// If we use CreateCollage, the generated collage may have strange aspect ratio such as
// too big or too small, which seems to be difficult to be shown. We let the user to
// input their expected aspect ratio and fast adjust to make the result aspect ratio
// close to the user defined one.
// The thresh here controls the closeness between the result aspect ratio and the expect
// aspect ratio. e.g. expect_alpha is 1, thresh is 2. The result aspect ratio is around
// [1 / 2, 1 * 2] = [0.5, 2].
// We also define MAX_ITER_NUM = 100,
// If max iteration number is reached and we cannot find a good result aspect ratio,
// this function returns false.
int CollageBasic::CreateCollage(float expect_alpha, float thresh) {
  assert(thresh > 1);
  assert(expect_alpha > 0);
  tree_root_->alpha_expect_ = expect_alpha;
  float lower_bound = expect_alpha / thresh;
  float upper_bound = expect_alpha * thresh;
  int total_iter_counter = 1;
  
  // Do the initial tree generatio and calculation.
  // A: generate a full balanced binary tree with image_num_ leaves.
  GenerateInitialTree();
  // B: recursively calculate aspect ratio.
  canvas_alpha_ = CalculateAlpha(tree_root_);
  
  while ((canvas_alpha_ < lower_bound) || (canvas_alpha_ > upper_bound)) {
    GenerateInitialTree();
    canvas_alpha_ = CalculateAlpha(tree_root_);
    ++total_iter_counter;
    if (total_iter_counter > MAX_TREE_GENE_NUM) {
      std::cout << "*******************************" << std::endl;
      std::cout << "max iteration number reached..." << std::endl;
      std::cout << "*******************************" << std::endl;
      return -1;
    }
  }
  // std::cout << "Canvas generation success!" << std::endl;
  std::cout << "Total iteration number is: " << total_iter_counter << std::endl;
  // After adjustment, set the position for all the tile images.
  canvas_height_ = static_cast<int>(canvas_width_ / canvas_alpha_);
  tree_root_->position_.x_ = 0;
  tree_root_->position_.y_ = 0;
  tree_root_->position_.height_ = canvas_height_;
  tree_root_->position_.width_ = canvas_width_;
  if (tree_root_->left_child_)
    CalculatePositions(tree_root_->left_child_);
  if (tree_root_->right_child_)
    CalculatePositions(tree_root_->right_child_);
  return total_iter_counter;
}
Esempio n. 6
0
void LetterChooser::Clear()
{
	for(int i = 0; i < (int)mSourceLetters.size(); ++i)
	{
		mSourceLetters[i]->RemoveFromMetaballGrid();
	}
	mActiveLetters.clear();
	ConstructMeshFromLocalData();
	CalculatePositions();
	//LayoutLetters();
	AdjustMeshForActiveLetters();
	
}
Esempio n. 7
0
void GridLayouter::CalculateRows()
{
    if (m_calculated_rows)
        return;

    unsigned row_fillroom = max(0, m_grid_rect.height - (int)m_minimum_height);
    GrowIfNecessary(m_row_info, m_row_count, row_fillroom);

    unsigned row_surplus = max(0, (int)m_minimum_height - m_grid_rect.height);
    ShrinkIfNecessary(m_row_info, m_row_count, m_minimum_height, row_surplus);

    CalculatePositions(m_row_info, m_row_count, m_grid_rect.y);

    m_calculated_rows = TRUE;
}
Esempio n. 8
0
void GridLayouter::CalculateColumns()
{
    if (m_calculated_columns)
        return;

    unsigned column_fillroom = max(0, m_grid_rect.width - (int)m_minimum_width);
    GrowIfNecessary(m_column_info, m_col_count, column_fillroom);

    unsigned column_surplus = max(0, (int)m_minimum_width - max(0, m_grid_rect.width));
    ShrinkIfNecessary(m_column_info, m_col_count, m_minimum_width, column_surplus);

    CalculatePositions(m_column_info, m_col_count, m_grid_rect.x);

    m_calculated_columns = TRUE;
}
Esempio n. 9
0
void LetterChooser::AdjustLayout()
{

	ConstructMeshFromLocalData();
	CalculatePositions();//The functions involved have to respond to only active letters... but need to respond to source letters at startup
	PlaceLetters();
	AdjustMeshForActiveLetters();
	for(int i = 0; i < (int)mSourceLetters.size(); ++i)
	{
		mSourceLetters[i]->RemoveFromMetaballGrid();
	}
	//mMetaballGrid->ClearGridValues();
	for(int i = 0; i < (int)mActiveLetters.size(); ++i)
	{
		mActiveLetters[i]->AddToMetaballGrid(mMetaballGrid);
	}
}
Esempio n. 10
0
        void EtherMenu::RectChanged(const QRectF& bounds)
        {
            boundaries_ = bounds;
            positions_.clear();

            if(bounds.height()< card_max_size_.height())
            {
                current_scale_factor_ = scale_factor_ - (1- (bounds.height()/ card_max_size_.height()));
                current_card_max_size_.setHeight( bounds.height() );

            }
            else
            {
                current_scale_factor_ = scale_factor_;
                current_card_max_size_.setHeight( card_max_size_.height() );
            }
            CalculateGap();
            CalculatePositions(positions_);
            InitializeObjectValues();
        }
Esempio n. 11
0
void LetterChooser::Reset()
{

	mActiveLetters.clear();
	for(int i = 0; i < (int)mSourceLetters.size(); ++i)
	{
		mActiveLetters.push_back(mSourceLetters[i]);
	}
	ConstructMeshFromLocalData();
	CalculatePositions();
	PlaceLetters();
	AdjustMeshForActiveLetters();
	for(int i = 0; i < (int)mSourceLetters.size(); ++i)
	{
		mSourceLetters[i]->RemoveFromMetaballGrid();
	}
	//mMetaballGrid->ClearGridValues();
	for(int i = 0; i < (int)mActiveLetters.size(); ++i)
	{
		mActiveLetters[i]->AddToMetaballGrid(mMetaballGrid);
	}
	
}
Esempio n. 12
0
        void EtherMenu::Initialize(const QRectF& bounds, const QVector<InfoCard *>& items, const QRectF& max_size, qreal scalef, int visible_objects, qreal opacity_factor, qreal max_gap)
        {
            objects_.clear();
            positions_.clear();
            animations_->clear();
            priority_list_.clear();

            objects_ = items;
            boundaries_ = bounds;
            max_visible_objects_ = visible_objects;
            priority_list_.fill(0, objects_.size());
            current_card_max_size_ = card_max_size_ = max_size;
            opacity_factor_ = opacity_factor;
            current_scale_factor_ = scale_factor_ = scalef;
            max_gap_ = max_gap;

            CalculateGap();
            CalculatePositions(positions_);

            ConstructPriorityList();
            CalculateLimits();
            InitializeAnimations();
            InitializeObjectValues();
        }
Esempio n. 13
0
// Top-down Calculate the image positions in the colage.
bool CollageBasic::CalculatePositions(TreeNode* node) {
  // Step 1: calculate height & width.
  if (node->parent_->split_type_ == 'v') {
    // Vertical cut, height unchanged.
    node->position_.height_ = node->parent_->position_.height_;
    if (node->child_type_ == 'l') {
      node->position_.width_ = node->position_.height_ * node->alpha_;
    } else if (node->child_type_ == 'r') {
      node->position_.width_ = node->parent_->position_.width_ -
          node->parent_->left_child_->position_.width_;
    } else {
      std::cout << "Error: CalculatePositions step 0" << std::endl;
      return false;
    }
  } else if (node->parent_->split_type_ == 'h') {
    // Horizontal cut, width unchanged.
    node->position_.width_ = node->parent_->position_.width_;
    if (node->child_type_ == 'l') {
      node->position_.height_ = node->position_.width_ / node->alpha_;
    } else if (node->child_type_ == 'r') {
      node->position_.height_ = node->parent_->position_.height_ -
      node->parent_->left_child_->position_.height_;
    }
  } else {
    std::cout << "Error: CalculatePositions step 1" << std::endl;
    return false;
  }
  
  // Step 2: calculate x & y.
  if (node->child_type_ == 'l') {
    // If it is left child, use its parent's x & y.
    node->position_.x_ = node->parent_->position_.x_;
    node->position_.y_ = node->parent_->position_.y_;
  } else if (node->child_type_ == 'r') {
    if (node->parent_->split_type_ == 'v') {
      // y (row) unchanged, x (colmn) changed.
      node->position_.y_ = node->parent_->position_.y_;
      node->position_.x_ = node->parent_->position_.x_ +
      node->parent_->position_.width_ -
      node->position_.width_;
    } else if (node->parent_->split_type_ == 'h') {
      // x (column) unchanged, y (row) changed.
      node->position_.x_ = node->parent_->position_.x_;
      node->position_.y_ = node->parent_->position_.y_ +
      node->parent_->position_.height_ -
      node->position_.height_;
    } else {
      std::cout << "Error: CalculatePositions step 2 - 1" << std::endl;
    }
  } else {
    std::cout << "Error: CalculatePositions step 2 - 2" << std::endl;
    return false;
  }
  
  // Calculation for children.
  if (node->left_child_) {
    bool success = CalculatePositions(node->left_child_);
    if (!success) return false;
  }
  if (node->right_child_) {
    bool success = CalculatePositions(node->right_child_);
    if (!success) return false;
  }
  return true;
}
Esempio n. 14
0
void EMSlimLabel::SetLabel(string* p_opLabel)
{
	m_opLabel = p_opLabel;
	CalculatePositions();
}