예제 #1
0
int main()
{
    NSInitialize();

    NSHContainer speed(300, 50);
    NSLabel speedLabel("Speed");
    NSTextField speedVal(80);

    speed.add(&speedLabel);
    speed.add(&speedVal);
    speed.reallocate();

    NSHContainer toggles(300, 50);
    NSToggleButton anim("Anim"), query("Query"), round("Rounded");

    toggles.add(&anim);
    toggles.add(&query);
    toggles.add(&round);
    toggles.reallocate();

    NSHContainer reply(300, 100);
    NSButton ok("  OK  "), cancel("Cancel");

    reply.add(&ok);
    reply.add(&cancel);
    reply.reallocate();

    NSVContainer main(300, 200);

    main.add(&speed);
    main.add(&toggles);
    main.add(&reply);
    main.reallocate();

    NSFrame frame;

    frame.container(&main);

    frame.map();

    NSMainLoop();

    return 0;
}
예제 #2
0
void sandbox(SDL_Surface *s, int width, int height){
	form sand(0,0,1000,600);
	cout<<sand.children.size()<<"\n";
	XAutomataEngine game(&sand,200,100,750,400,width,height);
	//configure key events to pass preview to sand.
	sand.tag = &game;
	sand.addHandler(event_keydown,sandKey);

	//pan controls
	Button panUp(&sand,70,190,45,45); panUp.text = "Up";
	Button panDown(&sand,70,290,45,45); panDown.text = "Down";
	Button panLeft(&sand,20,240,45,45); panLeft.text = "Left";
	Button panRight(&sand,120,240,45,45); panRight.text = "Right";
	Button home(&sand,70,240,45,45); home.text = (width==-1&&height==-1?"Home":"Fit");

	panUp.tag = panDown.tag = panLeft.tag = panRight.tag = home.tag = (void*)(&game);
	panUp.addHandler(event_Lclick,sandUpHandler);
	panDown.addHandler(event_Lclick,sandDownHandler);
	panLeft.addHandler(event_Lclick,sandLeftHandler);
	panRight.addHandler(event_Lclick,sandRightHandler);
	home.addHandler(event_Lclick,sandHomeHandler);

	//zoom controls
	Button zoomIn(&sand,55,375,75,45); zoomIn.text = "Zoom in";
	Button zoomOut(&sand,55,445,75,45); zoomOut.text = "Zoom out";
	zoomIn.tag = zoomOut.tag =  (void*)(&game);
	zoomIn.addHandler(event_Lclick,sandZoomInHandler);
	zoomOut.addHandler(event_Lclick,sandZoomOutHandler);

	//speed controls
	label speedLabel(&sand,200,530,130,30); speedLabel.text = "Speed: Paused";
	HScroll speedScroll(&sand,350,530,200,30,1,10,5);
	Button pause(&sand,600,530,70,30); pause.text = "Pause";
	Button step(&sand,700,530,70,30); step.text = "Step";
	speedLabel.tag = speedScroll.tag = pause.tag = step.tag = (void*)(&game);
	speedScroll.addHandler(event_scroll,sandScrollHandler);
	pause.addHandler(event_Lclick,sandPause);
	step.addHandler(event_Lclick,sandStep);
	
	//colour controls
	radioButton white(&sand,300,35,80,20,NULL);	white.setTextColour(255,255,255);	white.setText("Master");
	radioButton red(&sand,400,35,80,20,&white);	red.setTextColour(255,100,100);		red.setText("Red");
	radioButton green(&sand,500,35,80,20,&red);	green.setTextColour(0,255,100);	green.setText("Green");
	radioButton blue(&sand,600,35,80,20,&green);	blue.setTextColour(100,100,255);	blue.setText("Blue");
	radioButton yellow(&sand,700,35,80,20,&green);	yellow.setTextColour(255,255,0);	yellow.setText("Yellow");

	checkBox bind(&sand,300,70,150,30); bind.setText("Enforce rules");
	bind.tag = (void*)&game;
	bind.addHandler(event_checkchanged,changeRestrict);

	teamRadioStruct params[5];
	radioButton *colours[5] = {&white,&red,&green,&blue,&yellow};
	for(int i = 0; i < 5; i++){
		params[i] = teamRadioStruct(i,&game);
		colours[i]->tag = &params[i];
		colours[i]->addHandler(event_checkchanged,changeTeam);
	}
	
	white.select();
	game.fit();

	//adding a save feature. No open yet...
	Button save(&sand,900,10,80,40); save.text = "Save";

	//exit controls
	Button back(&sand,50,50,100,50); back.text = "Back";
	back.addHandler(event_Lclick,sandBack);

	sand.addHandler(event_quit,sandBack);

	//keep that label and pause button updated
	pause.addHandler(event_frameTick,sandPauseButtonText);
	speedLabel.addHandler(event_frameTick,sandLabelText);

	sand.startFramerate(20,s);
	
	running = true;
	while(running){
		sand.wait();
		SDL_Flip(s);
	}
	cout<<"Ended";
}