Exemplo n.º 1
0
MCGAffineTransform view_get_stack_transform(MCStackFullscreenMode p_mode, MCRectangle p_stack_rect, MCRectangle p_screen_rect)
{
	MCGFloat t_scale;
	MCGAffineTransform t_transform;

	switch (p_mode)
	{
	case kMCStackFullscreenModeNone:
		return MCGAffineTransformMakeIdentity();
		
	case kMCStackFullscreenResize:
		return MCGAffineTransformMakeIdentity();

	case kMCStackFullscreenExactFit:
		return MCGAffineTransformMakeScale((MCGFloat)p_screen_rect.width / (MCGFloat)p_stack_rect.width, (MCGFloat)p_screen_rect.height / (MCGFloat)p_stack_rect.height);

	case kMCStackFullscreenLetterbox:
	case kMCStackFullscreenShowAll:
		t_scale = MCMin((MCGFloat)p_screen_rect.width / (MCGFloat)p_stack_rect.width, (MCGFloat)p_screen_rect.height / (MCGFloat)p_stack_rect.height);
		t_transform = MCGAffineTransformMakeTranslation(-(MCGFloat)p_stack_rect.width / 2.0, -(MCGFloat)p_stack_rect.height / 2.0);
		t_transform = MCGAffineTransformPreScale(t_transform, t_scale, t_scale);
		t_transform = MCGAffineTransformPreTranslate(t_transform, (MCGFloat)p_screen_rect.width / 2.0, (MCGFloat)p_screen_rect.height / 2.0);

		return t_transform;

	case kMCStackFullscreenNoBorder:
		t_scale = MCMax((MCGFloat)p_screen_rect.width / (MCGFloat)p_stack_rect.width, (MCGFloat)p_screen_rect.height / (MCGFloat)p_stack_rect.height);
		t_transform = MCGAffineTransformMakeTranslation(-(MCGFloat)p_stack_rect.width / 2.0, -(MCGFloat)p_stack_rect.height / 2.0);
		t_transform = MCGAffineTransformPreScale(t_transform, t_scale, t_scale);
		t_transform = MCGAffineTransformPreTranslate(t_transform, (MCGFloat)p_screen_rect.width / 2.0, (MCGFloat)p_screen_rect.height / 2.0);

		return t_transform;

	case kMCStackFullscreenNoScale:
		// offset so stack is centered in screen
		MCRectangle t_rect;
		t_rect = MCU_center_rect(p_screen_rect, p_stack_rect);
		// IM-2013-12-19: [[ Bug 11590 ]] Adjust for screen rect origins other than 0,0
		return MCGAffineTransformMakeTranslation(t_rect.x - p_screen_rect.x, t_rect.y - p_screen_rect.y);
    default:
        MCUnreachableReturn(MCGAffineTransformMakeIdentity());
	}
}
Exemplo n.º 2
0
void MCStack::view_init(void)
{
	m_view_fullscreen = false;
	m_view_fullscreenmode = kMCStackFullscreenModeDefault;

	m_view_adjusted_stack_rect = m_view_requested_stack_rect = m_view_rect = MCRectangleMake(0, 0, 0, 0);
	m_view_stack_visible_rect = MCRectangleMake(0, 0, 0, 0);
	
	// MW-2011-08-26: [[ TileCache ]] Stacks start off with no tilecache.
	m_view_tilecache = nil;
	m_view_bg_layer_id = 0;
	
	// MW-2011-08-19: [[ Redraw ]] Initialize the view's update region
	m_view_update_region = nil;
	
	m_view_transform = MCGAffineTransformMakeIdentity();
	
	m_view_content_scale = 1.0;

	// IM-2014-01: [[ HiDPI ]] Initialize the view backing surface scale
	m_view_backing_scale = 1.0;
}
Exemplo n.º 3
0
bool MCFontCreate(MCNameRef p_name, MCFontStyle p_style, int32_t p_size, MCFontRef& r_font)
{
	for(MCFont *t_font = s_fonts; t_font != nil; t_font = t_font -> next)
	{
		if (p_name == t_font -> name &&
			p_style == t_font -> style &&
			p_size == t_font -> size)
		{
			t_font -> references += 1;
			r_font = t_font;
			return true;
		}
	}

	MCFontRef self;
	if (!MCMemoryNew(self))
		return false;

	self -> references = 1;
	/* UNCHECKED */ MCNameClone(p_name, self -> name);
	self -> style = p_style;
	self -> size = p_size;

	uint2 t_temp_size;
	t_temp_size = self -> size;
	self -> fontstruct = MCdispatcher -> loadfont(self -> name, t_temp_size, MCFontStyleToTextStyle(self -> style), (self -> style & kMCFontStylePrinterMetrics) != 0);

	// MW-2013-12-04: [[ Bug 11535 ]] Test to see if the font is fixed-width, at least for
	//   Roman script.
    MCGFont t_gfont;
	t_gfont = MCFontStructToMCGFont(self -> fontstruct);
	t_gfont . fixed_advance = 0;

	// We check the width of ' ', i, l, m and w. If they are all the same width
	// we assume the font is monospaced and subsequently set the fixed_advance
	// field to a suitable value.
	MCGFloat t_last_width;
	for(uindex_t i = 0; i < 5; i++)
	{
		unichar_t t_char;
		t_char = (unichar_t)((" ilmw")[i]);
		
		// MM-2014-04-16: [[ Bug 11964 ]] MCGContextMeasurePlatformText prototype updated to take scale. Pass identity.
		MCGFloat t_this_width;
		t_this_width = MCGContextMeasurePlatformText(nil, &t_char, 2, t_gfont, MCGAffineTransformMakeIdentity());
		if (t_this_width == 0.0 ||
			(i != 0 && t_this_width != t_last_width))
		{
			t_last_width = 0;
			break;
		}
		t_last_width = t_this_width;
	}
	self -> fixed_advance = floorf(t_last_width + 0.5);
	
	self -> next = s_fonts;
	s_fonts = self;

	r_font = self;

	return true;
}