Пример #1
0
void
View::update(float delta)
{
  //std::cout << "View:update: " << x1 << " " << y1 << " " << x2 << " " << y2 
    //<< " " << state.x_offset << " " << state.y_offset << std::endl;

  if (view_updater)
    view_updater->update(delta, state);

  scene_context->reset_modelview();
  scene_context->translate(get_x_offset(), get_y_offset());
  //drawing_context.translate(state.x_offset, state.y_offset);
}
Пример #2
0
ss_model::ss_model(MODULE *module)
{
	if (oclass==NULL)
	{
		// register to receive notice for first top down. bottom up, and second top down synchronizations
		oclass = gld_class::create(module,"ss_model",sizeof(ss_model),PC_BOTTOMUP|PC_AUTOLOCK);
		if (oclass==NULL)
			throw "unable to register class ss_model";
		else
			oclass->trl = TRL_PRINCIPLE;

		defaults = this;
		if (gl_publish_variable(oclass,
			PT_enumeration,"form",get_form_offset(),PT_DESCRIPTION,"desired canonical controller type",
				PT_KEYWORD,"CCF",CF_CCF,
				PT_KEYWORD,"OCF",CF_OCF,
			PT_double,"timestep",get_timestep_offset(),PT_UNITS,"s",PT_DESCRIPTION,"discrete timestep",
			PT_char1024, "Y", get_Y_offset(),PT_DESCRIPTION,"transfer function numerator coefficients",
			PT_char1024, "U", get_U_offset(),PT_DESCRIPTION,"transfer function denominator coefficients",
			PT_char1024, "x", get_x_offset(),PT_DESCRIPTION,"state variable values",
			PT_char1024, "u", get_u_offset(),PT_DESCRIPTION,"ss_model variable names",
			PT_char1024, "y", get_y_offset(),PT_DESCRIPTION,"output variable names",
			PT_char1024, "H", get_H_offset(),PT_DESCRIPTION,"transfer function",
			PT_char1024, "A", get_y_offset(),PT_DESCRIPTION,"canonical A matrix",
			PT_char1024, "B", get_y_offset(),PT_DESCRIPTION,"canonical B matrix",
			PT_char1024, "C", get_y_offset(),PT_DESCRIPTION,"canonical C matrix",
			PT_char1024, "D", get_y_offset(),PT_DESCRIPTION,"canonical D matrix",

			NULL)<1){
				char msg[256];
				sprintf(msg, "unable to publish properties in %s",__FILE__);
				throw msg;
		}

		memset(this,0,sizeof(ss_model));
	}
}
Пример #3
0
/**
 * ppg_ruler_draw_ruler:
 * @ruler: (in): A #PpgRuler.
 *
 * Draws the background of the ruler containing the time values and ticks
 * to an offscreen pixmap that can be blitted to the widget during
 * "expose-event".
 *
 * Returns: None.
 * Side effects: None.
 */
static void
ppg_ruler_draw_ruler (PpgRuler *ruler)
{
	PpgRulerPrivate *priv;
	GtkAllocation alloc;
	PangoLayout *layout;
	cairo_t *cr;
	GtkStyle *style;
	GdkColor text_color;
	gint text_width;
	gint text_height;
	gdouble every = 1.0;
	gdouble n_seconds;
	gdouble v;
	gdouble p;
	gint pw;
	gint ph;
	gint x;
	gint xx;
	gint n;
	gint z = 0;

	g_return_if_fail(PPG_IS_RULER(ruler));

	priv = ruler->priv;

	gtk_widget_get_allocation(GTK_WIDGET(ruler), &alloc);
	style = gtk_widget_get_style(GTK_WIDGET(ruler));
	cr = gdk_cairo_create(priv->ruler);

	cairo_save(cr);
	cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
	cairo_rectangle(cr, 0, 0, alloc.width, alloc.height);
	cairo_fill(cr);
	cairo_restore(cr);

	text_color = style->text[GTK_STATE_NORMAL];
	cairo_set_line_width(cr, 1.0);
	gdk_cairo_set_source_color(cr, &text_color);

	layout = pango_cairo_create_layout(cr);
	pango_layout_set_font_description(layout, priv->font_desc);
	pango_layout_set_markup(layout, "00:00:00.000", -1);
	pango_layout_get_pixel_size(layout, &text_width, &text_height);
	text_width += 5;

	n_seconds = priv->upper - priv->lower;
	if ((alloc.width / n_seconds) < text_width) {
		every = ceil(text_width / (alloc.width / n_seconds));
	}

	for (v = floor(priv->lower); v < priv->upper; v += every) {
		gdk_cairo_set_source_color(cr, &text_color);
		x = get_x_offset(priv, &alloc, v);
		cairo_move_to(cr, x + 0.5, alloc.height - 1.5);
		cairo_line_to(cr, x + 0.5, 0.5);

		/*
		 * Mini lines.
		 */
		for (p = v, n = 0, z = 0;
		     p < v + every;
		     p += (every / 10), n++, z++)
		{
			if (n == 0 || n == 10) {
				continue;
			}

			xx = get_x_offset(priv, &alloc, p);
			cairo_move_to(cr, xx + 0.5, alloc.height - 1.5);
			if (z % 2 == 0) {
				cairo_line_to(cr, xx + 0.5, text_height + 8.5);
			} else {
				cairo_line_to(cr, xx + 0.5, text_height + 5.5);
			}
		}

		cairo_stroke(cr);

		cairo_move_to(cr, x + 1.5, 1.5);
		ppg_ruler_update_layout_text(ruler, layout,
		                             CLAMP(v, priv->lower, priv->upper));

		/*
		 * If there is enough room to draw this layout before we get to the
		 * next layout, then draw it.
		 */
		pango_layout_get_pixel_size(layout, &pw, &ph);
		if ((x + pw) < get_x_offset(priv, &alloc, floor(v) + every)) {
			pango_cairo_show_layout(cr, layout);
		}
	}

	g_object_unref(layout);
	cairo_destroy(cr);
}
Пример #4
0
FloatVector2d
View::world_to_screen (const FloatVector2d& pos)
{
  return FloatVector2d (pos.x + get_x_offset (),
                        pos.y + get_y_offset ());
}
Пример #5
0
FloatVector2d
View::screen_to_world (const FloatVector2d& pos)
{
  return FloatVector2d (pos.x - get_x_offset (),
                        pos.y - get_y_offset ());
}
Пример #6
0
static void
ppg_line_visualizer_draw (PpgVisualizer *visualizer)
{
	PpgLineVisualizerPrivate *priv;
	PpgModelIter iter;
	Line *line;
	PpgColorIter color;
	cairo_t *cr;
	GValue value = { 0 };
	gfloat height;
	gfloat width;
	gdouble x;
	gdouble y;
	gdouble begin;
	gdouble end;
	gdouble lower;
	gdouble upper;
	gdouble val = 0;
	gint i;

	g_return_if_fail(PPG_IS_LINE_VISUALIZER(visualizer));

	priv = PPG_LINE_VISUALIZER(visualizer)->priv;

	clutter_cairo_texture_clear(CLUTTER_CAIRO_TEXTURE(priv->actor));
	cr = clutter_cairo_texture_create(CLUTTER_CAIRO_TEXTURE(priv->actor));

	g_object_get(visualizer,
	             "begin", &begin,
	             "end", &end,
	             NULL);

	g_object_get(priv->actor,
	             "width", &width,
	             "height", &height,
	             NULL);

	/* FIXME: */
	lower = 0;
	upper = 200;

	ppg_color_iter_init(&color);

	cairo_set_line_width(cr, 1.0);

	for (i = 0; i < priv->lines->len; i++) {
		line = &g_array_index(priv->lines, Line, i);
		cairo_move_to(cr, 0, height);
		gdk_cairo_set_source_color(cr, &color.color);

		if (!ppg_model_get_iter_first(line->model, &iter)) {
			goto next;
		}

		do {
			ppg_model_get_value(line->model, &iter, line->key, &value);
			if (G_VALUE_HOLDS(&value, G_TYPE_DOUBLE)) {
				val = g_value_get_double(&value);
			} else if (G_VALUE_HOLDS(&value, G_TYPE_INT)) {
				val = g_value_get_int(&value);
			} else if (G_VALUE_HOLDS(&value, G_TYPE_UINT)) {
				val = g_value_get_uint(&value);
			} else {
				g_critical("HOLDS %s", g_type_name(value.g_type));
				g_assert_not_reached();
			}
			x = get_x_offset(begin, end, width, iter.time);
			y = get_y_offset(lower, upper, height, val);
			cairo_line_to(cr, x, y);
			g_value_unset(&value);
		} while (ppg_model_iter_next(line->model, &iter));

		cairo_stroke(cr);

	  next:
		ppg_color_iter_next(&color);
	}

	cairo_destroy(cr);
}