texteff.c
branch0.5
changeset 5477 db92b7f416d3
parent 5470 9fce095970bb
child 5481 acf12c0e6f31
equal deleted inserted replaced
5476:942979c13339 5477:db92b7f416d3
   118 
   118 
   119 // Hide the textbox
   119 // Hide the textbox
   120 void UndrawTextMessage(void)
   120 void UndrawTextMessage(void)
   121 {
   121 {
   122 	if (_textmessage_visible) {
   122 	if (_textmessage_visible) {
       
   123 		int x, y, width, height;
       
   124 
   123 		// Sometimes we also need to hide the cursor
   125 		// Sometimes we also need to hide the cursor
   124 		//   This is because both textmessage and the cursor take a shot of the
   126 		//   This is because both textmessage and the cursor take a shot of the
   125 		//   screen before drawing.
   127 		//   screen before drawing.
   126 		//   Now the textmessage takes his shot and paints his data before the cursor
   128 		//   Now the textmessage takes his shot and paints his data before the cursor
   127 		//   does, so in the shot of the cursor is the screen-data of the textmessage
   129 		//   does, so in the shot of the cursor is the screen-data of the textmessage
   137 				_cursor.draw_pos.y <= _screen.height - _textmsg_box.y) {
   139 				_cursor.draw_pos.y <= _screen.height - _textmsg_box.y) {
   138 				UndrawMouseCursor();
   140 				UndrawMouseCursor();
   139 			}
   141 			}
   140 		}
   142 		}
   141 
   143 
       
   144 		x      = _textmsg_box.x;
       
   145 		y      = _screen.height - _textmsg_box.y - _textmsg_box.height;
       
   146 		width  = _textmsg_box.width;
       
   147 		height = _textmsg_box.height;
       
   148 		if (y < 0) {
       
   149 			height = max(height + y, min(_textmsg_box.height, _screen.height));
       
   150 			y = 0;
       
   151 		}
       
   152 		if (x + width >= _screen.width) {
       
   153 			width = _screen.width - x;
       
   154 		}
       
   155 
   142 		_textmessage_visible = false;
   156 		_textmessage_visible = false;
   143 		// Put our 'shot' back to the screen
   157 		// Put our 'shot' back to the screen
   144 		memcpy_pitch(
   158 		memcpy_pitch(
   145 			_screen.dst_ptr + _textmsg_box.x + (_screen.height - _textmsg_box.y - _textmsg_box.height) * _screen.pitch,
   159 			_screen.dst_ptr + x + y * _screen.pitch,
   146 			_textmessage_backup,
   160 			_textmessage_backup,
   147 			_textmsg_box.width, _textmsg_box.height, _textmsg_box.width, _screen.pitch);
   161 			width, height, _textmsg_box.width, _screen.pitch);
   148 
   162 
   149 		// And make sure it is updated next time
   163 		// And make sure it is updated next time
   150 		_video_driver->make_dirty(_textmsg_box.x, _screen.height - _textmsg_box.y - _textmsg_box.height, _textmsg_box.width, _textmsg_box.height);
   164 		_video_driver->make_dirty(x, y, width, height);
   151 
   165 
   152 		_textmessage_dirty = true;
   166 		_textmessage_dirty = true;
   153 	}
   167 	}
   154 }
   168 }
   155 
   169 
   178 }
   192 }
   179 
   193 
   180 // Draw the textmessage-box
   194 // Draw the textmessage-box
   181 void DrawTextMessage(void)
   195 void DrawTextMessage(void)
   182 {
   196 {
   183 	uint y, count;
   197 	int x, y, width, height;
       
   198 	uint offset_y, count;
   184 
   199 
   185 	if (!_textmessage_dirty) return;
   200 	if (!_textmessage_dirty) return;
   186 
   201 
   187 	// First undraw if needed
   202 	// First undraw if needed
   188 	UndrawTextMessage();
   203 	UndrawTextMessage();
   191 
   206 
   192 	/* Check if we have anything to draw at all */
   207 	/* Check if we have anything to draw at all */
   193 	count = GetTextMessageCount();
   208 	count = GetTextMessageCount();
   194 	if (count == 0) return;
   209 	if (count == 0) return;
   195 
   210 
       
   211 	x      = _textmsg_box.x;
       
   212 	y      = _screen.height - _textmsg_box.y - _textmsg_box.height;
       
   213 	width  = _textmsg_box.width;
       
   214 	height = _textmsg_box.height;
       
   215 	if (y < 0) {
       
   216 		height = max(height + y, min(_textmsg_box.height, _screen.height));
       
   217 		y = 0;
       
   218 	}
       
   219 	if (x + width >= _screen.width) {
       
   220 		width = _screen.width - x;
       
   221 	}
   196 	// Make a copy of the screen as it is before painting (for undraw)
   222 	// Make a copy of the screen as it is before painting (for undraw)
   197 	memcpy_pitch(
   223 	memcpy_pitch(
   198 		_textmessage_backup,
   224 		_textmessage_backup,
   199 		_screen.dst_ptr + _textmsg_box.x + (_screen.height - _textmsg_box.y - _textmsg_box.height) * _screen.pitch,
   225 		_screen.dst_ptr + x + y * _screen.pitch,
   200 		_textmsg_box.width, _textmsg_box.height, _screen.pitch, _textmsg_box.width);
   226 		width, height, _screen.pitch, _textmsg_box.width);
   201 
   227 
   202 	_cur_dpi = &_screen; // switch to _screen painting
   228 	_cur_dpi = &_screen; // switch to _screen painting
   203 
   229 
   204 	/* Paint a half-transparent box behind the text messages */
   230 	/* Paint a half-transparent box behind the text messages */
   205 	GfxFillRect(
   231 	GfxFillRect(
   209 			_screen.height - _textmsg_box.y - 2,
   235 			_screen.height - _textmsg_box.y - 2,
   210 			0x322 | USE_COLORTABLE // black, but with some alpha for background
   236 			0x322 | USE_COLORTABLE // black, but with some alpha for background
   211 		);
   237 		);
   212 
   238 
   213 	/* Paint the messages starting with the lowest at the bottom */
   239 	/* Paint the messages starting with the lowest at the bottom */
   214 	for (y = 13; count-- != 0; y += 13) {
   240 	for (offset_y = 13; count-- != 0; offset_y += 13) {
   215 		DoDrawString(_textmsg_list[count].message, _textmsg_box.x + 3, _screen.height - _textmsg_box.y - y + 1, _textmsg_list[count].color);
   241 		DoDrawString(_textmsg_list[count].message, _textmsg_box.x + 3, _screen.height - _textmsg_box.y - offset_y + 1, _textmsg_list[count].color);
   216  	}
   242  	}
   217 
   243 
   218 	// Make sure the data is updated next flush
   244 	// Make sure the data is updated next flush
   219 	_video_driver->make_dirty(_textmsg_box.x, _screen.height - _textmsg_box.y - _textmsg_box.height, _textmsg_box.width, _textmsg_box.height);
   245 	_video_driver->make_dirty(x, y, width, height);
   220 
   246 
   221 	_textmessage_visible = true;
   247 	_textmessage_visible = true;
   222 	_textmessage_dirty = false;
   248 	_textmessage_dirty = false;
   223 }
   249 }
   224 
   250