Exemplo n.º 1
0
// MW-2011-09-23: Ensures the buffering state is consistent with current flags
//   and state.
void MCPlayer::syncbuffering(MCContext *p_dc)
{
	bool t_should_buffer;
	
	// MW-2011-09-13: [[ Layers ]] If the layer is dynamic then the player must be buffered.
	t_should_buffer = getstate(CS_SELECTED) || getflag(F_ALWAYS_BUFFER) || getstack() -> getstate(CS_EFFECT) || (p_dc != nil && p_dc -> gettype() != CONTEXT_TYPE_SCREEN) || !MCModeMakeLocalWindows() || layer_issprite();
    
    // MW-2014-04-24: [[ Bug 12249 ]] If we are not in browse mode for this object, then it should be buffered.
    t_should_buffer = t_should_buffer || getstack() -> gettool(this) != T_BROWSE;
}
Exemplo n.º 2
0
void pop()
{
	stack *p=getstack(stacknum);
	switch(p->opsign){
	case ADD:
		result+=p->num;
		break;
	case SUB:
		result=p->num-result;
		break;
	case MUL:
		result*=p->num;
		break;
	case DIV:
		result=p->num/result;
		break;
	case POW:
		result=(float)pow(p->num,result);
		break;
	case FACT:
		result=fact((long)result);
		break;
	case 0:
		break;
	}
	if(stacknum>1) delete p;
	stacknum--;
}
Exemplo n.º 3
0
Boolean MCEPS::mup(uint2 which)
{
	if (!(state & CS_MFOCUSED))
		return False;
	state &= ~CS_MFOCUSED;
	switch (which)
	{
	case Button1:
		switch (getstack()->gettool(this))
		{
		case T_BROWSE:
			if (MCU_point_in_rect(rect, mx, my))
				message_with_args(MCM_mouse_up, "1");
			break;
		case T_POINTER:
			end();
			break;
		case T_HELP:
			help();
			break;
		default:
			return False;
		}
		break;
	case Button2:
	case Button3:
		if (MCU_point_in_rect(rect, mx, my))
			message_with_args(MCM_mouse_up, which);
		break;
	}
	return True;
}
Exemplo n.º 4
0
Boolean MCColors::mfocus(int2 x, int2 y)
{
	if (!(flags & F_VISIBLE || MCshowinvisibles))
		return False;
	if (state & CS_MOVE || state & CS_SIZE)
		return MCControl::mfocus(x, y);
	mx = x;
	my = y;
	if (MCU_point_in_rect(rect, x, y))
	{
		switch (getstack()->gettool(this))
		{
		case T_BROWSE:
		case T_POINTER:
			return True;
		default:
			return False;
		}
	}
	else
		if (state & CS_MFOCUSED)
			return True;
		else
			return False;
}
Exemplo n.º 5
0
void MCCard::layer_setviewport(int32_t p_x, int32_t p_y, int32_t p_width, int32_t p_height)
{
	MCTileCacheRef t_tilecache;
	t_tilecache = getstack() -> gettilecache();

	// Notify any tilecache of the changes.
	if (t_tilecache != nil)
		MCTileCacheSetViewport(t_tilecache, MCU_make_rect(p_x, p_y, p_width, p_height));

	// Get the current rect, before updating it.
	MCRectangle t_old_rect;
	t_old_rect = rect;
	
	// Update the rect.
	resize(p_width, p_height);
	
	// Add the rects to the update region.

	// MW-2012-05-01: [[ Bug 10157 ]] If the card has a border then add the whole card
	//   rect to the update region; otherwise just add the exposed rects.
	if (!getflag(F_SHOW_BORDER))
	{
		if (p_width > t_old_rect.width)
			layer_dirtyrect(MCU_make_rect(t_old_rect.width, 0, p_width - t_old_rect.width, p_height));
		if (p_height > t_old_rect.height)
			layer_dirtyrect(MCU_make_rect(0, t_old_rect.height, p_width, p_height - t_old_rect.height));
	}
	else
		layer_dirtyrect(rect);
}
Exemplo n.º 6
0
Boolean MCEPS::mdown(uint2 which)
{
	if (state & CS_MFOCUSED)
		return False;
	state |= CS_MFOCUSED;
	switch (which)
	{
	case Button1:
		switch (getstack()->gettool(this))
		{
		case T_BROWSE:
			message_with_valueref_args(MCM_mouse_down, MCSTR("1"));
			break;
		case T_POINTER:
			start(True);
			break;
		case T_HELP:
			break;
		default:
			return False;
		}
		break;
	case Button2:
	case Button3:
		message_with_args(MCM_mouse_down, which);
		break;
	}
	return True;
}
Exemplo n.º 7
0
Boolean MCColors::mup(uint2 which, bool p_release)
{
	if (!(state & CS_MFOCUSED))
		return False;
	state &= ~CS_MFOCUSED;
	switch (which)
	{
	case Button1:
		switch (getstack()->gettool(this))
		{
		case T_BROWSE:
			message_with_valueref_args(MCM_mouse_up, MCSTR("1"));
			break;
		case T_POINTER:
			end(true, p_release);
			break;
		default:
			return False;
		}
		break;
	case Button2:
	case Button3:
		message_with_args(MCM_mouse_up, which);
		break;
	}
	return True;
}
Exemplo n.º 8
0
void checkpthat(TString fnameevt, TString filename, TString prefix, TString jtptvar)
{
  TFile *f = new TFile(fnameevt);
  auto nt = (TTree *)f->Get("nt");

  auto h = geth(prefix+"mcpthat", 80, 0, 400);
  nt->Project(h->GetName(),"pthat","");


  int minbin = nt->GetMinimum("pthatbin");
  int maxbin = nt->GetMaximum("pthatbin");
  //assumes ints between min and max

  int N = maxbin-minbin+1;

  vector<TString> pthatcuts;
  pthatcuts = {"pthat>30 && pthat<50","pthat>50 && pthat<80","pthat>80 && pthat<120","pthat>120"};
  auto hs = getstack(nt, prefix+"mcpthatstack","pthat",pthatcuts,80,0,400);
  hs->SetMinimum(1E-2);

  fout->cd();
  hs->Write();
  h->Write();

  f->Close();

  f = new TFile(filename);
  nt = (TTree *)f->Get("nt");

  auto hj = geth(prefix+"mcjtpt", 80, 0, 400);
  nt->Project(hj->GetName(),jtptvar,"weight*(subid==0)",jtptvar);

  
  vector<TString> jtptcuts;
  jtptcuts = {"pthat>30 && pthat<50 && subid==0","pthat>50 && pthat<80 && subid==0","pthat>80 && pthat<120 && subid==0","pthat>120 && subid==0"};
  //  for (int i=0;i<N;i++) jtptcuts.push_back(Form("pthatbin==%d",i));
  auto hsjtpt = getstack(nt, prefix+"mcjtptstack",jtptvar,jtptcuts,80,0,400);
  hsjtpt->SetMinimum(1E-2);

  fout->cd();
  hsjtpt->Write();
  hj->Write();
  //  fout->Write();
  
  f->Close();
}
Exemplo n.º 9
0
Boolean MCPlayer::mfocus(int2 x, int2 y)
{
	if (!(flags & F_VISIBLE || showinvisible())
        || (flags & F_DISABLED && getstack()->gettool(this) == T_BROWSE))
		return False;
    
	return MCControl::mfocus(x, y);
}
Exemplo n.º 10
0
void MCCard::layer_selectedrectchanged(const MCRectangle& p_old_rect, const MCRectangle& p_new_rect)
{
	MCTileCacheRef t_tilecache;
	t_tilecache = getstack() -> gettilecache();

	if (t_tilecache != nil)
		MCTileCacheReshapeScenery(t_tilecache, m_fg_layer_id, p_old_rect, p_new_rect);

	layer_dirtyrect(p_old_rect);
	layer_dirtyrect(p_new_rect);
}
Exemplo n.º 11
0
void MCButton::SetMenuName(MCExecContext& ctxt, MCNameRef p_name)
{
	freemenu(False);
	MCValueAssign(menuname, p_name);

	if (opened)
	{
		if (findmenu(true) && menu != nil)
			menu->installaccels(getstack());
	}
}
Exemplo n.º 12
0
void MCCard::layer_added(MCControl *p_control, MCObjptr *p_previous, MCObjptr *p_next)
{
	MCTileCacheRef t_tilecache;
	t_tilecache = getstack() -> gettilecache();

	// Add the rects to the update region (for clarity, would prefer this at the end
	// but there is 'return' fall through in the rest :-( ).
	layer_dirtyrect(p_control -> geteffectiverect());
	
	// Notify any tilecache of the changes.
	if (t_tilecache != nil)
	{
		// Reset all the layer's attributes to defaults, including the layer id.
		p_control -> layer_resetattrs();

		// Recompute the control's attributes.
		p_control -> layer_computeattrs(true);

		// If the control is on a dynamic layer there is nothing to do (sprites will
		// be created implicitly at first render).
		if (p_control -> layer_issprite())
			return;

		// If the control is not being added between two existing layers then there
		// is nothing to do.
		if (p_previous == nil || p_next == nil)
			return;

		// If the previous (layer below) objptr has no id, then there is nothing to do
		// also. This will only occur if only new layers have been added above,
		// or if no rendering has been done yet.
		uint32_t t_before_layer_id;
		t_before_layer_id = p_previous -> getref() -> layer_getid();
		if (t_before_layer_id == 0)
			return;

		// MW-2013-06-21: [[ Bug 10974 ]] If the previous layer is a sprite then this layer
		//   will change the lower limit of the scenery layers above, thus there is
		//   nothing to do.
		if (p_previous -> getref() -> layer_issprite())
			return;
		
		// Now insert the scenery.
		MCTileCacheInsertScenery(t_tilecache, t_before_layer_id, p_control -> geteffectiverect());

		// Finally, set the id of the layer to that of the one before. This causes
		// the layer to be treated 'as one' with that layer until a redraw is done.
		// This means that any subsequent updates to the rect of the new layer will
		// appropriately flush the tiles in the cache.
		p_control -> layer_setid(t_before_layer_id);
	}
}
Exemplo n.º 13
0
Boolean MCPlayer::mdown(uint2 which)
{
	if (state & CS_MFOCUSED || flags & F_DISABLED)
		return False;
	if (state & CS_MENU_ATTACHED)
		return MCObject::mdown(which);
	state |= CS_MFOCUSED;
	if (flags & F_TRAVERSAL_ON && !(state & CS_KFOCUSED))
		getstack()->kfocusset(this);
	switch (which)
	{
        case Button1:
            switch (getstack()->gettool(this))
		{
            case T_BROWSE:
                if (message_with_valueref_args(MCM_mouse_down, MCSTR("1")) == ES_NORMAL)
                    return True;
                break;
            case T_POINTER:
            case T_PLAYER:  //when the movie object is in editing mode
                start(True); //starting draggin or resizing
                playpause(True);  //pause the movie
                break;
            case T_HELP:
                break;
            default:
                return False;
		}
            break;
		case Button2:
            if (message_with_valueref_args(MCM_mouse_down, MCSTR("2")) == ES_NORMAL)
                return True;
            break;
		case Button3:
            message_with_valueref_args(MCM_mouse_down, MCSTR("3"));
            break;
	}
	return True;
}
Exemplo n.º 14
0
void push(char opsign)
{
	stack *p=getstack(stacknum);
	if(stacknum>0) p=(p->pnext=new stack);
	p->bracket=bracket;
	if(string[point]=='('){
		++bracket;
		point++;
	}
	p->num=result;
	p->opsign=opsign;
	stacknum++;
}
Exemplo n.º 15
0
Boolean MCMagnify::mfocus(int2 x, int2 y)
{
	if (MCmagimage)
	{
		if (!inside)
		{
			getstack()->setcursor(MCmagimage->getstack()->getcursor(), True);
			inside = True;
		}
		return MCmagimage->magmfocus(x, y);
	}
	return False;
}
Exemplo n.º 16
0
Boolean MCPlayer::mup(uint2 which, bool p_release) //mouse up
{
	if (!(state & CS_MFOCUSED))
		return False;
	if (state & CS_MENU_ATTACHED)
		return MCObject::mup(which, p_release);
	state &= ~CS_MFOCUSED;
	if (state & CS_GRAB)
	{
		ungrab(which);
		return True;
	}
	switch (which)
	{
        case Button1:
            switch (getstack()->gettool(this))
		{
            case T_BROWSE:
                if (!p_release && MCU_point_in_rect(rect, mx, my))
                    message_with_valueref_args(MCM_mouse_up, MCSTR("1"));
                else
                    message_with_valueref_args(MCM_mouse_release, MCSTR("1"));
                
                break;
            case T_PLAYER:
            case T_POINTER:
                end(true, p_release);       //stop dragging or moving the movie object, will change controller size
                break;
            case T_HELP:
                help();
                break;
            default:
                return False;
		}
            break;
        case Button2:
        case Button3:
            if (!p_release && MCU_point_in_rect(rect, mx, my))
                message_with_args(MCM_mouse_up, which);
            else
                message_with_args(MCM_mouse_release, which);
            break;
	}
	return True;
}
Exemplo n.º 17
0
void MCButton::GetStyle(MCExecContext& ctxt, intenum_t& r_style)
{
	uint4 t_style;
	t_style = getstyleint(flags);

	if (t_style == F_MENU && getstack() -> hcaddress())
		r_style = kMCButtonStylePopup;
	else if (F_ROUNDRECT <= t_style && t_style <= F_RECTANGLE)
		r_style = (MCInterfaceButtonStyle)t_style;
	else if (!(flags & F_OPAQUE))
		r_style = kMCButtonStyleTransparent;
	else if (flags & F_SHADOW)
		r_style = kMCButtonStyleShadow;
	else if (!(flags & F_SHOW_BORDER))
		r_style = kMCButtonStyleShowBorder;
	else
		r_style = kMCButtonStyleStandard;
}
Exemplo n.º 18
0
void MCControl::layer_contentoriginchanged(int32_t p_dx, int32_t p_dy)
{
	if (!opened)
		return;

	if (!layer_isscrolling())
		return;

	// If the layer id is 0 then return.
	if (m_layer_id == 0)
		return;

	// Fetch the tilecache we are using.
	MCTileCacheRef t_tilecache;
	t_tilecache = getstack() -> gettilecache();

	// Scroll the sprite - note that this method is only called if
	// layer_isscrolling() is true, which is only possible if we have a tilecache.
	MCTileCacheScrollSprite(t_tilecache, m_layer_id, p_dx, p_dy);
}
Exemplo n.º 19
0
void MCControl::layer_dirtycontentrect(const MCRectangle& p_updated_rect, bool p_update_card)
{
	if (MCU_empty_rect(p_updated_rect))
		return;

	MCRectangle t_content_rect;
	t_content_rect = layer_getcontentrect();
	
	MCTileCacheRef t_tilecache;
	t_tilecache = getstack() -> gettilecache();

	// Note that this method is only called if layer_isscrolling() is true, which is only
	// possible if we have a tilecache.
	if (m_layer_id != 0)
		MCTileCacheUpdateSprite(t_tilecache, m_layer_id, MCU_offset_rect(p_updated_rect, -t_content_rect . x, -t_content_rect . y));
		
	// Add the rect to the update region - but only if instructed (update_card will be
	// false if the object was invisible).
	if (p_update_card)
		static_cast<MCCard *>(parent) -> layer_dirtyrect(MCU_intersect_rect(p_updated_rect, geteffectiverect()));
}
Exemplo n.º 20
0
void MCImage::setframe(int32_t p_newframe)
{
	// MW-2013-03-12: [[ Bug ]] Make sure we check we have a parent (an MCImage can have its frame set on
	//   startup via the templateImage which has no parent).
	MCStack *t_stack;
	t_stack = getstack();
	if (t_stack != nil && t_stack->getstate(CS_EFFECT))
		return;

	uindex_t t_framecount = 0;
	if (m_rep != nil)
		t_framecount = m_rep->GetFrameCount();

	// IM-2013-03-11: [[ BZ 10723 ]] if there is no image data or there is only one frame then currentframe should be zero
	if (t_framecount <= 1)
	{
		currentframe = 0;
		return;
	}

	if (p_newframe < 0)
		p_newframe = 0;
	else if (p_newframe >= t_framecount)
		p_newframe = t_framecount - 1;

	if (p_newframe == currentframe)
		return;

	currentframe = p_newframe;

	notifyneeds(false);

	// MW-2011-08-18: [[ Layers ]] Invalidate the whole object.
	// MW-2011-11-15: [[ Bug 9863 ]] Only invalidate the whole object if it has an
	//   owner!
	if (parent)
		layer_redrawall();
	}
Exemplo n.º 21
0
void checkbjetdatatrig(TString filename)
{
  TFile *f = new TFile(filename);
  auto nt = (TTree *)f->Get("nt");

  auto h = geth("incdatajtpt",48,0,120);
  nt->Project(h->GetName(),"jtpt1","weight");

  auto h2 = geth("incdatajtpt60",48,0,120);
  nt->Project(h2->GetName(),"jtpt1","weight*(hltCSV60)");

  auto hr = geth("incdatajtpt60ratio",48,0,120);
  hr->Divide(h2,h);

  vector<TString> trigcuts = {"hltCSV80", "hltCSV60 && !hltCSV80"};
  auto hs = getstack(nt, "trigcomb","jtpt1",trigcuts, 72, 0, 180);

  fout->cd();
  h->Write();
  hs->Write();
  hr->Write();
  f->Close();
}
Exemplo n.º 22
0
Boolean MCColors::mdown(uint2 which)
{
	if (state & CS_MFOCUSED)
		return False;
	state |= CS_MFOCUSED;
	MCColor color;
	switch (which)
	{
	case Button1:
		switch (getstack()->gettool(this))
		{
		case T_BROWSE:
			uint2 xcells;
			uint2 ycells;
			getcells(xcells, ycells);
			MCscreen->getpaletteentry((my - rect.y) * ycells / rect.height * xcells
			                          + (mx - rect.x) * xcells / rect.width, color);
			selectedcolor = color.pixel;
			// MW-2011-08-18: [[ Layers ]] Invalidate the whole object.
			layer_redrawall();
			message_with_valueref_args(MCM_mouse_down, MCSTR("1"));
			break;
		case T_POINTER:
			start(True);
			break;
		default:
			return False;
		}
		break;
	case Button2:
	case Button3:
		message_with_args(MCM_mouse_down, which);
		break;
	}
	return True;
}
Exemplo n.º 23
0
void MCCard::layer_dirtyrect(const MCRectangle& p_dirty_rect)
{
	getstack() -> dirtyrect(p_dirty_rect);
}
Exemplo n.º 24
0
Boolean MCScrollbar::mfocus(int2 x, int2 y)
{
	// MW-2007-09-18: [[ Bug 1650 ]] Disabled state linked to thumb size
	if (!(flags & F_VISIBLE || MCshowinvisibles)
	        || issbdisabled() && getstack()->gettool(this) == T_BROWSE)
		return False;
	if (state & CS_SCROLL)
	{
		// I.M. [[bz 9559]] disable scrolling where start value & end value are the same
		if (startvalue == endvalue)
			return True;

		real8 newpos;

		double t_thumbsize = thumbsize;
		if (t_thumbsize > fabs(endvalue - startvalue))
			t_thumbsize = fabs(endvalue - startvalue);
		if (flags & F_SCALE)
			t_thumbsize = 0;

		bool t_forward;
		t_forward = (endvalue > startvalue);
		MCRectangle t_bar_rect, t_thumb_rect, t_thumb_start_rect, t_thumb_end_rect;
		t_bar_rect = compute_bar();
		t_thumb_rect = compute_thumb(markpos);
		t_thumb_start_rect = compute_thumb(startvalue);
		if (t_forward)
			t_thumb_end_rect = compute_thumb(endvalue - t_thumbsize);
		else
			t_thumb_end_rect = compute_thumb(endvalue + t_thumbsize);

		int32_t t_bar_start, t_bar_length, t_thumb_start, t_thumb_length;
		int32_t t_movement;
		if (getstyleint(flags) == F_VERTICAL)
		{
			t_bar_start = t_thumb_start_rect.y;
			t_bar_length = t_thumb_end_rect.y + t_thumb_end_rect.height - t_bar_start;
			t_thumb_start = t_thumb_rect.y;
			t_thumb_length = t_thumb_rect.height;
			t_movement = y - my;
		}
		else
		{
			t_bar_start = t_thumb_start_rect.x;
			t_bar_length = t_thumb_end_rect.x + t_thumb_end_rect.width - t_bar_start;
			t_thumb_start = t_thumb_rect.x;
			t_thumb_length = t_thumb_rect.width;
			t_movement = x - mx;
		}

		t_bar_start += t_thumb_length / 2;
		t_bar_length -= t_thumb_length;

        // AL-2013-07-26: [[ Bug 11044 ]] Prevent divide by zero when computing scrollbar thumbposition
        if (t_bar_length == 0)
            t_bar_length = 1;
        
		int32_t t_new_position;
		t_new_position = t_thumb_start + t_thumb_length / 2 + t_movement;
		t_new_position = MCU_min(t_bar_start + t_bar_length, MCU_max(t_bar_start, t_new_position));
		
		if (t_forward)
			newpos = startvalue + ((t_new_position - t_bar_start) / (double)t_bar_length) * (fabs(endvalue - startvalue) - t_thumbsize);
		else
			newpos = startvalue - ((t_new_position - t_bar_start) / (double)t_bar_length) * (fabs(endvalue - startvalue) - t_thumbsize);

		update(newpos, MCM_scrollbar_drag);
		return True;
	}
	else if (!MCdispatcher -> isdragtarget() && MCcurtheme && MCcurtheme->getthemepropbool(WTHEME_PROP_SUPPORTHOVERING)
	         && MCU_point_in_rect(rect, x, y) )
	{
		if (!(state & CS_MFOCUSED) && !getstate(CS_SELECTED))
		{
			MCWidgetInfo winfo;
			winfo.type = (Widget_Type)getwidgetthemetype();
			if (MCcurtheme->iswidgetsupported(winfo.type))
			{
				getwidgetthemeinfo(winfo);
				Widget_Part wpart = MCcurtheme->hittest(winfo,mx,my,rect);
				if (wpart != hover_part)
				{
					hover_part = wpart;
					// MW-2011-08-18: [[ Layers ]] Invalidate the whole object.
					redrawall();
				}
			}
		}
	}
	return MCControl::mfocus(x, y);
}
Exemplo n.º 25
0
Boolean MCScrollbar::mdown(uint2 which)
{
	if (state & CS_MFOCUSED)
		return False;
	if (state & CS_MENU_ATTACHED)
		return MCObject::mdown(which);
	state |= CS_MFOCUSED;
	if (!IsMacEmulatedLF() && flags & F_TRAVERSAL_ON && !(state & CS_KFOCUSED))
		getstack()->kfocusset(this);
	uint2 margin;
	MCRectangle brect = compute_bar();
	if (flags & F_SCALE)
		margin = 0;
	else
		if (getstyleint(flags) == F_VERTICAL)
			margin = brect.width - 1;
		else
			margin = brect.height - 1;
	Tool tool = state & CS_NO_MESSAGES ? T_BROWSE : getstack()->gettool(this);
	MCWidgetInfo winfo;
	winfo.type = (Widget_Type)getwidgetthemetype();
	switch (which)
	{
	case Button1:
		switch (tool)
		{
		case T_BROWSE:
			message_with_args(MCM_mouse_down, "1");
			if (flags & F_PROGRESS) //progress bar does not respond to mouse down event
				return False;
			if (MCcurtheme && MCcurtheme->iswidgetsupported(winfo.type))
			{
				getwidgetthemeinfo(winfo);
				Widget_Part wpart = MCcurtheme->hittest(winfo,mx,my,rect);
				// scrollbar needs to check first if mouse-down occured in arrows
				switch (wpart)
				{
				case WTHEME_PART_ARROW_DEC:
					if (MCmodifierstate & MS_SHIFT)
						mode = SM_BEGINNING;
					else
						mode = SM_LINEDEC;
					break;
				case WTHEME_PART_ARROW_INC:
					if (MCmodifierstate & MS_SHIFT)
						mode = SM_END;
					else
						mode = SM_LINEINC;
					break;
				case WTHEME_PART_TRACK_DEC:
					mode = SM_PAGEDEC;
					break;
				case WTHEME_PART_TRACK_INC:
					mode = SM_PAGEINC;
					break;
				}
			}
			else
			{ //Non-theme appearence stuff: for vertical scrollbar or scale
				if (getstyleint(flags) == F_VERTICAL)
				{
					uint2 height;
					if (brect.height <= margin << 1)
						height = 1;
					else
						height = brect.height - (margin << 1);
					markpos = (my - (brect.y + margin))
					          * fabs(endvalue - startvalue) / height;
					if (my < brect.y + margin)
						if (MCmodifierstate & MS_SHIFT)
							mode = SM_BEGINNING;
						else
							mode = SM_LINEDEC;
					else
						if (my > brect.y + brect.height - margin)
							if (MCmodifierstate & MS_SHIFT)
								mode = SM_END;
							else
								mode = SM_LINEINC;
						else
						{
							MCRectangle thumb = compute_thumb(thumbpos);
							if (my < thumb.y)
								mode = SM_PAGEDEC;
							else
								if (my > thumb.y + thumb.height)
									mode = SM_PAGEINC;
						}
				}
				else
				{ //for Horizontal scrollbar or scale
					uint2 width;
					if (brect.width <= (margin << 1))
						width = 1;
					else
						width = brect.width - (margin << 1);
					markpos = (mx - (brect.x + margin))
					          * fabs(endvalue - startvalue) / width;
					if (mx < brect.x + margin)
						if (MCmodifierstate & MS_SHIFT)
							mode = SM_BEGINNING;
						else
							mode = SM_LINEDEC;
					else
						if (mx > brect.x + brect.width - margin)
							if (MCmodifierstate & MS_SHIFT)
								mode = SM_END;
							else
								mode = SM_LINEINC;
						else
						{
							MCRectangle thumb = compute_thumb(thumbpos);
							if (mx < thumb.x)
								mode = SM_PAGEDEC;
							else
								if (mx > thumb.x + thumb.width)
									mode = SM_PAGEINC;
						}
				}
			} //end of Non-MAC-Appearance Manager stuff
			switch (mode)
			{
			case SM_BEGINNING:
				update(0, MCM_scrollbar_beginning);
				break;
			case SM_END:
				update(endvalue, MCM_scrollbar_end);
				break;
			case SM_LINEDEC:
			case SM_LINEINC:
				timer(MCM_internal, NULL);
				redrawarrow(mode);
				break;
			case SM_PAGEDEC:
			case SM_PAGEINC:
				timer(MCM_internal, NULL);
				break;
			default:
				state |= CS_SCROLL;
				markpos = thumbpos;
				if (IsMacEmulatedLF())
					movethumb(thumbpos--);
				else if (MCcurtheme)
				{
					// MW-2011-08-18: [[ Layers ]] Invalidate the whole object.
					redrawall();
				}
			}
			break;
		case T_POINTER:
		case T_SCROLLBAR:
			start(True);
			break;
		case T_HELP:
			break;
		default:
			return False;
		}
		break;
	case Button2:
		if (message_with_args(MCM_mouse_down, "2") == ES_NORMAL)
			return True;
		state |= CS_SCROLL;
		{
			real8 newpos;
			real8 range = endvalue - startvalue;
			real8 offset = startvalue;
			if (flags & F_SCALE)
				margin = MOTIF_SCALE_THUMB_SIZE >> 1;
			else
				if (MCproportionalthumbs)
					if (startvalue > endvalue)
						offset += thumbsize / 2.0;
					else
						offset -= thumbsize / 2.0;
				else
					margin = FIXED_THUMB_SIZE >> 1;
			if (getstyleint(flags) == F_VERTICAL)
				newpos = (my - brect.y - margin) * range
				         / (brect.height - (margin << 1)) + offset;
			else
				newpos = (mx - brect.x - margin) * range
				         / (brect.width - (margin << 1)) + offset;
			update(newpos, MCM_scrollbar_drag);
			markpos = thumbpos;
		}
		break;
	case Button3:
		message_with_args(MCM_mouse_down, "3");
		break;
	}
Exemplo n.º 26
0
void MCCard::layer_removed(MCControl *p_control, MCObjptr *p_previous, MCObjptr *p_next)
{
	MCTileCacheRef t_tilecache;
	t_tilecache = getstack() -> gettilecache();

	// Add the rects to the update region (for clarity, would prefer this at the end
	// but there is 'return' fall through in the rest :-( )
	layer_dirtyrect(p_control -> geteffectiverect());
	
	// Notify any tilecache of the changes.
	if (t_tilecache != nil)
	{
		// If the control has no layer id then there is nothing to do.
		if (p_control -> layer_getid() == 0)
			return;

		// If the control is on a dynamic layer then remove any associated sprite.
		if (p_control -> layer_issprite())
		{
			MCTileCacheRemoveSprite(t_tilecache, p_control -> layer_getid());
			
			// MW-2012-09-21: [[ Bug 10005 ]] Make sure we reset the layer attrs so we
			//   don't try and reuse a dead sprite.
			p_control -> layer_resetattrs();
			
			return;
		}

		// Remove the scenery.
		MCTileCacheRemoveScenery(t_tilecache, p_control -> layer_getid(), p_control -> geteffectiverect());
		
		// MW-2012-10-11: [[ Bug ]] Redraw glitch caused by resetting the layer id
		//   before removing the layer.
		// MW-2012-09-21: [[ Bug 10005 ]] Make sure we reset the layer attrs so we
		//   don't try and reuse a dead scenery layer.
		p_control -> layer_resetattrs();
		
		// If there is no previous or next control we have no tweaks to ids
		// to perform.
		if (p_previous == nil || p_next == nil)
			return;

		// Now layer ids for new layers percolate from the next layer, so the
		// original layers are always at the bottom of the stack. If the next
		// layer has a different id than us, make sure all previous layers
		// with the same id match it.
		uint32_t t_before_layer_id;
		t_before_layer_id = p_previous -> getref() -> layer_getid();

		// The layer below us has the same id so there's nothing to do, we are
		// removing a 'new' layer before its been redrawn.
		if (t_before_layer_id == p_control -> layer_getid())
			return;

		// The layer below us has a different id, so this is an existing layer
		// and thus we must ensure all layers above us now use the id of the
		// layer below.
		MCObjptr *t_objptr;
		t_objptr = p_next;
		while(t_objptr != p_previous && t_objptr -> getref() -> layer_getid() == p_control -> layer_getid())
		{
			t_objptr -> getref() -> layer_setid(t_before_layer_id);
			t_objptr = t_objptr -> next();
		}
	}
}
Exemplo n.º 27
0
void MCControl::layer_changeeffectiverect(const MCRectangle& p_old_effective_rect, bool p_force_update, bool p_update_card)
{
	// Compute the 'new' effectiverect based on visibility.
	MCRectangle t_new_effective_rect;
	if (getflag(F_VISIBLE) || MCshowinvisibles)
		t_new_effective_rect = geteffectiverect();
	else
		MCU_set_rect(t_new_effective_rect, 0, 0, 0, 0);

	// If the effective rect has not changed this is at most an update.
	if (MCU_equal_rect(p_old_effective_rect, t_new_effective_rect))
	{
		// If we are forcing an update, use the dirty method.
		if (p_force_update)
		{
			// If the layer is not scrolling just defer to the normal
			// dirty method; otherwise use the dirty content method.
			if (!layer_isscrolling())
				layer_dirtyeffectiverect(t_new_effective_rect, p_update_card);
			else
				layer_dirtycontentrect(layer_getcontentrect(), p_update_card);
		}

		// We are done.
		return;
	}

	// Fetch the tilecache, making it nil if the parent is a group (in the
	// latter case, this is just a dirty op).
	MCTileCacheRef t_tilecache;
	if (parent -> gettype() != CT_GROUP)
		t_tilecache = getstack() -> gettilecache();
	else
		t_tilecache = nil;
	
	// If no tilecache, then just dirty the old and new effective rects.
	if (t_tilecache == nil)
	{
		layer_dirtyeffectiverect(p_old_effective_rect, p_update_card);
		layer_dirtyeffectiverect(t_new_effective_rect, p_update_card);
		return;
	}

	// MW-2011-10-17: [[ Bug 9808 ]] Make sure we update the card regardless of
	//    whether we have a layer id - otherwise new objects don't show!
	// Add the rects to the update region - but only if instructed (update_card will be
	// false if the object was invisible).
	if (p_update_card)
	{
		static_cast<MCCard *>(parent) -> layer_dirtyrect(p_old_effective_rect);
		static_cast<MCCard *>(parent) -> layer_dirtyrect(t_new_effective_rect);
	}
	
	// We must be in tile-cache mode with a top-level control, but if the layer
	// id is zero, there is nothing to do.
	if (m_layer_id == 0)
		return;

	if (!layer_issprite())
	{
		// Non-dynamic layers are scenery in the tilecache, and we must use old
		// new effective rects so that the appropriate tiles get flushed. Note
		// that 'force_update' has no effect here as reshaping a scenery layer
		// implicitly invalidates all tiles it touches.
		MCTileCacheReshapeScenery(t_tilecache, m_layer_id, p_old_effective_rect, t_new_effective_rect);
	}
	else
	{
		// Dynamic layers are sprites in the tilecache, and there is nothing to
		// do unless 'force update' is required. In particular, if the layer is
		// just moving then no redraw of the layer will be needed. Note, however,
		// that this implicitly assumes that 'force update' is true if the content
		// in a sprite-relative co-ord system has changed.
		if (p_force_update)
		{
			MCRectangle t_rect;
			
			// If the layer is not scrolling, just use the width/height from the
			// effective rect; otherwise use content width/height.
			if (!layer_isscrolling())
				t_rect = p_old_effective_rect;
			else
				t_rect = layer_getcontentrect();
				
			MCTileCacheUpdateSprite(t_tilecache, m_layer_id, MCU_make_rect(0, 0, t_rect . width, t_rect . height));
		}
	}
}
Exemplo n.º 28
0
void MCCard::render(void)
{
	MCTileCacheRef t_tiler;
	t_tiler = getstack() -> gettilecache();

	bool t_reset_ids;
	t_reset_ids = MCTileCacheIsClean(t_tiler);

	if (getstate(CS_SIZE))
	{
		MCTileCacheLayer t_fg_layer;
		t_fg_layer . id = m_fg_layer_id;
		t_fg_layer . region = selrect;
		t_fg_layer . is_opaque = false;
		t_fg_layer . opacity = 255;
		t_fg_layer . ink = GXblendSrcOver;
		t_fg_layer . callback = render_foreground;
		t_fg_layer . context = this;
		MCTileCacheRenderScenery(t_tiler, t_fg_layer);
		m_fg_layer_id = t_fg_layer . id;
	}
	else
		m_fg_layer_id = 0;

	MCObjptr *t_objptrs;
	t_objptrs = getobjptrs();
	if (t_objptrs != nil)
	{
		MCObjptr *t_objptr;
		t_objptr = t_objptrs -> prev();
		do
		{
			MCControl *t_control;
			t_control = t_objptr -> getref();

			// If the tilecache is 'clean' then we must reset the attrs to
			// force a sync.
			if (t_reset_ids)
				t_control -> layer_resetattrs();

			// Take note of whether the spriteness of a layer has changed.
			bool t_old_is_sprite;
			t_old_is_sprite = t_control -> layer_issprite();

			// Sync the attributes, make sure we commit the new values.
			t_control -> layer_computeattrs(true);

			// Initialize the common layer props.
			MCTileCacheLayer t_layer;
			t_layer . id = t_control -> layer_getid();
			t_layer . opacity = t_control -> getopacity();
			t_layer . ink = t_control -> getink();
			t_layer . context = t_control;

			// The opaqueness of a layer has already been computed.
			t_layer . is_opaque = t_control -> layer_isopaque();

			// Now compute the layer's region/clip.
			if (!t_control -> getflag(F_VISIBLE) && !MCshowinvisibles)
			{
				// Invisible layers just have empty region/clip.
				t_layer . region = MCU_make_rect(0, 0, 0, 0);
				t_layer . clip = MCU_make_rect(0, 0, 0, 0);
			}
			else if (!t_control -> layer_isscrolling())
			{
				// Non-scrolling layer's are the size of their effective rects.
				t_layer . region = t_control -> geteffectiverect();
				t_layer . clip = t_layer . region;
			}
			else
			{
				// For a scrolling layer, the clip is the bounds of the control, while
				// the region we draw is the group's minrect.
				t_layer . region = t_control -> layer_getcontentrect();
				t_layer . clip = t_control -> geteffectiverect();
			}

			// Now render the layer - what method we use depends on whether the
			// layer is a sprite or not.
			if (t_control -> layer_issprite())
			{
				// If the layer was not a sprite before, remove the scenery
				// layer that it was.
				if (!t_old_is_sprite && t_layer . id != 0)
				{
					MCTileCacheRemoveScenery(t_tiler, t_layer . id, t_control -> geteffectiverect());
					t_layer . id = 0;
				}

				t_layer . callback = testtilecache_sprite_renderer;
				MCTileCacheRenderSprite(t_tiler, t_layer);
			}
			else
			{
				// If the layer was a sprite before, remove the sprite
				// layer that it was.
				if (t_old_is_sprite && t_layer . id != 0)
				{
					MCTileCacheRemoveSprite(t_tiler, t_layer . id);
					t_layer . id = 0;
				}

				t_layer . callback = testtilecache_scenery_renderer;
				MCTileCacheRenderScenery(t_tiler, t_layer);
			}
			
			// Upate the id.
			t_control -> layer_setid(t_layer . id);

			// Advance to the object below.
			t_objptr = t_objptr -> prev();
		}
		while(t_objptr != t_objptrs -> prev());
	}

	// Final step is to render the background. Note that the background layer
	// really only needs to be the rect rounded outward to the nearest tile
	// boundaries, but 8192, 8192 is bigger than it can ever be at present so
	// is an easier alternative.
	MCTileCacheLayer t_bg_layer;
	t_bg_layer . id = m_bg_layer_id;
	t_bg_layer . region = MCU_make_rect(0, 0, 8192, 8192);
	t_bg_layer . is_opaque = true;
	t_bg_layer . opacity = 255;
	t_bg_layer . ink = GXblendSrcOver;
	t_bg_layer . callback = render_background;
	t_bg_layer . context = this;
	MCTileCacheRenderScenery(t_tiler, t_bg_layer);
	m_bg_layer_id = t_bg_layer . id;
}
int main()
{
    int local = 1;

    unsigned long stackBefore = getstack();
    unsigned long framePtrBefore = getebp();
    try
    {
        MyClass ins;
        foo1();
        local = 0;
    }
    catch(...)
    {
        // If Pin translated probed code properly, exception will reach the handler
        printf("Exception\n");
    }
    unsigned long stackAfter = getstack();
    unsigned long framePtrAfter = getebp();
    
    if ((stackBefore != stackAfter) || (framePtrBefore != framePtrAfter))
    {
        printf("before try  Stack at 0x%x, ebp 0x%x\n", getstack(), getebp());
        printf("after catch Stack at 0x%x, ebp 0x%x\n", getstack(), getebp());
        return -1;
    }
    
    int param1 = 1;
    int param2 = param1 * 5;
    float param3 = 0.5*1.5;
    float expectedResult = 0;
    try
    {
        expectedResult = param3+param2+param1;
        foo2();
    }
    catch(...)
    {
        float afterCatchResult = param3+param2+param1;
        if (afterCatchResult != expectedResult)
        {
            printf("expectedResult = %f; afterCatchResult = %f\n", expectedResult, afterCatchResult);
            printf("Registers may be restored incorrectly in the catch block\n");
            return -1;
        }
        else
        {
            printf("Try-catch works correctly while exception propagation from dll\n");
        }
        
    }
    stackAfter = getstack();
    framePtrAfter = getebp();
    
    if ((stackBefore != stackAfter) || (framePtrBefore != framePtrAfter))
    {
        printf("Incorrect stack of frame ptr after exception propagation from dll");
        printf("before try  Stack at 0x%x, ebp 0x%x\n", getstack(), getebp());
        printf("after catch Stack at 0x%x, ebp 0x%x\n", getstack(), getebp());
        return -1;
    }
            
    // Check that destructor was called and local var value was not changed when exception was handled
    if (!destructed || (local != 1))
    {
        return 1;
    }

    pBar = bar;

    try
    {
        foo1();
    }
    catch(...)
    {
        // No exception expected
        printf("Exception\n");
    }

    return 0;
}
Exemplo n.º 30
0
int ExpCalAmt(char *num_exp,double *out_amt)
{
	bool error=0;
	point=0;bracket=0;stacknum=0;error=0;
	strcpy(string,num_exp);
	STRLEN=strlen(string);
		if(!check()) 
		{
			return -1;
		}
		result=getnumber();
		while(point<=STRLEN-1){
			switch(string[point++]){//哪个运算符?
			case '+':
				if(getnextopsign()>ADDLEVEL){
					push(ADD);
					result=getnumber();
				}
				else result+=getnumber();
				break;
			case '-':
				if(getnextopsign()>SUBLEVEL){
					push(SUB);
					result=getnumber();
				}
				else result-=getnumber();
				break;
			case '*':
				if(getnextopsign()>MULLEVEL){
					push(MUL);
					result=getnumber();
				}
				else
				{
					result*=getnumber();
					result=d4u5(result,2);
					if(stacknum>0 && getnextopsign()<MULLEVEL && getstack(stacknum)->bracket>=bracket)
						pop();
				}
				break;
			case '/':
				if(getnextopsign()>DIVLEVEL){
					push(DIV);
					result=getnumber();
				}
				else
				{
					result/=getnumber();
					if(stacknum>0 && getnextopsign()<DIVLEVEL && getstack(stacknum)->bracket>=bracket)
						pop();
				}
				break;
			case ')'://右括号
				--bracket;
				if(getstack(stacknum)->opsign==0){//括号前面为空
					pop();
					break;
				}
				while(stacknum>0 && getnextopsign()<getlevel(getstack(stacknum)->opsign)
						&& getstack(stacknum)->bracket>=bracket && getstack(stacknum)->opsign!=0)
						//将本层括号内可以pop的都pop
						pop();
				break;
			case '^':
				if(getnextopsign()>POWLEVEL){
					push(POW);
					result=getnumber();
				}
				else
				{
					result=(float)pow((double)result,(double)getnumber());
					while(stacknum>0 && getnextopsign()<getlevel(getstack(stacknum)->opsign)
						&& getstack(stacknum)->bracket>=bracket) pop();
				}
				break;
			case '!':
				if(getnextopsign()>FACTLEVEL){
					push(FACT);
					result=getnumber();
				}
				else
				{
					result=fact((long)result);
					while(stacknum>0 && getnextopsign()<getlevel(getstack(stacknum)->opsign)
						&& getstack(stacknum)->bracket>=bracket) pop();
				}
				break;
			}
		}
		//if(!error) printf("计算结果:%g\n",result);
	*out_amt=result;
	return 0;
}