/**
 * @brief Sets the sprite model.
 * @param model The sprite model, or nullptr to remove any model.
 * This class does not take ownership on the model.
 * The model can be deleted safely.
 */
void SpritePreviewer::set_model(SpriteModel* model) {

  if (this->model != nullptr) {
    this->model->disconnect(this);
    this->model = nullptr;
  }

  this->model = model;

  if (model != nullptr) {
    connect(&model->get_selection_model(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
            this, SLOT(update_selection()));
    update_selection();

    connect(model, SIGNAL(animation_frame_delay_changed(Index,uint32_t)),
            this, SLOT(update_frame_delay()));
    connect(model, SIGNAL(animation_image_changed(Index,QString)),
            this, SLOT(update_frames()));

    connect(model, SIGNAL(direction_position_changed(Index,QPoint)),
            this, SLOT(update_frames()));
    connect(model, SIGNAL(direction_size_changed(Index,QSize)),
            this, SLOT(update_frames()));
    connect(model, SIGNAL(direction_num_frames_changed(Index,int)),
            this, SLOT(update_frames()));
    connect(model, SIGNAL(direction_num_columns_changed(Index,int)),
            this, SLOT(update_frames()));

    connect(model, SIGNAL(direction_origin_changed(Index,QPoint)),
            this, SLOT(update_origin()));
  }
void Animation::update_sprite_to_frame()
{
    int framewidth = sprite_.GetImage()->GetWidth() / total_frames_;
    int frameheight = sprite_.GetImage()->GetHeight();
    sf::IntRect clip(current_frame_ * framewidth, 0, (current_frame_+1) * framewidth, frameheight);
    sprite_.SetSubRect(clip);

    update_origin();
}
示例#3
0
void Dag::node_assign(InsCtrl& ins, std::map<unsigned int, symbol*>& node_operand, unsigned int index)
{
	std::vector<sym_node_pair> _assign=assignment[index];//the symbol is associated with the node in the second <symbol, node index ....>
	for(unsigned int i=0;i<_assign.size();i++)
	{
		symbol* arg1=_assign[i].first;	//need to assign the value of node[_assign[i].second ] to the symbol
		symbol *arg2=get_rep_operand(node_operand,_assign[i].second);	//get the "representative" symbol of that node
		update_origin(arg1,_assign[i].second);
		if(arg1!=arg2)
			ins.assign(arg1,arg2);
	}
}
/**
 * @brief Create a sprite previewer.
 * @param parent The parent object or nullptr.
 */
SpritePreviewer::SpritePreviewer(QWidget *parent) :
  QWidget(parent),
  model(nullptr),
  zoom(1.0) {

  ui.setupUi(this);

  // Create frame and origin items.
  item = new QGraphicsPixmapItem();
  origin_h = new QGraphicsLineItem();
  origin_v = new QGraphicsLineItem();

  origin_h->setPen(QPen(Qt::blue));
  origin_v->setPen(QPen(Qt::blue));

  // Create the scene.
  ui.frame_view->setScene(new QGraphicsScene());
  ui.frame_view->scene()->addItem(item);
  ui.frame_view->scene()->addItem(origin_h);
  ui.frame_view->scene()->addItem(origin_v);
  ui.frame_view->scene()->setBackgroundBrush(
        ui.frame_view->scene()->palette().base());

  // Zoom.
  ui.zoom_button->setMenu(create_zoom_menu());
  ui.zoom_button->setPopupMode(QToolButton::InstantPopup);
  set_zoom(2.0);
  update_zoom();

  connect(&timer, SIGNAL(timeout()), this, SLOT(timeout()));

  connect(ui.start_button, SIGNAL(clicked()), this, SLOT(start()));
  connect(ui.stop_button, SIGNAL(clicked()), this, SLOT(stop()));
  connect(ui.first_button, SIGNAL(clicked()), this, SLOT(first()));
  connect(ui.previous_button, SIGNAL(clicked()), this, SLOT(previous()));
  connect(ui.last_button, SIGNAL(clicked()), this, SLOT(last()));
  connect(ui.next_button, SIGNAL(clicked()), this, SLOT(next()));

  connect(ui.origin_check_box, SIGNAL(clicked()), this, SLOT(update_origin()));
}
示例#5
0
void Dag::output_quadcode(InsCtrl& ins)
{
	std::vector<unsigned int> oper_stack;
	std::map<unsigned int, symbol*> obj_operand;

	//get the reverse order of the all operators, will be put in the oper_stack
	while(!operators.empty())
	{
		bool find=false;
		unsigned int _index=0;
		//first find the node index which do not have a parent
		for(std::map<Quadcode::Quad_type,num_set>::iterator it=operators.begin();it!=operators.end();it++)
		{
			num_set& node_set=it->second;	//the list of node index which the operator is in
			for(num_set::iterator it1=node_set.begin();it1!=node_set.end();it1++)
			{
				if(is_no_parent(dag_nodes,*it1)&&(*it1>_index||!find))	//the dag tree can have multiple branches, so we find the one with maximum index
				{
					_index=*it1;
					find=true;
				}
			}
		}
		
		if(find)	//we have find the index
		{
			do
			{
				std::map<Quadcode::Quad_type,num_set>::iterator it=operators.find(dag_nodes[_index]->typ); //find the given operator set
				assert(it!=operators.end());
				num_set& node_set=it->second; //the node set of the operation
				num_set::iterator it1=node_set.find(_index);
				node_set.erase(it1);	//erase the find node
				if(node_set.empty()) operators.erase(it);

				oper_stack.push_back(_index);
				dag_nodes[_index]->enable=false;
				_index=dag_nodes[_index]->left;	//traverse the left branch
			}
			while(!dag_nodes[_index]->is_leaf&&is_no_parent(dag_nodes,_index));	//while the operation node have no parent
		}
		else
		{assert(operators.empty());}
	}

	//already get the operator stack , output the code in the reverse order

	node_assign(ins,obj_operand,0);
	for(int i=oper_stack.size();i>0;i--)
	{
		DNode* node=dag_nodes[oper_stack[i-1]];	//in reverse order
		Quadcode::Quad_type typ=node->typ;
		Quadcode* code=NULL;
		symbol* src_arg1=NULL;
		symbol* src_arg2=NULL;
		symbol* obj_arg=NULL;

		assert(!node->is_leaf);
		src_arg1=get_rep_operand(obj_operand,node->left);
		if(node->two_children) src_arg2=get_rep_operand(obj_operand,node->right);
		obj_arg=get_rep_operand(obj_operand,oper_stack[i-1]);
		update_origin(obj_arg,oper_stack[i-1]);		//if not leave, strip it out
		if(src_arg2!=NULL) code=new_instruction(typ,obj_arg,src_arg1,src_arg2);
		else code=new_instruction(typ,obj_arg,src_arg1,src_arg1);
		ins.new_instruction(code);
		node_assign(ins,obj_operand,oper_stack[i-1]+1);		//plus one because basic index of assign_info is 1
	}
	flush();
}
void Animation::set_origin(const sf::Vector2f& origin)
{
    origin_ = origin;
    update_origin();
}
void Animation::set_scale(float w, float h)
{
    assert( w >= 0 && h >= 0 );
    sprite_.SetScale(w,h);
    update_origin();
}