Exemple #1
0
void Inputbox_view::Render(const Widget& widget) const
{
	const Inputbox& inputbox = dynamic_cast<const Inputbox&>(widget);

	Vector2 p = widget.Get_position();
	Vector2 s = widget.Get_size();
	ALLEGRO_COLOR text_color = al_map_rgb_f(0, 0, 0);
	ALLEGRO_COLOR bg_color = al_map_rgb_f(1, 1, 1);
	ALLEGRO_COLOR edge_color = al_map_rgb_f(0.5, 0.5, 0.5);

	al_draw_filled_rectangle(p.x, p.y+1, p.x+s.x-1, p.y+s.y, bg_color);
	al_draw_rectangle(p.x, p.y+1, p.x+s.x-1, p.y+s.y, edge_color, 0);

	int y = p.y + 3;
	int x = p.x + 3;
	const Ustring& text = inputbox.Get_text();
	
	if(inputbox.Has_focus())
	{
		int sel_s = inputbox.Get_selection_start();
		int sel_e = inputbox.Get_selection_end();

		int cp_s = font->Get_ustr_width(text.Substring(0, sel_s).Astring());
		int cp_e = font->Get_ustr_width(text.Substring(0, sel_e).Astring());
		int h = al_get_font_line_height(font->Afont());
		if(sel_s != sel_e)
			al_draw_filled_rectangle(x+cp_s-1, y, x+cp_e, y+h, al_map_rgb_f(0.5, 0.5, 1));
		else if(cursor_flash>0)
			al_draw_line(x+cp_e-1, y, x+cp_e, y+h, al_map_rgb_f(0, 0, 0), 0);
	}

	al_draw_ustr(font->Afont(), text_color, x, y, 0, text.Astring());
}
Exemple #2
0
int main(void)
{
   ALLEGRO_DISPLAY *display;
   ALLEGRO_BITMAP *icons[NUM_ICONS];
   ALLEGRO_EVENT_QUEUE *queue;
   int u, v;

   if (!al_init()) {
      abort_example("Could not init Allegro.\n");
   }
   al_install_keyboard();
   al_init_image_addon();

   display = al_create_display(320, 200);
   if (!display) {
      abort_example("Error creating display\n");
   }
   al_clear_to_color(al_map_rgb_f(0, 0, 0));
   al_flip_display();

   /* First icon 16x16: Read from file. */
   icons[0] = al_load_bitmap("data/cursor.tga");
   if (!icons[0]) {
      abort_example("icons.tga not found\n");
   }

   /* Second icon 32x32: Create it. */
   al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
   icons[1] = al_create_bitmap(32, 32);
   al_set_target_bitmap(icons[1]);
   for (v = 0; v < 32; v++) {
      for (u = 0; u < 32; u++) {
         al_put_pixel(u, v, al_map_rgb_f(u / 31.0, v / 31.0, 1));
      }
   }
   al_set_target_backbuffer(display);

   al_set_display_icons(display, NUM_ICONS, icons);

   queue = al_create_event_queue();
   al_register_event_source(queue, al_get_keyboard_event_source());
   al_register_event_source(queue, al_get_display_event_source(display));

   for (;;) {
      ALLEGRO_EVENT event;
      al_wait_for_event(queue, &event);

      if (event.type == ALLEGRO_EVENT_KEY_DOWN &&
            event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
         break;
      }
      if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
         break;
      }
   }

   al_uninstall_system();

   return 0;
}
Exemple #3
0
void mapper_render(void * data)
{
	if(mapper_bg_color == 0)
	{
		al_clear_to_color(al_map_rgb_f(0.0, 0.0, 0.1));
	}
	else
	{
		al_clear_to_color(al_map_rgb_f(0.25, 0.25, 1.0));
	}
	al_hold_bitmap_drawing(true);
	switch(mapper_view)
	{
		case MAPPER_VIEW_TILESET:
		{
			mapper_tileset_render();
			break;
		}
		case MAPPER_VIEW_TILEMAP:
		{
			mapper_tilemap_render();
			break;
		}
		case MAPPER_VIEW_TILE_ANI:
		{
			mapper_tile_ani_render();
			break;
		}
	}
	if(t3f_key[ALLEGRO_KEY_F1])
	{
		mapper_help_render();
	}
	al_hold_bitmap_drawing(false);
}
void Horizontal_paned_view::Render(const Widget& widget) const
{
	const Horizontal_paned& horizontal_paned = dynamic_cast<const Horizontal_paned&>(widget);
	Widget* left = horizontal_paned.Get_left();
	Widget* right = horizontal_paned.Get_right();
	Widget_view* view;
	int clip_x, clip_y, clip_w, clip_h;
	al_get_clipping_rectangle(&clip_x, &clip_y, &clip_w, &clip_h);
	if(left)
	{
		Vector2 p = left->Get_position();
		Vector2 s = left->Get_size();
		al_set_clipping_rectangle(p.x, p.y, s.x, s.y);
		left->Render();
	}
	if(right)
	{
		Vector2 p = right->Get_position();
		Vector2 s = right->Get_size();
		al_set_clipping_rectangle(p.x, p.y, s.x, s.y);
		right->Render();
	}
	al_set_clipping_rectangle(clip_x, clip_y, clip_w, clip_h);

	Vector2 p = widget.Get_position();
	Vector2 s = widget.Get_size();
	float pane = p.x+horizontal_paned.Get_pane_position();
	ALLEGRO_COLOR bg_color = al_map_rgb_f(0.7, 0.7, 0.7);
	ALLEGRO_COLOR edge_color = al_map_rgb_f(0.3, 0.3, 0.3);
	al_draw_filled_rectangle(pane, p.y+1, pane+6, p.y+s.y, bg_color);
	al_draw_rectangle(pane, p.y+1, pane+6, p.y+s.y, edge_color, 0);
	al_draw_line(pane+2, p.y+s.y/2-10, pane+2, p.y+s.y/2+10, edge_color, 0);
	al_draw_line(pane+4, p.y+s.y/2-10, pane+4, p.y+s.y/2+10, edge_color, 0);
}
Exemple #5
0
static void draw_pattern(ALLEGRO_BITMAP *b)
{
   int w = al_get_bitmap_width(b);
   int h = al_get_bitmap_height(b);
   int x, y;
   int format = ALLEGRO_PIXEL_FORMAT_BGR_888;
   ALLEGRO_COLOR light = al_map_rgb_f(1, 1, 1);
   ALLEGRO_COLOR dark = al_map_rgb_f(1, 0.9, 0.8);
   ALLEGRO_LOCKED_REGION *lock;
   lock = al_lock_bitmap(b, format, ALLEGRO_LOCK_WRITEONLY);
   for (y = 0; y < h; y++) {
      for (x = 0; x < w; x++) {
         ALLEGRO_COLOR c = (x + y) & 1 ? light : dark;
         unsigned char r, g, b;
         unsigned char *data = lock->data;
         al_unmap_rgb(c, &r, &g, &b);
         data += y * lock->pitch;
         data += x * 3;
         data[0] = r;
         data[1] = g;
         data[2] = b;
      }
   }
   al_unlock_bitmap(b);
}
Exemple #6
0
void Vertical_paned_view::Render(const Widget& widget) const
{
	const Vertical_paned& vertical_paned = dynamic_cast<const Vertical_paned&>(widget);
	Widget* top = vertical_paned.Get_top();
	Widget* bottom = vertical_paned.Get_bottom();
	Widget_view* view;
	int clip_x, clip_y, clip_w, clip_h;
	al_get_clipping_rectangle(&clip_x, &clip_y, &clip_w, &clip_h);
	if(top)
	{
		Vector2 p = top->Get_position();
		Vector2 s = top->Get_size();
		al_set_clipping_rectangle(p.x, p.y, s.x, s.y);
		top->Render();
	}
	if(bottom)
	{
		Vector2 p = bottom->Get_position();
		Vector2 s = bottom->Get_size();
		al_set_clipping_rectangle(p.x, p.y, s.x, s.y);
		bottom->Render();
	}
	al_set_clipping_rectangle(clip_x, clip_y, clip_w, clip_h);

	Vector2 p = widget.Get_position();
	Vector2 s = widget.Get_size();
	float pane = p.y+vertical_paned.Get_pane_position()+1;
	ALLEGRO_COLOR bg_color = al_map_rgb_f(0.7, 0.7, 0.7);
	ALLEGRO_COLOR edge_color = al_map_rgb_f(0.3, 0.3, 0.3);
	al_draw_filled_rectangle(p.x, pane, p.x+s.x-1, pane+6, bg_color);
	al_draw_rectangle(p.x, pane, p.x+s.x-1, pane+6, edge_color, 0);
	al_draw_line(p.x+s.x/2-10, pane+2, p.x+s.x/2+10, pane+2, edge_color, 0);
	al_draw_line(p.x+s.x/2-10, pane+4, p.x+s.x/2+10, pane+4, edge_color, 0);
}
Exemple #7
0
void Draw_body(b2Body* body, b2Vec2 camera)
{
	float scale = 10;
	b2Vec2 position = scale*body->GetPosition() - camera;
	float32 angle = body->GetAngle();

	al_draw_pixel(position.x, position.y, al_map_rgb_f(1, 0, 0));

	for (b2Fixture* f = body->GetFixtureList(); f; f = f->GetNext())
	{
		b2Shape* shape_base = f->GetShape();
		if(shape_base->GetType() == b2Shape::e_polygon)
		{
			b2PolygonShape& shape = dynamic_cast<b2PolygonShape&>(*shape_base);
			int np = shape.GetVertexCount ();
			b2Vec2 pn = scale*shape.GetVertex(np-1);
			b2Vec2 ps, pe;
			ps.x = cos(angle)*pn.x - sin(angle)*pn.y;
			ps.y = sin(angle)*pn.x + cos(angle)*pn.y;
			for(int i=0; i<np; ++i)
			{
				pn = scale*shape.GetVertex(i);
				pe.x = cos(angle)*pn.x - sin(angle)*pn.y;
				pe.y = sin(angle)*pn.x + cos(angle)*pn.y;
				al_draw_line(position.x+ps.x, position.y+ps.y, position.x+pe.x, position.y+pe.y, al_map_rgb_f(1, 0, 0), 0);
				ps = pe;
			}
		}
		if(shape_base->GetType() == b2Shape::e_circle)
		{
			b2CircleShape& shape = dynamic_cast<b2CircleShape&>(*shape_base);
			al_draw_circle(position.x, position.y, shape.m_radius * scale, al_map_rgb_f(1, 0, 0), 0);
		}
	}
}
static void redraw(void)
{
   ALLEGRO_COLOR color;
   int w = al_get_display_width(display);
   int h = al_get_display_height(display);
   int pw = al_get_bitmap_width(picture);
   int ph = al_get_bitmap_height(picture);
   int th = al_get_font_line_height(font);
   float cx =  (w - pw) * 0.5;
   float cy =  (h - ph) * 0.5;
   ALLEGRO_COLOR white = al_map_rgb_f(1, 1, 1);

   color = al_map_rgb_f(0.8, 0.7, 0.9);
   al_clear_to_color(color);

   color = al_map_rgb(255, 0, 0);
   al_draw_line(0, 0, w, h, color, 0);
   al_draw_line(0, h, w, 0, color, 0);

   al_draw_bitmap(picture, cx, cy, 0);
   
   al_draw_textf(font, white, w / 2, cy + ph, ALLEGRO_ALIGN_CENTRE,
      "Press Space to toggle fullscreen");
   al_draw_textf(font, white, w / 2, cy + ph + th, ALLEGRO_ALIGN_CENTRE,
      "Press Enter to toggle window size");
   al_draw_textf(font, white, w / 2, cy + ph + th * 2, ALLEGRO_ALIGN_CENTRE,
      "Window: %dx%d (%s)",
      al_get_display_width(display), al_get_display_height(display),
      (al_get_display_flags(display) & ALLEGRO_FULLSCREEN_WINDOW) ?
      "fullscreen" : "not fullscreen");
   
   al_flip_display();
}
Exemple #9
0
static void draw(void)
{
   int x, y, offx, offy;
   float c = 1;
   static char logo_text1[] = "Allegro";
   static char logo_text2[] = "";
   /* XXX commented out because the font doesn't contain the characters for
    * anything other than "Allegro 4.2"
    */
   /* static char logo_text2[] = "5.0"; */

   if (progress < 0.5f) {
      c = progress / 0.5f;
      al_clear_to_color(al_map_rgb_f(c, c, c));
   } else {
      if (!already_played_midi) {
         play_music(DEMO_MIDI_INTRO, 0);
         already_played_midi = 1;
      }

      c = 1;
      al_clear_to_color(al_map_rgb_f(c, c, c));

      x = screen_width / 2;
      y = screen_height / 2 - 3 * al_get_font_line_height(demo_font_logo) / 2;

      offx = 0;
      if (progress < 1.0f) {
         offx =
            (int)(al_get_text_width(demo_font_logo, logo_text1) *
                  (1.0f - 2.0f * (progress - 0.5f)));
      }

      demo_textprintf_centre(demo_font_logo, x + 6 - offx,
                           y + 5, al_map_rgba_f(0.125, 0.125, 0.125, 0.25), logo_text1);
      demo_textprintf_centre(demo_font_logo, x - offx, y,
                           al_map_rgba_f(1, 1, 1, 1), logo_text1);

      if (progress >= 1.5f) {
         y += 3 * al_get_font_line_height(demo_font_logo) / 2;
         offy = 0;
         if (progress < 2.0f) {
            offy = (int)((screen_height - y) * (1.0f - 2.0f * (progress - 1.5f)));
         }

         demo_textprintf_centre(demo_font_logo, x + 6,
                              y + 5 + offy, al_map_rgba_f(0.125, 0.125, 0.125, 0.25),
                              logo_text2);
         demo_textprintf_centre(demo_font_logo, x, y + offy,
                              al_map_rgba_f(1, 1, 1, 1), logo_text2);
      }
   }
}
Exemple #10
0
    // Get color of the text color according this song's brainwave information. Ie calm song is different in color than energetic song.
    // Values are relative from 0.0 - 1.0 and 0.0 - 1.0 of their position in the min to max of the channel's avarages of each song.
    ALLEGRO_COLOR getMapColor(float valX, float valY) {

        ALLEGRO_COLOR startPointColor = al_map_rgb_f(0.0, 0.0, 0.0); // This is init color If no bw data is available.
        ALLEGRO_COLOR defPointColor   = al_map_rgb_f(0.2, 0.2, 0.2);

        // Jump to right positions.
        ALLEGRO_COLOR trans1 = getFromColorToColor(startPointColor,getGraphThemeColorOf(bwMeter.PROFILE_CHANNEL_1),valX);
        ALLEGRO_COLOR trans2 = getFromColorToColor(startPointColor,getGraphThemeColorOf(bwMeter.PROFILE_CHANNEL_2),valY);

        ALLEGRO_COLOR endPointColor = al_map_rgb_f(startPointColor.r + trans1.r + trans2.r, startPointColor.g + trans1.g + trans2.g, startPointColor.b + trans1.b + trans2.b);
        endPointColor = al_map_rgb_f(endPointColor.r*(1.0-defPointColor.r)+defPointColor.r,endPointColor.g*(1.0-defPointColor.g)+defPointColor.g,endPointColor.b*(1.0-defPointColor.b)+defPointColor.b);

        return endPointColor;
    }
void Horizontal_slider_view::Render(const Widget& widget) const
{
	const Horizontal_slider& horizontal_slider = dynamic_cast<const Horizontal_slider&>(widget);

	Vector2 p = widget.Get_position();
	Vector2 s = widget.Get_size();
	float pane = p.x+horizontal_slider.Get_pane_position();
	int pane_size = horizontal_slider.Get_pane_size();

	ALLEGRO_COLOR bg_color = al_map_rgb_f(0.7, 0.7, 0.7);
	ALLEGRO_COLOR edge_color = al_map_rgb_f(0.3, 0.3, 0.3);

	al_draw_filled_rectangle(pane, p.y+1, pane+pane_size-1, p.y+s.y, bg_color);
	al_draw_rectangle(pane, p.y+1, pane+pane_size-1, p.y+s.y, edge_color, 0);
}
Exemple #12
0
int yes_no_dialog(const char *text){
    ALLEGRO_EVENT_QUEUE *queue = al_create_event_queue();
    ALLEGRO_EVENT ev;
    int noexit;
    int yes_x, yes_y, no_x, no_y;
    int dw = al_get_bitmap_width(al_get_target_bitmap());
    int dh = al_get_bitmap_height(al_get_target_bitmap());
    int ret=0;
    int bh = 120, bw = 400;
    
    al_register_event_source(queue, al_get_keyboard_event_source());
    al_register_event_source(queue, al_get_mouse_event_source());

    al_clear_to_color(NULL_COLOR);
    al_draw_filled_rectangle((dw - bw)/2, (dh-bh)/2, (dw+bw)/2, (dh+bh)/2, WINDOW_BG_COLOR);
    al_draw_rectangle((dw - bw)/2, (dh-bh)/2, (dw+bw)/2, (dh+bh)/2, WINDOW_BD_COLOR,3);
    
    al_draw_multiline_text(default_font, al_map_rgb_f(1,1,1), dw/2, (dh-bh)/2+20, 360, 18, ALLEGRO_ALIGN_CENTER, text);
    
    yes_x = (dw-bw)/2 + 64;
    yes_y = (dh+bh)/2 - 44;
    no_x = (dw+bw)/2 - 128;
    no_y = (dh+bh)/2 - 44;
    
    al_draw_rectangle(yes_x, yes_y, yes_x+64, yes_y+24, al_map_rgb_f(1,1,1), 1);
    al_draw_rectangle(no_x, no_y, no_x+64, no_y+24, al_map_rgb_f(1,1,1), 1);
    al_draw_text(default_font, al_map_rgb_f(1,1,1), yes_x+32, yes_y+4, ALLEGRO_ALIGN_CENTER, "OK");
    al_draw_text(default_font, al_map_rgb_f(1,1,1), no_x+32, no_y+4, ALLEGRO_ALIGN_CENTER, "Cancel");
    
    al_flip_display();
    
    noexit=1;
    while(noexit){
        al_wait_for_event(queue, &ev);
        if(ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN){
            if( (ev.mouse.x > yes_x) && (ev.mouse.x < yes_x+64) && (ev.mouse.y > yes_y) && (ev.mouse.y < yes_y+24) ){
                ret = 1;
                noexit = 0;
            } else if( (ev.mouse.x > no_x) && (ev.mouse.x < no_x+64) && (ev.mouse.y > no_y) && (ev.mouse.y < no_y+24) ){
                ret = 0; noexit = 0;
            }
        }
        if(ev.type == ALLEGRO_EVENT_KEY_CHAR)
            noexit = 0;
    }
    al_destroy_event_queue(queue);
    return ret;
}
Exemple #13
0
ALLEGRO_COLOR getSpriteColor(t_SpriteWithOffset &sprite, t_unit* creature)
{
	uint32_t dayofLife = creature->birth_year*12*28 + creature->birth_time/1200;
	Block* b = viewedSegment->getBlock(creature->x, creature->y, creature->z);
	ALLEGRO_COLOR output;
	if(sprite.shadeBy == ShadeBodyPart)
	{
		if((!config.skipCreatureTypes) && (!config.skipCreatureTypesEx) && (!config.skipDescriptorColors))
		{
		for(unsigned int j = 0; j<b->creature->nbcolors ; j++)
		{
            t_creaturecaste & caste = contentLoader->Mats->raceEx[creature->race].castes[creature->caste];
            std::vector<t_colormodifier> & colormods =caste.ColorModifier;
			if(colormods[j].part == sprite.bodyPart)
			{
				uint32_t cr_color = colormods[j].colorlist[creature->color[j]];
					if(cr_color < contentLoader->Mats->color.size())
					{
						if(colormods[j].startdate > 0)
						{
							if((colormods[j].startdate <= dayofLife) && (colormods[j].enddate > dayofLife))
							{
								output = al_map_rgb_f(
									contentLoader->Mats->color[cr_color].red,
									contentLoader->Mats->color[cr_color].green,
									contentLoader->Mats->color[cr_color].blue);
								return output;
							}
						}
						else
							output = al_map_rgb_f(
							contentLoader->Mats->color[cr_color].red,
							contentLoader->Mats->color[cr_color].green,
							contentLoader->Mats->color[cr_color].blue);
					}
			}
		}
		return output;
		}
		else return al_map_rgb(255,255,255);
	}
	else if(sprite.shadeBy == ShadeJob)
	{
		return getDfColor(getJobColor(creature->profession));
	}

	return getSpriteColor(sprite, b->material, b->layerMaterial, b->veinMaterial);
}
Exemple #14
0
Engine::Engine(ALLEGRO_DISPLAY *display, Settings *settings, Map *currentMap, ImageLoader *imageLoader)
{
	//init
	display_ = display;
	settings_ = settings;
	currentMap_ = currentMap;
	imageLoader_ = imageLoader;
	finished_ = false;
	running_ = true;
	chosenColor_ = al_map_rgb_f(1,1,1);
	chosenColorText_ = al_map_rgb_f(0,0,0);


	//new used to keep it in memory the state. This needs to be freed when Engine is finished.
	PushNewState(new StateGameMainMenu());
}
Exemple #15
0
	void Map::SetMapHeight(int newmapheight)
	{
		oldMapHeight_ = height_;	
		height_ = newmapheight;

		for(int i = 0; i < width_; i++)
		{
			tiles_[i].resize(height_);	
		}

		int YGREATER = 0;
		int k = 0;
		if(height_ > oldMapHeight_)
		{		
			k = oldMapHeight_;
			YGREATER = 1;
		}

		if(YGREATER == 1)//only do this stuff if new Y is greater then old y
		{
			for (int i = 0; i < width_; i++)
			{
				for (int j = k; j < height_; j++)
				{
					tiles_[i][j].SetColor(al_map_rgb_f(1,1,1));//sets all tiles to grey
					tiles_[i][j].SetTileType(EnumDLL::TILETYPE::EMPTYTILE);
					tiles_[i][j].SetCurrentPosition(i,j);
					tiles_[i][j].SetWidth(1);
					tiles_[i][j].SetHeight(1);
				}
			}
		}
	}
Exemple #16
0
	void Map::SetMapWidth(int newmapwidth)
	{
		oldMapWidth_ = width_;	
		width_ = newmapwidth;
		tiles_.resize(width_);
		int XGREATER = 0;
		int k = 0;
		if(width_ > oldMapWidth_)
		{
			k = oldMapWidth_;
			XGREATER = 1;
		}
		if(XGREATER == 1)//only do this stuff if new x is greater then old x
		{
			for(int i = k; i < width_; i++)
			{
				tiles_[i].resize(height_);	
			}
			for (int i = k; i < width_; i++)
			{
				for (int j = 0; j < height_; j++)
				{
					tiles_[i][j].SetColor(al_map_rgb_f(1,1,1));//sets all tiles to grey
					tiles_[i][j].SetTileType(EnumDLL::TILETYPE::EMPTYTILE);
					tiles_[i][j].SetCurrentPosition(i,j);
					tiles_[i][j].SetWidth(1);
					tiles_[i][j].SetHeight(1);
				}
			}
		}	
	}
Exemple #17
0
int main(void)
{
   if (!al_init()) {
      abort_example("Could not init Allegro.\n");
   }

   open_log_monospace();

   display = al_create_display(WIDTH, HEIGHT);
   if (!display) {
      abort_example("al_create_display failed\n");
   }
   al_clear_to_color(al_map_rgb_f(0, 0, 0));
   al_flip_display();

   if (!al_install_keyboard()) {
      abort_example("al_install_keyboard failed\n");
   }

   event_queue = al_create_event_queue();
   if (!event_queue) {
      abort_example("al_create_event_queue failed\n");
   }

   al_register_event_source(event_queue, al_get_keyboard_event_source());
   al_register_event_source(event_queue, al_get_display_event_source(display));

   main_loop();

   close_log(false);

   return 0;
}
Exemple #18
0
void WPJDirector::Draw()
{
	CalculateInterval();

	// update events
	WPJEvent *pNowEvent = WPJInputUtil::GetSharedInst()->NextTriggedEvent();

	while (pNowEvent != NULL)
	{
		m_pNextScene->RunEvent(pNowEvent);
		pNowEvent = WPJInputUtil::GetSharedInst()->NextTriggedEvent();
	}


	// update scheduler
	m_pScheduler->Update(m_fDeltaTime);

	// update actions
	m_pActionManager->Update(m_fDeltaTime);

	// draw, using visit()
	al_clear_to_color(al_map_rgb_f(0,0,0));
	m_pNextScene->Visit();
	al_flip_display();

	ShowStatus();
}
Exemple #19
0
EditorEngine::EditorEngine(ALLEGRO_DISPLAY *display, Settings *settings, Map *currentMap, AssetLibrary *assetLibrary)
{
	//init
	display_ = display;
	settings_ = settings;
	currentMap_ = currentMap;
	assetLibrary_ = assetLibrary;
	finished_ = false;
	running_ = true;
	chosenColor_ = al_map_rgb_f(1,1,1);
	chosenColorText_ = al_map_rgb_f(0,0,0);


	//new used to keep it in memory the state. This needs to be freed when EditorEngine is finished.
	PushNewState(new StateEditorMainMenu());
}
static void draw(void)
{
   const float sw = al_get_bitmap_width(bmp);
   const float sh = al_get_bitmap_height(bmp);
   const float dw = al_get_bitmap_width(dbuf);
   const float dh = al_get_bitmap_height(dbuf);
   const float dx = dw / 2.0;
   const float dy = dh / 2.0;
   float db_l;
   float db_r;
   float db;
   float scale;
   float disp;

   /* Whatever looks okay. */
   if (rms_l > 0.0 && rms_r > 0.0) {
      db_l = 20 * log10(rms_l / 20e-6);
      db_r = 20 * log10(rms_r / 20e-6);
      db = (db_l + db_r) / 2.0;
      scale = db / 20.0;
      disp = (rms_l + rms_r) * 200.0;
   }
   else {
      db_l = db_r = db = scale = disp = 0.0;
   }

   al_set_target_bitmap(dbuf);
   al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA);
   al_draw_filled_rectangle(0, 0, al_get_bitmap_width(dbuf), al_get_bitmap_height(dbuf),
      al_map_rgba_f(0.8, 0.3, 0.1, 0.06));
   al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA);
   al_draw_tinted_scaled_rotated_bitmap(bmp,
      al_map_rgba_f(0.8, 0.3, 0.1, 0.2),
      sw/2.0, sh/2.0, dx, dy - disp, scale, scale, theta, 0);

   al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
   al_set_target_backbuffer(display);
   al_draw_bitmap(dbuf, 0, 0, 0);

   al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA);
   al_draw_line(10, dh - db_l, 10, dh, al_map_rgb_f(1, 0.6, 0.2), 6);
   al_draw_line(20, dh - db_r, 20, dh, al_map_rgb_f(1, 0.6, 0.2), 6);

   al_flip_display();

   theta -= (rms_l + rms_r) * 0.1;
}
Exemple #21
0
	Image::Image(int id, float r, float g, float b){
		id_ = id;
		
		color_ = al_map_rgb_f(r,g,b);
		
		width_ = 1;
		height_ = 1;
	}
Exemple #22
0
	EditorOverLay::EditorOverLay(Settings *settings, STATES id, AssetLibrary *assetLibrary)
	{
		id_ = id;

		settings_ = settings;
		assetLibrary_ = assetLibrary;

		widthMax_ = 9;
		tileVectorWidthMax_ = 4;

		height_ = settings_->GetDisplayHeight()*Constants::TileSize();

		overLayState_ = StaticDLL::OVERLAYSTATE::OVERLAYOPENED;
		overLayAction_ = StaticDLL::OVERLAYACTIONS::OVERLAYNONE;

		chosenColor_ = al_map_rgb_f(0.8,0.8,0.8);
		currentTilePage_ = 0;

		switch(id_)
		{
			case STATES::TILEIMAGEPICKER:
				imageSetId_ = StaticDLL::IMAGESETS::TILEIMAGESET;
				break;
			case STATES::TILECOLORPICKER:
				imageSetId_ = StaticDLL::IMAGESETS::TILECOLORSET;
				break;
			case STATES::OBJECTIMAGEPICKER:
				imageSetId_ = StaticDLL::IMAGESETS::OBJECTIMAGESET;
				break;
			case STATES::ENEMYPICKER:
				imageSetId_ = StaticDLL::IMAGESETS::ENEMYIMAGESET;
				break;
			case STATES::ITEMPICKER:
				imageSetId_ = StaticDLL::IMAGESETS::ITEMIMAGESET;
				break;
		}

		for(int i = 0; i < assetLibrary_->GetImageSetDictionary().size(); i ++)
		{
			if(assetLibrary_->GetImageSetDictionary()[i]->GetImageSetId() == imageSetId_)
			{
				imageBundleDictionaryId_ = i;
				imageBundleDictionarySize_ = assetLibrary_->GetImageSetDictionary()[i]->GetImageBundleDictionary().size();
				break;
			}
		}


		FormatTiles();



		CreateTileWindow();

		

	}
Exemple #23
0
	void EditorOverLay::CreateTileWindow()
	{
		//Create an arrow object
		tilePickerWindow_ = new ObjectBase();
		tilePickerWindow_->SetCurrentPosition(0, 1);
		tilePickerWindow_->SetWidth(widthMax_);
		tilePickerWindow_->SetHeight(settings_->GetDisplayHeight());
		tilePickerWindow_->SetColor(al_map_rgb_f(0.8,0.8,0.8));
	}
Exemple #24
0
	void EditorOverLay::SetMenuHeader(char *text, double positionX, double positionY)
	{
		menuHeaderItem_ = new ObjectBase();
		menuHeaderItem_->SetText(al_ustr_new(text));
		menuHeaderItem_->SetCurrentPosition(positionX,positionY);
		menuHeaderItem_->SetFont(al_load_font("arial.ttf", Constants::TileSize(), 0));
		menuHeaderItem_->SetColor(al_map_rgb_f(0,0,0));
		menuHeaderItem_->SetWidth(menuHeaderItem_->GetFontWidth());
		menuHeaderItem_->SetHeight(Constants::TileSize());
	}
Exemple #25
0
void drawPause(bool ingame) {
	ALLEGRO_COLOR bg = al_map_rgba(255,255,255,204);
	float l = easeOut(pauseTempo);
	
	//textos
	if (ingame) {
		BLENDALPHA();
		al_draw_filled_rectangle(px(0),py(0),px(1),py(1),al_map_rgba_f(0,0,0,.375*l));
		BLENDDEFAULT();
		drawBox(.5,.5,.4,.5*l,COLOR_HGHL,COLOR_SCND);
		al_draw_text(data.font_Regular37,COLOR_TEXT,px(.5),py(lerp(.5,.26,l)),ALLEGRO_ALIGN_CENTRE,"pause");
		al_draw_text(data.font_Regular52,(selection == -1)?COLOR_HGHL:COLOR_TEXT,px(.5),py(lerp(.5,.34,l)),ALLEGRO_ALIGN_CENTRE,"continuar");
		al_draw_text(data.font_Regular52,(selection == 3)?COLOR_HGHL:COLOR_TEXT,px(.5),py(lerp(.5,.66,l)),ALLEGRO_ALIGN_CENTRE,"sair ao menu");
	} else {
		drawBitmapTinted(data.bitmap_parallax1,al_map_rgb_f(1,1,.8),.5-sinf(animTempo)*.03,.5-cosf(animTempo)*.03,game.idealProp*1.1,1.1,0,0,0);
		l = easeOut((scene.tempo > 0)?(scene.tempo):(1+scene.tempo));
		drawBox(.5,.5,.4,.5*l,COLOR_HGHL,COLOR_SCND);
		al_draw_text(data.font_Regular52,COLOR_TEXT,px(.5),py(lerp(.5,.27,l)),ALLEGRO_ALIGN_CENTRE,"configurações");
		al_draw_text(data.font_Regular52,(selection == 3)?COLOR_HGHL:COLOR_TEXT,px(.5),py(lerp(.5,.66,l)),ALLEGRO_ALIGN_CENTRE,"voltar");
	}
	
	BLENDALPHA();
	if (selection > (ingame?-1:0)) {
		drawSpriteSheetTinted(data.bitmap_keys,al_map_rgba_f(1,1,1,.5),.5,lerp(.5,.2,l)-fabs(sinf(animTempo*16))*.007,1./18,1./18,4,2,4,0,0,0);
	}
	if (selection < 3) {
		drawSpriteSheetTinted(data.bitmap_keys,al_map_rgba_f(1,1,1,.5),.5,lerp(.5,.8,l)+fabs(sinf(animTempo*16))*.007,1./18,1./18,4,2,5,0,0,0);
	}
	if (selection < 0 || selection > 1) {
		drawSpriteSheetTinted(data.bitmap_keys,al_map_rgba_f(1,1,1,.5),.725+fabs(sinf(animTempo*16))*.007,.5,1./18,1./18,4,2,0,0,0,0);
	} else {
		drawSpriteSheetTinted(data.bitmap_keys,al_map_rgba_f(1,1,1,.5),.275-fabs(sinf(animTempo*16))*.007,.5,1./18,1./18,4,2,6,0,0,0);
		drawSpriteSheetTinted(data.bitmap_keys,al_map_rgba_f(1,1,1,.5),.725+fabs(sinf(animTempo*16))*.007,.5,1./18,1./18,4,2,7,0,0,0);
	}
	BLENDDEFAULT();
	
	//sliders
	drawSlider(lerp(.5,.42,l),game.volumeBgm,selection == 0,"volume bgm");
	drawSlider(lerp(.5,.5,l),game.volumeSfx,selection == 1,"volume sfx");
	
	//toggle
	al_draw_text(data.font_Regular52,(selection == 2)?COLOR_HGHL:COLOR_TEXT,px(.5),py(lerp(.5,.58,l)),ALLEGRO_ALIGN_CENTRE,game.showPopups?"desligar tutorial":"ligar tutorial");
	
	//tela de confirmação
	if (confirmTempo > 0) {
		float m = easeOut(confirmTempo);
		BLENDALPHA();
		al_draw_filled_rectangle(px(0),py(0),px(1),py(1),al_map_rgba_f(0,0,0,.375*m));
		BLENDDEFAULT();
		drawBox(.5,.5,.5,.2*m,COLOR_HGHL,COLOR_SCND);
		al_draw_text(data.font_Regular37,COLOR_TEXT,px(.5),py(lerp(.5,.415,m)),ALLEGRO_ALIGN_CENTRE,"tem certeza de que deseja sair?");
		al_draw_text(data.font_Regular52,(selection2 == 0)?COLOR_HGHL:COLOR_TEXT,px(.5),py(lerp(.5,.46,m)),ALLEGRO_ALIGN_CENTRE,"sim");
		al_draw_text(data.font_Regular52,(selection2 == 1)?COLOR_HGHL:COLOR_TEXT,px(.5),py(lerp(.5,.52,m)),ALLEGRO_ALIGN_CENTRE,"nem");
	}
}
Exemple #26
0
	Image::Image(int id, const std::string &file, float r, float g, float b){
		id_ = id;
		
		img_ = al_load_bitmap(file.c_str());
		color_ = al_map_rgb_f(r,g,b);
		
		width_ = 1;
		height_ = 1;
		imgWidth_ = al_get_bitmap_width(img_);
		imgHeight_ = al_get_bitmap_height(img_);
	}
// Funcao que contem os comandos para o desenho das sprites.
void draw_sprite(void)
{
	// Limpa o bitmap de destino e recebe por parametro uma referencia para a struct
	// ALLEGRO_COLOR, que descreve a cor em um dispositivo de forma independente.
	// ALLEGRO_COLOR al_map_rgb(unsigned char r, unsigned char g, unsigned char b)
	// eh a funcao usada para converter uma cor RGB para uma struct ALLEGRO_COLOR.
	al_clear_to_color(al_map_rgb_f(0, 0, 0));

	// Prototipo: void al_draw_bitmap(ALLEGRO_BITMAP *bitmap, float dx, float dy, int flags)
	// Desenha um bitmap sem escala e sem rotacao na posicao (dx,dy) passada por parametro
	al_draw_bitmap(spriteAnimada[currentSprite].sprite, spriteAnimada[currentSprite].x, spriteAnimada[currentSprite].y, 0);
}
Exemple #28
0
static mrb_value
color_map_rgb_f(mrb_state *mrb, mrb_value self)
{
  mrb_float r;
  mrb_float g;
  mrb_float b;
  ALLEGRO_COLOR *c;
  mrb_get_args(mrb, "fff", &r, &g, &b);
  c = mrb_malloc(mrb, sizeof(*c));
  *c = al_map_rgb_f(mrbal_clamp_f(r), mrbal_clamp_f(g), mrbal_clamp_f(b));
  return mrb_obj_value(Data_Wrap_Struct(mrb, mrb_class_ptr(self), &mrbal_color_data_type, c));
}
    void draw(double) override
    {
        m_context->draw_veil();

        al_draw_textf(
            m_context->m_const.menu_font,
            al_map_rgb_f(1, 1, 1),
            m_context->m_const.screen_w / 2,
            m_context->m_const.screen_w / 2,
            ALLEGRO_ALIGN_CENTRE,
            "name: %s",
            m_name.c_str());
    }
Exemple #30
0
void WhiteNoise(struct Game *game) {
	ALLEGRO_BITMAP *bitmap = al_get_target_bitmap();
	al_lock_bitmap(bitmap, ALLEGRO_LOCK_WRITEONLY, 0);
	float val; int width, height;
	width = al_get_bitmap_width(bitmap);
	height = al_get_bitmap_height(bitmap);
	for (int i=0; i < width; i++) {
		for (int j=0; j < height; j++) {
			val = (float)rand()/(float)RAND_MAX;
			al_put_pixel(i, j, al_map_rgb_f(val, val, val));
		}
	}
	al_unlock_bitmap(bitmap);
}