Example #1
0
Size2 GraphNode::get_minimum_size() const {

	Ref<Font> title_font = get_font("title_font");

	int sep = get_constant("separation");
	Ref<StyleBox> sb = get_stylebox("frame");
	bool first = true;

	Size2 minsize;
	minsize.x = title_font->get_string_size(title).x;
	if (show_close) {
		Ref<Texture> close = get_icon("close");
		minsize.x += sep + close->get_width();
	}

	for (int i = 0; i < get_child_count(); i++) {

		Control *c = get_child(i)->cast_to<Control>();
		if (!c)
			continue;
		if (c->is_set_as_toplevel())
			continue;

		Size2i size = c->get_combined_minimum_size();

		minsize.y += size.y;
		minsize.x = MAX(minsize.x, size.x);

		if (first)
			first = false;
		else
			minsize.y += sep;
	}

	return minsize + sb->get_minimum_size();
}
Example #2
0
File: font.c Project: juddy/edcde
extern Boolean
fontlist_to_font(
	XmFontList	 font_list,
	Cal_Font	*cal_font)
{
	XmFontType	 type_return;
	XtPointer	 font_data;

	if (!font_list) return False;

	font_data = get_font(font_list, &type_return);

	if (!font_data) 
		return False;

	cal_font->cf_type = type_return;

	if (type_return == XmFONT_IS_FONTSET)
		cal_font->f.cf_fontset = (XFontSet)font_data;
	else
		cal_font->f.cf_font = (XFontStruct *)font_data;

	return True;
}
Example #3
0
static void render(struct widget *w)
{
    struct widget_priv *priv = w->priv;
    struct canvas *ca = &w->ca;
    unsigned char i;
    unsigned int width = ca->width;
    int x, y;
    char buf[10];
    const struct font *f = get_font(0);

    for (i = 0; i < priv->total_ch; i++) {
        if ((w->cfg->props.mode == 0) || (w->cfg->props.mode == 1))
            sprintf(buf, "CH%u %4d", i+1, priv->ch_raw[i]);
        else
            sprintf(buf, "CH%u", i+1);
        draw_str(buf, 0, i*f->size, ca, 0);

        if ((w->cfg->props.mode == 0) || (w->cfg->props.mode == 2)) {
            x = priv->ch_raw[i] - 1000;
            if (x < 0)
                x = 0;
            else if (x > 1000)
                x = 1000;

            x = (x * (unsigned int) priv->bar_size) / 1000;
            y = i * f->size;

            draw_rect(width-priv->bar_size-1, y,   width-1, y+BAR_SIZE, 3, ca);
            draw_rect(width-priv->bar_size,   y+1, width-2, y+BAR_SIZE-1, 1, ca);

            draw_vline(width-priv->bar_size-1+x,   y+1, y+BAR_SIZE-1, 1, ca);
            draw_vline(width-priv->bar_size-1+x-1, y+1, y+BAR_SIZE-1, 3, ca);
            draw_vline(width-priv->bar_size-1+x+1, y+1, y+BAR_SIZE-1, 3, ca);
        }
    }
}
Example #4
0
void ProgressBar::_notification(int p_what) {

	if (p_what == NOTIFICATION_DRAW) {

		Ref<StyleBox> bg = get_stylebox("bg");
		Ref<StyleBox> fg = get_stylebox("fg");
		Ref<Font> font = get_font("font");
		Color font_color = get_color("font_color");

		draw_style_box(bg, Rect2(Point2(), get_size()));
		float r = get_as_ratio();
		int mp = fg->get_minimum_size().width;
		int p = r * get_size().width - mp;
		if (p > 0) {

			draw_style_box(fg, Rect2(Point2(), Size2(p + fg->get_minimum_size().width, get_size().height)));
		}

		if (percent_visible) {
			String txt = itos(int(get_as_ratio() * 100)) + "%";
			font->draw_halign(get_canvas_item(), Point2(0, font->get_ascent() + (get_size().height - font->get_height()) / 2), HALIGN_CENTER, get_size().width, txt, font_color);
		}
	}
}
Example #5
0
graphics::texture render_text_uncached(const std::string& text,
                                       const SDL_Color& color, int size)
{
#if !TARGET_IPHONE_SIMULATOR && !TARGET_OS_HARMATTAN && !TARGET_OS_IPHONE
	TTF_Font* font = get_font(size);

	graphics::surface s;
	if(std::find(text.begin(), text.end(), '\n') == text.end()) {
		s = graphics::surface(TTF_RenderUTF8_Blended(font, text.c_str(), color));
	} else {
		std::vector<graphics::surface> parts;
		std::vector<std::string> lines = util::split(text, '\n');
		int height = 0, width = 0;
		foreach(const std::string& line, lines) {
			parts.push_back(graphics::surface(TTF_RenderUTF8_Blended(font, line.c_str(), color)));
			if(parts.back().get() == NULL) {
				std::cerr << "FAILED TO RENDER STRING: '" << line << "'\n";
				throw error();
			}

			if(parts.back()->w > width) {
				width = parts.back()->w;
			}

			height += parts.back()->h;
		}

		const SDL_PixelFormat* f = parts.front()->format;
		s = graphics::surface(SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, f->BitsPerPixel, f->Rmask, f->Gmask, f->Bmask, f->Amask));
		int ypos = 0;
		foreach(graphics::surface part, parts) {
			SDL_Rect rect = {0, ypos, part->w, part->h};
			SDL_SetAlpha(part.get(), 0, SDL_ALPHA_OPAQUE);
			SDL_BlitSurface(part.get(), NULL, s.get(), &rect);
			ypos += part->h;
		}
Example #6
0
void RichTextLabel::_notification(int p_what) {

	switch (p_what) {

		case NOTIFICATION_RESIZED: {

			main->first_invalid_line=0; //invalidate ALL
			update();

		} break;
		case NOTIFICATION_ENTER_TREE: {

			set_bbcode(bbcode);
			main->first_invalid_line=0; //invalidate ALL
			update();

		} break;
		case NOTIFICATION_THEME_CHANGED: {

			if (is_inside_tree() && use_bbcode) {
				parse_bbcode(bbcode);
				//first_invalid_line=0; //invalidate ALL
				//update();
			}

		} break;
		case NOTIFICATION_DRAW: {

			_validate_line_caches(main);
			_update_scroll();


			RID ci=get_canvas_item();
			Size2 size = get_size();

			VisualServer::get_singleton()->canvas_item_set_clip(ci,true);

			if (has_focus()) {
				VisualServer::get_singleton()->canvas_item_add_clip_ignore(ci,true);
				draw_style_box(get_stylebox("focus"),Rect2(Point2(),size));
				VisualServer::get_singleton()->canvas_item_add_clip_ignore(ci,false);
			}

			int ofs = vscroll->get_val();

			//todo, change to binary search

			int from_line = 0;
			int total_chars = 0;
			while (from_line<main->lines.size()) {

				if (main->lines[from_line].height_accum_cache>=ofs)
					break;
				from_line++;
				total_chars+=main->lines[from_line].char_count;
			}

			if (from_line>=main->lines.size())
				break; //nothing to draw

			int y = (main->lines[from_line].height_accum_cache - main->lines[from_line].height_cache) - ofs;
			Ref<Font> base_font=get_font("normal_font");
			Color base_color=get_color("default_color");

			while (y<size.height && from_line<main->lines.size()) {

				_process_line(main,Point2(),y,size.width-scroll_w,from_line,PROCESS_DRAW,base_font,base_color,Point2i(),NULL,NULL,NULL,total_chars);
				total_chars+=main->lines[from_line].char_count;
				from_line++;
			}
		}
	}
}
Example #7
0
static void
options(void)

{

    int		ch;			/* return value from getopt() */
    int		n;			/* for CR and LF modes */

/*
 *
 * Reads and processes the command line options. Added the -P option so arbitrary
 * PostScript code can be passed through. Expect it could be useful for changing
 * definitions in the prologue for which options have not been defined.
 *
 * Although any PostScript font can be used, things will only work for constant
 * width fonts.
 *
 */

    while ( (ch = getopt(argc, argv, optnames)) != EOF )  {
	switch ( ch )  {
	    case 'a':			/* aspect ratio */
		    fprintf(stdout, "/aspectratio %s def\n", optarg);
		    break;

	    case 'c':			/* copies */
		    copies = atoi(optarg);
		    fprintf(stdout, "/#copies %s store\n", optarg);
		    break;

	    case 'f':			/* use this PostScript font */
		    fontname = get_font(optarg);
		    fprintf(stdout, "/font /%s def\n", fontname);
		    break;

	    case 'h':			/* default character spacing */
		    ohmi = hmi = atoi(optarg) * HSCALE;
		    fprintf(stdout, "/hmi %s def\n", optarg);
		    break;

	    case 'l':			/* lines per page */
		    linespp = atoi(optarg);
		    break;

	    case 'm':			/* magnification */
		    fprintf(stdout, "/magnification %s def\n", optarg);
		    break;

	    case 'n':			/* forms per page */
		    formsperpage = atoi(optarg);
		    fprintf(stdout, "%s %s\n", FORMSPERPAGE, optarg);
		    fprintf(stdout, "/formsperpage %s def\n", optarg);
		    break;

	    case 'o':			/* output page list */
		    out_list(optarg);
		    break;

	    case 'p':			/* landscape or portrait mode */
		    if ( *optarg == 'l' )
			fprintf(stdout, "/landscape true def\n");
		    else fprintf(stdout, "/landscape false def\n");
		    break;

	    case 'r':			/* set CR and LF modes */
		    n = atoi(optarg);
		    if ( n & 01 )
			lfiscr = ON;
		    else lfiscr = OFF;
		    if ( n & 02 )
			crislf = ON;
		    else crislf = OFF;
		    break;

	    case 's':			/* point size */
		    fprintf(stdout, "/pointsize %s def\n", optarg);
		    break;

	    case 'v':			/* default line spacing */
		    ovmi = vmi = atoi(optarg) * VSCALE;
		    break;

	    case 'x':			/* shift things horizontally */
		    fprintf(stdout, "/xoffset %s def\n", optarg);
		    break;

	    case 'y':			/* and vertically on the page */
		    fprintf(stdout, "/yoffset %s def\n", optarg);
		    break;

	    case 'A':			/* force job accounting */
	    case 'J':
		    if ( (fp_acct = fopen(optarg, "a")) == NULL )
			error(FATAL, "can't open accounting file %s", optarg);
		    break;

	    case 'C':			/* copy file straight to output */
		    if ( cat(optarg) == FALSE )
			error(FATAL, "can't read %s", optarg);
		    break;

	    case 'E':			/* text font encoding */
		    fontencoding = optarg;
		    break;

	    case 'L':			/* PostScript prologue file */
		    prologue = optarg;
		    break;

	    case 'P':			/* PostScript pass through */
		    fprintf(stdout, "%s\n", optarg);
		    break;

	    case 'R':			/* special global or page level request */
		    saverequest(optarg);
		    break;

	    case 'D':			/* debug flag */
		    debug = ON;
		    break;

	    case 'I':			/* ignore FATAL errors */
		    ignore = ON;
		    break;

	    case '?':			/* don't understand the option */
		    error(FATAL, "");
		    break;

	    default:			/* don't know what to do for ch */
		    error(FATAL, "missing case for option %c\n", ch);
		    break;
	}   /* End switch */
    }   /* End while */

    argc -= optind;			/* get ready for non-option args */
    argv += optind;

}   /* End of options */
Example #8
0
int read_info(void)
{
    char buf[1024];
    char *key, *data;
    int fontsize;
    double x, y;
    int r, g, b, ret;
    PSCOLOR color, bgcolor, border;

    fontsize = 0;
    set_color(&color, 0, 0, 0);
    set_color(&bgcolor, 255, 255, 255);
    unset_color(&border);
    x = y = 0.0;

    while (input(2, buf, help)) {
	if (!key_data(buf, &key, &data))
	    continue;

	if (KEY("where")) {
	    if (sscanf(data, "%lf %lf", &x, &y) != 2) {
		x = y = 0.0;
		error(key, data, _("illegal where request"));
	    }
	    else
		continue;
	}

	if (KEY("fontsize")) {
	    fontsize = atoi(data);
	    if (fontsize < 4 || fontsize > 50)
		fontsize = 0;
	    continue;
	}

	if (KEY("color")) {
	    ret = G_str_to_color(data, &r, &g, &b);
	    if (ret == 1)
		set_color(&color, r, g, b);
	    else if (ret == 2)  /* i.e. "none" */
		/* unset_color(&color); */
		error(key, data, _("Unsupported color request"));
	    else
		error(key, data, _("illegal color request"));

	    continue;
	}

	if (KEY("background")) {
	    ret = G_str_to_color(data, &r, &g, &b);
	    if (ret == 1)
		set_color(&bgcolor, r, g, b);
	    else if (ret == 2)  /* i.e. "none" */
		unset_color(&bgcolor);
	    else
		error(key, data, _("illegal bgcolor request"));

	    continue;
	}

	if (KEY("border")) {
	    ret = G_str_to_color(data, &r, &g, &b);
	    if (ret == 1)
		set_color(&border, r, g, b);
	    else if (ret == 2)  /* i.e. "none" */
		unset_color(&border);
	    else
		error(key, data, _("illegal border color request"));

	    continue;
	}

	if (KEY("font")) {
	    get_font(data);
	    m_info.font = G_store(data);
	    continue;
	}
	error(key, data, _("illegal mapinfo sub-request"));
    }
    m_info.x = x;
    m_info.y = y;
    m_info.color = color;
    m_info.bgcolor = bgcolor;
    m_info.border = border;
    if (fontsize)
	m_info.fontsize = fontsize;

    return 0;
}
Example #9
0
void Tabs::_notification(int p_what) {

	switch (p_what) {

		case NOTIFICATION_MOUSE_EXIT: {
			rb_hover = -1;
			cb_hover = -1;
			hover = -1;
			update();
		} break;
		case NOTIFICATION_RESIZED: {

			_ensure_no_over_offset();
		} break;
		case NOTIFICATION_DRAW: {

			RID ci = get_canvas_item();

			Ref<StyleBox> tab_bg = get_stylebox("tab_bg");
			Ref<StyleBox> tab_fg = get_stylebox("tab_fg");
			Ref<Font> font = get_font("font");
			Color color_fg = get_color("font_color_fg");
			Color color_bg = get_color("font_color_bg");
			Ref<Texture> close = get_icon("close");

			int h = get_size().height;
			int w = 0;
			int mw = 0;

			for (int i = 0; i < tabs.size(); i++) {

				tabs[i].ofs_cache = mw;
				mw += get_tab_width(i);
			}

			if (tab_align == ALIGN_CENTER) {
				w = (get_size().width - mw) / 2;
			} else if (tab_align == ALIGN_RIGHT) {
				w = get_size().width - mw;
			}

			if (w < 0) {
				w = 0;
			}

			Ref<Texture> incr = get_icon("increment");
			Ref<Texture> decr = get_icon("decrement");
			Ref<Texture> incr_hl = get_icon("increment_hilite");
			Ref<Texture> decr_hl = get_icon("decrement_hilite");

			int limit = get_size().width - incr->get_size().width - decr->get_size().width;

			missing_right = false;

			for (int i = 0; i < tabs.size(); i++) {

				if (i < offset)
					continue;

				tabs[i].ofs_cache = w;

				int lsize = get_tab_width(i);

				String text = tabs[i].text;
				int slen = font->get_string_size(text).width;

				if (w + lsize > limit) {
					max_drawn_tab = i - 1;
					missing_right = true;
					break;
				} else {
					max_drawn_tab = i;
				}

				Ref<StyleBox> sb;
				Color col;

				if (i == current) {
					sb = tab_fg;
					col = color_fg;
				} else {
					sb = tab_bg;
					col = color_bg;
				}

				Rect2 sb_rect = Rect2(w, 0, lsize, h);
				sb->draw(ci, sb_rect);

				w += sb->get_margin(MARGIN_LEFT);

				Size2i sb_ms = sb->get_minimum_size();
				Ref<Texture> icon = tabs[i].icon;
				if (icon.is_valid()) {

					icon->draw(ci, Point2i(w, sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - icon->get_height()) / 2));
					if (text != "")
						w += icon->get_width() + get_constant("hseparation");
				}

				font->draw(ci, Point2i(w, sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - font->get_height()) / 2 + font->get_ascent()), text, col);

				w += slen;

				if (tabs[i].right_button.is_valid()) {

					Ref<StyleBox> style = get_stylebox("button");
					Ref<Texture> rb = tabs[i].right_button;

					w += get_constant("hseparation");

					Rect2 rb_rect;
					rb_rect.size = style->get_minimum_size() + rb->get_size();
					rb_rect.pos.x = w;
					rb_rect.pos.y = sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - (rb_rect.size.y)) / 2;

					if (rb_hover == i) {
						if (rb_pressing)
							get_stylebox("button_pressed")->draw(ci, rb_rect);
						else
							style->draw(ci, rb_rect);
					}

					rb->draw(ci, Point2i(w + style->get_margin(MARGIN_LEFT), rb_rect.pos.y + style->get_margin(MARGIN_TOP)));
					w += rb->get_width();
					tabs[i].rb_rect = rb_rect;
				}

				if (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && i == current)) {

					Ref<StyleBox> style = get_stylebox("button");
					Ref<Texture> cb = close;

					w += get_constant("hseparation");

					Rect2 cb_rect;
					cb_rect.size = style->get_minimum_size() + cb->get_size();
					cb_rect.pos.x = w;
					cb_rect.pos.y = sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - (cb_rect.size.y)) / 2;

					if (cb_hover == i) {
						if (cb_pressing)
							get_stylebox("button_pressed")->draw(ci, cb_rect);
						else
							style->draw(ci, cb_rect);
					}

					cb->draw(ci, Point2i(w + style->get_margin(MARGIN_LEFT), cb_rect.pos.y + style->get_margin(MARGIN_TOP)));
					w += cb->get_width();
					tabs[i].cb_rect = cb_rect;
				}

				w += sb->get_margin(MARGIN_RIGHT);

				tabs[i].size_cache = w - tabs[i].ofs_cache;
			}

			if (offset > 0 || missing_right) {

				int vofs = (get_size().height - incr->get_size().height) / 2;

				if (offset > 0)
					draw_texture(hilite_arrow == 0 ? decr_hl : decr, Point2(limit, vofs));
				else
					draw_texture(decr, Point2(limit, vofs), Color(1, 1, 1, 0.5));

				if (missing_right)
					draw_texture(hilite_arrow == 1 ? incr_hl : incr, Point2(limit + decr->get_size().width, vofs));
				else
					draw_texture(incr, Point2(limit + decr->get_size().width, vofs), Color(1, 1, 1, 0.5));

				buttons_visible = true;
			} else {
				buttons_visible = false;
			}

		} break;
	}
}
Example #10
0
void ProjectManager::_load_recent_projects() {

	while(scroll_childs->get_child_count()>0) {
		memdelete( scroll_childs->get_child(0));
	}

	List<PropertyInfo> properties;
	EditorSettings::get_singleton()->get_property_list(&properties);

	Color font_color = get_color("font_color","Tree");

	for(List<PropertyInfo>::Element *E=properties.front();E;E=E->next()) {

		String _name = E->get().name;
		if (!_name.begins_with("projects/"))
			continue;

		String project = _name.get_slice("/",1);
		String path = EditorSettings::get_singleton()->get(_name);
		String conf=path.plus_file("engine.cfg");

		Ref<ConfigFile> cf = memnew( ConfigFile );
		Error err = cf->load(conf);
		ERR_CONTINUE(err!=OK);

		Ref<Texture> icon;
		String project_name="Unnamed Project";


		if (cf->has_section_key("application","icon")) {
			String appicon = cf->get_value("application","icon");
			if (appicon!="") {
				Image img;
				Error err = img.load(appicon.replace_first("res://",path+"/"));
				if (err==OK) {

					img.resize(64,64);
					Ref<ImageTexture> it = memnew( ImageTexture );
					it->create_from_image(img);
					icon=it;
				}
			}
		}

		if (cf->has_section_key("application","name")) {
			project_name = cf->get_value("application","name");
		}

		if (icon.is_null()) {
			icon=get_icon("DefaultProjectIcon","EditorIcons");
		}

		String main_scene;
		if (cf->has_section_key("application","main_scene")) {
			main_scene = cf->get_value("application","main_scene");
		}


		HBoxContainer *hb = memnew( HBoxContainer );
		hb->set_meta("name",project);
		hb->set_meta("main_scene",main_scene);
		hb->connect("draw",this,"_panel_draw",varray(hb));
		hb->connect("input_event",this,"_panel_input",varray(hb));
		TextureFrame *tf = memnew( TextureFrame );
		tf->set_texture(icon);
		hb->add_child(tf);
		VBoxContainer *vb = memnew(VBoxContainer);
		hb->add_child(vb);
		EmptyControl *ec = memnew( EmptyControl );
		ec->set_minsize(Size2(0,1));
		vb->add_child(ec);
		Label *title = memnew( Label(project_name) );
		title->add_font_override("font",get_font("large","Fonts"));
		title->add_color_override("font_color",font_color);
		vb->add_child(title);
		Label *fpath = memnew( Label(path) );
		vb->add_child(fpath);
		fpath->set_opacity(0.5);
		fpath->add_color_override("font_color",font_color);

		scroll_childs->add_child(hb);
	}

	erase_btn->set_disabled(selected=="");
	open_btn->set_disabled(selected=="");
	if (selected=="")
		run_btn->set_disabled(true);
}
Example #11
0
void OutputStrings::_notification(int p_what) {

	switch(p_what) {


		case NOTIFICATION_DRAW: {

			if (following) {

				updating=true;
				v_scroll->set_val( v_scroll->get_max() - v_scroll->get_page() );
				updating=false;
			}

			RID ci = get_canvas_item();
			Size2 size = get_size();

			Ref<Font> font = get_font("font","Tree");
			Ref<StyleBox> tree_st = get_stylebox("bg","Tree");
			tree_st->draw(ci,Rect2(Point2(),size));
			Color color = get_color("font_color","Tree");
			Ref<Texture> icon_error = get_icon("Error","EditorIcons");
			Ref<Texture> icon_warning = get_icon("Warning","EditorIcons");

		//	int lines = (size_height-(int)margin.y) / font_height;
			Point2 ofs=tree_st->get_offset();			

			LineMap::Element *E = line_map.find(v_scroll->get_val());
			float h_ofs = (int)h_scroll->get_val();
			Point2 icon_ofs=Point2(0,(font_height-(int)icon_error->get_height())/2);

			while( E && ofs.y < (size_height-(int)margin.y) ) {

				String str = E->get().text;
				Point2 line_ofs=ofs;

				switch(E->get().type) {

					case LINE_WARNING: {
						icon_warning->draw(ci,line_ofs+icon_ofs);

					} break;
					case LINE_ERROR: {
						icon_error->draw(ci,line_ofs+icon_ofs);
					} break;
					case LINE_LINK: {

					} break;
					default: {}
				}

				line_ofs.y+=font->get_ascent();
				line_ofs.x+=icon_error->get_width()+4;

				for(int i=0;i<str.length();i++) {
					if (line_ofs.x-h_ofs < 0 ) {
						line_ofs.x+=font->get_char_size(str[i],str[i+1]).width;
					} else if (line_ofs.x-h_ofs > size.width - margin.width) {
						break;
					} else {
						line_ofs.x+=font->draw_char(ci,Point2(line_ofs.x-h_ofs,line_ofs.y),str[i],str[i+1],color);
					}
				}

				ofs.y+=font_height;
				E=E->next();
			}

		} break;

		case NOTIFICATION_ENTER_TREE:
		case NOTIFICATION_RESIZED: {


			font_height = get_font("font","Tree")->get_height();
			size_height = get_size().height;
			update_scrollbars();
		} break;
	}

}
Example #12
0
void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {

	Ref<InputEventKey> k = p_event;

	if (k.is_valid()) {

		if (!k->is_pressed())
			return;

		switch (k->get_scancode()) {

			case KEY_DOWN: {

				for (int i = mouse_over + 1; i < items.size(); i++) {

					if (i < 0 || i >= items.size())
						continue;

					if (!items[i].separator && !items[i].disabled) {

						mouse_over = i;
						update();
						break;
					}
				}
			} break;
			case KEY_UP: {

				for (int i = mouse_over - 1; i >= 0; i--) {

					if (i < 0 || i >= items.size())
						continue;

					if (!items[i].separator && !items[i].disabled) {

						mouse_over = i;
						update();
						break;
					}
				}
			} break;
			case KEY_ENTER:
			case KEY_KP_ENTER: {

				if (mouse_over >= 0 && mouse_over < items.size() && !items[mouse_over].separator) {

					activate_item(mouse_over);
				}
			} break;
		}
	}

	Ref<InputEventMouseButton> b = p_event;

	if (b.is_valid()) {

		if (b->is_pressed())
			return;

		switch (b->get_button_index()) {

			case BUTTON_WHEEL_DOWN: {

				if (get_global_position().y + get_size().y > get_viewport_rect().size.y) {

					int vseparation = get_constant("vseparation");
					Ref<Font> font = get_font("font");

					Point2 pos = get_position();
					int s = (vseparation + font->get_height()) * 3;
					pos.y -= (s * b->get_factor());
					set_position(pos);

					//update hover
					Ref<InputEventMouseMotion> ie;
					ie.instance();
					ie->set_position(b->get_position() + Vector2(0, s));
					_gui_input(ie);
				}
			} break;
			case BUTTON_WHEEL_UP: {

				if (get_global_position().y < 0) {

					int vseparation = get_constant("vseparation");
					Ref<Font> font = get_font("font");

					Point2 pos = get_position();
					int s = (vseparation + font->get_height()) * 3;
					pos.y += (s * b->get_factor());
					set_position(pos);

					//update hover
					Ref<InputEventMouseMotion> ie;
					ie.instance();
					ie->set_position(b->get_position() - Vector2(0, s));
					_gui_input(ie);
				}
			} break;
			case BUTTON_LEFT: {

				int over = _get_mouse_over(b->get_position());

				if (invalidated_click) {
					invalidated_click = false;
					break;
				}
				if (over < 0) {
					hide();
					break; //non-activable
				}

				if (items[over].separator || items[over].disabled)
					break;

				if (items[over].submenu != "") {

					_activate_submenu(over);
					return;
				}
				activate_item(over);

			} break;
		}

		//update();
	}

	Ref<InputEventMouseMotion> m = p_event;

	if (m.is_valid()) {

		if (invalidated_click) {
			moved += m->get_relative();
			if (moved.length() > 4)
				invalidated_click = false;
		}

		for (List<Rect2>::Element *E = autohide_areas.front(); E; E = E->next()) {

			if (!Rect2(Point2(), get_size()).has_point(m->get_position()) && E->get().has_point(m->get_position())) {
				call_deferred("hide");
				return;
			}
		}

		int over = _get_mouse_over(m->get_position());
		int id = (over < 0 || items[over].separator || items[over].disabled) ? -1 : (items[over].ID >= 0 ? items[over].ID : over);

		if (id < 0) {
			mouse_over = -1;
			update();
			return;
		}

		if (items[over].submenu != "" && submenu_over != over) {
			submenu_over = over;
			submenu_timer->start();
		}

		if (over != mouse_over) {
			mouse_over = over;
			update();
		}
	}
}
Example #13
0
File: main.c Project: ryb/stroop
int main(int argc, char* argv[]) {
	Uint32 flags = SDL_INIT_VIDEO | SDL_INIT_JOYSTICK;
	SDL_Surface *screen;
	Uint8 video_bpp = 16;
	Uint32 videoflags = SDL_SWSURFACE | SDL_FULLSCREEN;
	SDL_Rect **video_modes;
	static TTF_Font *font;
	int done = 0;
	SDL_Event event;
	const int WORD_DELAY = 45; // frames
	int countdown_timer = WORD_DELAY;
	int trial_attempts = 10;
	
	if(SDL_Init(flags) < 0) {
		fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
		exit(1);
	}
	
	video_modes = SDL_ListModes(NULL, videoflags);
	if(video_modes == (SDL_Rect**)0) {
		fprintf(stderr, "No video modes available.\n");
	}
	if(video_modes == (SDL_Rect**)-1) {
		printf("All resolutions available.\n");
	}
	int i;
	for(i = 0; video_modes[i]; ++i) {
		screen = SDL_SetVideoMode(video_modes[i]->w, video_modes[i]->h, video_bpp, videoflags);
		if(screen != NULL) break;
	}
	if(screen == NULL) {
		fprintf(stderr, "Couldn't set video mode: %s\n", SDL_GetError());
		SDL_Quit();
		exit(2);
	}
	if(TTF_Init() < 0) {
		fprintf(stderr, "Couldn't initialize text renderer: %s\n", TTF_GetError());
		exit(2);
	}
	if(SDL_JoystickOpen(0) < 0) {
		fprintf(stderr, "Couldn't initialize joystick.\n");
	}
	
	font = get_font(font, video_modes[i]->h);
	
	SDL_ShowCursor(0);
	SDL_WM_SetCaption("Stroop", NULL);
	
	srand(time(NULL));
	
	while(!done) {
		static long timestamp ;
		static long last_timestamp;
		timestamp = SDL_GetTicks();
		if((timestamp-last_timestamp) < 33)
			continue;
		if(countdown_timer <= 0) {
			int trial = (trial_attempts > 0) ? 1 : 0;
			if(trial) trial_attempts--;
			draw_next_word(screen, font, trial);
			countdown_timer = WORD_DELAY;
		} else {
			countdown_timer--;
		}
		done = pollinput(&event);
		if(fullscreen && !(videoflags & SDL_FULLSCREEN)) {
			videoflags = videoflags ^ SDL_FULLSCREEN;
			screen = SDL_SetVideoMode(video_modes[i]->w, video_modes[i]->h, video_bpp, videoflags);
			font = get_font(font, video_modes[i]->h);
		}
		if(!fullscreen && (videoflags & SDL_FULLSCREEN)) {
			videoflags = videoflags ^ SDL_FULLSCREEN;
			screen = SDL_SetVideoMode(640, 480, video_bpp, videoflags);
			font = get_font(font, 480);
		}
		last_timestamp = timestamp;
	}
	
	TTF_CloseFont(font);
	SDL_JoystickClose(0);
	TTF_Quit();
	SDL_Quit();
	#ifdef GP2X
	chdir("/usr/gp2x");
	execl("/usr/gp2x/gp2xmenu", "/usr/gp2x/gp2xmenu", NULL);
	#endif
	
	return 0;
}
Example #14
0
void EditorHelp::_add_text(const String& p_bbcode) {


	class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/text_color"));
	class_desc->push_font( get_font("normal","Fonts") );
	class_desc->push_indent(1);
	int pos = 0;

	List<String> tag_stack;

	while(pos < p_bbcode.length()) {


		int brk_pos = p_bbcode.find("[",pos);

		if (brk_pos<0)
			brk_pos=p_bbcode.length();

		if (brk_pos > pos) {
			class_desc->add_text(p_bbcode.substr(pos,brk_pos-pos));

		}

		if (brk_pos==p_bbcode.length())
			break; //nothing else o add

		int brk_end = p_bbcode.find("]",brk_pos+1);

		if (brk_end==-1) {
			//no close, add the rest
			class_desc->add_text(p_bbcode.substr(brk_pos,p_bbcode.length()-brk_pos));

			break;
		}


		String tag = p_bbcode.substr(brk_pos+1,brk_end-brk_pos-1);


		if (tag.begins_with("/")) {
			bool tag_ok = tag_stack.size() && tag_stack.front()->get()==tag.substr(1,tag.length());
			if (tag_stack.size()) {



			}
			if (!tag_ok) {

				class_desc->add_text("[");
				pos++;
				continue;
			}

			tag_stack.pop_front();
			pos=brk_end+1;
			if (tag!="/img")
				class_desc->pop();

		} else if (tag.begins_with("method ")) {

			String m = tag.substr(7,tag.length());
			class_desc->push_meta("@"+m);
			class_desc->add_text(m+"()");
			class_desc->pop();
			pos=brk_end+1;

		} else if (doc->class_list.has(tag)) {


			class_desc->push_meta("#"+tag);
			class_desc->add_text(tag);
			class_desc->pop();
			pos=brk_end+1;

		} else if (tag=="b") {

			//use bold font
			class_desc->push_font(get_font("source","Fonts"));
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag=="i") {

			//use italics font
			//class_desc->push_font(get_font("italic","Fonts"));
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag=="code") {

			//use monospace font
			class_desc->push_font(get_font("source","EditorFonts"));
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag=="center") {

			//use monospace font
			class_desc->push_align(RichTextLabel::ALIGN_CENTER);
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag=="br") {

			//use monospace font
			class_desc->add_newline();
			pos=brk_end+1;
		} else if (tag=="u") {

			//use underline
			class_desc->push_underline();
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag=="s") {

			//use strikethrough (not supported underline instead)
			class_desc->push_underline();
			pos=brk_end+1;
			tag_stack.push_front(tag);

		} else if (tag=="url") {

			//use strikethrough (not supported underline instead)
			int end=p_bbcode.find("[",brk_end);
			if (end==-1)
				end=p_bbcode.length();
			String url = p_bbcode.substr(brk_end+1,end-brk_end-1);
			class_desc->push_meta(url);

			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag.begins_with("url=")) {

			String url = tag.substr(4,tag.length());
			class_desc->push_meta(url);
			pos=brk_end+1;
			tag_stack.push_front("url");
		} else if (tag=="img") {

			//use strikethrough (not supported underline instead)
			int end=p_bbcode.find("[",brk_end);
			if (end==-1)
				end=p_bbcode.length();
			String image = p_bbcode.substr(brk_end+1,end-brk_end-1);

			Ref<Texture> texture = ResourceLoader::load(base_path+"/"+image,"Texture");
			if (texture.is_valid())
				class_desc->add_image(texture);

			pos=end;
			tag_stack.push_front(tag);
		} else if (tag.begins_with("color=")) {

			String col = tag.substr(6,tag.length());
			Color color;

			if (col.begins_with("#"))
				color=Color::html(col);
			else if (col=="aqua")
				color=Color::html("#00FFFF");
			else if (col=="black")
				color=Color::html("#000000");
			else if (col=="blue")
				color=Color::html("#0000FF");
			else if (col=="fuchsia")
				color=Color::html("#FF00FF");
			else if (col=="gray" || col=="grey")
				color=Color::html("#808080");
			else if (col=="green")
				color=Color::html("#008000");
			else if (col=="lime")
				color=Color::html("#00FF00");
			else if (col=="maroon")
				color=Color::html("#800000");
			else if (col=="navy")
				color=Color::html("#000080");
			else if (col=="olive")
				color=Color::html("#808000");
			else if (col=="purple")
				color=Color::html("#800080");
			else if (col=="red")
				color=Color::html("#FF0000");
			else if (col=="silver")
				color=Color::html("#C0C0C0");
			else if (col=="teal")
				color=Color::html("#008008");
			else if (col=="white")
				color=Color::html("#FFFFFF");
			else if (col=="yellow")
				color=Color::html("#FFFF00");
			else
				color=Color(0,0,0,1); //base_color;



			class_desc->push_color(color);
			pos=brk_end+1;
			tag_stack.push_front("color");

		} else if (tag.begins_with("font=")) {

			String fnt = tag.substr(5,tag.length());


			Ref<Font> font = ResourceLoader::load(base_path+"/"+fnt,"Font");
			if (font.is_valid())
				class_desc->push_font(font);
			else {
				class_desc->push_font(get_font("source","rFonts"));
			}

			pos=brk_end+1;
			tag_stack.push_front("font");


		} else {

			class_desc->add_text("["); //ignore
			pos=brk_pos+1;

		}
	}

	class_desc->pop();
	class_desc->pop();

}
Example #15
0
Error EditorHelp::_goto_desc(const String& p_class,bool p_update_history,int p_vscr) {

	//ERR_FAIL_COND(!doc->class_list.has(p_class));
	if (!doc->class_list.has(p_class))
		return ERR_DOES_NOT_EXIST;


	if (tree_item_map.has(p_class)) {
		select_locked = true;
		tree_item_map[p_class]->select(0);
		class_list->ensure_cursor_is_visible();
	}

	class_desc->show();
	//tabs->set_current_tab(PAGE_CLASS_DESC);
	edited_class->set_pressed(true);
	class_list_button->set_pressed(false);
	description_line=0;

	if (p_class==edited_class->get_text())
		return OK; //already there

	scroll_locked=true;

	if (p_update_history) {

		history.resize(history_pos);
		history_pos++;
		History h;
		h.c=p_class;
		h.scroll=0;
		history.push_back(h);
		_update_history_buttons();
		class_desc->get_v_scroll()->set_val(0);
	}

	class_desc->clear();
	method_line.clear();
	edited_class->set_text(p_class);
	//edited_class->show();


	DocData::ClassDoc &cd=doc->class_list[p_class];

	Color h_color;

	Ref<Font> doc_font = get_font("normal","Fonts");
	Ref<Font> doc_code_font = get_font("source","Fonts");
	Ref<Font> doc_title_font = get_font("large","Fonts");


	h_color=Color(1,1,1,1);

	class_desc->push_font(doc_title_font);
	class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color"));
	class_desc->add_text("Class: ");
	class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/base_type_color"));
	class_desc->add_text(p_class);
	class_desc->pop();
	class_desc->pop();
	class_desc->pop();
	class_desc->add_newline();

	if (cd.inherits!="") {

		class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color"));
		class_desc->push_font(doc_title_font);
		class_desc->add_text("Inherits: ");
		class_desc->pop();
		class_desc->pop();
		class_desc->push_font(doc_font);
		_add_type(cd.inherits);
		class_desc->pop();
		class_desc->add_newline();
		class_desc->add_newline();

	}

	if (cd.brief_description!="") {

		class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color"));
		class_desc->push_font(doc_title_font);
		class_desc->add_text("Brief Description:");
		class_desc->pop();
		class_desc->pop();

		//class_desc->add_newline();
		class_desc->add_newline();
		_add_text(cd.brief_description);
		class_desc->add_newline();
		class_desc->add_newline();
	}

	bool method_descr=false;

	if (cd.methods.size()) {

		class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color"));
		class_desc->push_font(doc_title_font);
		class_desc->add_text("Public Methods:");
		class_desc->pop();
		class_desc->pop();

		//class_desc->add_newline();
		class_desc->add_newline();

		class_desc->push_indent(1);

		for(int i=0;i<cd.methods.size();i++) {

			method_line[cd.methods[i].name]=class_desc->get_line_count()-2;	//gets overriden if description
			class_desc->push_font(doc_code_font);
			_add_type(cd.methods[i].return_type);
			class_desc->add_text(" ");
			if (cd.methods[i].description!="") {
				method_descr=true;
				class_desc->push_meta("@"+cd.methods[i].name);
			}
			class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/text_color"));
			class_desc->add_text(cd.methods[i].name);
			class_desc->pop();
			if (cd.methods[i].description!="")
				class_desc->pop();
			class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/symbol_color"));
			class_desc->add_text(cd.methods[i].arguments.size()?"( ":"(");
			class_desc->pop();
			for(int j=0;j<cd.methods[i].arguments.size();j++) {
				class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/text_color"));
				if (j>0)
					class_desc->add_text(", ");
				_add_type(cd.methods[i].arguments[j].type);
				class_desc->add_text(" "+cd.methods[i].arguments[j].name);
				if (cd.methods[i].arguments[j].default_value!="") {

					class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/symbol_color"));
					class_desc->add_text("=");
					class_desc->pop();
					class_desc->add_text(cd.methods[i].arguments[j].default_value);
				}

				class_desc->pop();
			}

			class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/symbol_color"));
			class_desc->add_text(cd.methods[i].arguments.size()?" )":")");
			class_desc->pop();
			if (cd.methods[i].qualifiers!="") {

				class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color"));
				class_desc->add_text(" "+cd.methods[i].qualifiers);
				class_desc->pop();

			}
			class_desc->pop();//monofont
			class_desc->add_newline();

		}

		class_desc->pop();
		class_desc->add_newline();

	}

	if (cd.properties.size()) {


		class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color"));
		class_desc->push_font(doc_title_font);
		class_desc->add_text("Members:");
		class_desc->pop();
		class_desc->pop();
		class_desc->add_newline();

		class_desc->push_indent(1);

		//class_desc->add_newline();

		for(int i=0;i<cd.properties.size();i++) {

			property_line[cd.properties[i].name]=class_desc->get_line_count()-2;	//gets overriden if description
			class_desc->push_font(doc_code_font);
			_add_type(cd.properties[i].type);
			class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/text_color"));
			class_desc->add_text(" "+cd.properties[i].name);
			class_desc->pop();
			class_desc->pop();

			if (cd.properties[i].description!="") {
				class_desc->push_font(doc_font);
				class_desc->add_text("  ");
				class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/comment_color"));
				class_desc->add_text(cd.properties[i].description);
				class_desc->pop();
				class_desc->pop();

			}

			class_desc->add_newline();
		}

		class_desc->add_newline();
		class_desc->pop();


	}

	if (cd.theme_properties.size()) {


		class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color"));
		class_desc->push_font(doc_title_font);
		class_desc->add_text("GUI Theme Items:");
		class_desc->pop();
		class_desc->pop();
		class_desc->add_newline();

		class_desc->push_indent(1);

		//class_desc->add_newline();

		for(int i=0;i<cd.theme_properties.size();i++) {

			theme_property_line[cd.theme_properties[i].name]=class_desc->get_line_count()-2;	//gets overriden if description
			class_desc->push_font(doc_code_font);
			_add_type(cd.theme_properties[i].type);
			class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/text_color"));
			class_desc->add_text(" "+cd.theme_properties[i].name);
			class_desc->pop();
			class_desc->pop();

			if (cd.theme_properties[i].description!="") {
				class_desc->push_font(doc_font);
				class_desc->add_text("  ");
				class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/comment_color"));
				class_desc->add_text(cd.theme_properties[i].description);
				class_desc->pop();
				class_desc->pop();

			}

			class_desc->add_newline();
		}

		class_desc->add_newline();
		class_desc->pop();


	}
	if (cd.signals.size()) {

		class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color"));
		class_desc->push_font(doc_title_font);
		class_desc->add_text("Signals:");
		class_desc->pop();
		class_desc->pop();

		class_desc->add_newline();
		//class_desc->add_newline();

		class_desc->push_indent(1);

		for(int i=0;i<cd.signals.size();i++) {

			signal_line[cd.signals[i].name]=class_desc->get_line_count()-2;	//gets overriden if description
			class_desc->push_font(doc_code_font);
			//_add_type("void");
			//class_desc->add_text(" ");
			class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/text_color"));
			class_desc->add_text(cd.signals[i].name);
			class_desc->pop();
			class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/symbol_color"));
			class_desc->add_text(cd.signals[i].arguments.size()?"( ":"(");
			class_desc->pop();
			for(int j=0;j<cd.signals[i].arguments.size();j++) {
				class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/text_color"));
				if (j>0)
					class_desc->add_text(", ");
				_add_type(cd.signals[i].arguments[j].type);
				class_desc->add_text(" "+cd.signals[i].arguments[j].name);
				if (cd.signals[i].arguments[j].default_value!="") {

					class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/symbol_color"));
					class_desc->add_text("=");
					class_desc->pop();
					class_desc->add_text(cd.signals[i].arguments[j].default_value);
				}

				class_desc->pop();
			}

			class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/symbol_color"));
			class_desc->add_text(cd.signals[i].arguments.size()?" )":")");
			class_desc->pop();
			if (cd.signals[i].description!="") {

				class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/comment_color"));
				class_desc->add_text(" "+cd.signals[i].description);
				class_desc->pop();

			}
			class_desc->pop();//monofont
			class_desc->add_newline();

		}

		class_desc->pop();
		class_desc->add_newline();

	}

	if (cd.constants.size()) {


		class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color"));
		class_desc->push_font(doc_title_font);
		class_desc->add_text("Constants:");
		class_desc->pop();
		class_desc->pop();
		class_desc->push_indent(1);

		class_desc->add_newline();
		//class_desc->add_newline();

		for(int i=0;i<cd.constants.size();i++) {

			constant_line[cd.constants[i].name]=class_desc->get_line_count()-2;
			class_desc->push_font(doc_code_font);
			class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/base_type_color"));
			class_desc->add_text(cd.constants[i].name);
			class_desc->pop();
			class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/symbol_color"));
			class_desc->add_text(" = ");
			class_desc->pop();
			class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color"));
			class_desc->add_text(cd.constants[i].value);
			class_desc->pop();
			class_desc->pop();
			if (cd.constants[i].description!="") {
				class_desc->push_font(doc_font);
				class_desc->add_text("  ");
				class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/comment_color"));
				class_desc->add_text(cd.constants[i].description);
				class_desc->pop();
				class_desc->pop();
			}

			class_desc->add_newline();
		}

		class_desc->pop();
		class_desc->add_newline();


	}

	if (cd.description!="") {

		description_line=class_desc->get_line_count()-2;
		class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color"));
		class_desc->push_font(doc_title_font);
		class_desc->add_text("Description:");
		class_desc->pop();
		class_desc->pop();

		class_desc->add_newline();
		class_desc->add_newline();
		_add_text(cd.description);
		class_desc->add_newline();
		class_desc->add_newline();
	}

	if (method_descr) {

		class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color"));
		class_desc->push_font(doc_title_font);
		class_desc->add_text("Method Description:");
		class_desc->pop();
		class_desc->pop();

		class_desc->add_newline();
		class_desc->add_newline();


		for(int i=0;i<cd.methods.size();i++) {

			method_line[cd.methods[i].name]=class_desc->get_line_count()-2;

			class_desc->push_font(doc_code_font);
			_add_type(cd.methods[i].return_type);

			class_desc->add_text(" ");
			class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/text_color"));
			class_desc->add_text(cd.methods[i].name);
			class_desc->pop();
			class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/symbol_color"));
			class_desc->add_text(cd.methods[i].arguments.size()?"( ":"(");
			class_desc->pop();
			for(int j=0;j<cd.methods[i].arguments.size();j++) {
				class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/text_color"));
				if (j>0)
					class_desc->add_text(", ");
				_add_type(cd.methods[i].arguments[j].type);
				class_desc->add_text(" "+cd.methods[i].arguments[j].name);
				if (cd.methods[i].arguments[j].default_value!="") {

					class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/symbol_color"));
					class_desc->add_text("=");
					class_desc->pop();
					class_desc->add_text(cd.methods[i].arguments[j].default_value);
				}

				class_desc->pop();
			}

			class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/symbol_color"));
			class_desc->add_text(cd.methods[i].arguments.size()?" )":")");
			class_desc->pop();
			if (cd.methods[i].qualifiers!="") {

				class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color"));
				class_desc->add_text(" "+cd.methods[i].qualifiers);
				class_desc->pop();

			}

			class_desc->pop();

			class_desc->add_newline();
			class_desc->add_newline();
			_add_text(cd.methods[i].description);
			class_desc->add_newline();
			class_desc->add_newline();

		}





	}

	if (!p_update_history) {

		class_desc->get_v_scroll()->set_val(history[history_pos-1].scroll);
	}

	scroll_locked=false;

	return OK;
}
Example #16
0
void    GLUI_EditText::draw_text( int x, int y )
{
  GLUI_DRAWINGSENTINAL_IDIOM
  int text_x, i, sel_lo, sel_hi;

  if ( debug )    dump( stdout, "-> DRAW_TEXT" );

  if ( NOT draw_text_only ) {
    if ( enabled )
      glColor3f( 1., 1., 1. );
    else
      set_to_bkgd_color();
    glDisable( GL_CULL_FACE );
    glBegin( GL_QUADS );
    glVertex2i( text_x_offset+2, 2 );     glVertex2i( w-2, 2 );
    glVertex2i( w-2, h-2 );               glVertex2i( text_x_offset+2, h-2 );
    glEnd();
  }

  /** Find where to draw the text **/

  text_x = text_x_offset + 2 + GLUI_EDITTEXT_BOXINNERMARGINX;

  /*printf( "text_x: %d      substr_width: %d     start/end: %d/%d\n",
    text_x,     substring_width( substring_start, substring_end ),
    substring_start, substring_end );
    */
  /** Find lower and upper selection bounds **/
  sel_lo = MIN(sel_start, sel_end );
  sel_hi = MAX(sel_start, sel_end );

  int sel_x_start, sel_x_end, delta;

  /** Draw selection area dark **/
  if ( sel_start != sel_end ) {
    sel_x_start = text_x;
    sel_x_end   = text_x;
    for( i=substring_start; i<=substring_end; i++ ) {
      delta = char_width( text[i] );

      if ( i < sel_lo ) {
	sel_x_start += delta;
	sel_x_end   += delta;
      }
      else if ( i < sel_hi ) {
	sel_x_end   += delta;
      }
    }

    glColor3f( 0.0f, 0.0f, .6f );
    glBegin( GL_QUADS );
    glVertex2i( sel_x_start, 2 );    glVertex2i( sel_x_end, 2 );
    glVertex2i( sel_x_end, h-2 );    glVertex2i( sel_x_start, h-2 );
    glEnd();
  }
   

  if ( sel_start == sel_end ) {   /* No current selection */
    if ( enabled )
      glColor3b( 0, 0, 0 );
    else
      glColor3b( 32, 32, 32 );
      
    glRasterPos2i( text_x, 13);
    for( i=substring_start; i<=substring_end; i++ ) {
      glutBitmapCharacter( get_font(), this->text[i] );
    }
  }
  else {                          /* There is a selection */
    int x = text_x;
    for( i=substring_start; i<=substring_end; i++ ) {
      if ( IN_BOUNDS( i, sel_lo, sel_hi-1)) { /* This character is selected */
	glColor3f( 1., 1., 1. );
	glRasterPos2i( x, 13);
	glutBitmapCharacter( get_font(), this->text[i] );
      }
      else {
	glColor3f( 0., 0., 0. );
	glRasterPos2i( x, 13);
	glutBitmapCharacter( get_font(), this->text[i] );
      }
      
      x += char_width( text[i] );
    }
  }

  if ( debug )    dump( stdout, "<- DRAW_TEXT" );  
}
Example #17
0
// -------------------------------------------------------------------
// dialog for purchasing buildings in town
// create buttons for purchasing buildings.
// -------------------------------------------------------------------
void t_buy_building_window::create_buttons( t_window* background )
{
	t_button_info button_info[k_max_buttons];
	t_town_type   town_type = m_town->get_type();
	t_help_block const& help = get_help_block( "town_hall" );

	int i;

	for (i = 0; i < k_max_buttons; i++)
	{
		button_info[i].id = -1;
		button_info[i].state = k_button_hidden;
	}

	set_button_state( button_info, m_town, k_common_buttons, ELEMENTS_OF( k_common_buttons ));
	set_button_state( button_info, m_town, k_button_maps[town_type].map, 
	                  k_button_maps[town_type].count );

	t_bitmap_layer const* layer;
	t_button*			  button;
	t_bitmap_layer const* frame = m_interface->find( "frame" );
	t_screen_point        frame_origin = frame->get_rect().top_left();
	t_bitmap_layer const* thumbnail = m_interface->find( "thumbnail" );
	t_screen_point        thumbnail_origin = thumbnail->get_rect().top_left() - frame_origin;
	t_bitmap_layer const* x_mark = m_interface->find( "cannot build" );
	t_bitmap_layer const* bars[6];
	t_window*             frame_window;
	t_window*             window;
	t_town_building       building;

	m_thumbnails = g_building_thumbnails[town_type]->get();

	bars[k_button_disabled - 1]		 = m_interface->find( "gray bar" );
	bars[k_button_built - 1]		 = m_interface->find( "gold bar" );
	bars[k_button_cannot_build - 1]	 = m_interface->find( "red bar" );
	bars[k_button_cannot_afford - 1] = bars[k_button_cannot_build - 1];
	bars[k_button_not_owner - 1]     = bars[k_button_cannot_build - 1];
	bars[k_button_ok - 1]			 = m_interface->find( "green bar" );

	// find row rectangles
	t_bitmap_layer const* rows[5];
	int                   row_counts[5];
	int                   row_spacing[5];
	int                   row_start[5];

	for (i = 0; i < 5; i++)
	{
		row_counts[i] = 0;
		rows[i] = m_interface->find( format_string( "row %i", i + 1 ) );
	}

	// count # of buttons in each row
	for (i = 0; i < 20; i++)
		if (button_info[i].state != k_button_hidden)
			row_counts[i / 4]++;

	// compute row spacing
    int             width_diff;
	for (i = 0; i < 5; i++)
	{
        // Diff. between row frame and sum of individual building frames.
        width_diff = (rows[i]->get_width() - k_building_columns * frame->get_width());

		row_spacing[i] = width_diff / (k_building_columns - 1) + frame->get_width();
		row_start[i] =  (rows[i]->get_width() - frame->get_width() 
			             - row_spacing[i] * (row_counts[i] - 1)) / 2;
	}             

	// create the buttons
	t_screen_point  point;
	int             row;
	t_window*       bar;
	t_text_window*  text_window;
	t_screen_rect   rect;
	t_screen_rect   text_rect = m_interface->find("building_text")->get_rect();

	//t_screen_point  thumbnail_offset;

	for (i = 0; i < k_max_buttons; i++)
	{
		if (button_info[i].state == k_button_hidden)
			continue;

		building = t_town_building( button_info[i].id  );

		t_building_traits const& traits = get_traits( town_type, building );

		row = i / k_building_columns;
		point = rows[row]->get_rect().top_left();
		point.x += row_start[row] + (i % k_building_columns ) * row_spacing[row];
		button = new t_button( point, background );
		
        rect = frame->get_rect() - frame->get_rect().top_left();
	    frame_window = new t_window ( rect, k_completely_transparent, button );
		window = new t_bitmap_layer_window( frame, -frame->get_rect().top_left(), frame_window );

		// add thumbnail
		layer = m_thumbnails->find( traits.keyword );
		window = new t_bitmap_layer_window( layer, thumbnail_origin, frame_window );

		// if cannot build, add X mark
		switch (button_info[i].state)
		{
			case k_button_disabled:
			case k_button_cannot_build:
			case k_button_cannot_afford:
				window = new t_bitmap_layer_window( x_mark, -frame_origin, frame_window );
				break;
		}
		
		// add appropriate bar
		t_bitmap_layer const* bar_layer = bars[button_info[i].state - 1];
		bar = new t_bitmap_layer_window( bar_layer, -frame_origin, frame_window );
		
		// add name to bar
		text_window = new t_text_window( get_font( text_rect.height() / 2 ), text_rect - bar_layer->get_rect().top_left(),
			                             bar, traits.name, t_pixel_24(0, 0, 0) );
		text_window->set_center_horizontal();
		text_window->set_center_vertical();
		//text_window->set_drop_shadow( true );

		switch (button_info[i].state)
		{
            case k_button_built:
	            set_help( button, help, "gold_bar" );
                break;

			case k_button_disabled:
	            set_help( button, help, "gray_bar" );
                break;

			case k_button_cannot_build:
	            set_help( button, help, "red_bar_x" );
                break;

			case k_button_cannot_afford:
	            set_help( button, help, "red_bar_$" );
				break;

			case k_button_not_owner:
				set_help( button, help, "red_bar_owner" );
				break;

            default :
	            set_help( button, help, "green_bar" );
				break;
		}
		
		// set image and handler
	    frame_window->set_size_from_children();
		button->set_released_image( frame_window );
		if (button_info[i].state == k_button_disabled)
        {
		    button->set_click_handler( add_2nd_argument(
			    bound_handler( *this, &t_buy_building_window::disabled_building_click ), button_info[i].id ));
        }
        else
        {
		    button->set_click_handler( add_2nd_argument(
			    bound_handler( *this, &t_buy_building_window::building_click ), button_info[i].id ));
        }
		button->set_right_click_handler( add_2nd_argument(
			bound_handler( *this, &t_buy_building_window::describe_building ), button_info[i].id ));
	}
}
Example #18
0
void PopupMenu::_input_event(const InputEvent &p_event) {

	switch( p_event.type) {

		case InputEvent::KEY: {


			if (!p_event.key.pressed)
				break;

			switch(p_event.key.scancode) {


				case KEY_DOWN: {


					for(int i=mouse_over+1;i<items.size();i++) {

						if (i<0 || i>=items.size())
							continue;

						if (!items[i].separator && !items[i].disabled) {


							mouse_over=i;
							update();
							break;
						}
					}
				} break;
				case KEY_UP: {


					for(int i=mouse_over-1;i>=0;i--) {

						if (i<0 || i>=items.size())
							continue;


						if (!items[i].separator && !items[i].disabled) {


						   mouse_over=i;
						   update();
						   break;
						}
					}
				} break;
				case KEY_RETURN:
				case KEY_ENTER: {

					if (mouse_over>=0 && mouse_over<items.size() && !items[mouse_over].separator) {


						activate_item(mouse_over);

					}
				} break;
			}





		} break;

		case InputEvent::MOUSE_BUTTON: {
	
			
			const InputEventMouseButton &b=p_event.mouse_button;
			if (b.pressed)
				break;			

			switch(b.button_index) {


				case BUTTON_WHEEL_DOWN: {

					if (get_global_pos().y + get_size().y > get_viewport_rect().size.y) {

						int vseparation = get_constant("vseparation");
						Ref<Font> font = get_font("font");

						Point2 pos = get_pos();
						int s = (vseparation+font->get_height())*3;
						pos.y-=s;
						set_pos(pos);

						//update hover
						InputEvent ie;
						ie.type=InputEvent::MOUSE_MOTION;
						ie.mouse_motion.x=b.x;
						ie.mouse_motion.y=b.y+s;
						_input_event(ie);
					}
				} break;
				case BUTTON_WHEEL_UP: {

					if (get_global_pos().y < 0) {

						int vseparation = get_constant("vseparation");
						Ref<Font> font = get_font("font");

						Point2 pos = get_pos();
						int s = (vseparation+font->get_height())*3;
						pos.y+=s;
						set_pos(pos);

						//update hover
						InputEvent ie;
						ie.type=InputEvent::MOUSE_MOTION;
						ie.mouse_motion.x=b.x;
						ie.mouse_motion.y=b.y-s;
						_input_event(ie);


					}
				} break;
				case BUTTON_LEFT: {

					int over=_get_mouse_over(Point2(b.x,b.y));

					if (invalidated_click) {
						invalidated_click=false;
						break;
					}
					if (over<0) {
						hide();
						break; //non-activable
					}

					if (items[over].separator || items[over].disabled)
						break;

					if (items[over].submenu!="") {

						_activate_submenu(over);
						return;
					}
					activate_item(over);

				} break;
			}
			
			//update();
		} break;
		case InputEvent::MOUSE_MOTION: {
	

			if (invalidated_click) {
				moved+=Vector2(p_event.mouse_motion.relative_x,p_event.mouse_motion.relative_y);
				if (moved.length()>4)
					invalidated_click=false;

			}

			const InputEventMouseMotion &m=p_event.mouse_motion;
			for(List<Rect2>::Element *E=autohide_areas.front();E;E=E->next()) {

				if (!Rect2(Point2(),get_size()).has_point(Point2(m.x,m.y)) && E->get().has_point(Point2(m.x,m.y))) {
					call_deferred("hide");
					return;
				}
			}

			int over=_get_mouse_over(Point2(m.x,m.y));
			int id = (over<0 || items[over].separator || items[over].disabled)?-1:items[over].ID;

			if (id<0) {
				mouse_over=-1;
				update();
				break;
			}

			if (items[over].submenu!="" && submenu_over!=over) {
				submenu_over=over;
				submenu_timer->start();
			}

			if (over!=mouse_over) {
				mouse_over=over;
				update();
			}
		} break;

	}
}
Example #19
0
int read_scalebar(void)
{
    char buf[1024];
    char *key, *data;
    char ch;

    /* struct defined in decorate.h */
    sb.segment = 4;		/* four segments */
    sb.numbers = 1;		/* label each segment */
    sb.font = G_store("Helvetica");
    sb.fontsize = 8;
    sb.color = BLACK;		/* TODO: multi-color */
    sb.width = 1.;
    sb.length = -1.;
    sb.height = 0.1;		/* default height in inches */
    sb.x = PS.page_width / 2.;
    sb.y = 2.;
    sb.bgcolor = 1;		/* TODO: multi-color */
    sb.units = SB_UNITS_AUTO;   /* default to automatic based on value in PROJ_UNITS */


    while (input(2, buf, help)) {
	if (!key_data(buf, &key, &data))
	    continue;

	if (KEY("where")) {
	    if (sscanf(data, "%lf %lf", &sb.x, &sb.y) != 2) {
		error(key, data, "illegal where request");
	    }
	    else
		continue;
	}

	if (KEY("height")) {
	    if (sscanf(data, "%lf", &sb.height) != 1 || sb.height <= 0.) {
		error(key, data, "illegal height request");
	    }
	    else
		continue;
	}

	if (KEY("length")) {
	    if (sscanf(data, "%lf", &sb.length) != 1 || sb.length <= 0.) {
		error(key, data, "illegal length request");
	    }
	    else
		continue;
	}

	if (KEY("units")) {
	    G_strip(data);
	    if (strcmp(data, "auto") == 0) {
		sb.units = SB_UNITS_AUTO;
		continue;
	    }
	    else if (G_projection() == PROJECTION_XY) {
		error(key, data,
		  "Earth units not available in simple XY location");
	    }
	    else if (strcmp(data, "meters") == 0) {
		sb.units = SB_UNITS_METERS;
		continue;
	    }
	    else if (strcmp(data, "kilometers") == 0 || strcmp(data, "km") == 0) {
		sb.units = SB_UNITS_KM;
		continue;
	    }
	    else if (strcmp(data, "feet") == 0) {
		sb.units = SB_UNITS_FEET;
		continue;
	    }
	    else if (strcmp(data, "miles") == 0) {
		sb.units = SB_UNITS_MILES;
		continue;
	    }
	    else if (strcmp(data, "nautmiles") == 0 || strcmp(data, "nm") == 0) {
		sb.units = SB_UNITS_NMILES;
		continue;
	    }
	    else
		error(key, data, "illegal units request");
	}

	if (KEY("segment")) {
	    if (sscanf(data, "%d", &sb.segment) != 1 || sb.segment <= 0) {
		error(key, data, "illegal segment request");
	    }
	    else
		continue;
	}

	if (KEY("numbers")) {
	    if (sscanf(data, "%d", &sb.numbers) != 1 || sb.numbers <= 0) {
		error(key, data, "illegal numbers request");
	    }
	    else
		continue;
	}

	if (KEY("font")) {
	    get_font(data);
	    G_free(sb.font);
	    sb.font = G_store(data);
	    continue;
	}

	if (KEY("fontsize")) {
	    if (sscanf(data, "%d", &sb.fontsize) != 1 || sb.fontsize <= 0) {
		error(key, data, "illegal fontsize request");
	    }
	    else
		continue;
	}

	if (KEY("color"))
	{
	    sb.color = get_color_number(data);
	    if (sb.color < 0)
	    {
		sb.color = BLACK;
		error(key, data, "illegal color request");
	    }
	    continue;
	}

	if (KEY("background")) {
	    sb.bgcolor = yesno(key, data);
	    continue;
	}

	if (KEY("width")) {
	    sb.width = -1.;
	    ch = ' ';
	    if ((sscanf(data, "%lf%c", &sb.width, &ch) < 1) ||
		(sb.width < 0.)) {
		sb.width = 1.;
		error(key, data, "illegal grid width request");
	    }
	    if (ch == 'i')
		sb.width = sb.width * 72.0;
	    continue;
	}

	error(key, data, "illegal request (scalebar)");

    }

    return 0;

}
Example #20
0
void PopupMenu::_notification(int p_what) {

	switch(p_what) {
	

		case NOTIFICATION_DRAW: {
		
			RID ci = get_canvas_item();
			Size2 size=get_size();
		
			Ref<StyleBox> style = get_stylebox("panel");
			Ref<StyleBox> hover = get_stylebox("hover");
			Ref<Font> font = get_font("font");
			Ref<Texture> check = get_icon("checked");
			Ref<Texture> uncheck = get_icon("unchecked");
			Ref<Texture> submenu= get_icon("submenu");
			Ref<StyleBox> separator = get_stylebox("separator");
			
			style->draw( ci, Rect2( Point2(), get_size() ) );
			Point2 ofs=style->get_offset();
			int vseparation = get_constant("vseparation");
			int hseparation = get_constant("hseparation");
			Color font_color = get_color("font_color");
			Color font_color_disabled = get_color("font_color_disabled");
			Color font_color_accel = get_color("font_color_accel");
			Color font_color_hover = get_color("font_color_hover");
			float font_h=font->get_height();
			
			for (int i=0;i<items.size();i++) {
			
				if (i>0)
					ofs.y+=vseparation;
				Point2 item_ofs=ofs;
				float h;
				Size2 icon_size;
								
				if (!items[i].icon.is_null()) {
				
					icon_size = items[i].icon->get_size();
					h = MAX( icon_size.height, font_h );
				} else {
				
					h=font_h;
				}
					
				if (i==mouse_over) {
							
					hover->draw(ci,	Rect2( ofs+Point2(-hseparation,-vseparation), Size2( get_size().width - style->get_minimum_size().width + hseparation*2, h+vseparation*2 ) ));
				}
				
				if (items[i].separator) {
				
					int sep_h=separator->get_center_size().height+separator->get_minimum_size().height;
					separator->draw(ci,	Rect2( ofs+Point2(0,Math::floor((h-sep_h)/2.0)), Size2( get_size().width - style->get_minimum_size().width , sep_h ) ));
					
				}
				
				if (items[i].checkable) {

					if (items[i].checked)
						check->draw(ci, item_ofs+Point2(0,Math::floor((h-check->get_height())/2.0)));
					else
						uncheck->draw(ci, item_ofs+Point2(0,Math::floor((h-check->get_height())/2.0)));

					item_ofs.x+=check->get_width()+hseparation;
				}

				if (!items[i].icon.is_null()) {
					items[i].icon->draw( ci, item_ofs+Point2(0,Math::floor((h-icon_size.height)/2.0)));
					item_ofs.x+=items[i].icon->get_width();
					item_ofs.x+=hseparation;
				}

				if (items[i].submenu!="") {
					submenu->draw( ci, Point2(size.width - style->get_margin(MARGIN_RIGHT) - submenu->get_width(),item_ofs.y+Math::floor(h-submenu->get_height())/2));
				}

				item_ofs.y+=font->get_ascent();
				if (!items[i].separator)
					font->draw(ci,item_ofs+Point2(0,Math::floor((h-font_h)/2.0)),items[i].text,items[i].disabled?font_color_disabled:(i==mouse_over?font_color_hover:font_color));


				if (items[i].accel) {
					//accelerator
					String text = _get_accel_text(items[i].accel);
					item_ofs.x=size.width-style->get_margin(MARGIN_RIGHT)-font->get_string_size(text).width;
					font->draw(ci,item_ofs+Point2(0,Math::floor((h-font_h)/2.0)),text,i==mouse_over?font_color_hover:font_color_accel);

				}

				items[i]._ofs_cache=ofs.y;

				ofs.y+=h;
				
			}
			
		} break;
		case NOTIFICATION_MOUSE_ENTER: {

			grab_focus();
		} break;
		case NOTIFICATION_MOUSE_EXIT: {
		
			if (mouse_over>=0) {
				mouse_over=-1;
				update();
			}
		} break;
	}
}
Example #21
0
ProjectManager::ProjectManager() {

	int margin = get_constant("margin","Dialogs");
	int button_margin = get_constant("button_margin","Dialogs");

	// load settings
	if (!EditorSettings::get_singleton())
		EditorSettings::create();


	set_area_as_parent_rect();
	Panel *panel = memnew( Panel );
	add_child(panel);
	panel->set_area_as_parent_rect();

	VBoxContainer *vb = memnew( VBoxContainer );
	panel->add_child(vb);
	vb->set_area_as_parent_rect(20);


	Label *l = memnew( Label );
	l->set_text(_MKSTR(VERSION_NAME)" - Project Manager");
	l->add_font_override("font",get_font("large","Fonts"));
	l->set_align(Label::ALIGN_CENTER);
	vb->add_child(l);
	l = memnew( Label );
	l->set_text("v"VERSION_MKSTRING);
	//l->add_font_override("font",get_font("bold","Fonts"));
	l->set_align(Label::ALIGN_CENTER);
	vb->add_child(l);
	vb->add_child(memnew(HSeparator));
	vb->add_margin_child("\n",memnew(Control));


	HBoxContainer *tree_hb = memnew( HBoxContainer);
	vb->add_margin_child("Recent Projects:",tree_hb,true);

	PanelContainer *pc = memnew( PanelContainer);
	pc->add_style_override("panel",get_stylebox("bg","Tree"));
	tree_hb->add_child(pc);
	pc->set_h_size_flags(SIZE_EXPAND_FILL);

	scroll = memnew( ScrollContainer );
	pc->add_child(scroll);
	scroll->set_enable_h_scroll(false);

	VBoxContainer *tree_vb = memnew( VBoxContainer);
	tree_hb->add_child(tree_vb);	
	scroll_childs = memnew( VBoxContainer );
	scroll_childs->set_h_size_flags(SIZE_EXPAND_FILL);
	scroll->add_child(scroll_childs);

	//HBoxContainer *hb = memnew( HBoxContainer );
	//vb->add_child(hb);

	Button *open = memnew( Button );
	open->set_text("Edit");
	tree_vb->add_child(open);
	open->connect("pressed", this,"_open_project");
	open_btn=open;

	Button *run = memnew( Button );
	run->set_text("Run");
	tree_vb->add_child(run);
	run->connect("pressed", this,"_run_project");
	run_btn=run;

	tree_vb->add_child(memnew( HSeparator ));

	Button *scan = memnew( Button );
	scan->set_text("Scan");
	tree_vb->add_child(scan);
	scan->connect("pressed", this,"_scan_projects");

	tree_vb->add_child(memnew( HSeparator ));

	scan_dir = memnew( FileDialog );
	scan_dir->set_access(FileDialog::ACCESS_FILESYSTEM);
	scan_dir->set_mode(FileDialog::MODE_OPEN_DIR);
	add_child(scan_dir);
	scan_dir->connect("dir_selected",this,"_scan_begin");


	Button* create = memnew( Button );
	create->set_text("New Project");
	tree_vb->add_child(create);
	create->connect("pressed", this,"_new_project");

	Button* import = memnew( Button );
	import->set_text("Import");
	tree_vb->add_child(import);
	import->connect("pressed", this,"_import_project");


	Button* erase = memnew( Button );
	erase->set_text("Erase");
	tree_vb->add_child(erase);
	erase->connect("pressed", this,"_erase_project");
	erase_btn=erase;


	tree_vb->add_spacer();

	Button * cancel = memnew( Button );
	cancel->set_text("Exit");
	tree_vb->add_child(cancel);
	cancel->connect("pressed", this,"_exit_dialog");


	vb->add_margin_child("\n",memnew(Control));
	vb->add_child(memnew(HSeparator));

	l = memnew( Label );
	String cp;
	cp.push_back(0xA9);
	cp.push_back(0);
	l->set_text(cp+" 2008-2012 Juan Linietsky, Ariel Manzur.");
	l->set_align(Label::ALIGN_CENTER);
	vb->add_child(l);


	erase_ask = memnew( ConfirmationDialog );
	erase_ask->get_ok()->set_text("Erase");
	erase_ask->get_ok()->connect("pressed", this,"_erase_project_confirm");

	add_child(erase_ask);

	OS::get_singleton()->set_low_processor_usage_mode(true);

	npdialog = memnew( NewProjectDialog );
	add_child(npdialog);

	Ref<Theme> theme = memnew( Theme );
	editor_register_icons(theme);
	set_theme(theme);

	npdialog->connect("project_created", this,"_load_recent_projects");
	_load_recent_projects();
	//get_ok()->set_text("Open");
	//get_ok()->set_text("Exit");

}
Example #22
0
void TabContainer::_notification(int p_what) {


    switch(p_what) {


    case NOTIFICATION_DRAW: {

        RID ci = get_canvas_item();
        Ref<StyleBox> panel = get_stylebox("panel");
        Size2 size = get_size();

        if (!tabs_visible) {

            panel->draw(ci, Rect2( 0, 0, size.width, size.height));
            return;
        }



        Ref<StyleBox> tab_bg = get_stylebox("tab_bg");
        Ref<StyleBox> tab_fg = get_stylebox("tab_fg");
        Ref<Texture> incr = get_icon("increment");
        Ref<Texture> decr = get_icon("decrement");
        Ref<Texture> menu = get_icon("menu");
        Ref<Texture> menu_hl = get_icon("menu_hl");
        Ref<Font> font = get_font("font");
        Color color_fg = get_color("font_color_fg");
        Color color_bg = get_color("font_color_bg");

        int side_margin = get_constant("side_margin");
        int top_margin = _get_top_margin();


        Size2 top_size = Size2( size.width, top_margin );



        int w=0;
        int idx=0;
        Vector<int> offsets;
        Vector<Control*> controls;
        int from=0;
        int limit=get_size().width;
        if (popup) {
            top_size.width-=menu->get_width();
            limit-=menu->get_width();
        }

        bool notdone=false;
        last_tab_cache=-1;

        for(int i=0; i<get_child_count(); i++) {

            Control *c = get_child(i)->cast_to<Control>();
            if (!c)
                continue;
            if (c->is_set_as_toplevel())
                continue;
            if (idx<tab_display_ofs) {
                idx++;
                from=idx;
                continue;
            }

            if (w>=get_size().width) {
                buttons_visible_cache=true;
                notdone=true;
                break;
            }

            offsets.push_back(w);
            controls.push_back(c);

            String s = c->has_meta("_tab_name")?String(XL_MESSAGE(String(c->get_meta("_tab_name")))):String(c->get_name());
            w+=font->get_string_size(s).width;
            if (c->has_meta("_tab_icon")) {
                Ref<Texture> icon = c->get_meta("_tab_icon");
                if (icon.is_valid()) {
                    w+=icon->get_width();
                    if (s!="")
                        w+=get_constant("hseparation");

                }
            }

            if (idx==current) {

                w+=tab_fg->get_minimum_size().width;
            } else {
                w+=tab_bg->get_minimum_size().width;
            }

            if (idx<tab_display_ofs) {

            }
            last_tab_cache=idx;

            idx++;
        }


        int ofs;

        switch(align) {

        case ALIGN_LEFT:
            ofs = side_margin;
            break;
        case ALIGN_CENTER:
            ofs = (int(limit) - w)/2;
            break;
        case ALIGN_RIGHT:
            ofs = int(limit) - w - side_margin;
            break;
        };

        tab_display_ofs=0;


        tabs_ofs_cache=ofs;
        idx=0;



        for(int i=0; i<controls.size(); i++) {

            idx=i+from;
            if (current>=from && current<from+controls.size()-1) {
                //current is visible! draw it last.
                if (i==controls.size()-1) {
                    idx=current;
                } else if (idx>=current) {
                    idx+=1;
                }
            }

            Control *c = controls[idx-from];

            String s = c->has_meta("_tab_name")?String(c->get_meta("_tab_name")):String(c->get_name());
            int w=font->get_string_size(s).width;
            Ref<Texture> icon;
            if (c->has_meta("_tab_icon")) {
                icon = c->get_meta("_tab_icon");
                if (icon.is_valid()) {

                    w+=icon->get_width();
                    if (s!="")
                        w+=get_constant("hseparation");

                }
            }


            Ref<StyleBox> sb;
            Color col;

            if (idx==current) {

                sb=tab_fg;
                col=color_fg;
            } else {
                sb=tab_bg;
                col=color_bg;
            }

            int lofs = ofs + offsets[idx-from];

            Size2i sb_ms = sb->get_minimum_size();
            Rect2 sb_rect = Rect2( lofs, 0, w+sb_ms.width, top_margin);


            sb->draw(ci, sb_rect );

            Point2i lpos = sb_rect.pos;
            lpos.x+=sb->get_margin(MARGIN_LEFT);
            if (icon.is_valid()) {

                icon->draw(ci, Point2i( lpos.x, sb->get_margin(MARGIN_TOP)+((sb_rect.size.y-sb_ms.y)-icon->get_height())/2 ) );
                if (s!="")
                    lpos.x+=icon->get_width()+get_constant("hseparation");

            }

            font->draw(ci, Point2i( lpos.x, sb->get_margin(MARGIN_TOP)+((sb_rect.size.y-sb_ms.y)-font->get_height())/2+font->get_ascent() ), s, col );

            idx++;
        }


        if (buttons_visible_cache) {

            int vofs = (top_margin-incr->get_height())/2;
            decr->draw(ci,Point2(limit,vofs),Color(1,1,1,tab_display_ofs==0?0.5:1.0));
            incr->draw(ci,Point2(limit+incr->get_width(),vofs),Color(1,1,1,notdone?1.0:0.5));
        }

        if (popup) {
            int from = get_size().width-menu->get_width();

            if (mouse_x_cache > from)
                menu_hl->draw(get_canvas_item(),Size2(from,0));
            else
                menu->draw(get_canvas_item(),Size2(from,0));
        }

        panel->draw(ci, Rect2( 0, top_size.height, size.width, size.height-top_size.height));

    }
    break;
    case NOTIFICATION_THEME_CHANGED: {
        if (get_tab_count() > 0) {
            call_deferred("set_current_tab",get_current_tab()); //wait until all changed theme
        }
    }
    break;
    }
}
Example #23
0
void ButtonArray::_notification(int p_what) {

    switch(p_what) {
    case NOTIFICATION_MOUSE_EXIT: {
        hover=-1;
        update();
    }
    break;
    case NOTIFICATION_READY: {
        MethodInfo mi;
        mi.name="mouse_sub_enter";

        add_user_signal(mi);

    }
    break;
    case NOTIFICATION_DRAW: {

        Size2 size=get_size();
        Size2 minsize=get_combined_minimum_size();
        Ref<StyleBox> style_normal = get_stylebox("normal");
        Ref<StyleBox> style_selected = get_stylebox("selected");
        Ref<StyleBox> style_focus = get_stylebox("focus");
        Ref<StyleBox> style_hover = get_stylebox("hover");
        Ref<Font> font_normal = get_font("font");
        Ref<Font> font_selected = get_font("font_selected");
        int icon_sep = get_constant("icon_separator");
        int button_sep = get_constant("button_separator");
        Color color_normal = get_color("font_color");
        Color color_selected = get_color("font_color_selected");

        int sep=button_sep;
        int ofs=0;
        int expand=0;

        switch(align) {
        case ALIGN_BEGIN: {

            ofs=0;
        }
        break;
        case ALIGN_CENTER: {

            ofs=Math::floor((size[orientation] - minsize[orientation])/2);
        }
        break;
        case ALIGN_END: {

            ofs=Math::floor((size[orientation] - minsize[orientation]));
        }
        break;
        case ALIGN_FILL: {

            if (buttons.size()>1)
                sep+=Math::floor((size[orientation]- minsize[orientation])/(buttons.size()-1.0));
            ofs=0;
        }
        break;
        case ALIGN_EXPAND_FILL: {

            ofs=0;
            expand=size[orientation] - minsize[orientation];
        }
        break;



        }

        int op_size = orientation==VERTICAL ? size.width : size.height;


        for(int i=0; i<buttons.size(); i++) {

            int ms = buttons[i]._ms_cache;
            int s=ms;
            if (expand>0) {
                s+=expand/buttons.size();
            }
            if(min_button_size != -1 && s < min_button_size) {
                s = min_button_size;
            }

            Rect2 r;
            r.pos[orientation]=ofs;
            r.pos[!orientation]=0;
            r.size[orientation]=s;
            r.size[!orientation]=op_size;

            Ref<Font> f;
            Color c;
            Point2 sbsize;
            Point2 sbofs;
            if (i==selected) {
                draw_style_box(style_selected,r);
                sbsize=style_selected->get_minimum_size();
                sbofs=style_selected->get_offset();
                f=font_selected;
                c=color_selected;
                if (has_focus())
                    draw_style_box(style_focus,r);
            } else {
                if (hover==i)
                    draw_style_box(style_hover,r);
                else if (!flat)
                    draw_style_box(style_normal,r);
                sbsize=style_normal->get_minimum_size();
                sbofs=style_normal->get_offset();
                f=font_normal;
                c=color_normal;
            }

            Size2 ssize = f->get_string_size(buttons[i].text);
            if (buttons[i].icon.is_valid()) {

                ssize.x+=buttons[i].icon->get_width();
            }
            Point2 text_ofs=((r.size-ssize-sbsize)/2.0+Point2(0,f->get_ascent())).floor()+sbofs;
            if (buttons[i].icon.is_valid()) {

                draw_texture(buttons[i].icon,r.pos+Point2(text_ofs.x,Math::floor((r.size.height-buttons[i].icon->get_height())/2.0)));
                text_ofs.x+=buttons[i].icon->get_width()+icon_sep;

            }
            draw_string(f,text_ofs+r.pos,buttons[i].text,c);
            buttons[i]._pos_cache=ofs;
            buttons[i]._size_cache=s;

            ofs+=s;
            ofs+=sep;
        }

    }
    break;
    }
}
Example #24
0
void TabContainer::_input_event(const InputEvent& p_event) {

    if (p_event.type==InputEvent::MOUSE_BUTTON &&
            p_event.mouse_button.pressed &&
            p_event.mouse_button.button_index==BUTTON_LEFT) {

        // clicks
        Point2 pos( p_event.mouse_button.x, p_event.mouse_button.y );

        int top_margin = _get_top_margin();
        if (pos.y>top_margin)
            return; // no click (too far down)

        if (pos.x<tabs_ofs_cache)
            return; // no click (too far left)

        Ref<StyleBox> tab_bg = get_stylebox("tab_bg");
        Ref<StyleBox> tab_fg = get_stylebox("tab_fg");
        Ref<Font> font = get_font("font");
        Ref<Texture> incr = get_icon("increment");
        Ref<Texture> decr = get_icon("decrement");
        Ref<Texture> menu = get_icon("menu");
        Ref<Texture> menu_hl = get_icon("menu_hl");

        if (popup && pos.x>get_size().width-menu->get_width()) {


            emit_signal("pre_popup_pressed");
            Vector2 pp_pos = get_global_pos();
            pp_pos.x+=get_size().width;
            pp_pos.x-=popup->get_size().width;
            pp_pos.y+=menu->get_height();

            popup->set_global_pos( pp_pos );
            popup->popup();;
            return;
        }
        pos.x-=tabs_ofs_cache;

        int idx=0;
        int found=-1;
        bool rightroom=false;

        for(int i=0; i<get_child_count(); i++) {

            Control *c = get_child(i)->cast_to<Control>();
            if (!c)
                continue;
            if (c->is_set_as_toplevel())
                continue;

            if (idx<tab_display_ofs) {
                idx++;
                continue;
            }

            if (idx>last_tab_cache) {
                rightroom=true;
                break;
            }

            String s = c->has_meta("_tab_name")?String(XL_MESSAGE(String(c->get_meta("_tab_name")))):String(c->get_name());
            int tab_width=font->get_string_size(s).width;

            if (c->has_meta("_tab_icon")) {
                Ref<Texture> icon = c->get_meta("_tab_icon");
                if (icon.is_valid()) {
                    tab_width+=icon->get_width();
                    if (s!="")
                        tab_width+=get_constant("hseparation");

                }
            }

            if (idx==current) {

                tab_width+=tab_fg->get_minimum_size().width;
            } else {
                tab_width+=tab_bg->get_minimum_size().width;
            }

            if (pos.x < tab_width) {

                found=idx;
                break;
            }

            pos.x-=tab_width;
            idx++;
        }

        if (buttons_visible_cache) {

            if (p_event.mouse_button.x>get_size().width-incr->get_width()) {
                if (rightroom) {
                    tab_display_ofs+=1;
                    update();
                }
            } else if (p_event.mouse_button.x>get_size().width-incr->get_width()-decr->get_width()) {

                if (tab_display_ofs>0) {
                    tab_display_ofs-=1;
                    update();
                }

            }
        }


        if (found!=-1) {

            set_current_tab(found);
        }
    }

}
Example #25
0
void t_quest_log_window::create_quests_windows()
{
    t_screen_rect           rect;
    t_screen_point          text_background_offset;
    t_screen_point          background_offset;
    t_screen_point          mini_map_offset;
    t_screen_point          frame_offset;
    t_screen_point          origin(0,0);
    t_screen_point          point;
    t_window_ptr            window_ptr;
    t_text_window*          text_window_ptr;
    t_bitmap_layer const*   layer;
    t_bitmap_layer*         exit_marker = m_bitmaps_ptr->find( "marker" );
    std::string             name;
    int i;

    rect = exit_marker->get_rect();
    exit_marker->offset( -rect.top_left() );

    t_bitmap_layer const* text_background = m_bitmaps_ptr->find( "text_background" );
    background_offset = text_background->get_rect().top_left() -
                        m_bitmaps_ptr->find( "quest_1" )->get_rect().top_left();
    background_offset -= m_bitmaps_ptr->find( "text_background" )->get_rect().top_left();

    text_background_offset = m_bitmaps_ptr->find( "quest_text" )->get_rect().top_left() -
                             m_bitmaps_ptr->find( "quest_1" )->get_rect().top_left();

    layer = m_bitmaps_ptr->find( "frame" );
    m_map_frame = new t_bitmap_layer_window( layer, t_screen_point(0, 0), this );
    m_map_frame->set_visible( false );

    frame_offset = layer->get_rect().top_left() -
                   m_bitmaps_ptr->find( "quest_1" )->get_rect().top_left();
    mini_map_offset = m_bitmaps_ptr->find( "mini_map" )->get_rect().top_left() -
                      m_bitmaps_ptr->find( "quest_1" )->get_rect().top_left();

    i=0;
    while ((i<m_data.size()) && (i<k_max_windows))
    {
        i++;
        // Create background layer for text window.
        name = format_string( "quest_%i", i );
        origin = m_bitmaps_ptr->find( name )->get_rect().top_left();
        point = origin + background_offset;
        window_ptr = new t_bitmap_layer_window( text_background, point, this );

        // Create text window.
        point = origin + text_background_offset;

        rect = m_bitmaps_ptr->find( "quest_text" )->get_rect();
        rect -= m_bitmaps_ptr->find( "quest_text" )->get_rect().top_left();
        rect += point;

        text_window_ptr = new t_text_window( get_font( 20 ), rect, this, "", t_pixel_24(0,0,0) );
        text_window_ptr->set_center_horizontal();

        m_text_window_list.push_back( text_window_ptr );

        // Frame points.
        t_screen_point mini_map_point;
        t_screen_point frame_point;

        mini_map_point = origin + mini_map_offset;
        frame_point = origin + frame_offset;

        // Create button holder for mini-map.
        t_button *      map_button_ptr;
        map_button_ptr = new t_button( mini_map_point, this );

        // Create mini-map.
        t_center_map_window *   mini_map_ptr;

        rect = m_bitmaps_ptr->find( "mini_map" )->get_rect();
        rect -= rect.top_left();
        mini_map_ptr = new t_center_map_window( *m_map, rect, m_frame->get_map_window(),
                                                map_button_ptr );

        map_button_ptr->enable( true );
        map_button_ptr->update_size();
        map_button_ptr->set_click_handler( add_2nd_argument( bound_handler( *this, &t_quest_log_window::mini_map_clicked ), (i - 1)));
        m_map_button_list.push_back( map_button_ptr );
        m_mini_map_list.push_back( mini_map_ptr );

        // Frame window.
        layer = m_bitmaps_ptr->find( "frame" );
        window_ptr = new t_bitmap_layer_window( layer, frame_point-layer->get_rect().top_left(), this );
        //m_screen_frame_points.push_back( frame_point );

        // Create teleporter exit marker.
        window_ptr = new t_bitmap_layer_window( exit_marker, t_screen_point(0,0), mini_map_ptr );
        m_marker_window_list.push_back ( window_ptr );
    }

    // Create scrollbar.
    if ( m_data.size() > k_max_windows )
    {
        int scrollbar_limit = 0;
        scrollbar_limit = m_data.size() - k_max_windows;

        rect = m_bitmaps_ptr->find( "scrollbar" )->get_rect();
        m_scrollbar = new t_scrollbar( rect.top_left(), rect.height(), this, 0, 0, true );
        m_scrollbar->set_position( 0 );
        m_scrollbar->set_handler( bound_handler( *this, &t_quest_log_window::scrollbar_move));
        m_scrollbar->set_limits( 0, scrollbar_limit );
    }

    m_current_quest_index = 0;
}
void
display_Temps(int xmin, int ymin)
{
    int x, y;
    int interval = ((grid_sz*3+2)/4)/(S_BINS+2);
    int xmax = xmin+(interval*S_BINS);
    int ymax;
    fastf_t xrange = xmax - xmin;

    /* Avoid page thrashing of frame buffer.			*/
    ymin = adjust_Page(ymin);
    ymax = ymin + interval;

    /* Initialize ir_table if necessary.				*/
    if (! ir_Chk_Table())
	return;

    for (y = ymin; y <= ymax; y++) {
	x = xmin;
	if (fb_seek(fbiop, x, y) == -1) {
	    bu_log("\"%s\"(%d) fb_seek to pixel <%d, %d> failed.\n",
		   __FILE__, __LINE__, x, y
		);
	    return;
	}
	for (; x <= xmax + interval; x++) {
	    fastf_t percent;
	    static RGBpixel *pixel;
	    percent = D_XPOS / xrange;
	    if (D_XPOS % interval == 0) {
		int temp = AMBIENT+percent*RANGE;
		int lgtindex = temp - ir_min;
		pixel = (RGBpixel *) ir_table[(lgtindex < ir_max_index ?
					       lgtindex : ir_max_index)];
		/* this should be an &ir_table...,
		   allowed by ANSI C, but not K&R
		   compilers. */
		(void) fb_wpixel(fbiop, (unsigned char *) black);
	    } else {
		(void) fb_wpixel(fbiop, (unsigned char *) pixel);
	    }
	}
    }
    font = get_font((char *) NULL, bu_log);
    if (font.ffdes == NULL) {
	bu_log("Could not load font.\n");
	fb_flush(fbiop);
	return;
    }
    y = ymin;
    for (x = xmin; x <= xmax; x += interval) {
	char tempstr[4];
	fastf_t percent = D_XPOS / xrange;
	int temp = AMBIENT+percent*RANGE;
	int shrinkfactor = fb_getwidth(fbiop)/grid_sz;
	(void) sprintf(tempstr, "%3d", temp);
	do_line(x+2,
		y+(interval-(12/shrinkfactor))/2,
		tempstr
/*, shrinkfactor*/
	    );
    }
    fb_flush(fbiop);
    return;
}
Example #27
0
Error RichTextLabel::append_bbcode(const String& p_bbcode) {

	int pos = 0;

	List<String> tag_stack;
	Ref<Font> normal_font=get_font("normal_font");
	Ref<Font> bold_font=get_font("bold_font");
	Ref<Font> italics_font=get_font("italics_font");
	Ref<Font> bold_italics_font=get_font("bold_italics_font");
	Ref<Font> mono_font=get_font("mono_font");

	Color base_color=get_color("default_color");

	int indent_level=0;

	bool in_bold=false;
	bool in_italics=false;

	while(pos < p_bbcode.length()) {


		int brk_pos = p_bbcode.find("[",pos);

		if (brk_pos<0)
			brk_pos=p_bbcode.length();

		if (brk_pos > pos) {
			add_text(p_bbcode.substr(pos,brk_pos-pos));
		}

		if (brk_pos==p_bbcode.length())
			break; //nothing else o add

		int brk_end = p_bbcode.find("]",brk_pos+1);

		if (brk_end==-1) {
			//no close, add the rest
			add_text(p_bbcode.substr(brk_pos,p_bbcode.length()-brk_pos));
			break;
		}


		String tag = p_bbcode.substr(brk_pos+1,brk_end-brk_pos-1);


		if (tag.begins_with("/") && tag_stack.size()) {

			bool tag_ok = tag_stack.size() && tag_stack.front()->get()==tag.substr(1,tag.length());



			if (tag_stack.front()->get()=="b")
				in_bold=false;
			if (tag_stack.front()->get()=="i")
				in_italics=false;
			if (tag_stack.front()->get()=="indent")
				indent_level--;


			if (!tag_ok) {

				add_text("[");
				pos++;
				continue;
			}

			tag_stack.pop_front();
			pos=brk_end+1;
			if (tag!="/img")
				pop();

		} else if (tag=="b") {

			//use bold font
			in_bold=true;
			if (in_italics)
				push_font(bold_italics_font);
			else
				push_font(bold_font);
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag=="i") {

			//use italics font
			in_italics=true;
			if (in_bold)
				push_font(bold_italics_font);
			else
				push_font(italics_font);
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag=="code") {

			//use monospace font
			push_font(mono_font);
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag.begins_with("table=")) {

			int columns = tag.substr(6,tag.length()).to_int();
			if (columns<1)
				columns=1;
			//use monospace font
			push_table(columns);
			pos=brk_end+1;
			tag_stack.push_front("table");
		} else if (tag=="cell") {

			push_cell();
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag.begins_with("cell=")) {

			int ratio = tag.substr(6,tag.length()).to_int();
			if (ratio<1)
				ratio=1;
			//use monospace font
			set_table_column_expand(get_current_table_column(),true,ratio);
			push_cell();
			pos=brk_end+1;
			tag_stack.push_front("cell");
		} else if (tag=="u") {

			//use underline
			push_underline();
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag=="s") {

			//use strikethrough (not supported underline instead)
			push_underline();
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag=="center") {

			//use underline
			push_align(ALIGN_CENTER);
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag=="fill") {

			//use underline
			push_align(ALIGN_FILL);
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag=="right") {

			//use underline
			push_align(ALIGN_RIGHT);
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag=="ul") {

			//use underline
			push_list(LIST_DOTS);
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag=="ol") {

			//use underline
			push_list(LIST_NUMBERS);
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag=="indent") {

			//use underline
			indent_level++;
			push_indent(indent_level);
			pos=brk_end+1;
			tag_stack.push_front(tag);

		} else if (tag=="url") {

			//use strikethrough (not supported underline instead)
			int end=p_bbcode.find("[",brk_end);
			if (end==-1)
				end=p_bbcode.length();
			String url = p_bbcode.substr(brk_end+1,end-brk_end-1);
			push_meta(url);

			pos=brk_end+1;
			tag_stack.push_front(tag);

		} else if (tag.begins_with("url=")) {

			String url = tag.substr(4,tag.length());
			push_meta(url);
			pos=brk_end+1;
			tag_stack.push_front("url");
		} else if (tag=="img") {

			//use strikethrough (not supported underline instead)
			int end=p_bbcode.find("[",brk_end);
			if (end==-1)
				end=p_bbcode.length();
			String image = p_bbcode.substr(brk_end+1,end-brk_end-1);

			Ref<Texture> texture = ResourceLoader::load(image,"Texture");
			if (texture.is_valid())
				add_image(texture);

			pos=end;
			tag_stack.push_front(tag);
		} else if (tag.begins_with("color=")) {

			String col = tag.substr(6,tag.length());
			Color color;

			if (col.begins_with("#"))
				color=Color::html(col);
			else if (col=="aqua")
				color=Color::html("#00FFFF");
			else if (col=="black")
				color=Color::html("#000000");
			else if (col=="blue")
				color=Color::html("#0000FF");
			else if (col=="fuchsia")
				color=Color::html("#FF00FF");
			else if (col=="gray" || col=="grey")
				color=Color::html("#808080");
			else if (col=="green")
				color=Color::html("#008000");
			else if (col=="lime")
				color=Color::html("#00FF00");
			else if (col=="maroon")
				color=Color::html("#800000");
			else if (col=="navy")
				color=Color::html("#000080");
			else if (col=="olive")
				color=Color::html("#808000");
			else if (col=="purple")
				color=Color::html("#800080");
			else if (col=="red")
				color=Color::html("#FF0000");
			else if (col=="silver")
				color=Color::html("#C0C0C0");
			else if (col=="teal")
				color=Color::html("#008008");
			else if (col=="white")
				color=Color::html("#FFFFFF");
			else if (col=="yellow")
				color=Color::html("#FFFF00");
			else
				color=base_color;



			push_color(color);
			pos=brk_end+1;
			tag_stack.push_front("color");

		} else if (tag.begins_with("font=")) {

			String fnt = tag.substr(5,tag.length());


			Ref<Font> font = ResourceLoader::load(fnt,"Font");
			if (font.is_valid())
				push_font(font);
			else
				push_font(normal_font);

			pos=brk_end+1;
			tag_stack.push_front("font");


		} else {

			add_text("["); //ignore
			pos=brk_pos+1;

		}
	}

	return OK;
}
Example #28
0
int read_header(void)
{
    char buf[1024];
    char *key, *data;
    int fontsize;
    PSCOLOR color;
    int ret, r, g, b;

    fontsize = 0;
    set_color(&color, 0, 0, 0);

    while (input(2, buf, help)) {
	if (!key_data(buf, &key, &data))
	    continue;

	if (KEY("none")) {
	    PS.do_header = 0;
	    continue;
	}

	if (KEY("file")) {
	    G_strip(data);
	    hdr.fp = fopen(data, "r");
	    if (hdr.fp != NULL)
		hdr.file = G_store(data);
	    continue;
	}

	if (KEY("fontsize")) {
	    fontsize = atoi(data);
	    if (fontsize < 4 || fontsize > 50)
		fontsize = 0;
	    continue;
	}

	if (KEY("color")) {
	    ret = G_str_to_color(data, &r, &g, &b);
            if (ret == 1)
                set_color(&color, r, g, b);
            else if (ret == 2)  /* i.e. "none" */
                /* unset_color(&color); */
                error(key, data, _("Unsupported color request"));
            else
                error(key, data, _("illegal color request")); 

	    continue;
	}

	if (KEY("font")) {
	    get_font(data);
	    hdr.font = G_store(data);
	    continue;
	}
	error(key, data, _("illegal header sub-request"));
    }

    hdr.color = color;
    if (fontsize)
	hdr.fontsize = fontsize;

    return 0;
}
Example #29
0
void RichTextLabel::_input_event(InputEvent p_event) {

	switch(p_event.type) {

		case InputEvent::MOUSE_BUTTON: {

			if (main->first_invalid_line<main->lines.size())
				return;

			const InputEventMouseButton& b = p_event.mouse_button;

			if (b.button_index==BUTTON_LEFT) {

				if (true) {


					if (b.pressed && !b.doubleclick) {
						int line=0;
						Item *item=NULL;

						bool outside;
						_find_click(main,Point2i(b.x,b.y),&item,&line,&outside);

						if (item) {

							Variant meta;
							if (!outside && _find_meta(item,&meta)) {
								//meta clicked

								emit_signal("meta_clicked",meta);
							} else if (selection.enabled) {

								selection.click=item;
								selection.click_char=line;

							}

						}

					} else if (!b.pressed) {

						selection.click=NULL;
					}
				}
			}

			if (b.button_index==BUTTON_WHEEL_UP) {

				if (scroll_active)
					vscroll->set_val( vscroll->get_val()-vscroll->get_page()/8 );
			}
			if (b.button_index==BUTTON_WHEEL_DOWN) {

				if (scroll_active)
					vscroll->set_val( vscroll->get_val()+vscroll->get_page()/8 );
			}
		} break;
		case InputEvent::KEY: {

			const InputEventKey &k=p_event.key;
			if (k.pressed && !k.mod.alt && !k.mod.shift && !k.mod.meta) {
				bool handled=true;
				switch(k.scancode) {
					case KEY_PAGEUP: {

						if (vscroll->is_visible())
							vscroll->set_val( vscroll->get_val() - vscroll->get_page() );
					} break;
					case KEY_PAGEDOWN: {

						if (vscroll->is_visible())
							vscroll->set_val( vscroll->get_val() + vscroll->get_page() );
					} break;
					case KEY_UP: {

						if (vscroll->is_visible())
							vscroll->set_val( vscroll->get_val() - get_font("normal_font")->get_height() );
					} break;
					case KEY_DOWN: {

						if (vscroll->is_visible())
							vscroll->set_val( vscroll->get_val() + get_font("normal_font")->get_height() );
					} break;
					case KEY_HOME: {

						if (vscroll->is_visible())
							vscroll->set_val( 0 );
					} break;
					case KEY_END: {

						if (vscroll->is_visible())
							vscroll->set_val( vscroll->get_max() );
					} break;
					case KEY_INSERT:
					case KEY_C: {

						if (k.mod.command) {
							selection_copy();
						} else {
							handled=false;
						}

					} break;
					default: handled=false;
				}


				if (handled)
					accept_event();
			}

		} break;
		case InputEvent::MOUSE_MOTION: {

			if (main->first_invalid_line<main->lines.size())
				return;

			const InputEventMouseMotion& m = p_event.mouse_motion;

			if (selection.click) {

				int line=0;
				Item *item=NULL;
				_find_click(main,Point2i(m.x,m.y),&item,&line);
				if (!item)
					return; // do not update


				selection.from=selection.click;
				selection.from_char=selection.click_char;

				selection.to=item;
				selection.to_char=line;

				bool swap=false;
				if (selection.from->index > selection.to->index )
					swap=true;
				else if (selection.from->index == selection.to->index) {
					if (selection.from_char > selection.to_char)
						swap=true;
					else if (selection.from_char == selection.to_char) {

						selection.active=false;
						return;
					}
				}

				if (swap) {
					SWAP( selection.from, selection.to );
					SWAP( selection.from_char, selection.to_char );
				}

				selection.active=true;
				update();

			}

		} break;
	}

}
		TITANIUM_PROPERTY_GETTER(ActivityIndicator, font)
		{
			JSObject font = Titanium::UI::Font_to_js(get_context(), get_font());
			return static_cast<JSValue>(font);
		}