コード例 #1
0
void Box2DWorld::componentComplete()
{
    QDeclarativeItem::componentComplete();

    const b2Vec2 gravity(mGravity.x(), mGravity.y());
    bool doSleep = true;

    mWorld = new b2World(gravity, doSleep);
    mWorld->SetContactListener(mContactListener);

    foreach (QGraphicsItem *child, childItems())
        if (Box2DBody *body = dynamic_cast<Box2DBody*>(child))
            registerBody(body);

    mTimerId = startTimer(mFrameTime);
}
コード例 #2
0
ファイル: intro.c プロジェクト: RenatoGeh/hammertime
int run() {
	int page = 0, npage;
	char *input = (char*)malloc(sizeof(char));
	do {
		npage = drawSide(page);
		drawBoard(page);

		Body *line = newLine(35, 1, 60, 'v', '-');
		Stroke *lineStroke = newStroke(1, newBorder("|"));
		line->addStroke(line, lineStroke);
		stroke.setStrokeJoint(lineStroke, '#');
		registerBody("NULL", line);

		draw();
		gets(input);

		handleInput(&page, npage, input);
		
		clearAndRefresh();
		clearBodies();
	} while(!isKeyword(input, "exit"));

	return 0;
}
コード例 #3
0
ファイル: intro.c プロジェクト: RenatoGeh/hammertime
int drawSide(int page) {
	int i, j, n=3;
	char *contents[] = {"Introduction", "Hello Hammertime!", "The Basics"};
	char str[1000][1000];

	registerBody("NULL", newTextBox(10, 1, "  HAMMERTIME  ", -1, '#'));
	registerBody("NULL", newLine(2, 4, 150, 'h', '-'));
	registerBody("NULL", newText(10, 5, "Table of Content", 0));
	registerBody("NULL", newLine(10, 6, 16, 'h', '_'));
	
	for(i=0;i<n;i++) {
		sprintf(str[2*i], "t%d", i);
		sprintf(str[2*i+1], "%d.    %s", i, contents[i]);
		registerBody(str[2*i], newText(8, 10+2*i, str[2*i+1], 0));
	}
	
	registerBody("NULL", newPoint(13, 10+2*page, '*'));
	return n;
}
コード例 #4
0
ファイル: main.c プロジェクト: RenatoGeh/hammertime
int run() {
	char *str = (char*)malloc(100*sizeof(char));
	//Polynomial *poly;

	function.addAxis();
	function.setScale(50, 50);
	//registerBody("Poly", newPolynomial(-1, -1, -1, -1, '*', 2, 1, 0, 0));
	//registerBody("First", newPolynomial(-1, -1, -1, -1, 'o', 1, 1, 0));
	//registerBody("Third", newPolynomial(-1, -1, -1, -1, '+', 3, 1, 8, 10, 0));
	registerBody("Sin", newFunction(-1, -1, -1, -1, '#', invx));
	//registerBody("Cos", newFunction(-1, -1, -1, -1, '!', cosx));
	//registerBody("Tan", newFunction(-1, -1, -1, -1, '$', tanx));
	//registerBody("Abs", newFunction(-1, -1, -1, -1, '&', absolute));
	//registerBody("exp2", newFunction(-1, -1, -1, -1, 'o', exp2));
	//registerBody("ln", newFunction(-1, -1, -1, -1, '+', ln));
	//registerBody("log10", newFunction(-1, -1, -1, -1, '=', logarithm10));
	//registerBody("e^x", newFunction(-1, -1, -1, -1, 'e', eulerx));
	//registerBody("signum", newFunction(-1, -1, -1, -1, 's', signx));
	//registerBody("sqrt", newFunction(-1, -1, -1, -1, '@', sqrt));
	//registerBody("Poly2", newFunction(-1, -1, -1, -1, '~', poly2));
	//registerBody("sin(1/x)", newFunction(-1, -1, -1, -1, 'x', sinix));
	//registerBody("1/x", newFunction(-1, -1, -1, -1, '|', invx));
	//registerBody("arcsin(x)", newFunction(-1, -1, -1, -1, '?', arcsin));
	//registerBody("arccos(x)", newFunction(-1, -1, -1, -1, '?', arccos));
	//registerBody("arctan(x)", newFunction(-1, -1, -1, -1, '?', arctan));
	//registerBody("f(x)", newFunction(-1, -1, -1, -1, 'f', f));
	//registerBody("xsin(x)", newFunction(-1, -1, -1, -1, 'x', xsinx));

	//poly = (Polynomial*)getByName("Poly");
	//poly->toString(str, poly);

	draw();

	//puts("Poly:");
	//puts(str);
	//free(str);

	/*char *t = (char*)malloc(sizeof(char));
	registerBody("t1", newTextBox(50, 15, "STOP", 11, '*'));
	registerBody("t2", newTextBox(22, 10, "THAT'S WHAT SHE SAID", 1, '<'));
	registerBody("t3", newTextBox(30, 20, "Hey, Michael Scott is back!", 0, '='));
	registerBody("t4", newTextBox(40, 28, "feelings", -1, '#'));

	Body *r = newRectangle(20, 40, 20, 5, '*', 'l');
	Stroke *s = newStroke(1, newBorder("renatolordofeverything"));
	r->addStroke(r, s);
	setStrokeJoint(s, 'X');
	registerBody("rect", r);

	Body *tb = newTextBox(55, 40, "VARARGS ARE SO BEAUTIFUL!", 0, '!');
	tb->addStroke(tb, newStroke(1, newBorder("varmyargs")));
	registerBody("tb", tb);

	Body *c = newCircle(60, 10, 5, '*', 'l');
	c->addStroke(c, newStroke(1, newBorder("!@#$^&*()")));
	registerBody("c", c);

	Body *huge = newRectangle(100, 10, 50, 40, '&', 'l');
	Stroke *leStroke = newStroke(4, newBorder(" THEY SEE ME STROKIN' "), 
		newBorder("nurses are not amused "), newBorder(" THEY HATIN' "), 
		newBorder("doctors be mad "));
	setStrokeJoint(leStroke, '$');
	huge->addStroke(huge, leStroke);
	registerBody("huge", huge);

	Body *line = newLine(1, 55, 150, 'h', '-');
	Stroke *lineStroke = newStroke(1, newBorder("-="));
	line->addStroke(line, lineStroke);
	setStrokeJoint(lineStroke, 'O');
	registerBody("line", line);

	draw();
	gets(t);
	killByName(t);*/

	/*Body *t = newTable(0, 0, 5, 5, -25, -12, '!', '=');
	Stroke *s = newStroke(4, newBorder("-"), newBorder("|"), newBorder("-"), newBorder("|"));
	t->addStroke(t, s);
	setStrokeJoint(s, 'O');

	Table *tab = (Table*)t;
	Body *c = newCircle(0, 0, 4, '*', 'l');
	c->addStroke(c, newStroke(1, newBorder("!@#$^&*()-+")));
	tab->add(tab, c, 1, 1, 1);

	Body *rect = newRectangle(0, 0, 15, 8, '@', 'f');
	Stroke *rectStroke = newStroke(4, newBorder("wassup"), newBorder("dawgs"),
		newBorder("chillin'"), newBorder("much?"));
	setStrokeJoint(rectStroke, '+');
	rect->addStroke(rect, rectStroke);
	tab->add(tab, rect, 3, 3, 1);

	Body *tb = newTextBox(1, 2, " Table is so awesome! Said everyone. ", 21, '=');
	Stroke *tbStroke = newStroke(4, newBorder("amazing"), newBorder("genius"),
		newBorder("10/10_reviews_"), newBorder("WOOHO!"));
	tb->addStroke(tb, tbStroke);
	tab->add(tab, tb, 2, 4, 1);

	registerBody("t", t);
	draw();*/
}
コード例 #5
0
ファイル: intro.c プロジェクト: RenatoGeh/hammertime
void drawBoard(int page) {
	switch(page) {
		case 0:
			registerBody("NULL", newHeader(60, 1, "INTRODUCTION", -1));

			registerBody("NULL", newText(65, 9, "STOP!", 0));
			registerBody("NULL", newText(40, 12, "    Welcome to *hammertime*, a text-based \"visual\" framework made and functional with the language C.", max(60, screen.width-40)));
			registerBody("NULL", newText(40, 15, "    The original idea was to create a simple yet useful     framework to use in projects using C, that didn't require   much knowledge in programming.", max(60, screen.width-40)));

			registerBody("NULL", newText(40, 19, "    This little guide will help you with the basics of      *hammertime*. The window on the left indicates the page     you're on. To proceed to the next page, type 'next' (or     'n'). To return to the previous page, type 'prev' (or 'p'). Or if you want you can just type the page's number and pressenter.", max(60, screen.width-40)));
			registerBody("NULL", newText(40, 26, "    Type 'exit' at any time to leave this guide.", 0));

			registerBody("NULL", newText(45, 32, "https://github.com/RenatoGeh/hammertime/wiki", 0));
		break;
		case 1:
			registerBody("NULL", newHeader(60, 1, "USING *HAMMERTIME*", -1));

			registerBody("NULL", newText(40, 10, "    First of all, lets see how to include *hammertime* in   any C source file.", 60));
			registerBody("NULL", newText(40, 13, "    Make sure all files from *hammertime* are in the same   folder as your project.", 60));
			registerBody("NULL", newText(40, 16, "    Just as any other library, you'll need to include       \"hammertime.h\" in the beginning of your C project(#include  \"hammertime.h\").", 60));
			registerBody("NULL", newText(40, 20, "    Instead of a \"int main()\" function, you'll write the    things *hammertime* will print in a \"int run()\" function.", 60));
			registerBody("NULL", newText(40, 23, "    But just as a normal C source file, you can write other functions as well.", 60));
			registerBody("NULL", newText(40, 25, "    Example of a simple *hammertime* project:", 60));
			registerBody("NULL", newTextBox(40, 29, "#include \"hammertime.h\"", 40, '#'));
		break;
		case 2:
			registerBody("NULL", newHeader(60, 1, "BODIES AND BASIC DRAWING", -1));

			registerBody("NULL", newText(40, 10, "    In *hammertime*, the basic thing you'll need to learn is how to create (or register) \"bodies\" and make them visible.", 60));
			registerBody("NULL", newText(40, 13, "    A body is some sort of object, and it may vary from a simple text to a circle made of \"$\".", 60));
			registerBody("NULL", newText(40, 16, "    To create a simple body you follow this model:", 60));
			registerBody("NULL", newText(40, 19, "       registerBody(name, newThing(thing parameters));", 60));
		break;
	}
}
コード例 #6
0
ファイル: tutorial.c プロジェクト: RenatoGeh/hammertime
void basics() {
	/*************** HAMMERTIME BASICS ***************/

	/* Creating a Text Body:
	 * newText accepts four arguments:
	 *
	 *		1. The x-axis coordinate.
	 *		2. The y-axis coordinate.
	 *		3. A String with the text.
	 *		4. Wrap mode:
	 *			= -1 never wraps.
	 *			= 0 wraps on end of screen.
	 *			= n>0 wraps after n characters.
	 *
	 *	Hammertime works the same way as most frameworks,
	 *	the origin (0,0) is set to be the top-left corner 
	 * of the screen.
	 * 
	 * Note: '\n' does not work very well with Hammertime's Text. 	
	*/
	Body *caption = newText(5, 2, "Hello Hammertime!", 0);

	/* Registering a Body:
	 * registerBody accepts two arguments:
	 *		
	 *		1. A name for the Body.
	 *		2. The pointer to the Body.
	 *
	 *	Names will be used to 'kill' or 'get' Bodies.
	*/
	registerBody("hello", caption);

	/* Drawing a Rectangle:
	 * newRectangle accepts six arguments:
	 *
	 *		1. The x-axis coordinate.
	 *		2. The y-axis coordinate.
	 *		3. The rectangle's width.
	 *		4. The rectangle's height.
	 *		5. The rectangle's drawing character.
	 *		6. Draw mode:
	 *			= 'l' line mode -> draws the shape's contour.
	 *			= 'f' fill mode -> fills the shape completely.
	 *
	 *	The drawing character will be used to draw the shape.
	 * This character will be used both in line and fill mode,
	 * and will also work as a 'default paint' when we see
	 * Strokes.
	 * All Bodies are positioned at (x,y) where x and y are 
	 * the top left corner of the object.
	*/
	Body *rect = newRectangle(5, 5, 8, 4, '~', 'f');
	registerBody("rect", rect);

	/* Text + Rectangle = TextBox:
	 *	newTextBox accepts five arguments: 
	 *
	 *		1. The x-axis coordinate.
	 *		2. The y-axis coordinate.
	 *		3. A String with the desired text.
	 *		4. Wrap mode.
	 *		5. The rectangle's drawing character.
	 *	
	 *	TextBox automatically calculates the width and height
	 *	necessary for drawing the rectangle according to the
	 * given text.
	 * Text will be 'glued in' into the Rectangle, meaning there
	 * will be no spacing between the outline and the text.
	 * We will later see how we can override that with the use
	 * of Tables.
	*/
	Body *tb = newTextBox(5, 12, "Help! I'm trapped!", 9, '#');
	registerBody("tb", tb);

	/* Goin' round (Circle):
	 * newCircle accepts five arguments:
	 *
	 *		1. The x-axis coordinate.
	 *		2. The y-axis coordinate.
	 *		3. The circle's radius.
	 *		4. The drawing character.
	 *		5. Draw mode.
	 *		
	 * In Hammertime Circles are actually "pseudo-circles" due to
	 * the console's font dimensions. If the font's width is different
	 * than its height, we will get an ellipse opposed to a circle.
	 * This could be fixed by getting the console's current font, but
	 * due to portability issues and OS dependent requirements, we have
	 * left it this way for now.
	*/
	Body *circle = newCircle(30, 2, 5, 'O', 'l');
	registerBody("circle", circle);

	/* Point:
	 * newPoint accepts three arguments:
	 *
	 *		1. The x-axis coordinate.
	 *		2. The y-axis coordinate.
	 *		3. The drawing character.
	 *
	 *	Points are the most basic shapes in Hammertime. They
	 * are consisted of only one character.
	 * In this tutorial we've drawn the point in the center of
	 * the previous Body, a circle.
	*/
	Body *point = newPoint(35, 7, '*');
	registerBody("point", point);

	/* Lines:
	 * newLine accepts five arguments:
	 *
	 *		1. The x-axis coordinate.
	 *		2. The y-axis coordinate.
	 *		3. The size of the line.
	 *		4. Its direction:
	 *			- 'h'=horizontal
	 *			- 'v'=vertical
	 *		5. The drawing character.
	 *
	 *	For now, lines are only vertical or horizontal. We are
	 *	planning on creating a Function Body, in which the user
	 * inputs the mathematical function and Hammertime draws it.
	 * This will then be the most efficient (and easiest) way to
	 * create horizontal or vertical line. 
	*/
	Body *line = newLine(5, 20, 40, 'h', '_');
	registerBody("line", line);

	/* Drawing:
	 * draw accepts no arguments.
	 * 
	 * For Hammertime to know that you're done and that you
	 * want to actually draw what you've registered, you must
	 * call 'draw'.
	 * Drawing will cause all the registered Bodies to be drawn
	 * in the order that they were added, meaning that objects that
	 * intersect one another will have their intersection overriden
	 * by the last registered Body's drawing character.
	*/
	draw();
}