⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 atbwapaui.c

📁 GSM手机设计软件代码
💻 C
📖 第 1 页 / 共 5 页
字号:
	
	dspl_DrawLine(x1,y1,x2,y2);
	return;
}


/*******************************************************************************

 $Function:    	ATB_wap_buffer_onscreen

 $Description:	Returns TRUE if the point supplied is on-screen
 
 $Returns:		TRUE if point is onscreen

 $Arguments:	x,y - coordinates of the point
 				deltaX, deltaY - returns offset from screen
 
*******************************************************************************/

static BOOL ATB_wap_buffer_onscreen(SHORT x, SHORT y, SHORT *deltaX, SHORT *deltaY)
{
	BOOL outcome = TRUE;
	*deltaX = 0;
	*deltaY = 0;
	
	if (x<WAP_LEFT_BORDER)
	{
		outcome = FALSE;
		*deltaX = WAP_LEFT_BORDER-x;
	}
	if (x>(WAP_SCREEN_RIGHT-1))
	{
		outcome = FALSE;
		*deltaX = (WAP_SCREEN_RIGHT-1)-x;
	}
	if (y<WAP_TOP_BORDER)
	{
		outcome = FALSE;
		*deltaY = WAP_TOP_BORDER-y;
	}
	if (y>(WAP_SCREEN_BOTTOM-1))
	{
		outcome = FALSE;
		*deltaY = (WAP_SCREEN_BOTTOM-1)-y;
	}

	return outcome;
}


/*******************************************************************************

 $Function:    	ATB_wap_buffer_image_display

 $Description:	Trims an image to fit into the specified space, then displays it
 
 $Returns:		None.

 $Arguments:	image - the image to display
 
*******************************************************************************/

static void ATB_wap_buffer_image_display(T_WAP_MMI_SEND_IMAGE_IND *image)
{
	UBYTE *Region;								/* Pointer to trimmed image */
	SHORT offsetX = 0;							/* Offsets from origin of original image... */
	SHORT offsetY = 0;							/* ...where trimmed image starts */
	SHORT scrWidth = image->pWidth;				/* Width of trimmed image on screen */
	SHORT scrHeight = image->pHeight;			/* Height of trimmed image on screen */
	SHORT elementX;								/* Its x position on the screen */
	SHORT elementY;								/* Its y position on the screen */
	USHORT byteWidth;							/* Width of original in bytes */
	USHORT scrByteWidth;						/* Width of screen image in bytes */
	USHORT	offsetByteWidth;
	USHORT heightIndex;	
	USHORT widthIndex;
	USHORT memIndex = 0;
	UBYTE *Image = image->Image;				/* The image data */
	UBYTE pixShift;								/* Pixel shift, shift bytes by this amount */

#ifdef TRACE_ATBWAPAUI
	TRACE_FUNCTION("ATB_wap_buffer_image_display");
#endif

	byteWidth = image->pWidth/8;
	if (image->pWidth % 8)
		byteWidth++;
	
	elementX = image->pX;
	elementY = image->pY;

	/* If image starts off the left of the screen */
	
	if (elementX < 0)
	{
		offsetX = -elementX;					/* Set the X offset so it is trimmed appropriately */
		scrWidth -= offsetX;					/* Change its width */
		elementX = 0;							/* And place it at the left of the screen */
	}

	/* If image starts above the top of the screen */
	
	if (image->pY < 0)
	{
		offsetY = -elementY;					/* Set the Y offset so it is trimmed appropriately */
		scrHeight -= offsetY;					/* Change its height */
		elementY = 0;							/* And place it at the top of the screen */
	}

	/* If the image goes off the right of the screen, reduce its width */
	
	if ((elementX+scrWidth)>WAP_SCREEN_WIDTH)							
		scrWidth = WAP_SCREEN_WIDTH-elementX;

	/* If the image goes off the bottom of the screen, trim its height */
	
	if ((elementY+scrHeight)>WAP_SCREEN_HEIGHT)
		scrHeight = WAP_SCREEN_HEIGHT-elementY;

	scrByteWidth = scrWidth/8;	/* Work out the width of the trimmed image in bytes */
	if (scrWidth % 8)
		scrByteWidth++;

	/* Allocate memory for the trimmed image */
	
	Region = (UBYTE *)AUI_wap_memory_alloc(scrByteWidth*scrHeight);

	offsetByteWidth = offsetX/8;
	pixShift = offsetX % 8;			/* Offset within the byte of the first pixel */
	
	Image += (offsetY*byteWidth)+offsetByteWidth;	/* Point to the first byte of the region to be isolated */
		
	/* Copy the trimmed region of the image into our allocated memory,
	 * inverting it as necessary */
	
	for (heightIndex = 0; heightIndex<scrHeight; heightIndex++)
	{
		for (widthIndex = 0; widthIndex<scrByteWidth; widthIndex++)
		{
			Region[memIndex] = Image[widthIndex] << pixShift;
			if ((offsetByteWidth+scrByteWidth)<byteWidth || widthIndex<(scrByteWidth-1))
				Region[memIndex] |= Image[widthIndex+1] >> (8-pixShift);
			
			if (!image->invert)
				Region[memIndex] ^= 0xFF;	/* De-invert it if not selected */

			memIndex++;
		}
		Image += byteWidth;					/* Move down one line */
	}

#ifdef TRACE_ATBWAPAUI
	TRACE_EVENT_P2( "byteWidth: %d, scrByteWidth: %d", byteWidth, scrByteWidth);
	TRACE_EVENT_P4( "pX: %d, pY: %d, pWidth: %d, pHeight: %d", image->pX, image->pY, image->pWidth, image->pHeight);
	TRACE_EVENT_P4( "offsetX: %d, offsetY: %d, scrWidth: %d, scrHeight: %d", offsetX, offsetY, scrWidth, scrHeight);
	TRACE_EVENT_P2( "elementX: %d, elementY: %d", elementX, elementY);
	TRACE_EVENT_P2( "Region size: %d, should be: %d", memIndex, scrByteWidth*scrHeight);
#endif

	/* Display the image */

	dspl_BitBlt (elementX+WAP_LEFT_BORDER, elementY+WAP_TOP_BORDER, scrWidth, scrHeight, 0, (void *)Region, 0);

	/* Free the memory */
	
	AUI_wap_memory_free(Region, scrByteWidth*scrHeight);
	
	return;
}


/*******************************************************************************

 $Function:    	ATB_wap_buffer_image_scale

 $Description:	Scales an image to fit into a specified space
 
 $Returns:		None.

 $Arguments:	View - pointer to the appropriate view
 
*******************************************************************************/

static void ATB_wap_buffer_image_scale(T_WAP_MMI_SEND_IMAGE_IND *image)
{
	T_WAP_MMI_SEND_IMAGE_IND *Scaled;		/* Pointer to scaled image */
	SHORT	newWidth;
	SHORT	newHeight;
	USHORT heightIndex;	
	USHORT widthIndex;
	USHORT oldIndex;
	USHORT	newIndex;
	USHORT	byteWidth;
	USHORT	scrByteWidth;
	UBYTE	*Image = image->Image;
	UBYTE	oldMask;						/* Pixel shift, shift bytes by this amount */
	UBYTE	newMask;
	UBYTE	pixel;
	USHORT	xScale;
	USHORT	xScaleOld;
	USHORT	yScale;
	USHORT	yScaleOld;

#ifdef TRACE_ATBWAPAUI
	TRACE_FUNCTION("ATB_wap_buffer_image_scale");
#endif

	/* Allocate memory for scaled image */
	
	Scaled = (T_WAP_MMI_SEND_IMAGE_IND *)AUI_wap_memory_alloc(sizeof(T_WAP_MMI_SEND_IMAGE_IND));	

	/* Squash to fit horizontally */
	
	if (image->pWidth > WAP_SCREEN_WIDTH)
		newWidth = WAP_SCREEN_WIDTH;
	else
		newWidth = image->pWidth;

	/* Squash to fit vertically */

	if (image->pHeight > WAP_SCREEN_HEIGHT)
		newHeight = WAP_SCREEN_HEIGHT;
	else
		newHeight = image->pHeight;

	/* Work out the width of the original image in bytes */
	
	byteWidth = image->pWidth/8;
	if (image->pWidth % 8)
		byteWidth++;

	/* Work out the width of the scaled image in bytes */
	scrByteWidth = newWidth/8;
	if (newWidth % 8)
		scrByteWidth++;

	/* Allocate memory for the scaled image */
	
	Scaled->Image = (UBYTE *)AUI_wap_memory_alloc(scrByteWidth*newHeight);

	oldIndex = -1;
	newIndex = -1;
	yScaleOld = 0;
	
	/* Scale the image */
	
	for (heightIndex = 0; heightIndex<image->pHeight; heightIndex++)
	{
		yScale = (USHORT) (heightIndex+1)*newHeight/image->pHeight;
		
		if (yScale != yScaleOld)
		{
			oldMask = 1;		/* Mask within the byte of the first pixel */
			newMask = 1;
			xScaleOld = 0;

			for (widthIndex = 0; widthIndex<image->pWidth; widthIndex++)
			{
				xScale = (USHORT) (widthIndex+1)*newWidth/image->pWidth;

				if (oldMask == 1)
				{
					oldMask = 128;
					oldIndex++;
				}
				else
					oldMask /= 2;
				
				if (xScale != xScaleOld)
				{
					if (newMask == 1)
					{
						newMask = 128;
						newIndex++;
						Scaled->Image[newIndex] = 0;
					}
					else
						newMask /= 2;

					if (Image[oldIndex] & oldMask)							/* If old pixel set, */
						Scaled->Image[newIndex] |= newMask;					/* set new pixel */
				}
				
				xScaleOld = xScale;
			}
		}
		else
		{
			oldIndex += byteWidth;
		}
		yScaleOld = yScale;
	}

#ifdef TRACE_ATBWAPAUI
	TRACE_EVENT_P2( "byteWidth: %d, scrByteWidth: %d", byteWidth, scrByteWidth);
	TRACE_EVENT_P4( "pX: %d, pY: %d, pWidth: %d, pHeight: %d",
		image->pX, image->pY, image->pWidth, image->pHeight);
	TRACE_EVENT_P2( "newWidth: %d, newHeight: %d", newWidth, newHeight);

#endif

	/* Display the image */

	Scaled->object_id = image->object_id;
	Scaled->image_length = scrByteWidth*newHeight;
	Scaled->invert = image->invert;
	Scaled->pX = image->pX;
	Scaled->pY = image->pY;
	Scaled->pWidth = newWidth;
	Scaled->pHeight = newHeight;
	Scaled->selected = image->selected;
	
	ATB_wap_buffer_image_display(Scaled);
	
	/* Free the memory */
	
	AUI_wap_memory_free(Scaled->Image, scrByteWidth*newHeight);
	AUI_wap_memory_free((UBYTE *)Scaled, sizeof(T_WAP_MMI_SEND_IMAGE_IND));
	
	return;
}


/*******************************************************************************

 $Function:    	ATB_wap_buffer_clear

 $Description:	Clears the element buffer
 
 $Returns:		None.

 $Arguments:	View - pointer to the appropriate view
 
*******************************************************************************/

void ATB_wap_buffer_clear(T_WAP_VIEW *View)
{
	T_WAP_ELEMENT					*Element	= View->ElementHeader;
	T_WAP_ELEMENT					*NextElement;
	T_WAP_MMI_SEND_TEXT_IND			*TextElement;
	T_WAP_MMI_SEND_TABLE_IND 		*TableElement;
	T_WAP_MMI_SEND_IMAGE_IND 		*ImageElement;
	USHORT 							elementCount = 0;

#ifdef TRACE_ATBWAPAUI
	TRACE_FUNCTION("ATB_wap_buffer_clear");
#endif

	while (Element != NULL)
	{
		switch (Element->type)
		{
			case WAP_TEXT:
				/* Delete a text element */
				TextElement = (T_WAP_MMI_SEND_TEXT_IND *)Element->data;
				if (TextElement->text_length != 0)
					AUI_wap_memory_free((UBYTE *)TextElement->Text, TextElement->text_length*sizeof(USHORT));
				if (TextElement->formatstring_length != 0)
				{
					AUI_wap_memory_free((UBYTE *)TextElement->Formatstring,
						TextElement->formatstring_length*sizeof(USHORT));
				}
				AUI_wap_memory_free((UBYTE *)TextElement, sizeof(T_WAP_MMI_SEND_TEXT_IND));
				break;

			case WAP_TABLE:
				/* Delete a table/fieldset element */
				TableElement = (T_WAP_MMI_SEND_TABLE_IND *)Element->data;
				if (TableElement->title_length != 0)
					AUI_wap_memory_free((UBYTE *)TableElement->Title, TableElement->title_length*sizeof(USHORT));
				if (TableElement->cols_length != 0)
					AUI_wap_memory_free((UBYTE *)TableElement->ColWidth, TableElement->cols_length*sizeof(SHORT));
				if (TableElement->rows_length != 0)
					AUI_wap_memory_free((UBYTE *)TableElement->RowHeight, TableElement->rows_length*sizeof(SHORT));
				AUI_wap_memory_free((UBYTE *)TableElement, sizeof(T_WAP_MMI_SEND_TABLE_IND));
				break;
				
			case WAP_IMAGE:
				/* Delete an image element */
				ImageElement = (T_WAP_MMI_SEND_IMAGE_IND *)Element->data;
				if (ImageElement->image_length != 0)
					AUI_wap_memory_free((UBYTE *)ImageElement->Image, ImageElement->image_length*sizeof(UBYTE));
				AUI_wap_memory_free((UBYTE *)ImageElement, sizeof(T_WAP_MMI_SEND_IMAGE_IND));
				break;
		}
		
		NextElement = Element->NextElement;
		AUI_wap_memory_free((UBYTE *)Element, sizeof(T_WAP_ELEMENT));
		Element = NextElement;
		elementCount++;
	}

	/* Element chain is now empty */
	
	View->ElementHeader = NULL;
	
	return;
}


/*******************************************************************************

 $Function:    	ATB_wap_buffer_identify_element

 $Description:	Identifies which element is selected (based on the invert property) and
 				returns an appropriate type.
 
 $Returns:		The type of the element that is selected, or NULL if none

 $Arguments:	View	- pointer to the view
 
*******************************************************************************/

UBYTE ATB_wap_buffer_identify_element(T_WAP_VIEW *View)
{
	T_WAP_ELEMENT				*Element	= View->ElementHeader;
	T_WAP_MMI_SEND_TEXT_IND		*TextElement;
	T_WAP_MMI_SEND_IMAGE_IND	*ImageElement;

#ifdef TRACE_ATBWAPAUI
	TRACE_FUNCTION("ATB_wap_buffer_identify_element");
#endif

	while (Element!=NULL)
	{
		switch (Element->type)
		{
			case WAP_TEXT:
				TextElement = (T_WAP_MMI_SEND_TEXT_IND *)Element->data;
				if (TextElement->invert)
				{
					return TextElement->type;
				}
				break;

			case WAP_IMAGE:
				ImageElement = (T_WAP_MMI_SEND_IMAGE_IND *)Element->data;
				if (ImageElement->invert)
				{
					return WAP_SELECTABLE_IMAGE;
				}
				break;
		}
		Element = Element->NextElement;
	}

	/* Element not identified */
	
	return NULL;
}


/*******************************************************************************

 $Function:    	ATB_wap_profile_read

 $Description:	Reads in the specified profile and changes the ProfileId

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -