Пример #1
0
int initialize_menu_renderer(struct menu_renderer *self,
			     struct renderer *renderer,
			     const struct b6_clock *clock,
			     const char *skin_id)
{
	static const struct renderer_observer_ops h_renderer_observer_ops = {
		.on_render = menu_renderer_image_on_render_h,
	};
	static const struct renderer_observer_ops v_renderer_observer_ops = {
		.on_render = menu_renderer_image_on_render_v,
	};
	static const struct renderer_observer_ops renderer_observer_ops = {
		.on_render = menu_renderer_on_render,
	};
	struct renderer_base *root;
	self->renderer = renderer;
	self->clock = clock;
	self->menu = NULL;
	root = get_renderer_base(renderer);
	if (make_font(&self->normal_font, skin_id, MENU_NORMAL_FONT_DATA_ID))
		return -1;
	make_font(&self->bright_font, skin_id, MENU_BRIGHT_FONT_DATA_ID);
	if ((self->background = create_renderer_tile(renderer, root, 0, 0,
						     640, 480, NULL)))
		set_renderer_tile_texture(self->background, make_texture(
			renderer, skin_id, MENU_BACKGROUND_DATA_ID));
	initialize_menu_renderer_image(&self->title, renderer, self->clock,
				       70, -118, 500, 150, 32, 3e-4,
				       skin_id, MENU_TITLE_DATA_ID,
				       &v_renderer_observer_ops);
	initialize_menu_renderer_image(&self->pacman, renderer, self->clock,
				       640, 328, 96, 96, 440, 4e-4,
				       skin_id, MENU_PACMAN_DATA_ID,
				       &h_renderer_observer_ops);
	initialize_menu_renderer_image(&self->ghost, renderer, self->clock,
				       -100, 304, 100, 124, 100, 4e-4,
				       skin_id, MENU_GHOST_DATA_ID,
				       &h_renderer_observer_ops);
	add_renderer_observer(self->renderer, setup_renderer_observer(
			&self->renderer_observer,
			"menu_renderer",
			&renderer_observer_ops));
	return 0;
}
Пример #2
0
/* <font> <matrix> makefont <new_font> */
static int
zmakefont(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    int code;
    gs_matrix mat;

    if ((code = read_matrix(imemory, op, &mat)) < 0)
        return code;
    return make_font(i_ctx_p, &mat);
}
Пример #3
0
/* <font> <scale> scalefont <new_font> */
static int
zscalefont(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    int code;
    double scale;
    gs_matrix mat;

    if ((code = real_param(op, &scale)) < 0)
        return code;
    if ((code = gs_make_scaling(scale, scale, &mat)) < 0)
        return code;
    return make_font(i_ctx_p, &mat);
}
Пример #4
0
	::std::shared_ptr<platform_abstraction::font> platform_abstraction::default_font(const ::std::shared_ptr<font>& new_font)
	{
		auto & r = platform_storage();
		if (new_font)
		{
			auto f = r.font;
			if (new_font != r.font)
				r.font = new_font;

			return f;
		}

		if (!r.font)
			r.font = make_font({}, 0, {});

		return r.font;
	}
Пример #5
0
// Create a separate tty window; return its name in TTYNAME, its
// process id in PID, its terminal type in TERM, and its window id in
// WINDOWID.
static void launch_separate_tty(string& ttyname, pid_t& pid, string& term,
				Window& windowid, Widget origin)
{
    // If we're already running, all is done.
    if (pid > 0 && (remote_gdb() || kill(pid, 0) == 0))
	return;

    string term_command = app_data.term_command;
    term_command.gsub("@FONT@", make_font(app_data, FixedWidthDDDFont));

    static bool canceled;
    canceled = false;

    static Widget dialog = 0;
    if (dialog == 0)
    {
	Arg args[10];
	Cardinal arg = 0;
	XtSetArg(args[arg], XmNdialogStyle, 
		 XmDIALOG_FULL_APPLICATION_MODAL); arg++;
	dialog = verify(XmCreateWorkingDialog(find_shell(origin), 
					      XMST("launch_tty_dialog"), 
					      args, arg));
	XtUnmanageChild(XmMessageBoxGetChild(dialog, 
					     XmDIALOG_OK_BUTTON));
	XtUnmanageChild(XmMessageBoxGetChild(dialog, 
					     XmDIALOG_HELP_BUTTON));
	XtAddCallback(dialog, XmNcancelCallback, CancelTTYCB,
		      XtPointer(&canceled));
    }

    string base = term_command;
    if (base.contains(' '))
	base = base.before(' ');
    MString msg = rm("Starting ") + tt(base) + rm("...");
    XtVaSetValues(dialog, XmNmessageString, msg.xmstring(), XtPointer(0));
    manage_and_raise(dialog);
    wait_until_mapped(dialog);

    StatusDelay delay("Starting execution window");

    // Fill in defaults
    ttyname = "";
    pid     = -1;

    string command = 
	
	// Set up a temporary file in TMP.
	"tmp=${TMPDIR-/tmp}/ddd$$; export tmp; "

	// Be sure to remove it when exiting...
	"trap \"rm -f $tmp\" 0; "

	// ... or being interrupted.
	"trap 'exit 1' 1 2 15; "

	// Now execute the xterm command
	+ term_command +

	// which saves TTY, PID, TERM, and WINDOWID in TMP and goes to
	// sleep forever.  Signal 2 (SIGINT) is blocked for two
	// reasons: first, we don't want ^C to kill the tty window;
	// second, later invocations will send us SIGINT to find out
	// whether we're still alive.
	" '"
	"echo `tty` $$ $TERM $WINDOWID >$tmp; "
	"trap \"\" 2; "
	"while true; do sleep 3600; done"
	"' "

	// The whole thing is redirected and in the background such
	// that rsh won't wait for us.
	">/dev/null </dev/null 2>&1 & "

	// The main file waits for TMP to be created...
	"while test ! -s $tmp; do sleep 1; done; "

	// ...and sends TMP's contents to stdout, where DDD is waiting.
	"cat $tmp";

    if (pid > 0 && remote_gdb())
    {
	// We're already running.  Don't start a new tty
	// if the old one is still running.
	std::ostringstream os;
	os << "kill -2 " << pid << " 2>/dev/null"
	   << " || ( " << command << " )";
	command = string(os);
    }

    command = sh_command(command);

    {
	XtAppContext app_context = XtWidgetToApplicationContext(dialog);
	LiterateAgent tty(app_context, command);

	string reply = "";
	tty.addHandler(Input, GotReplyHP, (void *)&reply);
	tty.start();

	while (!reply.contains('\n') && !canceled && tty.running())
	    XtAppProcessEvent(app_context, XtIMAll);

	if (reply.length() > 2)
	{
	    std::istringstream is(reply.chars());
	    is >> ttyname >> pid >> term >> windowid;
	}

	tty.terminate();
    }
Пример #6
0
static int hall_of_fame_phase_init(struct phase *up, const struct phase *prev)
{
	static const struct controller_observer_ops controller_observer_ops = {
		.on_key_pressed = on_key_pressed,
		.on_text_input = on_text_input,
	};
	static const struct renderer_observer_ops renderer_observer_ops = {
		.on_render = on_render,
	};
	struct hall_of_fame_phase *self =
		b6_cast_of(up, struct hall_of_fame_phase, up);
	struct renderer *renderer = get_engine_renderer(up->engine);
	struct renderer_base *root;
	unsigned short int font_w, font_h;
	struct hall_of_fame_iterator iter;
	struct data_entry *entry;
	struct istream *is;
	const char *skin_id = hof_skin ? hof_skin : get_skin_id();
	int i;
	self->array = open_hall_of_fame(&up->engine->hall_of_fame,
					up->engine->layout_provider->id,
					up->engine->game_config->entry.id);
	if (!self->array)
		return -1;
	if (b6_utf8_is_empty(&self->name.utf8)) {
		struct b6_utf8 utf8;
		if (user || (user = get_user_name()))
			b6_utf8_from_ascii(&utf8, user);
		else
			b6_clone_utf8(&utf8, B6_UTF8("PLAYER"));
		b6_clear_utf8_string(&self->name);
		b6_extend_utf8_string(&self->name, &utf8);
	}
	self->entry = NULL;
	self->quit = 0;
	if (prev == lookup_phase(B6_UTF8("game"))) {
		struct game_result game_result;
		get_last_game_result(up->engine, &game_result);
		self->entry = amend_hall_of_fame(self->array,
						 game_result.level + 1,
						 game_result.score);
		if (!self->entry)
			self->quit = 1;
		else
			alter_hall_of_fame_entry(self->entry, &self->name.utf8);
	}
	root = get_renderer_base(renderer);
	if (make_font(&self->font, skin_id, HOF_FONT_DATA_ID))
		return -1;
	font_w = get_fixed_font_width(&self->font);
	font_h = get_fixed_font_height(&self->font);

	if ((self->background = create_renderer_tile(renderer, root, 0, 0,
						     640, 480, NULL)))
		set_renderer_tile_texture(self->background, make_texture(
				renderer, skin_id, HOF_BACKGROUND_DATA_ID));
	if ((self->panel = create_renderer_tile(renderer, root, 0, 0, 112, 480,
						NULL)))
		set_renderer_tile_texture(self->panel, make_texture(
				renderer, skin_id, HOF_PANEL_DATA_ID));
	for (i = 0; i < b6_card_of(self->label); i += 1) {
		const unsigned short int u = 2 + 32 * font_w, v = 2 + font_h;
		const float x = 96, y = 50 + i * 40;
		const float w = 2 + 32 * 16, h = 2 + 16;
		initialize_toolkit_label(&self->label[i], renderer,
					 &self->font, u, v, root, x, y, w, h);
		enable_toolkit_label_shadow(&self->label[i]);
	}
	reset_hall_of_fame_iterator(&iter, self->array);
	for (i = 0; i < b6_card_of(self->label); i += 1) {
		struct b6_json_object *entry;
		if (!hall_of_fame_iterator_has_next(&iter))
			break;
		entry = hall_of_fame_iterator_get_next(&iter);
		if (entry == self->entry)
			self->rank = i;
		setup_label(self, i, entry);
	}
	for (; i < b6_card_of(self->label); i += 1)
		hide_toolkit_label(&self->label[i]);
	if (self->entry) {
		float x = self->label[self->rank].image[0].tile->x +
			(16 + self->name.utf8.nchars) * 16;
		float y = self->label[self->rank].image[0].tile->y;
		self->cursor_base = create_renderer_base_or_die(renderer, root,
								"cursor", x, y);
		initialize_toolkit_label(&self->cursor_label, renderer,
					 &self->font, 16, 16,
					 self->cursor_base, 1, 1, 16, 16);
		enable_toolkit_label_shadow(&self->cursor_label);
		set_toolkit_label(&self->cursor_label, &b6_utf8_char['#']);
	} else
		self->cursor_base = NULL;
	add_renderer_observer(renderer, setup_renderer_observer(
			&self->renderer_observer, "hof",
			&renderer_observer_ops));
	add_controller_observer(get_engine_controller(up->engine),
				setup_controller_observer(
					&self->controller_observer,
					&controller_observer_ops));
	self->music = 0;
	initialize_fade_io(&self->fade_io, "hof_fade_io", renderer,
			   up->engine->clock, 0., 1., 5e-6);
	if (self->quit) {
		set_fade_io_target(&self->fade_io, 0.);
		return 0;
	}
	if ((entry = lookup_data(skin_id, audio_data_type,
				 HOF_MUSIC_DATA_ID)) &&
	    (is = get_data(entry))) {
		int retval = up->engine->mixer->ops->load_music_from_stream(
			up->engine->mixer, is);
		if (!retval) {
			play_music(up->engine->mixer);
			self->music = 1;
		} else
			log_w(_s("could not load background music"));
		put_data(entry, is);
	} else
		log_w(_s("cannot find background music"));
	return 0;
}
Пример #7
0
// Create a new plot window
PlotAgent *new_plotter(const string& name, DispValue *source)
{
    static int tics = 1;

    string cmd = app_data.plot_command;
    cmd.gsub("@FONT@", make_font(app_data, FixedWidthDDDFont));

    string window_name = ddd_NAME "plot" + itostring(tics++);
    if (cmd.contains("@NAME@"))
	cmd.gsub("@NAME@", window_name);
    else
	cmd += " -name " + window_name;

    // Create shell
    PlotWindowInfo *plot = new_decoration(name);
    if (plot == 0)
	return 0;

    plot->source      = source;
    plot->window_name = window_name;
    XtVaSetValues(plot->shell, XmNuserData, XtPointer(True), XtPointer(0));

    // Pop up a working dialog
    static Widget dialog = 0;
    if (dialog == 0)
    {
	Arg args[10];
	Cardinal arg = 0;
	dialog = verify(XmCreateWorkingDialog(find_shell(),
					      XMST("launch_plot_dialog"), 
					      args, arg));
	XtUnmanageChild(XmMessageBoxGetChild(dialog,
					     XmDIALOG_OK_BUTTON));
	XtUnmanageChild(XmMessageBoxGetChild(dialog,
					     XmDIALOG_HELP_BUTTON));
    }

    XtRemoveAllCallbacks(dialog, XmNcancelCallback);
    XtAddCallback(dialog, XmNcancelCallback, CancelPlotCB, XtPointer(plot));
    plot->working_dialog = dialog;

    string base = cmd;
    if (base.contains(' '))
	base = cmd.before(' ');
    MString msg = rm("Starting ") + tt(base) + rm("...");
    XtVaSetValues(dialog, XmNmessageString, msg.xmstring(), XtPointer(0));
    manage_and_raise(dialog);
    wait_until_mapped(dialog);

    // Invoke plot process
    PlotAgent *plotter = 
	new PlotAgent(XtWidgetToApplicationContext(plot->shell), cmd);

    XtAddCallback(plot->shell, XtNpopdownCallback,
		  CancelPlotCB, XtPointer(plot));

    if (plot->area != 0)
    {
	XtAddCallback(plot->area->widget(), XmNexposeCallback,
		      ExposePlotAreaCB, XtPointer(plot));
	XtAddCallback(plot->area->widget(), XmNresizeCallback,
		      ResizePlotAreaCB, XtPointer(plot));
    }

    string init = app_data.plot_init_commands;
    init.prepend("set term " + string(app_data.plot_term_type) + "\n");
    if (!init.empty() && !init.contains('\n', -1))
	init += '\n';

    // Add trace handlers
    plotter->addHandler(Input,  TraceInputHP);     // Gnuplot => DDD
    plotter->addHandler(Output, TraceOutputHP);    // DDD => Gnuplot
    plotter->addHandler(Error,  TraceErrorHP);     // Gnuplot Errors => DDD

    // Show Gnuplot Errors in status line
    plotter->addHandler(Error,  SetStatusHP,       (void *)plot);

    // Handle death
    plotter->addHandler(Died, PlotterNotFoundHP, (void *)plot);
    plotter->addHandler(Died, DeletePlotterHP,   (void *)plot);

    if (plot->area != 0)
	plotter->addHandler(Plot, GetPlotHP, (void *)plot);

    plotter->start_with(init);
    plot->plotter = plotter;

    return plotter;
}
Пример #8
0
static PlotWindowInfo *new_decoration(const string& name)
{
    PlotWindowInfo *plot = 0;

    // Check whether we can reuse an existing decoration
    for (int i = 0; i < plot_infos.size(); i++)
    {
	PlotWindowInfo *info = (PlotWindowInfo *)plot_infos[i];
	if (info->plotter == 0)
	{
	    // Shell is unused - use this one
	    plot = info;
	    break;
	}
    }

    if (plot == 0)
    {
	plot = new PlotWindowInfo;

	// Create decoration windows
	Arg args[10];
	Cardinal arg = 0;
	XtSetArg(args[arg], XmNallowShellResize, True);       arg++;
	XtSetArg(args[arg], XmNdeleteResponse, XmDO_NOTHING); arg++;

	// Mark shell as `used'
	XtSetArg(args[arg], XmNuserData, XtPointer(True)); arg++;
	plot->shell = verify(XtCreateWidget("plot", topLevelShellWidgetClass,
					    find_shell(), args, arg));

	AddDeleteWindowCallback(plot->shell, CancelPlotCB, XtPointer(plot));

	arg = 0;
	Widget main_window = XmCreateMainWindow(plot->shell, 
						XMST("main_window"), 
						args, arg);
	XtManageChild(main_window);

	MMcreateMenuBar(main_window, "menubar", menubar);
	MMaddCallbacks(file_menu,    XtPointer(plot));
	MMaddCallbacks(simple_edit_menu);
	MMaddCallbacks(view_menu,    XtPointer(plot));
	MMaddCallbacks(plot_menu,    XtPointer(plot));
	MMaddCallbacks(scale_menu,   XtPointer(plot));
	MMaddCallbacks(contour_menu, XtPointer(plot));
	MMaddCallbacks(simple_help_menu);
	MMaddHelpCallback(menubar, ImmediateHelpCB);

	arg = 0;
	XtSetArg(args[arg], XmNscrollingPolicy, XmAPPLICATION_DEFINED); arg++;
	XtSetArg(args[arg], XmNvisualPolicy,    XmVARIABLE);            arg++;
	Widget scroll = 
	    XmCreateScrolledWindow(main_window, XMST("scroll"), args, arg);
	XtManageChild(scroll);

	// Create work window
	Widget work;
	string plot_term_type = downcase(app_data.plot_term_type);
	if (plot_term_type.contains("xlib", 0))
	{
	    // xlib type - create plot area to draw plot commands
	    arg = 0;
	    work = XmCreateDrawingArea(scroll, 
				       XMST(PLOT_AREA_NAME), args, arg);
	    XtManageChild(work);

	    plot->area = 
		new PlotArea(work, make_font(app_data, FixedWidthDDDFont));
	    XtVaSetValues(work, XmNuserData, XtPointer(plot->area), 
			  XtPointer(0));
	}
	else if (plot_term_type.contains("x11", 0))
	{
	    // x11 type - swallow Gnuplot window
	    arg = 0;
	    work = plot->swallower = 
		XtCreateManagedWidget(SWALLOWER_NAME, swallowerWidgetClass, 
				      scroll, args, arg);
	}
	else
	{
	    // Unknown terminal type
	    post_error("Unknown plot terminal type " + 
		       quote(app_data.plot_term_type),
		       "unknown_plot_term_type_error");
	    return 0;
	}

	// Create scroll bars
	const int slider_size = 20;

	arg = 0;
	XtSetArg(args[arg], XmNorientation, XmHORIZONTAL);      arg++;
	XtSetArg(args[arg], XmNminimum,     0);                 arg++;
	XtSetArg(args[arg], XmNmaximum,     360 + slider_size); arg++;
	plot->hsb = XmCreateScrollBar(scroll, XMST("hsb"), args, arg);
	XtManageChild(plot->hsb);

	arg = 0;
	XtSetArg(args[arg], XmNorientation, XmVERTICAL);        arg++;
	XtSetArg(args[arg], XmNminimum,     0);                 arg++;
	XtSetArg(args[arg], XmNmaximum,     180 + slider_size); arg++;
	plot->vsb = XmCreateScrollBar(scroll, XMST("vsb"), args, arg);
	XtManageChild(plot->vsb);

	XtAddCallback(plot->hsb, XmNvalueChangedCallback,
		      SetViewCB, XtPointer(plot));
	XtAddCallback(plot->vsb, XmNvalueChangedCallback,
		      SetViewCB, XtPointer(plot));

#if 0
	XtAddCallback(plot->hsb, XmNdragCallback, SetViewCB, XtPointer(plot));
	XtAddCallback(plot->vsb, XmNdragCallback, SetViewCB, XtPointer(plot));
#endif

	XmScrolledWindowSetAreas(scroll, plot->hsb, plot->vsb, work);

	Delay::register_shell(plot->shell);
	InstallButtonTips(plot->shell);

	plot_infos += plot;
    }

    string title = DDD_NAME ": " + name;
    XtVaSetValues(plot->shell,
		  XmNtitle, title.chars(),
		  XmNiconName, title.chars(),
		  XtPointer(0));

    if (plot->swallower != 0)
    {
	XtRemoveAllCallbacks(plot->swallower, XtNwindowCreatedCallback);
	XtAddCallback(plot->swallower, XtNwindowCreatedCallback,
		      SwallowCB, XtPointer(plot));

	XtRemoveAllCallbacks(plot->swallower, XtNwindowGoneCallback);
	XtAddCallback(plot->swallower, XtNwindowGoneCallback, 
		      SwallowAgainCB, XtPointer(plot));

	if (plot->swallow_timer != 0)
	    XtRemoveTimeOut(plot->swallow_timer);

	plot->swallow_timer = 
	    XtAppAddTimeOut(XtWidgetToApplicationContext(plot->swallower),
			    app_data.plot_window_delay, SwallowTimeOutCB, 
			    XtPointer(plot));
    }

    plot->active = false;

    return plot;
}