示例#1
0
GBWindow::GBWindow(GBView * contents, short left, short top, bool vis)
	: showGrowBox(false), //TODO
	window(nil),
	view(contents),
	visible(vis)
{
	Rect bounds;
	bounds.left = left;
	bounds.top = top;
	bounds.right = left + view->PreferredWidth();
	bounds.bottom = top + view->PreferredHeight();
	Str255 s;
	ToPascalString(view->Name(), s);
	view->SetBounds(GBRect(0, 0, view->PreferredWidth(), view->PreferredHeight()));
	if ( CreateNewWindow(kDocumentWindowClass,
			view->Resizable() ? kWindowStandardDocumentAttributes
				: (kWindowCloseBoxAttribute | kWindowCollapseBoxAttribute),
			&bounds, &window) )
		throw GBOutOfMemoryError();
	SetWTitle(window, s);
	SetWRefCon(window, (long)this);
	SetWindowKind(window, kMacWindowKind);
	view->SetGraphics(&graphics);
	if ( vis )
		ShowWindow(window);
}
示例#2
0
void GBRobot::Draw(GBGraphics & g, const GBRect & where, bool detailed) const {
	if(where.Width() <= 5) {
		DrawMini(g,where);
		return;
	}
// shield
	if ( hardware.ActualShield() > 0 )
		g.DrawOpenRect(where, GBColor(0.3f, 0.5f, 1)
			* (hardware.ActualShield() / (mass * kStandardShieldPerMass)).ToDouble());
// body
	g.DrawSolidOval(where, Owner()->Color());
// meters
	if ( detailed ) {
		short meterWidth = std::max(1, (where.Width() + 10) / 10);
		short arcsize;
		GBRect meterRect = where;
		meterRect.Shrink((meterWidth + 1) / 2); //TODO is this portable?
	// energy meter
		if ( hardware.MaxEnergy() ) {
			arcsize = round(hardware.Energy() / hardware.MaxEnergy() * 180);
			g.DrawArc(meterRect, 180 - arcsize, arcsize,
				Owner()->Color().ChooseContrasting(GBColor::green, GBColor(0, 0.5f, 1), kMinMeterContrast), meterWidth);
		}
	// armor meter
		arcsize = round(max(hardware.Armor(), 0) / hardware.MaxArmor() * 180);
		g.DrawArc(meterRect, 180, arcsize,
			Owner()->Color().ChooseContrasting(GBColor::lightGray, GBColor::darkGray, kMinMeterContrast), meterWidth);
	// gestation meter
		meterRect.Shrink(meterWidth);
		if ( hardware.constructor.Progress() ) {
			arcsize = round(hardware.constructor.Fraction() * 360);
			g.DrawArc(meterRect, 360 - arcsize, arcsize,
				Owner()->Color().ChooseContrasting(GBColor(1, 1, 0), GBColor(0, 0.5f, 0), kMinMeterContrast), meterWidth);
		}
	}
// decoration
	short thickness = (15 + where.right - where.left) / 15; //was 2 for >15 else 1
	GBRect dec((where.left * 2 + where.right + 2) / 3,
		(where.top * 2 + where.bottom + 2) / 3,
		(where.left + where.right * 2 + 1) / 3,
		(where.top + where.bottom * 2 + 1) / 3);
	short dx = where.Width() / 4;
	short dy = where.Height() / 4;
	//cross, hline, and vline draw in bigDec instead of dec
	GBRect bigDec(where.CenterX() - dx, where.CenterY() - dy, where.CenterX() + dx, where.CenterY() + dy);
	switch ( type->Decoration() ) {
		case rdDot:
			g.DrawSolidOval(GBRect(where.CenterX() - thickness, where.CenterY() - thickness,
				where.CenterX() + thickness, where.CenterY() + thickness), type->DecorationColor());
			break;
		case rdCircle: g.DrawOpenOval(dec, type->DecorationColor(), thickness); break;
		case rdSquare: g.DrawOpenRect(dec, type->DecorationColor(), thickness); break;
		case rdTriangle:
			g.DrawLine(dec.left, dec.bottom, dec.CenterX(), dec.top,
				type->DecorationColor(), thickness);
			g.DrawLine(dec.CenterX(), dec.top, dec.right, dec.bottom,
				type->DecorationColor(), thickness);
			g.DrawLine(dec.left, dec.bottom, dec.right, dec.bottom,
				type->DecorationColor(), thickness);
			break;
		case rdCross:
			g.DrawLine(where.CenterX(), bigDec.top, where.CenterX(), bigDec.bottom,
				type->DecorationColor(), thickness);
			g.DrawLine(bigDec.left, where.CenterY(), bigDec.right, where.CenterY(),
				type->DecorationColor(), thickness);
			break;
		case rdX:
			g.DrawLine(dec.left, dec.top, dec.right, dec.bottom,
				type->DecorationColor(), thickness);
			g.DrawLine(dec.left, dec.bottom, dec.right, dec.top,
				type->DecorationColor(), thickness);
			break;
		case rdHLine:
			g.DrawLine(bigDec.left, where.CenterY(), bigDec.right, where.CenterY(),
				type->DecorationColor(), thickness);
			break;
		case rdVLine:
			g.DrawLine(where.CenterX(), bigDec.top, where.CenterX(), bigDec.bottom,
				type->DecorationColor(), thickness);
			break;
		case rdSlash:
			g.DrawLine(dec.left, dec.bottom, dec.right, dec.top,
				type->DecorationColor(), thickness);
			break;
		case rdBackslash:
			g.DrawLine(dec.left, dec.top, dec.right, dec.bottom,
				type->DecorationColor(), thickness);
			break;
		case rdNone: default: break;
	}
//rim (last in case something is slightly in the wrong place)
	g.DrawOpenOval(where, type->Color());
}