void TestVideo::testGetNumberOfFrames() {
	std::unique_ptr<QImage> frame(new QImage);
	video_.insertFrame(std::move(frame), 0);

	std::unique_ptr<QImage> frame2(new QImage);
	video_.insertFrame(std::move(frame2), 1);

	QVERIFY(2 == video_.getNumberOfFrames());
}
Exemple #2
0
void mainframe()
{
char d;
textbackground(BLACK);
textcolor(RED);
_setcursortype(0);
clrscr();
cprintf(" �����������������������������������������������������������������������������ͻ");
cprintf(" �                        Master COMMAND.COM ver 1.0                           �");
cprintf(" �                                                                             �");
cprintf(" �                            It's a KVSM Product                              �");
cprintf(" �                        -----------------------------                        �");
cprintf(" �����������������������������������������������������������������������������ͼ");
cprintf(" �����������������������������������������������������������������������������ͻ");
cprintf(" �                                                                             �");
cprintf(" �                                                                             �");
cprintf(" �                 1. Change Commands                                          �");
cprintf(" �                                                                             �");
cprintf(" �                 2. Help                                                     �");
cprintf(" �                                                                             �");
cprintf(" �                 3. About                                                    �");
cprintf(" �                                                                             �");
cprintf(" �                 4. Exit                                                     �");
cprintf(" �                                                                             �");
cprintf(" �                                                 press any key(1,2,3,4)      �");
cprintf(" �����������������������������������������������������������������������������ͼ");
cprintf(" �����������������������������������������������������������������������������ͻ");
cprintf(" �                               DEVELOPED BY                                  �");
cprintf(" �                                                                             �");
cprintf(" �                            MANOHAR SINGH NEGI                               �");
cprintf(" �����������������������������������������������������������������������������ͼ");
scanf("%c",&d);
switch(d)
{
case '1':
	mani();
	mainframe();
	break;
case '2':
	frame2();
	break;
case '3':
	frameabout();
	break;
case '4':
	exit(1);
default:
	clrscr();
	cprintf("Please enter the valid choice");
	delay(300);
	mainframe();
}
}
void tst_QStyleOption::copyconstructors()
{
    QStyleOptionFrame frame;
    QStyleOptionFrameV2 frame2(frame);
    QCOMPARE(frame2.version, int(QStyleOptionFrameV2::Version));
    frame2 = frame;
    QCOMPARE(frame2.version, int(QStyleOptionFrameV2::Version));

    QStyleOptionProgressBar bar;
    QStyleOptionProgressBarV2 bar2(bar);
    QCOMPARE(bar2.version, int(QStyleOptionProgressBarV2::Version));
    bar2 = bar;
    QCOMPARE(bar2.version, int(QStyleOptionProgressBarV2::Version));
}
void TestVideo::testRemoveFrame() {
	video_.removeFrame(1);
	QVERIFY(0 == video_.getHeight());

	std::unique_ptr<QImage> frame(new QImage);
	video_.insertFrame(std::move(frame), 0);

	std::unique_ptr<QImage> frame2(new QImage);
	QImage* tempframe2 = frame2.get();
	video_.insertFrame(move(std::move(frame2)), 1);


	video_.removeFrame(1);
	QVERIFY(tempframe2 != video_.getFrame(1));


	QVERIFY(nullptr == video_.getFrame(2));


}
TEST_F(VideoThumbnailerTest, FrameSelection)
{
    vector<VideoFrame> videoFrames;
    vector<Histogram<int> > histograms;

    VideoFrame frame1(5, 5, 15);
    fill(frame1.frameData.begin(), frame1.frameData.end(), 255);

    VideoFrame frame2(5, 5, 15);
    fill(frame2.frameData.begin(), frame2.frameData.end(), 0);

    VideoFrame frame3(5, 5, 15);
    fill(frame3.frameData.begin(), frame3.frameData.end(), 128);

    Histogram<int> hist1;
    hist1.r[255] = 25;
    hist1.g[255] = 25;
    hist1.b[255] = 25;

    Histogram<int> hist2;
    hist2.r[0] = 25;
    hist2.g[0] = 25;
    hist2.b[0] = 25;

    Histogram<int> hist3;
    hist3.r[128] = 25;
    hist3.g[128] = 25;
    hist3.b[128] = 25;

    videoFrames.push_back(frame1);
    videoFrames.push_back(frame2);
    videoFrames.push_back(frame3);

    histograms.push_back(hist1);
    histograms.push_back(hist2);
    histograms.push_back(hist3);

    //This test is bad
    //EXPECT_EQ(getBestThumbnailIndex(videoFrames, histograms), 1);
}
Exemple #6
0
int main()
{
    //ocl::setUseOpenCL(true);
    
    VideoCapture video("/Users/sonhojun/Downloads/data/all.mp4");
    
    if(!video.isOpened())
    {
        cout<<"video open error"<<endl;
        return 0 ;
    }
    Mat pri;
    Mat aft;
    Mat binary;
    Mat frame1,frame2;
    
    while (1)
    {
        
        video.read(frame1);
        video.read(frame2);
        
//        Mat cropFrame1, cropFrame2;
//        Mat oriConv = frame1(Rect(10,340,700,200));
//        
////        cropFrame1 = frame1(Rect(10,340,700,200));
////        cropFrame2 = frame2(Rect(10,340,700,200));
//        
//        Mat grayImage1,grayImage2;
//        Mat differenceImage;
//        Mat thresholdImage;
//        Vec<double,4> totalDiff = 0.0;
//        
//        cropFrame1 = frame1(Rect(10,340,700,200));
//        cvtColor(cropFrame1, grayImage1, COLOR_BGR2GRAY);
//        
//        cropFrame2 =frame2(Rect(10,340,700,200));
//        
//        cvtColor(cropFrame2, grayImage2, COLOR_BGR2GRAY);
//        absdiff(grayImage1,grayImage2,differenceImage);
//        
//        totalDiff = sum(differenceImage) / (690 * 140);
//        cout << "sum diff: " <<totalDiff<<endl;
//        
//        if(totalDiff[0] > 14.0)
//            continue;
//        
//        threshold(differenceImage, thresholdImage, SENSITIVITY_VALUE, 255, THRESH_BINARY);
//        
//        blur(thresholdImage, thresholdImage , Size(BLUR_SIZE,BLUR_SIZE));
//        
//        threshold(thresholdImage,thresholdImage,SENSITIVITY_VALUE,255,THRESH_BINARY);
//        
//        
//        //if tracking enabled, search for contours in our thresholded image
//
//        //searchForMovement(thresholdImage, oriConv);
//        
//        
//        //show our captured frame
//        imshow("moving",thresholdImage);
        
      
       // imshow("ori",temp);
        Mat cropRGB = frame2(Rect(10,340,700,200));
        Mat cropG;
        cvtColor(cropRGB, cropG, CV_RGB2GRAY);
        GaussianBlur(cropG, cropG, Size(5,5), 0,0);
        threshold(cropG,binary,0,255,THRESH_OTSU|THRESH_BINARY);
      //  adaptiveThreshold(cropG, binary, 255, <#int adaptiveMethod#>, THRESH_OTSU|THRESH_BINARY, 3, 0.);
       // bitwise_xor(thresholdImage,binary,binary);
        imshow("bin",binary);
      
        Mat fg;
        
        erode(binary, fg, Mat(), Point(-1, -1), 6);

        namedWindow("Foreground Image");
        imshow("Foreground Image", fg);

        Mat bg;
        dilate(binary,bg,Mat(),Point(-1,-1),6);
        threshold(bg,bg,1,128,THRESH_BINARY_INV);

        namedWindow("Background Image");
        imshow("Background Image",bg);

//        Mat dist;
//        distanceTransform(binary, dist, CV_DIST_L2, 5);
//        normalize(dist, dist, 0, 1., NORM_MINMAX);
//        imshow("dist",dist);
//        
//        threshold(dist, dist, .4, 1., CV_THRESH_BINARY);
//                // Dilate a bit the dist image
//        Mat kernel1 = Mat::ones(3, 3, CV_8UC1);
//        dilate(dist, dist, kernel1);
//        imshow("Peaks", dist);
        
        Mat markers(binary.size(),CV_8U,Scalar(0));
        markers= fg+bg;

        namedWindow("Markers");
        imshow("Markers",markers);
        
        WatershedSegmenter segmenter;
        
        segmenter.setMarkers(markers);
        segmenter.process(cropRGB);

        namedWindow("Segmentation");
        imshow("Segmentation",segmenter.getSegmentation());
        
       // segmenter.getSegmentation()
//        namedWindow("Watersheds"); // 워터쉐드 띄워 보기
//        imshow("Watersheds",segmenter.getWatersheds());
        
        
        
        
//111        Mat kernel = Mat::ones(3,3,CV_8U);
//        
//        Mat morpho;
//        morphologyEx(binary,morpho,MORPH_OPEN,kernel);
//        
//        imshow("open",morpho);
//        
//        Mat sure_bg;
//        dilate(morpho,sure_bg,kernel);
//        
//        imshow("dilate",sure_bg);
//        
//        Mat dist;
//        distanceTransform(binary, dist, CV_DIST_L2, 5);
//        // Normalize the distance image for range = {0.0, 1.0}
//        // so we can visualize and threshold it
//        normalize(dist, dist, 0, 1., NORM_MINMAX);
//        imshow("Distance Transform Image", dist);
//        // Threshold to obtain the peaks
//        // This will be the markers for the foreground objects
//        threshold(dist, dist, .4, 1., CV_THRESH_BINARY);
//        // Dilate a bit the dist image
//        Mat kernel1 = Mat::ones(3, 3, CV_8UC1);
//        dilate(dist, dist, kernel1);
//        imshow("Peaks", dist);
//        // Create the CV_8U version of the distance image
//        // It is needed for findContours()
//        Mat dist_8u;
//        dist.convertTo(dist_8u, CV_8U);
//        // Find total markers
//        vector<vector<Point> > contours;
//        findContours(dist_8u, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
//        // Create the marker image for the watershed algorithm
//        Mat markers = Mat::zeros(dist.size(), CV_32SC1);
//        // Draw the foreground markers
//        for (size_t i = 0; i < contours.size(); i++)
//            drawContours(markers, contours, static_cast<int>(i), Scalar::all(static_cast<int>(i)+1), -1);
//        // Draw the background marker
//        circle(markers, Point(5,5), 3, CV_RGB(255,255,255), -1);
//        imshow("Markers", markers*10000);
//        // Perform the watershed algorithm
//        watershed(cropRGB, markers);
////        Mat mark = Mat::zeros(markers.size(), CV_8UC1);
////        markers.convertTo(mark, CV_8UC1);
////        bitwise_not(mark, mark);
////        imshow("Markers_v2", mark); // uncomment this if you want to see how the mark
//        // image looks like at that point
//        // Generate random colors
//        vector<Vec3b> colors;
//        for (size_t i = 0; i < contours.size(); i++)
//        {
//            int b = theRNG().uniform(0, 255);
//            int g = theRNG().uniform(0, 255);
//            int r = theRNG().uniform(0, 255);
//            colors.push_back(Vec3b((uchar)b, (uchar)g, (uchar)r));
//        }
//        // Create the result image
//        Mat dst = Mat::zeros(markers.size(), CV_8UC3);
//        // Fill labeled objects with random colors
//        for (int i = 0; i < markers.rows; i++)
//        {
//            for (int j = 0; j < markers.cols; j++)
//            {
//                int index = markers.at<int>(i,j);
//                if (index > 0 && index <= static_cast<int>(contours.size()))
//                    dst.at<Vec3b>(i,j) = colors[index-1];
//                else
//                    dst.at<Vec3b>(i,j) = Vec3b(0,0,0);
//            }
//        }
//        // Visualize the final image
//        imshow("Final Result", dst);
//        
//    
// 111       1

        cvWaitKey(10);
    }
    
    return 0;
}
void ModuleSceneIntro::LoadAssets()
{
	App->renderer->camera.x = App->renderer->camera.y = 0;
	background_up = App->textures->Load("pinball/bg_up.png");
	background_lights = App->textures->Load("pinball/bg_lights.png");
	background = App->textures->Load("pinball/bg.png");
	help = App->textures->Load("pinball/help.png");
	ball = App->textures->Load("pinball/ballSmall.png");
	rFlipper = App->textures->Load("pinball/rFlipper.png");
	lFlipper = App->textures->Load("pinball/lFlipper.png");
	circleTexture = App->textures->Load("pinball/circle.png");
	orange_bump = App->textures->Load("pinball/orange_bump.png");
	text = App->textures->Load("pinball/text.png");
//	reds = App->textures->Load("pinball/Reds.png");


	bonus1_fx = App->audio->LoadFx("pinball/bonus.wav");
	bonus2_fx = App->audio->LoadFx("pinball/bonus1.wav");
	bonus3_fx = App->audio->LoadFx("pinball/bonus2.wav");
	bonusLong_fx = App->audio->LoadFx("pinball/long_bonus.wav");
	bonusLong2_fx = App->audio->LoadFx("pinball/long_bonus2.wav");

	ballBounce_fx = App->audio->LoadFx("pinball/ball_bounce.wav");
	bell_fx = App->audio->LoadFx("pinball/bell.wav");
	ding_fx = App->audio->LoadFx("pinball/ding_short.wav");
	flipper_fx = App->audio->LoadFx("pinball/flipper.wav");

	SDL_Rect frame1; frame1.x = 0; frame1.y = 0; frame1.h = 40; frame1.w = 90;
	SDL_Rect frame2(frame1); frame2.y += 40;
	SDL_Rect frame3(frame2); frame3.y += 40;
	SDL_Rect frame4(frame3); frame4.y += 40;
	SDL_Rect frame5(frame4); frame5.y += 40;
	circle.frames.PushBack(frame1);
	circle.frames.PushBack(frame2);
	circle.frames.PushBack(frame3);
	circle.frames.PushBack(frame4);
	circle.frames.PushBack(frame5);
	circle.speed = 0.1f;
	circle.loop = true;

	SDL_Rect LED;
	SDL_Rect NULLRECT;
	LED.x = 423; LED.y = 92; LED.w = 36; LED.h = 30;
	NULLRECT.x = 0; NULLRECT.y = 0; NULLRECT.w = 0; NULLRECT.y = 0;
	BlackBoxLed.frames.PushBack(LED);
	BlackBoxLed.frames.PushBack(NULLRECT);
	BlackBoxLed.loop = true;
	BlackBoxLed.speed = 0.005f;

	texts[0].h = 84;
	texts[0].w = 154;
	texts[0].x = 0;
	texts[0].y = 0;
	texts[4] = texts[2] = texts[1] = texts[0];
	texts[1].x = 154;
	texts[5] = texts[3] = texts[1];
	texts[2].y = texts[3].y = 84;
	texts[4].y = texts[5].y = 168;
	/*
	//Pos = 390 x 100
	redsRect[0].x = 0; redsRect[0].y = 578; redsRect[0].w = 64; redsRect[0].h = 72;
	redsRect[3] = redsRect[2] = redsRect[1] = redsRect[0];
	redsRect[1].x = 64;
	redsRect[2].x = 128;
	redsRect[3].x = 192;
	*/
}
main (void)
{
  asm ("main_label: .globl main_label");
  frame2 ();
}
Exemple #9
0
void CamThreadCycle(void* lpParam)
{
	// thread handle
	HANDLE hThread;

	char        errBuff[2048];

	BeadCoord* bc;

	unsigned xn_min = 1344;
	unsigned yn_min = 0;

	char cc = '0';

	bool needle = TRUE;
	bool adjust_array = false;

	// get thread params
	threadinfo* t = (threadinfo*)lpParam;

	// light mode
	long lm=1;
	t->cam->setSimple_Lightmode(lm);

	// trigger
	t->cam->setSave_Trigger_Mode(HamamatsuCamera::CAP::TRIGGER_EDGE);
	t->cam->setSave_Trigger_Polarity(HamamatsuCamera::CAP::TRIGGER_POS);

	// subarray
	t->cam->set_SubArray(0,0,1344,1024);

	// exposure
	double ext = *t->extime*1E-3;
	t->cam->setSimple_ExposureTime(ext);

	// init save frame for tracking
	SBwinSaveFrame2D<unsigned short> frame2(1344,1024,SB_BUFFER_SIZE);
	frame2.zero();

	// init capture frame
	t->sframe = new SBwinCaptureFrame2D<unsigned short>(1344,1024,SB_BUFFER_SIZE);
	t->sframe->set_autoBcst(FALSE);
	t->sframe->set_AlwaysDisplay(TRUE);

	// show key definitions
	cerr<<"\n\n(n) = next measurement (#"<<t->cell+1<<")";
	if (t->cell>0) cerr<<"\n(r) = repeat this measurement (#"<<t->cell<<")";
	cerr<<"\n\n(g/b) = Bead Window\t(j/m) = BeadDistance";
	cerr<<"\n(6/7) = extime +/-\t(5) = Needle update";
	cerr<<"\n(s/x) = Low Threshold\t(d/c) = Bead Diameter";
	cerr<<"\n(a/y) = High Threshold\t(q) = quit program\n\n";

	int j=0;

	t->dist = 999;

	// cycle
	while(1){

		// loop while no key pressed
		while(!_kbhit()){

			// let camera wait for image
			hThread = (HANDLE)_beginthread(CaptureCycle,0,t);
			Sleep(100);
			if(t->mt->TriggerFrames(1))
			{
				DAQmxGetExtendedErrorInfo(errBuff,2048);
				cerr<<errBuff;
			}
			WaitForSingleObject(hThread, INFINITE);

			// find beads in image
			t->ba.findBeads(frame2);

			// copy bead info
			bc = frame2.get_BeadInfo()->bc;
			t->nofBeads = frame2.get_BeadInfo()->nofBeads;

			// find needle
			if(needle){
				delete t->needleframe;
				t->needleframe = &frame2.find_Needle();
				needle = FALSE;
			}

			// Adjust array position acording to the needle tip
			if(adjust_array){
				xn_min = 1344;
				yn_min = 0;

				// find position of needle tip
				for(unsigned xn=0;xn<1344;xn++) {
					for(unsigned yn=0;yn<1024;yn++) {
						if(t->needleframe->get_Pointer()[yn*1344+xn] && xn<xn_min)
						{
							xn_min = xn;
							yn_min = yn;
						}
					}
				}

				t->array_top = yn_min-(*t->array_size)/2;
				if(t->array_top < 0) t->array_top = 0;
				if(t->array_top > 1024-(*t->array_size)-8) t->array_top = 1024-(*t->array_size)-8;
				t->array_top = ( (int)(t->array_top/8) ) * 8;
				adjust_array = false;
			}

			// draw array borders
			for(unsigned i=0;i<1344;i++)
			{
				frame2.get_Pointer()[1344*t->array_top+i] = 0;
				frame2.get_Pointer()[1344*(t->array_top+*t->array_size)+i] = 0;
			}

			// mark needle red
			for(unsigned i=0;i<1344*1024;i++)
				if((t->needleframe->get_Pointer())[i])
					frame2.get_Pointer()[i] = 4096;

			xn_min = 1344;
			yn_min = 0;

			// find position of needle tip in subframe
			for(unsigned xn=0;xn<1344;xn++) {
				for(unsigned yn=0;yn<*t->array_size;yn++) {
					if(t->needleframe->get_Pointer()[(yn+t->array_top)*1344+xn] && xn<xn_min)
					{
						xn_min = xn;
						yn_min = yn + t->array_top;
					}
				}
			}

			// get number of beads and distance of closest bead (for ramp)
			t->dist = 999;
			double temp_dist = 0;
			for(unsigned j=0;j<t->nofBeads;j++)
			{
				// dist of this bead in µm
				temp_dist = sqrt(pow((int)(xn_min-bc[j].x),2) + pow((int)(yn_min-bc[j].y),2))* 6.45/(*t->magnification);
				// if closer than the bead before => use this one
				if (temp_dist < t->dist && bc[j].y > t->array_top && bc[j].y < *t->array_size + t->array_top)
				{
					t->closest_idx = i;
					t->dist = temp_dist;
				}
			}

			// now broadcast paint signal and increase pointer manually
			t->sframe->Bcst();
			frame2.inc_FramePointer();

			// output live disp information
			cerr<<"exp="<<*t->extime<<" BTHi="<<t->ba.BeadThreshHigh<<" BTLo="<<t->ba.BeadThreshLow<<" BDia="<<t->ba.BeadDiameter<<" BWin="<<t->ba.BeadWindow<<" BDist="<<t->ba.BeadDistance<<" dist="<<(int)t->dist<<" um ("<<t->nofBeads<<") MT="<<cc<<"  \r";
		}

		// get key and react
		t->ch = _getch();

		// array position
		if(t->ch=='+' && t->array_top<=1015)
			t->array_top+=8;

		if(t->ch=='-' && t->array_top>=8)
			t->array_top-=8;

		// high threshold
		if(t->ch=='a')
			t->ba.BeadThreshHigh+=50;
		if(t->ch=='y')
			t->ba.BeadThreshHigh-=50;

		// low threshold
		if(t->ch=='s')
			t->ba.BeadThreshLow+=50;
		if(t->ch=='x')
			t->ba.BeadThreshLow-=50;

		// diameter
		if(t->ch=='d')
			t->ba.BeadDiameter+=1;
		if(t->ch=='c')
			t->ba.BeadDiameter-=1;

		// distance
		if(t->ch=='j')
			t->ba.BeadDistance+=1;
		if(t->ch=='m')
			t->ba.BeadDistance-=1;

		// window
		if(t->ch=='g')
			t->ba.BeadWindow+=1;
		if(t->ch=='b')
			t->ba.BeadWindow-=1;

		// find needle
		if(t->ch=='5')
		{
			needle = TRUE;
			adjust_array = true;
		}

		// find needle
		if(t->ch=='9')
		{			
			if(t->mt->Degauss())
		{
			DAQmxGetExtendedErrorInfo(errBuff,2048);
			cerr<<errBuff;
			t->mt->RecoverFromError();
		}

		cerr<<"\nresetting...\n"<<endl;

		if(t->mt->Reset())
		{
			DAQmxGetExtendedErrorInfo(errBuff,2048);
			cerr<<errBuff;
			t->mt->RecoverFromError();
		}

		t->mt->SetCurrent(*t->anti_voltage);

}
		// exposure time
		if(t->ch=='6')
		{
			*t->extime=*t->extime+0.5;
			double ext = *t->extime*1E-3;
			t->cam->setSimple_ExposureTime(ext);
		}

		if(t->ch=='7')
		{
			*t->extime=*t->extime-0.5;
			if(*t->extime<0.5) *t->extime = 0.5;
			double ext = *t->extime*1E-3;
			t->cam->setSimple_ExposureTime(ext);
		}

		// continue
		if(t->ch=='q' || t->ch=='n' || t->ch=='r') break;
	}

	// get another frame for needle recognition
	hThread = (HANDLE)_beginthread(CaptureCycle,0,t);
	Sleep(100);
	if(t->mt->TriggerFrames(1))
	{
		DAQmxGetExtendedErrorInfo(errBuff,2048);
		cerr<<errBuff;
	}
	WaitForSingleObject(hThread, INFINITE);

	// find beads
	cerr<<"\nfound "<<t->ba.findBeads(frame2)<<" beads!\n";

	// copy bead info
	bc = frame2.get_BeadInfo()->bc;
	t->nofBeads = frame2.get_BeadInfo()->nofBeads;

	// find needle
	delete t->needleframe;
	t->needleframe = &frame2.find_Needle();

	// find position of needle tip
	xn_min = 1344;
	yn_min = 0;
	for(unsigned xn=0;xn<1344;xn++) {
		for(unsigned yn=0;yn<1024;yn++) {
			if(t->needleframe->get_Pointer()[yn*1344+xn] && xn<xn_min)
			{
				xn_min = xn;
				yn_min = yn;
			}
		}
	}

	t->array_top = yn_min-(*t->array_size)/2;
	if(t->array_top < 0) t->array_top = 0;
	if(t->array_top > 1023-(*t->array_size)) t->array_top = 1023-(*t->array_size);
	t->array_top = ( (int)(t->array_top/8) ) * 8;

	// draw again array borders
	for(unsigned i=0;i<1344;i++)
	{
		frame2.get_Pointer()[1344*t->array_top+i] = 0;
		frame2.get_Pointer()[1344*(t->array_top+*t->array_size)+i] = 0;
	}

	// mark needle red
	for(unsigned i=0;i<1344*1024;i++)
		if((t->needleframe->get_Pointer())[i])
			frame2.get_Pointer()[i] = 4096;

	// send paint signal and save image
	t->sframe->Bcst();
	DeleteFile("overview.tif");
	frame2.saveCapturedImage("overview.tif");

	// find position of needle tip in subframe
	xn_min = 1344;
	yn_min = 0;

	for(unsigned xn=0;xn<1344;xn++) {
		for(unsigned yn=0;yn<*t->array_size;yn++) {
			if(t->needleframe->get_Pointer()[(yn+t->array_top)*1344+xn] && xn<xn_min)
			{
				xn_min = xn;
				yn_min = yn + t->array_top;
			}
		}
	}

	// create distance matrix from needle tip
	t->distmat = new double[1344*1024];
	for(unsigned x=0;x<1344;x++){
		for(unsigned y=0;y<1024;y++){
			if(t->needleframe->get_Pointer()[y*1344+x]){
				t->distmat[y*1344+x] = 0;
			}
			else
				t->distmat[y*1344+x] = sqrt(pow((int)(xn_min-x),2) + pow((int)(yn_min-y),2));
			//t->distmat[y*1344+x] = sqrt(pow(xn_min-x,2.0));
		}
	}

	// get number of beads and distance of closest bead (for ramp)
	t->dist = 999;
	double temp_dist = 0;
	for(unsigned j=0;j<t->nofBeads;j++)
	{
		// dist of this bead in µm
		temp_dist = sqrt(pow((int)(xn_min-bc[j].x),2) + pow((int)(yn_min-bc[j].y),2))* 6.45/(*t->magnification);
		// if closer than the bead before => use this one
		if (temp_dist < t->dist && bc[j].y > t->array_top && bc[j].y < *t->array_size + t->array_top)
		{
			t->closest_idx = i;
			t->dist = temp_dist;
		}
	}

	delete t->sframe;

	t->cam->Image_Idle();
	t->cam->Image_Free();

	return;
}
Exemple #10
0
Settings::Settings(sfg::Desktop &theDesktop):
    window(sfg::Window::Create()),
    desktop(theDesktop),
    closeButton(sfg::Button::Create("Close")),
    colors{{"Black","Blue","Blue2","Brown","Green","Green2","Red","Red2",
                                                          "Violet","Violet2","White","Yellow"}},
    boardColors{{"Black","Blue","Brown"}}
{
    window->SetRequisition(sf::Vector2f(100.f,100.f));
    window->SetTitle("Settings");
    window->Show(false);



    sfg::Box::Ptr buttonLayout1 = sfg::Box::Create(sfg::Box::Orientation::VERTICAL);
    sfg::RadioButtonGroup::Ptr buttonGroup1(sfg::RadioButtonGroup::Create());

    sfg::Box::Ptr buttonLayout2 = sfg::Box::Create(sfg::Box::Orientation::VERTICAL);
    sfg::RadioButtonGroup::Ptr buttonGroup2(sfg::RadioButtonGroup::Create());

    int iMax(colors.size());
    for (int i=0; i<iMax; ++i)
    {
        whiteButtons[i] = sfg::RadioButton::Create(colors[i],buttonGroup1);
        blackButtons[i] = sfg::RadioButton::Create(colors[i],buttonGroup2);

        buttonLayout1->Pack(whiteButtons[i]);
        buttonLayout2->Pack(blackButtons[i]);
    }

    sfg::Frame::Ptr frame1(sfg::Frame::Create("White"));
    frame1->Add(buttonLayout1);

    sfg::Frame::Ptr frame2(sfg::Frame::Create("Black"));
    frame2->Add(buttonLayout2);

    sfg::Box::Ptr buttonLayout3 = sfg::Box::Create(sfg::Box::Orientation::VERTICAL);
    sfg::RadioButtonGroup::Ptr buttonGroup3(sfg::RadioButtonGroup::Create());

    iMax = boardColors.size();
    for (int i=0; i<iMax; ++i)
    {
        boardButtons[i] = sfg::RadioButton::Create(boardColors[i],buttonGroup3);

        buttonLayout3->Pack(boardButtons[i]);
    }

    sfg::Frame::Ptr frame3(sfg::Frame::Create("Board"));
    frame3->Add(buttonLayout3);

    sfg::Table::Ptr mainLayout(sfg::Table::Create());
    mainLayout->SetRowSpacings(3.f);
    mainLayout->SetColumnSpacings(3.f);

    mainLayout->Attach(frame1,{0,0,1,1});
    mainLayout->Attach(frame2,{1,0,1,1});
    mainLayout->Attach(frame3,{2,0,1,1});
    mainLayout->Attach(closeButton,{2,1,1,1});

    closeButton->GetSignal(sfg::Widget::OnLeftClick).Connect(std::bind(&Settings::requestClose,this));

    window->Add(mainLayout);
}
Exemple #11
0
int main( int argc, char** argv ){

	if (argc != 2) {
		printf("USAGE: %s <input>\n", argv[0]);
		return -1;
	}

	char* file = (char *)"file";
	int nFrames;
	uint rows, cols, fps, type;
	uint qY = 8, qU = 16, qV = 16;
	uint mode = 7;

	BitStream bs = BitStream(file, BitStream::WRITE);

	YuvReader reader(argv[1]);
	printf("%d\n", reader.open());
	printf("%d\n", reader.readHeader());

	rows = reader.getNRows();
	cols = reader.getNCols();
	fps = reader.getFps();
	type = reader.getType();

	printf("%d, %d, %d, %d, %d, %d, %d, %d\n", cols, rows, fps, type, mode, qY, qU, qV);

	printf("%d\n", bs.open());

	YuvFrame frame1(type, rows, cols);

	IntraCoder::writeHeader(rows, cols, fps, type, mode, qY, qU, qV, bs);

	while (reader.readFrame(frame1) == 0){
		printf("frame #%d\n",nFrames++);
		IntraCoder::encode(frame1, bs, mode, qY, qU, qV);
	}

	bs.close();

	printf("Done! %d frames!\n",nFrames);

	nFrames = rows = cols = fps = type = qY = qU = qV = mode = 0;

	BitStream bs1 = BitStream(file, BitStream::READ);
	printf("%d\n", bs1.open());

	printf("%d\n", IntraCoder::readHeader(bs1, &rows, &cols, &fps, &type, &mode, &qY, &qU, &qV));
	YuvFrame frame2(type, rows, cols);

	YuvDisplay display((char*)"YuvShow", fps, rows, cols);
	printf("%d, %d, %d, %d, %d, %d, %d, %d\n", cols, rows, fps, type, mode, qY, qU, qV);

	display.start();

	while (IntraCoder::decode(bs1, frame2, mode, qY, qU, qV) == 0){
		printf("frame #%d\n",nFrames++);
		display.displayFrame(frame2);
	}

	bs1.close();

	return 0;
}
Exemple #12
0
void SampleApp::Run() {
	sf::Event event;

	//m_window.SetFramerateLimit( 60 );
	//m_window.EnableVerticalSync( true );

	// Tune Renderer
	sfg::Renderer::Get().TuneDepthTest( sfg::Renderer::ALTERNATE_DEPTH );
	sfg::Renderer::Get().TuneAlphaThreshold( .2f );
	sfg::Renderer::Get().TunePrecomputeBlending( true );
	sfg::Renderer::Get().TuneCull( true );

	// Create widgets.
	m_wndmain = sfg::Window::Create( sfg::Window::TITLEBAR | sfg::Window::BACKGROUND | sfg::Window::RESIZE );
	m_wndmain->SetTitle( L"Example application" );

	sfg::Button::Ptr btnaddbuttonh( sfg::Button::Create( L"Add button horizontally" ) );
	sfg::Button::Ptr btnaddbuttonv( sfg::Button::Create( L"Add button vertically" ) );
	m_titlebar_toggle = sfg::ToggleButton::Create( "Toggle titlebar" );
	m_titlebar_toggle->SetActive( true );

	{
		sf::Image add_image;
		if( add_image.loadFromFile( "data/add.png" ) ) {
			sfg::Image::Ptr image( sfg::Image::Create( add_image ) );
			btnaddbuttonh->SetImage( image );

			image = sfg::Image::Create( add_image );
			btnaddbuttonv->SetImage( image );
		}
	}

	sfg::Button::Ptr btnhidewindow( sfg::Button::Create( L"Close window" ) );
	btnhidewindow->SetId( "close" );

	{
		sf::Image close_image;
		if( close_image.loadFromFile( "data/delete.png" ) ) {
			sfg::Image::Ptr image( sfg::Image::Create( close_image ) );
			btnhidewindow->SetImage( image );
		}
	}

	sfg::Button::Ptr btntogglespace( sfg::Button::Create( L"Box Spacing") );
	sfg::Button::Ptr btnloadstyle( sfg::Button::Create( L"Load theme") );

	m_entry = sfg::Entry::Create( L"Type" );
	m_entry->SetRequisition( sf::Vector2f( 100.f, .0f ) );
	m_entry->AppendText( L" something!" );

	m_limit_check = sfg::CheckButton::Create( L"Limit to 4 chars" );
	m_limit_check->SetId( "limit_check" );

	sfg::Entry::Ptr password( sfg::Entry::Create() );
	password->HideText( '*' );

	// Layout.
	sfg::Box::Ptr boxtoolbar( sfg::Box::Create( sfg::Box::HORIZONTAL ) );
	boxtoolbar->SetSpacing( 5.f );
	boxtoolbar->Pack( btnaddbuttonh, false );
	boxtoolbar->Pack( btnaddbuttonv, false );
	boxtoolbar->Pack( m_titlebar_toggle, false );
	boxtoolbar->Pack( btnhidewindow, false );
	boxtoolbar->Pack( m_entry, true );
	boxtoolbar->Pack( m_limit_check, false );

	sfg::Frame::Ptr frame1( sfg::Frame::Create( L"Toolbar 1" ) );
	frame1->Add( boxtoolbar );

	sfg::Box::Ptr boxtoolbar2( sfg::Box::Create( sfg::Box::HORIZONTAL ) );
	boxtoolbar2->SetSpacing( 5.f );
	boxtoolbar2->Pack( btntogglespace, false );
	boxtoolbar2->Pack( btnloadstyle, false );

	m_boxbuttonsh = sfg::Box::Create( sfg::Box::HORIZONTAL );
	m_boxbuttonsh->SetSpacing( 5.f );

	m_boxbuttonsv = sfg::Box::Create( sfg::Box::VERTICAL );
	m_boxbuttonsv->SetSpacing( 5.f );

	sfg::Entry::Ptr username_entry( sfg::Entry::Create() );
	username_entry->SetMaximumLength( 8 );

	m_progress = sfg::ProgressBar::Create( sfg::ProgressBar::HORIZONTAL );
	m_progress->SetRequisition( sf::Vector2f( 0.f, 20.f ) );

	m_progress_vert = sfg::ProgressBar::Create( sfg::ProgressBar::VERTICAL );
	m_progress_vert->SetRequisition( sf::Vector2f( 20.f, 0.f ) );

	sfg::Separator::Ptr separatorv( sfg::Separator::Create( sfg::Separator::VERTICAL ) );

	m_table = sfg::Table::Create();
	m_table->Attach( sfg::Label::Create( L"Please login using your username and password (span example)." ), sf::Rect<sf::Uint32>( 0, 0, 2, 1 ), sfg::Table::FILL, sfg::Table::FILL | sfg::Table::EXPAND );
	m_table->Attach( sfg::Label::Create( L"Username:"******"Password:"******"Login" ), sf::Rect<sf::Uint32>( 2, 1, 1, 2 ), sfg::Table::FILL, sfg::Table::FILL );
	m_table->Attach( separatorv, sf::Rect<sf::Uint32>( 3, 0, 1, 3 ), sfg::Table::FILL, sfg::Table::FILL );
	m_table->Attach( m_progress_vert, sf::Rect<sf::Uint32>( 4, 0, 1, 3 ), sfg::Table::FILL, sfg::Table::FILL );
	m_table->SetRowSpacings( 5.f );
	m_table->SetColumnSpacings( 5.f );

	m_scrolled_window_box = sfg::Box::Create( sfg::Box::VERTICAL );

	for( int i = 0; i < 5; i++ ) {
		sfg::Box::Ptr box = sfg::Box::Create( sfg::Box::HORIZONTAL );

		for( int j = 0; j < 20; j++ ) {
			box->Pack( sfg::Button::Create( L"One button among many" ), true );
		}

		m_scrolled_window_box->Pack( box, false );
	}

	m_scrolled_window = sfg::ScrolledWindow::Create();
	m_scrolled_window->SetRequisition( sf::Vector2f( .0f, 150.f ) );
	m_scrolled_window->SetScrollbarPolicy( sfg::ScrolledWindow::HORIZONTAL_AUTOMATIC | sfg::ScrolledWindow::VERTICAL_AUTOMATIC );
	m_scrolled_window->SetPlacement( sfg::ScrolledWindow::TOP_LEFT );
	m_scrolled_window->AddWithViewport( m_scrolled_window_box );

	sfg::Scrollbar::Ptr scrollbar( sfg::Scrollbar::Create() );
	scrollbar->SetRange( .0f, 100.f );

	m_scale = sfg::Scale::Create();
	m_scale->SetAdjustment( scrollbar->GetAdjustment() );
	m_scale->SetRequisition( sf::Vector2f( 100.f, .0f ) );
	boxtoolbar2->Pack( m_scale, false );

	m_combo_box = sfg::ComboBox::Create();
	m_combo_box->AppendItem( "Item 0" );
	m_combo_box->AppendItem( "Item 1" );
	m_combo_box->AppendItem( "Item 2" );
	m_combo_box->AppendItem( "Item 3" );
	boxtoolbar2->Pack( m_combo_box, true );

	sfg::Frame::Ptr frame2( sfg::Frame::Create( L"Toolbar 2" ) );
	frame2->Add( boxtoolbar2 );
	frame2->SetAlignment( sf::Vector2f( .8f, .0f ) );

	sfg::Separator::Ptr separatorh( sfg::Separator::Create( sfg::Separator::HORIZONTAL ) );

	sfg::Box::Ptr box_image( sfg::Box::Create( sfg::Box::HORIZONTAL ) );
	box_image->SetSpacing( 5.f );

	sfg::Fixed::Ptr fixed_container( sfg::Fixed::Create() );
	sfg::Button::Ptr fixed_button( sfg::Button::Create( L"I'm at (34,61)" ) );
	fixed_container->Put( fixed_button, sf::Vector2f( 34.f, 61.f ) );
	box_image->Pack( fixed_container, false );

	sf::Image sfgui_logo;
	sfg::Image::Ptr image = sfg::Image::Create();

	if( sfgui_logo.loadFromFile("sfgui.png") ) {
		image->SetImage( sfgui_logo );
		box_image->Pack( image, false );
	}

	sfg::Box::Ptr spinner_box( sfg::Box::Create( sfg::Box::VERTICAL ) );

	m_spinner = sfg::Spinner::Create();
	m_spinner->SetRequisition( sf::Vector2f( 40.f, 40.f ) );
	m_spinner->Start();
	sfg::ToggleButton::Ptr spinner_toggle( sfg::ToggleButton::Create( L"Spin") );
	spinner_toggle->SetActive( true );
	spinner_box->SetSpacing( 5.f );
	spinner_box->Pack( m_spinner, false );
	spinner_box->Pack( spinner_toggle, false );

	box_image->Pack( spinner_box, false );

	sfg::ComboBox::Ptr aligned_combo_box( sfg::ComboBox::Create() );
	aligned_combo_box->AppendItem( L"I'm way over here" );
	aligned_combo_box->AppendItem( L"Me too" );
	aligned_combo_box->AppendItem( L"Me three" );
	aligned_combo_box->SelectItem( 0 );

	sfg::Alignment::Ptr alignment( sfg::Alignment::Create() );
	alignment->Add( aligned_combo_box );
	box_image->Pack( alignment, true );
	alignment->SetAlignment( sf::Vector2f( 1.f, .5f ) );
	alignment->SetScale( sf::Vector2f( 0.f, .01f ) );

	sfg::Box::Ptr boxmain( sfg::Box::Create( sfg::Box::VERTICAL ) );
	boxmain->SetSpacing( 5.f );
	boxmain->Pack( scrollbar, false );
	boxmain->Pack( m_progress, false );
	boxmain->Pack( frame1, false );
	boxmain->Pack( frame2, false );
	boxmain->Pack( m_boxbuttonsh, false );
	boxmain->Pack( m_boxbuttonsv, false );
	boxmain->Pack( box_image, true );
	boxmain->Pack( separatorh, false );
	boxmain->Pack( m_table, true );
	boxmain->Pack( m_scrolled_window );

	sfg::Notebook::Ptr notebook1( sfg::Notebook::Create() );
	sfg::Notebook::Ptr notebook2( sfg::Notebook::Create() );
	sfg::Notebook::Ptr notebook3( sfg::Notebook::Create() );
	sfg::Notebook::Ptr notebook4( sfg::Notebook::Create() );

	notebook1->SetTabPosition( sfg::Notebook::TOP );
	notebook2->SetTabPosition( sfg::Notebook::RIGHT );
	notebook3->SetTabPosition( sfg::Notebook::BOTTOM );
	notebook4->SetTabPosition( sfg::Notebook::LEFT );

	sfg::Box::Ptr vertigo_box( sfg::Box::Create( sfg::Box::HORIZONTAL ) );
	sfg::Button::Ptr vertigo_button( sfg::Button::Create( L"Vertigo" ) );
	vertigo_box->Pack( vertigo_button, true, true );

	notebook1->AppendPage( boxmain, sfg::Label::Create( "Page Name Here" ) );
	notebook1->AppendPage( notebook2, sfg::Label::Create( "Another Page" ) );
	notebook2->AppendPage( notebook3, sfg::Label::Create( "Yet Another Page" ) );
	notebook2->AppendPage( sfg::Label::Create( L"" ), sfg::Label::Create( "Dummy Page" ) );
	notebook3->AppendPage( notebook4, sfg::Label::Create( "And Another Page" ) );
	notebook3->AppendPage( sfg::Label::Create( L"" ), sfg::Label::Create( "Dummy Page" ) );
	notebook4->AppendPage( vertigo_box, sfg::Label::Create( "And The Last Page" ) );
	notebook4->AppendPage( sfg::Label::Create( L"" ), sfg::Label::Create( "Dummy Page" ) );

	m_wndmain->Add( notebook1 );

	// Signals.
	btnaddbuttonh->OnClick.Connect( &SampleApp::OnAddButtonHClick, this );
	btnaddbuttonv->OnClick.Connect( &SampleApp::OnAddButtonVClick, this );
	m_titlebar_toggle->OnClick.Connect( &SampleApp::OnToggleTitlebarClick, this );
	btnhidewindow->OnClick.Connect( &SampleApp::OnHideWindowClicked, this );
	btntogglespace->OnClick.Connect( &SampleApp::OnToggleSpaceClick, this );
	m_limit_check->OnToggle.Connect( &SampleApp::OnLimitCharsToggle, this );
	btnloadstyle->OnClick.Connect( &SampleApp::OnLoadThemeClick, this );
	m_scale->GetAdjustment()->OnChange.Connect( &SampleApp::OnAdjustmentChange, this );
	spinner_toggle->OnClick.Connect( &SampleApp::OnToggleSpinner, this );

	m_wndmain->SetPosition( sf::Vector2f( 100.f, 100.f ) );

	// Another window
	sfg::Window::Ptr second_window( sfg::Window::Create( sfg::Window::TITLEBAR | sfg::Window::BACKGROUND ) );
	second_window->SetId( "second_window" );
	second_window->SetTitle( "Another window" );
	sfg::Box::Ptr box( sfg::Box::Create( sfg::Box::VERTICAL, 5.f ) );
	box->Pack( sfg::Label::Create( "Aliquam sed pretium lacus." ), false );
	box->Pack( sfg::Label::Create( "Nullam placerat mauris vel nulla sagittis pellentesque." ), false );
	box->Pack( sfg::Label::Create( "Suspendisse in justo dui." ), false );
	box->Pack( sfg::Label::Create( "Ut dolor massa, gravida eu facilisis convallis, convallis sed odio." ), false );
	box->Pack( sfg::Label::Create( "Nunc placerat consequat vehicula." ), false );
	second_window->Add( box );
	second_window->SetPosition( sf::Vector2f( 10.f, 10.f ) );
	second_window->SetId( "second_window" );
	m_desktop.Add( second_window );

	// Add window to desktop
	m_desktop.Add( m_wndmain );

	// Play around with resource manager.
	sf::Font my_font;
	my_font.loadFromFile( "data/linden_hill.otf" );
	m_desktop.GetEngine().GetResourceManager().AddFont( "custom_font", my_font, false ); // false -> do not manage!

	// Set properties.
	m_desktop.SetProperty( "Button#close:Normal", "Color", sf::Color::Yellow );
	m_desktop.SetProperty( "Button#close", "FontName", "data/linden_hill.otf" );
	m_desktop.SetProperty( "Button#close", "FontSize", 15.f );
	m_desktop.SetProperty( "Window#second_window > Box > Label", "FontName", "custom_font" );
	m_desktop.SetProperty( "Window#second_window > Box > Label", "FontSize", 18.f );

	m_fps_counter = 0;
	m_fps_clock.restart();

	sf::Clock clock;

	while( m_window.isOpen() ) {
		while( m_window.pollEvent( event ) ) {
			if( event.type == sf::Event::Closed ) {
				m_window.close();
			}
			else if( event.type == sf::Event::Resized ) {
				m_desktop.UpdateViewRect( sf::FloatRect( 0.f, 0.f, static_cast<float>( event.size.width ), static_cast<float>( event.size.height ) ) );
			}

			m_desktop.HandleEvent( event );
		}

		m_window.draw( m_background_sprite );

		sf::Uint64 microseconds = clock.getElapsedTime().asMicroseconds();

		// Only update every 5ms
		if( microseconds > 5000 ) {
			m_desktop.Update( static_cast<float>( microseconds ) / 1000000.f );
			clock.restart();
		}

		sfg::Renderer::Get().Display( m_window );

		m_window.display();

		if( m_fps_clock.getElapsedTime().asMicroseconds() >= 1000000 ) {
			m_fps_clock.restart();

			std::stringstream sstr;
			sstr << "SFGUI test -- FPS: " << m_fps_counter;

			m_window.setTitle( sstr.str() );

			m_fps_counter = 0;
		}

		++m_fps_counter;
	}
}
Exemple #13
0
void SampleApp::Run() {
	sf::Event event;

	//m_window.SetFramerateLimit( 60 );
	//m_window.EnableVerticalSync( true );

	// Tune Renderer
	m_sfgui.TuneUseFBO( true );
	m_sfgui.TuneAlphaThreshold( .2f );
	m_sfgui.TuneCull( true );

	// Create widgets.
	m_wndmain = sfg::Window::Create( sfg::Window::TITLEBAR | sfg::Window::BACKGROUND | sfg::Window::RESIZE );
	m_wndmain->SetTitle( L"Example application" );

	sfg::Button::Ptr btnaddbuttonh( sfg::Button::Create( L"Add button horizontally" ) );
	sfg::Button::Ptr btnaddbuttonv( sfg::Button::Create( L"Add button vertically" ) );
	m_titlebar_toggle = sfg::ToggleButton::Create( "Toggle titlebar" );
	m_titlebar_toggle->SetActive( true );

	{
		sf::Image add_image;
		if( add_image.loadFromFile( "data/add.png" ) ) {
			sfg::Image::Ptr image( sfg::Image::Create( add_image ) );
			btnaddbuttonh->SetImage( image );

			image = sfg::Image::Create( add_image );
			btnaddbuttonv->SetImage( image );
		}
	}

	sfg::Button::Ptr btnhidewindow( sfg::Button::Create( L"Close window" ) );
	btnhidewindow->SetId( "close" );

	{
		sf::Image close_image;
		if( close_image.loadFromFile( "data/delete.png" ) ) {
			sfg::Image::Ptr image( sfg::Image::Create( close_image ) );
			btnhidewindow->SetImage( image );
		}
	}

	sfg::Button::Ptr btntogglespace( sfg::Button::Create( L"Box Spacing") );
	sfg::Button::Ptr btnloadstyle( sfg::Button::Create( L"Load theme") );

	m_entry = sfg::Entry::Create( L"Type" );
	m_entry->SetRequisition( sf::Vector2f( 100.f, .0f ) );
	m_entry->AppendText( L" something!" );

	m_limit_check = sfg::CheckButton::Create( L"Limit to 4 chars" );
	m_limit_check->SetId( "limit_check" );

	sfg::Entry::Ptr password( sfg::Entry::Create() );
	password->HideText( '*' );

	// Layout.
	sfg::Box::Ptr boxtoolbar( sfg::Box::Create( sfg::Box::HORIZONTAL ) );
	boxtoolbar->SetSpacing( 5.f );
	boxtoolbar->Pack( btnaddbuttonh, false );
	boxtoolbar->Pack( btnaddbuttonv, false );
	boxtoolbar->Pack( m_titlebar_toggle, false );
	boxtoolbar->Pack( btnhidewindow, false );
	boxtoolbar->Pack( m_entry, true );
	boxtoolbar->Pack( m_limit_check, false );

	sfg::Frame::Ptr frame1( sfg::Frame::Create( L"Toolbar 1" ) );
	frame1->Add( boxtoolbar );

	sfg::Box::Ptr boxtoolbar2( sfg::Box::Create( sfg::Box::HORIZONTAL ) );
	boxtoolbar2->SetSpacing( 5.f );
	boxtoolbar2->Pack( btntogglespace, false );
	boxtoolbar2->Pack( btnloadstyle, false );

	m_boxbuttonsh = sfg::Box::Create( sfg::Box::HORIZONTAL );
	m_boxbuttonsh->SetSpacing( 5.f );

	m_boxbuttonsv = sfg::Box::Create( sfg::Box::VERTICAL );
	m_boxbuttonsv->SetSpacing( 5.f );

	sfg::Entry::Ptr username_entry( sfg::Entry::Create() );
	username_entry->SetMaximumLength( 8 );

	m_progress = sfg::ProgressBar::Create( sfg::ProgressBar::HORIZONTAL );
	m_progress->SetRequisition( sf::Vector2f( 0.f, 20.f ) );

	m_progress_vert = sfg::ProgressBar::Create( sfg::ProgressBar::VERTICAL );
	m_progress_vert->SetRequisition( sf::Vector2f( 20.f, 0.f ) );

	sfg::Separator::Ptr separatorv( sfg::Separator::Create( sfg::Separator::VERTICAL ) );

	m_table = sfg::Table::Create();
	m_table->Attach( sfg::Label::Create( L"Please login using your username and password (span example)." ), sf::Rect<sf::Uint32>( 0, 0, 2, 1 ), sfg::Table::FILL, sfg::Table::FILL | sfg::Table::EXPAND );
	m_table->Attach( sfg::Label::Create( L"Username:"******"Password:"******"Login" ), sf::Rect<sf::Uint32>( 2, 1, 1, 2 ), sfg::Table::FILL, sfg::Table::FILL );
	m_table->Attach( separatorv, sf::Rect<sf::Uint32>( 3, 0, 1, 3 ), sfg::Table::FILL, sfg::Table::FILL );
	m_table->Attach( m_progress_vert, sf::Rect<sf::Uint32>( 4, 0, 1, 3 ), sfg::Table::FILL, sfg::Table::FILL );
	m_table->SetRowSpacings( 5.f );
	m_table->SetColumnSpacings( 5.f );

	m_scrolled_window_box = sfg::Box::Create( sfg::Box::VERTICAL );

	for( int i = 0; i < 5; i++ ) {
		sfg::Box::Ptr box = sfg::Box::Create( sfg::Box::HORIZONTAL );

		for( int j = 0; j < 20; j++ ) {
			box->Pack( sfg::Button::Create( L"One button among many" ), true );
		}

		m_scrolled_window_box->Pack( box, false );
	}

	m_scrolled_window = sfg::ScrolledWindow::Create();
	m_scrolled_window->SetRequisition( sf::Vector2f( .0f, 160.f ) );
	m_scrolled_window->SetScrollbarPolicy( sfg::ScrolledWindow::HORIZONTAL_AUTOMATIC | sfg::ScrolledWindow::VERTICAL_AUTOMATIC );
	m_scrolled_window->SetPlacement( sfg::ScrolledWindow::TOP_LEFT );
	m_scrolled_window->AddWithViewport( m_scrolled_window_box );

	sfg::Scrollbar::Ptr scrollbar( sfg::Scrollbar::Create() );
	scrollbar->SetRange( .0f, 100.f );

	m_scale = sfg::Scale::Create();
	m_scale->SetAdjustment( scrollbar->GetAdjustment() );
	m_scale->SetRequisition( sf::Vector2f( 100.f, .0f ) );
	boxtoolbar2->Pack( m_scale, false );

	m_combo_box = sfg::ComboBox::Create();

	for( int index = 0; index < 30; ++index ) {
		std::stringstream sstr;

		sstr << "Item " << index;

		m_combo_box->AppendItem( sstr.str() );
	}

	boxtoolbar2->Pack( m_combo_box, true );

	sfg::Frame::Ptr frame2( sfg::Frame::Create( L"Toolbar 2" ) );
	frame2->Add( boxtoolbar2 );
	frame2->SetAlignment( sf::Vector2f( .8f, .0f ) );

	sfg::Separator::Ptr separatorh( sfg::Separator::Create( sfg::Separator::HORIZONTAL ) );

	sfg::Box::Ptr box_image( sfg::Box::Create( sfg::Box::HORIZONTAL ) );
	box_image->SetSpacing( 15.f );

	sfg::Fixed::Ptr fixed_container( sfg::Fixed::Create() );
	sfg::Button::Ptr fixed_button( sfg::Button::Create( L"I'm at (34,61)" ) );
	fixed_container->Put( fixed_button, sf::Vector2f( 34.f, 61.f ) );
	box_image->Pack( fixed_container, false );

	sf::Image sfgui_logo;
	m_image = sfg::Image::Create();

	if( sfgui_logo.loadFromFile( "data/sfgui.png" ) ) {
		m_image->SetImage( sfgui_logo );
		box_image->Pack( m_image, false );
	}

	sfg::Button::Ptr mirror_image( sfg::Button::Create( L"Mirror Image" ) );

	box_image->Pack( mirror_image, false );

	sfg::Box::Ptr spinner_box( sfg::Box::Create( sfg::Box::VERTICAL ) );

	m_spinner = sfg::Spinner::Create();
	m_spinner->SetRequisition( sf::Vector2f( 40.f, 40.f ) );
	m_spinner->Start();
	sfg::ToggleButton::Ptr spinner_toggle( sfg::ToggleButton::Create( L"Spin") );
	spinner_toggle->SetActive( true );
	spinner_box->SetSpacing( 5.f );
	spinner_box->Pack( m_spinner, false );
	spinner_box->Pack( spinner_toggle, false );

	box_image->Pack( spinner_box, false );

	sfg::Box::Ptr radio_box( sfg::Box::Create( sfg::Box::VERTICAL ) );

	sfg::RadioButton::Ptr radio1( sfg::RadioButton::Create( "Radio 1" ) );
	sfg::RadioButton::Ptr radio2( sfg::RadioButton::Create( "Radio 2", radio1->GetGroup() ) );
	sfg::RadioButton::Ptr radio3( sfg::RadioButton::Create( "Radio 3", radio2->GetGroup() ) );

	radio_box->Pack( radio1 );
	radio_box->Pack( radio2 );
	radio_box->Pack( radio3 );

	box_image->Pack( radio_box, false );

	sfg::SpinButton::Ptr spinbutton( sfg::SpinButton::Create( scrollbar->GetAdjustment() ) );
	spinbutton->SetRequisition( sf::Vector2f( 80.f, 0.f ) );
	spinbutton->SetDigits( 3 );

	sfg::Box::Ptr spinbutton_box( sfg::Box::Create( sfg::Box::VERTICAL ) );
	spinbutton_box->Pack( spinbutton, false, false );

	box_image->Pack( spinbutton_box, false, false );

	sfg::ComboBox::Ptr aligned_combo_box( sfg::ComboBox::Create() );
	aligned_combo_box->AppendItem( L"I'm way over here" );
	aligned_combo_box->AppendItem( L"Me too" );
	aligned_combo_box->AppendItem( L"Me three" );
	aligned_combo_box->SelectItem( 0 );

	sfg::Alignment::Ptr alignment( sfg::Alignment::Create() );
	alignment->Add( aligned_combo_box );
	box_image->Pack( alignment, true );
	alignment->SetAlignment( sf::Vector2f( 1.f, .5f ) );
	alignment->SetScale( sf::Vector2f( 0.f, .01f ) );

	sfg::Box::Ptr boxmain( sfg::Box::Create( sfg::Box::VERTICAL ) );
	boxmain->SetSpacing( 5.f );
	boxmain->Pack( scrollbar, false );
	boxmain->Pack( m_progress, false );
	boxmain->Pack( frame1, false );
	boxmain->Pack( frame2, false );
	boxmain->Pack( m_boxbuttonsh, false );
	boxmain->Pack( m_boxbuttonsv, false );
	boxmain->Pack( box_image, true );
	boxmain->Pack( separatorh, false );
	boxmain->Pack( m_table, true );
	boxmain->Pack( m_scrolled_window );

	sfg::Notebook::Ptr notebook1( sfg::Notebook::Create() );
	sfg::Notebook::Ptr notebook2( sfg::Notebook::Create() );
	sfg::Notebook::Ptr notebook3( sfg::Notebook::Create() );
	sfg::Notebook::Ptr notebook4( sfg::Notebook::Create() );

	notebook1->SetTabPosition( sfg::Notebook::TOP );
	notebook2->SetTabPosition( sfg::Notebook::RIGHT );
	notebook3->SetTabPosition( sfg::Notebook::BOTTOM );
	notebook4->SetTabPosition( sfg::Notebook::LEFT );

	sfg::Box::Ptr vertigo_box( sfg::Box::Create( sfg::Box::HORIZONTAL ) );
	sfg::Button::Ptr vertigo_button( sfg::Button::Create( L"Vertigo" ) );
	vertigo_box->Pack( vertigo_button, true, true );

	notebook1->AppendPage( boxmain, sfg::Label::Create( "Page Name Here" ) );
	notebook1->AppendPage( notebook2, sfg::Label::Create( "Another Page" ) );
	notebook2->AppendPage( notebook3, sfg::Label::Create( "Yet Another Page" ) );
	notebook2->AppendPage( sfg::Label::Create( L"" ), sfg::Label::Create( "Dummy Page" ) );
	notebook3->AppendPage( notebook4, sfg::Label::Create( "And Another Page" ) );
	notebook3->AppendPage( sfg::Label::Create( L"" ), sfg::Label::Create( "Dummy Page" ) );
	notebook4->AppendPage( vertigo_box, sfg::Label::Create( "And The Last Page" ) );
	notebook4->AppendPage( sfg::Label::Create( L"" ), sfg::Label::Create( "Dummy Page" ) );

	m_wndmain->Add( notebook1 );

	// Signals.
	btnaddbuttonh->GetSignal( sfg::Widget::OnLeftClick ).Connect( &SampleApp::OnAddButtonHClick, this );
	btnaddbuttonv->GetSignal( sfg::Widget::OnLeftClick ).Connect( &SampleApp::OnAddButtonVClick, this );
	m_titlebar_toggle->GetSignal( sfg::Widget::OnLeftClick ).Connect( &SampleApp::OnToggleTitlebarClick, this );
	btnhidewindow->GetSignal( sfg::Widget::OnLeftClick ).Connect( &SampleApp::OnHideWindowClicked, this );
	btntogglespace->GetSignal( sfg::Widget::OnLeftClick ).Connect( &SampleApp::OnToggleSpaceClick, this );
	m_limit_check->GetSignal( sfg::ToggleButton::OnToggle ).Connect( &SampleApp::OnLimitCharsToggle, this );
	btnloadstyle->GetSignal( sfg::Widget::OnLeftClick ).Connect( &SampleApp::OnLoadThemeClick, this );
	m_scale->GetAdjustment()->GetSignal( sfg::Adjustment::OnChange ).Connect( &SampleApp::OnAdjustmentChange, this );
	spinner_toggle->GetSignal( sfg::Widget::OnLeftClick ).Connect( &SampleApp::OnToggleSpinner, this );
	mirror_image->GetSignal( sfg::Widget::OnLeftClick ).Connect( &SampleApp::OnMirrorImageClick, this );

	spinbutton->SetValue( 20.f );
	spinbutton->GetAdjustment()->SetMinorStep( .8f );

	m_wndmain->SetPosition( sf::Vector2f( 100.f, 100.f ) );

	// Another window
	sfg::Window::Ptr second_window( sfg::Window::Create( sfg::Window::TITLEBAR | sfg::Window::BACKGROUND | sfg::Window::RESIZE ) );
	second_window->SetId( "second_window" );
	second_window->SetTitle( "Resize this window to see ad-hoc wrapping." );
	sfg::Box::Ptr box( sfg::Box::Create( sfg::Box::VERTICAL, 5.f ) );

	sfg::Label::Ptr lipsum = sfg::Label::Create(
		"Nullam ut ante leo. Quisque consequat condimentum pulvinar. "
		"Duis a enim sapien, ut vestibulum est. Vestibulum commodo, orci non gravida. "
		"Aliquam sed pretium lacus. "
		"Nullam placerat mauris vel nulla sagittis pellentesque. "
		"Suspendisse in justo dui.\n"
		"Ut dolor massa, gravida eu facilisis convallis, convallis sed odio.\n"
		"Nunc placerat consequat vehicula."
	);

	lipsum->SetRequisition( sf::Vector2f( 400.f, 0.f ) );
	lipsum->SetLineWrap( true );

	box->Pack( lipsum );
	second_window->Add( box );
	second_window->SetPosition( sf::Vector2f( 10.f, 10.f ) );
	second_window->SetId( "second_window" );
	m_desktop.Add( second_window );

	sfg::Window::Ptr third_window( sfg::Window::Create( sfg::Window::TITLEBAR | sfg::Window::BACKGROUND | sfg::Window::RESIZE ) );

	m_gl_canvas = sfg::Canvas::Create( true );
	m_gl_canvas->SetRequisition( sf::Vector2f( 200.f, 150.f ) );

	third_window->Add( m_gl_canvas );

	third_window->SetId( "third_window" );
	third_window->SetTitle( "Embedded OpenGL drawing" );
	third_window->SetPosition( sf::Vector2f( 480.f, 20.f ) );
	m_desktop.Add( third_window );

	sf::Texture texture;
	texture.loadFromImage( sfgui_logo );
	m_canvas_sprite.setTexture( texture );

	sfg::Window::Ptr fourth_window( sfg::Window::Create( sfg::Window::TITLEBAR | sfg::Window::BACKGROUND | sfg::Window::RESIZE ) );

	m_sfml_canvas = sfg::Canvas::Create();
	m_sfml_canvas->SetRequisition( sf::Vector2f( static_cast<float>( texture.getSize().x ), static_cast<float>( texture.getSize().y ) ) );

	fourth_window->Add( m_sfml_canvas );

	fourth_window->SetId( "fourth_window" );
	fourth_window->SetTitle( "Embedded SFML drawing" );
	fourth_window->SetPosition( sf::Vector2f( 760.f, 20.f ) );
	m_desktop.Add( fourth_window );

	// Add window to desktop
	m_desktop.Add( m_wndmain );

	// Play around with resource manager.
	sf::Font my_font;
	my_font.loadFromFile( "data/linden_hill.otf" );
	m_desktop.GetEngine().GetResourceManager().AddFont( "custom_font", my_font, false ); // false -> do not manage!

	// Set properties.
	m_desktop.SetProperty( "Button#close:Normal", "Color", sf::Color::Yellow );
	// #close is sufficient since there is only 1 widget with this id
	m_desktop.SetProperty( "#close", "FontName", "data/linden_hill.otf" );
	m_desktop.SetProperty( "#close", "FontSize", 15.f );

	// Multiple properties can be set at once to save calls.
	m_desktop.SetProperties(
		"Window#second_window > Box > Label {"
		"	FontName: custom_font;"
		"	FontSize: 18;"
		"}"
	);

	m_fps_counter = 0;
	m_fps_clock.restart();

	sf::Clock clock;
	sf::Clock frame_time_clock;

	sf::Int64 frame_times[5000];
	std::size_t frame_times_index = 0;

	while( m_window.isOpen() ) {
		while( m_window.pollEvent( event ) ) {
			if( event.type == sf::Event::Closed ) {
				m_window.close();
			}
			else if( event.type == sf::Event::Resized ) {
				m_desktop.UpdateViewRect( sf::FloatRect( 0.f, 0.f, static_cast<float>( event.size.width ), static_cast<float>( event.size.height ) ) );
			}

			m_desktop.HandleEvent( event );
		}

		m_window.draw( m_background_sprite );

		sf::Uint64 microseconds = clock.getElapsedTime().asMicroseconds();

		// Only update every 5ms
		if( microseconds > 5000 ) {
			m_desktop.Update( static_cast<float>( microseconds ) / 1000000.f );
			clock.restart();

			// Only refresh canvas contents every 5ms too
			m_gl_canvas->Bind();
			m_gl_canvas->Clear( sf::Color( 0, 0, 0, 0 ), true );
			RenderCustomGL();
			m_gl_canvas->Display();
			m_gl_canvas->Unbind();

			m_sfml_canvas->Bind();
			m_sfml_canvas->Clear( sf::Color( 0, 0, 0, 0 ) );
			RenderCustomSFML();
			m_sfml_canvas->Display();
			m_sfml_canvas->Unbind();

			m_window.setActive( true );
		}

		m_sfgui.Display( m_window );

		m_window.display();

		sf::Int64 frame_time = frame_time_clock.getElapsedTime().asMicroseconds();
		frame_time_clock.restart();

		frame_times[ frame_times_index ] = frame_time;
		frame_times_index = ( frame_times_index + 1 ) % 5000;

		if( m_fps_clock.getElapsedTime().asMicroseconds() >= 1000000 ) {
			m_fps_clock.restart();

			sf::Int64 total_time = 0;

			for( std::size_t index = 0; index < 5000; ++index ) {
				total_time += frame_times[index];
			}

			std::stringstream sstr;
			sstr << "SFGUI test -- FPS: " << m_fps_counter << " -- Frame Time (microsecs): min: "
			<< *std::min_element( frame_times, frame_times + 5000 ) << " max: "
			<< *std::max_element( frame_times, frame_times + 5000 ) << " avg: "
			<< static_cast<float>( total_time ) / 5000.f;

			m_window.setTitle( sstr.str() );

			m_fps_counter = 0;
		}

		++m_fps_counter;
	}

	glDeleteLists( m_custom_draw_display_list, 1 );
}
	static int load()
	{
		FreeTypeDecoder::initialize();

		ShowWindow(GetConsoleWindow(), SW_HIDE);

		Graphics3D * graphics = D3DGraphics::initialize();
		FinalAction finally(D3DGraphics::free);

		graphics->setClearColor({0.0f, 0.0f, 0.0f});

		Handle<Window> window(graphics, 0, 0, 1024, 758);
		Handle<WindowBackground> back(window);
		back->name = "Background";

		Handle<Panel> frame(back);
		frame->setPlacement({0.5f, 0.5f, 0.5f, 0.5f}, {-300, -300, 300, 300});
		frame << [](const DrawParams & p)
		{
			p.graphics->setColor({0.25f, 0.25f, 0.25f});
			p.graphics->rectangle(p.clipped);
		};

		Handle<Panel> frame0(frame);
		frame0->setPlacement(ModelMask::FullSize, {4, 4, -4, -4});
		frame0 << [](const DrawParams & p)
		{
			p.graphics->setColor({0.5f, 0.5f, 0.5f});
			p.graphics->rectangle(p.clipped);
		};

		Handle<Panel> frame1(frame0);
		frame1->setPlacement(ModelMask::FullSize, {3, 3, -3, -3});
		frame1 << [](const DrawParams & p)
		{
			p.graphics->setColor({0.75f, 0.75f, 0.75f});
			p.graphics->rectangle(p.clipped);
		};

		Handle<Panel> frame2(frame1);
		frame2->setPlacement(ModelMask::FullSize, {2, 2, -2, -2});
		frame2 << [](const DrawParams & p)
		{
			p.graphics->setColor({1.0f, 1.0f, 1.0f});
			p.graphics->rectangle(p.clipped);
		};

		Handle<Panel> panel(frame2);
		panel->setPlacement(ModelMask::FullSize, {1, 1, -1, -1});
		panel << [](const DrawParams & p)
		{
			p.graphics->setColor({0.0f, 0.0f, 0.0f});
			p.graphics->rectangle(p.clipped);
		};

		auto arial = Font::load("arial.ttf");

		graphics->bind(arial);
		graphics->setFontSize(16);

		Handle<String> project_name("Independence");
		Handle<Panel> project_name_panel(back);
		project_name_panel->setPlacement(10, 10, 0, 0);
		project_name_panel->setSize(graphics->getTextSize(*project_name));

		project_name_panel << [arial, project_name](const DrawParams & p)
		{
			auto & graphics = p.graphics;
			auto & region = p.region;
			graphics->bind(arial);
			graphics->setFontSize(16);

			p.graphics->setColor({1.0f, 1.0f, 1.0f});
			graphics->draw(region.left, region.top, *project_name);
		};

		Handle<String> text("Press Esc to quit");
		Handle<Panel> text_panel(back);
		text_panel->setPlacement(ModelMask::RightTop, {0, 10, -10, 0});
		text_panel->setSize(graphics->getTextSize(*text));

		text_panel << [arial, text](const DrawParams & p)
		{
			auto & graphics = p.graphics;
			auto & region = p.region;
			graphics->bind(arial);
			graphics->setFontSize(16);

			p.graphics->setColor({1.0f, 1.0f, 1.0f});
			graphics->draw(region.left, region.top, *text);
		};

		Handle<FpsCounter> counter(emptiness);

		Handle<Panel> fps_panel(back);
		fps_panel->setPlacement({0.5f, 1.0f, 0.5f, 1.0f}, {-40, -30, 40, -10});
		fps_panel << [counter, arial](const DrawParams & p)
		{
			auto graphics = p.graphics;
			graphics->bind(arial);
			graphics->setFontSize(16);

			auto text = String(counter->get()) + " fps";
			auto textSize = graphics->getTextSize(text);
			int left = p.region.left + (p.region.width() - textSize.x) / 2;
			int top = p.region.top + (p.region.height() - textSize.y) / 2;

			p.graphics->setColor({1.0f, 1.0f, 1.0f});
			graphics->draw(left, top, text);
		};
		
		Handle<Scene> scene(panel);
		scene->append<Snake>(color(1.0f, 0.0f, 0.0f));
		scene->append<Snake>(color(1.0f, 0.5f, 0.0f));
		scene->append<Snake>(color(1.0f, 1.0f, 0.0f));
		scene->append<Snake>(color(0.0f, 1.0f, 0.0f));
		scene->append<Snake>(color(0.0f, 1.0f, 1.0f));
		scene->append<Snake>(color(0.0f, 0.0f, 1.0f));
		scene->append<Snake>(color(0.5f, 0.0f, 1.0f));

		connect(*window, onWindowKeyDown);

		window->setBorderStyle(BorderStyle::Static);
		window->setCaption("Independence");
		window->centralize();
		window->show();

		ThreadLoop::add(processWindowMessage);
		ThreadLoop::add([scene, window, counter, fps_panel] () mutable
		{
			//std::this_thread::sleep_for(1ms);
			
			counter->next();
			window->invalidate(fps_panel);
			
			scene->invalidate();
			window->validate();

			return 0;
		});

		ThreadLoop::run();

		return 0;
	}