Ejemplo n.º 1
0
	void WidgetSkin::setUnselectedImage(MAHandle image) {
		this->unselectedImage = image;
		if(!unselectedImage) return;
		MAExtent imgSize = maGetImageSize(image);

		unselectedImageWidth = EXTENT_X(imgSize);
		unselectedImageHeight = EXTENT_Y(imgSize);

		if(selectedImage) {
			if(unselectedImageHeight!=selectedImageHeight ||
				unselectedImageWidth!=selectedImageWidth) {
				unselectedImageWidth = 0;
				unselectedImageHeight = 0;
				unselectedImage = 0;
				maPanic(0, "Not the same dimension on WidgetSkin unselectedImage as selectedImage");
			}
		} else {
			imageWidth = unselectedImageWidth;
			imageHeight = unselectedImageHeight;
		}

		rebuildRects();
	}
Ejemplo n.º 2
0
GLMoblet::GLMoblet(int apiVersions) :
	mPreferredMillisecondsPerFrame(-1),
	mFramesSinceStartDrawing(0),
	mMillisOfStartDrawing(0),
	mIsDrawing(false)
{
	bool glInitialized = false;

	if(apiVersions & GL2) {
		if(maOpenGLInitFullscreen(MA_GL_API_GL2) < 0) {

		} else {
			mApiVersion = GL2;
			glInitialized = true;
		}
	}

	if(!glInitialized) {
		if(!glInitialized && (apiVersions & GL1)) {
			if(maOpenGLInitFullscreen(MA_GL_API_GL1) < 0) {
			} else {
				mApiVersion = GL1;
				glInitialized = true;
			}
		}

	}

	if(!glInitialized) {
		maPanic(1, "Failed to initialize OpenGL|ES. OpenGL|ES is only available on Android and iOS. Also, please check that the device is able to run the version of OpenGL|ES you requested.");
	}

	mListener = new GLMobletListener(this);

	Environment::getEnvironment ().addCustomEventListener(mListener);

}
Ejemplo n.º 3
0
MainScreen::MainScreen() {
	mDrawing = false;

	setProperty("title", "Graphun");

	Widget* layout = new Widget("VerticalLayout");
	layout->setProperty("width", -1);
	layout->setProperty("height", -1);
	setMainWidget(layout);

	layout->setProperty("backgroundColor", "000000");
	layout->setProperty("childHorizontalAlignment", "center");

	Widget* horizontalLayout = new Widget("HorizontalLayout");
	horizontalLayout->setProperty("childVerticalAlignment", "center");
	horizontalLayout->setProperty("width", "-1");
	horizontalLayout->setProperty("height", -2); // should be -2?

	Widget* label = new Widget("Label");
	label->setProperty("text", " z =");
	label->setProperty("fontColor", "ffffff");
	label->setProperty("fontSize", 16);
	label->setProperty("width", -2);
	label->setProperty("height", -2);
	label->setProperty("backgroundColor", "000000");
	horizontalLayout->addChild(label);

	mExpression = "sin(x*10.0*y+time)*0.5";
	mEditBox = new Widget("EditBox");
	mEditBox->setProperty("width", -1);
	mEditBox->setProperty("height", -2);
	mEditBox->setProperty("placeholder", "Expression (x,y,sin,cos,sqrt,time)");
	mEditBox->setProperty("text", mExpression.c_str());
	mEditBox->setProperty("autocorrectionEnabled", "false");
	horizontalLayout->addChild(mEditBox);

	layout->addChild(horizontalLayout);

	mGLView = new Widget("GLView");
	if(Widget::getLastError() < 0)
	{
		maPanic(1, "OpenGL|ES unavailable!");
	}

	layout->addChild(mGLView);

	mGLView->setProperty("width", -1);
	mGLView->setProperty("height", -1);

	Widget* toolBar = new Widget("HorizontalLayout");
	toolBar->setProperty("childVerticalAlignment", "center");
	toolBar->setProperty("width", "-1");
	toolBar->setProperty("height", EXTENT_Y(maGetScrSize()) / 10);
	layout->addChild(toolBar);

	toolBar->setProperty("leftMargin", "8");
	toolBar->setProperty("rightMargin", "8");
	toolBar->setProperty("topMargin", "8");
	toolBar->setProperty("bottomMargin", "8");

	mSettingsButton = new Widget("ImageButton");
	mSettingsButton->setProperty("image", R_SETTINGS_ICON);
	mSettingsButton->setProperty("width", "-2");
	mSettingsButton->setProperty("height", "-2");
	toolBar->addChild(mSettingsButton);

	grid = new Grid(0, 0, 0, 0);
}
Ejemplo n.º 4
0
void XML::WriteNode(Data data)
{

	MAUtil::String coords_tag = "<Point>\n";

	maFileWrite(file, coords_tag.c_str(), coords_tag.size());

	coords_tag = "	<Coords>\n";

	maFileWrite(file, coords_tag.c_str(), coords_tag.size());

	//Write the Lan and Lon values.
	coords_tag = "		<Lat>";
	maFileWrite(file, coords_tag.c_str(), coords_tag.size());

	MAUtil::String data2;
	data2 = MAUtil::doubleToString(data.loc.lat);

	maFileWrite(file, data2.c_str(), data2.size());

	coords_tag = "</Lat>\n";
	maFileWrite(file, coords_tag.c_str(), coords_tag.size());


	coords_tag = "		<Lon>";
	maFileWrite(file, coords_tag.c_str(), coords_tag.size());

	data2 = MAUtil::doubleToString(data.loc.lon);

	maFileWrite(file, data2.c_str(), data2.size());

	coords_tag = "</Lon>\n";
	maFileWrite(file, coords_tag.c_str(), coords_tag.size());
	//
	coords_tag = "	</Coords>\n";

	maFileWrite(file, coords_tag.c_str(), coords_tag.size());


	if(data.imagePath.size() > 0)
	{
		_ActivityIndicator->show();

		byte *tdata;
		int dataLen;
		MAUtil::String img_tag = "	<Image>";


		lprintfln("Image file: %s", data.imagePath.c_str());

		maFileWrite(file, img_tag.c_str(), img_tag.size());
		//maFileWrite(file, data.imagePath.c_str(), data.imagePath.size());
		//Write the data to the xml

		if(!writeDataToXML(data.imagePath))
		{
			maPanic(0, "Couldn't locate the image file.");
		}

		//maFileWrite(file, tdata, dataLen);
		//End of data writting.

		img_tag = "</Image>\n";

		maFileWrite(file, img_tag.c_str(), img_tag.size());

		_ActivityIndicator->hide();
	}


	if(data.videoPath.size() > 0)
	{
		_ActivityIndicator->show();

		byte *tdata;
		int dataLen;
		MAUtil::String vid_tag = "	<Video>";

		maFileWrite(file, vid_tag.c_str(), vid_tag.size());
		//maFileWrite(file, data.videoPath.c_str(), data.videoPath.size());
		//Write the data to the xml

		lprintfln("Image file: %s", data.videoPath.c_str());

		if(!writeDataToXML(data.videoPath))
		{
			maPanic(0, "Couldn't locate the video file.");
		}

		//maFileWrite(file, tdata, dataLen);
		//End of data writting.

		vid_tag = "</Video>\n";

		maFileWrite(file, vid_tag.c_str(), vid_tag.size());

		_ActivityIndicator->hide();
	}

	if(data.text.size() > 0)
	{
		MAUtil::String text_tag = "	<Text>";

		maFileWrite(file, text_tag.c_str(), text_tag.size());
		maFileWrite(file, data.text.c_str(), data.text.size());

		text_tag = "</Text>\n";

		maFileWrite(file, text_tag.c_str(), text_tag.size());
	}


	//Write the date time.
	coords_tag = "	<DateTime>";

	maFileWrite(file, coords_tag.c_str(), coords_tag.size());

	coords_tag = dateToString(data.time);

	maFileWrite(file, coords_tag.c_str(), coords_tag.size());

	coords_tag = "</DateTime>\n";

	maFileWrite(file, coords_tag.c_str(), coords_tag.size());

	//End of date time.

	coords_tag = "</Point>";
	maFileWrite(file, coords_tag.c_str(), coords_tag.size());
}
Ejemplo n.º 5
0
void bfeHandler(int value, const char* filename, int line) {
	char buf[1024];
	sprintf(buf, "BFE %s:%i", FileNameFromPath(filename), line);
	maPanic(value, buf);
}
Ejemplo n.º 6
0
/**
 * TODO: This comment seems outdated. Returns a boolean rather than a
 * byte buffer. UPDATE COMMENT.
 * @return The newly created Data Section as a Direct ByteBuffer object
 */
static jboolean nativeLoad(
	JNIEnv* env,
	jobject jthis,
	jobject program,
	jlong programOffset,
	jobject resource,
	jlong resourceOffset)
{
	SYSLOG("load program and resource");

	// Program file descriptor.
	int prgFd;

	// Due to logic -1 is never passed to LoadVMApp, use -2 when
	// no resource file is needed.
	// Details:
	//  -1: resource file needed but not found
	//  -2: resource file is not needed
	int resFd = -2;

	// Check that global variable gCore has a value.
	if (NULL == gCore)
	{
		maPanic(-1, "MoSyncBridge.cpp: nativeLoad: NULL == gCore");
	}
	else
	{
		SYSLOG("gCore exists");
	}

	// Get program file descriptor.
	SYSLOG("MoSyncBridge.cpp: nativeLoad: Get program file descriptor");

	jclass fdClass = env->FindClass("java/io/FileDescriptor");
	if (fdClass != NULL)
	{
		jclass fdPrgClassRef = (jclass) env->NewGlobalRef(fdClass);
		jfieldID fdClassDescriptorFieldID =
			env->GetFieldID(fdPrgClassRef, "descriptor", "I");

		if (fdClassDescriptorFieldID != NULL && program != NULL)
		{
			jint fd = env->GetIntField(program, fdClassDescriptorFieldID);
			prgFd = dup(fd);
			lseek(prgFd, programOffset, SEEK_SET);
		}
	}

	// Check that program file exists.
	if (-1 == prgFd)
	{
		maPanic(-1, "MoSyncBridge.cpp: nativeLoad: No program file available!");
	}
	else
	{
		SYSLOG("MoSyncBridge.cpp: nativeLoad: Program file exists!");
	}

	// Get resorce file descriptor.

	if (resourceOffset != 0)
	{
		SYSLOG("MoSyncBridge.cpp: nativeLoad: Get resource file descriptor");
		jclass fdClass2 = env->FindClass("java/io/FileDescriptor");
		if (fdClass2 != NULL)
		{
			jclass fdResClassRef = (jclass) env->NewGlobalRef(fdClass2);
			jfieldID fdClassDescriptorFieldID =
				env->GetFieldID(fdResClassRef, "descriptor", "I");

			if (fdClassDescriptorFieldID != NULL && resource != NULL)
			{
				jint fd = env->GetIntField(
					resource,
					fdClassDescriptorFieldID);
				resFd = dup(fd);
				lseek(resFd, resourceOffset, SEEK_SET);
			}
			else if (resource == NULL)
			{
				resFd = -2;
			}
		}
	}

	SYSLOG("MoSyncBridge.cpp: nativeLoad: Setting jni environment");

	gCore->mJniEnv = env;
	gCore->mJThis = jthis;
	Base::gSyscall->setJNIEnvironment(env, jthis);

	SYSLOG("MoSyncBridge.cpp: nativeLoad: Calling Core::LoadVMApp");

	return Core::LoadVMApp(gCore, prgFd, resFd);
}
Ejemplo n.º 7
0
/**
* @brief nativePostEvent
*/
static void nativePostEvent(JNIEnv* env, jobject jthis, jintArray eventBuffer)
{
	// Get array data.
	jsize arrayLength = env->GetArrayLength(eventBuffer);
	jint *intArray = env->GetIntArrayElements(eventBuffer, 0);

	// Must have at least one element.
	if (arrayLength < 1)
	{
		maPanic(-1, "MoSyncBridge.cpp: nativePostEvent: array length is zero");
		return;
	}

	// Build the event.
	MAEvent event;
	event.type = intArray[0];
	event.data = NULL;

	// Print log message.
	char logBuf[256];
	sprintf(logBuf, "nativePostEvent event.type: %i", event.type);
	SYSLOG(logBuf);

	if (event.type == EVENT_TYPE_POINTER_PRESSED ||
		event.type == EVENT_TYPE_POINTER_RELEASED ||
		event.type == EVENT_TYPE_POINTER_DRAGGED)
	{
		event.point.x = intArray[1];
		event.point.y = intArray[2];
		event.touchId = intArray[3];
	}
	else if (
		event.type == EVENT_TYPE_KEY_RELEASED ||
		event.type == EVENT_TYPE_KEY_PRESSED)
	{
		event.key = intArray[1];
		event.nativeKey = intArray[2];
	}
	else if (event.type == EVENT_TYPE_CONN)
	{
		event.conn.handle = intArray[1];
		event.conn.opType = intArray[2];
		event.conn.result = intArray[3];
	}
	else if (event.type == EVENT_TYPE_LOCATION)
	{
		// Copy location data. This data starts at array index 1.
		int size = sizeof(MALocation);
		byte* data = new byte[size];
		memcpy(data, intArray + 1, size);
		event.data = (int)data;
	}
	else if (event.type == EVENT_TYPE_LOCATION_PROVIDER)
	{
		event.state = intArray[1];
	}
	else if (event.type == EVENT_TYPE_BT)
	{
		event.state = intArray[1];
	}
	else if (event.type == EVENT_TYPE_TEXTBOX)
	{
		event.textboxResult = intArray[1];
		event.textboxLength = intArray[2];
	}
	else if (event.type == EVENT_TYPE_IMAGE_PICKER)
	{
		event.imagePickerState = intArray[1];
		event.imagePickerItem = intArray[2];
	}
	else if (event.type == EVENT_TYPE_SMS)
	{
		event.status = intArray[1];
	}
	else if (event.type == EVENT_TYPE_WIDGET)
	{
		/*
		 * Structure of intArray for widget events.
		 *
		 * Required:
		 * intArray[0] - EVENT_TYPE_WIDGET
		 * intArray[1] - Specifies exactly which widget event that occurred.
		 * intArray[2] - Handle to the widget that sent the event.
		 *
		 * Optional:
		 * WIDGET_EVENT_MESSAGE
		 * intArray[3] - The id of the message being sent (if it has 
		 *               dynamically allocated data)
		 * intARray[4] - Size of the message.
		 *
		 * MAW_EVENT_CLICKED
		 * intArray[3] - Can be used to determine a checkbox or toggle button that was clicked.
		 *
		 * MAW_EVENT_ITEM_CLICKED
		 * intArray[3] - The index of the list item that was clicked.
		 *
		 * MAW_EVENT_TAB_CHANGED
		 * intArray[3] - The index of the new tab.
		 *
		 * MAW_EVENT_STACK_SCREEN_POPPED
		 * intArray[3] - Handle to the screen that was popped.
		 * intArray[4] - Handle to the screen that we popped to.
		 *
		 * MAW_EVENT_WEB_VIEW_CONTENT_LOADING
		 * intArray[3] - Page loading status.
		 *
		 * MAW_EVENT_WEB_VIEW_HOOK_INVOKED
		 * intArray[3] - Hook type.
		 * intArray[4] - Handle to url data.
		 *
		 * WIDGET_EVENT_SLIDER_VALUE_CHANGED
		 * intArray[3] - The slider value.
		 *
		 * WIDGET_EVENT_DATE_PICKER_VALUE_CHANGED
		 * intArray[3] - The day of month value.
		 * intArray[4] - The month value.
		 * intArray[5] - The year value.
		 *
		 * WIDGET_EVENT_TIME_PICKER_VALUE_CHANGED
		 * intArray[3] - The current hour value.
		 * intArray[4] - The current minute value.
		 *
		 * WIDGET_EVENT_NUMBER_PICKER_VALUE_CHANGED
		 * intArray[3] - The current value.
		 *
		 * WIDGET_EVENT_VIDEO_STATE_CHANGED
		 * intArray[3] - One of the MAW_VIDEO_WIDGET_STATE constants.
		 *
		 * MAW_EVENT_WEB_VIEW_CONTENT_LOADING
		 * intArray[3] - Page loading status.
		 *
		 * MAW_EVENT_WEB_VIEW_HOOK_INVOKED
		 * intArray[3] - Hook type.
		 * intArray[4] - Handle to url data.
		 */

		// Allocate the widget event data structure.
		// maGetEvent will handle the deallocation of this memory
		MAWidgetEventData *widgetEvent = new MAWidgetEventData();

		// Temporary variable for readability (?).
		int widgetEventType = intArray[1];

		widgetEvent->eventType = widgetEventType;
		widgetEvent->widgetHandle = intArray[2];

		if (widgetEventType == MAW_EVENT_CLICKED)
		{
			widgetEvent->checked = intArray[3];
		}
		else if (widgetEventType == MAW_EVENT_ITEM_CLICKED)
		{
			widgetEvent->listItemIndex = intArray[3];
		}
		else if (widgetEventType == MAW_EVENT_TAB_CHANGED)
		{
			widgetEvent->tabIndex = intArray[3];
		}
		else if (widgetEventType == MAW_EVENT_STACK_SCREEN_POPPED)
		{
			widgetEvent->fromScreen = intArray[3];
			widgetEvent->toScreen = intArray[4];
		}
		else if(widgetEventType == MAW_EVENT_SLIDER_VALUE_CHANGED)
		{
			widgetEvent->sliderValue = intArray[3];
		}
		else if(widgetEventType == MAW_EVENT_DATE_PICKER_VALUE_CHANGED)
		{
			widgetEvent->dayOfMonth = intArray[3];
			widgetEvent->month = intArray[4];
			widgetEvent->year = intArray[5];
		}
		else if(widgetEventType == MAW_EVENT_TIME_PICKER_VALUE_CHANGED)
		{
			widgetEvent->hour = intArray[3];
			widgetEvent->minute = intArray[4];
		}
		else if(widgetEventType == MAW_EVENT_NUMBER_PICKER_VALUE_CHANGED)
		{
			widgetEvent->numberPickerValue = intArray[3];
		}
		else if(widgetEventType == MAW_EVENT_VIDEO_STATE_CHANGED)
		{
			widgetEvent->videoViewState = intArray[3];
		}
		else if (widgetEventType == MAW_EVENT_WEB_VIEW_CONTENT_LOADING)
		{
			widgetEvent->status = intArray[3];
		}
		else if (widgetEventType == MAW_EVENT_WEB_VIEW_HOOK_INVOKED)
		{
			widgetEvent->hookType = intArray[3];
			widgetEvent->urlData = intArray[4];
		}

		event.data = (int)widgetEvent;
	}
	else if (event.type == EVENT_TYPE_SENSOR)
	{
		event.sensor.type = intArray[1];
		memcpy( event.sensor.values, intArray + 2, (arrayLength - 2) * sizeof(jint) );
	}

	// Release the memory used for the int array.
	env->ReleaseIntArrayElements(eventBuffer, intArray, 0);

	Base::gSyscall->postEvent(event);
}
Ejemplo n.º 8
0
	int parseBitmapFontGeneratorFile(MAHandle file, int end, Charset *charset) {
		char ident[4];
		// read magic
		//maReadData(file, ident, filePtr, 4); 
		readChars(ident, 4);
		int version = ident[3];
		if(ident[0] != 'B' || ident[1] != 'M' || ident[2] != 'F' || version < 2 || version > 3) {
			//PANIC_MESSAGE("Wrong .fnt format!");
			//printf("Wrong .fnt format!\n");
			return 0;
		}

		for(int i = 0; i < 255; i++) {
			charset->chars[i].x	= 0xffff;
		}

		while(sFilePos != end) {
			// read block type and block size
			unsigned char id = readByte();
			unsigned int blockSize = readInt();
			unsigned int skipValue = blockSize;
			if(version == 2) skipValue -= 4;
			switch(id) {
				case 1:
					{
						int initialFilePos = sFilePos;
						skipBytes(14);

						int i = readChars(charset->name, CHARSET_MAX_NAME_LEN);
						charset->name[i-1] = 0;
						skipBytes((skipValue+initialFilePos)-sFilePos);
					}
					break;
				case 2:
					// type common
					//#pragma pack(1)
					//struct commonBlock
					//{
					//    int  blockSize;
					//    WORD lineHeight;
					//    WORD base;
					//    WORD scaleW;
					//    WORD scaleH;
					//    WORD pages;
					//    BYTE packed  :1;
					//    BYTE encoded :1;      // Added with version 2
					//    BYTE reserved:6;
					//}; 
					//int blockSize = readInt(file, &filePtr);
					{
						//int filePtrBefore = filePtr;
						//printf("Reading common block!\n");
						charset->lineHeight		= readShort();
						charset->base			= readShort();
						charset->width			= readShort();
						charset->height			= readShort();
						charset->pages			= readShort();
						if(version==2)
							skipBytes(1);
						else
							skipBytes(5);

						//int currentBlockSize = (filePtr-filePtrBefore)+4;	
						//printf("blockSize: %d, currentBlockSize: %d\n", blockSize, currentBlockSize);
					}
					break;
				case 4:
					// type char
					//struct charsBlock
					//{
					//    int blockSize;
					//    struct charInfo
					//    {
					//        WORD  id;
					//        WORD  x;
					//        WORD  y;
					//        WORD  width;
					//        WORD  height;
					//        short xoffset;
					//        short yoffset;
					//        short xadvance;
					//        BYTE  page;
					//        BYTE  chnl;
					//    } chars[1];
					//};
					//int blockSize = readInt(file, &filePtr);
					{
						//int filePtrBefore = filePtr;
						int numBytesPerChar = 18;
						if(version == 3) numBytesPerChar = 20;

						int numTimes = skipValue/numBytesPerChar;
						while(numTimes--) {
							//printf("Reading char block! filePtr: %d\n", filePtr);
							
							unsigned int c;
							if(version == 2)
								c = readShort();
							else
								c = readInt();

							if(c>256) {
								maPanic(1, "Font contains unicode characters! Only ascii is supported.");
							}
							//printf("Reading char %c!\n", (char)c);
							charset->chars[c].x			= readShort();
							charset->chars[c].y			= readShort();
							charset->chars[c].width		= readShort();
							charset->chars[c].height		= readShort();
							charset->chars[c].xOffset	= readShort();
							charset->chars[c].yOffset	= readShort();
							charset->chars[c].xAdvance	= readShort();
							charset->chars[c].page		= readByte();
							skipBytes(1);
						}

						//int currentBlockSize = (filePtr-filePtrBefore)+4;
						//printf("blockSize: %d, currentBlockSize: %d\n", blockSize, currentBlockSize);		
					}
					break;
				default:
					//printf("not reading this id\n");;
					skipBytes(skipValue);
					break;

			}
		}

		for(int i = 0; i < 255; i++) {
			if(charset->chars[i].x == 0xffff) {
				charset->chars[i] = charset->chars[(byte)' '];
			}
		}

		return 1;
	}
Ejemplo n.º 9
0
/**
* @brief nativePostEvent
* Don't forget to update the file EventQueue.cpp when adding
* event types that would potentially overflow the event queue.
*/
static void nativePostEvent(JNIEnv* env, jobject jthis, jintArray eventBuffer)
{
	// Get array data.
	jsize arrayLength = env->GetArrayLength(eventBuffer);
	jint *intArray = env->GetIntArrayElements(eventBuffer, 0);

	// Must have at least one element.
	if (arrayLength < 1)
	{
		maPanic(-1, "MoSyncBridge.cpp: nativePostEvent: array length is zero");
		return;
	}

	// Build the event.
	MAEvent event;
	event.type = intArray[0];
	event.data = (MAAddress)NULL;

	// Print log message.
	char logBuf[256];
	sprintf(logBuf, "nativePostEvent event.type: %i", event.type);
	SYSLOG(logBuf);

	if (event.type == EVENT_TYPE_POINTER_PRESSED ||
		event.type == EVENT_TYPE_POINTER_RELEASED ||
		event.type == EVENT_TYPE_POINTER_DRAGGED)
	{
		event.point.x = intArray[1];
		event.point.y = intArray[2];
		event.touchId = intArray[3];
	}
	else if (
		event.type == EVENT_TYPE_KEY_RELEASED ||
		event.type == EVENT_TYPE_KEY_PRESSED)
	{
		event.key = intArray[1];
		event.nativeKey = intArray[2];
	}
	else if (event.type == EVENT_TYPE_CONN)
	{
		event.conn.handle = intArray[1];
		event.conn.opType = intArray[2];
		event.conn.result = intArray[3];
	}
	else if (event.type == EVENT_TYPE_LOCATION)
	{
		// Copy location data. This data starts at array index 1.
		int size = sizeof(MALocation);
		byte* data = new byte[size];
		memcpy(data, intArray + 1, size);
		event.data = (int)data;
	}
	else if (event.type == EVENT_TYPE_LOCATION_PROVIDER)
	{
		event.state = intArray[1];
	}
	else if (event.type == EVENT_TYPE_BT)
	{
		event.state = intArray[1];
	}
	else if (event.type == EVENT_TYPE_TEXTBOX)
	{
		event.textboxResult = intArray[1];
		event.textboxLength = intArray[2];
	}
	else if (event.type == EVENT_TYPE_IMAGE_PICKER)
	{
		event.imagePickerState = intArray[1];
		event.imagePickerItem = intArray[2];
		event.imagePickerEncodingType = intArray[3];
	}
	else if (event.type == EVENT_TYPE_SMS)
	{
		event.status = intArray[1];
	}
	else if (event.type == EVENT_TYPE_ALERT)
	{
		event.alertButtonIndex = intArray[1];
	}
	else if (event.type == EVENT_TYPE_OPTIONS_BOX_BUTTON_CLICKED)
	{
		event.optionsBoxButtonIndex = intArray[1];
	}
	else if (event.type == EVENT_TYPE_ADS_BANNER)
	{
		event.adsData.bannerEventType = intArray[1];
		event.adsData.bannerHandle = intArray[2];
		event.adsData.bannerErrorCode = intArray[3];
	}
	else if (event.type == EVENT_TYPE_LOCAL_NOTIFICATION)
	{
		event.localNotificationHandle = intArray[1];
	}
	else if (event.type == EVENT_TYPE_PUSH_NOTIFICATION_REGISTRATION)
	{
		// Just signals that we have a result to the request,
		// and the result can be taken with maNotificationPushGetRegistration.
	}
	else if (event.type == EVENT_TYPE_PUSH_NOTIFICATION_UNREGISTRATION)
	{
		// Just signals that we've unregistered. No data needed.
	}
	else if (event.type == EVENT_TYPE_PUSH_NOTIFICATION)
	{
		event.pushNotificationHandle = intArray[1];
	}
	else if (event.type == EVENT_TYPE_CAPTURE)
	{
		event.captureData.type = intArray[1];
		event.captureData.handle = intArray[2];
	}
	else if (event.type == EVENT_TYPE_PURCHASE)
	{
		event.purchaseData.type = intArray[1];
		event.purchaseData.state = intArray[2];
		event.purchaseData.productHandle = intArray[3];
		event.purchaseData.errorCode = intArray[4];
	}
	else if (event.type == EVENT_TYPE_WIDGET)
	{
		/*
		 * Structure of intArray for widget events.
		 *
		 * Required:
		 * intArray[0] - EVENT_TYPE_WIDGET
		 * intArray[1] - Specifies exactly which widget event that occurred.
		 * intArray[2] - Handle to the widget that sent the event.
		 *
		 * Optional:
		 * WIDGET_EVENT_MESSAGE
		 * intArray[3] - The id of the message being sent (if it has
		 *               dynamically allocated data)
		 * intARray[4] - Size of the message.
		 *
		 * MAW_EVENT_CLICKED
		 * intArray[3] - Can be used to determine a checkbox or toggle button that was clicked.
		 *
		 * MAW_EVENT_ITEM_CLICKED
		 * intArray[3] - The index of the list item that was clicked.
		 *
		 * MAW_EVENT_TAB_CHANGED
		 * intArray[3] - The index of the new tab.
		 *
		 * MAW_EVENT_STACK_SCREEN_POPPED
		 * intArray[3] - Handle to the screen that was popped.
		 * intArray[4] - Handle to the screen that we popped to.
		 *
		 * MAW_EVENT_WEB_VIEW_CONTENT_LOADING
		 * intArray[3] - Page loading status.
		 *
		 * MAW_EVENT_WEB_VIEW_HOOK_INVOKED
		 * intArray[3] - Hook type.
		 * intArray[4] - Handle to url data.
		 *
		 * WIDGET_EVENT_SLIDER_VALUE_CHANGED
		 * intArray[3] - The slider value.
		 *
		 * WIDGET_EVENT_DATE_PICKER_VALUE_CHANGED
		 * intArray[3] - The day of month value.
		 * intArray[4] - The month value.
		 * intArray[5] - The year value.
		 *
		 * WIDGET_EVENT_TIME_PICKER_VALUE_CHANGED
		 * intArray[3] - The current hour value.
		 * intArray[4] - The current minute value.
		 *
		 * WIDGET_EVENT_NUMBER_PICKER_VALUE_CHANGED
		 * intArray[3] - The current value.
		 *
		 * WIDGET_EVENT_VIDEO_STATE_CHANGED
		 * intArray[3] - One of the MAW_VIDEO_WIDGET_STATE constants.
		 *
		 * MAW_EVENT_WEB_VIEW_CONTENT_LOADING
		 * intArray[3] - Page loading status.
		 *
		 * MAW_EVENT_WEB_VIEW_HOOK_INVOKED
		 * intArray[3] - Hook type.
		 * intArray[4] - Handle to url data.
		 *
		 * WIDGET_EVENT_RATING_STAR_VALUE_CHANGED
		 */

		// Allocate the widget event data structure.
		// maGetEvent will handle the deallocation of this memory
		MAWidgetEventData *widgetEvent = new MAWidgetEventData();

		// Temporary variable for readability (?).
		int widgetEventType = intArray[1];

		widgetEvent->eventType = widgetEventType;
		widgetEvent->widgetHandle = intArray[2];

		if (widgetEventType == MAW_EVENT_CLICKED)
		{
			widgetEvent->checked = intArray[3];
		}
		else if (widgetEventType == MAW_EVENT_ITEM_CLICKED)
		{
			widgetEvent->listItemIndex = intArray[3];
		}
		else if (widgetEventType == MAW_EVENT_SEGMENTED_LIST_ITEM_CLICKED)
		{
			widgetEvent->sectionIndex = intArray[3];
			widgetEvent->sectionItemIndex = intArray[4];
		}
		else if (widgetEventType == MAW_EVENT_TAB_CHANGED)
		{
			widgetEvent->tabIndex = intArray[3];
		}
		else if (widgetEventType == MAW_EVENT_STACK_SCREEN_POPPED)
		{
			widgetEvent->fromScreen = intArray[3];
			widgetEvent->toScreen = intArray[4];
		}
		else if(widgetEventType == MAW_EVENT_SLIDER_VALUE_CHANGED)
		{
			widgetEvent->sliderValue = intArray[3];
		}
		else if(widgetEventType == MAW_EVENT_DATE_PICKER_VALUE_CHANGED)
		{
			widgetEvent->dayOfMonth = intArray[3];
			widgetEvent->month = intArray[4];
			widgetEvent->year = intArray[5];
		}
		else if(widgetEventType == MAW_EVENT_TIME_PICKER_VALUE_CHANGED)
		{
			widgetEvent->hour = intArray[3];
			widgetEvent->minute = intArray[4];
		}
		else if(widgetEventType == MAW_EVENT_NUMBER_PICKER_VALUE_CHANGED)
		{
			widgetEvent->numberPickerValue = intArray[3];
		}
		else if(widgetEventType == MAW_EVENT_VIDEO_STATE_CHANGED)
		{
			widgetEvent->videoViewState = intArray[3];
		}
		else if (widgetEventType == MAW_EVENT_WEB_VIEW_CONTENT_LOADING)
		{
			widgetEvent->status = intArray[3];
		}
		else if (widgetEventType == MAW_EVENT_WEB_VIEW_HOOK_INVOKED)
		{
			widgetEvent->hookType = intArray[3];
			widgetEvent->urlData = intArray[4];
		}
		else if (widgetEventType == MAW_EVENT_RATING_BAR_VALUE_CHANGED)
		{
			memcpy( &widgetEvent->value, intArray + 3, sizeof(jint) );
			widgetEvent->fromUser = intArray[4];
		}
		else if (widgetEventType == MAW_EVENT_RADIO_GROUP_ITEM_SELECTED)
		{
			widgetEvent->radioGroupItemHandle = intArray[3];
		}
		else if (widgetEventType == MAW_EVENT_RADIO_BUTTON_STATE_CHANGED)
		{
			widgetEvent->radioButtonState = intArray[3];
		}
		else if (widgetEventType == MAW_EVENT_OPTIONS_MENU_ITEM_SELECTED)
		{
			widgetEvent->optionsMenuItem = intArray[3];
		}

		event.data = (int)widgetEvent;
	}
	else if (event.type == EVENT_TYPE_SENSOR)
	{
		event.sensor.type = intArray[1];
		memcpy( event.sensor.values, intArray + 2, (arrayLength - 2) * sizeof(jint) );
	}
	else if (event.type == EVENT_TYPE_NFC_TAG_RECEIVED ||
			event.type == EVENT_TYPE_NFC_TAG_DATA_READ ||
			event.type == EVENT_TYPE_NFC_TAG_DATA_WRITTEN ||
			event.type == EVENT_TYPE_NFC_BATCH_OP ||
			event.type == EVENT_TYPE_NFC_TAG_AUTH_COMPLETE ||
			event.type == EVENT_TYPE_NFC_TAG_READ_ONLY)
	{
		event.nfc.handle = intArray[1];
		event.nfc.result = intArray[2];
		event.nfc.dstId = intArray[3];
	}
	else if (event.type == EVENT_TYPE_AUDIO_PREPARED ||
			event.type == EVENT_TYPE_AUDIO_COMPLETED)
	{
		event.audioInstance = intArray[1];
	}
	else if (event.type == EVENT_TYPE_CAMERA_PREVIEW)
	{
		__android_log_write(ANDROID_LOG_INFO, "@@@@@@@@ MoSync JNI", "Camera event sent");
	}
	// HOLD ON!
	// Don't forget to update the file EventQueue.cpp when adding
	// event types that would potentially overflow the event queue.

	// Release the memory used for the int array.
	env->ReleaseIntArrayElements(eventBuffer, intArray, 0);

	Base::gSyscall->postEvent(event);
}
Ejemplo n.º 10
0
	//First, the constructor, which will be called whenever we need an
	//instance of AppScreen.
	AppScreen()
	{
		//Make the AppScreen listen for events coming from widgets.
		MAUtil::Environment::getEnvironment().addCustomEventListener(this);

		//Create a Native UI screen using the IOCTL function maWidgetCreate.
		mScreen = maWidgetCreate(MAW_SCREEN);

		//Check if this is supported on the device it's running on
		if(mScreen == IOCTL_UNAVAILABLE)
		{
			maPanic(0,"Sorry but this program does not run currently on this platform");
		}
	   
		//Create the screen's main layout widget. As it is a member variable
		//we give its name an "m" prefix.
		mMainLayoutWidget = maWidgetCreate(MAW_VERTICAL_LAYOUT);
		maWidgetSetProperty(mMainLayoutWidget, MAW_WIDGET_WIDTH, "-1");
		maWidgetSetProperty(mMainLayoutWidget, MAW_WIDGET_HEIGHT, "-1");

		//Identify the main layout widget as root of the screen's widget tree.
		maWidgetAddChild(mScreen, mMainLayoutWidget);

		//Now we create four child widgets within the main layout widget.

		//The first widget is a label that we'll use to present instructions.
		//We set its width and height, and we initialize it with some text.
		//Finally we locate it inside the screen widget.
		mInstructions = maWidgetCreate(MAW_LABEL);
		maWidgetSetProperty(mInstructions, MAW_WIDGET_WIDTH, "-1");
		maWidgetSetProperty(mInstructions, MAW_WIDGET_HEIGHT, "-2");
		maWidgetSetProperty(mInstructions, MAW_LABEL_TEXT, "Enter a password:"******"-1");
		maWidgetSetProperty(mPasswordBox, MAW_WIDGET_HEIGHT, "-2");
		maWidgetSetProperty(mPasswordBox, "editMode", "password");
		maWidgetAddChild(mMainLayoutWidget, mPasswordBox);

		//The third and fourth widgets are labels that we will use as buttons.
		//We centre the text vertically and horizontally within the buttons.
		mClearButton = maWidgetCreate(MAW_BUTTON);
		maWidgetSetProperty(mClearButton, MAW_WIDGET_WIDTH, "-1");
		maWidgetSetProperty(mClearButton, MAW_WIDGET_HEIGHT, "-2");
		maWidgetSetProperty(mClearButton, MAW_BUTTON_TEXT_VERTICAL_ALIGNMENT, "center");
		maWidgetSetProperty(mClearButton, MAW_BUTTON_TEXT_HORIZONTAL_ALIGNMENT, "center");
		maWidgetSetProperty(mClearButton, MAW_BUTTON_TEXT, "Clear");
		maWidgetAddChild(mMainLayoutWidget, mClearButton);

		mSubmitButton = maWidgetCreate(MAW_BUTTON);
		maWidgetSetProperty(mSubmitButton, MAW_WIDGET_WIDTH, "-1");
		maWidgetSetProperty(mSubmitButton, MAW_WIDGET_HEIGHT, "-2");
		maWidgetSetProperty(mSubmitButton, MAW_BUTTON_TEXT_VERTICAL_ALIGNMENT, "center");
		maWidgetSetProperty(mSubmitButton, MAW_BUTTON_TEXT_HORIZONTAL_ALIGNMENT, "center");
		maWidgetSetProperty(mSubmitButton, MAW_BUTTON_TEXT, "Submit");
		maWidgetAddChild(mMainLayoutWidget, mSubmitButton);

	//That's the constructor finished.
	}
Ejemplo n.º 11
0
void FatalError ( char msg[] )
{
	maPanic( -1, msg );
}
Ejemplo n.º 12
0
	void ImageGenerators::linearGradient(
		MAHandle image, 
		Point start, 
		Point end, 
		int startColor,
		int endColor, 
		ImageGenerators::AlphaMode alphaMode)
	{
		MAExtent size = maGetImageSize(image);
		int imgWidth = EXTENT_X(size);
		int imgHeight = EXTENT_Y(size);

		int gradVecX;
		int gradVecY;
		int gradOrthoVecX;
		int gradOrthoVecY;

		gradVecX = end.x - start.x;
		gradVecY = end.y - start.y;
		gradOrthoVecX = gradVecY;
		gradOrthoVecY = -gradVecX;

		int startAlpha =	(startColor&0xff000000)>>24;
		int startRed =		(startColor&0x00ff0000)>>16;
		int startGreen =	(startColor&0x0000ff00)>>8;
		int startBlue =		(startColor&0x000000ff);

		int endAlpha =		(endColor&0xff000000)>>24;
		int endRed =		(endColor&0x00ff0000)>>16;
		int endGreen =		(endColor&0x0000ff00)>>8;
		int endBlue =		(endColor&0x000000ff);

		int *tempSurface = new int[imgWidth*imgHeight];

		if(!tempSurface) {
			maPanic(0, "ImageGenerators::linearGradient, NO MEMORY!");
		}

		int *dst = tempSurface;

		MAHandle lastDrawTarget = maSetDrawTarget(image);

		int sqrLen = gradOrthoVecX*gradOrthoVecX + gradOrthoVecY*gradOrthoVecY;
		double sqrtLen = (sqrt((double)sqrLen));
		double sqrtLenRecip = 1.0/sqrtLen;
		//lprintfln("imgWidth: %d, imgHeight: %d\n", imgWidth, imgHeight);
		for(int j = 0; j < imgHeight; j++) {
			for(int i = 0; i < imgWidth; i++) {

				int u = (((i - start.x)*gradOrthoVecX + 
					(j - start.y)*gradOrthoVecY)<<16) / sqrLen;

				int projectedPointX = ((u*gradOrthoVecX)>>16);
				int projectedPointY = ((u*gradOrthoVecY)>>16);

				//lprintfln("we come here! %d\n", i + j*imgWidth);

				double distToStart = 
					(sqrt((double)
						(((start.x+projectedPointX)-i)*((start.x+projectedPointX)-i) +
						((start.y+projectedPointY)-j)*((start.y+projectedPointY)-j))
						));

				double distToEnd = (sqrt((double)
					(((end.x+projectedPointX)-i)*((end.x+projectedPointX)-i) +
					((end.y+projectedPointY)-j)*((end.y+projectedPointY)-j))
					)); 
				//double distToStart = 0.0;
				//double distToEnd = 0.0;

				//	double distToEnd = sqrtLen - distToStart;

				if(distToEnd >= sqrtLen) {
					*dst++  = startColor;
				} 
				else if(distToStart >= sqrtLen) {
					*dst++ = endColor;
				} 
				else {
					int r = (int)(((distToStart*(double)endRed) 
						+ (distToEnd*(double)startRed))*sqrtLenRecip);
					int g = (int)(((distToStart*(double)endGreen) 
						+ (distToEnd*(double)startGreen))*sqrtLenRecip);
					int b = (int)(((distToStart*(double)endBlue) 
						+ (distToEnd*(double)startBlue))*sqrtLenRecip);
					int a = (int)(((distToStart*(double)endAlpha) 
						+ (distToEnd*(double)startAlpha))*sqrtLenRecip);
					if(r<0)		r = 0;
					if(r>255)	r = 255;
					if(g<0)		g = 0;
					if(g>255)	g = 255;
					if(b<0)		b = 0;
					if(b>255)	b = 255;
					if(a<0)		a = 0;
					if(a>255)	a = 255;

					*dst++ = (a<<24)|(r<<16)|(g<<8)|(b);
				}
			} 
		}

		if(alphaMode == AM_WRITEALPHA) {
			MAPoint2d dstPoint = {0, 0};
			MARect srcRect = {0, 0, imgWidth, imgHeight};
			maDrawRGB(&dstPoint, tempSurface, &srcRect, imgWidth);
			maSetDrawTarget(lastDrawTarget);
		} 
		else if(alphaMode == AM_USEALPHA) {
			// TODO: Implement missing code.
		} 
		else if(alphaMode == AM_NOALPHA) {
			// TODO: Implement missing code.
		}

		delete []tempSurface;
	}
Ejemplo n.º 13
0
long long __ashldi3(long long a, int b)
{
    maPanic(0, "__ashldi3 unimplemented");
    return 0;
}
Ejemplo n.º 14
0
	/**
	 * In the constructor we create the user interface.
	 */
	SineRunnerMoblet() :
		mGLViewInitialized(false)
	{
		// Create a screen widget that will hold the OpenGL view.
		int screen = maWidgetCreate(MAW_SCREEN);

		MAExtent screenSize = maGetScrSize();
		mXRes = EXTENT_X(screenSize);
		mYRes = EXTENT_Y(screenSize);

		mTime = 0;
		mX = mY = 0.0;
		mCPosStart = -100.0;
		mCPos = mCPosStart; //behind the front of the curve
		mCYPos = 0.0;
		mMaxPoint = 0.0;

		mHit = false;
		mHitTimes = 0;

		mScreenIsPressed = false;
		mNumTicks = 0;

		inAir = false;
		mDead = false;
		mFinished = false;

		// Check if NativeUI is supported by the runtime platform.
		// For example, MoRE does not support NativeUI at the time
		// of writing this program.
		if (IOCTL_UNAVAILABLE == screen)
		{
			maPanic(0, "NativeUI is not available.");
		}

		// Create a GL_VIEW widget and add it to the screen.
		// widgetSetPropertyInt is a helper function defined
		// in WidgetUtil.cpp.
		mGLView = maWidgetCreate(MAW_GL_VIEW);
		if (MAW_RES_INVALID_TYPE_NAME == mGLView)
		{
			maPanic(1, "OpenGL|ES unavailable. OpenGL|ES is only available on Android and iOS. Also, please check that the device is able to run the version of OpenGL|ES you requested.");
		}

		widgetSetPropertyInt(
				mGLView,
				MAW_WIDGET_WIDTH,
				MAW_CONSTANT_FILL_AVAILABLE_SPACE);
		widgetSetPropertyInt(
				mGLView,
				MAW_WIDGET_HEIGHT,
				MAW_CONSTANT_FILL_AVAILABLE_SPACE);
		maWidgetAddChild(screen, mGLView);

		// Show the screen.
		maWidgetScreenShow(screen);

		// Make the Moblet listen to custom events, so that we
		// know when the GLView widget is ready to be drawn.
		MAUtil::Environment::getEnvironment().addCustomEventListener(this);
	}
Ejemplo n.º 15
0
	void WidgetSkin::drawDirect(int x, int y, int width, int height, eType type) {
		MAPoint2d dst;
		MAPoint2d dst2;
		MAHandle image;
		switch(type) {
			case SELECTED:
				image = selectedImage;
				break;
			case UNSELECTED:
				image = unselectedImage;
				break;
			default:
				maPanic(0, "WidgetSkin::draw undefined drawing type");
		}

		if(image == 0) return;

		// draw corners
		dst.x = x; dst.y = y;
		//maDrawImageRegion(image, &topLeft, &dst, TRANS_NONE);
		Gfx_drawImageRegion(image, &topLeft, &dst, TRANS_NONE);

		dst.x = x; dst.y = y+height-bottomLeft.height;
		//maDrawImageRegion(image, &bottomLeft, &dst, TRANS_NONE);
		Gfx_drawImageRegion(image, &bottomLeft, &dst, TRANS_NONE);

		dst.x = x+width-topRight.width; dst.y = y;
		//maDrawImageRegion(image, &topRight, &dst, TRANS_NONE);
		Gfx_drawImageRegion(image, &topRight, &dst, TRANS_NONE);

		dst.x = x+width-bottomRight.width; dst.y = y+height-bottomRight.height;
		//maDrawImageRegion(image, &bottomRight, &dst, TRANS_NONE);
		Gfx_drawImageRegion(image, &bottomRight, &dst, TRANS_NONE);

		// draw middle
		if(center.height && center.width) {
		for(int j = y+top.height; j < y+height-bottom.height; j+=center.height) {
			int h = center.height;
			if(j+center.height>y+height-bottom.height) {
				center.height -= (j+center.height)-(y+height-bottom.height);
			}
			for(int i = x+left.width; i < x+width-right.width; i+=center.width) {
				dst.x = i; dst.y = j;
				int w = center.width;
				if(i+center.width>x+width-right.width) {
					center.width -= (i+center.width)-(x+width-right.width);
				}
				//maDrawImageRegion(image, &center, &dst, TRANS_NONE);
				Gfx_drawImageRegion(image, &center, &dst, TRANS_NONE);

				center.width = w;
			}
			center.height = h;
		}
		}

		// draw borders
		if(top.width) {
		for(int i = x+left.width; i < x+width-right.width; i+=top.width) {
				dst.x = i; dst.y = y;
				dst2.x = i; dst2.y = y+height-bottom.height;

				int w1 = top.width;
				int w2 = bottom.width;
				if(i+top.width>x+width-right.width) {
					top.width -= (i+w1)-(x+width-right.width);
					bottom.width -= (i+w1)-(x+width-right.width);
				}
				//maDrawImageRegion(image, &top, &dst, TRANS_NONE);
				//maDrawImageRegion(image, &bottom, &dst2, TRANS_NONE);
				Gfx_drawImageRegion(image, &top, &dst, TRANS_NONE);
				Gfx_drawImageRegion(image, &bottom, &dst2, TRANS_NONE);

				top.width = w1;
				bottom.width = w2;
		}
		}

		if(left.height) {
		for(int i = y+top.height; i < y+height-bottom.height; i+=left.height) {
				dst.x = x; dst.y = i;
				dst2.x = x+width-right.width; dst2.y = i;

				int w1 = left.height;
				int w2 = right.height;
				if(i+left.height>y+height-bottom.height) {
					left.height -= (i+w1)-(y+height-bottom.height);
					right.height -= (i+w1)-(y+height-bottom.height);
				}
				//maDrawImageRegion(image, &left, &dst, TRANS_NONE);
				//maDrawImageRegion(image, &right, &dst2, TRANS_NONE);
				Gfx_drawImageRegion(image, &left, &dst, TRANS_NONE);
				Gfx_drawImageRegion(image, &right, &dst2, TRANS_NONE);

				left.height = w1;
				right.height = w2;
		}
		}
	}
Ejemplo n.º 16
0
void PrintConsole(const wchar_t *str)
{
	int length, pos = 0;
	wchar_t* line;

	if (gConsoleLogging)
	{
		static const char prefix[] = "PrintConsole: ";
		maWriteLog(prefix, strlen(prefix));
		length = wcslen(str);
		if (length > 0)
		{
#ifdef MAPIP
			char buf8[length * MB_LEN_MAX];
#else
			char* buf8 = (char*)malloc(length * MB_LEN_MAX);
#endif
			int len8;
			//maWriteLog(str, length*sizeof(wchar_t));
			//convert to utf-8
			memset(buf8, 0, length * MB_LEN_MAX);
			len8 = wcstombs(buf8, str, length * MB_LEN_MAX);
			maWriteLog(buf8, len8);
			if (str[length - 1] != '\n')
				maWriteLog("\n", 1);
#ifndef MAPIP
			free(buf8);
#endif
		}
	}
	if(gConsoleFile > 0) {
		int res = maFileWrite(gConsoleFile, str, wcslen(str));
		if(res < 0) {
			maPanic(res, "PrintConsole maFileWrite");
		}
	}

	if (!sConsole.initialized)
		InitConsole();

	if (sConsole.postponedLineFeed)
	{
		FeedLine();
		sConsole.postponedLineFeed = 0;
	}

	while (str[pos] != '\0')
	{
		if (str[pos] == '\r')
			sConsole.cursorPos.x = 0;
		else if (str[pos] == '\n')
		{
			if (str[pos + 1] == '\0')
				sConsole.postponedLineFeed = 1;
			else
				FeedLine();
		}
		else
		{
			line = sConsole.lines[(sConsole.cursorPos.y + sConsole.firstLine) %
				sConsole.height].line;
			line[sConsole.cursorPos.x++] = str[pos];

			if (sConsole.cursorPos.x >= CONSOLE_WIDTH)
			{
				if (str[pos + 1] == '\0')
					sConsole.postponedLineFeed = 1;
				else
					FeedLine();
			}
		}

		pos++;
	}

	if(gConsoleForceDisplay)
		DisplayConsole();
}