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

📄 atbwapaui.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 5 页
字号:
	lineX = elementX+gle_cell_hBefore;
	
	if (parameter->rows_length == 0)
		lineY = top;															// For fieldset
	else
		lineY = elementY+gle_cell_vBefore;										// For table

	ATB_wap_buffer_line_draw(elementX, lineY, elementX, bottom);				// Left hand line
	
	if (parameter->cols_length > 1)												// Column lines
	{
		for (index=0; index<(parameter->cols_length-1); index++)
		{
			lineX += parameter->ColWidth[index]+gle_cell_spaceToBorder;
			ATB_wap_buffer_line_draw(lineX, lineY, lineX, bottom);
			lineX += gle_cell_borderExtent+gle_cell_spaceToBorder;
		}
	}
	ATB_wap_buffer_line_draw(right, lineY, right, bottom);						// Right hand line
		
	return;
}


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

 $Function:    	ATB_wap_buffer_line_draw

 $Description:	Draws a line, making sure it fits on-screen
 
 $Returns:		

 $Arguments:	x1,y1 - Coordinates of the start of the line
 				x2,y2 - Coordinates of the end of the line
 
*******************************************************************************/

void ATB_wap_buffer_line_draw(SHORT x1, SHORT y1, SHORT x2, SHORT y2)
{
	SHORT deltaX1;
	SHORT deltaY1;
	SHORT deltaX2;
	SHORT deltaY2;
	double m;
	
	ATB_wap_buffer_onscreen(x1,y1, &deltaX1, &deltaY1);
	ATB_wap_buffer_onscreen(x2,y2, &deltaX2, &deltaY2);
	
	if (x2==x1)
	{
		if (deltaX1)
			return;
		y1+=deltaY1;
		y2+=deltaY2;
	}
	else if (y2==y1)
	{
		if (deltaY1)
			return;
		x1+=deltaX1;
		x2+=deltaX2;
	}
	else
	{
		m = (y2-y1)/(x2-x1);	
		if (deltaX1 || deltaY1)
		{
			x1 += deltaX1;
			y1 += m*deltaX1;
			if (!ATB_wap_buffer_onscreen(x1,y1,&deltaX1,&deltaY1))
				return;
		}
		if (deltaX2 || deltaY2)
		{
			x2 += deltaX2;
			y2 += m*deltaX2;
			if (!ATB_wap_buffer_onscreen(x2,y2,&deltaX2,&deltaY2))
				return;
		}
	}
	
	dspl_DrawLine(x1,y1,x2,y2);
	return;
}


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

 $Function:    	ATB_wap_buffer_onscreen

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

 $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:		

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

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;
	UBYTE pixShift;																// Pixel shift, shift bytes by this amount

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

	byteWidth = image->pWidth/8;
	if (image->pWidth % 8)
		byteWidth++;
	
	elementX = image->pX;
	elementY = image->pY;
	
	if (elementX < 0)															// If image starts off the left of the screen...
	{
		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->pY < 0)															// If image starts above the top of the screen
	{
		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 ((elementX+scrWidth)>WAP_SCREEN_WIDTH)									// If the image goes off the right of the screen
		scrWidth = WAP_SCREEN_WIDTH-elementX;									// Reduce its width
	if ((elementY+scrHeight)>WAP_SCREEN_HEIGHT)									// If the image goes off the bottom of the screen
		scrHeight = WAP_SCREEN_HEIGHT-elementY;									// Trim its height

	scrByteWidth = scrWidth/8;													// Work out the width of the trimmed image in bytes
	if (scrWidth % 8)
		scrByteWidth++;
	
	Region = (UBYTE *)AUI_wap_memory_alloc(scrByteWidth*scrHeight);				// Allocate memory for the trimmed image

	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:		

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

void ATB_wap_buffer_image_scale(T_WAP_MMI_SEND_IMAGE_IND *image)
{
	T_WAP_MMI_SEND_IMAGE_IND *Scaled = (T_WAP_MMI_SEND_IMAGE_IND *)AUI_wap_memory_alloc(sizeof(T_WAP_MMI_SEND_IMAGE_IND));																// 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
	TRACE_EVENT("ATB_wap_buffer_image_scale_zhao");

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

	if (image->pHeight > WAP_SCREEN_HEIGHT)
		newHeight = WAP_SCREEN_HEIGHT;											// Squash to fit vertically
	else
		newHeight = image->pHeight;
	
	byteWidth = image->pWidth/8;												// Work out the width of the original image in bytes
	if (image->pWidth % 8)
		byteWidth++;
	
	scrByteWidth = newWidth/8;													// Work out the width of the scaled image in bytes
	if (newWidth % 8)
		scrByteWidth++;
	
	Scaled->Image = (UBYTE *)AUI_wap_memory_alloc(scrByteWidth*newHeight);		// Allocate memory for the scaled image

	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;
#if defined(TRACE_ATBWAPAUI) 
			TRACE_EVENT_P1( "Skipping line %d.", heightIndex);
#endif
		}
		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:		

 $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:
				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:
				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));

⌨️ 快捷键说明

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