Exemplo n.º 1
0
rectf::rectf(const std::string& str)
{
	if(str.empty()) {
		*this = rectf();
		return;
	}

	GLfloat items[4];
	int num_items = 0;
	std::vector<std::string> buf = util::split(str, ",");
	for(int n = 0; n != 4 && n != buf.size(); ++n) {
		items[num_items++] = boost::lexical_cast<GLfloat>(buf[n]);
	}

	switch(num_items) {
	case 2:
		*this = rectf::from_coordinates(items[0], items[1], 1, 1);
		break;
	case 3:
		*this = rectf::from_coordinates(items[0], items[1], items[2], 1);
		break;
	case 4:
		*this = rectf::from_coordinates(items[0], items[1], items[2], items[3]);
		break;
	default:
		*this = rectf();
		break;
	}
}
Exemplo n.º 2
0
ripple()
{
	register Point p1, p2;
	register Point inc;
	register Point p;

	while (kbdchar() != 'q') {
		if (P->state & MOVED) {
			P->state &= ~(MOVED|RESHAPED);
			p = sub (Drect.origin, p);
			p1 = add (p1, p);
			p2 = add (p2, p);
			p = Drect.origin;
		}
		else if (P->state & RESHAPED) {
			P->state &= ~RESHAPED;
			p1.x=p2.x=avg(Drect.origin.x, Drect.corner.x);
			p1.y=p2.y=avg(Drect.origin.y, Drect.corner.y);
			inc.x=1;
			inc.y=1;
			rectf(&display, Drect, F_XOR);
			p = Drect.origin;
		}
		rectf(&display, canon(p1, p2), F_XOR);
		if (p1.x==Drect.origin.x || p1.x==Drect.corner.x) {
			inc.x= -inc.x;
		}
		if (p1.y==Drect.origin.y || p1.y==Drect.corner.y) {
			inc.y= -inc.y;
		}
		p1 = sub (p1, inc);
		p2 = add (p2, inc);
		wait (CPU);
	}
}
Exemplo n.º 3
0
	const rectf Material::getNormalisedTextureCoords(const std::vector<TexturePtr>::const_iterator& it)
	{
		float w = static_cast<float>((*it)->width());
		float h = static_cast<float>((*it)->height());
		if(draw_rect_.x() == 0.0f && draw_rect_.y() == 0.0f && draw_rect_.x2() == 0.0f && draw_rect_.y2() == 0.0f) {
			return rectf(0.0f, 0.0f, 1.0f, 1.0f);
		}
		return rectf(draw_rect_.x()/w, draw_rect_.y()/h, draw_rect_.x2()/w, draw_rect_.y2()/h);
	}
Exemplo n.º 4
0
static void drawslider(gl_slider *sl) {
    Int32 lw = getlwidth();
    Int32 cl = getcolor();
    Int32 oriwin = winget();
    long co;
    int i;
    Screencoord x, y;
    Int32 xo, yo;
    
    winset(sl->win);
    linewidth(1);
   
    update_slider_value(sl);
    locate_slider(sl);
    
    if (sl->txbg == -1) {
	/* first time, get bg color */
	cmov2(sl->x + sl->len + sl->thick, sl->y);
	getcpos(&x, &y);
	getorigin(&xo, &yo);
	x -= xo;
	y -= yo;
	i = lrectread(x, y, x, y, &co);
	sl->txbg = co;
#ifdef DEBUG
	printf("textbg = %d, bytes = %d x %d (soll %g) y %d (soll %g)\n",
	       co,i,x,sl->x + sl->len + sl->thick,
	       y,sl->y);	
#endif
    }
    color(sl->bg);
    rectf(sl->x, sl->y, sl->x+sl->thick+sl->len, sl->y+sl->height);
    color(sl->fg);
    rect (sl->x, sl->y, sl->x+sl->thick+sl->len, sl->y+sl->height);
    rectf(sl->x + sl->len * (sl->value - sl->min)/(sl->max - sl->min),
	  sl->y,
	  sl->x + sl->len * (sl->value - sl->min)/(sl->max - sl->min) + sl->thick,
	  sl->y + sl->height);
    if (sl->buf != NULL) {
	color(sl->txbg);
	cmov2(sl->x + sl->len + sl->thick, sl->y);
	charstr(sl->buf);
	color(sl->fg);
	sprintf(sl->buf + 1, sl->format, sl->value);
	cmov2(sl->x + sl->len + sl->thick, sl->y);
	charstr(sl->buf);
    }
    
    winset(oriwin);
    color(cl);
    linewidth(lw);
    
    sleep(0);
}
Exemplo n.º 5
0
rectf Font::getBounds(uint16_t charcode, float fontSize) const {
  MetricsData::const_iterator itr = mMetrics.find(charcode);
  if (itr != mMetrics.end())
    return getBounds(itr->second, fontSize);
  else
    return rectf();
}
Exemplo n.º 6
0
static void drawbutton(gl_button *bt) {
    Int32 lw = getlwidth();
    Int32 cl = getcolor();
    Int32 oriwin = winget();
    int cfg, bg;
    
    winset(bt->win);
    linewidth(1);
    locate_button(bt);
    
    cfg = *(bt->state)?bt->bg:bt->fg;
    bg  = *(bt->state)?((bt->type == BUTTON)?bt->fg:bt->active_c):bt->bg;
	
    color(bg);
    rectf(bt->x, bt->y, bt->x + bt->width, bt->y + bt->height);
    
    color(bt->fg);
    rect (bt->x, bt->y, bt->x + bt->width, bt->y + bt->height);

    if (bt->label != NULL) {
	color(cfg);
	cmov2(bt->x, bt->y + 0.05 * bt->height);
	charstr(bt->label);
    }
    
    winset(oriwin);
    color(cl);
    linewidth(lw);
    
    sleep(0);
}
Exemplo n.º 7
0
rectf path::bbox(void) const
{
    if (size() == 0)
        return rectf(0, 0, 0, 0);
    else
    {
        vertex_type vertex = fetch_vertex(0);
        rectf bbox(vertex.x, vertex.y, vertex.x, vertex.y);

        for (unsigned int i = 1; i < size(); ++i)
        {
            vertex = fetch_vertex(i);

            if (bbox.left   > vertex.x) bbox.left   = vertex.x;
            else
            if (bbox.right  < vertex.x) bbox.right  = vertex.x;

            if (bbox.top    > vertex.y) bbox.top    = vertex.y;
            else
            if (bbox.bottom < vertex.y) bbox.bottom = vertex.y;
        }

        return bbox;
    }
}
Exemplo n.º 8
0
	void text_entry::refresh_render_text_part(render_text_part& part, const render_text_part* previous_part, int begin_pos, int end_pos, const rectf& all_parts_area) {
		int visible_begin_pos = std::max(_visible_pos, begin_pos);
		int unclipped_char_count = std::max(0, end_pos - visible_begin_pos);
		part._unclipped_text.assign(_text.c_str(), visible_begin_pos, unclipped_char_count);
		raw_text_to_visible_text(part._unclipped_text);
		
		part._clipped_text.assign(L"");
		float clipped_text_width = 0.f;

		pointf clipped_top_left = all_parts_area.get_top_left();
		if (previous_part != nullptr) {
			clipped_top_left = previous_part->_area.get_top_right();
		}
		const float available_width = all_parts_area.get_right() - clipped_top_left._x;

		size_t clipped_char_count = part._unclipped_text.length();
		while (clipped_char_count >= 0) {
			part._clipped_text.assign(part._unclipped_text.c_str(), 0, clipped_char_count);
			
			clipped_text_width = get_text_width(part._clipped_text);
			if (previous_part != nullptr && !previous_part->_clipped_text.empty()) {
				clipped_text_width += get_kerning_pair_offset(
					previous_part->_clipped_text[previous_part->_clipped_text.length() - 1],
					part._clipped_text[0]);
			}
			
			if (clipped_text_width <= available_width) {
				break;
			}
		}

		part._area = rectf(clipped_top_left, sizef(clipped_text_width, all_parts_area.get_height()));
	}
Exemplo n.º 9
0
/***********************************************************************
    This routine is called when the menu command ROTATEMINUS is selected.
    The region selected is rotated 90 degress counterclockwise.  
***********************************************************************/
OpRotMinus()
{
	int	vsize, hsize, size;
	Rectangle r, rbuf;
	Bitmap * buffer;
	if (GetIconRect(&r) == 0) 
		return(0);
	hsize = horsize(r); 
	vsize = versize(r); 
	size = hsize + vsize;
	buffer = balloc(Rect(0, 0, size, size));
	if (buffer == ((Bitmap * ) 0)) 
		return(0);
	rectf(buffer, buffer->rect, F_CLR);
	rbuf = raddp(r, sub(Pt(vsize, 0), r.origin));
	bitblt(&display, raddp(r, icon.origin), buffer, rbuf.origin, F_XOR);
	horshear(buffer, rbuf, -vsize, true);
	vershear(buffer,
	    Rect(rbuf.origin.x - vsize, rbuf.origin.y, rbuf.corner.x, rbuf.corner.y),
	    size, true);
	horshear(buffer,
	    Rect(rbuf.origin.x - vsize, rbuf.corner.y - 1,
	    rbuf.corner.x, rbuf.corner.y + hsize - 1),
	    hsize, false);
	Erase(r);
	FetchIcon(buffer,
	    Rect(rbuf.corner.x - vsize, rbuf.corner.y - 1,
	    rbuf.corner.x, rbuf.corner.y + hsize - 1),
	    add(r.origin, sub(Pt(hsize / 2, vsize / 2), Pt(vsize / 2, hsize / 2))),
	    Rect(0, 0, Xblocks, Yblocks));
	bfree(buffer);
}
Exemplo n.º 10
0
main()
{
	register got;
	request(KBD|MOUSE|RCV|SEND);
	newlnsz=defont.height;
	init();
	strzero(&snarfbuf);
	waitunix(&diagdone);	/* when menu is loaded */
	for(got=0; ; got=wait(MOUSE|KBD|RCV)){
		if(P->state&RESHAPED){
			rectf(&display, Drect, F_CLR);
			closeall();
			init();
			P->state&=~RESHAPED;
		}
		/* NOTE: cursor is OFF at all times... */
		if((got&RCV) && rcv()){
			curse(current->frame);
			(void)message();
			curse(current->frame);
		}
		if((got&MOUSE) && bttn123() && ptinrect(mouse.xy, display.rect)){
			curse(current->frame);
			buttonhit(mouse.xy, mouse.buttons);
			curse(current->frame);
		}
		if((got&KBD) && current)	/* ...except in type */
			type(current);	/* manages cursor itself */
	}
}
Exemplo n.º 11
0
static bool powerup_help_render(float t) {
	if(t != 0.0f)
		game_update_empty();

	UIElement* element = uidesc_get("powerup_help");

	UIElement* text_elem2 = uidesc_get_child(element, "text2");
	UIElement* text_elem3 = uidesc_get_child(element, "text3");	

	UIElement* star = uidesc_get_child(element, "star");
	UIElement* item = uidesc_get_child(element, "item");	
	UIElement* button_quit = uidesc_get_child(element, "button_quit");

	float state_alpha = 1.0f-fabsf(t);
	byte a = lrintf(255.0f * state_alpha);
	Color col = COLOR_RGBA(255, 255, 255, a);

	spr_draw("blue_shade", hud_layer-1, rectf(0.0f, 0.0f, v_width, v_height), col); 

	static float xpos = 0.0f;
	static float inc = 600.0f;

	xpos = hud_scroll(xpos, inc, item_count, t);

	for(uint i = 0; i < item_count; ++i) {
		Vector2 off = vec2(xpos + i * inc, 0.0f);
		float d = normalize(fabsf(off.x), 0.0f, inc * (item_count-1));
		float scroll_alpha = 1.0f / exp(PI*d);
		byte a2 = lrintf(255.0f * scroll_alpha * state_alpha);
		Color col2 = COLOR_RGBA(255, 255, 255, a2);

		// Star
		spr_draw_cntr_h(star->spr, hud_layer, vec2_add(off, star->vec2), time_s()/10.0f, 1.0f, col2);

		// Item
		const char* item_img = powerup_params[i].unlocked_spr;
		spr_draw_cntr(item_img, hud_layer, vec2_add(off, item->vec2), 0.0f, 1.0f, col2);

		// Description text
		const char* text3 = powerup_params[i].description;
		vfont_select(FONT_NAME, 32.0f);
		Vector2 half_size3 = vec2_scale(vfont_size(text3), 0.5f);
		vfont_draw(text3, hud_layer+1, vec2_add(off, vec2_sub(text_elem3->vec2,half_size3)), col2);	

		// Item name
		const char* text2 = powerup_params[i].name;
		vfont_select(FONT_NAME, 48.0f);
		Vector2 half_size2 = vec2_scale(vfont_size(text2), 0.5f);
		vfont_draw(text2, hud_layer+1, vec2_add(off, vec2_sub(text_elem2->vec2,half_size2)), col2);	

	}

	// Quit button
	if(hud_button(button_quit, col, t)) {
		malka_states_pop();
	}

	return true;
}
Exemplo n.º 12
0
main()
{
	register Point Min;
	register Point Max;
	register Rectangle r;
	register Point p, q, s;
	register Point inc;

#ifdef DMD630
	local();
#endif
	request(KBD);
	s.x = s.y = SIZE;
	P->state |= RESHAPED;
	while (kbdchar() != 'q') {
		if (P->state & MOVED) {
			q = sub (Drect.origin, q);
			p = add (q, p);
			Max = add (q, Max);
			Min = add (q, Min);
			P->state &= ~(MOVED|RESHAPED);
			q = Drect.origin;
		}
		else if (P->state & RESHAPED) {
			rectf(&display, Drect, F_XOR);
			Min = p = Drect.origin;
			Max = sub (Drect.corner, s);
			inc.x = 1;
			inc.y = 1;
			P->state &= ~RESHAPED;
			q = Drect.origin;
		}
		rectf(&display, Rpt(p, add (p, s)), F_XOR);
		p.x += inc.x;
		if ((p.x >= Max.x) || (p.x <= Min.x))
			inc.x = -inc.x;
		p.y += inc.y;
		if ((p.y >= Max.y) || (p.y <= Min.y))
			inc.y = -inc.y;
		wait(CPU);
	}
}
Exemplo n.º 13
0
	Counter(Scene2::Texture &tex, const vec2f &at, const f32 &scale, const u32 &val)
		: Tex({	Scene2::Texture( tex, rectf(0,164, Stride, 164), vec2s(496,329)  ), 
			Scene2::Texture( tex, rectf(Stride,164, Stride, 164), vec2s(496,329)  ), 
			Scene2::Texture( tex, rectf(Stride*2,164, Stride, 164), vec2s(496,329)  ), 
			Scene2::Texture( tex, rectf(Stride*3,164, Stride, 164), vec2s(496,329)  ), 
			Scene2::Texture( tex, rectf(Stride*4,164, Stride, 164), vec2s(496,329)  ), 
			Scene2::Texture( tex, rectf(0,0, Stride, 164), vec2s(496,329)  ), 
			Scene2::Texture( tex, rectf(Stride,0, Stride, 164), vec2s(496,329)  ), 
			Scene2::Texture( tex, rectf(Stride*2,0, Stride, 164), vec2s(496,329)  ), 
			Scene2::Texture( tex, rectf(Stride*3,0, Stride, 164), vec2s(496,329)  ), 
			Scene2::Texture( tex, rectf(Stride*4,0, Stride, 164), vec2s(496,329)  )
	}), Value(val)
	{
		for( int i = 3; i--; ) {
			Spr[i].Size = vec2f(99, 164)*scale;
			Spr[i].Pos = at + vec2f(Spr[i].Size.x,0)*(f32)i;
			Spr[i].Tex = &Tex[0];
			Spr[i].Rotation = 0;
		}
	}
Exemplo n.º 14
0
rectf rectf::from_coordinates(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
{
	if(x1 > x2+1) {
		std::swap(x1, x2);
	}

	if(y1 > y2+1) {
		std::swap(y1, y2);
	}
	return rectf(x1, y1, x2-x1+1, y2-y1+1);
}
Exemplo n.º 15
0
static void printBoxes(FILE *f)
{
    for (int i = 0; i<10; i++) {
        startLayer(f);
        for (double x=-45; x<45; x+=20) {
            for (double y=-45; y<45; y+=20) {
                rectf(f, x, y, 10.0, 10.0);
            }
        }
        endLayer(f);
    }
}
Exemplo n.º 16
0
	void Blittable::preRender(const WindowPtr& wm)
	{
		if(changed_) {
			changed_ = false;

			if(draw_rect_.w() == 0 || draw_rect_.h() == 0) {
				draw_rect_ = rectf(0.0f, 0.0f, static_cast<float>(getTexture()->surfaceWidth()), static_cast<float>(getTexture()->surfaceHeight()));
			}

			float offs_x = 0.0f;
			float offs_y = 0.0f;
			switch(centre_) {
				case Centre::MIDDLE:		
					offs_x = -draw_rect_.w()/2.0f;
					offs_y = -draw_rect_.h()/2.0f;
					break;
				case Centre::TOP_LEFT: break;
				case Centre::TOP_RIGHT:
					offs_x = -draw_rect_.w();
					offs_y = 0;
					break;
				case Centre::BOTTOM_LEFT:
					offs_x = 0;
					offs_y = -draw_rect_.h();
					break;
				case Centre::BOTTOM_RIGHT:
					offs_x = -draw_rect_.w();
					offs_y = -draw_rect_.h();
					break;
				case Centre::MANUAL:
					offs_x = centre_offset_.x;
					offs_y = centre_offset_.y;
					break;
			}

			const float vx1 = (vertical_mirrored_ ? draw_rect_.x2() : draw_rect_.x()) + offs_x;
			const float vy1 = (horizontal_mirrored_ ? draw_rect_.y2() : draw_rect_.y()) + offs_y;
			const float vx2 = (vertical_mirrored_ ? draw_rect_.x() : draw_rect_.x2()) + offs_x;
			const float vy2 = (horizontal_mirrored_ ? draw_rect_.y() : draw_rect_.y2()) + offs_y;

			const rectf& r = getTexture()->getSourceRectNormalised();

			std::vector<vertex_texcoord> vertices;
			vertices.emplace_back(glm::vec2(vx1,vy1), glm::vec2(r.x(),r.y()));
			vertices.emplace_back(glm::vec2(vx2,vy1), glm::vec2(r.x2(),r.y()));
			vertices.emplace_back(glm::vec2(vx1,vy2), glm::vec2(r.x(),r.y2()));
			vertices.emplace_back(glm::vec2(vx2,vy2), glm::vec2(r.x2(),r.y2()));
			getAttributeSet().back()->setCount(vertices.size());
			attribs_->update(&vertices);
		}
	}
Exemplo n.º 17
0
rectf::rectf(const std::vector<int>& v)
{
	switch(v.size()) {
	case 2:
		*this = rectf::from_area(v[0], v[1], 0, 0);
		break;
	case 3:
		*this = rectf::from_area(v[0], v[1], v[2], 0);
		break;
	case 4:
		*this = rectf::from_area(v[0], v[1], v[2], v[3]);
		break;
	default:
		*this = rectf();
		break;
	}
}
Exemplo n.º 18
0
rectf::rectf(const variant& value)
{
	std::vector<decimal> v = value.as_list_decimal();
	switch(v.size()) {
	case 2:
		*this = rectf::from_area(GLfloat(v[0].as_float()), GLfloat(v[1].as_float()), 0, 0);
		break;
	case 3:
		*this = rectf::from_area(GLfloat(v[0].as_float()), GLfloat(v[1].as_float()), GLfloat(v[2].as_float()), 0);
		break;
	case 4:
		*this = rectf::from_area(GLfloat(v[0].as_float()), GLfloat(v[1].as_float()), GLfloat(v[2].as_float()), GLfloat(v[3].as_float()));
		break;
	default:
		*this = rectf();
		break;
	}
}
Exemplo n.º 19
0
GuiDesc greed_gui_style(bool highres) {
	GuiDesc style;

	gui_tex = tex_load("greed_assets/gui_new.png");
	if(highres) {
		huge_font = font_load_ex("greed_assets/lucida_grande_60px.bft", 0.5f);
		big_font = font_load_ex("greed_assets/lucida_grande_28px.bft", 0.5f);
		small_font = font_load_ex("greed_assets/lucida_grande_20px.bft", 0.5f);
	}	
	else {
		huge_font = font_load("greed_assets/lucida_grande_30px.bft");
		big_font = font_load("greed_assets/lucida_grande_14px.bft");
		small_font = font_load("greed_assets/lucida_grande_10px.bft");
	}	

	style.texture = gui_tex;
	style.font = big_font;

	style.text_color = COLOR_WHITE;

	style.first_layer = 12;
	style.second_layer = 13;
	style.text_layer = 14;

	style.src_button_up = rectf(0.0f, 0.0f, 252.0f, 41.0f);
	style.src_button_down = rectf(0.0f, 42.0f, 252.0f, 42.0f + 41.0f);
	style.src_switch_off_up = rectf(0.0f, 93.0f, 0.0f + 24.0f, 93.0f + 30.0f);
	style.src_switch_off_down = rectf(23.0f, 93.0f, 23.0f + 24.0f, 93.0f + 30.0f);
	style.src_switch_on_up = rectf(48.0f, 93.0f, 48.0f + 24.0f, 93.0f + 30.0f);
	style.src_switch_on_down = rectf(74.0f, 93.0f, 74.0f + 24.0f, 93.0f + 30.0f);
	style.src_slider = rectf(0.0f, 126.0f, 254.0f, 126.0f + 18.0f);
	style.src_slider_knob_up = rectf(1.0f, 149.0f, 1.0f + 18.0f, 149.0f + 18.0f);
	style.src_slider_knob_down = rectf(20.0f, 149.0f, 20.0f + 18.0f, 149.0f + 18.0f);

	return style;
}
Exemplo n.º 20
0
static void obj_trampoline_construct(GameObject* self, Vector2 pos, void* user_data) {
	SprHandle spr_handle = (SprHandle)user_data;

	ObjTrampoline* trampoline = (ObjTrampoline*)self;

	Vector2 size = sprsheet_get_size_h(spr_handle);
	float width = size.x;
	float height = size.y;

	trampoline->oh = height;
	trampoline->h = height;
	trampoline->dh = 0.0f;
	trampoline->db = 0.0f;

	RectF collider = {
		pos.x - 50.0f, 			pos.y,
		pos.x  + width + 50.0f, pos.y - height
	};

	// Physics
	PhysicsComponent* physics = self->physics;
	physics->cd_obj = coldet_new_aabb(objects_cdworld, &collider, OBJ_TRAMPOLINE_TYPE, NULL);
	physics->inv_mass = 0.0f;
	physics->hit_callback = obj_trampoline_collide;

	// Render
	RenderComponent* render = self->render;
	render->world_dest = rectf(
			pos.x, pos.y - height,
			pos.x + width, pos.y
	);
	render->layer = foreground_layer;
	render->anim_frame = MAX_UINT16;
	render->spr = spr_handle;
	render->update_pos = obj_trampoline_update_pos;
	render->became_invisible = obj_trampoline_became_invisible;

	// for rising up animation
	physics->cd_obj->pos.y += height/2.0f + 15.0f;
	render->world_dest.bottom += height/2.0f + 15.0f;
}
Exemplo n.º 21
0
static void _precalc_vis(DArray geometry, NavMesh* res) {
	assert(res);

	Segment* segs = DARRAY_DATA_PTR(geometry, Segment);

	res->vis_bitmap = MEM_ALLOC(sizeof(uint) * vis_bitmap_size);
	memset(res->vis_bitmap, 0, sizeof(uint) * vis_bitmap_size);

	for(uint y = 0; y < vis_bitmap_height; ++y) {
		for(uint x = 0; x < vis_bitmap_width; ++x) {
			// Construct corresponding screen rect
			float fx = (float)x;
			float fy = (float)y;
			RectF r = rectf(
				fx * vis_cell_width, fy * vis_cell_height,
				(fx + 1.0f) * vis_cell_width, (fy + 1.0f) * vis_cell_height
			);

			// Check if any wall segment intersects rect
			bool solid = false;
			for(uint i = 0; i < geometry.size; ++i) {
				// Raycast is used as a simple binary check
				Vector2 hitp = rectf_raycast(&r, &segs[i].p1, &segs[i].p2);

				// Float comparison is ok here - see rectf_raycast code
				if(hitp.x != segs[i].p2.x || hitp.y != segs[i].p2.y) {
					solid = true;
					break;
				}	
			}

			// Set bit
			if(solid) {
				uint cell = IDX_2D(x, y, vis_bitmap_width);
				res->vis_bitmap[cell/32] |= (1 << (31 - (cell % 32)));
			}
		}
	}
}
Exemplo n.º 22
0
	void Material::init(const variant& node)
	{
		blend_.set(BlendModeConstants::BM_SRC_ALPHA, BlendModeConstants::BM_ONE_MINUS_SRC_ALPHA);

		if(node.is_string()) {
			name_ = node.as_string();
			tex_.emplace_back(DisplayDevice::createTexture(name_));
		} else if(node.is_map()) {
			name_ = node["name"].as_string();
		
			// XXX: technically a material could have multiple technique's and passes -- ignoring for now.
			ASSERT_LOG(node.has_key("technique"), "PSYSTEM2: 'material' must have 'technique' attribute.");
			ASSERT_LOG(node["technique"].has_key("pass"), "PSYSTEM2: 'material' must have 'pass' attribute.");
			const variant& pass = node["technique"]["pass"];
			use_lighting_ = pass["lighting"].as_bool(false);
			use_fog_ = pass["fog_override"].as_bool(false);
			do_depth_write_ = pass["depth_write"].as_bool(true);
			do_depth_check_ = pass["depth_check"].as_bool(true);
			if(pass.has_key("scene_blend")) {
				blend_.set(pass["scene_blend"]);
			}
			if(pass.has_key("texture_unit")) {
				if(pass["texture_unit"].is_map()) {
					tex_.emplace_back(createTexture(pass["texture_unit"]));
				} else if(pass["texture_unit"].is_list()) {
					for(size_t n = 0; n != pass["texture_unit"].num_elements(); ++n) {
						tex_.emplace_back(createTexture(pass["texture_unit"][n]));
					}
				} else {
					ASSERT_LOG(false, "'texture_unit' attribute must be map or list ");
				}
			}
			if(pass.has_key("rect")) {
				draw_rect_ = rectf(pass["rect"]);
			}
		} else {
			ASSERT_LOG(false, "Materials(Textures) must be either a single string filename or a map.");
		}
	}
Exemplo n.º 23
0
static void obj_mushroom_construct(GameObject* self, Vector2 pos, void* user_data) {
	SprHandle spr_handle = (SprHandle)user_data;

	ObjMushroom* mushroom = (ObjMushroom*)self;

	Vector2 size = sprsheet_get_size_h(spr_handle);
	float width = size.x;
	float height = size.y;

	mushroom->oh = height;
	mushroom->h = height;
	mushroom->dh = 0.0f;

	float adjust = 20.0f;

	// Take 10 pixel slice at the top as a collider geometry
	RectF collider = {
		pos.x  + adjust, 		pos.y - height,
		pos.x  + width - adjust, pos.y - height + 10.0f
	};

	// Physics
	PhysicsComponent* physics = self->physics;
	physics->cd_obj = coldet_new_aabb(objects_cdworld, &collider, OBJ_MUSHROOM_TYPE, NULL);
	physics->inv_mass = 0.0f;
	physics->hit_callback = obj_mushroom_collide;

	// Render
	RenderComponent* render = self->render;
	render->world_dest = rectf(
			pos.x, pos.y - height,
			pos.x + width, pos.y
	);
	render->layer = foreground_layer;
	render->anim_frame = MAX_UINT16;
	render->spr = spr_handle;
	render->update_pos = obj_mushroom_update_pos;
	render->became_invisible = obj_mushroom_became_invisible;
}
Exemplo n.º 24
0
    //-------------------------------------------------------------------------
    //                                   i n i t
    //-------------------------------------------------------------------------
    int CApplication::init()
    {
        SIrrlichtCreationParameters cp;
        static SKeyMap keyMap[5];
        keyMap[0].Action = EKA_MOVE_FORWARD;
        keyMap[0].KeyCode = KEY_KEY_W;
        keyMap[1].Action = EKA_STRAFE_LEFT;
        keyMap[1].KeyCode = KEY_KEY_A;
        keyMap[2].Action = EKA_MOVE_BACKWARD;
        keyMap[2].KeyCode = KEY_KEY_S;
        keyMap[3].Action = EKA_STRAFE_RIGHT;
        keyMap[3].KeyCode = KEY_KEY_D;
        keyMap[4].Action = EKA_JUMP_UP;
        keyMap[4].KeyCode = KEY_SPACE;

        int result=0;
        stringc msg;


        // use null device for early file system access
        IrrlichtDevice* m_nullDevice = createDevice(EDT_NULL);
        IFileSystem* fileSystem = m_nullDevice->getFileSystem();

        m_currentDirectory = fileSystem->getWorkingDirectory();
        m_currentDirectory = fileSystem->flattenFilename(m_currentDirectory);
        if(m_argv)
        {
            m_appExecutable = m_argv[0];
        }
        else
        {
            m_appExecutable = "irrlicht.exe";
        }


        stringc appBaseName;
        appBaseName = fileSystem->getAbsolutePath(m_appExecutable);
        appBaseName = fileSystem->getFileBasename(appBaseName, false);

        //
        // create log writer
        //
        m_logName = appBaseName;
        m_logName += ".log";

        m_logFile = fileSystem->createAndWriteFile(m_logName);

        msg = "Created log file: ";
        msg += m_logName;
        logMessage(msg);

        //
        // configuration system
        //
        // locate the data directory - underneath our executable or outside of it.
        stringc temp("data/");
        if(!fileSystem->existFile(temp))
        {
            temp = "../data/";
            // todo - look for "data.zip"...
        }
        m_dataRoot = fileSystem->getAbsolutePath(temp);
        m_configName = m_dataRoot;
        m_configName += "/cfg/";
        m_configName += appBaseName;
        m_configName += ".xml";


        if(!fileSystem->existFile(m_configName))
        {
            // not in data/cfg or ../data/cfg so look in the working directory.
            m_configName = appBaseName;
            m_configName += ".xml";
            if(!fileSystem->existFile(m_configName))
            {
                return -1;
            }
        }

        // load the config file
        m_config = new CXMLConfig();
        if(!m_config->load(m_configName))
        {
            return -1;
        }

        // setup the device based on config settings
        stringc sdriver = m_config->getString("driver","video","EDT_OPENGL");
        cp.DriverType = EDT_OPENGL;
        if(sdriver == "EDT_DIRECT3D9")
            cp.DriverType = EDT_DIRECT3D9;        
        cp.WindowSize = m_config->getDimension("resolution","video",dimension2di(800, 600));
        cp.Bits = m_config->getInt("colordepth","video",32);
        cp.Fullscreen = m_config->getBool("fullscreen","video",false);
        cp.Vsync = m_config->getBool("vsync","video",true);
        cp.Stencilbuffer = m_config->getBool("stencilbuffer","video",false);
        cp.AntiAlias = m_config->getInt("antialias","video",0);
        cp.EventReceiver = this;
        cp.WindowId = 0;

        m_device =  createDeviceEx(cp);
        if(!m_device)
            return -1;

        m_fileSystem = m_device->getFileSystem();
        m_videoDriver = m_device->getVideoDriver();
        m_sceneManager = m_device->getSceneManager();
        m_gui = m_device->getGUIEnvironment();

        m_device->getCursorControl()->setVisible(m_config->getBool("HWCursorVisible","video",true));
        m_device->setWindowCaption(stringw(m_title).c_str());


        //
        // add configured file systems
        //
        if(_initFileSystems())
            return -1;

        //
        // set up the default font
        //        
        stringc fontFolder = "fnt/";
        stringc defFonts = fontFolder + "defaults.zip";
        if(m_fileSystem->existFile(defFonts.c_str()))
        {
            m_fileSystem->addZipFileArchive(defFonts.c_str());
            m_defaultFont = m_gui->getFont("tdeffont.xml");
            if(m_defaultFont)
            {
                m_defaultFont->grab();
                m_gui->getSkin()->setFont(m_defaultFont);
            }
            m_monoFont = m_gui->getFont("monospace.xml");
            if(m_monoFont)
            {
                m_monoFont->grab();
            }
        }

        m_world = m_sceneManager->createMetaTriangleSelector();

        // camera setup
        f32 rotateSpeed = m_config->getFloat("rotateSpeed","options",100.f);
        m_orgMoveSpeed = m_config->getFloat("moveSpeed","options",0.001f);
        f32 jumpSpeed = m_config->getFloat("jumpSpeed","options",0.05f);
        m_camera = m_sceneManager->addCameraSceneNodeFPS(0, rotateSpeed, m_orgMoveSpeed, -1,keyMap,5,true, jumpSpeed);

        vector3df v = m_config->getVector3("campos","options");
        m_camera->setPosition(v);

        v = m_config->getVector3("camtarget","options");
        m_camera->setTarget(v);

        bool collisionEnabled = m_config->getBool("collision","options");
        if(collisionEnabled)
        {
            vector3df gravity,ellipsoid;
            gravity = m_config->getVector3("gravity","options",vector3df(0,-0.1f,0));
            ellipsoid = m_config->getVector3("ellipsoid","options",vector3df(2,5,2));
            m_collisionResponse = m_sceneManager->createCollisionResponseAnimator(m_world,m_camera,
                ellipsoid, gravity);
            m_camera->addAnimator(m_collisionResponse);
        }
        
        // debug & help panels setup
        m_debugPanel = new gui::CGUITextPanel(m_gui, "debugPanel", rectf(0.25f,0.005f,0.75f,0.05f));
        m_debugPanel->addItem("Node: Pos(x,y,z) Hpr(x,y,z) Dir(x,y,z)", EGUIA_CENTER);
        m_debugPanel->addItem("Frame: Avg(0.0) Min(0.0) Max(0.0)", EGUIA_CENTER);
        m_debugPanel->setVisible(true);

        m_helpPanel = new gui::CGUITextPanel(m_gui, "helpPanel", rectf(0.005f,0.005f,0.245f,0.05f));
        m_helpPanel->addItem(" wasd - Movement");
        m_helpPanel->addItem("   F1 - Toggle Help");
        m_helpPanel->addItem("   F2 - Toggle Debug");

        createScene();

        return result;
    }
Exemplo n.º 25
0
void CDraw::recti( SColor& color, short x, short y, short width, short height )
{
	rectf( color, float(x)/float(Engine::g_width), float(y)/float(Engine::g_height), float(width)/float(Engine::g_width), float(height)/float(Engine::g_height) );
}
Exemplo n.º 26
0
void MapWidget::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    QRectF rectf(0, 0, width(), height());
    QPointF vpTopLeft = mViewportPos + mDragOffset;

    painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);

    painter.fillRect(rectf, Qt::black);

    painter.save();
    painter.translate(vpTopLeft);
    painter.scale(mScale, mScale);

    if (mTileSize.isValid()) {
        int i, j, tile_indx;
        QPoint visAreaBeg = getCellUnderMouse(QPoint(0,0)); // TODO: this is just viewport coords / width-height!
        clipCellCoord(visAreaBeg);
        QPoint visAreaEnd = getCellUnderMouse(visAreaBeg + QPoint(this->width(), this->height()));
        clipCellCoord(visAreaEnd);

        for(i = visAreaBeg.x(); i <= visAreaEnd.x(); ++i) {
            for(j = visAreaBeg.y(); j <= visAreaEnd.y(); ++j) {
                tile_indx = mCells.at(i + j * mCols);
                if (tile_indx >= 0)
                    painter.drawImage(i * mTileSize.width(), j * mTileSize.height(), mTiles[tile_indx].im);
            }
        }

        // highlight cursor
        switch (mEditMode) {
        case NORMAL:
            if (mSelectionBegin && !mSelectionEnd) {
                QRect frame = getSelectedArea(*mSelectionBegin, mCellUnderMouse);
                painter.fillRect(
                    frame.left() * mTileSize.width(),
                    frame.top() * mTileSize.height(),
                    frame.width() * mTileSize.width(),
                    frame.height() * mTileSize.height(),
                    QColor(127, 127, 255, 50));
            } else if (isValidCell(mCellUnderMouse)) {
                int x = mCellUnderMouse.x() * mTileSize.width();
                int y = mCellUnderMouse.y() * mTileSize.height();
                painter.fillRect(x, y, mTileSize.width(), mTileSize.height(), QColor(127, 127, 255, 50));
            }
            break;

        case GRAB:
        case DUPLICATE:
            {
                QRect selArea = getSelectedArea(*mSelectionBegin, *mSelectionEnd);
                QRect frame(
                    mCellUnderMouse.x() - mGrabOrigin.x(),
                    mCellUnderMouse.y() - mGrabOrigin.y(),
                    selArea.width(),
                    selArea.height());
                painter.fillRect(
                    frame.left() * mTileSize.width(),
                    frame.top() * mTileSize.height(),
                    frame.width() * mTileSize.width(),
                    frame.height() * mTileSize.height(),
                    QColor(127, 127, 255, 50));
            }
            break;
        }

        // highlight selected
        if (mSelectionBegin && mSelectionEnd) {
            QRect frame = getSelectedArea(*mSelectionBegin, *mSelectionEnd);
            painter.fillRect(
                frame.left() * mTileSize.width(),
                frame.top() * mTileSize.height(),
                frame.width() * mTileSize.width(),
                frame.height() * mTileSize.height(),
                QColor(0, 255, 0, 75));
        }

        painter.setPen(Qt::red);
        painter.drawRect(-1, -1, mCols * mTileSize.width(), mRows * mTileSize.height());
    } else {
        painter.setPen(Qt::red);
        painter.drawLine(-10, 0, 10, 0);
        painter.drawLine(0, -10, 0, 10);
    }
    painter.restore();

    painter.setPen(Qt::green);
    painter.drawRect(rectf);
}
Exemplo n.º 27
0
void PieWidget::paintEvent(QPaintEvent *event)
{

    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing,true);
    painter.setPen(Qt::NoPen);
    QRectF rectf(0,0,diameter,diameter);
    int allcount = 0;
    for(int i = 0; i < STATENUM; i++)
    {
        allcount+=statecounts[i];
    }
    int startangle = 0;
    int spanangle = 0;
    if(allcount != 0)
    {
        for(int i = 0; i < STATENUM; i++)
        {
            startangle = startangle + spanangle;
            spanangle = 360*16*statecounts[i]/float(allcount);
            painter.setBrush(QBrush(statecolors[i]));
            painter.drawPie(rectf,startangle,spanangle);
        }
        /*QPen pen;
        pen.setColor(Qt::blue);
        pen.setWidth(2);
        painter.setPen(pen);
        painter.drawEllipse(1,1,diameter - 2,diameter - 2);*/

    }
    else
    {
        painter.setBrush(QBrush(Qt::Dense4Pattern));
        painter.drawEllipse(rectf);
        /*QPen pen;
        pen.setColor(Qt::blue);
        pen.setWidth(2);
        painter.setPen(pen);
        painter.drawEllipse(1,1,diameter - 2,diameter - 2);*/
    }
    if(isparent)
    {
        int ystart = (diameter - STATENUM*STATEHINTHEIGHT - (STATENUM - 1)*STATEHINTVERSPACE)/2;
        for(int i = 0; i < STATENUM; i++)
        {
            painter.setPen(Qt::NoPen);
            painter.setBrush(QBrush(statecolors[i]));
            painter.drawRect(diameter+HORIZONSPACE,ystart+(STATEHINTHEIGHT+STATEHINTVERSPACE)*i,STATEHINTHEIGHT,STATEHINTHEIGHT);
            painter.setBrush(Qt::NoBrush);
            painter.setPen(Qt::SolidLine);
            QRectF textrectf(diameter+HORIZONSPACE + STATEHINTHEIGHT + 10,ystart+(STATEHINTHEIGHT+STATEHINTVERSPACE)*i,100,STATEHINTHEIGHT);
            if(allcount != 0)
                painter.drawText(textrectf,Qt::AlignLeft|Qt::AlignVCenter,statename.at(i) + QString::number(statecounts[i]/float(allcount)*100,'f',1) + "%(" +QString::number(statecounts[i])+")");
            else
                painter.drawText(textrectf,Qt::AlignLeft|Qt::AlignVCenter,statename.at(i) + "0.0%(0)");
            painter.drawText(diameter+HORIZONSPACE + STATEHINTHEIGHT + 10,ystart+(STATEHINTHEIGHT+STATEHINTVERSPACE)*STATENUM,100,STATEHINTHEIGHT,Qt::AlignLeft|Qt::AlignLeft,name);
        }
    }
    else
    {
        int ystart = diameter + VERTICALSPACE;
        for(int i = 0; i < STATENUM; i++)
        {
            painter.setPen(Qt::NoPen);
            painter.setBrush(QBrush(statecolors[i]));
            //painter.drawRect(diameter/4,ystart+(STATEHINTHEIGHT+STATEHINTVERSPACE)*i,STATEHINTHEIGHT,STATEHINTHEIGHT);
            painter.drawRect(0,ystart+(STATEHINTHEIGHT+STATEHINTVERSPACE)*i,STATEHINTHEIGHT,STATEHINTHEIGHT);
            painter.setBrush(Qt::NoBrush);
            painter.setPen(Qt::SolidLine);
           // QRectF textrectf(diameter/4 + STATEHINTHEIGHT + 10,ystart+(STATEHINTHEIGHT+STATEHINTVERSPACE)*i,100,STATEHINTHEIGHT);
            QRectF textrectf(0 + STATEHINTHEIGHT + 10,ystart+(STATEHINTHEIGHT+STATEHINTVERSPACE)*i,100,STATEHINTHEIGHT);
            if(allcount != 0)
                painter.drawText(textrectf,Qt::AlignLeft|Qt::AlignVCenter,/*statename.at(i) +*/QString::number(statecounts[i]/float(allcount)*100,'f',1) + "%(" +QString::number(statecounts[i])+")");
            else
                painter.drawText(textrectf,Qt::AlignLeft|Qt::AlignVCenter,/*statename.at(i) +*/"0.0%(0)");
        }
        /*namelabel->setFixedHeight(STATEHINTHEIGHT);
        namelabel->setAlignment(Qt::AlignCenter);
        namelabel->setText(name);
        namelabel->move(0,ystart+(STATEHINTHEIGHT+STATEHINTVERSPACE)*STATENUM);*/
        painter.drawText(0,ystart+(STATEHINTHEIGHT+STATEHINTVERSPACE)*STATENUM - STATEHINTVERSPACE ,diameter,STATEHINTHEIGHT,Qt::AlignCenter,name);

    }
}
Exemplo n.º 28
0
void SaagharItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
						 const QModelIndex &index) const
{
//	if (parent()->objectName()=="searchTable")
//	{
//		qDebug() << keywordList;
//	}
	const bool flagRightToLeft = true;
	int textHMargin = 0;
	if (tableStyle)
	{
		textHMargin = tableStyle->pixelMetric(QStyle::PM_FocusFrameHMargin, &option) +1 ;
	}

	QBrush itemBrush = painter->brush();
	
	itemBrush.setColor(SaagharWidget::matchedTextColor);
	itemBrush.setStyle(Qt::SolidPattern);

	QString text="";
	QString cleanedText = "";
	int lastX,x;
	const QFontMetrics fontMetric(option.fontMetrics);
	const QString tatweel = QString(0x0640);

	int iconWidth = 0;

	if (index.data().isValid())
	{
		text = index.data().toString();

		if (index.data(Qt::DecorationRole).isValid())
		{
			QIcon icon = index.data(Qt::DecorationRole).value<QIcon>();
			iconWidth = icon.pixmap(100, 100).width()+5;
		}

		cleanedText = QGanjoorDbBrowser::cleanString(text);
//		if (text.contains( QString::fromLocal8Bit(
//							  "پسر چون ز مادر بران گونه زاد"
////			                      "پرپر شد ..."
//					/*"وَز ســوری و نــعــمـان وزد، هـر دم شـمـیـم عـنـبـریـن"*/)))
//		{
//			qDebug() << "textt="<<text;
//			qDebug() << "clean="<<cleanedText;
//		}
		text = QGanjoorDbBrowser::cleanString(text/*, false*/);
	}
	//qDebug() << "text="<<text<<"cleanedText="<<cleanedText;
	Qt::Alignment itemAlignment = 0;
	QVariant alignValue = index.data(Qt::TextAlignmentRole);
	
	if (alignValue.isValid() && !alignValue.isNull())
		itemAlignment = Qt::Alignment(alignValue.toInt());

	int keywordsCount = keywordList.size();
	for (int i=0; i<keywordsCount; ++i)
	{
		lastX = x = option.rect.x()+textHMargin;
		//QString keyword = keywordList.isEmpty() ? "" : keywordList.at(0);
		QString keyword = keywordList.at(i);

		keyword.replace(QChar(0x200C), "", Qt::CaseInsensitive);//replace ZWNJ by ""
		//qDebug() << "keyword1="<<keyword;
		keyword = keyword.split("", QString::SkipEmptyParts).join(tatweel+"*");
		//qDebug() << "keyword2="<<keyword;
		keyword.replace("@"+tatweel+"*", "\\S*", Qt::CaseInsensitive);//replace wildcard by word chars
		//qDebug() << "keyword3="<<keyword;
		QRegExp maybeTatweel(keyword, Qt::CaseInsensitive);
		maybeTatweel.indexIn(text);
		//qDebug() << text<<"count=" << maybeTatweel.captureCount()<<maybeTatweel.capturedTexts();
		//qDebug() << "Match: "<<maybeTatweel.cap(0);
		keyword = maybeTatweel.cap(0);
	if (!(keyword.isEmpty() || text.indexOf(keyword) == -1 ) )
	{
		QString txt = text;
		while (txt.size() > 0)
		{
			int index = txt.indexOf(keyword);
			QString thisPart;
			if (index == -1)
			{
				thisPart = txt;
				txt = QString();
			}
			else
			{
				if (index == 0)
				{
					thisPart = txt.mid(0, keyword.size());
					if (txt == keyword)
						txt = QString();
					else
						txt = txt.mid(keyword.size(), txt.size() - keyword.size());
				}
				else
				{
					thisPart = txt.mid(0, index);
					txt = txt.mid(index);
				}
			}
				
			QSize sz = fontMetric.boundingRect(thisPart).size();
			if (index == 0)
			{
				if (flagRightToLeft)
				{
					switch (itemAlignment^Qt::AlignVCenter)
					{
						case Qt::AlignRight:
							lastX = option.rect.left()+textHMargin+fontMetric.boundingRect(text).width()-(lastX-option.rect.x()+sz.width()-textHMargin);
							break;

						case Qt::AlignHCenter:
							lastX = option.rect.left()+textHMargin+fontMetric.boundingRect(text).width()-(lastX-option.rect.x()+sz.width()-textHMargin)+((option.rect.width()-fontMetric.boundingRect(text).width()-textHMargin)/2);
							break;

						case Qt::AlignLeft:
						default:
							lastX = option.rect.right()+textHMargin-1 - (lastX-option.rect.x()+sz.width());
							break;
					}
				}

				QRectF rectf(lastX , option.rect.y()+((option.rect.height()-qMin(option.rect.height(), fontMetric.height()))/2), sz.width(), fontMetric.height() );
				qreal oldOpacity = painter->opacity();
				painter->setOpacity(0.65);
				rectf.adjust(-iconWidth, 0, -iconWidth, 0);
				QPainterPath roundedRect;
				roundedRect.addRoundRect(rectf, 50, 50);
				QPen defaultPen(painter->pen());
				painter->setPen(SaagharWidget::matchedTextColor.darker(150));
				painter->drawPath(roundedRect);
				painter->fillPath( roundedRect, itemBrush );
				painter->setOpacity(oldOpacity);
				painter->setPen(defaultPen);
				//painter->fillRect( rectf, itemBrush );
			}
			x += option.fontMetrics.width(thisPart);
			lastX = x;
		}
	}
	else if (!(keyword.isEmpty() || cleanedText.indexOf(keyword) == -1 ) )
	{
		qreal oldOpacity = painter->opacity();
		painter->setOpacity(0.35);
		painter->fillRect( option.rect, itemBrush );
		painter->setOpacity(oldOpacity);
		//painter->fillRect( rectf, itemBrush );
	}
	}
	QStyledItemDelegate::paint(painter, option, index);
}
Exemplo n.º 29
0
Arquivo: rect.c Projeto: berndf/avg_q
/*
 * rectfs
 *
 * draw a filled rectangle given two opposite corners (expressed as short
 * integers)
 */
void
rectfs(Scoord x1, Scoord y1, Scoord x2, Scoord y2)
{
	rectf((Coord)x1, (Coord)y1, (Coord)x2, (Coord)y2);
}
Exemplo n.º 30
0
Arquivo: rect.c Projeto: berndf/avg_q
/*
 * rectfi
 *
 * draw a filled rectangle given two opposite corners (expressed as integers)
 */
void
rectfi(Icoord x1, Icoord y1, Icoord x2, Icoord y2)
{
	rectf((Coord)x1, (Coord)y1, (Coord)x2, (Coord)y2);
}