Пример #1
0
static void
draw_func (GtkDrawingArea *da,
           cairo_t        *cr,
           int             width,
           int             height,
           gpointer        data)
{
  GtkWidget *widget = GTK_WIDGET (da);
  gint panewidth;
  gint x, y;

  panewidth = width / 2;

  cairo_rectangle (cr, 0, 0, width, height);
  cairo_set_source_rgb (cr, 0.9, 0.9, 0.9);
  cairo_fill (cr);

  x = y = 10;
  draw_horizontal_scrollbar (widget, cr, x, y, panewidth - 20, 30, GTK_STATE_FLAG_NORMAL, &height);
  y += height + 8;
  draw_horizontal_scrollbar (widget, cr, x, y, panewidth - 20, 40, GTK_STATE_FLAG_PRELIGHT, &height);
  y += height + 8;
  draw_horizontal_scrollbar (widget, cr, x, y, panewidth - 20, 50, GTK_STATE_FLAG_ACTIVE|GTK_STATE_FLAG_PRELIGHT, &height);

  y += height + 8;
  draw_text (widget, cr, x,  y, panewidth - 20, 20, "Not selected", GTK_STATE_FLAG_NORMAL);
  y += 20 + 10;
  draw_text (widget, cr, x, y, panewidth - 20, 20, "Selected", GTK_STATE_FLAG_SELECTED);

  x = 10;
  y += 20 + 10;
  draw_check (widget, cr,  x, y, GTK_STATE_FLAG_NORMAL, &width, &height);
  x += width + 10;
  draw_check (widget, cr,  x, y, GTK_STATE_FLAG_CHECKED, &width, &height);
  x += width + 10;
  draw_radio (widget, cr,  x, y, GTK_STATE_FLAG_NORMAL, &width, &height);
  x += width + 10;
  draw_radio (widget, cr, x, y, GTK_STATE_FLAG_CHECKED, &width, &height);
  x = 10;

  y += height + 10;
  draw_progress (widget, cr, x, y, panewidth - 20, 50, &height);

  y += height + 10;
  draw_scale (widget, cr, x, y, panewidth - 20, 75, &height);

  y += height + 20;
  draw_notebook (widget, cr, x, y, panewidth - 20, 160);

  /* Second column */
  x += panewidth;
  y = 10;
  draw_menu (widget, cr, x, y, panewidth - 20, &height);

  y += height + 10;
  draw_menubar (widget, cr, x, y, panewidth - 20, &height);

  y += height + 20;
  draw_spinbutton (widget, cr, x, y, panewidth - 20, &height);

  y += height + 30;
  draw_combobox (widget, cr, x, y, panewidth - 20, FALSE, &height);

  y += height + 10;
  draw_combobox (widget, cr, 10 + panewidth, y, panewidth - 20, TRUE, &height);
}
Пример #2
0
int main(int argc, char **argv)
{
    struct GModule *module;
    struct Option *bg_color_opt, *fg_color_opt, *coords, *fsize, *barstyle,
            *text_placement, *length_opt, *segm_opt, *units_opt, *label_opt,
            *width_scale_opt;
    struct Flag *feet, *no_text, *n_symbol;
    struct Cell_head W;
    double east, north;
    double fontsize;
    int bar_style, text_position, units;
    double length;
    int segm;
    char *label;
    double width_scale;

    /* Initialize the GIS calls */
    G_gisinit(argv[0]);

    module = G_define_module();
    G_add_keyword(_("display"));
    G_add_keyword(_("cartography"));
    module->description = _("Displays a barscale on the graphics monitor.");

    feet = G_define_flag();
    feet->key = 'f';
    feet->description = _("Use feet/miles instead of meters");

    no_text = G_define_flag();
    no_text->key = 't';
    no_text->description = _("Draw the scale bar without text");
    no_text->guisection = _("Text");

    n_symbol = G_define_flag();
    n_symbol->key = 'n';
    n_symbol->description = _("Display north-arrow symbol.");
    n_symbol->guisection = _("Style");

    barstyle = G_define_option();
    barstyle->key = "style";
    barstyle->description = _("Type of barscale to draw");
    barstyle->options =
        "classic,line,solid,hollow,full_checker,part_checker,mixed_checker,tail_checker,up_ticks,down_ticks,both_ticks,arrow_ends";
    barstyle->answer = "classic";
    barstyle->gisprompt = "old,barscale,barscale";
    barstyle->guisection = _("Style");
    G_asprintf((char **)&(barstyle->descriptions),
               "classic;%s;"
               "line;%s;"
               "solid;%s;"
               "hollow;%s;"
               "full_checker;%s;"
               "part_checker;%s;"
               "mixed_checker;%s;"
               "tail_checker;%s;"
               "up_ticks;%s;"
               "down_ticks;%s;"
               "both_ticks;%s;"
               "arrow_ends;%s",
               _("Classic style"),
               _("Line style"),
               _("Solid style"),
               _("Hollow style"),
               _("Full checker style"),
               _("Part checker style"),
               _("Mixed checker style"),
               _("Tail checker style"),
               _("Up ticks style"),
               _("Down ticks style"),
               _("Both ticks style"), _("Arrow ends style"));

    coords = G_define_option();
    coords->key = "at";
    coords->key_desc = "x,y";
    coords->type = TYPE_DOUBLE;
    coords->answer = "0.0,10.0";
    coords->options = "0-100";
    coords->label =
        _("Screen coordinates of the rectangle's top-left corner");
    coords->description = _("(0,0) is lower-left of the display frame");

    length_opt = G_define_option();
    length_opt->key = "length";
    length_opt->key_desc = "integer";
    length_opt->type = TYPE_INTEGER;
    length_opt->answer = "0";
    length_opt->options = "0-";
    length_opt->label = _("Length of barscale in map units");

    units_opt = G_define_option();
    units_opt->key = "units";
    units_opt->description = _("Barscale units to display");
    units_opt->options = "meters, kilometers, feet, miles";

    label_opt = G_define_option();
    label_opt->key = "label";
    label_opt->description = _("Custom label of unit");
    label_opt->type = TYPE_STRING;
    label_opt->guisection = _("Text");

    segm_opt = G_define_option();
    segm_opt->key = "segment";
    segm_opt->type = TYPE_INTEGER;
    segm_opt->answer = "10";
    segm_opt->options = "1-100";
    segm_opt->label = _("Number of segments");
    segm_opt->guisection = _("Style");

    fg_color_opt = G_define_standard_option(G_OPT_C);
    fg_color_opt->label = _("Bar scale and text color");
    fg_color_opt->guisection = _("Colors");

    bg_color_opt = G_define_standard_option(G_OPT_CN);
    bg_color_opt->key = "bgcolor";
    bg_color_opt->answer = "white";
    bg_color_opt->label = _("Background color (drawn behind the bar)");
    bg_color_opt->guisection = _("Colors");

    text_placement = G_define_option();
    text_placement->key = "text_position";
    text_placement->description = _("Text position");
    text_placement->options = "under,over,left,right";
    text_placement->answer = "right";
    text_placement->guisection = _("Text");
    
    width_scale_opt = G_define_option();
    width_scale_opt->key = "width_scale";
    width_scale_opt->type = TYPE_DOUBLE;
    width_scale_opt->required = NO;
    width_scale_opt->answer = "1";
    width_scale_opt->options = "0.5-100";
    width_scale_opt->description = _("Scale factor to change bar width");

    fsize = G_define_option();
    fsize->key = "fontsize";
    fsize->type = TYPE_DOUBLE;
    fsize->required = NO;
    fsize->answer = "12";
    fsize->options = "1-360";
    fsize->description = _("Font size");
    fsize->guisection = _("Text");

     G_option_exclusive(feet, units_opt, NULL);

    if (G_parser(argc, argv))
        exit(EXIT_FAILURE);


    G_get_window(&W);
    if (W.proj == PROJECTION_LL)
        G_fatal_error(_("%s does not work with a latitude-longitude location"),
                      argv[0]);


    north_arrow = n_symbol->answer ? TRUE : FALSE;

    switch (barstyle->answer[0]) {
    case 'c':
        bar_style = STYLE_CLASSIC_BAR;
        break;
    case 'p':
        bar_style = STYLE_PART_CHECKER;
        break;
    case 'f':
        bar_style = STYLE_FULL_CHECKER;
        break;
    case 'm':
        bar_style = STYLE_MIXED_CHECKER;
        break;
    case 't':
        bar_style = STYLE_TAIL_CHECKER;
        break;
    case 'l':
        bar_style = STYLE_THIN_WITH_ENDS;
        break;
    case 's':
        bar_style = STYLE_SOLID_BAR;
        break;
    case 'h':
        bar_style = STYLE_HOLLOW_BAR;
        break;
    case 'u':
        bar_style = STYLE_TICKS_UP;
        break;
    case 'd':
        bar_style = STYLE_TICKS_DOWN;
        break;
    case 'b':
        bar_style = STYLE_TICKS_BOTH;
        break;
    case 'a':
        bar_style = STYLE_ARROW_ENDS;
        break;
    default:
        G_fatal_error(_("Programmer error"));
    }

    switch (text_placement->answer[0]) {
    case 'u':
        text_position = TEXT_UNDER;
        break;
    case 'o':
        text_position = TEXT_OVER;
        break;
    case 'l':
        text_position = TEXT_LEFT;
        break;
    case 'r':
        text_position = TEXT_RIGHT;
        break;
    default:
        G_fatal_error(_("Programmer error"));
    }

    sscanf(coords->answers[0], "%lf", &east);
    sscanf(coords->answers[1], "%lf", &north);


    length = atof(length_opt->answer);
    sscanf(segm_opt->answer, "%d", &segm);

    if (feet->answer == 1){
        use_feet = 1;
        units = U_FEET;
        label = "ft";
    }
    else {
        if (!units_opt->answer)
            units = G_database_unit();
        else
            units = G_units(units_opt->answer);
        switch (units) {
        case U_METERS:
            label = "m";
            break;
        case U_KILOMETERS:
            label = "km";
            break;
        case U_FEET:
            use_feet = 1;
            label = "ft";
            break;
        case U_USFEET:
            use_feet = 1;
            label = "ft";
            break;
        case U_MILES:
            use_feet = 1;
            label = "mi";
            break;
        default:
            units = U_METERS;
            label = "m";
        }
    }

    if (label_opt->answer){
        label = label_opt->answer;
    }

    fontsize = atof(fsize->answer);
    if (no_text->answer)
        fontsize = -1;

    width_scale = atof(width_scale_opt->answer);

    /* Parse and select foreground color */
    fg_color = D_parse_color(fg_color_opt->answer, 0);

    /* Parse and select background color */
    bg_color = D_parse_color(bg_color_opt->answer, 1);
    if (bg_color == 0)
        do_background = FALSE;


    D_open_driver();

    D_setup(0);

    draw_scale(east, north, length, segm, units, label, bar_style, text_position, width_scale, fontsize);

    D_save_command(G_recreate_command());
    D_close_driver();

    exit(EXIT_SUCCESS);
}
Пример #3
0
static void get_values(int init,int kernelVersion)
{
    FILE *file;
    char line[256];
    char tag[32];
    int user,nice,system,idle;
    unsigned long long r_io=0,w_io=0;
    int mem_total=0,mem_free=0,mem_cached=0,mem_buffers=0;
    int swap_total=0,swap_free=0;
    float uptime=0.0;

    file=fopen("/proc/stat","r");
    while(fgets(line,sizeof(line),file)!=NULL) {
	sscanf(line,"%s",tag);
	if(strcmp(tag,"cpu")==0) {
	    sscanf(line,"%s %d %d %d %d",tag,&user,&nice,&system,&idle);
	    break;
	}
    }
    fclose(file);
    if(kernelVersion<KERNEL_VERSION(2,6,0)) {
	getDiskValue24(&r_io,&w_io);
    } else {
	getDiskValue26(&r_io,&w_io);
    }
    file=fopen("/proc/meminfo","r");
    while(fgets(line,sizeof(line),file)!=NULL) {
	sscanf(line,"%s",tag);
	if(strcmp(tag,"MemTotal:")==0) {
	    sscanf(line,"%s %d",tag,&mem_total);
	    continue;
	}
	if(strcmp(tag,"MemFree:")==0) {
	    sscanf(line,"%s %d",tag,&mem_free);
	    continue;
	}
	if(strcmp(tag,"Cached:")==0) {
	    sscanf(line,"%s %d",tag,&mem_cached);
	    continue;
	}
	if(strcmp(tag,"Buffers:")==0) {
	    sscanf(line,"%s %d",tag,&mem_buffers);
	    continue;
	}
	if(strcmp(tag,"SwapTotal:")==0) {
	    sscanf(line,"%s %d",tag,&swap_total);
	    continue;
	}
	if(strcmp(tag,"SwapFree:")==0) {
	    sscanf(line,"%s %d",tag,&swap_free);
	    break;
	}
    }
    fclose(file);

    file=fopen("/proc/uptime","r");
    fscanf(file,"%f",&uptime);
    fclose(file);

    if(init) {
	last.cpu_idle=idle;
	last.cpu_use=user+nice+system;
	last.r_diff_max=1;
	last.r_io=r_io;
	last.w_diff_max=1;
	last.w_io=w_io;
    } else {
	long long diff;
	long long diff1;
	int width;

	/* cpu */
	diff=idle-last.cpu_idle;
	diff1=user+nice+system-last.cpu_use;
	width=diff1*scale_width/(diff+diff1+1);
	last.cpu_idle=idle;
	last.cpu_use=user+nice+system;
	draw_scale(width,cpu_s_x,cpu_s_y);

	/* r_io */
	diff=r_io-last.r_io;
	if(diff>last.r_diff_max) {
	    last.r_diff_max=diff;
	}
	width=abs(diff)*scale_width/last.r_diff_max;
	last.r_io=r_io;
	draw_scale(width,ior_s_x,ior_s_y);
	if(diff && !width) {
	    draw_enable_point(point_read_x,point_read_y);
	} else {
	    draw_disable_point(point_read_x,point_read_y);
	}

	/* w_io */
	diff=w_io-last.w_io;
	if(diff>last.w_diff_max) {
	    last.w_diff_max=diff;
	}
	width=abs(diff)*scale_width/last.w_diff_max;
	last.w_io=w_io;
	draw_scale(width,iow_s_x,iow_s_y);
	if(diff && !width) {
	    draw_enable_point(point_write_x,point_write_y);
	} else {
	    draw_disable_point(point_write_x,point_write_y);
	}

	/* mem */
	if(!mem_total) {
	    width=0;
	} else {
	    if(mem_correction) {
		width=(mem_total-mem_free-mem_cached-mem_buffers)*scale_width/mem_total;
	    } else {
		width=(mem_total-mem_free)*scale_width/mem_total;
	    }
	}
	draw_scale(width,mem_s_x,mem_s_y);

	/* swap */
	if(!swap_total) {
	    width=0;
	} else {
	    width=(swap_total-swap_free)*scale_width/swap_total;
	}
	draw_scale(width,swap_s_x,swap_s_y);

	/* uptime */
	{
	    int day,hour,min,sec;

	    day=(int)uptime/(24*3600);
	    uptime-=day*24*3600;
	    hour=(int)uptime/3600;
	    uptime-=hour*3600;
	    min=(int)uptime/60;
	    uptime-=min*60;
	    sec=uptime;
	    draw_uptime(day,hour,min,sec);
	}
    }
}
Пример #4
0
void draw_HUD(SDL_Renderer* ren)
{
    //Draw the top bar
    SDL_SetRenderDrawColor(ren, 255, 255, 255, 0);
    top_bar.w = window_size_x;
    SDL_RenderFillRect(ren, &top_bar);

    draw_int(ren, font, top_bar_text_color, 20, 0, reqired_power,  "Required: ", " MW");
    draw_int(ren, font, top_bar_text_color, 20, 20, power_avalible, "Avalible: ", " MW");
    draw_int(ren, font, top_bar_text_color, 200, 00, getBalance(), "£", "000");
    draw_int(ren, font, top_bar_text_color, 200, 20, lastBalanceChange, "£", "000");

    draw_int(ren, font, top_bar_text_color, 400, 0, getPopulation(), "Pop: ", "");

    fill_scale_values();
    public_happiness_scale.x = window_size_x-100-80;
    draw_scale(ren, &public_happiness_scale, scale_values.average);

    //Draw the side bar
    if(show_sidebar) {
        SDL_SetRenderDrawColor(ren, 255, 255, 255, 0);
        side_bar.x = window_size_x - side_bar.w;
        SDL_RenderFillRect(ren, &side_bar);
        SDL_Rect scaleBox = {window_size_x-100-5,0,100,fontSizeLarge+2};
        int item_y = side_bar.y+5;

        draw_string(ren, fontLarge, top_bar_text_color, side_bar.x+5, item_y, &_binary_VALUE_TEXT_POLICE_start);
        scaleBox.y = item_y;
        draw_scale(ren, &scaleBox, scale_values.police);

        item_y += fontSizeLarge+2;
        draw_string(ren, fontLarge, top_bar_text_color, side_bar.x+5, item_y, &_binary_VALUE_TEXT_HEALTH_start);
        setColorGoodBad(ren, scale_values.health);
        scaleBox.y = item_y;
        SDL_RenderFillRect(ren, &scaleBox);

        item_y += fontSizeLarge+2;
        draw_string(ren, fontLarge, top_bar_text_color, side_bar.x+5, item_y, &_binary_VALUE_TEXT_EDUCATION_start);
        setColorGoodBad(ren, populationPerSchool() < target_population_per_school);
        scaleBox.y = item_y;
        draw_scale(ren, &scaleBox, scale_values.education);

        item_y += fontSizeLarge+2;
        draw_string(ren, fontLarge, top_bar_text_color, side_bar.x+5, item_y, &_binary_VALUE_TEXT_SHOPPING_start);
        setColorGoodBad(ren, scale_values.shopping);
        scaleBox.y = item_y;
        SDL_RenderFillRect(ren, &scaleBox);

        item_y += fontSizeLarge+2;
        draw_string(ren, fontLarge, top_bar_text_color, side_bar.x+5, item_y, &_binary_VALUE_TEXT_POWER_start);
        scaleBox.y = item_y;
        draw_scale(ren, &scaleBox, scale_values.power);

        item_y += fontSizeLarge+2;
        draw_string(ren, fontLarge, top_bar_text_color, side_bar.x+5, item_y, &_binary_VALUE_TEXT_WASTE_start);
        scaleBox.y = item_y;
        draw_scale(ren, &scaleBox, scale_values.waste);

        item_y += fontSizeLarge+2;
        draw_string(ren, fontLarge, top_bar_text_color, side_bar.x+5, item_y, &_binary_VALUE_TEXT_POLUTION_start);
        scaleBox.y = item_y;
        draw_scale(ren, &scaleBox, scale_values.polution);
    }

    SDL_SetRenderDrawColor(ren, 0, 0, 0, 0);

    SDL_Rect open_menu_button = {window_size_x-30,0,30,30};
    SDL_RenderFillRect(ren, &open_menu_button);

    char* modeText = NULL;
    switch(getMode()) {
        case MODE_BUILD_RESIDENTIAL_1:
            modeText = &_binary_MODE_TEXT_RESIDENTIAL_1_start;
            break;
        case MODE_BUILD_RESIDENTIAL_2:
            modeText = &_binary_MODE_TEXT_RESIDENTIAL_2_start;
            break;
        case MODE_BUILD_ROAD:
            modeText = &_binary_MODE_TEXT_BUILD_ROAD_start;
            break;
        case MODE_BUILD_POWER_GAS:
            modeText = &_binary_MODE_TEXT_BUILD_POWER_GAS_start;
            break;
        case MODE_BUILD_DESTROY:
            modeText = &_binary_MODE_TEXT_DESTROY_start;
            break;
        case MODE_BUILD_RETAIL:
            modeText = &_binary_MODE_TEXT_BUILD_RETAIL_start;
            break;
        case MODE_BUILD_HOSPITAL:
            modeText = &_binary_MODE_TEXT_BUILD_HOSPITAL_start;
            break;
        case MODE_BUILD_POWER_SOLAR:
            modeText = &_binary_MODE_TEXT_BUILD_POWER_SOLAR_start;
            break;
        default:
            break;
    }
    if(modeText != NULL) {
        draw_string(ren, font, top_bar_text_color, 5, window_size_y-15, modeText);
    }
    if(ready_to_place) {
        SDL_SetRenderDrawColor(ren, 255, 255, 255, 0);
        SDL_RenderFillRect(ren, &planned_cost_box);
        draw_int(ren, font, top_bar_text_color, 200, 35, costOfPlannedBuild(),  "(-£", "000)");
    }

    SDL_SetRenderDrawColor(ren, 0, 0, 0, 0);
    draw_menu(ren);

    if(active_emergency()) {
        Point p = {window_size_x-16, 80};
        drawTile(ren, &p, getClip(SPRITE_BUILD_BACKGROUND));
        drawTile(ren, &p, getClip(SPRITE_BUILD_SERVICES_POLICE));
    }
}
Пример #5
0
/*********************************************************************
 *	グラフ表示内の文字を書く.
 *********************************************************************
 */
void draw_AnalogFrame(void)
{
	draw_panel();
	draw_scale();
	draw_wireframe();
}