Example #1
0
static void roadmap_layer_reload_internal (void) {

    int i;
    int j;
    int k;
    RoadMapConfigDescriptor descriptor = ROADMAP_CONFIG_ITEM_EMPTY;
    static BOOL initialized = FALSE;
    const char *global_label_color, *global_label_bg_color;
    global_label_color = roadmap_config_get (&RoadMapConfigLabelsColor);
    global_label_bg_color = roadmap_config_get (&RoadMapConfigLabelsBgColor);
    use_new_pens = FALSE;
    for (i = 1; i <= RoadMapCategoryCount; ++i) {
		int max_pens;
        struct roadmap_canvas_category *category = RoadMapCategory + i;
        const char *name = RoadMapDefaultCategoryTable[i-1];
        const char *class_name;
        const char *color[ROADMAP_LAYER_PENS];
        const char *label_color;
		int bg_color;
        int  thickness;
        int  other_pens_length = strlen(name) + 64;
        char *other_pens = malloc(other_pens_length);
        RoadMapClass *p;

        descriptor.category = name;
        descriptor.age = 0;

        /* Retrieve the class of the category. */
        if (!initialized) {
           category->name = name;
           category->visible = 1;
           category->label_visible = 1;
           category->label_pen = NULL;

           descriptor.name = "Class";
           descriptor.reference = NULL;
           roadmap_config_declare ("schema", &descriptor, "", NULL);
           class_name = roadmap_config_get (&descriptor);
           for (p = RoadMapClasses; p->name != NULL; ++p) {
               if (strcasecmp (class_name, p->name) == 0) {
                   p->category[p->count++] = i;
                   category->class_index = (int) (p - RoadMapClasses);
                   break;
               }
           }
        }


        /* Retrieve the category thickness & declutter. */

        descriptor.name     = "Thickness";
        descriptor.reference = NULL;
        if (!initialized)
           roadmap_config_declare ("schema", &descriptor, "1", NULL);
        thickness = category->thickness = roadmap_config_get_integer (&descriptor);
#if !defined (ANDROID) && !defined(J2ME)
        if ( roadmap_screen_is_hd_screen() )
        {
         category->thickness = (int)(category->thickness * roadmap_screen_get_screen_scale() /100);
         thickness = (int)(thickness * roadmap_screen_get_screen_scale() /100);
        }
#endif
        if (!initialized) {
           descriptor.name     = "Declutter";
           descriptor.reference = NULL;
           roadmap_config_declare
                  ("schema", &descriptor, "2024800000", NULL);

           category->declutter = roadmap_config_get_integer (&descriptor);

           descriptor.name     = "LabelDeclutter";
                   descriptor.reference = NULL;
                   roadmap_config_declare
                          ("schema", &descriptor, "-1", NULL);

           category->label_declutter = roadmap_config_get_integer (&descriptor);
           if (category->label_declutter == -1)
              category->label_declutter = category->declutter;
        }

        /* Retrieve the first pen's color (mandatory). */

        descriptor.name = "Color";
        descriptor.reference = NULL;

        if (!initialized)
           roadmap_config_declare ("schema", &descriptor, "black", NULL);
        color[0] = roadmap_config_get (&descriptor);

        /* Retrieve label color (optional) */
        descriptor.name = "LabelColor";
        descriptor.reference = NULL;

        roadmap_config_declare ("schema", &descriptor, "", NULL);
        label_color = roadmap_config_get (&descriptor);


        /* Retrieve the category's other colors (optional). */
        if (!editor_screen_gray_scale())
           max_pens = 2;
        else
           max_pens = ROADMAP_LAYER_PENS;

        for (j = 1; j < max_pens; ++j) {
           int is_new = 0;

           snprintf (other_pens, other_pens_length, "Delta%d", j);

           descriptor.name = strdup(other_pens);
           descriptor.reference = NULL;

           if (!initialized)
              roadmap_config_declare ("schema", &descriptor, "0", &is_new);

           category->delta_thickness[j] =
              roadmap_config_get_integer (&descriptor);
#if !defined (ANDROID) && !defined(J2ME)
           if ( roadmap_screen_is_hd_screen() )
           {
            category->delta_thickness[j] = (int)(category->delta_thickness[j] * roadmap_screen_get_screen_scale() /100);
           }
#endif

           if ((j == 2) && !editor_screen_gray_scale()) break;
           if (!is_new) free ((void *)descriptor.name);

           if (category->delta_thickness[j] == 0) break;

           snprintf (other_pens, other_pens_length, "Color%d", j);

           descriptor.name = strdup(other_pens);
           descriptor.reference = NULL;

           if (!initialized)
              roadmap_config_declare ("schema", &descriptor, "", &is_new);
           color[j] = roadmap_config_get (&descriptor);
           if (!is_new) free ((void *)descriptor.name);

           if (*color[j] == 0) break;
        }
        category->pen_count = j;
        if (j > RoadMapMaxUsedPen) RoadMapMaxUsedPen = j;


        /* Create all necessary pens. */

        for (j=0; j<LAYER_PROJ_AREAS; j++) {
           snprintf (other_pens, other_pens_length, "%d%s", j, name);

           category->pen[j][0] = roadmap_canvas_create_pen(other_pens,use_new_pens);

           roadmap_canvas_set_thickness (category->thickness);

           if (color[0] != NULL && *(color[0]) > ' ') {
              roadmap_canvas_set_foreground (color[0]);
           }
        }

        for (k=0; k<LAYER_PROJ_AREAS; k++)
           for (j = 1; j < category->pen_count; ++j) {

              snprintf (other_pens, other_pens_length, "%d%s%d", k, name, j);
              category->pen[k][j] = roadmap_canvas_create_pen (other_pens, use_new_pens);

              if (category->delta_thickness[j] < 0) {
                 thickness = category->thickness + category->delta_thickness[j];
              } else {
                 thickness = category->delta_thickness[j];
              }

              roadmap_canvas_set_foreground (color[j]);
              if (thickness > 0) {
                 roadmap_canvas_set_thickness (thickness);
              }
           }

        snprintf (other_pens, other_pens_length, "%s_label_pen", name);
        category->label_pen = roadmap_canvas_create_pen (other_pens,use_new_pens);

        if (strlen(label_color) != 0) {
           roadmap_canvas_set_foreground (label_color);
        } else {
           roadmap_canvas_set_foreground (global_label_color);
        }
#ifdef OPENGL
        bg_color = (category->pen_count > 2 ? 1 : 0);
        if (color[bg_color] != NULL && *(color[bg_color]) > ' ') {
				roadmap_canvas_set_background (global_label_bg_color);
        }
#endif //OPENGL

        free (other_pens);
    }

    initialized = TRUE;
}
Example #2
0
static void roadmap_speedometer_after_refresh (void){
   RoadMapGuiPoint image_position;
   RoadMapGuiPoint text_position;
   RoadMapGuiPoint units_position;
   RoadMapGpsPosition pos;
   RoadMapPen speedometer_pen;
   char str[30];
   char unit_str[30];
   int font_size = 20;
   int font_size_units = 10;
   int speed_offset = 6;
   int units_offset = 6;
   int speed;

#ifdef IPHONE_NATIVE
	font_size = 18;
	font_size_units = 8;
#else
   if ( roadmap_lang_rtl() )
      font_size_units--;     // Longer text for units
#endif


   if (SpeedometerImage == NULL){
      return;
   }

   if (gHideSpeedometer){
         after_refresh_callback();
         return;
   }

   if (!roadmap_map_settings_isShowSpeedometer()){
      after_refresh_callback();
      return;
   }

   if (roadmap_screen_is_hd_screen()){
      speed_offset *= 1.5;
      units_offset *= 1.5;
   }
   roadmap_navigate_get_current (&pos, NULL, NULL);
   speed = pos.speed;
   if ((speed == -1) || !roadmap_gps_have_reception()){
      after_refresh_callback();
      return;
   }


   speedometer_pen = roadmap_canvas_create_pen ("speedometer_pen");
   if (roadmap_skin_state() == 1)
      roadmap_canvas_set_foreground(SPEEDOMETER_SPEED_COLOR_NIGHT);
   else
      roadmap_canvas_set_foreground(SPEEDOMETER_SPEED_COLOR_DAY);

   image_position.x = roadmap_canvas_width() - roadmap_canvas_image_width(SpeedometerImage);
   image_position.y = roadmap_canvas_height() - roadmap_canvas_image_height(SpeedometerImage) - roadmap_bar_bottom_height() - gOffset;
   roadmap_canvas_draw_image (SpeedometerImage, &image_position,  0, IMAGE_NORMAL);

   text_position.y = image_position.y + roadmap_canvas_image_height(SpeedometerImage) *.8;
   units_position.y = image_position.y + roadmap_canvas_image_height(SpeedometerImage)*.8;

   if (speed != -1){
      if (!roadmap_gps_is_show_raw()) {
         snprintf (str, sizeof(str), "%3d", roadmap_math_to_speed_unit(speed));
         snprintf (unit_str, sizeof(unit_str), "%s",  roadmap_lang_get(roadmap_math_speed_unit()));
      } else {
         snprintf (str, sizeof(str), "%3d", pos.accuracy);
         snprintf (unit_str, sizeof(unit_str), "%s",  "ac");
      }

      if (ssd_widget_rtl(NULL)){
         text_position.x = roadmap_canvas_width() -speed_offset;
         roadmap_canvas_draw_string_size(&text_position, ROADMAP_CANVAS_BOTTOMRIGHT, font_size, str);

         units_position.x = image_position.x + units_offset;
         roadmap_canvas_draw_string_size(&units_position, ROADMAP_CANVAS_BOTTOMLEFT, font_size_units, unit_str);
      }
      else{
         text_position.x = image_position.x + speed_offset;
         roadmap_canvas_draw_string_size(&text_position, ROADMAP_CANVAS_BOTTOMLEFT, font_size, str);

         units_position.x = roadmap_canvas_width() -units_offset;
         roadmap_canvas_draw_string_size(&units_position, ROADMAP_CANVAS_BOTTOMRIGHT, font_size_units, unit_str);
      }
   }

   after_refresh_callback();
}
Example #3
0
static void draw_objects(BarObjectTable_s *table){
	int font_size;
	int i;
	int state, condition;
	RoadMapGuiPoint TextLocation;
	RoadMapImage image;

	int text_flag = ROADMAP_CANVAS_LEFT|ROADMAP_CANVAS_TOP ;

	for (i=0; i < table->count; i++) {
		RoadMapGuiPoint ObjectLocation;
		RoadMapGuiPoint BgFocusLocation;
		if (table->object[i] == NULL)
			continue;

		if (table->object[i]->condition_fn[0]){
			int j;
			BOOL cond = TRUE;
			for (j=0; j< table->object[i]->num_conditions;j++){
				condition = (*table->object[i]->condition_fn[j]) ();
				if (condition !=  table->object[i]->condition_value[j])
					cond = FALSE;
			}
			if (!cond)
				continue;
		}

		roadmap_bar_pos(table->object[i], &ObjectLocation);
		if (table->object[i]->state_fn) {
			state = (*table->object[i]->state_fn) ();
			if ((state < 0) || (state >= MAX_STATES)){
			}
			else{
				if (table->object[i]->images[state] != NULL){
					if (table->object[i]->image_state == IMAGE_STATE_SELECTED){
						if (table->object[i]->image_selected[state] != NULL){
							image = roadmap_bar_load_image( table->object[i]->name, table->object[i]->image_selected[state] );
							roadmap_canvas_draw_image ( image, &ObjectLocation, 0,IMAGE_NORMAL);
						}
						else{
#ifdef TOUCH_SCREEN
							if (TopBarSelectedBg){
								image = roadmap_bar_load_image( table->object[i]->name, table->object[i]->images[state] );
								BgFocusLocation.x = ObjectLocation.x - (roadmap_canvas_image_width(TopBarSelectedBg) -roadmap_canvas_image_width( image ))/2;
								BgFocusLocation.y = ObjectLocation.y - (roadmap_canvas_image_height(TopBarSelectedBg) -roadmap_canvas_image_height( image ))/4*3;
								roadmap_canvas_draw_image ( TopBarSelectedBg, &BgFocusLocation, 0,IMAGE_NORMAL );
							}
#endif
							image = roadmap_bar_load_image( table->object[i]->name, table->object[i]->images[state] );
							roadmap_canvas_draw_image ( image, &ObjectLocation, 0,IMAGE_NORMAL);
						}
					}
					else{
						image = roadmap_bar_load_image( table->object[i]->name, table->object[i]->images[state] );
						roadmap_canvas_draw_image ( image, &ObjectLocation, 0,IMAGE_NORMAL);
					}
				}
			}
		}
		else{
			if (table->object[i]->image_state == IMAGE_STATE_SELECTED){
				if (table->object[i]->image_selected[0] != NULL){
					image = roadmap_bar_load_image( table->object[i]->name, table->object[i]->image_selected[0] );
					roadmap_canvas_draw_image ( image, &ObjectLocation, 0,IMAGE_NORMAL);
				}
				else{
#ifdef TOUCH_SCREEN
					if (TopBarSelectedBg){
						image = roadmap_bar_load_image( table->object[i]->name, table->object[i]->images[0] );
						BgFocusLocation.x = ObjectLocation.x - (roadmap_canvas_image_width(TopBarSelectedBg) -roadmap_canvas_image_width( image ))/2;
						BgFocusLocation.y = ObjectLocation.y - (roadmap_canvas_image_height(TopBarSelectedBg) -roadmap_canvas_image_height( image ))/4*3;
						roadmap_canvas_draw_image ( TopBarSelectedBg, &BgFocusLocation, 0,IMAGE_NORMAL );
					}
#endif
					image = roadmap_bar_load_image( table->object[i]->name, table->object[i]->images[0] );
					roadmap_canvas_draw_image (image, &ObjectLocation, 0,IMAGE_NORMAL);
				}
			}
			else if (table->object[i]->images[0] )
			{
				image = roadmap_bar_load_image( table->object[i]->name, table->object[i]->images[0] );
				roadmap_canvas_draw_image ( image , &ObjectLocation, 0,IMAGE_NORMAL);
			}
		}

		if (table->object[i]->bar_image_fn){
		   const char *image_name = NULL;
		   image_name = table->object[i]->bar_image_fn->bar_text_fn();
		   if (image_name && *image_name){
		      image = roadmap_res_get (RES_BITMAP, RES_SKIN, image_name );
		      if (image){
		         roadmap_canvas_draw_image ( image , &ObjectLocation, 0,IMAGE_NORMAL);
		      }
		   }
		}

		if (table->object[i]->bar_text){

			if (table->object[i]->font_size != 0)
				font_size = table->object[i]->font_size;
			else
				font_size = 10;

			if (table->object[i]->text_alling != -1){
				text_flag = table->object[i]->text_alling;
			}
			else if (table->object[i]->pos_x < 0){
				text_flag = ROADMAP_CANVAS_RIGHT|ROADMAP_CANVAS_TOP;
			}

			if (!table->object[i]->bar_text->pen) {
				table->object[i]->bar_text->pen =
						roadmap_canvas_create_pen (table->object[i]->bar_text->name, FALSE);
				if (table->object[i]->text_color){
					roadmap_canvas_set_foreground (table->object[i]->text_color);
				}
			} else {
				roadmap_canvas_select_pen (table->object[i]->bar_text->pen);
			}
			if (!table->object[i]->text_color){
				if (roadmap_skin_state())
					roadmap_canvas_set_foreground ("#ffffff");
				else
					roadmap_canvas_set_foreground (table->object[i]->bar_text->default_foreground);
			}


			if (table->object[i]->state_fn) {
				state = (*table->object[i]->state_fn) ();
				if (state >0){
					if (table->object[i]->images[state])
					{
						image = roadmap_bar_load_image( table->object[i]->name, table->object[i]->images[state] );
						TextLocation.x = ObjectLocation.x + roadmap_canvas_image_width( image )/2;
						TextLocation.y = ObjectLocation.y + roadmap_canvas_image_height( image )/2;
					}
					else
						roadmap_bar_pos(table->object[i], &TextLocation);
						roadmap_canvas_draw_string_size (&TextLocation,
							text_flag,
							font_size,(*table->object[i]->bar_text->bar_text_fn)());
				}
			}
			else{
				if (table->object[i]->images[0]){
					image = roadmap_bar_load_image( table->object[i]->name, table->object[i]->images[0] );
					TextLocation.x = ObjectLocation.x + roadmap_canvas_image_width( image )/2;
					TextLocation.y = ObjectLocation.y + roadmap_canvas_image_height( image )/2 -2;
				}
				else
					roadmap_bar_pos(table->object[i], &TextLocation);
				roadmap_canvas_draw_string_size (&TextLocation,
						text_flag,
						font_size,(*table->object[i]->bar_text->bar_text_fn)());
			}
		}
		if (table->object[i]->fixed_text){

			if (table->object[i]->font_size != 0)
				font_size = table->object[i]->font_size;
			else
				font_size = 10;

			if (table->object[i]->text_alling != -1){
				text_flag = table->object[i]->text_alling;
			}
			else if (table->object[i]->pos_x < 0){
				text_flag = ROADMAP_CANVAS_RIGHT|ROADMAP_CANVAS_TOP;
			}

			roadmap_canvas_create_pen (table->object[i]->name, FALSE);
			if (table->object[i]->text_color){
				roadmap_canvas_set_foreground (table->object[i]->text_color);
			}
			else{
				if (roadmap_skin_state())
					roadmap_canvas_set_foreground ("#ffffff");
				else
					roadmap_canvas_set_foreground ("#000000");
			}

			if (table->object[i]->state_fn) {
				state = (*table->object[i]->state_fn) ();
				if (state >0){
					roadmap_bar_pos(table->object[i], &TextLocation);
					roadmap_canvas_draw_string_size (&TextLocation,
							text_flag,
							font_size,table->object[i]->fixed_text);
				}
			}
			else{
				roadmap_bar_pos(table->object[i], &TextLocation);
				roadmap_canvas_draw_string_size (&TextLocation,
						text_flag,
						font_size,table->object[i]->fixed_text);
			}
		}
	}
}
Example #4
0
void draw_objects(BarObjectTable_s *table){
   int font_size;
   int i;
   int state, condition;
   RoadMapGuiPoint TextLocation;
   int text_flag = ROADMAP_CANVAS_LEFT|ROADMAP_CANVAS_TOP ;

	for (i=0; i < table->count; i++) {
    	RoadMapGuiPoint ObjectLocation;
    	if (table->object[i] == NULL)
    		continue;

    	if (table->object[i]->condition_fn[0]){
				int j;
				BOOL cond = TRUE;
				for (j=0; j< table->object[i]->num_conditions;j++){
					condition = (*table->object[i]->condition_fn[j]) ();
    				if (condition !=  table->object[i]->condition_value[j])
    					cond = FALSE;
				}
				if (!cond)
					continue;
    	}

		roadmap_bar_pos(table->object[i], &ObjectLocation);
		if (table->object[i]->state_fn) {
      		state = (*table->object[i]->state_fn) ();
      		if ((state < 0) || (state >= MAX_STATES)){
   			}
   			else{
   				if (table->object[i]->images[state] != NULL){
   					if ((table->object[i]->image_state == IMAGE_STATE_SELECTED) && (table->object[i]->image_selected[state] != NULL))
   						roadmap_canvas_draw_image (table->object[i]->image_selected[state], &ObjectLocation, 0,IMAGE_NORMAL);
   					else
   						roadmap_canvas_draw_image (table->object[i]->images[state], &ObjectLocation, 0,IMAGE_NORMAL);
   				}
   			}
		}
		else{
			if ((table->object[i]->image_state == IMAGE_STATE_SELECTED) && (table->object[i]->image_selected[0] != NULL)){
				roadmap_canvas_draw_image (table->object[i]->image_selected[0], &ObjectLocation, 0,IMAGE_NORMAL);

			}
			else if (table->object[i]->images[0])
	   			roadmap_canvas_draw_image (table->object[i]->images[0], &ObjectLocation, 0,IMAGE_NORMAL);
		}

    	if (table->object[i]->bar_text){

    		if (table->object[i]->font_size != 0)
    			font_size = table->object[i]->font_size;
    		else
    			font_size = 10;

    		if (table->object[i]->text_alling != -1){
    				text_flag = table->object[i]->text_alling;
    		}
    		else if (table->object[i]->pos_x < 0){
    			text_flag = ROADMAP_CANVAS_RIGHT|ROADMAP_CANVAS_TOP;
    		}

    		roadmap_canvas_create_pen (table->object[i]->bar_text->name);
    		if (table->object[i]->text_color){
    			roadmap_canvas_set_foreground (table->object[i]->text_color);
    		}
    		else{
    				roadmap_canvas_set_foreground (table->object[i]->bar_text->default_foreground);
    		}

			if (table->object[i]->state_fn) {
    	  		state = (*table->object[i]->state_fn) ();
      			if (state >0){
      				if (table->object[i]->images[state]){
      					TextLocation.x = ObjectLocation.x + roadmap_canvas_image_width(table->object[i]->images[state])/2;
      					TextLocation.y = ObjectLocation.y + roadmap_canvas_image_height(table->object[i]->images[state])/2;
      				}
      				else
						roadmap_bar_pos(table->object[i], &TextLocation);
  						roadmap_canvas_draw_string_size (&TextLocation,
       			    			                    text_flag,
           			    			                font_size,(*table->object[i]->bar_text->bar_text_fn)());
      			}
			}
			else{
				if (table->object[i]->images[0]){
      				TextLocation.x = ObjectLocation.x + roadmap_canvas_image_width(table->object[i]->images[0])/2;
      				TextLocation.y = ObjectLocation.y + roadmap_canvas_image_height(table->object[i]->images[0])/2 -2;
				}
				else
					roadmap_bar_pos(table->object[i], &TextLocation);
  					roadmap_canvas_draw_string_size (&TextLocation,
       		    				                    text_flag,
       			    				                font_size,(*table->object[i]->bar_text->bar_text_fn)());
			}
    	}
    	if (table->object[i]->fixed_text){

    		if (table->object[i]->font_size != 0)
    			font_size = table->object[i]->font_size;
    		else
    			font_size = 10;

    		if (table->object[i]->text_alling != -1){
    				text_flag = table->object[i]->text_alling;
    		}
    		else if (table->object[i]->pos_x < 0){
    			text_flag = ROADMAP_CANVAS_RIGHT|ROADMAP_CANVAS_TOP;
    		}

    		roadmap_canvas_create_pen (table->object[i]->name);
    		if (table->object[i]->text_color){
    			roadmap_canvas_set_foreground (table->object[i]->text_color);
    		}
    		else{
    			if (roadmap_skin_state())
					roadmap_canvas_set_foreground ("#ffffff");
				else
    				roadmap_canvas_set_foreground ("#000000");
    		}

			if (table->object[i]->state_fn) {
    	  		state = (*table->object[i]->state_fn) ();
      			if (state >0){
						roadmap_bar_pos(table->object[i], &TextLocation);
  						roadmap_canvas_draw_string_size (&TextLocation,
       			    			                    text_flag,
           			    			                font_size,table->object[i]->fixed_text);
      			}
			}
			else{
					roadmap_bar_pos(table->object[i], &TextLocation);
  					roadmap_canvas_draw_string_size (&TextLocation,
       		    				                    text_flag,
       			    				                font_size,table->object[i]->fixed_text);
			}
    	}
    }
}