Exemplo n.º 1
0
void Frame::updateFrames(CRI * boss)
{
	// Todo: Need to interpolate rotation aswell!!!
	
	bool found;
	vector<string> listFromTF;
	vector<string>::iterator listIt;
	vector<Frame>::iterator frameIt;
	
	tf::StampedTransform transform;
	GFrame * tframe;
	
	tfListener->getFrameStrings(listFromTF);
	
	// Check for the appearance of any new frames...
	for (listIt = listFromTF.begin(); listIt != listFromTF.end(); listIt++)
	{
		found = false;
		for (frameIt = availableFrames.begin(); frameIt != availableFrames.end(); frameIt++)
		{
			if ((*frameIt).name == *listIt)
			{
				found = true;
				break;
			}
		}
		
		if (!found)
		{
			Frame newFrame = Frame(*listIt);
			
			// We assume the frame is valid
			newFrame.valid = true;
			
			availableFrames.push_back(newFrame);
			
			// Add a representative frame
			tframe = new GFrame((char *)(*listIt).c_str());
			boss->addGadget(tframe);
			tframe->applyProperties();
			tframe->show(true);
			tframe->sourceFrame = availableFrames.size() - 1;
		}
	}

	double timeDiff, timeFut;
	ros::Time tTime;
	tf::StampedTransform tTran;
	int framePosition = -1;

	// Update frame locations by extrapolating
	// Todo: second order extrapolation, please
	for (frameIt = availableFrames.begin(); frameIt != availableFrames.end(); frameIt++)
	{
		Frame & tFr = (*frameIt);
		framePosition++;
		
		if (tfListener->canTransform(fixedFrame, tFr.name, ros::Time(0), NULL))
		{
			// Check if the frame has become valid
			if (!tFr.valid)
			{
				tFr.valid = true;
				
				// Add a renewed representative frame
				tframe = new GFrame((char *)tFr.name.c_str());
				boss->addGadget(tframe);
				tframe->applyProperties();
				tframe->show(true);
				tframe->sourceFrame = framePosition;
			}
			
			tfListener->lookupTransform(fixedFrame, tFr.name, ros::Time(0), tTran);
		}
		else
		{
			// TODO: error msg
			
			// The frame is not connected to the fixed frame, or we're extrapolating, either way,
			// the frame is useless.
			tFr.valid = false;
			
			continue;
		}
		
		//cout << "Beer: " << ros::Time::now() << "\n";
		//cout << tTran.stamp_ << "\n";
		
		if (tFr.gotLast == false)
		{
			tFr.curTransform = tTran;
			tFr.curTime = tTime;
			tFr.extrapTransform = tTran;
			tFr.gotLast = true;
		}
		else
		{
			// Do we have a new sample?  If so, update the pair of samples
			if (tTran.stamp_ > tFr.curTime)
			{
				tFr.lastTransform = tFr.curTransform;
				tFr.lastTime = tFr.curTime;
				
				tFr.curTransform = tTran;
				tFr.curTime = tTran.stamp_;
			}
			
			// Calculate the extrapolated position
			timeDiff = (tFr.curTime - tFr.lastTime).toSec();
			timeFut = (ros::Time::now() - tFr.curTime).toSec();
			
			tf::Vector3 & lPos = tFr.lastTransform.getOrigin();
			tf::Quaternion lRot = tFr.lastTransform.getRotation();
			tf::Vector3 & cPos = tFr.curTransform.getOrigin();
			tf::Quaternion cRot = tFr.curTransform.getRotation();
			
			// Todo: No magic numbers
			if (timeDiff > 0.001 && timeFut < 0.5)
			{
				tFr.extrapTransform.setOrigin(tf::Vector3((cPos.x() - lPos.x()) / timeDiff * timeFut + cPos.x(), 
					(cPos.y() - lPos.y()) / timeDiff * timeFut + cPos.y(), 
					(cPos.z() - lPos.z()) / timeDiff * timeFut + cPos.z()));
				tFr.extrapTransform.setRotation(tFr.curTransform.getRotation());
			}
			else
			{
				tFr.extrapTransform.setOrigin(tFr.curTransform.getOrigin());
				tFr.extrapTransform.setRotation(tFr.curTransform.getRotation());
			}
			
		}
		
	}
	
	// If we need to draw the frame tree, do so
	
	if (drawFrameTree)
	{
		tf::StampedTransform endPoint;
		tf::StampedTransform startPoint;
		string startFrameName;
		
		if (treeNode && !treeWasVisible)
		{
			boss->rootSceneNode->addChild(treeNode);
		}
		else if (treeNode == NULL)
		{
			treeNode = boss->rootSceneNode->createChildSceneNode();
		}
		
		if (!treeManual)
		{
			treeManual = boss->scene->createManualObject("TreeManual");
			treeNode->attachObject(treeManual);
			
			treeManual->setDynamic(true);
			treeManual->estimateVertexCount(1000);
			treeManual->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_LIST);
			
		}
		else
		{
			treeManual->beginUpdate(0);
		}
		
		treeManual->colour(Ogre::ColourValue(1, 1, 0, 1));
		
		for (frameIt = availableFrames.begin(); frameIt != availableFrames.end(); frameIt++)
		{
			if ((*frameIt).valid)
			{
				//tfListener->lookupTransform(fixedFrame, tFr.name, ros::Time(0), endPoint);
				tf::Vector3 startPos = (*frameIt).extrapTransform.getOrigin();
				
				tfListener->getParent((*frameIt).name, ros::Time(), startFrameName);
				int fNum = findFrame(startFrameName);
				
				if (fNum >= 0)
				{
					tf::Vector3 endPos = availableFrames[fNum].extrapTransform.getOrigin();
					
					treeManual->position(startPos.x(), startPos.y(), startPos.z());
					treeManual->position(endPos.x(), endPos.y(), endPos.z());
				}
			}
		}
		
		// A dummy to keep things sane, can't have zero length manual object
		treeManual->position(0, 0, 0);
		treeManual->position(0, 0, 0);
		
		treeManual->end();
		
		treeWasVisible = 1;
	}
	else
	{
		if (treeWasVisible)
		{
			boss->rootSceneNode->removeChild(treeNode);
		}
		treeWasVisible = 0;
	}
}
 bool doGetFrame(Frame& _frame)
 {
   _frame = Frame(&m_frameBuffer.front(), m_frameBuffer.size());
   return true;
 }
Exemplo n.º 3
0
	bool CameraGigeSdkIc::grabSingleImage(Frame &frame, int camID){

		// Retrieve a list with the video capture devices connected to the computer.
		DShowLib::Grabber::tVidCapDevListPtr pVidCapDevList = m_pGrabber->getAvailableVideoCaptureDevices();
		
		if(pVidCapDevList == 0 || pVidCapDevList->empty()){

			cout << "No device available." << endl;
			return false;

		}else{

			// Print available devices.
			int numCam = -1;
			for(int i = 0; i < pVidCapDevList->size(); i++){
				
				cout << "(" << i << ") " << pVidCapDevList->at(i).c_str() << endl;

				if(camID == i){
					numCam = i; 
					break;
				}

			}

			if(numCam == -1){

				return false;

			}else{

				// Open the selected video capture device.
				m_pGrabber->openDev(pVidCapDevList->at(numCam));

				/*cout << "Available video formats : " << endl;

				DShowLib::Grabber::tVidFmtDescListPtr DecriptionList;

				DecriptionList = m_pGrabber->getAvailableVideoFormatDescs();

				for( DShowLib::Grabber::tVidFmtDescList::iterator pDescription = DecriptionList->begin(); pDescription != DecriptionList->end(); pDescription++ )
				{
					printf("%s\n", (*pDescription)->toString().c_str());
				}*/
				
				DShowLib::tFrameHandlerSinkPtr pSink;

				cout << "Current bits per pixel : " << m_pGrabber->getVideoFormat().getBitsPerPixel() << endl;

				

				switch(frame.getBitDepth()){
					
					case MONO_8 :

						m_pGrabber->setVideoFormat("Y8 (1280x960-1280x960)");

						// Set the image buffer format to eY800. eY800 means monochrome, 8 bits (1 byte) per pixel.
						// Let the sink create a matching MemBufferCollection with 1 buffer.
						pSink = DShowLib::FrameHandlerSink::create( DShowLib::eY800, 1 );

						break;

					case MONO_12 :
						
						m_pGrabber->setVideoFormat("Y16 (1280x960-1280x960)");

						// Disable overlay.
						// http://www.theimagingsourceforums.com/archive/index.php/t-319880.html
						m_pGrabber->setOverlayBitmapPathPosition(DShowLib::ePP_NONE);

						// Set the image buffer format to eY16. eY16 means monochrome, 16 bits (2 byte) per pixel.
						// Let the sink create a matching MemBufferCollection with 1 buffer.
						pSink = DShowLib::FrameHandlerSink::create( DShowLib::eY16, 1 );

						break;
						
					default:
												
						return false;

						break;
				}

				cout << "New video format : " << m_pGrabber->getVideoFormat().getBitsPerPixel() << endl;
 
				// Get properties.
				_DSHOWLIB_NAMESPACE::tIVCDPropertyItemsPtr pItems = m_pGrabber->getAvailableVCDProperties();

				// Set Exposure time.
				int exposure = frame.getExposure();
								
				long eMin  = getPropertyRangeMin(DShowLib::VCDID_Exposure, pItems);
				long eMax  = getPropertyRangeMax(DShowLib::VCDID_Exposure, pItems);
				long e = getPropertyValue(DShowLib::VCDID_Exposure, pItems);

				cout << "Previous exposure time value : " << e << endl;

				if(exposure <= eMax && exposure >= eMin){

					setPropertyValue(DShowLib::VCDID_Exposure, (long)exposure, pItems);
					cout << "New exposure time value : " << getPropertyValue(DShowLib::VCDID_Exposure, pItems) << endl;

				}else{

					cout << "Fail to set exposure. Available range value is " << eMin << " to " << eMax << endl;
					return false;
				}

				// Set Gain (db)
				int gain = frame.getGain();
								
				long gMin  = getPropertyRangeMin(DShowLib::VCDID_Gain, pItems);
				long gMax  = getPropertyRangeMax(DShowLib::VCDID_Gain, pItems);
				long g = getPropertyValue(DShowLib::VCDID_Gain, pItems);

				cout << "Previous gain value : " << g << endl;

				if(gain <= gMax && gain >= gMin){

					setPropertyValue(DShowLib::VCDID_Gain, (long)gain, pItems);
					cout << "New gain value : " << getPropertyValue(DShowLib::VCDID_Gain, pItems) << endl;

				}else{

					cout << "Fail to set gain. Available range value is " << gMin << " to " << gMax << endl;
					return false;
				}

				
				// Set the sink.
				m_pGrabber->setSinkType(pSink);
				
				// We use snap mode.
				pSink->setSnapMode(true);

		

				// Prepare the live mode, to get the output size if the sink.
				if(!m_pGrabber->prepareLive(false)){

					std::cerr << "Could not render the VideoFormat into a eY800 sink.";
					return false;
				}

				// Retrieve the output type and dimension of the handler sink.
				// The dimension of the sink could be different from the VideoFormat, when
				// you use filters.
				DShowLib::FrameTypeInfo info;
				pSink->getOutputFrameType(info);
				cout << info.getBitsPerPixel() << endl;

				Mat newImg;
				DShowLib::Grabber::tMemBufferCollectionPtr pCollection;

				switch(info.getBitsPerPixel()){
					
					case 8 :

						{

							newImg = Mat(info.dim.cy, info.dim.cx, CV_8UC1, Scalar(0));
							BYTE* pBuf[1];
							// Allocate image buffers of the above calculate buffer size.
							pBuf[0] = new BYTE[info.buffersize];

							// Create a new MemBuffer collection that uses our own image buffers.
							pCollection = DShowLib::MemBufferCollection::create( info, 1, pBuf );
							if( pCollection == 0 || !pSink->setMemBufferCollection(pCollection)){

								std::cerr << "Could not set the new MemBufferCollection, because types do not match.";
								return false;

							}

							m_pGrabber->startLive(false);

							pSink->snapImages(1);
					
							memcpy(newImg.ptr(), pBuf[0], info.buffersize);

						}

						break;

					case 16 :

						{

							newImg = Mat(info.dim.cy, info.dim.cx, CV_16UC1, Scalar(0));
							BYTE * pBuf[1];
							// Allocate image buffers of the above calculate buffer size.
							pBuf[0] = new BYTE[info.buffersize];

							// Create a new MemBuffer collection that uses our own image buffers.
							pCollection = DShowLib::MemBufferCollection::create(info, 1, pBuf);
							if(pCollection == 0 || !pSink->setMemBufferCollection(pCollection)){

								std::cerr << "Could not set the new MemBufferCollection, because types do not match.";
								return false;

							}

							m_pGrabber->startLive(false);

							pSink->snapImages(1);

							memcpy(newImg.ptr(), pBuf[0], info.buffersize);

						}

						break;
						
					default:
												
						return false;

						break;
				}

				m_pGrabber->stopLive();

				m_pGrabber->closeDev();

				//Timestamping.
				string acquisitionDate = TimeDate::localDateTime(microsec_clock::universal_time(),"%Y:%m:%d:%H:%M:%S");
				boost::posix_time::ptime time = boost::posix_time::microsec_clock::universal_time();
				string acqDateInMicrosec = to_iso_extended_string(time);

                frame = Frame(newImg, 0, 0, acquisitionDate);
                frame.setAcqDateMicro(acqDateInMicrosec);
                frame.setFPS(0);

				//cout << "save " << endl;
				//pCollection->save( "yio*.bmp" );

				double minVal, maxVal;
				minMaxLoc(newImg, &minVal, &maxVal);

				cout << "minVal :" << minVal << endl;
				cout << "maxVal :" << maxVal << endl;
				
				unsigned short * ptr;

				double t = (double)getTickCount();

				for(int i = 0; i < newImg.rows; i++){

					ptr = newImg.ptr<unsigned short>(i);

					for(int j = 0; j < newImg.cols; j++){

						ptr[j] = ptr[j] >> 4;

					}
				}	

				t = (((double)getTickCount() - t )/getTickFrequency())*1000;

				cout << "time decalage : " << t << endl;
				
				minMaxLoc(newImg, &minVal, &maxVal);

				cout << "minVal :" << minVal << endl;
				cout << "maxVal :" << maxVal << endl;

			}
		}

		return true;
	}
Exemplo n.º 4
0
void TestWindow::MakeTermSettings()
{
	BView* settings = 0;
	BView* root = 0;
	BWindow* win = 0;
	
	try {
		// Pick some arbitrary initial frame for the window.
		BRect initFrame(0,0,100,100);
		
		// Create our three objects: the settings view, the top-level view
		// in the window, and the window itself.
		settings = GetTermSettings(BMessenger(), BMessage());
		root = new BView(initFrame, "root", B_FOLLOW_ALL, B_WILL_DRAW);
		win = new BWindow(initFrame, "Terminal Settings",
							B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
							B_ASYNCHRONOUS_CONTROLS);
		
		// Set the background color of the root view and add it to the window.
		root->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
		win->AddChild(root);
		
		// Set the size and position of the settings view -- inset a little
		// from the root -- and add it.
		float fw = be_plain_font->StringWidth("W");
		font_height fhs;
		be_plain_font->GetHeight(&fhs);
		float fh = fhs.ascent+fhs.descent+fhs.leading;
		
		settings->MoveTo(fw, fh);
		settings->ResizeTo(initFrame.right-fw*2, initFrame.bottom-fh*2);
		root->AddChild(settings);
		
		win->Run();
		mTermWin = win;
		mTermSet = settings;
		
		if( root ) {
			// Send a message to the view with our current global settings.
			// If the view is an ArpRootView, it will get the message and
			// know what to do with it.
			const BMessage* curGlobs = this->root->Globals()->GlobalValues();
			if( curGlobs ) {
				BMessage globals(*curGlobs);
				globals.what = ARP_PREF_MSG;
				BMessage ret;
				mTermSet.SendMessage(&globals, &ret);
			}
		}
		
		// Get preferred size of settings view, and make final window dimensions
		// from this.
		float width=0, height=0;
		settings->GetPreferredSize(&width, &height);
		width += fw*2;
		height += fh*2;
		
		float minw=0,minh=0,maxw=0,maxh=0;
		win->GetSizeLimits(&minw,&maxw,&minh,&maxh);
		win->SetSizeLimits(width,maxw,height,maxh);
		
		BRect frm = Frame();
		win->ResizeTo(width, height);
		BRect cfrm = Frame();
		win->MoveTo( frm.left
					+ (frm.Width()-cfrm.Width())/2,
				 	frm.top
				 	+ (frm.Height()-cfrm.Height())/2);
		
		win->Show();
		mTermWin = win;
		mTermSet = settings;
	} catch(...) {
		delete settings;
		delete root;
		delete win;
	}
}
Exemplo n.º 5
0
void ListItemView::MessageReceived(BMessage* msg)
{

	switch (msg->what)
	{
		case SET_DRAW:
		{
			if (gFuncList->LockAsWriter())
			{
				function->SetDraw(checkBox->Value());
				gFuncList->UnlockAsWriter();
			}
		}
		break;
		case COLOR_CHG:
		{	
			const void* data;
			ssize_t size = sizeof(rgb_color);
			if (msg->FindData("color",B_RGB_COLOR_TYPE,&data,&size)== B_OK)
			{
				if (gFuncList->LockAsWriter())
				{
					function->SetColor(*(const rgb_color*)(data));
					gFuncList->UnlockAsWriter();
				}
			}
		}
		break;
		case SET_TYPE_CART:
		{
			if (gFuncList->LockAsWriter())
			{
				if (function->Type()==cart)
				{
					gFuncList->UnlockAsWriter(false);
					break;
				}
				function->SetType(cart);
				ListItemView* newItem = function->CreateListItemView(Frame(),"List Item");
				BMessenger messanger(Parent());
				BMessage viewMessage(ADD_ITEM);
				viewMessage.AddPointer("ListItemPtr",newItem);
				viewMessage.AddPointer("OldItemPtr",this);
				messanger.SendMessage(&viewMessage);
				gFuncList->UnlockAsWriter();
			}
		}
		break;		
		case SET_TYPE_PARA:
		{
			if (gFuncList->LockAsWriter())
			{
				if (function->Type()==para)
				{
					gFuncList->UnlockAsWriter(false);
					break;
				}
				function->SetType(para);
				ListItemView* newItem = function->CreateListItemView(Frame(),"List Item");
				BMessenger messanger(Parent());
				BMessage* viewMessage= new BMessage(ADD_ITEM);
				viewMessage->AddPointer("ListItemPtr",newItem);
				viewMessage->AddPointer("OldItemPtr",this);
				messanger.SendMessage(viewMessage);
				gFuncList->UnlockAsWriter();
			}
		}
		break;
		case SET_TYPE_POLAR:
		{
			if (gFuncList->LockAsWriter())
			{
				if (function->Type()==polar)
				{
					gFuncList->UnlockAsWriter(false);
					break;
				}
				function->SetType(polar);
				ListItemView* newItem = function->CreateListItemView(Frame(),"List Item");
				BMessenger messanger(Parent());
				BMessage* viewMessage= new BMessage(ADD_ITEM);
				viewMessage->AddPointer("ListItemPtr",newItem);
				viewMessage->AddPointer("OldItemPtr",this);
				messanger.SendMessage(viewMessage);
				gFuncList->UnlockAsWriter();
			}
		}
		break;		
		default:
			BView::MessageReceived(msg);
			break;
	}
}
 // CONSTRUCTORS
 Frame framevr( const Vector& v, const Rotation& r )
 {
         return Frame( r, v );
 };
Exemplo n.º 7
0
void
KernelMemoryBarMenuItem::DrawBar(bool force)
{
	bool selected = IsSelected();
	BRect frame = Frame();
	BMenu* menu = Menu();

	// draw the bar itself
	BRect cadre (frame.right - kMargin - kBarWidth, frame.top + 5,
		frame.right - kMargin, frame.top + 13);

	if (fLastSum < 0)
		force = true;
	if (force) {
		if (selected)
			menu->SetHighColor(gFrameColorSelected);
		else
			menu->SetHighColor(gFrameColor);
		menu->StrokeRect (cadre);
	}
	cadre.InsetBy(1, 1);
	BRect r = cadre;

	double grenze1 = cadre.left + (cadre.right - cadre.left)
						* fCachedMemory / fPhysicalMemory;
	double grenze2 = cadre.left + (cadre.right - cadre.left)
						* fCommittedMemory / fPhysicalMemory;
	if (grenze1 > cadre.right)
		grenze1 = cadre.right;
	if (grenze2 > cadre.right)
		grenze2 = cadre.right;
	r.right = grenze1;
	if (!force)
		r.left = fGrenze1;
	if (r.left < r.right) {
		if (selected)
			menu->SetHighColor(gKernelColorSelected);
		else
			menu->SetHighColor(gKernelColor);
//		menu->SetHighColor(gKernelColor);
		menu->FillRect (r);
	}
	r.left = grenze1;
	r.right = grenze2;
	if (!force) {
		if (fGrenze2 > r.left && r.left >= fGrenze1)
			r.left = fGrenze2;
		if (fGrenze1 < r.right && r.right <= fGrenze2)
			r.right = fGrenze1;
	}
	if (r.left < r.right) {
		if (selected)
			menu->SetHighColor(tint_color (kLavender, B_HIGHLIGHT_BACKGROUND_TINT));
		else
			menu->SetHighColor(kLavender);
//		menu->SetHighColor(gUserColor);
		menu->FillRect (r);
	}
	r.left = grenze2;
	r.right = cadre.right;
	if (!force)
		r.right = fGrenze2;
	if (r.left < r.right) {
		if (selected)
			menu->SetHighColor(gWhiteSelected);
		else
			menu->SetHighColor(kWhite);
		menu->FillRect(r);
	}
	menu->SetHighColor(kBlack);
	fGrenze1 = grenze1;
	fGrenze2 = grenze2;

	// draw the value
	double sum = fCachedMemory * FLT_MAX + fCommittedMemory;
	if (force || sum != fLastSum) {
		if (selected) {
			menu->SetLowColor(gMenuBackColorSelected);
			menu->SetHighColor(gMenuBackColorSelected);
		} else {
			menu->SetLowColor(gMenuBackColor);
			menu->SetHighColor(gMenuBackColor);
		}
		BRect trect(cadre.left - kMargin - gMemoryTextWidth, frame.top,
			cadre.left - kMargin, frame.bottom);
		menu->FillRect(trect);
		menu->SetHighColor(kBlack);

		char infos[128];
		string_for_size(fCachedMemory * 1024.0, infos, sizeof(infos));
		BPoint loc(cadre.left, cadre.bottom + 1);
		loc.x -= kMargin + gMemoryTextWidth / 2 + menu->StringWidth(infos);
		menu->DrawString(infos, loc);
		string_for_size(fCommittedMemory * 1024.0, infos, sizeof(infos));
		loc.x = cadre.left - kMargin - menu->StringWidth(infos);
		menu->DrawString(infos, loc);
		fLastSum = sum;
	}
}
Exemplo n.º 8
0
void MediaJack::_drawInto(
	BView *target,
	BRect targetRect,
	int32 layout)
{
	D_METHOD(("MediaJack::_drawInto()\n"));

	bool selected = isConnecting() || isSelected();
	switch (layout)
	{
		case MediaRoutingView::M_ICON_VIEW:
		{
			if (isInput())
			{
				BRect r;
				BPoint p;

				// fill rect
				r = targetRect;
				target->SetLowColor(M_GRAY_COLOR);
				r.left += 2.0;
				target->FillRect(r, B_SOLID_LOW);

				// draw connection point
				r = targetRect;
				p.Set(0.0, Frame().Height() / 2.0 - 2.0);
				target->BeginLineArray(4);
				{
					target->AddLine(r.LeftTop(),
									p,
									M_DARK_GRAY_COLOR);
					target->AddLine(r.LeftTop() + BPoint(1.0, 0.0),
									p + BPoint(1.0, 0.0),
									M_LIGHT_GRAY_COLOR);
					target->AddLine(p + BPoint(0.0, 5.0),
									r.LeftBottom(),
									M_DARK_GRAY_COLOR);
					target->AddLine(p + BPoint(1.0, 5.0),
									r.LeftBottom() + BPoint(1.0, 0.0),
									M_LIGHT_GRAY_COLOR);
				}
				target->EndLineArray();

				if (isConnected() || isConnecting())
				{
					target->BeginLineArray(11);
					{
						target->AddLine(p, p, M_DARK_GRAY_COLOR);
						target->AddLine(p + BPoint(0.0, 4.0), p + BPoint(0.0, 4.0), M_DARK_GRAY_COLOR);
						target->AddLine(p + BPoint(1.0, 0.0), p + BPoint(4.0, 0.0), M_DARK_GRAY_COLOR);
						target->AddLine(p + BPoint(1.0, 4.0), p + BPoint(4.0, 4.0), M_LIGHT_GRAY_COLOR);
						target->AddLine(p + BPoint(4.0, 1.0), p + BPoint(4.0, 3.0), M_LIGHT_GRAY_COLOR);
						target->AddLine(p + BPoint(0.0, 1.0), p + BPoint(2.0, 1.0), selected ? M_BLUE_COLOR : M_DARK_GRAY_COLOR);
						target->AddLine(p + BPoint(3.0, 1.0), p + BPoint(3.0, 1.0), M_MED_GRAY_COLOR);
						target->AddLine(p + BPoint(0.0, 2.0), p + BPoint(2.0, 2.0), selected ? M_LIGHT_BLUE_COLOR : M_LIGHT_GRAY_COLOR);
						target->AddLine(p + BPoint(3.0, 2.0), p + BPoint(3.0, 2.0), selected ? M_BLUE_COLOR : M_DARK_GRAY_COLOR);
						target->AddLine(p + BPoint(0.0, 3.0), p + BPoint(2.0, 3.0), selected ? M_BLUE_COLOR : M_DARK_GRAY_COLOR);
						target->AddLine(p + BPoint(3.0, 3.0), p + BPoint(3.0, 3.0), M_MED_GRAY_COLOR);
					}
					target->EndLineArray();
				}
				else
				{
					target->BeginLineArray(7);
					{
						target->AddLine(p, p + BPoint(0.0, 4.0), M_DARK_GRAY_COLOR);
						target->AddLine(p + BPoint(1.0, 0.0), p + BPoint(4.0, 0.0), M_DARK_GRAY_COLOR);
						target->AddLine(p + BPoint(1.0, 4.0), p + BPoint(4.0, 4.0), M_LIGHT_GRAY_COLOR);
						target->AddLine(p + BPoint(4.0, 1.0), p + BPoint(4.0, 3.0), M_LIGHT_GRAY_COLOR);
						target->AddLine(p + BPoint(1.0, 1.0), p + BPoint(3.0, 1.0), M_MED_GRAY_COLOR);
						target->AddLine(p + BPoint(1.0, 2.0), p + BPoint(3.0, 2.0), M_MED_GRAY_COLOR);
						target->AddLine(p + BPoint(1.0, 3.0), p + BPoint(3.0, 3.0), M_MED_GRAY_COLOR);
					}
					target->EndLineArray();
				}

				// draw abbreviation string
				BFont font(be_plain_font);
				font_height fh;
				font.SetSize(font.Size() - 2.0);
				font.GetHeight(&fh);
				p.x += 7.0;
				p.y = (Frame().Height() / 2.0) + (fh.ascent / 2.0);
				target->SetFont(&font);
				target->SetDrawingMode(B_OP_OVER);
				target->SetHighColor((isConnected() || isConnecting()) ?
									  M_MED_GRAY_COLOR :
									  M_DARK_GRAY_COLOR);
				target->DrawString(m_abbreviation.String(), p);
			}
			else if (isOutput())
			{
				BRect r;
				BPoint p;

				// fill rect
				r = targetRect;
				target->SetLowColor(M_GRAY_COLOR);
				r.right -= 2.0;
				target->FillRect(r, B_SOLID_LOW);

				// draw connection point
				r = targetRect;
				p.Set(targetRect.right - 4.0, Frame().Height() / 2.0 - 2.0);
				target->BeginLineArray(4);
				{
					target->AddLine(r.RightTop(),
									p + BPoint(4.0, 0.0),
									M_DARK_GRAY_COLOR);
					target->AddLine(r.RightTop() + BPoint(-1.0, 0.0),
									p + BPoint(3.0, 0.0),
									M_MED_GRAY_COLOR);
					target->AddLine(p + BPoint(4.0, 5.0),
									r.RightBottom(),
									M_DARK_GRAY_COLOR);
					target->AddLine(p + BPoint(3.0, 5.0),
									r.RightBottom() + BPoint(-1.0, 0.0),
									M_MED_GRAY_COLOR);
				}
				target->EndLineArray();

				if (isConnected() || isConnecting())
				{
					target->BeginLineArray(11);
					target->AddLine(p + BPoint(4.0, 0.0), p + BPoint(4.0, 0.0), M_DARK_GRAY_COLOR);
					target->AddLine(p + BPoint(4.0, 4.0), p + BPoint(4.0, 4.0), M_DARK_GRAY_COLOR);
					target->AddLine(p, p + BPoint(3.0, 0.0), M_DARK_GRAY_COLOR);
					target->AddLine(p + BPoint(0.0, 1.0), p + BPoint(0.0, 3.0), M_DARK_GRAY_COLOR);
					target->AddLine(p + BPoint(0.0, 4.0), p + BPoint(3.0, 4.0), M_LIGHT_GRAY_COLOR);
					target->AddLine(p + BPoint(1.0, 1.0), p + BPoint(1.0, 1.0), M_MED_GRAY_COLOR);
					target->AddLine(p + BPoint(2.0, 1.0), p + BPoint(4.0, 1.0), selected ? M_BLUE_COLOR : M_DARK_GRAY_COLOR);
					target->AddLine(p + BPoint(1.0, 2.0), p + BPoint(1.0, 2.0), selected ? M_BLUE_COLOR : M_DARK_GRAY_COLOR);
					target->AddLine(p + BPoint(2.0, 2.0), p + BPoint(4.0, 2.0), selected ? M_LIGHT_BLUE_COLOR : M_LIGHT_GRAY_COLOR);
					target->AddLine(p + BPoint(1.0, 3.0), p + BPoint(1.0, 3.0), M_MED_GRAY_COLOR);
					target->AddLine(p + BPoint(2.0, 3.0), p + BPoint(4.0, 3.0), selected ? M_BLUE_COLOR : M_DARK_GRAY_COLOR);
					target->EndLineArray();
				}
				else
				{
					target->BeginLineArray(7);
					target->AddLine(p + BPoint(4.0, 0.0), p + BPoint(4.0, 4.0), M_DARK_GRAY_COLOR);
					target->AddLine(p, p + BPoint(3.0, 0.0), M_DARK_GRAY_COLOR);
					target->AddLine(p + BPoint(0.0, 1.0), p + BPoint(0.0, 3.0), M_DARK_GRAY_COLOR);
					target->AddLine(p + BPoint(0.0, 4.0), p + BPoint(3.0, 4.0), M_LIGHT_GRAY_COLOR);
					target->AddLine(p + BPoint(1.0, 1.0), p + BPoint(3.0, 1.0), M_MED_GRAY_COLOR);
					target->AddLine(p + BPoint(1.0, 2.0), p + BPoint(3.0, 2.0), M_MED_GRAY_COLOR);
					target->AddLine(p + BPoint(1.0, 3.0), p + BPoint(3.0, 3.0), M_MED_GRAY_COLOR);
					target->EndLineArray();
				}

				// draw abbreviation string
				BFont font(be_plain_font);
				font_height fh;
				font.SetSize(font.Size() - 2.0);
				font.GetHeight(&fh);
				p.x -= font.StringWidth(m_abbreviation.String()) + 2.0;
				p.y = (Frame().Height() / 2.0) + (fh.ascent / 2.0);
				target->SetFont(&font);
				target->SetDrawingMode(B_OP_OVER);
				target->SetHighColor((isConnected() || isConnecting()) ?
									  M_MED_GRAY_COLOR :
									  M_DARK_GRAY_COLOR);
				target->DrawString(m_abbreviation.String(), p);
			}
			break;
		}
		case MediaRoutingView::M_MINI_ICON_VIEW:
		{
			if (isInput())
			{
				BRect r;
				BPoint p;

				// fill rect
				r = targetRect;
				target->SetLowColor(M_GRAY_COLOR);
				r.top += 2.0;
				target->FillRect(r, B_SOLID_LOW);

				// draw connection point
				r = targetRect;
				p.Set(Frame().Width() / 2.0 - 2.0, 0.0);
				target->BeginLineArray(4);
				{
					target->AddLine(r.LeftTop(),
									p,
									M_DARK_GRAY_COLOR);
					target->AddLine(r.LeftTop() + BPoint(0.0, 1.0),
									p + BPoint(0.0, 1.0),
									M_LIGHT_GRAY_COLOR);
					target->AddLine(p + BPoint(5.0, 0.0),
									r.RightTop(),
									M_DARK_GRAY_COLOR);
					target->AddLine(p + BPoint(5.0, 1.0),
									r.RightTop() + BPoint(0.0, 1.0),
									M_LIGHT_GRAY_COLOR);
				}
				target->EndLineArray();
				if (isConnected() || isConnecting())
				{
					target->BeginLineArray(11);
					target->AddLine(p, p, M_DARK_GRAY_COLOR);
					target->AddLine(p + BPoint(4.0, 0.0), p + BPoint(4.0, 0.0), M_DARK_GRAY_COLOR);
					target->AddLine(p + BPoint(0.0, 1.0), p + BPoint(0.0, 4.0), M_DARK_GRAY_COLOR);
					target->AddLine(p + BPoint(4.0, 1.0), p + BPoint(4.0, 4.0), M_LIGHT_GRAY_COLOR);
					target->AddLine(p + BPoint(1.0, 4.0), p + BPoint(3.0, 4.0), M_LIGHT_GRAY_COLOR);
					target->AddLine(p + BPoint(1.0, 0.0), p + BPoint(1.0, 2.0), selected ? M_BLUE_COLOR : M_DARK_GRAY_COLOR);
					target->AddLine(p + BPoint(1.0, 3.0), p + BPoint(1.0, 3.0), M_MED_GRAY_COLOR);
					target->AddLine(p + BPoint(2.0, 0.0), p + BPoint(2.0, 2.0), selected ? M_LIGHT_BLUE_COLOR : M_LIGHT_GRAY_COLOR);
					target->AddLine(p + BPoint(2.0, 3.0), p + BPoint(2.0, 3.0), selected ? M_BLUE_COLOR : M_DARK_GRAY_COLOR);
					target->AddLine(p + BPoint(3.0, 0.0), p + BPoint(3.0, 2.0), selected ? M_BLUE_COLOR : M_DARK_GRAY_COLOR);
					target->AddLine(p + BPoint(3.0, 3.0), p + BPoint(3.0, 3.0), M_MED_GRAY_COLOR);
					target->EndLineArray();
				}
				else
				{
					target->BeginLineArray(7);
					target->AddLine(p, p + BPoint(4.0, 0.0), M_DARK_GRAY_COLOR);
					target->AddLine(p + BPoint(0.0, 1.0), p + BPoint(0.0, 4.0), M_DARK_GRAY_COLOR);
					target->AddLine(p + BPoint(4.0, 1.0), p + BPoint(4.0, 4.0), M_LIGHT_GRAY_COLOR);
					target->AddLine(p + BPoint(1.0, 4.0), p + BPoint(3.0, 4.0), M_LIGHT_GRAY_COLOR);
					target->AddLine(p + BPoint(1.0, 1.0), p + BPoint(1.0, 3.0), M_MED_GRAY_COLOR);
					target->AddLine(p + BPoint(2.0, 1.0), p + BPoint(2.0, 3.0), M_MED_GRAY_COLOR);
					target->AddLine(p + BPoint(3.0, 1.0), p + BPoint(3.0, 3.0), M_MED_GRAY_COLOR);
					target->EndLineArray();
				}
			}
			else if (isOutput())
			{
				BRect r = targetRect;
				BPoint p;

				// fill rect
				r = targetRect;
				target->SetLowColor(M_GRAY_COLOR);
				r.bottom -= 2.0;
				target->FillRect(r, B_SOLID_LOW);

				// draw connection point
				r = targetRect;
				p.Set(Frame().Width() / 2.0 - 2.0, targetRect.bottom - 4.0);
				target->BeginLineArray(4);
				{
					target->AddLine(r.LeftBottom(),
									p + BPoint(0.0, 4.0),
									M_DARK_GRAY_COLOR);
					target->AddLine(r.LeftBottom() + BPoint(0.0, -1.0),
									p + BPoint(0.0, 3.0),
									M_MED_GRAY_COLOR);
					target->AddLine(p + BPoint(5.0, 4.0),
									r.RightBottom(),
									M_DARK_GRAY_COLOR);
					target->AddLine(p + BPoint(5.0, 3.0),
									r.RightBottom() + BPoint(0.0, -1.0),
									M_MED_GRAY_COLOR);
				}
				target->EndLineArray();
				if (isConnected() || isConnecting())
				{
					target->BeginLineArray(11);
					target->AddLine(p + BPoint(0.0, 4.0), p + BPoint(0.0, 4.0), M_DARK_GRAY_COLOR);
					target->AddLine(p + BPoint(4.0, 4.0), p + BPoint(4.0, 4.0), M_DARK_GRAY_COLOR);
					target->AddLine(p, p + BPoint(0.0, 3.0), M_DARK_GRAY_COLOR);
					target->AddLine(p + BPoint(1.0, 0.0), p + BPoint(3.0, 0.0), M_DARK_GRAY_COLOR);
					target->AddLine(p + BPoint(4.0, 0.0), p + BPoint(4.0, 3.0), M_LIGHT_GRAY_COLOR);
					target->AddLine(p + BPoint(1.0, 1.0), p + BPoint(1.0, 1.0), M_MED_GRAY_COLOR);
					target->AddLine(p + BPoint(1.0, 2.0), p + BPoint(1.0, 4.0), selected ? M_BLUE_COLOR : M_DARK_GRAY_COLOR);
					target->AddLine(p + BPoint(2.0, 1.0), p + BPoint(2.0, 1.0), selected ? M_BLUE_COLOR : M_DARK_GRAY_COLOR);
					target->AddLine(p + BPoint(2.0, 2.0), p + BPoint(2.0, 4.0), selected ? M_LIGHT_BLUE_COLOR : M_LIGHT_GRAY_COLOR);
					target->AddLine(p + BPoint(3.0, 1.0), p + BPoint(3.0, 1.0), M_MED_GRAY_COLOR);
					target->AddLine(p + BPoint(3.0, 2.0), p + BPoint(3.0, 4.0), selected ? M_BLUE_COLOR : M_DARK_GRAY_COLOR);
					target->EndLineArray();
				}
				else
				{
					target->BeginLineArray(7);
					target->AddLine(p + BPoint(0.0, 4.0), p + BPoint(4.0, 4.0), M_DARK_GRAY_COLOR);
					target->AddLine(p, p + BPoint(0.0, 3.0), M_DARK_GRAY_COLOR);
					target->AddLine(p + BPoint(1.0, 0.0), p + BPoint(3.0, 0.0), M_DARK_GRAY_COLOR);
					target->AddLine(p + BPoint(4.0, 0.0), p + BPoint(4.0, 3.0), M_LIGHT_GRAY_COLOR);
					target->AddLine(p + BPoint(1.0, 1.0), p + BPoint(1.0, 3.0), M_MED_GRAY_COLOR);
					target->AddLine(p + BPoint(2.0, 1.0), p + BPoint(2.0, 3.0), M_MED_GRAY_COLOR);
					target->AddLine(p + BPoint(3.0, 1.0), p + BPoint(3.0, 3.0), M_MED_GRAY_COLOR);
					target->EndLineArray();
				}
			}
			break;
		}
	}
}
Exemplo n.º 9
0
CatBrowser::CatBrowser(const BRect &frame, const BMessenger &msgr,
						const char *category, bool editmode)
 :	BWindow(frame,"Recipe Browser",B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS),
 	fMessenger(msgr),
 	fCategoryCount(-1),
 	fCurrentPage(-1),
 	fEditMode(editmode)
{
	AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED));
	AddShortcut('Q', B_COMMAND_KEY, new BMessage(M_QUIT_APP));
	
	BView *back = new BView(Bounds(),"back",B_FOLLOW_ALL, B_WILL_DRAW);
	back->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	AddChild(back);
	
	fCategories = new BMenu("Categories");
	CppSQLite3Query query = DBQuery("select category from categories order by category;",
									"FindWindow:get categories");
	while(!query.eof())
	{
		BString cat(DeescapeIllegalCharacters(query.getStringField(0)));
		fCategories->AddItem(new BMenuItem(cat.String(),new BMessage(M_SET_CATEGORY)));
		query.nextRow();
	}
	fCategories->SetRadioMode(true);
	fCategories->SetLabelFromMarked(true);
	if(fCategories->CountItems()>0)
		fCategories->ItemAt(0)->SetMarked(true);
	BRect r(10,10,10 + fCategories->MaxContentWidth(),11);
	BMenuField *field = new BMenuField(r,"field","Category",fCategories);
	back->AddChild(field);
	field->ResizeToPreferred();
	r = field->Frame();
	
	BMenuItem *marked = fCategories->FindItem(category);
	if(marked)
		marked->SetMarked(true);
	
	r.OffsetBy(0,r.Height() + 10);
	r.right = Bounds().right - 10 - B_V_SCROLL_BAR_WIDTH;
	r.bottom = Bounds().bottom - 10;
	
	fList = new BListView(r, "newlist", B_SINGLE_SELECTION_LIST, B_FOLLOW_ALL);
	fList->SetInvocationMessage(new BMessage(M_SET_RECIPE));
	BScrollView *newscroll = new BScrollView("newscroll",fList,
											B_FOLLOW_ALL, 0, false, true);
	back->AddChild(newscroll);
	
	fBack = new BButton(BRect(10,10,11,11),"back","Back", new BMessage(M_RESULTS_BACK),
					B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW);
	fBack->ResizeToPreferred();
	fBack->ResizeTo(be_plain_font->StringWidth("Back") + 15,fBack->Frame().Height());
	fBack->MoveTo(10,Bounds().bottom - fBack->Bounds().Height() - 10);
	r = fBack->Frame();
	back->AddChild(fBack);
	fBack->SetEnabled(false);
	
	r.OffsetBy(r.Width() + 5, 0);
	fNext = new BButton(r,"next","Next", new BMessage(M_RESULTS_NEXT),
					B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW);
	back->AddChild(fNext);
	fNext->SetEnabled(false);
	
	fClose = new BButton(BRect(10,10,11,11),"close","View Recipe", new BMessage(B_QUIT_REQUESTED),
					B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM, B_WILL_DRAW);
	fClose->ResizeToPreferred();
	fClose->SetLabel("Close");
	fClose->MoveTo(Bounds().right - fClose->Bounds().Width() - 10,r.top);
	r = fClose->Frame();
	fClose->MakeDefault(true);
	
	r.OffsetBy(-r.Width() - 10, 0);
	fOpen = new BButton(r,"openrecipe","View Recipe",new BMessage(M_SET_RECIPE),
						B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM, B_WILL_DRAW);
	
	back->AddChild(fOpen);
	back->AddChild(fClose);
	
	fList->MakeFocus(true);
	
	r = fList->Parent()->Frame();
	r.bottom = fClose->Frame().top - 10;
	fList->Parent()->ResizeTo(r.Width(),r.Height());
	
	float controlwidth = (fBack->Frame().Width() * 2) + (fOpen->Frame().Width() * 2) + 65;
	if( Frame().Width() < controlwidth )
		ResizeTo(controlwidth, Frame().Height());
	
	if(fEditMode)
	{
		// This hidden mode (Command-Click on the browser menu item) is for doing
		// massive edits on the database
		fList->SetListType(B_MULTIPLE_SELECTION_LIST);
		fList->SetSelectionMessage(new BMessage(M_SET_RECIPE));
		
		BMenu *editmenu = new BMenu("Edit");
		editmenu->AddItem(new BMenuItem("Mass Recategorize",new BMessage(M_SHOW_RECAT)));
		editmenu->AddItem(new BMenuItem("Delete Recipe",new BMessage(M_DELETE_RECIPE)));
		
		r.Set(10,10,10 + be_plain_font->StringWidth("Edit") + 25,11);
		r.OffsetTo(Bounds().right - 10 - r.Width(), 10);
		BMenuField *editfield = new BMenuField(r,"editfield","Edit",editmenu,
											B_FOLLOW_RIGHT | B_FOLLOW_TOP);
		editfield->SetDivider(0);
		back->AddChild(editfield);
		
		fSortString = " order by number ";
	}
	
	PostMessage(M_SET_CATEGORY);
}
Exemplo n.º 10
0
// moved into a helper function to ensure args is destroyed before
// exit(), which may result in a memory leak.
static void RunGameOrAtlas(int argc, const char* argv[])
{
	CmdLineArgs args(argc, argv);

	g_args = args;

	// We need to initialise libxml2 in the main thread before
	// any thread uses it. So initialise it here before we
	// might run Atlas.
	CXeromyces::Startup();

	// run Atlas (if requested via args)
	bool ran_atlas = ATLAS_RunIfOnCmdLine(args, false);
	// Atlas handles the whole init/shutdown/etc sequence by itself;
	// when we get here, it has exited and we're done.
	if(ran_atlas)
		return;

	// run non-visual simulation replay if requested
	if (args.Has("replay"))
	{
		std::string replayFile = args.Get("replay");
		if (!FileExists(OsPath(replayFile)))
		{
			debug_printf("ERROR: The requested replay file '%s' does not exist!\n", replayFile.c_str());
			return;
		}
		Paths paths(args);
		g_VFS = CreateVfs(20 * MiB);
		g_VFS->Mount(L"cache/", paths.Cache(), VFS_MOUNT_ARCHIVABLE);
		MountMods(paths, GetMods(args, INIT_MODS));

		{
			CReplayPlayer replay;
			replay.Load(replayFile);
			replay.Replay(args.Has("serializationtest"), args.Has("ooslog"));
		}

		g_VFS.reset();

		CXeromyces::Terminate();
		return;
	}

	// If visual replay file does not exist, quit before starting the renderer
	if (args.Has("replay-visual"))
	{
		std::string replayFile = args.Get("replay-visual");
		if (!FileExists(OsPath(replayFile)))
		{
			debug_printf("ERROR: The requested replay file '%s' does not exist!\n", replayFile.c_str());
			return;
		}
	}

	// run in archive-building mode if requested
	if (args.Has("archivebuild"))
	{
		Paths paths(args);

		OsPath mod(args.Get("archivebuild"));
		OsPath zip;
		if (args.Has("archivebuild-output"))
			zip = args.Get("archivebuild-output");
		else
			zip = mod.Filename().ChangeExtension(L".zip");

		CArchiveBuilder builder(mod, paths.Cache());

		// Add mods provided on the command line
		// NOTE: We do not handle mods in the user mod path here
		std::vector<CStr> mods = args.GetMultiple("mod");
		for (size_t i = 0; i < mods.size(); ++i)
			builder.AddBaseMod(paths.RData()/"mods"/mods[i]);

		builder.Build(zip, args.Has("archivebuild-compress"));

		CXeromyces::Terminate();
		return;
	}

	const double res = timer_Resolution();
	g_frequencyFilter = CreateFrequencyFilter(res, 30.0);

	// run the game
	int flags = INIT_MODS;
	do
	{
		restart = false;
		quit = false;
		if (!Init(args, flags))
		{
			flags &= ~INIT_MODS;
			Shutdown(SHUTDOWN_FROM_CONFIG);
			continue;
		}
		InitGraphics(args, 0);
		MainControllerInit();
		while (!quit)
			Frame();
		Shutdown(0);
		MainControllerShutdown();
		flags &= ~INIT_MODS;
	} while (restart);

	if (restart_in_atlas)
	{
		ATLAS_RunIfOnCmdLine(args, true);
		return;
	}

	// Shut down libxml2 (done here to match the Startup call)
	CXeromyces::Terminate();
}
Exemplo n.º 11
0
void CatBrowser::MessageReceived(BMessage *msg)
{
	switch(msg->what)
	{
		case M_QUIT_APP:
		{
			be_app->PostMessage(B_QUIT_REQUESTED);
			break;
		}
		case M_SET_CATEGORY:
		{
			BMenuItem *marked = fCategories->FindMarked();
			if(!marked)
				break;
			else
				fCategory = marked->Label();
			fBack->SetEnabled(false);
			SetupQuery();
			RunQuery();
			
			if(fPageCount < 2)
				fNext->SetEnabled(false);
			else
				fNext->SetEnabled(true);
			break;
		}
		case M_RESULTS_BACK:
		{
			if(fCurrentPage > 0)
			{
				fCurrentPage--;
				RunQuery();
			}
			if(fCurrentPage < fPageCount - 1)
				fNext->SetEnabled(true);
			
			if(fCurrentPage == 0)
				fBack->SetEnabled(false);
			break;
		}
		case M_RESULTS_NEXT:
		{
			if(fCurrentPage < fPageCount - 1)
			{
				fCurrentPage++;
				if(fCurrentPage >= fPageCount - 1)
					fNext->SetEnabled(false);
				
				RunQuery();
			}
			
			if(!fBack->IsEnabled())
				fBack->SetEnabled(true);
			break;
		}
		case M_RECATEGORIZE_RECIPE:
		{
			int32 number;
			BString oldcat, newcat;
			msg->FindInt32("number",&number);
			msg->FindString("oldcategory",&oldcat);
			msg->FindString("newcategory",&newcat);
			
			int32 index = 0, selection;
			DBCommand("BEGIN","CatBrowser:begin mass recat");
			BeginViewTransaction();
			do
			{
				selection = fList->CurrentSelection(index);
				index++;
				if(selection >=0)
				{
					RecipeItem *item = (RecipeItem*)fList->ItemAt(selection);
					if(item)
					{
						ChangeCategory(item->fNumber, item->fCategory.String(),
										newcat.String());
					}
				}
				
			} while(selection >= 0);
			EndViewTransaction();
			DBCommand("COMMIT","ChefView:end mass recat");
			SetupQuery();
			RunQuery();
			break;
		}
		case M_SHOW_RECAT:
		{
			int32 selection, firstselection, count=0;
			firstselection = selection = fList->CurrentSelection();
			if(selection < 0)
				break;
			count++;
			
			do
			{
				selection = fList->CurrentSelection(count);
				if(selection >= 0)
					count++;
			} while (selection >= 0);
			
			RecipeItem *item = (RecipeItem*)fList->ItemAt(firstselection);
			if(item)
			{
				BRect r(Frame().OffsetByCopy(20,20));
				r.right = r.left + 300;
				r.bottom = r.top + 200;
				RecatWindow *win = new RecatWindow(r,BMessenger(this), 
												(count>1) ? -1 : item->fNumber,
												item->fCategory.String());
				win->AddToSubset(this);
				win->Show();
			}
			break;
		}
		case M_DELETE_RECIPE:
		{
			int32 index = 0, selection;
			DBCommand("BEGIN","CatBrowser:begin mass delete");
			BeginViewTransaction();
			do
			{
				selection = fList->CurrentSelection(index);
				index++;
				if(selection >=0)
				{
					RecipeItem *item = (RecipeItem*)fList->ItemAt(selection);
					if(item)
						DeleteRecipe(item->fNumber, item->fCategory.String());
				}
				
			} while(selection >= 0);
			EndViewTransaction();
			DBCommand("COMMIT","ChefView:end mass recat");
			SetupQuery();
			RunQuery();
			
			// refresh the display in the main window in case we deleted something
			// that would be in the results
			BMessage msg(M_FIND_RECIPE);
			fMessenger.SendMessage(&msg);
			break;
		}
		case M_SET_RECIPE:
		{
			if(fEditMode)
			{
				if(fList->CurrentSelection(1)>=0)
					break;
			}
			
			RecipeItem *item = (RecipeItem*)fList->ItemAt(fList->CurrentSelection());
			if(item)
			{
				BMessage msg(M_LOOKUP_RECIPE);
				msg.AddInt32("number",item->fNumber);
				msg.AddString("category",item->fCategory);
				msg.AddString("name",item->fName);
				fMessenger.SendMessage(&msg);
			}
			break;
		}
		default:
			BWindow::MessageReceived(msg);
	}
}
Exemplo n.º 12
0
// moved into a helper function to ensure args is destroyed before
// exit(), which may result in a memory leak.
static void RunGameOrAtlas(int argc, const char* argv[])
{
	CmdLineArgs args(argc, argv);

	// We need to initialise libxml2 in the main thread before
	// any thread uses it. So initialise it here before we
	// might run Atlas.
	CXeromyces::Startup();

	// run Atlas (if requested via args)
	bool ran_atlas = ATLAS_RunIfOnCmdLine(args, false);
	// Atlas handles the whole init/shutdown/etc sequence by itself;
	// when we get here, it has exited and we're done.
	if(ran_atlas)
		return;

	// run non-visual simulation replay if requested
	if (args.Has("replay"))
	{
		snd_disable(true);

		Paths paths(args);
		g_VFS = CreateVfs(20 * MiB);
		g_VFS->Mount(L"cache/", paths.Cache(), VFS_MOUNT_ARCHIVABLE);
		g_VFS->Mount(L"", paths.RData()/"mods"/"public", VFS_MOUNT_MUST_EXIST);

		{
			CReplayPlayer replay;
			replay.Load(args.Get("replay"));
			replay.Replay();
		}

		g_VFS.reset();

		CXeromyces::Terminate();
		return;
	}

	// run in archive-building mode if requested
	if (args.Has("archivebuild"))
	{
		Paths paths(args);

		OsPath mod(args.Get("archivebuild"));
		OsPath zip;
		if (args.Has("archivebuild-output"))
			zip = args.Get("archivebuild-output");
		else
			zip = mod.Filename().ChangeExtension(L".zip");

		CArchiveBuilder builder(mod, paths.Cache());
		builder.Build(zip, args.Has("archivebuild-compress"));

		CXeromyces::Terminate();
		return;
	}

	const double res = timer_Resolution();
	g_frequencyFilter = CreateFrequencyFilter(res, 30.0);

	// run the game
	Init(args, 0);
	InitGraphics(args, 0);
	MainControllerInit();
	while(!quit)
		Frame();
	Shutdown(0);
	ScriptingHost::FinalShutdown(); // this can't go in Shutdown() because that could be called multiple times per process, so stick it here instead
	MainControllerShutdown();

	if (restart_in_atlas)
	{
		ATLAS_RunIfOnCmdLine(args, true);
		return;
	}

	// Shut down libxml2 (done here to match the Startup call)
	CXeromyces::Terminate();
}
Exemplo n.º 13
0
JSlidePiece::JSlidePiece()
{
    m_pSlideGame        = NULL;
    SetFocusable( true );
    SetExt( Frame( 0.0f, 0.0f, 140.0f, 130.0f ) );
} // JSlidePiece::JSlidePiece
Exemplo n.º 14
0
BPoint MediaJack::connectionPoint() const
{
	D_METHOD(("MediaJack::connectionPoint()\n"));

	switch (dynamic_cast<MediaRoutingView *>(view())->getLayout())
	{
		case MediaRoutingView::M_ICON_VIEW:
		{
			if (isInput())
			{
				return BPoint(Frame().left - 1.0, Frame().top + Frame().Height() / 2.0);
			}
			else if (isOutput())
			{
				return BPoint(Frame().right + 1.0, Frame().top + Frame().Height() / 2.0);
			}
			break;
		}
		case MediaRoutingView::M_MINI_ICON_VIEW:
		{
			if (isInput())
			{
				return BPoint(Frame().left + Frame().Width() / 2.0, Frame().top - 1.0);
			}
			else if (isOutput())
			{
				return BPoint(Frame().left + Frame().Width() / 2.0, Frame().bottom + 1.0);
			}
			break;
		}
	}
	return BPoint(-1.0, -1.0);
}
Exemplo n.º 15
0
Win::Win(
	BRect frame,
	const char *title,
	window_type type,
	uint32 flags,
	uint32 wspace )
    : BWindow( frame, title, type, flags, wspace ), MessageSystem("Themis Window")
{
	MsgSysRegister(this);
	// size limits
	BScreen Screen;
	SetSizeLimits( 300, Screen.Frame().right, 200, Screen.Frame().bottom );
	
	protocol=0;
	startup=true;
	urlpopupwindow = NULL;
	fNextWindow = NULL;
	fOldFrame = Frame();
	fMaximized = false;
	fQuitConfirmed = false;

	LoadInterfaceGraphics();
	
	BRect rect;
	rect = Bounds();
	
	// lets add a menubar
	menubar = new BMenuBar( BRect(0,0,0,0), "MENUBAR" );
	AddChild( menubar );
	
	// menu messages
	BMessage* tabaddmsg = new BMessage( TAB_ADD );
	tabaddmsg->AddBool( "force_non_hidden", true );
		
	// filemenu
	filemenu = new BMenu( "File" );
	menubar->AddItem( filemenu );
	BMenuItem* newwinitem = new BMenuItem( "New Window", new BMessage( WINDOW_NEW ), 'N');
	filemenu->AddItem( newwinitem );
	BMenuItem* newtabitem = new BMenuItem( "New Tab", tabaddmsg, 'T' );
	filemenu->AddItem( newtabitem );
	BMenuItem* aboutitem = new BMenuItem( "About Themis", new BMessage( B_ABOUT_REQUESTED ), 'A', B_SHIFT_KEY );
	filemenu->AddItem( aboutitem );
	BMenuItem* quitwentry = new BMenuItem( "Close Window", new BMessage( B_QUIT_REQUESTED ), 'W' );
	filemenu->AddItem( quitwentry );
	BMenuItem* quitentry = new BMenuItem( "Quit Themis", new BMessage( B_QUIT_REQUESTED ), 'Q' );
	filemenu->AddItem( quitentry );
	quitentry->SetTarget( be_app );

	// optionsmenu
	optionsmenu=new BMenu( "Options" );
	menubar->AddItem(optionsmenu);
	BMenuItem* prefsentry = new BMenuItem( "Preferences", new BMessage( PREFSWIN_SHOW ), 'P' );
	prefsentry->SetTarget( be_app );
	optionsmenu->AddItem( prefsentry );
	
		
	// now we need the navigation view
	navview = new ThemisNavView(
		BRect( rect.left, menubar->Bounds().Height() + 1,
			rect.right,	menubar->Bounds().Height() + 31 ) );
	AddChild( navview );
	
	// and finally the statusview at the bottom
	statusview = new ThemisStatusView(
		BRect(
			rect.left,
			rect.bottom - 13,	// heigth of the lower-right doc-view corner
			rect.right,			// - 13 taken out because of dano decors
			rect.bottom ) );
	AddChild( statusview );
	
	// the tabview-system comes last as we need the height of the statusview
	CreateTabView();
	
	// make the urlview the focusview for fast pasting :D
	if( CurrentFocus() != NULL )
		CurrentFocus()->MakeFocus( false );
	navview->urlview->TextView()->MakeFocus( true );
}
Exemplo n.º 16
0
void MediaJack::disconnected()
{
	D_METHOD(("MediaJack::disconnected()\n"));
	_updateBitmap();
	view()->Invalidate(Frame());
}
Exemplo n.º 17
0
void
Win::Zoom( BPoint origin, float width, float height )
{
	bool IM = false;
	AppSettings->FindBool( kPrefsIntelligentZoom, &IM );
	
	if( IM == true )
	{
		if( fMaximized == false )
		{
			fOldFrame = Frame();
			
			BScreen screen;
			BDeskbar deskbar;
			BRect dbframe = deskbar.Frame();
		
			switch( deskbar.Location() )
			{
				case B_DESKBAR_TOP :
				{
					origin.y += dbframe.Height() + 2;
					break;
				}
				case B_DESKBAR_BOTTOM :
				{
					height -= dbframe.Height() + 2;
					break;
				}
				case B_DESKBAR_LEFT_BOTTOM :
				{
					origin.x += dbframe.Width() + 2;
					width -= dbframe.right + 2;
					break;
				}
				case B_DESKBAR_RIGHT_BOTTOM :
				{
					width = dbframe.left - origin.x - 7;
					break;
				}
				case B_DESKBAR_LEFT_TOP :
				{
					origin.x += dbframe.Width() + 2;
					width -= dbframe.right + 2;
					break;
				}
				case B_DESKBAR_RIGHT_TOP :
				{
					width = dbframe.left - origin.x - 7;
					break;
				}
			}
						
			fMaximized = true;
			
			BWindow::Zoom( origin, width, height );
		}
		else
		{
			origin = fOldFrame.LeftTop();
			width = fOldFrame.right - fOldFrame.left;
			height = fOldFrame.bottom - fOldFrame.top;
			
			fMaximized = false;
			
			BWindow::Zoom( origin, width, height );
		}
	}
	else
		BWindow::Zoom( origin, width, height );
}
Exemplo n.º 18
0
ListItemView::ListItemView(BRect frame, const char* name, FunctionItem* func):
			BView(frame, name, B_FOLLOW_LEFT|B_FOLLOW_TOP,0)
{
	//gFuncList had better already be locked!!
	rgb_color background;
	background.red = 216;
	background.green = 216;
	background.blue = 216;
	background.alpha = 255;
	SetViewColor(background);

	function=func;
	
	BRect rect;

	
	rect = Bounds();
	
	box = new BBox(rect, "box", B_FOLLOW_ALL_SIDES,
				   B_WILL_DRAW|B_FRAME_EVENTS|B_NAVIGABLE_JUMP,
				   B_PLAIN_BORDER);
	AddChild(box);
	
	rect.InsetBy(5,5);
	
	checkBox = new BCheckBox(rect, "Draw", "Draw", new BMessage(SET_DRAW),
														B_FOLLOW_LEFT|B_FOLLOW_BOTTOM);
	checkBox->ResizeToPreferred();
	checkBox->SetValue(func->ShouldDraw());
	box->AddChild(checkBox);
	
	rect.left = checkBox->Frame().right+4;
	rect.top = checkBox->Frame().top;
	rect.bottom = checkBox->Frame().bottom;
	rect.right = checkBox->Frame().Height() + rect.left;
	
	rect.InsetBy(4,4);
	patch = new class ColorPatch(rect,"patch",func->Color(),B_FOLLOW_LEFT|B_FOLLOW_BOTTOM);
	box->AddChild(patch);
	
	rect.left = patch->Frame().right+4;
	rect.top = checkBox->Frame().top;
	rect.bottom = rect.top+1;
	rect.right = rect.left+1;
	
	menuField=	new BMenuField(rect, "Type Menu","Type:",new FunctionTypePopup,B_FOLLOW_LEFT|
																B_FOLLOW_BOTTOM);
	box->AddChild(menuField);
	
	float width;
	float cbheight;
	float mfheight;
	
	checkBox->GetPreferredSize(&width, &cbheight);
	menuField->MenuBar()->GetPreferredSize(&width,&mfheight);
	//This is a correction for the extra pixals that the menuField draws
	mfheight+=4;
	
	ResizeTo(Frame().Width(), max(mfheight,cbheight)+5+5); //calculates the height, including a 5 pixel border on the top and bottom
	box->ResizeTo(Frame().Width(), Frame().Height());
	
}
Exemplo n.º 19
0
	void handle(const ZhttpRequestPacket &packet)
	{
		if(packet.type == ZhttpRequestPacket::Error)
		{
			errorCondition = convertError(packet.condition);

			log_debug("zws server: error id=%s cond=%s", packet.id.data(), packet.condition.data());

			state = Idle;
			cleanup();
			emit q->error();
			return;
		}
		else if(packet.type == ZhttpRequestPacket::Cancel)
		{
			log_debug("zws server: received cancel id=%s", packet.id.data());

			errorCondition = ErrorGeneric;
			state = Idle;
			cleanup();
			emit q->error();
			return;
		}

		if(packet.seq != inSeq)
		{
			log_warning("zws server: error id=%s received message out of sequence, canceling", packet.id.data());

			tryRespondCancel(packet);

			state = Idle;
			errorCondition = ErrorGeneric;
			cleanup();
			emit q->error();
			return;
		}

		++inSeq;

		refreshTimeout();

		if(packet.type == ZhttpRequestPacket::Data || packet.type == ZhttpRequestPacket::Ping || packet.type == ZhttpRequestPacket::Pong)
		{
			if(inSize + packet.body.size() > IDEAL_CREDITS)
				log_warning("zws client: id=%s server is sending too fast", packet.id.data());

			if(packet.type == ZhttpRequestPacket::Data)
			{
				handleIncomingDataPacket(packet.contentType, packet.body, packet.more);
			}
			else if(packet.type == ZhttpRequestPacket::Ping)
			{
				inFrames += Frame(Frame::Ping, packet.body, false);
				inSize += packet.body.size();
			}
			else if(packet.type == ZhttpRequestPacket::Pong)
			{
				inFrames += Frame(Frame::Pong, packet.body, false);
				inSize += packet.body.size();
			}

			if(packet.credits > 0)
			{
				outCredits += packet.credits;
				if(outCredits > 0)
				{
					// try to write anything that was waiting on credits
					QPointer<QObject> self = this;
					tryWrite();
					if(!self)
						return;
				}
			}

			emit q->readyRead();
		}
		else if(packet.type == ZhttpRequestPacket::Close)
		{
			handlePeerClose(packet.code);
		}
		else if(packet.type == ZhttpRequestPacket::Credit)
		{
			if(packet.credits > 0)
			{
				outCredits += packet.credits;
				tryWrite();
			}
		}
		else if(packet.type == ZhttpRequestPacket::KeepAlive)
		{
			// nothing to do
		}
		else
		{
			log_debug("zws server: unsupported packet type id=%s type=%d", packet.id.data(), (int)packet.type);
		}
	}
Exemplo n.º 20
0
 virtual void Paint(nsDisplayListBuilder* aBuilder,
                    nsRenderingContext* aCtx) {
   nsListControlFrame* listFrame = GetEnclosingListFrame(Frame());
   // listFrame must be non-null or we wouldn't get called.
   listFrame->PaintFocus(*aCtx, aBuilder->ToReferenceFrame(listFrame));
 }
Exemplo n.º 21
0
	void handle(const ZhttpResponsePacket &packet)
	{
		if(packet.type == ZhttpResponsePacket::Error)
		{
			errorCondition = convertError(packet.condition);

			log_debug("zws client: error id=%s cond=%s", packet.id.data(), packet.condition.data());

			responseCode = packet.code;
			responseReason = packet.reason;
			responseHeaders = packet.headers;
			responseBody = packet.body;

			state = Idle;
			cleanup();
			emit q->error();
			return;
		}
		else if(packet.type == ZhttpResponsePacket::Cancel)
		{
			log_debug("zws client: received cancel id=%s", packet.id.data());

			errorCondition = ErrorGeneric;
			state = Idle;
			cleanup();
			emit q->error();
			return;
		}

		if(!packet.from.isEmpty())
			toAddress = packet.from;

		if(packet.seq != inSeq)
		{
			log_warning("zws client: error id=%s received message out of sequence, canceling", packet.id.data());

			tryRespondCancel(packet);

			state = Idle;
			errorCondition = ErrorGeneric;
			cleanup();
			emit q->error();
			return;
		}

		if(!toAddress.isEmpty() && !keepAliveTimer->isActive())
			startKeepAlive();

		++inSeq;

		refreshTimeout();

		if(state == Connecting)
		{
			if(packet.type != ZhttpResponsePacket::Data && packet.type != ZhttpResponsePacket::Credit && packet.type != ZhttpResponsePacket::KeepAlive)
			{
				state = Idle;
				errorCondition = ErrorGeneric;
				cleanup();
				log_warning("zws client: error id=%s initial response wrong type", packet.id.data());
				emit q->error();
				return;
			}

			if(packet.from.isEmpty())
			{
				state = Idle;
				errorCondition = ErrorGeneric;
				cleanup();
				log_warning("zws client: error id=%s initial ack did not contain from field", packet.id.data());
				emit q->error();
				return;
			}
		}

		if(packet.type == ZhttpResponsePacket::Data || packet.type == ZhttpResponsePacket::Ping || packet.type == ZhttpResponsePacket::Pong)
		{
			if(state == Connecting)
			{
				// this is assured earlier
				assert(packet.type == ZhttpResponsePacket::Data);

				responseCode = packet.code;
				responseReason = packet.reason;
				responseHeaders = packet.headers;

				if(packet.credits > 0)
					outCredits += packet.credits;

				state = Connected;
				update();
				emit q->connected();
			}
			else
			{
				if(inSize + packet.body.size() > IDEAL_CREDITS)
					log_warning("zws client: id=%s server is sending too fast", packet.id.data());

				if(packet.type == ZhttpResponsePacket::Data)
				{
					handleIncomingDataPacket(packet.contentType, packet.body, packet.more);
				}
				else if(packet.type == ZhttpResponsePacket::Ping)
				{
					inFrames += Frame(Frame::Ping, packet.body, false);
					inSize += packet.body.size();
				}
				else if(packet.type == ZhttpResponsePacket::Pong)
				{
					inFrames += Frame(Frame::Pong, packet.body, false);
					inSize += packet.body.size();
				}

				if(packet.credits > 0)
				{
					outCredits += packet.credits;
					if(outCredits > 0)
					{
						// try to write anything that was waiting on credits
						QPointer<QObject> self = this;
						tryWrite();
						if(!self)
							return;
					}
				}

				emit q->readyRead();
			}
		}
		else if(packet.type == ZhttpResponsePacket::Close)
		{
			handlePeerClose(packet.code);
		}
		else if(packet.type == ZhttpResponsePacket::Credit)
		{
			if(packet.credits > 0)
			{
				outCredits += packet.credits;
				if(outCredits > 0)
					tryWrite();
			}
		}
		else if(packet.type == ZhttpResponsePacket::KeepAlive)
		{
			// nothing to do
		}
		else
		{
			log_debug("zws client: unsupported packet type id=%s type=%d", packet.id.data(), (int)packet.type);
		}
	}
Exemplo n.º 22
0
 Frame framerv( const Rotation& r, const Vector& v )
 {
         return Frame( r, v );
 };
Exemplo n.º 23
0
PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName)
	: HWindow(BRect(0,0,400,220), "Page setup", B_TITLED_WINDOW_LOOK,
 		B_MODAL_APP_WINDOW_FEEL, B_NOT_RESIZABLE | B_NOT_MINIMIZABLE |
 		B_NOT_ZOOMABLE),
	 fResult(B_ERROR),
	 fSetupMsg(msg),
	 fAdvancedSettings(*msg),
	 fPrinterDirName(printerName)
{
	fExitSem 	= create_sem(0, "PageSetup");

	if (printerName)
		SetTitle(BString(printerName).Append(" page setup").String());

	if (fSetupMsg->FindInt32("orientation", &fCurrentOrientation) != B_OK)
		fCurrentOrientation = PrinterDriver::PORTRAIT_ORIENTATION;

	BRect page;
	float width = letter_width;
	float height = letter_height;
	if (fSetupMsg->FindRect("paper_rect", &page) == B_OK) {
		width = page.Width();
		height = page.Height();
	} else {
		page.Set(0, 0, width, height);
	}

	BString label;
	if (fSetupMsg->FindString("pdf_paper_size", &label) != B_OK)
		label = "Letter";

	int32 compression;
	fSetupMsg->FindInt32("pdf_compression", &compression);

	int32 units;
	if (fSetupMsg->FindInt32("units", &units) != B_OK)
		units = kUnitInch;

	// re-calculate the margin from the printable rect in points
	BRect margin = page;
	if (fSetupMsg->FindRect("printable_rect", &margin) == B_OK) {
		margin.top -= page.top;
		margin.left -= page.left;
		margin.right = page.right - margin.right;
		margin.bottom = page.bottom - margin.bottom;
	} else {
		margin.Set(28.34, 28.34, 28.34, 28.34);		// 28.34 dots = 1cm
	}

	BString setting_value;
	if (fSetupMsg->FindString("pdf_compatibility", &setting_value) != B_OK)
		setting_value = "1.3";

	// Load font settings
	fFonts = new Fonts();
	fFonts->CollectFonts();
	BMessage fonts;
	if (fSetupMsg->FindMessage("fonts", &fonts) == B_OK)
		fFonts->SetTo(&fonts);

	// add a *dialog* background
	BRect bounds(Bounds());
	BBox *panel = new BBox(bounds, "background", B_FOLLOW_ALL,
		B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_PLAIN_BORDER);
	AddChild(panel);

	bounds.InsetBy(10.0, 10.0);
	bounds.right = 230.0;
	bounds.bottom = 160.0;
	fMarginView = new MarginView(bounds, int32(width), int32(height), margin,
		MarginUnit(units));
	panel->AddChild(fMarginView);
	fMarginView->SetResizingMode(B_FOLLOW_NONE);

	BPopUpMenu* m = new BPopUpMenu("Page size");
	m->SetRadioMode(true);

	bounds.OffsetBy(bounds.Width() + 10.0, 5.0);
	float divider = be_plain_font->StringWidth("PDF compatibility: ");
	fPageSizeMenu = new BMenuField(bounds, "page_size", "Page size:", m);
	panel->AddChild(fPageSizeMenu);
	fPageSizeMenu->ResizeToPreferred();
	fPageSizeMenu->SetDivider(divider);
	fPageSizeMenu->Menu()->SetLabelFromMarked(true);

	for (int32 i = 0; pageFormat[i].label != NULL; i++) {
		BMessage* message = new BMessage(PAGE_SIZE_CHANGED);
		message->AddFloat("width", pageFormat[i].width);
		message->AddFloat("height", pageFormat[i].height);
		BMenuItem* item = new BMenuItem(pageFormat[i].label, message);
		m->AddItem(item);

		if (label.Compare(pageFormat[i].label) == 0)
			item->SetMarked(true);
	}

	m = new BPopUpMenu("Orientation");
	m->SetRadioMode(true);

	bounds.OffsetBy(0.0, fPageSizeMenu->Bounds().Height() + 10.0);
	fOrientationMenu = new BMenuField(bounds, "orientation", "Orientation:", m);
	panel->AddChild(fOrientationMenu);
	fOrientationMenu->ResizeToPreferred();
	fOrientationMenu->SetDivider(divider);
	fOrientationMenu->Menu()->SetLabelFromMarked(true);

	for (int32 i = 0; orientation[i].label != NULL; i++) {
	 	BMessage* message = new BMessage(ORIENTATION_CHANGED);
		message->AddInt32("orientation", orientation[i].orientation);
		BMenuItem* item = new BMenuItem(orientation[i].label, message);
		m->AddItem(item);

		if (fCurrentOrientation == orientation[i].orientation)
			item->SetMarked(true);
	}

	m = new BPopUpMenu("PDF compatibility");
	m->SetRadioMode(true);

	bounds.OffsetBy(0.0, fOrientationMenu->Bounds().Height() + 10.0);
	fPDFCompatibilityMenu = new BMenuField(bounds, "pdf_compatibility",
		"PDF compatibility:", m);
	panel->AddChild(fPDFCompatibilityMenu);
	fPDFCompatibilityMenu->ResizeToPreferred();
	fPDFCompatibilityMenu->SetDivider(divider);
	fPDFCompatibilityMenu->Menu()->SetLabelFromMarked(true);

	for (int32 i = 0; pdf_compatibility[i] != NULL; i++) {
		BMenuItem* item = new BMenuItem(pdf_compatibility[i], NULL);
		m->AddItem(item);
		if (setting_value == pdf_compatibility[i])
			item->SetMarked(true);
	}

	bounds.OffsetBy(0.0, fPDFCompatibilityMenu->Bounds().Height() + 10.0);
	fPDFCompressionSlider = new BSlider(bounds, "pdf_compression",
		"Compression:", NULL, 0, 9);
	panel->AddChild(fPDFCompressionSlider);
	fPDFCompressionSlider->SetLimitLabels("None", "Best");
	fPDFCompressionSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
	fPDFCompressionSlider->SetValue(compression);
	fPDFCompressionSlider->ResizeToPreferred();

	bounds = Bounds();
	bounds.InsetBy(5.0, 0.0);
	bounds.top = MAX(fPDFCompressionSlider->Frame().bottom,
		fMarginView->Frame().bottom) + 10.0;
	BBox *line = new BBox(BRect(bounds.left, bounds.top, bounds.right,
		bounds.top + 1.0), NULL, B_FOLLOW_LEFT_RIGHT);
	panel->AddChild(line);

	bounds.InsetBy(5.0, 0.0);
	bounds.OffsetBy(0.0, 11.0);
	BButton *cancel = new BButton(bounds, NULL, "Cancel", new BMessage(CANCEL_MSG));
	panel->AddChild(cancel);
	cancel->ResizeToPreferred();

	BButton *ok = new BButton(bounds, NULL, "OK", new BMessage(OK_MSG));
	panel->AddChild(ok, cancel);
	ok->ResizeToPreferred();

	bounds.right = fPDFCompressionSlider->Frame().right;
	ok->MoveTo(bounds.right - ok->Bounds().Width(), ok->Frame().top);

	bounds = ok->Frame();
	cancel->MoveTo(bounds.left - cancel->Bounds().Width() - 10.0, bounds.top);

	ok->MakeDefault(true);
	ResizeTo(bounds.right + 10.0, bounds.bottom + 10.0);

	BButton *button = new BButton(bounds, NULL, "Fonts" B_UTF8_ELLIPSIS,
		new BMessage(FONTS_MSG));
	panel->AddChild(button);
	button->ResizeToPreferred();
	button->MoveTo(fMarginView->Frame().left, bounds.top);

	bounds = button->Frame();
	button = new BButton(bounds, NULL, "Advanced" B_UTF8_ELLIPSIS,
		new BMessage(ADVANCED_MSG));
	panel->AddChild(button);
	button->ResizeToPreferred();
	button->MoveTo(bounds.right + 10, bounds.top);

	BRect winFrame(Frame());
	BRect screenFrame(BScreen().Frame());
	MoveTo((screenFrame.right - winFrame.right) / 2,
		(screenFrame.bottom - winFrame.bottom) / 2);
}
Exemplo n.º 24
0
Terrain MapHandler::getNextTerrain()
{
    //find the appropriate tile graphic and store it
    Terrain temp = Terrain();
    Frame frame;
    switch(map[xTer][yTer])
    {
        //trees (picks from a selection of trees)
        case 'T':
            frame = Frame(0, xTer*TILES_X, yTer*TILES_Y+UI_HEIGHT, 32, 64, 0, 0, 32, 64, SHEET_TERRAIN);
            frame.addStandBox(5, 40, 22, 20);
            temp.addFrame(frame);
            break;
            
        case '0':
            frame = Frame(0, xTer*TILES_X, yTer*TILES_Y+UI_HEIGHT, 16, 16, 128, 0, 16, 16, SHEET_TERRAIN);
            frame.addStandBox(0, 0, 16, 16);
            temp.addFrame(frame);
            break;
        
        case '1':
            frame = Frame(0, xTer*TILES_X, yTer*TILES_Y+UI_HEIGHT, 16, 16, 144, 0, 16, 16, SHEET_TERRAIN);
            frame.addStandBox(0, 0, 16, 16);
            temp.addFrame(frame);
            break;
        
        case '2':
            frame = Frame(0, xTer*TILES_X, yTer*TILES_Y+UI_HEIGHT, 16, 16, 160, 0, 16, 16, SHEET_TERRAIN);
            frame.addStandBox(0, 0, 16, 16);
            temp.addFrame(frame);
            break;
        
        case '3':
            frame = Frame(0, xTer*TILES_X, yTer*TILES_Y+UI_HEIGHT, 16, 16, 176, 0, 16, 16, SHEET_TERRAIN);
            frame.addStandBox(0, 0, 16, 16);
            temp.addFrame(frame);
            break;
        
        case '4':
            frame = Frame(0, xTer*TILES_X, yTer*TILES_Y+UI_HEIGHT, 16, 16, 128, 16, 16, 16, SHEET_TERRAIN);
            frame.addStandBox(0, 0, 16, 16);
            temp.addFrame(frame);
            break;
        
        case '5':
            frame = Frame(0, xTer*TILES_X, yTer*TILES_Y+UI_HEIGHT, 16, 16, 144, 16, 16, 16, SHEET_TERRAIN);
            frame.addStandBox(0, 0, 16, 16);
            temp.addFrame(frame);
            break;
        
        case '6':
            frame = Frame(0, xTer*TILES_X, yTer*TILES_Y+UI_HEIGHT, 16, 16, 160, 16, 16, 16, SHEET_TERRAIN);
            frame.addStandBox(0, 0, 16, 16);
            temp.addFrame(frame);
            break;
        
        case '7':
            frame = Frame(0, xTer*TILES_X, yTer*TILES_Y+UI_HEIGHT, 16, 16, 176, 16, 16, 16, SHEET_TERRAIN);
            frame.addStandBox(0, 0, 16, 16);
            temp.addFrame(frame);
            break;
            
        case '8':
            frame = Frame(0, xTer*TILES_X, yTer*TILES_Y+UI_HEIGHT, 16, 16, 128, 32, 16, 16, SHEET_TERRAIN);
            frame.addStandBox(0, 0, 16, 16);
            temp.addFrame(frame);
            break;
        
        case '9':
            frame = Frame(0, xTer*TILES_X, yTer*TILES_Y+UI_HEIGHT, 16, 16, 144, 32, 16, 16, SHEET_TERRAIN);
            frame.addStandBox(0, 0, 16, 16);
            temp.addFrame(frame);
            break;
        
        case 'A':
            frame = Frame(0, xTer*TILES_X, yTer*TILES_Y+UI_HEIGHT, 16, 16, 160, 32, 16, 16, SHEET_TERRAIN);
            frame.addStandBox(0, 0, 16, 16);
            temp.addFrame(frame);
            break;
        
        case 'B':
            frame = Frame(0, xTer*TILES_X, yTer*TILES_Y+UI_HEIGHT, 16, 16, 176, 32, 16, 16, SHEET_TERRAIN);
            frame.addStandBox(0, 0, 16, 16);
            temp.addFrame(frame);
            break;
        
        case 'C':
            frame = Frame(0, xTer*TILES_X, yTer*TILES_Y+UI_HEIGHT, 16, 16, 128, 48, 16, 16, SHEET_TERRAIN);
            frame.addStandBox(0, 0, 16, 16);
            temp.addFrame(frame);
            break;
        
        case 'D':
            frame = Frame(0, xTer*TILES_X, yTer*TILES_Y+UI_HEIGHT, 16, 16, 144, 48, 16, 16, SHEET_TERRAIN);
            frame.addStandBox(0, 0, 16, 16);
            temp.addFrame(frame);
            break;
        
        case 'E':
            frame = Frame(0, xTer*TILES_X, yTer*TILES_Y+UI_HEIGHT, 16, 16, 160, 48, 16, 16, SHEET_TERRAIN);
            frame.addStandBox(0, 0, 16, 16);
            temp.addFrame(frame);
            break;
        
        case 'F':
            frame = Frame(0, xTer*TILES_X, yTer*TILES_Y+UI_HEIGHT, 16, 16, 176, 48, 16, 16, SHEET_TERRAIN);
            frame.addStandBox(0, 0, 16, 16);
            temp.addFrame(frame);
            break;
    }
    
    //increment x/y counters
    xTer++;
    if (xTer >= 30)
    {
        xTer = 0;
        yTer++;
    }
    
    return temp;
}
Exemplo n.º 25
0
	Spectrum sampleEmissionDirection(EmissionRecord &eRec, const Point2 &sample) const {
		Vector wo = squareToHemispherePSA(sample);
		eRec.d = Frame(eRec.sRec.n).toWorld(wo);
		eRec.pdfDir = Frame::cosTheta(wo) * INV_PI;
		return Spectrum(INV_PI);
	}
Exemplo n.º 26
0
StatusWindow::StatusWindow(bool oddPages, bool evenPages, uint32 firstPage, uint32 numPages, uint32 numCopies, uint32 nup)
	: BWindow (BRect(200, 200, 650, 270), "Print Status", B_DOCUMENT_WINDOW, B_NOT_RESIZABLE | B_NOT_CLOSABLE | B_NOT_ZOOMABLE)
{
	//	oddPages	- if true, only print odd umbered pages		
	//	evenPages	- if true, only print even umbered pages	
	//  firstPage	- number of first page
	//  numPages	- total number of pages (must be recalculate if odd/even is used)
	//  numCopies - total number of document copies	
	
	BRect frame = Frame();
	// the status view
	frame.OffsetTo(B_ORIGIN);
	fStatusView = new BView(frame,"Status View",B_FOLLOW_ALL, B_WILL_DRAW);
	fStatusView->SetViewColor(216,216,216);
	AddChild(fStatusView);			
	
	// the status bar
	fStatusBar = new BStatusBar(BRect(10, 15, 245, 50),"Status Bar","Page: ");
	fStatusView->AddChild(fStatusBar);
	
	// the cancel button
	fHideButton = new BButton(BRect(260, 25, 330,50),"Hide Button","Hide Status", new BMessage(HIDE_MSG));
	fHideButton->ResizeToPreferred();
	fStatusView->AddChild(fHideButton);

	fCancelButton = new BButton(BRect(260, 25, 330,50),"Cancel Button","Cancel", new BMessage(CANCEL_MSG));
	fCancelButton->ResizeToPreferred();
	fCancelButton->MoveBy(90,0);
	
	fStatusView->AddChild(fCancelButton);
	
	fCancelBar = false;		
			
	// calculate the real number of pages
	fNops = numPages;
	
	bool evenFirstPage 	= (firstPage % 2) == 0;
	bool evenNumPages 	= (numPages  % 2) == 0;
	
	// recalculate page numbers if even or odd is used 
	if (oddPages || evenPages) { 		
		if  (evenNumPages) { 		
			fNops = numPages / 2;
		} else if (evenFirstPage) {
			if (oddPages)
				fNops = (numPages - 1) / 2;
			if (evenPages)
				fNops = (numPages + 1) / 2;
		} else {
			if (oddPages)  
				fNops = (numPages + 1) / 2;
			if (evenPages)
				fNops = (numPages - 1) / 2;
		}
	}	
	
	uint32 addPage = 0;
	if (fNops % nup > 0) 
		addPage = 1;
	fNops = (uint32) ( fNops/(float)nup ) +  addPage;
		// recalculate page numbers nup-pages-up
			
	fStatusBar->SetMaxValue ((float)fNops);
		// max value of status bar = real number of pages
	fDelta = 1.0/numCopies;
		// reduce step width of status bar
	fStatusDelta = fDelta;
	fDocCopies = numCopies;
	
	fDocumentCopy = fDocCopies > 1;	
	
	fDocCopies++;

	ResetStatusBar();
	Show();
}
Exemplo n.º 27
0
void
TBarMenuTitle::DrawContent()
{
	BMenu* menu = Menu();
	BRect frame(Frame());

	if (be_control_look != NULL) {
		menu->SetDrawingMode(B_OP_ALPHA);

		if (fIcon != NULL) {
			BRect dstRect(fIcon->Bounds());
			dstRect.OffsetTo(frame.LeftTop());
			dstRect.OffsetBy(rintf(((frame.Width() - dstRect.Width()) / 2)
				- 1.0f), rintf(((frame.Height() - dstRect.Height()) / 2)
				- 0.0f));

			menu->DrawBitmapAsync(fIcon, dstRect);
		}
		return;
	}

	rgb_color menuColor = menu->ViewColor();
	rgb_color dark = tint_color(menuColor, B_DARKEN_1_TINT);
	rgb_color light = tint_color(menuColor, B_LIGHTEN_2_TINT);
	rgb_color black = {0, 0, 0, 255};

	bool inExpandoMode = dynamic_cast<TExpandoMenuBar*>(menu) != NULL;

	BRect bounds(menu->Window()->Bounds());
	if (bounds.right < frame.right)
		frame.right = bounds.right;

	menu->SetDrawingMode(B_OP_COPY);

	if (!IsSelected() && !menu->IsRedrawAfterSticky()) {
		menu->BeginLineArray(8);
		menu->AddLine(frame.RightTop(), frame.LeftTop(), light);
		menu->AddLine(frame.LeftBottom(), frame.RightBottom(), dark);
		menu->AddLine(frame.LeftTop(),
			frame.LeftBottom()+BPoint(0, inExpandoMode ? 0 : -1), light);
		menu->AddLine(frame.RightBottom(), frame.RightTop(), dark);
		if (inExpandoMode) {
			frame.top += 1;
			menu->AddLine(frame.LeftTop(), frame.RightTop() + BPoint(-1, 0),
				light);
		}

		menu->EndLineArray();

		frame.InsetBy(1, 1);
		menu->SetHighColor(menuColor);
		menu->FillRect(frame);
		menu->SetHighColor(black);
		frame.InsetBy(-1, -1);
		if (inExpandoMode)
			frame.top -= 1;
	}

	ASSERT(IsEnabled());
	if (IsSelected() && !menu->IsRedrawAfterSticky()) {
		menu->SetHighColor(tint_color(menuColor, B_HIGHLIGHT_BACKGROUND_TINT));
		menu->FillRect(frame);

		if (menu->IndexOf(this) > 0) {
			menu->SetHighColor(tint_color(menuColor, B_DARKEN_4_TINT));
			menu->StrokeLine(frame.LeftTop(), frame.LeftBottom());
		}

		menu->SetHighColor(black);
	}

	menu->SetDrawingMode(B_OP_ALPHA);

	if (fIcon != NULL) {
		BRect dstRect(fIcon->Bounds());
		dstRect.OffsetTo(frame.LeftTop());
		dstRect.OffsetBy(rintf(((frame.Width() - dstRect.Width()) / 2) - 1.0f),
			rintf(((frame.Height() - dstRect.Height()) / 2) - 0.0f));

		menu->DrawBitmapAsync(fIcon, dstRect);
	}
}
Exemplo n.º 28
0
	void handleRequest(ZhttpRequest *_req, const QByteArray &jsonpCallback, const QByteArray &lastPart, const QByteArray &body)
	{
		connect(_req, SIGNAL(bytesWritten(int)), SLOT(req_bytesWritten(int)));
		connect(_req, SIGNAL(error()), SLOT(req_error()));

		if(lastPart == "xhr" || lastPart == "jsonp")
		{
			if(req)
			{
				QVariantList out;
				out += 2010;
				out += QString("Another connection still open");

				requests.insert(_req, new RequestItem(_req, jsonpCallback, RequestItem::Background, true));
				respondOk(_req, out, "c", jsonpCallback);
				return;
			}

			if(peerClosed)
			{
				QVariantList out;
				out += 3000;
				out += QString("Client already closed connection");

				requests.insert(_req, new RequestItem(_req, jsonpCallback, RequestItem::Background, true));
				respondOk(_req, out, "c", jsonpCallback);
				return;
			}

			req = _req;
			requests.insert(req, new RequestItem(req, jsonpCallback, RequestItem::Receive));
			keepAliveTimer->start(KEEPALIVE_TIMEOUT * 1000);

			tryWrite();
		}
		else if(lastPart == "xhr_send" || lastPart == "jsonp_send")
		{
			// only allow one outstanding send request at a time
			if(findFirstSendRequest())
			{
				requests.insert(_req, new RequestItem(_req, jsonpCallback, RequestItem::Background, true));
				respondError(_req, 400, "Bad Request", "Already sending");
				return;
			}

			QByteArray param;

			if(_req->requestMethod() == "POST")
			{
				if(lastPart == "xhr_send")
				{
					// assume json
					param = body;
				}
				else // jsonp_send
				{
					// assume form encoded
					foreach(const QByteArray &kv, body.split('&'))
					{
						int at = kv.indexOf('=');
						if(at == -1)
							continue;
						if(QUrl::fromPercentEncoding(kv.mid(0, at)) == "d")
						{
							param = QUrl::fromPercentEncoding(kv.mid(at + 1)).toUtf8();
							break;
						}
					}
				}
			}
			else // GET
			{
				param = _req->requestUri().queryItemValue("d").toUtf8();
			}

			QJson::Parser parser;
			bool ok;
			QVariant vmessages = parser.parse(param, &ok);
			if(!ok || vmessages.type() != QVariant::List)
			{
				requests.insert(_req, new RequestItem(_req, jsonpCallback, RequestItem::Background, true));
				respondError(_req, 400, "Bad Request", "Payload expected");
				return;
			}

			QList<Frame> frames;
			int bytes = 0;
			foreach(const QVariant &vmessage, vmessages.toList())
			{
				if(vmessage.type() != QVariant::String)
				{
					requests.insert(_req, new RequestItem(_req, jsonpCallback, RequestItem::Background, true));
					respondError(_req, 400, "Bad Request", "Payload expected");
					return;
				}

				QByteArray data = vmessage.toString().toUtf8();
				if(data.size() > BUFFER_SIZE)
				{
					requests.insert(_req, new RequestItem(_req, jsonpCallback, RequestItem::Background, true));
					respondError(_req, 400, "Bad Request", "Message too large");
					return;
				}

				frames += Frame(Frame::Text, data, false);
				bytes += data.size();
			}

			if(frames.isEmpty())
			{
				requests.insert(_req, new RequestItem(_req, jsonpCallback, RequestItem::Background, true));
				respondOk(_req, QString("ok"), jsonpCallback);
				return;
			}

			RequestItem *ri = new RequestItem(_req, jsonpCallback, RequestItem::Send);
			requests.insert(_req, ri);
			ri->sendFrames = frames;
			ri->sendBytes = bytes;

			tryRead();
		}
Exemplo n.º 29
0
CParticle::CParticle(ParticleType type, unsigned x, unsigned y, sf::Image explosion) :
        Animated(true, true, 0.05f)
{
    m_explosion = explosion;
    switch (type)
    {
    case Middle:
        m_anim.PushFrame(Frame(&m_explosion, sf::Rect<int>(169, 215, 199, 244)));
        m_anim.PushFrame(Frame(&m_explosion, sf::Rect<int>(34, 215, 64, 244)));
        m_anim.PushFrame(Frame(&m_explosion, sf::Rect<int>(171, 69, 201, 99)));
        m_anim.PushFrame(Frame(&m_explosion, sf::Rect<int>(34, 67, 64, 96)));
        break;
    case HorizontalLeft:
        m_anim.PushFrame(Frame(&m_explosion, sf::Rect<int>(142, 219, 166, 242)));
        m_anim.PushFrame(Frame(&m_explosion, sf::Rect<int>(4, 217, 32, 244)));
        m_anim.PushFrame(Frame(&m_explosion, sf::Rect<int>(139, 69, 169, 96)));
        m_anim.PushFrame(Frame(&m_explosion, sf::Rect<int>(0, 68, 32, 97)));
        break;
    case HorizontalRight:
        m_anim.PushFrame(Frame(&m_explosion, sf::Rect<int>(234, 219, 258, 240)));
        m_anim.PushFrame(Frame(&m_explosion, sf::Rect<int>(99, 217, 127, 243)));
        m_anim.PushFrame(Frame(&m_explosion, sf::Rect<int>(235, 70, 267, 98)));
        m_anim.PushFrame(Frame(&m_explosion, sf::Rect<int>(99, 67, 129, 96)));
        break;
    case VerticalUp:
        m_anim.PushFrame(Frame(&m_explosion, sf::Rect<int>(172, 156, 196, 180)));
        m_anim.PushFrame(Frame(&m_explosion, sf::Rect<int>(35, 152, 63, 180)));
        m_anim.PushFrame(Frame(&m_explosion, sf::Rect<int>(171, 5, 200, 34)));
        m_anim.PushFrame(Frame(&m_explosion, sf::Rect<int>(35, 0, 64, 32)));
        break;
    case VerticalDown:
        m_anim.PushFrame(Frame(&m_explosion, sf::Rect<int>(171, 247, 195, 272)));
        m_anim.PushFrame(Frame(&m_explosion, sf::Rect<int>(35, 247, 62, 276)));
        m_anim.PushFrame(Frame(&m_explosion, sf::Rect<int>(172, 100, 201, 129)));
        m_anim.PushFrame(Frame(&m_explosion, sf::Rect<int>(34, 99, 64, 129)));
        break;
    case Horizontal:
        m_anim.PushFrame(Frame(&m_explosion, sf::Rect<int>(201, 218, 231, 242)));
        m_anim.PushFrame(Frame(&m_explosion, sf::Rect<int>(66, 216, 97, 243)));
        m_anim.PushFrame(Frame(&m_explosion, sf::Rect<int>(203, 70, 234, 99)));
        m_anim.PushFrame(Frame(&m_explosion, sf::Rect<int>(66, 67, 97, 97)));
        break;
    case Vertical:
        m_anim.PushFrame(Frame(&m_explosion, sf::Rect<int>(169, 181, 196, 213)));
        m_anim.PushFrame(Frame(&m_explosion, sf::Rect<int>(34, 182, 63, 213)));
        m_anim.PushFrame(Frame(&m_explosion, sf::Rect<int>(169, 36, 202, 67)));
        m_anim.PushFrame(Frame(&m_explosion, sf::Rect<int>(33, 33, 65, 65)));
        break;
    }
    SetAnim(&m_anim);
    m_type = type;
    SetPosition(x * BLOCK_SIZE, y * BLOCK_SIZE);
    m_x = x;
    m_y = y;
}