Ejemplo n.º 1
0
void GetA::paint(int paintCursor)
{
	err_when( cursor_pos < 0 || cursor_pos > strlen(input_field) );
	err_when( mark_cursor_pos < 0 || mark_cursor_pos > strlen(input_field) );
	int cursorX = font_ptr->text_width(input_field, cursor_pos);
	int leftX = font_ptr->text_width(input_field, mark_begin());
	int rightX = font_ptr->text_width(input_field, mark_end());

	// create a temp buffer to store character
	int rightLimit = x_limit - x;
	int textWidth = font_ptr->text_width(input_field, -1, rightLimit ) + 1;
	int textHeight = font_ptr->max_font_height;
	char *bitmap = sys.common_data_buf;
	err_when( 2*sizeof(short) + textWidth * textHeight > COMMON_DATA_BUF_SIZE );

	*(short *)bitmap = textWidth;
	bitmap += sizeof(short);
	*(short *)bitmap = textHeight;
	bitmap += sizeof(short);

	memset( bitmap, TRANSPARENT_CODE, textWidth * textHeight );
	if( back_ground_bitmap && !Vga::use_back_buf )
	{
		short backGroundWidth = *(short *)back_ground_bitmap;
		short backGroundHeight = *(1+(short *)back_ground_bitmap);
		// fill backGround
		switch(align_flag)
		{
		case 0:
			IMGbltArea(bitmap, textWidth, 0, 0, back_ground_bitmap, 
				0, 0, MIN(textWidth, backGroundWidth)-1, MIN(textHeight, backGroundHeight)-1 );
			break;
		case 1:
			{
				int l = (x_limit - x + 1 - textWidth ) / 2;
				if( l >= 0 && l < backGroundWidth )
				IMGbltArea(bitmap, textWidth, 0, 0, back_ground_bitmap, 
					l, 0, MIN(l+textWidth, backGroundWidth)-1, MIN(textHeight, backGroundHeight)-1 );
			}
			break;
		case -1:
			{
				int l = x_limit - textWidth + 1 - x;
				if( l < backGroundWidth )
					IMGbltArea(bitmap, textWidth, 0, 0, back_ground_bitmap, 
						l, 0, MIN(x_limit-x+1, backGroundWidth)-1, MIN(textHeight, backGroundHeight)-1 );
			}
			break;
		default:
			err_here();
		}
	}
	font_ptr->put_to_buffer(bitmap, textWidth, 0, 0, input_field);

	if( paintCursor && enable_flag && cursorX < x_limit )
	{
		// horizontal bar for selected area
		if( leftX < textWidth )
		{
			IMGbar( bitmap, textWidth, 
				leftX, font_ptr->height()-1, MIN(rightX, textWidth-1), font_ptr->height()-1, 0);
		}

		// vertical bar
		if( cursorX < textWidth )
			IMGbar( bitmap, textWidth, cursorX, 0, cursorX, font_ptr->height()-1, 0);
	}

	if( !Vga::use_back_buf)
	{
		mouse.hide_area(x,y, x_limit, y+font_ptr->max_font_height-1 );
		switch( align_flag )
		{
		case 0:		// left justified
			if( !back_ground_bitmap )
			{
				if( x+textWidth <= x_limit )		// fill right
					vga_util.blt_buf( x+textWidth, y, x_limit, y + font_ptr->max_font_height-1, 0);
				IMGjoinTrans(vga_front.buf_ptr(), vga_front.buf_pitch(), 
					vga_back.buf_ptr(), vga_back.buf_pitch(),
					x, y, sys.common_data_buf);
			}
			else
			{
				short backGroundWidth = *(short *)back_ground_bitmap;
				short backGroundHeight = *(1+(short *)back_ground_bitmap);
				if( textWidth < backGroundWidth && x+textWidth <= x_limit )		// fill right
					vga_front.put_bitmap_area(x, y, back_ground_bitmap,
					textWidth, 0, MIN(x_limit-x, backGroundWidth-1), backGroundHeight-1 );
				vga_front.put_bitmap_trans(x, y, sys.common_data_buf);
			}
			break;

		case 1:		// center justified
			if( !back_ground_bitmap )
			{
				int l = x + (x_limit - x + 1 - textWidth ) / 2;
				if( x < l )
				{
					vga_util.blt_buf( x, y, l-1, y + font_ptr->max_font_height-1, 0);
				}
				if( l+textWidth <= x_limit )
				{
					vga_util.blt_buf( l+textWidth, y, x_limit, y + font_ptr->max_font_height-1, 0);
				}
				IMGjoinTrans(vga_front.buf_ptr(), vga_front.buf_pitch(), 
					vga_back.buf_ptr(), vga_back.buf_pitch(),
					l, y, sys.common_data_buf);
			}
			else
			{
				int l = x + (x_limit - x + 1 - textWidth ) / 2;
				short backGroundWidth = *(short *)back_ground_bitmap;
				short backGroundHeight = *(1+(short *)back_ground_bitmap);
				if( x < l && l-x <= backGroundWidth)
				{
					vga_front.put_bitmap_area(x, y, back_ground_bitmap, 
						0, 0, MIN(l-x, backGroundWidth)-1, backGroundHeight-1);
				}
				if( l+textWidth <= x_limit && l+textWidth-x < backGroundWidth)
				{
					vga_front.put_bitmap_area(x, y, back_ground_bitmap,
						l+textWidth-x, 0, MIN(x_limit-x+1, backGroundWidth)-1, backGroundHeight-1);
				}
				vga_front.put_bitmap_trans(l, y, sys.common_data_buf);
			}
			break;

		case -1:		// right justified
			if( !back_ground_bitmap )
			{
				int l = x_limit - textWidth + 1;
				if( x < l )		// fill left
					vga_util.blt_buf( x, y, l-1, y + font_ptr->max_font_height-1, 0);
				IMGjoinTrans(vga_front.buf_ptr(), vga_front.buf_pitch(), 
					vga_back.buf_ptr(), vga_back.buf_pitch(),
					l, y, sys.common_data_buf);
			}
			else
			{
				short backGroundWidth = *(short *)back_ground_bitmap;
				short backGroundHeight = *(1+(short *)back_ground_bitmap);
				int l = x_limit - textWidth + 1;
				if( x < l )
					vga_front.put_bitmap_area(0, 0, back_ground_bitmap,
					0, 0, MIN(l-x, backGroundWidth)-1, backGroundHeight-1 );
				vga_front.put_bitmap_trans(l, y, sys.common_data_buf);
			}
			break;
		
		default:
			err_here();
		}
		mouse.show_area();
	}
	else
	{
		switch( align_flag )
		{
		case 0:		// left justified
			IMGbltTrans( vga_back.buf_ptr(), vga_back.buf_pitch(),
				x, y, sys.common_data_buf);
			break;

		case 1:		// center justified
			{
				int l = x + (x_limit - x + 1 - textWidth ) / 2;
				IMGbltTrans( vga_back.buf_ptr(), vga_back.buf_pitch(),
					l, y, sys.common_data_buf);
			}

			// BUGHERE : fill left and right
			break;

		case -1:		// right justified
			IMGbltTrans( vga_back.buf_ptr(), vga_back.buf_pitch(),
				x_limit - textWidth + 1, y, sys.common_data_buf);
			break;
		
		default:
			err_here();
		}
	}
}
Ejemplo n.º 2
0
unsigned GetA::detect_key()
{
	if( !enable_flag )
		return 0;

	err_when( cursor_pos < 0 || cursor_pos > strlen(input_field) );
	err_when( mark_cursor_pos < 0 || mark_cursor_pos > strlen(input_field) );

	if( mouse.is_key_event() )
	{
		unsigned keyCode = mouse.key_code;
		unsigned	shiftPressed = mouse.event_skey_state & SHIFT_KEY_MASK;
		// printable character
		if( keyCode >= ' ' && keyCode <= 0xff )
		{
			if( strlen(input_field)-(mark_end() - mark_begin()) < field_len)
			{
				// insert character
				memmove( input_field+mark_begin()+1, input_field+mark_end(), 
					strlen(input_field)-mark_end()+1);
				input_field[mark_begin()] = keyCode;
				cursor_pos = mark_begin()+1;
				clear_select();
			}
			err_when( cursor_pos < 0 || cursor_pos > strlen(input_field) );
			err_when( mark_cursor_pos < 0 || mark_cursor_pos > strlen(input_field) );
			return keyCode;
		}
		else if( keyCode == KEY_DEL )
		{
			if( is_select() )
			{
				err_when( cursor_pos < 0 || cursor_pos > strlen(input_field) );
				err_when( mark_cursor_pos < 0 || mark_cursor_pos > strlen(input_field) );
				// erase selected area
				memmove( input_field+mark_begin(), input_field+mark_end(),
					strlen(input_field)-mark_end()+1);
				cursor_pos = mark_begin();
				clear_select();
			}
			else 
			{
				if(strlen(input_field) > cursor_pos)
				{
					err_when( cursor_pos < 0 || cursor_pos > strlen(input_field) );
					memmove( input_field+cursor_pos, input_field+cursor_pos+1, 
						strlen(input_field)-cursor_pos);
					err_when( cursor_pos < 0 || cursor_pos > strlen(input_field) );
				}
			}
			err_when( cursor_pos < 0 || cursor_pos > strlen(input_field) );
			err_when( mark_cursor_pos < 0 || mark_cursor_pos > strlen(input_field) );
			return keyCode;
		}
		else if( keyCode == KEY_BACK_SPACE )
		{
			if( is_select() )
			{
				err_when( cursor_pos < 0 || cursor_pos > strlen(input_field) );
				err_when( mark_cursor_pos < 0 || mark_cursor_pos > strlen(input_field) );
				// erase selected area
				memmove( input_field+mark_begin(), input_field+mark_end(),
					strlen(input_field)-mark_end()+1);
				cursor_pos = mark_begin();
				clear_select();
			}
			else 
			{
				if(cursor_pos > 0)
				{
					err_when( cursor_pos < 0 || cursor_pos > strlen(input_field) );
					memmove( input_field+cursor_pos-1, input_field+cursor_pos, 
						strlen(input_field)-cursor_pos+1);
					cursor_pos--;
					err_when( cursor_pos < 0 || cursor_pos > strlen(input_field) );
					clear_select();
				}
			}
			err_when( cursor_pos < 0 || cursor_pos > strlen(input_field) );
			err_when( mark_cursor_pos < 0 || mark_cursor_pos > strlen(input_field) );
			return keyCode;
		}
		if( keyCode == KEY_LEFT )
		{
			if(cursor_pos > 0)
				cursor_pos--;
			if( !shiftPressed )
				clear_select();
			err_when( cursor_pos < 0 || cursor_pos > strlen(input_field) );
			err_when( mark_cursor_pos < 0 || mark_cursor_pos > strlen(input_field) );
			return keyCode;
		}
		if( keyCode == KEY_RIGHT )
		{
			if(cursor_pos < strlen(input_field))
				cursor_pos++;
			if( !shiftPressed )
				clear_select();
			err_when( cursor_pos < 0 || cursor_pos > strlen(input_field) );
			err_when( mark_cursor_pos < 0 || mark_cursor_pos > strlen(input_field) );
			return keyCode;
		}
		if( keyCode == KEY_HOME)
		{
			cursor_pos = 0;
			if( !shiftPressed )
				clear_select();
			err_when( cursor_pos < 0 || cursor_pos > strlen(input_field) );
			err_when( mark_cursor_pos < 0 || mark_cursor_pos > strlen(input_field) );
			return keyCode;
		}
		if( keyCode == KEY_END)
		{
			cursor_pos = strlen(input_field);
			if( !shiftPressed )
				clear_select();
			err_when( cursor_pos < 0 || cursor_pos > strlen(input_field) );
			err_when( mark_cursor_pos < 0 || mark_cursor_pos > strlen(input_field) );
			return keyCode;
		}
		if( esc_key_flag && keyCode == KEY_ESC )
		{
			// if esc_key_flag is 0 and ESC key pressed, still return 0
			clear();
			return keyCode;
		}
		if( keyCode == KEY_RETURN || keyCode == KEY_UP ||
			keyCode == KEY_DOWN || keyCode == KEY_TAB )
		{
			return keyCode;
		}
	}

	return 0;
}
Ejemplo n.º 3
0
Archivo: ogeta.cpp Proyecto: mecirt/7k2
void GetA::paint(int paintCursor)
{
	err_when( cursor_pos < 0 || cursor_pos > strlen(input_field) );
	err_when( mark_cursor_pos < 0 || mark_cursor_pos > strlen(input_field) );
	int cursorX = font_ptr->text_width(input_field, cursor_pos);
	int leftX = font_ptr->text_width(input_field, mark_begin());
	int rightX = font_ptr->text_width(input_field, mark_end());

	// create a temp buffer to store character
	int rightLimit = x_limit - x;
	int textWidth = font_ptr->text_width(input_field, -1, rightLimit ) + 1;
	int textHeight = font_ptr->max_font_height;

	// ###### begin Gilbert 14/10 ######//
	Blob2DW tempBuffer;
	// ###### end Gilbert 14/10 ######//
	tempBuffer.resize(0, 0, textWidth, textHeight);
	BitmapW *bitmap = tempBuffer.ptr;

	bitmap->init(textWidth, textHeight);

	if( back_ground_bitmap )
	{
		short backGroundWidth = back_ground_bitmap->get_width();
		short backGroundHeight = back_ground_bitmap->get_height();
		// fill backGround
		switch(align_flag)
		{
		case 0:
			vga_buffer.put_bitmapW_area(0, 0, (short *)back_ground_bitmap, 0, 0, min(textWidth, backGroundWidth)-1, min(textHeight, backGroundHeight)-1, false, bitmap->get_ptr(), bitmap->get_true_pitch());
			break;
		case 1:
			{
				int l = (x_limit - x + 1 - textWidth ) / 2;
				if( l >= 0 && l < backGroundWidth )
				vga_buffer.put_bitmapW_area(-l, 0, (short *)back_ground_bitmap, l, 0, min(l+textWidth, backGroundWidth)-1, min(textHeight, backGroundHeight)-1, false, bitmap->get_ptr(), bitmap->get_true_pitch());
			}
			break;
		case -1:
			{
				int l = x_limit - textWidth + 1 - x;
				if( l < backGroundWidth )
					vga_buffer.put_bitmapW_area(-l, 0, (short *)back_ground_bitmap, l, 0, min(l+textWidth, backGroundWidth)-1, min(textHeight, backGroundHeight)-1, false, bitmap->get_ptr(), bitmap->get_true_pitch());
			}
			break;
		default:
			err_here();
		}
	}
	else
	{
			// get from the back buffer
			switch(align_flag)
			{
			case 0:	// left just
				vga_back.read_bitmapW( x, y, x+textWidth-1, y+textHeight-1, bitmap);
				break;
			case 1:	// centre just
				{
					int l = (x_limit - x + 1 - textWidth ) / 2;
					vga_back.read_bitmapW( x+l, y, x+l+textWidth-1, y+textHeight-1, bitmap );
				}
				break;
			case -1:
				vga_back.read_bitmapW( x_limit-textWidth+1, y, x_limit, y+textHeight-1, bitmap );
				break;
			default:
				err_here();
			}
	}

	font_ptr->put_to_bufferW(bitmap->get_ptr(), bitmap->get_true_pitch(), 0, 0, input_field);

	if( paintCursor && enable_flag && cursorX < x_limit )
	{
		// horizontal bar for selected area
		if( leftX < textWidth )
		{
			vga_buffer.put_bar(leftX, font_ptr->height()-1, min(rightX, textWidth-1), font_ptr->height()-1, 0, 5, bitmap->get_ptr(), bitmap->get_true_pitch());
		}

		// vertical bar
		if( cursorX < textWidth )
			vga_buffer.put_bar(cursorX, 0, cursorX, font_ptr->height()-1, 0, 5, bitmap->get_ptr(), bitmap->get_true_pitch());
	}

	switch( align_flag )
	{
	case 0:		// left justified
		// ##### begin Gilbert 22/2 ########//
		Vga::active_buf->put_bitmapW(x, y, bitmap );
		// ##### end Gilbert 22/2 ########//
		break;

	case 1:		// center justified
		{
			int l = x + (x_limit - x + 1 - textWidth ) / 2;
			// ##### begin Gilbert 22/2 ########//
			Vga::active_buf->put_bitmapW(l, y, bitmap );
			// ##### end Gilbert 22/2 ########//
		}
		break;

	case -1:		// right justified
		// ##### begin Gilbert 22/2 ########//
		Vga::active_buf->put_bitmapW(x_limit-textWidth+1, y, bitmap );
		// ##### end Gilbert 22/2 ########//
		break;
	
	default:
		err_here();
	}
}