Beispiel #1
0
/** Displays the FPS in the top corner of the screen */
void print_fps(void)
{
	set_font_size(.75);
	glColor4f(0.0, 1.0, 1.0, 1.0);
	if(fps < 100.0) print_gl(640 - 75, 5, "FPS: %2.1f", fps);
	else print_gl(640 - 75, 5, "FPS:%3.1f", fps);
	set_font_size(1.0);
}
	void
	mucharmap_mini_font_selection_reset_font_size (MucharmapMiniFontSelection *fontsel)
	{
	  if (fontsel->default_size > 0) {
		set_font_size (fontsel, fontsel->default_size);
	  } else {
		GtkStyle *style;

		style = gtk_widget_get_style (GTK_WIDGET (fontsel));
		set_font_size (fontsel, pango_font_description_get_size (style->font_desc) * 2.0f / PANGO_SCALE);
	  }
	}
Beispiel #3
0
static void draw_centered_label(int y, int size, char * label) {
	set_font_face(FONT_SANS_SERIF);
	set_font_size(size);

	int x = center_win_x(draw_string_width(label));
	draw_string(ctx, x, y, rgb(0,0,0), label);
}
Beispiel #4
0
void _ttk_draw_button_select(cairo_t * cr, int x, int y, int width, int height, char * title) {
	cairo_save(cr);

	cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
	cairo_set_line_join(cr, CAIRO_LINE_JOIN_ROUND);

	cairo_rounded_rectangle(cr, 2 + x, 2 + y, width - 4, height - 4, 2.0);
	cairo_set_source_rgba(cr, 134.0/255.0, 173.0/255.0, 201.0/255.0, 1.0);
	cairo_set_line_width(cr, 2);
	cairo_stroke(cr);

	cairo_rounded_rectangle(cr, 2 + x, 2 + y, width - 4, height - 4, 2.0);
	cairo_set_source_rgba(cr, 202.0/255.0, 211.0/255.0, 232.0/255.0, 1.0);
	cairo_fill(cr);

	{
		cairo_surface_t * surface = cairo_get_target(cr);
		gfx_context_t fake_context = {
			.width = cairo_image_surface_get_width(surface),
			.height = cairo_image_surface_get_height(surface),
			.depth = 32,
			.buffer = NULL,
			.backbuffer = cairo_image_surface_get_data(surface)
		};

		set_font_face(FONT_SANS_SERIF);
		set_font_size(13);

		int str_width = draw_string_width(title);
		draw_string(&fake_context, (width - str_width) / 2 + x, y + (height) / 2 + 4, rgb(49,49,49), title);
	}

	cairo_restore(cr);
	
}
Beispiel #5
0
void _ttk_draw_menu(cairo_t * cr, int x, int y, int width) {
	cairo_save(cr);

	int height = TTK_MENU_HEIGHT;
	cairo_set_source_rgba(cr, 59.0/255.0, 59.0/255.0, 59.0/255.0, 1);
	cairo_rectangle(cr, x, y, width, height);
	cairo_fill(cr);

	{
		cairo_surface_t * surface = cairo_get_target(cr);
		gfx_context_t fake_context = {
			.width = cairo_image_surface_get_width(surface),
			.height = cairo_image_surface_get_height(surface),
			.depth = 32,
			.buffer = NULL,
			.backbuffer = cairo_image_surface_get_data(surface)
		};

		set_font_face(FONT_SANS_SERIF);
		set_font_size(13);

		draw_string(&fake_context, x + 8, y + height - 6, rgb(248,248,248), "File");
	}


	cairo_restore(cr);
}
Beispiel #6
0
void _ttk_draw_button_hover(cairo_t * cr, int x, int y, int width, int height) {
	cairo_save(cr);

	cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
	cairo_set_line_join(cr, CAIRO_LINE_JOIN_ROUND);

	cairo_rounded_rectangle(cr, 2 + x, 2 + y, width - 4, height - 4, 2.0);
	cairo_set_source_rgba(cr, 44.0/255.0, 71.0/255.0, 91.0/255.0, 29.0/255.0);
	cairo_set_line_width(cr, 4);
	cairo_stroke(cr);

	cairo_rounded_rectangle(cr, 2 + x, 2 + y, width - 4, height - 4, 2.0);
	cairo_set_source_rgba(cr, 158.0/255.0, 169.0/255.0, 177.0/255.0, 1.0);
	cairo_set_line_width(cr, 2);
	cairo_stroke(cr);

	{
		cairo_pattern_t * pat = cairo_pattern_create_linear(2 + x, 2 + y, 2 + x, 2 + y + height - 4);
		cairo_pattern_add_color_stop_rgba(pat, 0, 1, 1, 1, 1);
		cairo_pattern_add_color_stop_rgba(pat, 1, 229.0/255.0, 229.0/255.0, 246.0/255.0, 1);
		cairo_rounded_rectangle(cr, 2 + x, 2 + y, width - 4, height - 4, 2.0);
		cairo_set_source(cr, pat);
		cairo_fill(cr);
		cairo_pattern_destroy(pat);
	}

	{
		cairo_pattern_t * pat = cairo_pattern_create_linear(3 + x, 3 + y, 3 + x, 3 + y + height - 4);
		cairo_pattern_add_color_stop_rgba(pat, 0, 252.0/255.0, 252.0/255.0, 254.0/255.0, 1);
		cairo_pattern_add_color_stop_rgba(pat, 1, 212.0/255.0, 223.0/255.0, 251.0/255.0, 1);
		cairo_rounded_rectangle(cr, 3 + x, 3 + y, width - 5, height - 5, 2.0);
		cairo_set_source(cr, pat);
		cairo_fill(cr);
		cairo_pattern_destroy(pat);
	}

	{
		cairo_surface_t * surface = cairo_get_target(cr);
		gfx_context_t fake_context = {
			.width = cairo_image_surface_get_width(surface),
			.height = cairo_image_surface_get_height(surface),
			.depth = 32,
			.buffer = NULL,
			.backbuffer = cairo_image_surface_get_data(surface)
		};

		set_font_face(FONT_SANS_SERIF);
		set_font_size(13);

		char * title = "Button with Hover Highlight";
		int str_width = draw_string_width(title);
		draw_string(&fake_context, (width - str_width) / 2 + x, y + (height) / 2 + 4, rgb(49,49,49), title);
	}

	cairo_restore(cr);
	
}
	Text_input::Text_input(std::string font, Mesure x, Mesure y, Mesure w, Mesure h, WritingRestriction wrestriction) :Rectangle(x, y, w, h), restrictions(wrestriction)
	{
		set_bgcolor(0xffffff);
		set_bgopacity(1);
		set_font(font);
		set_font_size(21);
		set_alignement(left);
		ever_refresh_text = true;
	}
	static void 
	font_size_changed (GtkAdjustment *adjustment,
		               MucharmapMiniFontSelection *fontsel)
	{
	  int new_size;

	  new_size = gtk_adjustment_get_value (adjustment);
	  if (new_size != get_font_size (fontsel))
		set_font_size (fontsel, new_size);
	}
Beispiel #9
0
static void render_decorations_fancy(yutani_window_t * window, gfx_context_t * ctx, char * title, int decors_active) {
	int width = window->width;
	int height = window->height;

	for (int j = 0; j < decor_top_height; ++j) {
		for (int i = 0; i < width; ++i) {
			GFX(ctx,i,j) = 0;
		}
	}

	for (int j = decor_top_height; j < height - decor_bottom_height; ++j) {
		for (int i = 0; i < decor_left_width; ++i) {
			GFX(ctx,i,j) = 0;
		}
		for (int i = width - decor_right_width; i < width; ++i) {
			GFX(ctx,i,j) = 0;
		}
	}

	for (int j = height - decor_bottom_height; j < height; ++j) {
		for (int i = 0; i < width; ++i) {
			GFX(ctx,i,j) = 0;
		}
	}

	if (decors_active == DECOR_INACTIVE) decors_active = INACTIVE;

	draw_sprite(ctx, sprites[decors_active + 0], 0, 0);
	for (int i = 0; i < width - (ul_width + ur_width); ++i) {
		draw_sprite(ctx, sprites[decors_active + 1], i + ul_width, 0);
	}
	draw_sprite(ctx, sprites[decors_active + 2], width - ur_width, 0);
	for (int i = 0; i < height - (u_height + l_height); ++i) {
		draw_sprite(ctx, sprites[decors_active + 3], 0, i + u_height);
		draw_sprite(ctx, sprites[decors_active + 4], width - mr_width, i + u_height);
	}
	draw_sprite(ctx, sprites[decors_active + 5], 0, height - l_height);
	for (int i = 0; i < width - (ll_width + lr_width); ++i) {
		draw_sprite(ctx, sprites[decors_active + 6], i + ll_width, height - l_height);
	}
	draw_sprite(ctx, sprites[decors_active + 7], width - lr_width, height - l_height);

	set_font_face(FONT_SANS_SERIF_BOLD);
	set_font_size(12);

	int title_offset = (width / 2) - (draw_string_width(title) / 2);
	if (decors_active == 0) {
		draw_string(ctx, title_offset, TEXT_OFFSET, rgb(226,226,226), title);
	} else {
		draw_string(ctx, title_offset, TEXT_OFFSET, rgb(147,147,147), title);
	}

	/* Buttons */
	draw_sprite(ctx, sprites[decors_active + 8], width - 28, 16);
}
Beispiel #10
0
void draw_text_box(cairo_t * cr, struct text_box * tb) {
	int x = tb->parent->x + tb->x;
	int y = tb->parent->y + tb->y;

	set_font_size(13);
	int text_offset = 15;

	cairo_rounded_rectangle(cr, 1 + x, 1 + y, tb->width - 2, tb->height - 2, 2.0);
	if (tb->is_focused) {
		cairo_set_source_rgba(cr, 8.0/255.0, 193.0/255.0, 236.0/255.0, 1.0);
	} else {
		cairo_set_source_rgba(cr, 158.0/255.0, 169.0/255.0, 177.0/255.0, 1.0);
	}
	cairo_set_line_width(cr, 2);
	cairo_stroke(cr);

	{
		cairo_pattern_t * pat = cairo_pattern_create_linear(1 + x, 1 + y, 1 + x, 1 + y + tb->height - 2);
		if (tb->is_focused) {
			cairo_pattern_add_color_stop_rgba(pat, 0, 241.0/255.0, 241.0/255.0, 244.0/255.0, 1.0);
			cairo_pattern_add_color_stop_rgba(pat, 1, 1, 1, 1, 1.0);
		} else {
			cairo_pattern_add_color_stop_rgba(pat, 0, 241.0/255.0, 241.0/255.0, 244.0/255.0, 0.9);
			cairo_pattern_add_color_stop_rgba(pat, 1, 1, 1, 1, 0.9);
		}
		cairo_rounded_rectangle(cr, 1 + x, 1 + y, tb->width - 2, tb->height - 2, 2.0);
		cairo_set_source(cr, pat);
		cairo_fill(cr);
		cairo_pattern_destroy(pat);
	}

	char * text = tb->buffer;
	char password_circles[512];
	uint32_t color = tb->text_color;

	if (strlen(tb->buffer) == 0 && !tb->is_focused) {
		text = tb->placeholder;
		color = rgba(0,0,0,127);
	} else if (tb->is_password) {
		strcpy(password_circles, "");
		for (int i = 0; i < strlen(tb->buffer); ++i) {
			strcat(password_circles, "⚫");
		}
		text = password_circles;
	}

	draw_string(ctx, x + TEXTBOX_INTERIOR_LEFT, y + text_offset, color, text);

	if (tb->is_focused) {
		int width = draw_string_width(text);
		draw_line(ctx, x + TEXTBOX_INTERIOR_LEFT + width, x + TEXTBOX_INTERIOR_LEFT + width, y + 2, y + text_offset + 1, tb->text_color);
	}

}
Beispiel #11
0
BEE::Font::Font (std::string new_name, std::string new_path, int new_font_size, bool new_is_sprite) {
	reset();

	add_to_resources();
	if (id < 0) {
		game->messenger_send({"engine", "resource"}, BEE_MESSAGE_WARNING, "Failed to add font resource: \"" + new_name + "\" from " + new_path);
		throw(-1);
	}

	set_name(new_name);
	set_path(new_path);
	set_font_size(new_font_size);
	is_sprite = new_is_sprite;
}
Beispiel #12
0
widget_settings_dialog* label::settings_dialog(int x, int y, int w, int h)
{
	widget_settings_dialog* d = widget::settings_dialog(x,y,w,h);

	grid_ptr g(new grid(2));

	text_editor_widget_ptr text_edit = new text_editor_widget(150, 30);
	text_edit->set_text(text());
	text_edit->set_on_user_change_handler([=](){set_text(text_edit->text());});
	g->add_col(new label("Text:", d->text_size(), d->font()))
		.add_col(text_edit);

	g->add_col(new label("Size:", d->text_size(), d->font())).
		add_col(new slider(120, [&](double f){set_font_size(int(f*72.0+6.0));}, (size()-6.0)/72.0, 1));

	std::vector<std::string> fonts = font::get_available_fonts();
	fonts.insert(fonts.begin(), "");
	dropdown_widget_ptr font_list(new dropdown_widget(fonts, 150, 28, dropdown_widget::DROPDOWN_LIST));
	font_list->set_font_size(14);
	font_list->set_dropdown_height(height());
	auto fit = std::find(fonts.begin(), fonts.end(), font());
	font_list->set_selection(fit == fonts.end() ? 0 : fit-fonts.begin());
	font_list->set_on_select_handler([&](int n, const std::string& s){set_font(s);});
	font_list->set_zorder(19);
	g->add_col(new label("Font:", d->text_size(), d->font()))
		.add_col(font_list);
	g->add_col(new label("Color:", d->text_size(), d->font()))
		.add_col(new button(new label("Choose...", d->text_size(), d->font()), [&](){
			int mx, my;
			SDL_GetMouseState(&mx, &my);
			mx = mx + 200 > preferences::actual_screen_width() ? preferences::actual_screen_width()-200 : mx;
			my = my + 600 > preferences::actual_screen_height() ? preferences::actual_screen_height()-600 : my;
			my -= d->y();
			color_picker* cp = new color_picker(rect(0, 0, 200, 600), [&](const graphics::color& color){set_color(color.as_sdl_color());});
			cp->set_primary_color(graphics::color(color_));

			grid_ptr gg = new grid(1);
			gg->allow_selection();
			gg->swallow_clicks();
			gg->set_show_background(true);
			gg->allow_draw_highlight(false);
			gg->register_selection_callback([=](int n){if(n != 0){d->remove_widget(gg); d->init();}});
			gg->set_zorder(100);
			gg->add_col(cp);
			d->add_widget(gg, d->x()-mx-100, my);
	}));

	d->add_widget(g);
	return d;
}
Beispiel #13
0
void ttext_box::load_config_extra()
{
	assert(config());

	boost::intrusive_ptr<const ttext_box_definition::tresolution>
	conf = boost::dynamic_pointer_cast<const ttext_box_definition::tresolution>(
			config());

	assert(conf);

	set_font_size(conf->text_font_size);
	set_font_style(conf->text_font_style);

	update_offsets();
}
Beispiel #14
0
void ttext_box::load_config_extra()
{
	assert(config());

	std::shared_ptr<const ttext_box_definition::tresolution>
	conf = std::static_pointer_cast<const ttext_box_definition::tresolution>(
			config());

	assert(conf);

	set_font_size(conf->text_font_size);
	set_font_style(conf->text_font_style);

	update_offsets();
}
Beispiel #15
0
void draw_bonus(player_data_t *plyr) {
    bonus_data_t* bonus = bonus_list;

    int i=0;
    while (bonus!=NULL)
    {
        i++;
        bonus_data_t* next_bonus = bonus->next;
        scalar_t anim_time = g_game.time-bonus->start_time;
        if (anim_time < BONUS_TIME_ANIMATION) {
            char *binding;
            font_t *font;

            //Use the same font as for FPS
            binding = "bonus";

            if ( !get_font_binding( binding, &font ) ) {
                print_warning( IMPORTANT_WARNING,
                               "Couldn't get font for binding %s", binding );
                return;
            }

            char* string = bonus->bonus_string;

            set_font_color(font, color_from_time_delta(anim_time));
            set_font_size(font, scale_from_time_delta(anim_time) * 12);
            scalar_t width, a, d;
            get_font_metrics_scalar( font, string, &width, &a, &d);

            bind_font_texture( font );
            set_gl_options( TEXFONT );

            glPushMatrix();
            {
                glTranslatef( 800 * (1 - position_from_time_delta(anim_time)) - width/2 - 140, 200.0 + i*18.0, 0 );

                draw_string( font, string );
            }
            glPopMatrix();
        } else {
            remove_bonus(bonus);
        }

        bonus = next_bonus;

    }
}
Beispiel #16
0
void label::set_value(const std::string& key, const variant& v)
{
	if(key == "text") {
		if(v.is_null()) {
			set_text("");
		} else {
			set_text(v.as_string());
		}
	} else if(key == "color") {
		set_color(graphics::color(v).as_sdl_color());
	} else if(key == "size") {
		set_font_size(v.as_int());
	} else if(key == "font") {
		set_font(v.as_string());
	}
	widget::set_value(key, v);
}
Beispiel #17
0
bool vsx_widget_note::init_from_command(vsx_command_s* c)
{
  set_render_type(render_3d);
  vsx_vector3<> np;
  np = vsx_vector3_helper::from_string<float>(c->parts[2]);
  set_pos(np);
  np = vsx_vector3_helper::from_string<float>(c->parts[3]);
  set_size(np);
  set_font_size(vsx_string_helper::s2f(c->parts[5]));
  set_border(font_size*0.15f);
  size_min.x = font_size*3.0f;
  size_min.y = font_size*4.0f;

  //new_note->target_size = new_note->size;
  load_text( vsx_string_helper::base64_decode(c->parts[4]));
  return true;
}
	void
	mucharmap_mini_font_selection_change_font_size (MucharmapMiniFontSelection *fontsel,
		                                            float factor)
	{
	  int size, new_size;

	  g_return_if_fail (factor > 0.0f);

	  size = get_font_size (fontsel);
	  new_size = (float) size * factor;

	  if (factor > 1.0f)
		new_size = MAX (new_size, size + 1);
	  else if (factor < 1.0f)
		new_size = MIN (new_size, size - 1);

	  set_font_size (fontsel, new_size);
	}
Beispiel #19
0
void draw_login_container(cairo_t * cr, struct login_container * lc) {

	/* Draw rounded rectangle */
	cairo_rounded_rectangle(cr, lc->x, lc->y, lc->width, lc->height, (float)BOX_ROUNDNESS);
	cairo_set_source_rgba(cr, (float)(BOX_COLOR_R)/255.0, (float)(BOX_COLOR_G)/255.0, (float)(BOX_COLOR_B)/255.0, (float)(BOX_COLOR_A)/255.0);
	cairo_fill(cr);

	/* Draw labels */
	if (lc->show_error) {
		char * error_message = "Incorrect username or password.";

		set_font_size(11);
		draw_string(ctx, lc->x + (lc->width - draw_string_width(error_message)) / 2, lc->y + 6 + EXTRA_TEXT_OFFSET, rgb(240, 20, 20), error_message);
	}

	draw_text_box(cr, lc->username_box);
	draw_text_box(cr, lc->password_box);

}
Beispiel #20
0
//---------------------------------------------------------------------------------------
bool FontStorage::set_font(const std::string& fontFullName, double height,
                           EFontCacheType type)
{
    m_fValidFont = false;
    lomse::glyph_rendering gren = lomse::glyph_ren_agg_gray8;
    if(! m_fontEngine.select_font(fontFullName, 0, gren))
        return !m_fValidFont;    //error

    //set curren values for renderization
    m_fontCacheType = type;
    set_font_size(height);

    ////un-comment this to rotate/skew/translate the text
    ////agg::trans_affine mtx;
    ////mtx *= agg::trans_affine_rotation(agg::deg2rad(-4.0));
    //////mtx *= agg::trans_affine_skewing(-0.4, 0);
    //////mtx *= agg::trans_affine_translation(1, 0);
    ////m_fontEngine.transform(mtx);

    m_fValidFont = true;
    return !m_fValidFont;
}
Beispiel #21
0
int main (int argc, char ** argv) {
	setup_windowing();

	int width  = wins_globals->server_width;
	int height = wins_globals->server_height;

	win_width = width;
	win_height = height;

	init_shmemfonts();
	set_font_size(14);

	/* Create the panel */
	window_t * panel = window_create(0, 0, width, PANEL_HEIGHT);
	window_reorder (panel, 0xFFFF);
	ctx = init_graphics_window_double_buffer(panel);
	draw_fill(ctx, rgba(0,0,0,0));
	flip(ctx);

	init_sprite_png(0, "/usr/share/panel.png");
	init_sprite_png(1, "/usr/share/icons/panel-shutdown.png");

	for (uint32_t i = 0; i < width; i += sprites[0]->width) {
		draw_sprite(ctx, sprites[0], i, 0);
	}

	size_t buf_size = panel->width * panel->height * sizeof(uint32_t);
	char * buf = malloc(buf_size);
	memcpy(buf, ctx->backbuffer, buf_size);

	flip(ctx);

	struct timeval now;
	int last = 0;
	struct tm * timeinfo;
	char   buffer[80];

	struct utsname u;
	uname(&u);

	/* UTF-8 Strings FTW! */
	uint8_t * os_name_ = "PonyOS";
	uint8_t final[512];
	uint32_t l = snprintf(final, 512, "%s %s", os_name_, u.release);

	syscall_signal(2, sig_int);

	/* Enable mouse */
	win_use_threaded_handler();
	mouse_action_callback = panel_check_click;

	while (_continue) {
		/* Redraw the background by memcpy (super speedy) */
		memcpy(ctx->backbuffer, buf, buf_size);
		syscall_gettimeofday(&now, NULL); //time(NULL);
		if (now.tv_sec != last) {
			last = now.tv_sec;
			timeinfo = localtime((time_t *)&now.tv_sec);
			strftime(buffer, 80, "%I:%M:%S %p", timeinfo);

			draw_string(ctx, width - 120, 17, rgb(255,255,255), buffer);
			draw_string(ctx, 10, 17, rgb(255,255,255), final);

			draw_sprite(ctx, sprites[1], win_width - 23, 1); /* Logout button */

			flip(ctx);
		}
		syscall_nanosleep(0,50);
	}
Beispiel #22
0
static void
set_font_size (GtkWidget *widget, gint size)
{
  const gchar *class[3] = { "small-font", "medium-font", "large-font" };

  gtk_style_context_add_class (gtk_widget_get_style_context (widget), class[size]);
}

int
main (int    argc,
      char **argv)
{
  GtkWidget *window, *label, *entry, *button, *grid, *notebook;
  GtkWidget *vbox, *hbox, *grid_hbox, *spin, *spin2, *toggle, *combo, *image;
  GtkAdjustment *adjustment;
  int i, j;
  GtkCssProvider *provider;

  gtk_init ();

  provider = gtk_css_provider_new ();
  gtk_css_provider_load_from_data (provider,
    ".small-font { font-size: 5px; }"
    ".medium-font { font-size: 10px; }"
    ".large-font { font-size: 15px; }", -1);
  gtk_style_context_add_provider_for_display (gdk_display_get_default (),
                                              GTK_STYLE_PROVIDER (provider),
                                              GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
  g_object_unref (provider);
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL);

  notebook = gtk_notebook_new ();
  gtk_container_add (GTK_CONTAINER (window), notebook);

  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
  gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
			    vbox, gtk_label_new ("hboxes"));

  for (j = 0; j < 2; j++)
    {
      hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
      gtk_box_pack_start (GTK_BOX (vbox), hbox);

      char *aligns_names[] = { "FILL", "BASELINE" };
      GtkAlign aligns[] = { GTK_ALIGN_FILL, GTK_ALIGN_BASELINE};

      label = gtk_label_new (aligns_names[j]);
      gtk_container_add (GTK_CONTAINER (hbox), label);

      for (i = 0; i < 3; i++) {
	label = gtk_label_new ("│XYyj,Ö...");

        set_font_size (label, i);

	gtk_widget_set_valign (label, aligns[j]);

	gtk_container_add (GTK_CONTAINER (hbox), label);
      }

      for (i = 0; i < 3; i++) {
	entry = gtk_entry_new ();
	gtk_entry_set_text (GTK_ENTRY (entry), "│XYyj,Ö...");

        set_font_size (entry, i);

	gtk_widget_set_valign (entry, aligns[j]);

	gtk_container_add (GTK_CONTAINER (hbox), entry);
      }

      spin = gtk_spin_button_new (NULL, 0, 1);
      gtk_orientable_set_orientation (GTK_ORIENTABLE (spin), GTK_ORIENTATION_VERTICAL);
      gtk_widget_set_valign (spin, aligns[j]);
      gtk_container_add (GTK_CONTAINER (hbox), spin);

      spin = gtk_spin_button_new (NULL, 0, 1);
      gtk_widget_set_valign (spin, aligns[j]);
      gtk_container_add (GTK_CONTAINER (hbox), spin);
    }

  grid_hbox = hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
  gtk_box_pack_start (GTK_BOX (vbox), hbox);

  combo = gtk_combo_box_text_new ();
  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), baseline_pos_str[0]);
  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), baseline_pos_str[1]);
  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), baseline_pos_str[2]);
  gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 1);
  gtk_container_add (GTK_CONTAINER (hbox), combo);

  for (j = 0; j < 2; j++)
    {
      hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
      gtk_box_pack_start (GTK_BOX (vbox), hbox);

      g_signal_connect (G_OBJECT (combo), "changed",
			G_CALLBACK (baseline_position_changed), hbox);

      if (j == 0)
	label = gtk_label_new ("Baseline:");
      else
	label = gtk_label_new ("Normal:");
      gtk_container_add (GTK_CONTAINER (hbox), label);

      for (i = 0; i < 3; i++)
	{
	  button = gtk_button_new_with_label ("│Xyj,Ö");

          set_font_size (button, i);

	  if (j == 0)
	    gtk_widget_set_valign (button, GTK_ALIGN_BASELINE);

	  gtk_container_add (GTK_CONTAINER (hbox), button);
	}

      for (i = 0; i < 3; i++)
	{
          GtkWidget *box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,  6);
          button = gtk_button_new ();

          gtk_container_add (GTK_CONTAINER (box), gtk_label_new ("│Xyj,Ö"));
          gtk_container_add (GTK_CONTAINER (box), gtk_image_new_from_icon_name ("face-sad"));
          gtk_container_add (GTK_CONTAINER (button), box);

          set_font_size (button, i);

	  if (j == 0)
	    gtk_widget_set_valign (button, GTK_ALIGN_BASELINE);

	  gtk_container_add (GTK_CONTAINER (hbox), button);
	}

      image = gtk_image_new_from_icon_name ("face-sad");
      gtk_image_set_pixel_size (GTK_IMAGE (image), 34);
      if (j == 0)
	gtk_widget_set_valign (image, GTK_ALIGN_BASELINE);
      gtk_container_add (GTK_CONTAINER (hbox), image);

      button = gtk_toggle_button_new_with_label ("│Xyj,Ö");
      if (j == 0)
	gtk_widget_set_valign (button, GTK_ALIGN_BASELINE);
      gtk_container_add (GTK_CONTAINER (hbox), button);

      button = gtk_toggle_button_new_with_label ("│Xyj,Ö");
      if (j == 0)
	gtk_widget_set_valign (button, GTK_ALIGN_BASELINE);
      gtk_container_add (GTK_CONTAINER (hbox), button);

      button = gtk_check_button_new_with_label ("│Xyj,Ö");
      if (j == 0)
	gtk_widget_set_valign (button, GTK_ALIGN_BASELINE);
      gtk_container_add (GTK_CONTAINER (hbox), button);

      button = gtk_radio_button_new_with_label (NULL, "│Xyj,Ö");
      if (j == 0)
	gtk_widget_set_valign (button, GTK_ALIGN_BASELINE);
      gtk_container_add (GTK_CONTAINER (hbox), button);
    }


  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
  gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
			    vbox, gtk_label_new ("grid"));

  grid_hbox = hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
  gtk_box_pack_start (GTK_BOX (vbox), hbox);

  label = gtk_label_new ("Align me:");
  gtk_widget_set_valign (label, GTK_ALIGN_BASELINE);

  gtk_container_add (GTK_CONTAINER (hbox), label);

  grid = gtk_grid_new ();
  gtk_widget_set_valign (grid, GTK_ALIGN_BASELINE);
  gtk_grid_set_column_spacing (GTK_GRID (grid), 8);
  gtk_grid_set_row_spacing (GTK_GRID (grid), 8);

  for (j = 0; j < 4; j++)
    {
      char *labels[] = { "Normal:", "Baseline (top):", "Baseline (center):", "Baseline (bottom):"};
      label = gtk_label_new (labels[j]);

      gtk_grid_attach (GTK_GRID (grid),
		       label,
		       0, j,
		       1, 1);
      gtk_widget_set_vexpand (label, TRUE);

      if (j != 0)
	gtk_grid_set_row_baseline_position (GTK_GRID (grid),
					    j, (GtkBaselinePosition)(j-1));

      for (i = 0; i < 3; i++)
	{
	  label = gtk_label_new ("Xyjg,Ö.");

          set_font_size (label, i);

	  if (j != 0)
	    gtk_widget_set_valign (label, GTK_ALIGN_BASELINE);

	  gtk_grid_attach (GTK_GRID (grid),
			   label,
			   i+1, j,
			   1, 1);
	}

      for (i = 0; i < 3; i++)
	{
          GtkWidget *box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,  6);
          button = gtk_button_new ();

          gtk_container_add (GTK_CONTAINER (box), gtk_label_new ("│Xyj,Ö"));
          gtk_container_add (GTK_CONTAINER (box), gtk_image_new_from_icon_name ("face-sad"));
          gtk_container_add (GTK_CONTAINER (button), box);

          set_font_size (button, i);

	  if (j != 0)
	    gtk_widget_set_valign (button, GTK_ALIGN_BASELINE);

	  gtk_grid_attach (GTK_GRID (grid),
			   button,
			   i+4, j,
			   1, 1);
	}

    }

  gtk_container_add (GTK_CONTAINER (hbox), grid);

  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
  gtk_box_pack_start (GTK_BOX (vbox), hbox);

  adjustment = gtk_adjustment_new (0.0, -1.0, 5.0, 1.0, 1.0, 0.0);
  spin = gtk_spin_button_new (adjustment, 1.0, 0);
  g_signal_connect (spin, "value-changed", (GCallback)baseline_row_value_changed, grid);
  gtk_container_add (GTK_CONTAINER (hbox), spin);

  toggle = gtk_toggle_button_new_with_label ("Homogeneous");
  g_signal_connect (toggle, "toggled", (GCallback)homogeneous_changed, grid);
  gtk_container_add (GTK_CONTAINER (hbox), toggle);

  combo = gtk_combo_box_text_new ();
  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), baseline_pos_str[0]);
  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), baseline_pos_str[1]);
  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), baseline_pos_str[2]);
  gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 1);
  g_signal_connect (G_OBJECT (combo), "changed",
		    G_CALLBACK (baseline_position_changed), grid_hbox);
  gtk_container_add (GTK_CONTAINER (hbox), combo);

  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
  gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
			    vbox, gtk_label_new ("button box"));

  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
  gtk_box_pack_start (GTK_BOX (vbox), hbox);

  adjustment = gtk_adjustment_new (34.0, 1.0, 64.0, 1.0, 1.0, 0.0);
  spin = gtk_spin_button_new (adjustment, 1.0, 0);
  gtk_container_add (GTK_CONTAINER (hbox), spin);

  adjustment = gtk_adjustment_new (16.0, 1.0, 64.0, 1.0, 1.0, 0.0);
  spin2 = gtk_spin_button_new (adjustment, 1.0, 0);
  gtk_container_add (GTK_CONTAINER (hbox), spin2);

  for (j = 0; j < 3; j++)
    {
      hbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
      gtk_box_pack_start (GTK_BOX (vbox), hbox);

      gtk_box_set_baseline_position (GTK_BOX (hbox), j);

      label = gtk_label_new (baseline_pos_str[j]);
      gtk_container_add (GTK_CONTAINER (hbox), label);
      gtk_widget_set_vexpand (label, TRUE);

      image = gtk_image_new_from_icon_name ("face-sad");
      gtk_image_set_pixel_size (GTK_IMAGE (image), 34);
      gtk_container_add (GTK_CONTAINER (hbox), image);

      g_signal_connect (spin, "value-changed", (GCallback)image_size_value_changed, image);

      for (i = 0; i < 3; i++)
	{
	  button = gtk_button_new_with_label ("│Xyj,Ö");

          set_font_size (button, i);

	  if (i != 0)
	    gtk_widget_set_valign (button, GTK_ALIGN_BASELINE);

	  gtk_container_add (GTK_CONTAINER (hbox), button);
	}

      for (i = 0; i < 3; i++)
	{
          GtkWidget *box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,  6);
          button = gtk_button_new ();

          gtk_container_add (GTK_CONTAINER (box), gtk_label_new ("│Xyj,Ö"));
          image = gtk_image_new_from_icon_name ("face-sad");
          gtk_image_set_pixel_size (GTK_IMAGE (image), 16);
          gtk_container_add (GTK_CONTAINER (box), image);
          gtk_container_add (GTK_CONTAINER (button), box);

	  if (i == 0)
	    g_signal_connect (spin2, "value-changed", (GCallback)image_size_value_changed, image);

          set_font_size (button, i);

	  gtk_widget_set_valign (button, GTK_ALIGN_BASELINE);

	  gtk_container_add (GTK_CONTAINER (hbox), button);
	}
    }

  gtk_widget_show (window);

  gtk_main ();

  return 0;
}
Beispiel #23
0
int main (int argc, char ** argv) {
	init_sprite_png(0, "/usr/share/logo_login.png");
	init_shmemfonts();

	while (1) {
		syscall_print("Setup...\n");
		setup_windowing();

		int width  = wins_globals->server_width;
		int height = wins_globals->server_height;

		win_width = width;
		win_height = height;

		/* Do something with a window */
		window_t * wina = window_create(0,0, width, height);
		assert(wina);
		window_reorder (wina, 0); /* Disables movement */
		ctx = init_graphics_window_double_buffer(wina);

		for (int i = 0; i < LOGO_FINAL_OFFSET; ++i) {
			draw_fill(ctx, rgb(39,55,113));
			draw_sprite(ctx, sprites[0], center_x(sprites[0]->width), center_y(sprites[0]->height) - i);
			flip(ctx);
		}

		size_t buf_size = wina->width * wina->height * sizeof(uint32_t);
		char * buf = malloc(buf_size);

		uint32_t i = 0;

		uint32_t black = rgb(0,0,0);
		uint32_t white = rgb(255,255,255);
		uint32_t red   = rgb(240, 20, 20);

		int x_offset = 65;
		int y_offset = 64;

		int fuzz = 3;

		char username[INPUT_SIZE] = {0};
		char password[INPUT_SIZE] = {0};
		char hostname[512];

		{
			char _hostname[256];
			syscall_gethostname(_hostname);

			struct tm * timeinfo;
			struct timeval now;
			syscall_gettimeofday(&now, NULL); //time(NULL);
			timeinfo = localtime((time_t *)&now.tv_sec);

			char _date[256];
			strftime(_date, 256, "%a %B %d %Y", timeinfo);

			sprintf(hostname, "%s // %s", _hostname, _date);
		}

		char kernel_v[512];

		{
			struct utsname u;
			uname(&u);
			/* UTF-8 Strings FTW! */
			uint8_t * os_name_ = "PonyOS";
			uint32_t l = snprintf(kernel_v, 512, "%s %s", os_name_, u.release);
		}

		uid = 0;

#define BOX_WIDTH  272
#define BOX_HEIGHT 104
#define USERNAME_BOX 1
#define PASSWORD_BOX 2
#define EXTRA_TEXT_OFFSET 12
#define TEXTBOX_INTERIOR_LEFT 4
#define LEFT_OFFSET 80
		int box_x = center_x(BOX_WIDTH);
		int box_y = center_y(0) + 8;

		int focus = USERNAME_BOX;

		set_font_size(11);

		int username_label_left = LEFT_OFFSET - 2 - draw_string_width("Username:"******"Password:"******"");
				for (int i = 0; i < strlen(password); ++i) {
					strcat(password_circles, "●");
				}

				/* Redraw the background */
				draw_fill(ctx, rgb(39,55,113));
				draw_sprite(ctx, sprites[0], center_x(sprites[0]->width), center_y(sprites[0]->height) - LOGO_FINAL_OFFSET);

				draw_string(ctx, hostname_label_left, height - 12, white, hostname);
				draw_string(ctx, kernel_v_label_left, height - 12, white, kernel_v);

				/* Draw backdrops */
				draw_box(ctx, box_x, box_y, BOX_WIDTH, BOX_HEIGHT, rgb(180,124,205));
				draw_box(ctx, box_x + LEFT_OFFSET, box_y + 32, 168, 16, rgb(255,255,255));
				draw_box(ctx, box_x + LEFT_OFFSET, box_y + 56, 168, 16, rgb(255,255,255));

				/* Draw labels */
				draw_string(ctx, box_x + username_label_left, box_y + 32 + EXTRA_TEXT_OFFSET, white, "Username:"******"Password:"******"Incorrect username or password.";
					
					draw_string(ctx, box_x + (BOX_WIDTH - draw_string_width(error_message)) / 2, box_y + 8 + EXTRA_TEXT_OFFSET, red, error_message);
				}

				if (focus == USERNAME_BOX) {
					draw_box_border(ctx, box_x + LEFT_OFFSET, box_y + 32, 168, 16, rgb(229, 68, 138));
				} else if (focus == PASSWORD_BOX) {
					draw_box_border(ctx, box_x + LEFT_OFFSET, box_y + 56, 168, 16, rgb(229, 68, 138));
				}

				flip(ctx);

				w_keyboard_t * kbd = NULL;
				do {
					kbd = poll_keyboard();
				} while (!kbd);

				if (kbd->key == '\n') {
					if (focus == USERNAME_BOX) {
						free(kbd);
						focus = PASSWORD_BOX;
						continue;
					} else if (focus == PASSWORD_BOX) {
						free(kbd);
						break;
					}
				}

				if (kbd->key == '\t') {
					if (focus == USERNAME_BOX) {
						focus = PASSWORD_BOX;
					} else if (focus == PASSWORD_BOX) {
						focus = USERNAME_BOX;
					}
					free(kbd);
					continue;
				}

				if (focus == USERNAME_BOX) {
					buffer_put(username, kbd->key);
				} else if (focus == PASSWORD_BOX) {
					buffer_put(password, kbd->key);
				}
				free(kbd);

			}

			uid = checkUserPass(username, password);

			if (uid >= 0) {
				break;
			}
			show_error = 1;
		}

		draw_fill(ctx, rgb(39,55,113));
		draw_sprite(ctx, sprites[0], center_x(sprites[0]->width), center_y(sprites[0]->height) - LOGO_FINAL_OFFSET);
		flip(ctx);

		teardown_windowing();

		pid_t _session_pid = fork();
		if (!_session_pid) {
			setenv("PATH", "/usr/bin:/bin", 0);
			syscall_setuid(uid);
			char * args[] = {"/bin/gsession", NULL};
			execvp(args[0], args);
		}

		free(buf);
		free(ctx->backbuffer);
		free(ctx);

		syscall_wait(_session_pid);
	}

	return 0;
}
Beispiel #24
0
static void proctext(sdata_t *sdata, weed_timecode_t tc, char *xtext, cairo_t *cairo, PangoLayout *layout,
                     PangoFontDescription *font, int width, int height) {
  double dwidth,dheight;
  double radX,radY;

  switch (sdata->mode) {
  case (PT_WORD_COALESCE):

    if (sdata->timer==0.) {
      sdata->start=-1;
      sdata->length=1;
      sdata->tmode=PT_WORD_MODE;
    }

    if (sdata->start>-1) {
      set_font_size(layout,font,64);
      // get pixel size of word
      getlsize(layout, &dwidth, &dheight);

      setxypos(dwidth,dheight,width/2,height/2,&sdata->x_text,&sdata->y_text);

      sdata->dbl1-=sdata->dbl1/3.5+.5; // blur shrink
      sdata->dbl2+=.07;
      sdata->fg_alpha=sdata->dbl2;
    }

    if (sdata->alarm) {
      pt_subst_t *xsubst;
      char nxlast;

      sdata->bool1=!sdata->bool1;
      sdata->dbl1=300.; // blur start
      sdata->fg_alpha=sdata->dbl2=0.;

      if (sdata->length>0) {
        sdata->start++;
        if (sdata->start>=sdata->wlength) {
          sdata->start=0;
          sdata->length=0;
          sdata->dbl1=0.;
          pt_set_alarm(sdata,1000); // milliseconds
        }
      } else {
        sdata->length=1;
        sdata->bool1=TRUE;
      }

      if (sdata->length>0) {
        if (sdata->start==sdata->wlength-1) {
          pt_set_alarm(sdata,1000); // milliseconds
        } else {
          // peek at last char of next word
          if (sdata->text_type==TEXT_TYPE_ASCII) {
            xsubst=get_nth_word_ascii(sdata->text,sdata->start);
          } else {
            xsubst=get_nth_word_utf8(sdata->text,sdata->start);
          }

          nxlast=sdata->text[xsubst->start+xsubst->length-1];

          weed_free(xsubst);

          if (nxlast=='.'||nxlast=='!'||nxlast=='?') pt_set_alarm(sdata,1000); // milliseconds
          else if (nxlast==',') pt_set_alarm(sdata,700); // milliseconds
          else if (nxlast==';') pt_set_alarm(sdata,800); // milliseconds
          else pt_set_alarm(sdata,500); // milliseconds
        }
      }
    }

    break;

  case (PT_LETTER_STARFIELD):
    if (sdata->timer==0.) {
      sdata->start=0;
      sdata->length=0;

      sdata->tmode=PT_LETTER_MODE;

      sdata->letter_data=letter_data_create(sdata->tlength);
    }

    if (sdata->length>0) {
      pt_letter_data_t *ldt=&sdata->letter_data[sdata->count];
      double dist=ldt->zpos;
      if (dist>1.) {
        set_font_size(layout,font,1024./dist);

        // get pixel size of letter/word
        getlsize(layout, &dwidth, &dheight);

        sdata->x_text=ldt->xpos/dist+(double)width/2.;
        sdata->y_text=ldt->ypos/dist+(double)height/2.;

        setxypos(dwidth,dheight,sdata->x_text,sdata->y_text,&sdata->x_text,&sdata->y_text);

        sdata->fg_alpha=dist/100.+.5;

        anim_letter(ldt);

        colour_copy(&sdata->fg,&ldt->colour);

      } else pango_layout_set_text(layout, "", -1);

    }

    if (sdata->alarm) {
      // set values for next letter
      pt_letter_data_t *ldt=&sdata->letter_data[sdata->length];
      double angle=rand_angle();

      ldt->xpos=ldt->ypos=ldt->rot=ldt->rotvel=0.;
      ldt->zpos=80.+sdata->length;

      if (ldt->zpos>100.) ldt->zpos=100.;

      ldt->xvel=sin(angle)*16.;
      ldt->yvel=cos(angle)*16.;
      ldt->zvel=-2.;

      ldt->xaccel=ldt->yaccel=ldt->zaccel=ldt->rotaccel=0.;

      if (sdata->length==0||!strncmp(&sdata->text[utf8offs(sdata->text,sdata->length)]," ",1)) {
        ldt->colour.red=getrandi(60,255);
        ldt->colour.green=getrandi(60,255);
        ldt->colour.blue=getrandi(60,255);
      } else {
        colour_copy(&ldt->colour,&(sdata->letter_data[sdata->length-1].colour));
      }

      sdata->length++;

      if (sdata->length<sdata->tlength) pt_set_alarm(sdata,400); // milliseconds
      else pt_set_alarm(sdata,-1);
    }


    break;

  case (PT_SPINNING_LETTERS):
    if (sdata->timer==0.) {
      sdata->int1=0;

      // select all text
      sdata->start=0;
      sdata->length=sdata->tlength;

      sdata->tmode=PT_LETTER_MODE;
      sdata->dbl3=0.;
    }

    if (!sdata->count) {
      sdata->dbl1=0.;
      sdata->dbl2=sdata->dbl3;
      sdata->dbl3+=.1;
    }

    set_font_size(layout,font,64);

    sdata->x_text=width-sdata->int1+sdata->dbl1;
    sdata->y_text=height/2;

    // rotate letter
    rotate_text(cairo,layout,sdata->x_text,sdata->y_text,sdata->dbl2);

    // must re-center after rotating
    sdata->x_text=sdata->y_text=0;

    // get pixel size of letter/word
    getlsize(layout, &dwidth, &dheight);

    sdata->dbl1+=dwidth+10.;

    setxypos(0,dheight,sdata->x_text,sdata->y_text,&sdata->x_text,&sdata->y_text);

    if (sdata->alarm) {
      pt_set_alarm(sdata,25); // milliseconds
      // shift rate
      sdata->int1+=8;
    }

    // spin rate
    sdata->dbl2+=.1;

    break;

  case (PT_SPIRAL_TEXT):

    if (sdata->timer==0.) {
      sdata->int1=0;
      sdata->start=0;
      sdata->tmode=PT_LETTER_MODE;
    }

    set_font_size(layout,font,2560./(sdata->count+19.));

    // get pixel size of letter/word
    getlsize(layout, &dwidth, &dheight);

    // expansion factor
    if (sdata->int1<2) {
      sdata->dbl3=1.;
      sdata->bool1=FALSE;
    } else sdata->dbl3+=.0001;

    // set x_text, y_text
    if (!sdata->count) {
      sdata->dbl1=radX=width*.45*sdata->dbl3;
      sdata->dbl2=radY=height*.45*sdata->dbl3;
    } else {
      if (!sdata->bool1) {
        sdata->dbl1=radX=sdata->dbl1*.98;
        sdata->dbl2=radY=sdata->dbl2*.98;
      } else {
        sdata->dbl1=radX=sdata->dbl1*.97;
        sdata->dbl2=radY=sdata->dbl2*.97;
      }
    }

    if (sdata->bool1)
      setxypos(dwidth,dheight,width/2+sin(sdata->count/4.+(sdata->dbl3-1.)*9.)*radX,
               height/2-cos(-sdata->count/4.-(sdata->dbl3-1.)*8.)*radY,&sdata->x_text,&sdata->y_text);

    else
      setxypos(dwidth,dheight,width/2+sin(sdata->count/4.+(sdata->dbl3-1.)*8.)*radX,
               height/2-cos(-sdata->count/4.-(sdata->dbl3-1.)*8.)*radY,&sdata->x_text,&sdata->y_text);

    if (!strncmp(xtext,".",1)) sdata->int1++;

    if (sdata->alarm) {
      pt_set_alarm(sdata,250); // milliseconds
      if (sdata->start+sdata->length<sdata->tlength) {
        // add an extra letter
        sdata->length++;
      } else {
        sdata->length-=2;
        sdata->start+=2;
        sdata->dbl3-=.0002;

        sdata->dbl1=sdata->dbl1*.97;
        sdata->dbl2=radY=sdata->dbl2*.97;

        // trip to lissajou
        if (!sdata->bool1) sdata->bool1=TRUE;

        if (sdata->length<=0) {
          sdata->length=1;
          sdata->start=0;
          sdata->bool1=FALSE;
          sdata->dbl3=-sdata->dbl3/12.;
        } else pt_set_alarm(sdata,50); // milliseconds

      }

    }
    break;

  } // end switch

}
Beispiel #25
0
int do_scalebar(void)
{
    double scale_size;
    double length, width;
    double x, x1, x2, y1, y2, y3;
    int seg, i, j, lab;
    int margin;
    char num[50];

    /* get scale size */
    scale_size =
	METERS_TO_INCHES * distance(PS.w.east, PS.w.west) / scale(PS.scaletext);

    /* convert scale size to map inches */
    length = (sb.length / scale_size) *
	G_database_units_to_meters_factor() * METERS_TO_INCHES;

    /* if(sb.units == SB_UNITS_AUTO) { do nothing } */
    if(sb.units == SB_UNITS_METERS)
	    length /= G_database_units_to_meters_factor();
    else if(sb.units == SB_UNITS_KM)
	    length *= KILOMETERS_TO_METERS / G_database_units_to_meters_factor();
    else if(sb.units == SB_UNITS_FEET)
	    length *= FEET_TO_METERS / G_database_units_to_meters_factor();
    else if(sb.units == SB_UNITS_MILES)
	    length *= MILES_TO_METERS / G_database_units_to_meters_factor();
    else if(sb.units == SB_UNITS_NMILES)
	    length *= NAUT_MILES_TO_METERS / G_database_units_to_meters_factor();

    width = sb.height;
    seg = sb.segment;
    j = 0;
    lab = 0;

    margin = (int)(0.2 * (double)sb.fontsize + 0.5);
    if (margin < 2)
	margin = 2;
    fprintf(PS.fp, "/mg %d def\n", margin);
    x = sb.x - (length / 2.);
    set_font_size(sb.fontsize);
    set_line_width(sb.width);

    if (strcmp(sb.type, "f") == 0) {
	/* draw fancy scale bar */

	for (i = 0; i < seg; i++) {
	    /* draw a filled rectangle */
	    x1 = 72.0 * (x + (length / seg) * i) + 0.5;
	    y1 = 72.0 * (PS.page_height - sb.y);
	    x2 = 72.0 * (x + (length / seg) * (i + 1)) + 0.5;
	    y2 = (72.0 * (PS.page_height - sb.y)) + (width * 72.0);

	    /* Alternate black and white */
	    if (j == 0) {
		fprintf(PS.fp, "0.0 0.0 0.0 C\n");
		j = 1;
	    }
	    else {
		fprintf(PS.fp, "1.0 1.0 1.0 C\n");
		j = 0;
	    }
	    fprintf(PS.fp, "%.1f %.1f %.1f %.1f B\n", x1, y1, x2, y2);

	    /* set outline to black */
	    fprintf(PS.fp, "F 0.0 0.0 0.0 C\n");
	    fprintf(PS.fp, "D\n");

	    lab++;

	    /* do text */
	    if (i == 0 || lab == sb.numbers) {
		sprintf(num, "%s", nice_number((sb.length / sb.segment) * i));
		text_box_path(x1, y2 + margin, CENTER, LOWER, num,
			      sb.fontsize, 0);
		if (sb.bgcolor) {	/* TODO: take bg color, not just [white|none] */
		    set_rgb_color(WHITE);
		    fprintf(PS.fp, "F ");
		}
		set_rgb_color(BLACK);
		fprintf(PS.fp, "TIB\n");
		lab = 0;
	    }

	    if ((lab > 0 && i == seg - 1) ||
		(sb.numbers == 1 && i == seg - 1)) {
		/* special case for last label */
		sprintf(num, "%s", nice_number(sb.length));
		text_box_path(x2, y2 + margin, CENTER, LOWER, num,
			      sb.fontsize, 0);
		if (sb.bgcolor) {
		    set_rgb_color(WHITE);
		    fprintf(PS.fp, "F ");
		}
		set_rgb_color(BLACK);
		fprintf(PS.fp, "TIB\n");
	    }

	}

    }
    else {
	/* draw simple scalebar */

	x1 = 72.0 * x + 0.5;
	y1 = (72.0 * (PS.page_height - sb.y)) + (width * 72.0);
	x2 = 72.0 * x + 0.5;
	y2 = 72.0 * (PS.page_height - sb.y);

	fprintf(PS.fp, "%.1f %.1f %.1f %.1f L D\n", x1, y1, x2, y2);

	/* draw label */
	text_box_path(x1, y1 + margin, CENTER, LOWER, "0", sb.fontsize, 0);
	if (sb.bgcolor) {
	    set_rgb_color(WHITE);
	    fprintf(PS.fp, "F ");
	}
	set_rgb_color(BLACK);
	fprintf(PS.fp, "TIB\n");


	x1 = 72.0 * x + 0.5;
	y1 = 72.0 * (PS.page_height - sb.y);
	x2 = 72.0 * (x + length) + 0.5;
	y2 = 72.0 * (PS.page_height - sb.y);
	fprintf(PS.fp, "%.1f %.1f %.1f %.1f L D\n", x1, y1, x2, y2);

	x1 = 72.0 * (x + length) + 0.5;
	y2 = (72.0 * (PS.page_height - sb.y)) + (width * 72.0);
	x2 = 72.0 * (x + length) + 0.5;
	y1 = 72.0 * (PS.page_height - sb.y);
	fprintf(PS.fp, "%.1f %.1f %.1f %.1f L D\n", x1, y1, x2, y2);

	/* draw label */
	sprintf(num, "%s", nice_number(sb.length));
	text_box_path(x1, y2 + margin, CENTER, LOWER, num, sb.fontsize, 0);
	if (sb.bgcolor) {
	    set_rgb_color(WHITE);
	    fprintf(PS.fp, "F ");
	}
	set_rgb_color(BLACK);
	fprintf(PS.fp, "TIB\n");


	for (i = 1; i < seg; i++) {
	    x1 = 72.0 * (x + (length / seg) * i) + 0.5;
	    y1 = 72.0 * (PS.page_height - sb.y);
	    x2 = 72.0 * (x + (length / seg) * i) + 0.5;
	    y2 = (72.0 * (PS.page_height - sb.y)) + (width / 2. * 72.0);
	    y3 = (72.0 * (PS.page_height - sb.y)) + (width * 72.0);

	    fprintf(PS.fp, "%.1f %.1f %.1f %.1f L D\n", x1, y1, x2, y2);

	    lab++;

	    /* do text */
	    if (lab == sb.numbers) {
		sprintf(num, "%s", nice_number((sb.length / sb.segment) * i));

		text_box_path(x1, y3 + margin, CENTER, LOWER, num,
			      sb.fontsize, 0);
		if (sb.bgcolor) {
		    set_rgb_color(WHITE);
		    fprintf(PS.fp, "F ");
		}
		set_rgb_color(BLACK);
		fprintf(PS.fp, "TIB\n");
		lab = 0;
	    }

	}
    }


    /* draw units label */
    if (sb.units == SB_UNITS_AUTO)
	strcpy(num, G_database_unit_name(TRUE));
    else if(sb.units == SB_UNITS_METERS)
	strcpy(num, "meters");
    else if(sb.units == SB_UNITS_KM)
	strcpy(num, "kilometers");
    else if(sb.units == SB_UNITS_FEET)
	strcpy(num, "feet");
    else if(sb.units == SB_UNITS_MILES)
	strcpy(num, "miles");
    else if(sb.units == SB_UNITS_NMILES)
	strcpy(num, "nautical miles");
    
    text_box_path(72.0 * (x + length/2), 72.0 * (PS.page_height - (sb.y + 0.075)),
	CENTER, UPPER, num, sb.fontsize, 0);

    if (sb.bgcolor) {
	set_rgb_color(WHITE);
	fprintf(PS.fp, "F ");
    }
    set_rgb_color(BLACK);
    fprintf(PS.fp, "TIB\n");


    return 0;
}
Beispiel #26
0
int main (int argc, char ** argv) {
	init_shmemfonts();

	yutani_t * y = yutani_init();

	if (!y) {
		fprintf(stderr, "[glogin] Connection to server failed.\n");
		return 1;
	}

	/* Load config */
	{
		confreader_t * conf = confreader_load("/etc/glogin.conf");

		LOGO_FINAL_OFFSET = confreader_intd(conf, "style", "logo_padding", LOGO_FINAL_OFFSET);
		BOX_WIDTH = confreader_intd(conf, "style", "box_width", BOX_WIDTH);
		BOX_HEIGHT = confreader_intd(conf, "style", "box_height", BOX_HEIGHT);
		BOX_ROUNDNESS = confreader_intd(conf, "style", "box_roundness", BOX_ROUNDNESS);
		CENTER_BOX_X = confreader_intd(conf, "style", "center_box_x", CENTER_BOX_X);
		CENTER_BOX_Y = confreader_intd(conf, "style", "center_box_y", CENTER_BOX_Y);
		BOX_LEFT = confreader_intd(conf, "style", "box_left", BOX_LEFT);
		BOX_RIGHT = confreader_intd(conf, "style", "box_right", BOX_RIGHT);
		BOX_TOP = confreader_intd(conf, "style", "box_top", BOX_TOP);
		BOX_BOTTOM = confreader_intd(conf, "style", "box_bottom", BOX_BOTTOM);
		BOX_COLOR_R = confreader_intd(conf, "style", "box_color_r", BOX_COLOR_R);
		BOX_COLOR_G = confreader_intd(conf, "style", "box_color_g", BOX_COLOR_G);
		BOX_COLOR_B = confreader_intd(conf, "style", "box_color_b", BOX_COLOR_B);
		BOX_COLOR_A = confreader_intd(conf, "style", "box_color_a", BOX_COLOR_A);

		WALLPAPER = confreader_getd(conf, "image", "wallpaper", WALLPAPER);
		LOGO = confreader_getd(conf, "image", "logo", LOGO);

		confreader_free(conf);

		TRACE("Loading complete");
	}

	TRACE("Loading logo...");
	load_sprite_png(&logo, LOGO);
	TRACE("... done.");

	/* Generate surface for background */
	sprite_t * bg_sprite;

	int width  = y->display_width;
	int height = y->display_height;
	int skip_animation = 0;

	/* Do something with a window */
	TRACE("Connecting to window server...");
	yutani_window_t * wina = yutani_window_create(y, width, height);
	assert(wina);
	yutani_set_stack(y, wina, 0);
	ctx = init_graphics_yutani_double_buffer(wina);
	draw_fill(ctx, rgba(0,0,0,255));
	yutani_flip(y, wina);
	TRACE("... done.");


redo_everything:
	win_width = width;
	win_height = height;

	cairo_surface_t * cs = cairo_image_surface_create_for_data((void*)ctx->backbuffer, CAIRO_FORMAT_ARGB32, ctx->width, ctx->height, cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, ctx->width));
	cairo_t * cr = cairo_create(cs);


	TRACE("Loading wallpaper...");
	{
		sprite_t * wallpaper = malloc(sizeof(sprite_t));
		load_sprite_png(wallpaper, WALLPAPER);

		float x = (float)width  / (float)wallpaper->width;
		float y = (float)height / (float)wallpaper->height;

		int nh = (int)(x * (float)wallpaper->height);
		int nw = (int)(y * (float)wallpaper->width);;

		bg_sprite = create_sprite(width, height, ALPHA_OPAQUE);
		gfx_context_t * bg = init_graphics_sprite(bg_sprite);

		if (nw > width) {
			draw_sprite_scaled(bg, wallpaper, (width - nw) / 2, 0, nw, height);
		} else {
			draw_sprite_scaled(bg, wallpaper, 0, (height - nh) / 2, width, nh);
		}

		/* Three box blurs = good enough approximation of a guassian, but faster*/
		blur_context_box(bg, 20);
		blur_context_box(bg, 20);
		blur_context_box(bg, 20);

		free(bg);
		free(wallpaper);
	}
	TRACE("... done.");

	while (1) {

		yutani_set_stack(y, wina, 0);
		yutani_focus_window(y, wina->wid);

		draw_fill(ctx, rgb(0,0,0));
		draw_sprite(ctx, bg_sprite, center_x(width), center_y(height));
		flip(ctx);
		yutani_flip(y, wina);

		char * foo = malloc(sizeof(uint32_t) * width * height);
		memcpy(foo, ctx->backbuffer, sizeof(uint32_t) * width * height);

		TRACE("Begin animation.");
		if (!skip_animation) {
			struct timeval start;
			gettimeofday(&start, NULL);

			while (1) {
				uint32_t tick;
				struct timeval t;
				gettimeofday(&t, NULL);

				uint32_t sec_diff = t.tv_sec - start.tv_sec;
				uint32_t usec_diff = t.tv_usec - start.tv_usec;

				if (t.tv_usec < start.tv_usec) {
					sec_diff -= 1;
					usec_diff = (1000000 + t.tv_usec) - start.tv_usec;
				}

				tick = (uint32_t)(sec_diff * 1000 + usec_diff / 1000);
				int i = (float)LOGO_FINAL_OFFSET * (float)tick / 700.0f;
				if (i >= LOGO_FINAL_OFFSET) break;

				memcpy(ctx->backbuffer, foo, sizeof(uint32_t) * width * height);
				draw_sprite(ctx, &logo, center_x(logo.width), center_y(logo.height) - i);
				flip(ctx);
				yutani_flip_region(y, wina, center_x(logo.width), center_y(logo.height) - i, logo.width, logo.height + 5);
				usleep(10000);
			}
		}
		TRACE("End animation.");
		skip_animation = 0;

		size_t buf_size = wina->width * wina->height * sizeof(uint32_t);
		char * buf = malloc(buf_size);

		uint32_t i = 0;

		uint32_t black = rgb(0,0,0);
		uint32_t white = rgb(255,255,255);

		int x_offset = 65;
		int y_offset = 64;

		int fuzz = 3;

		char username[INPUT_SIZE] = {0};
		char password[INPUT_SIZE] = {0};
		char hostname[512];

		// we do it here to calculate the final string position
		get_updated_hostname_with_time_info(hostname);

		char kernel_v[512];

		{
			struct utsname u;
			uname(&u);
			/* UTF-8 Strings FTW! */
			uint8_t * os_name_ = "とあるOS";
			uint32_t l = snprintf(kernel_v, 512, "%s %s", os_name_, u.release);
		}

		uid = 0;

		int box_x, box_y;

		if (CENTER_BOX_X) {
			box_x = center_x(BOX_WIDTH);
		} else if (BOX_LEFT == -1) {
			box_x = win_width - BOX_RIGHT - BOX_WIDTH;
		} else {
			box_x = BOX_LEFT;
		}
		if (CENTER_BOX_Y) {
			box_y = center_y(0) + 8;
		} else if (BOX_TOP == -1) {
			box_y = win_width - BOX_BOTTOM - BOX_HEIGHT;
		} else {
			box_y = BOX_TOP;
		}

		int focus = 0;

		set_font_size(11);
		int hostname_label_left = width - 10 - draw_string_width(hostname);
		int kernel_v_label_left = 10;

		struct text_box username_box = { (BOX_WIDTH - 170) / 2, 30, 170, 20, rgb(0,0,0), NULL, 0, 0, 0, username, "Username" };
		struct text_box password_box = { (BOX_WIDTH - 170) / 2, 58, 170, 20, rgb(0,0,0), NULL, 0, 1, 0, password, "Password" };

		struct login_container lc = { box_x, box_y, BOX_WIDTH, BOX_HEIGHT, &username_box, &password_box, 0 };

		username_box.parent = &lc;
		password_box.parent = &lc;

		while (1) {
			focus = 0;
			memset(username, 0x0, INPUT_SIZE);
			memset(password, 0x0, INPUT_SIZE);

			while (1) {

				// update time info
				get_updated_hostname_with_time_info(hostname);

				memcpy(ctx->backbuffer, foo, sizeof(uint32_t) * width * height);
				draw_sprite(ctx, &logo, center_x(logo.width), center_y(logo.height) - LOGO_FINAL_OFFSET);

				set_font_size(11);
				draw_string_shadow(ctx, hostname_label_left, height - 12, white, hostname, rgb(0,0,0), 2, 1, 1, 3.0);
				draw_string_shadow(ctx, kernel_v_label_left, height - 12, white, kernel_v, rgb(0,0,0), 2, 1, 1, 3.0);

				if (focus == USERNAME_BOX) {
					username_box.is_focused = 1;
					password_box.is_focused = 0;
				} else if (focus == PASSWORD_BOX) {
					username_box.is_focused = 0;
					password_box.is_focused = 1;
				} else {
					username_box.is_focused = 0;
					password_box.is_focused = 0;
				}

				draw_login_container(cr, &lc);

				flip(ctx);
				yutani_flip(y, wina);

				struct yutani_msg_key_event kbd;
				struct yutani_msg_window_mouse_event mou;
				int msg_type = 0;
collect_events:
				do {
					yutani_msg_t * msg = yutani_poll(y);
					switch (msg->type) {
						case YUTANI_MSG_KEY_EVENT:
							{
								struct yutani_msg_key_event * ke = (void*)msg->data;
								if (ke->event.action == KEY_ACTION_DOWN) {
									memcpy(&kbd, ke, sizeof(struct yutani_msg_key_event));
									msg_type = 1;
								}
							}
							break;
						case YUTANI_MSG_WINDOW_MOUSE_EVENT:
							{
								struct yutani_msg_window_mouse_event * me = (void*)msg->data;
								memcpy(&mou, me, sizeof(struct yutani_msg_mouse_event));
								msg_type = 2;
							}
							break;
						case YUTANI_MSG_WELCOME:
							{
								struct yutani_msg_welcome * mw = (void*)msg->data;
								yutani_window_resize(y, wina, mw->display_width, mw->display_height);
							}
							break;
						case YUTANI_MSG_RESIZE_OFFER:
							{
								struct yutani_msg_window_resize * wr = (void*)msg->data;
								width = wr->width;
								height = wr->height;
								yutani_window_resize_accept(y, wina, width, height);
								reinit_graphics_yutani(ctx, wina);
								yutani_window_resize_done(y, wina);

								sprite_free(bg_sprite);
								cairo_destroy(cr);
								cairo_surface_destroy(cs);

								skip_animation = 1;
								goto redo_everything;
							}
							break;
					}
					free(msg);
				} while (!msg_type);

				if (msg_type == 1) {

					if (kbd.event.keycode == '\n') {
						if (focus == USERNAME_BOX) {
							focus = PASSWORD_BOX;
							continue;
						} else if (focus == PASSWORD_BOX) {
							break;
						} else {
							focus = USERNAME_BOX;
							continue;
						}
					}

					if (kbd.event.keycode == '\t') {
						if (focus == USERNAME_BOX) {
							focus = PASSWORD_BOX;
						} else {
							focus = USERNAME_BOX;
						}
						continue;
					}

					if (kbd.event.key) {

						if (!focus) {
							focus = USERNAME_BOX;
						}

						if (focus == USERNAME_BOX) {
							buffer_put(username, kbd.event.key);
						} else if (focus == PASSWORD_BOX) {
							buffer_put(password, kbd.event.key);
						}

					}

				} else if (msg_type == 2) {

					if ((mou.command == YUTANI_MOUSE_EVENT_DOWN
					     && mou.buttons & YUTANI_MOUSE_BUTTON_LEFT)
					    || (mou.command == YUTANI_MOUSE_EVENT_CLICK)) {
						/* Determine if we were inside of a text box */

						if (mou.new_x >= lc.x + username_box.x &&
						    mou.new_x <= lc.x + username_box.x + username_box.width &&
						    mou.new_y >= lc.y + username_box.y &&
						    mou.new_y <= lc.y + username_box.y + username_box.height) {
							/* Ensure this box is focused. */
							focus = USERNAME_BOX;
							continue;
						} else if (mou.new_x >= lc.x + password_box.x &&
						    mou.new_x <= lc.x + password_box.x + password_box.width &&
						    mou.new_y >= lc.y + password_box.y &&
						    mou.new_y <= lc.y + password_box.y + password_box.height) {
							/* Ensure this box is focused. */
							focus = PASSWORD_BOX;
							continue;
						} else {
							focus = 0;
							continue;
						}

					} else {
						goto collect_events;
					}
				}

			}

			uid = toaru_auth_check_pass(username, password);

			if (uid >= 0) {
				break;
			}
			lc.show_error = 1;
		}

		memcpy(ctx->backbuffer, foo, sizeof(uint32_t) * width * height);
		flip(ctx);
		yutani_flip(y, wina);
		syscall_yield();

		pid_t _session_pid = fork();
		if (!_session_pid) {
			setuid(uid);
			toaru_auth_set_vars();
			char * args[] = {"/bin/gsession", NULL};
			execvp(args[0], args);
		}

		free(foo);
		free(buf);

		waitpid(_session_pid, NULL, 0);
	}

	yutani_close(y, wina);


	return 0;
}
int load_config(const char *path, hash_map < string, module_info * >*modules, list < module_info * >*clients) {
    char module[1024] = { 0, };
    char line[1024] = { 0, };
    char indicator = '=';
    module_info *cur_mod = NULL;

    FILE *file = fopen(path, "r");

    if(file == NULL) {
        ALOGE("%s open failed\n", path);
        return CONFIG_NOT_FOUND_ERR;
    }

    modules->clear();
    clients->clear();

    ALOGD("Loading config: %s\n", path);

    while(fgets(line, sizeof(line), file) != NULL) {
        char name[1024] = { 0, }, value[1024] = {
        0,};

        if(line[0] == '#')
            continue;

        if(line[0] == '[') {
            parse_module(line, module, sizeof(module));
            cur_mod = new module_info(module);
            // add module into global list
            (*modules)[(string) module] = cur_mod;
            clients->push_back(cur_mod);
            ALOGD("[%s]\n", module);
            continue;
        }

        if(module[0] != '\0') {
            parse_value(line, indicator, name, sizeof(name), value, sizeof(value));
            char *pname = trim(name);
            char *pvalue = trim(value);

            if(*pname != '\0' && *pvalue != '\0') {

                /*Initial language */
                if(!strcmp(pname, KEY_STR_LANGUAGE)) {
                    load_lang(pvalue);
                }

                /*initial font size */
                if(!strcmp(pname, KEY_FONTSIZE)) {
                    set_font_size(pvalue);
                }

                cur_mod->config_list[(string) pname] = (string) pvalue;
                ALOGI("[%s] %s:%s \n", module, pname, pvalue);
            }
        }
    }

    fclose(file);
    return CONFIG_SUCCESS;
}
Beispiel #28
0
int do_grid_numbers(void)
{
    double g;
    char num_text[50];
    int grid, vy, vx, hy = 0, hx = 0;
    int first, len, x, y, last_bottom, last_right;
    int rounded_grid, margin;

    if (PS.grid <= 0 || PS.grid_numbers <= 0)
	return 1;
    grid = PS.grid * PS.grid_numbers;

    /* round grid to multiple of 10 */
    rounded_grid = 1;
    if (PS.w.proj != PROJECTION_LL) {
	sprintf(num_text, "%d", PS.grid);
	len = strlen(num_text);
	while (len-- && num_text[len] == '0')
	    rounded_grid *= 10;
	if (rounded_grid == 10)
	    rounded_grid = 1;
    }

    /* initialize */
    set_font_name(PS.grid_font);
    set_font_size(PS.grid_fontsize);
    set_ps_color(&PS.grid_numbers_color);
    first = 1;

    /* horizontal grid numbers
     * these numbers only appear on the left edge of the first panel.
     * center the numbers on each grid line.
     * suppress number if it falls off the map or would overlay the previous
     *  label
     */
    margin = (int)(0.2 * (double)PS.grid_fontsize + 0.5);
    if (margin < 2)
	margin = 2;
    fprintf(PS.fp, "/mg %d def\n", margin);
    g = floor(PS.w.north / grid) * grid;
    last_bottom = (int)PS.map_top;
    first = 1;
    /* x = XCONV(PS.w.west); */

    for (; g > PS.w.south; g -= grid) {
	/*y = YCONV(g); */

	G_plot_where_xy(PS.w.west, g, &vx, &vy);
	x = (double)vx / 10.;
	y = (double)vy / 10.;

	if (y + PS.grid_fontsize > last_bottom)
	    continue;
	if (y - PS.grid_fontsize < (int)PS.map_bot)
	    continue;
	sprintf(num_text, "%s", format_northing(g, rounded_grid));
	text_box_path(x, y, LEFT, CENTER, num_text, PS.grid_fontsize, 0);
	set_rgb_color(WHITE);
	fprintf(PS.fp, "F ");
	set_ps_color(&PS.grid_numbers_color);
	fprintf(PS.fp, "TIB\n");
	last_bottom = y - PS.grid_fontsize;
	if (first) {
	    first = 0;
	    hy = y + (int)(0.5 * (double)PS.grid_fontsize + 0.5) + margin;
	    hx = x + 0.7 * strlen(num_text) * PS.grid_fontsize + 2 * margin;
	}
    }

    /* vertical grid numbers 
     * center the numbers on each grid line.
     * suppress number if it falls of the map or would overlay the previous
     *  label
     */
    g = floor(PS.w.west / grid) * grid;
    last_right = (int)PS.map_left;
    /* y = YCONV(PS.w.north); */
    for (; g < PS.w.east; g += grid) {
	/* x = XCONV(g); */

	G_plot_where_xy(g, PS.w.north, &vx, &vy);
	x = (double)vx / 10.;
	y = (double)vy / 10.;

	if (x - PS.grid_fontsize < last_right)
	    continue;
	if (x + PS.grid_fontsize > (int)PS.map_right)
	    continue;
	sprintf(num_text, "%s", format_easting(g, rounded_grid));
	vy = y - 0.7 * strlen(num_text) * PS.grid_fontsize - 2 * margin;
	vx = x - (int)(0.5 * (double)PS.grid_fontsize + 0.5) - margin;
	if (vx < hx && vy < hy)
	    continue;
	fprintf(PS.fp, "ZB (%s) PB 90 rotate\n", num_text);
	fprintf(PS.fp, "%d br sub bl add mg add\n", y);
	fprintf(PS.fp, "%d bt bb sub D2 add mg sub neg TR TB\n", x);
	set_rgb_color(WHITE);
	fprintf(PS.fp, "F ");
	set_ps_color(&PS.grid_numbers_color);
	fprintf(PS.fp, "TIB\n");
	last_right = x + PS.grid_fontsize;
    }

    return 0;
}
Beispiel #29
0
void load_dataset2(string &ds_name, string &data_fname, string &labels_fname) {
  // file names
  string	classes_fname;
  string	scales_fname;
  string	classpairs_fname;
  string	deformpairs_fname;
  // // boolean successes of files loading
  // bool		bdefpairs   = true;
  // bool		bclasspairs = true;
  // data files
  idx<Tdata>	data;
  midx<Tdata>   datas;
  idx<Tlabel>	labels;
  idx<ubyte>	classes;
  idx<intg>	scales;
  idx<intg>	classpairs;
  idx<intg>	defpairs;

  // build file names
  build_fname(ds_name, CLASSES_NAME, classes_fname);
  build_fname(ds_name, SCALES_NAME, scales_fname);
  build_fname(ds_name, CLASSPAIRS_NAME, classpairs_fname);
  build_fname(ds_name, DEFORMPAIRS_NAME, deformpairs_fname);

  // // check format of data file
  // bool multimat = has_multiple_matrices(data_fname.c_str());

  // // if size is defined, only load data and print dimensions
  // if (size) {
  //   if (multimat) {
  //     datas = load_matrices<Tdata>(data_fname);
  //     cout << datas.dim(0) << endl;
  //   } else {
  //     data = load_matrix<Tdata>(data_fname);
  //     cout << data.dim(0) << endl;
  //   }
  //   return ;
  // }
  // // load data
  // if (multimat)
  //   datas = load_matrices<Tdata>(data_fname);
  // else
  //   data = load_matrix<Tdata>(data_fname);
  // loading_error(labels, labels_fname);
  // loading_warning(classes, classes_fname);
  // loading_warning(scales, scales_fname);
  // bclasspairs = loading_nowarning(classpairs, classpairs_fname);
  // bdefpairs = loading_nowarning(defpairs, deformpairs_fname);

  // // display only 1 channel
  // if (channel >= 0) {
  //   if (multimat)
  //     eblerror("showing only 1 channel is not supported with "
  // 	       << "multimats yet (TODO)");
  //   if (channel >= data.dim(1)) {
  //     cerr << "trying to select channel " << channel
  // 	   << " but channel dimension is of size " << data.dim(0)
  // 	   << " (in " << data << ")." << endl;
  //     eblerror("trying to select unknown channel dimension");
  //   }
  //   data = data.select(1, channel);
  // }

  class_datasource<Tdata, Tdata, Tlabel> *train_ds =
      new class_datasource<Tdata,Tdata,Tlabel>
      (data_fname.c_str(), labels_fname.c_str(), NULL,
       scales_fname.c_str(), classes_fname.c_str(), "Dataset");


  // // create datasource object
  // class_datasource<Tdata, Tdata, Tlabel> *train_ds = NULL;
  // if (multimat)
  //   train_ds = new class_datasource<Tdata, Tdata, Tlabel>(datas, labels, classes, "Dataset");
  // else
  //   train_ds = new class_datasource<Tdata, Tdata, Tlabel>(data, labels, classes, "Dataset");


  // display it
#ifdef __GUI__
  if (!info) { // only display if info is false
    // if (bclasspairs) {
    //   labeled_pair_datasource<Tdata, Tdata, Tlabel>
    // 	train_cp_ds(data, labels, classes, classpairs,
    // 		    "Class pairs (training)");
    //   labeled_pair_datasource_gui<Tdata, Tdata, Tlabel> dsgui_cp(true);
    //   dsgui_cp.display(train_cp_ds, dims.dim(0), dims.dim(1),
    // 		       0, 0, 1, -1, NULL, false,
    // 		       (Tdata) range[0], (Tdata) range[1]);
    //   secsleep(1);
    // }

    // if (bdefpairs) {
    //   labeled_pair_datasource<Tdata, Tdata, Tlabel>
    // 	train_dp_ds(data, labels, classes, defpairs,
    // 		    "Deformation pairs (training)");
    //   labeled_pair_datasource_gui<Tdata, Tdata, Tlabel> dsgui_dp(true);
    //   dsgui_dp.display(train_dp_ds, dims.dim(0), dims.dim(1),
    // 		       0, 0, 1, -1, NULL, false,
    // 		       (Tdata) range[0], (Tdata) range[1]);
    //   secsleep(1);
    // }

    labeled_datasource_gui<Tdata, Tdata, Tlabel> dsgui(true);
    dsgui.display(*train_ds, dims.dim(0), dims.dim(1), 0, 0, 1, -1, NULL, false,
		  (Tdata) range[0], (Tdata) range[1]);
    if (font_size > 0)
      set_font_size(font_size);
    secsleep(1);
  }
  delete train_ds;
#else
  cerr << "warning: QT gui libraries not available, install them and recompile"
       << endl;
#endif
}
Beispiel #30
0
/**
 * Compute the absolute values of a style
 *
 * \param parent             Parent style, or NULL for tree root
 * \param style              Computed style to process
 * \param compute_font_size  Callback to calculate an absolute font-size
 * \param pw                 Private word for callback
 * \return CSS_OK on success.
 */
css_error compute_absolute_values(const css_computed_style *parent,
		css_computed_style *style,
		css_error (*compute_font_size)(void *pw, 
			const css_hint *parent, css_hint *size),
		void *pw)
{
	css_hint psize, size, ex_size;
	css_error error;

	/* Ensure font-size is absolute */
	if (parent != NULL) {
		psize.status = get_font_size(parent, 
				&psize.data.length.value, 
				&psize.data.length.unit);
	}

	size.status = get_font_size(style, 
			&size.data.length.value, 
			&size.data.length.unit);

	error = compute_font_size(pw, parent != NULL ? &psize : NULL, &size);
	if (error != CSS_OK)
		return error;

	error = set_font_size(style, size.status,
			size.data.length.value, 
			size.data.length.unit);
	if (error != CSS_OK)
		return error;

	/* Compute the size of an ex unit */
	ex_size.status = CSS_FONT_SIZE_DIMENSION;
	ex_size.data.length.value = INTTOFIX(1);
	ex_size.data.length.unit = CSS_UNIT_EX;
	error = compute_font_size(pw, &size, &ex_size);
	if (error != CSS_OK)
		return error;

	/* Convert ex size into ems */
	if (size.data.length.value != 0)
		ex_size.data.length.value = FDIV(ex_size.data.length.value, 
					size.data.length.value);
	else
		ex_size.data.length.value = 0;
	ex_size.data.length.unit = CSS_UNIT_EM;

	/* Fix up background-position */
	error = compute_absolute_length_pair(style, &ex_size.data.length, 
			get_background_position,
			set_background_position);
	if (error != CSS_OK)
		return error;

	/* Fix up border-{top,right,bottom,left}-color */
	error = compute_border_colors(style);
	if (error != CSS_OK)
		return error;

	/* Fix up border-{top,right,bottom,left}-width */
	error = compute_absolute_border_width(style, &ex_size.data.length);
	if (error != CSS_OK)
		return error;

	/* Fix up sides */
	error = compute_absolute_sides(style, &ex_size.data.length);
	if (error != CSS_OK)
		return error;

	/* Fix up height */
	error = compute_absolute_length_auto(style, &ex_size.data.length, 
			get_height, set_height);
	if (error != CSS_OK)
		return error;

	/* Fix up line-height (must be before vertical-align) */
	error = compute_absolute_line_height(style, &ex_size.data.length);
	if (error != CSS_OK)
		return error;

	/* Fix up margins */
	error = compute_absolute_margins(style, &ex_size.data.length);
	if (error != CSS_OK)
		return error;

	/* Fix up max-height */
	error = compute_absolute_length_none(style, &ex_size.data.length, 
			get_max_height, set_max_height);
	if (error != CSS_OK)
		return error;

	/* Fix up max-width */
	error = compute_absolute_length_none(style, &ex_size.data.length, 
			get_max_width, set_max_width);
	if (error != CSS_OK)
		return error;

	/* Fix up min-height */
	error = compute_absolute_length(style, &ex_size.data.length, 
			get_min_height, set_min_height);
	if (error != CSS_OK)
		return error;

	/* Fix up min-width */
	error = compute_absolute_length(style, &ex_size.data.length, 
			get_min_width, set_min_width);
	if (error != CSS_OK)
		return error;

	/* Fix up padding */
	error = compute_absolute_padding(style, &ex_size.data.length);
	if (error != CSS_OK)
		return error;

	/* Fix up text-indent */
	error = compute_absolute_length(style, &ex_size.data.length, 
			get_text_indent, set_text_indent);
	if (error != CSS_OK)
		return error;

	/* Fix up vertical-align */
	error = compute_absolute_vertical_align(style, &ex_size.data.length);
	if (error != CSS_OK)
		return error;

	/* Fix up width */
	error = compute_absolute_length_auto(style, &ex_size.data.length, 
			get_width, set_width);
	if (error != CSS_OK)
		return error;

	/* Uncommon properties */
	if (style->uncommon != NULL) {
		/* Fix up border-spacing */
		error = compute_absolute_length_pair(style,
				&ex_size.data.length,
				get_border_spacing,
				set_border_spacing);
		if (error != CSS_OK)
			return error;

		/* Fix up clip */
		error = compute_absolute_clip(style, &ex_size.data.length);
		if (error != CSS_OK)
			return error;

		/* Fix up letter-spacing */
		error = compute_absolute_length_normal(style,
				&ex_size.data.length,
				get_letter_spacing, 
				set_letter_spacing);
		if (error != CSS_OK)
			return error;

		/* Fix up outline-width */
		error = compute_absolute_border_side_width(style, 
				&ex_size.data.length, 
				get_outline_width, 
				set_outline_width);
		if (error != CSS_OK)
			return error;

		/* Fix up word spacing */
		error = compute_absolute_length_normal(style,
				&ex_size.data.length,
				get_word_spacing, 
				set_word_spacing);
		if (error != CSS_OK)
			return error;
	}

	return CSS_OK;
}