graphics.c 12.4 KB
Newer Older
Patrik Stridvall's avatar
Patrik Stridvall committed
1 2 3 4
/*
 * TTY DC graphics
 *
 * Copyright 1999 Patrik Stridvall
5 6 7 8 9 10 11 12 13 14 15 16 17 18
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
Patrik Stridvall's avatar
Patrik Stridvall committed
19 20 21 22
 */

#include "config.h"

23
#include "winnls.h"
24
#include "gdi.h"
25
#include "wine/debug.h"
Patrik Stridvall's avatar
Patrik Stridvall committed
26 27
#include "ttydrv.h"

28
WINE_DEFAULT_DEBUG_CHANNEL(ttydrv);
Patrik Stridvall's avatar
Patrik Stridvall committed
29 30 31 32

/***********************************************************************
 *		TTYDRV_DC_Arc
 */
33
BOOL TTYDRV_DC_Arc(TTYDRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom,
Patrik Stridvall's avatar
Patrik Stridvall committed
34 35
		   INT xstart, INT ystart, INT xend, INT yend)
{
36 37
  FIXME("(%x, %d, %d, %d, %d, %d, %d, %d, %d): stub\n",
        physDev->hdc, left, top, right, bottom, xstart, ystart, xend, yend);
Patrik Stridvall's avatar
Patrik Stridvall committed
38 39 40 41 42 43
  return TRUE;
}

/***********************************************************************
 *		TTYDRV_DC_Chord
 */
44
BOOL TTYDRV_DC_Chord(TTYDRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom,
Patrik Stridvall's avatar
Patrik Stridvall committed
45 46
		     INT xstart, INT ystart, INT xend, INT yend)
{
47 48
  FIXME("(%x, %d, %d, %d, %d, %d, %d, %d, %d): stub\n",
        physDev->hdc, left, top, right, bottom, xstart, ystart, xend, yend);
Patrik Stridvall's avatar
Patrik Stridvall committed
49 50 51 52 53 54
  return TRUE;
}

/***********************************************************************
 *		TTYDRV_DC_Ellipse
 */
55
BOOL TTYDRV_DC_Ellipse(TTYDRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom)
Patrik Stridvall's avatar
Patrik Stridvall committed
56
{
57
  FIXME("(%x, %d, %d, %d, %d): stub\n", physDev->hdc, left, top, right, bottom);
Patrik Stridvall's avatar
Patrik Stridvall committed
58 59 60 61 62 63
  return TRUE;
}

/***********************************************************************
 *		TTYDRV_DC_ExtFloodFill
 */
64
BOOL TTYDRV_DC_ExtFloodFill(TTYDRV_PDEVICE *physDev, INT x, INT y,
Patrik Stridvall's avatar
Patrik Stridvall committed
65 66
			    COLORREF color, UINT fillType)
{
67
  FIXME("(%x, %d, %d, 0x%08lx, %u): stub\n", physDev->hdc, x, y, color, fillType);
Patrik Stridvall's avatar
Patrik Stridvall committed
68 69 70 71 72 73
  return TRUE;
}

/***********************************************************************
 *		TTYDRV_DC_GetPixel
 */
74
COLORREF TTYDRV_DC_GetPixel(TTYDRV_PDEVICE *physDev, INT x, INT y)
Patrik Stridvall's avatar
Patrik Stridvall committed
75
{
76
  FIXME("(%x, %d, %d): stub\n", physDev->hdc, x, y);
Patrik Stridvall's avatar
Patrik Stridvall committed
77 78 79 80 81 82
  return RGB(0,0,0); /* FIXME: Always returns black */
}

/***********************************************************************
 *		TTYDRV_DC_LineTo
 */
83
BOOL TTYDRV_DC_LineTo(TTYDRV_PDEVICE *physDev, INT x, INT y)
Patrik Stridvall's avatar
Patrik Stridvall committed
84
{
85
#ifdef WINE_CURSES
Patrik Stridvall's avatar
Patrik Stridvall committed
86
  INT row1, col1, row2, col2;
87
  DC *dc = physDev->dc;
Patrik Stridvall's avatar
Patrik Stridvall committed
88

89
  TRACE("(%x, %d, %d)\n", physDev->hdc, x, y);
Patrik Stridvall's avatar
Patrik Stridvall committed
90

91 92 93
  if(!physDev->window)
    return FALSE;

94 95 96 97
  row1 = (dc->DCOrgY + XLPTODP(dc, dc->CursPosY)) / physDev->cellHeight;
  col1 = (dc->DCOrgX + XLPTODP(dc, dc->CursPosX)) / physDev->cellWidth;
  row2 = (dc->DCOrgY + XLPTODP(dc, y)) / physDev->cellHeight;
  col2 = (dc->DCOrgX + XLPTODP(dc, x)) / physDev->cellWidth;
Patrik Stridvall's avatar
Patrik Stridvall committed
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112

  if(row1 > row2) {
    INT tmp = row1;
    row1 = row2;
    row2 = tmp; 
  } 

  if(col1 > col2) {
    INT tmp = col1;
    col1 = col2;
    col2 = tmp; 
  } 

  wmove(physDev->window, row1, col1);
  if(col1 == col2) {
113
    wvline(physDev->window, ACS_VLINE, row2-row1);
Patrik Stridvall's avatar
Patrik Stridvall committed
114
  } else if(row1 == row2) {
115
    whline(physDev->window, ACS_HLINE, col2-col1);
Patrik Stridvall's avatar
Patrik Stridvall committed
116 117 118 119 120 121
  } else {
    FIXME("Diagonal line drawing not yet supported\n");
  }
  wrefresh(physDev->window);

  return TRUE;
122
#else /* defined(WINE_CURSES) */
123
  FIXME("(%x, %d, %d): stub\n", physDev->hdc, x, y);
Patrik Stridvall's avatar
Patrik Stridvall committed
124 125

  return TRUE;
126
#endif /* defined(WINE_CURSES) */
Patrik Stridvall's avatar
Patrik Stridvall committed
127 128 129 130 131
}

/***********************************************************************
 *		TTYDRV_DC_PaintRgn
 */
132
BOOL TTYDRV_DC_PaintRgn(TTYDRV_PDEVICE *physDev, HRGN hrgn)
Patrik Stridvall's avatar
Patrik Stridvall committed
133
{
134
  FIXME("(%x, 0x%04x): stub\n", physDev->hdc, hrgn);
Patrik Stridvall's avatar
Patrik Stridvall committed
135 136 137 138 139 140
  return TRUE;
}

/***********************************************************************
 *		TTYDRV_DC_Pie
 */
141
BOOL TTYDRV_DC_Pie(TTYDRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom,
Patrik Stridvall's avatar
Patrik Stridvall committed
142 143
		   INT xstart, INT ystart, INT xend, INT yend)
{
144 145
  FIXME("(%x, %d, %d, %d, %d, %d, %d, %d, %d): stub\n",
	physDev->hdc, left, top, right, bottom, xstart, ystart, xend, yend);
Patrik Stridvall's avatar
Patrik Stridvall committed
146 147 148 149 150 151
  return TRUE;
}

/***********************************************************************
 *		TTYDRV_DC_Polygon
 */
152
BOOL TTYDRV_DC_Polygon(TTYDRV_PDEVICE *physDev, const POINT* pt, INT count)
Patrik Stridvall's avatar
Patrik Stridvall committed
153
{
154
  FIXME("(%x, %p, %d): stub\n", physDev->hdc, pt, count);
Patrik Stridvall's avatar
Patrik Stridvall committed
155 156 157 158 159 160
  return TRUE;
}

/***********************************************************************
 *		TTYDRV_DC_Polyline
 */
161
BOOL TTYDRV_DC_Polyline(TTYDRV_PDEVICE *physDev, const POINT* pt, INT count)
Patrik Stridvall's avatar
Patrik Stridvall committed
162
{
163
  FIXME("(%x, %p, %d): stub\n", physDev->hdc, pt, count);
Patrik Stridvall's avatar
Patrik Stridvall committed
164 165 166 167 168 169
  return TRUE;
}

/***********************************************************************
 *		TTYDRV_DC_PolyPolygon
 */
170
BOOL TTYDRV_DC_PolyPolygon(TTYDRV_PDEVICE *physDev, const POINT* pt, const INT* counts, UINT polygons)
Patrik Stridvall's avatar
Patrik Stridvall committed
171
{
172
  FIXME("(%x, %p, %p, %u): stub\n", physDev->hdc, pt, counts, polygons);
Patrik Stridvall's avatar
Patrik Stridvall committed
173 174 175 176 177 178
  return TRUE;
}

/***********************************************************************
 *		TTYDRV_DC_PolyPolyline
 */
179
BOOL TTYDRV_DC_PolyPolyline(TTYDRV_PDEVICE *physDev, const POINT* pt, const DWORD* counts, DWORD polylines)
Patrik Stridvall's avatar
Patrik Stridvall committed
180
{
181
  FIXME("(%x, %p, %p, %lu): stub\n", physDev->hdc, pt, counts, polylines);
Patrik Stridvall's avatar
Patrik Stridvall committed
182 183 184 185 186 187 188
  
  return TRUE;
}

/***********************************************************************
 *		TTYDRV_DC_Rectangle
 */
189
BOOL TTYDRV_DC_Rectangle(TTYDRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom)
Patrik Stridvall's avatar
Patrik Stridvall committed
190
{
191
#ifdef WINE_CURSES
Patrik Stridvall's avatar
Patrik Stridvall committed
192
  INT row1, col1, row2, col2;
193
  DC *dc = physDev->dc;
Patrik Stridvall's avatar
Patrik Stridvall committed
194

195
  TRACE("(%x, %d, %d, %d, %d)\n", physDev->hdc, left, top, right, bottom);
Patrik Stridvall's avatar
Patrik Stridvall committed
196

197 198 199
  if(!physDev->window)
    return FALSE;

200 201 202 203
  row1 = (dc->DCOrgY + XLPTODP(dc, top)) / physDev->cellHeight;
  col1 = (dc->DCOrgX + XLPTODP(dc, left)) / physDev->cellWidth;
  row2 = (dc->DCOrgY + XLPTODP(dc, bottom)) / physDev->cellHeight;
  col2 = (dc->DCOrgX + XLPTODP(dc, right)) / physDev->cellWidth;
Patrik Stridvall's avatar
Patrik Stridvall committed
204 205 206 207 208 209 210 211 212 213 214 215 216

  if(row1 > row2) {
    INT tmp = row1;
    row1 = row2;
    row2 = tmp; 
  } 
  if(col1 > col2) {
    INT tmp = col1;
    col1 = col2;
    col2 = tmp; 
  } 

  wmove(physDev->window, row1, col1);
217
  whline(physDev->window, ACS_HLINE, col2-col1);
Patrik Stridvall's avatar
Patrik Stridvall committed
218 219

  wmove(physDev->window, row1, col2);
220
  wvline(physDev->window, ACS_VLINE, row2-row1);
Patrik Stridvall's avatar
Patrik Stridvall committed
221 222

  wmove(physDev->window, row2, col1);
223
  whline(physDev->window, ACS_HLINE, col2-col1);
Patrik Stridvall's avatar
Patrik Stridvall committed
224 225

  wmove(physDev->window, row1, col1);
226
  wvline(physDev->window, ACS_VLINE, row2-row1);
Patrik Stridvall's avatar
Patrik Stridvall committed
227

228 229 230 231
  mvwaddch(physDev->window, row1, col1, ACS_ULCORNER);
  mvwaddch(physDev->window, row1, col2, ACS_URCORNER);
  mvwaddch(physDev->window, row2, col2, ACS_LRCORNER);
  mvwaddch(physDev->window, row2, col1, ACS_LLCORNER);
Patrik Stridvall's avatar
Patrik Stridvall committed
232 233 234 235

  wrefresh(physDev->window);

  return TRUE;
236
#else /* defined(WINE_CURSES) */
237
  FIXME("(%x, %d, %d, %d, %d): stub\n", physDev->hdc, left, top, right, bottom);
Patrik Stridvall's avatar
Patrik Stridvall committed
238 239

  return TRUE;
240
#endif /* defined(WINE_CURSES) */
Patrik Stridvall's avatar
Patrik Stridvall committed
241 242 243 244 245
}

/***********************************************************************
 *		TTYDRV_DC_RoundRect
 */
246
BOOL TTYDRV_DC_RoundRect(TTYDRV_PDEVICE *physDev, INT left, INT top, INT right,
Patrik Stridvall's avatar
Patrik Stridvall committed
247 248
			 INT bottom, INT ell_width, INT ell_height)
{
249 250
  FIXME("(%x, %d, %d, %d, %d, %d, %d): stub\n", 
	physDev->hdc, left, top, right, bottom, ell_width, ell_height);
Patrik Stridvall's avatar
Patrik Stridvall committed
251 252 253 254 255 256 257
  
  return TRUE;
}

/***********************************************************************
 *		TTYDRV_DC_SetPixel
 */
258
COLORREF TTYDRV_DC_SetPixel(TTYDRV_PDEVICE *physDev, INT x, INT y, COLORREF color)
Patrik Stridvall's avatar
Patrik Stridvall committed
259
{
260
#ifdef WINE_CURSES
Patrik Stridvall's avatar
Patrik Stridvall committed
261
  INT row, col;
262
  DC *dc = physDev->dc;
Patrik Stridvall's avatar
Patrik Stridvall committed
263

264
  TRACE("(%x, %d, %d, 0x%08lx)\n", physDev->hdc, x, y, color);
Patrik Stridvall's avatar
Patrik Stridvall committed
265

266 267 268
  if(!physDev->window)
    return FALSE;

269 270
  row = (dc->DCOrgY + XLPTODP(dc, y)) / physDev->cellHeight;
  col = (dc->DCOrgX + XLPTODP(dc, x)) / physDev->cellWidth;
Patrik Stridvall's avatar
Patrik Stridvall committed
271

272
  mvwaddch(physDev->window, row, col, ACS_BULLET);
Patrik Stridvall's avatar
Patrik Stridvall committed
273 274 275
  wrefresh(physDev->window);

  return RGB(0,0,0); /* FIXME: Always returns black */
276
#else /* defined(WINE_CURSES) */
277
  FIXME("(%x, %d, %d, 0x%08lx): stub\n", physDev->hdc, x, y, color);
Patrik Stridvall's avatar
Patrik Stridvall committed
278 279

  return RGB(0,0,0); /* FIXME: Always returns black */
280
#endif /* defined(WINE_CURSES) */
Patrik Stridvall's avatar
Patrik Stridvall committed
281 282
}

283 284 285
/***********************************************************************
 *		TTYDRV_DC_BitBlt
 */
286 287
BOOL TTYDRV_DC_BitBlt(TTYDRV_PDEVICE *physDevDst, INT xDst, INT yDst,
		      INT width, INT height, TTYDRV_PDEVICE *physDevSrc,
288 289
		      INT xSrc, INT ySrc, DWORD rop)
{
290 291
  FIXME("(%x, %d, %d, %d, %d, %x, %d, %d, %lu): stub\n",
        physDevDst->hdc, xDst, yDst, width, height, physDevSrc->hdc, xSrc, ySrc, rop );
292 293 294 295 296 297
  return TRUE;
}

/***********************************************************************
 *		TTYDRV_DC_PatBlt
 */
298
BOOL TTYDRV_DC_PatBlt(TTYDRV_PDEVICE *physDev, INT left, INT top,
299 300
		      INT width, INT height, DWORD rop)
{
301
  FIXME("(%x, %d, %d, %d, %d, %lu): stub\n", physDev->hdc, left, top, width, height, rop );
302 303 304 305 306 307
  return TRUE;
}

/***********************************************************************
 *		TTYDRV_DC_StretchBlt
 */
308
BOOL TTYDRV_DC_StretchBlt(TTYDRV_PDEVICE *physDevDst, INT xDst, INT yDst,
309
			  INT widthDst, INT heightDst,
310
			  TTYDRV_PDEVICE *physDevSrc, INT xSrc, INT ySrc,
311 312
			  INT widthSrc, INT heightSrc, DWORD rop)
{
313 314 315
  FIXME("(%x, %d, %d, %d, %d, %x, %d, %d, %d, %d, %lu): stub\n",
        physDevDst->hdc, xDst, yDst, widthDst, heightDst,
        physDevSrc->hdc, xSrc, ySrc, widthSrc, heightSrc, rop );
316 317 318 319 320 321 322

  return TRUE;
}

/***********************************************************************
 *		TTYDRV_DC_ExtTextOut
 */
323
BOOL TTYDRV_DC_ExtTextOut(TTYDRV_PDEVICE *physDev, INT x, INT y, UINT flags,
324 325 326 327 328 329
			  const RECT *lpRect, LPCWSTR str, UINT count,
			  const INT *lpDx)
{
#ifdef WINE_CURSES
  INT row, col;
  LPSTR ascii;
330
  DWORD len;
331
  DC *dc = physDev->dc;
332

333 334
  TRACE("(%x, %d, %d, 0x%08x, %p, %s, %d, %p)\n",
        physDev->hdc, x, y, flags, lpRect, debugstr_wn(str, count), count, lpDx);
335 336 337 338 339

  if(!physDev->window)
    return FALSE;

  /* FIXME: Is this really correct? */
340 341 342
  if(dc->textAlign & TA_UPDATECP) {
    x = dc->CursPosX;
    y = dc->CursPosY;
343 344 345 346 347
  }

  x = XLPTODP(dc, x);
  y = YLPTODP(dc, y);
  
348 349
  row = (dc->DCOrgY + y) / physDev->cellHeight;
  col = (dc->DCOrgX + x) / physDev->cellWidth;
350 351 352 353
  len = WideCharToMultiByte( CP_ACP, 0, str, count, NULL, 0, NULL, NULL );
  ascii = HeapAlloc( GetProcessHeap(), 0, len );
  WideCharToMultiByte( CP_ACP, 0, str, count, ascii, len, NULL, NULL );
  mvwaddnstr(physDev->window, row, col, ascii, len);
354 355 356
  HeapFree( GetProcessHeap(), 0, ascii );
  wrefresh(physDev->window);

357 358 359
  if(dc->textAlign & TA_UPDATECP) {
    dc->CursPosX += count * physDev->cellWidth;
    dc->CursPosY += physDev->cellHeight;
360 361 362 363
  }

  return TRUE;
#else /* defined(WINE_CURSES) */
364 365
  FIXME("(%x, %d, %d, 0x%08x, %p, %s, %d, %p): stub\n",
        physDev->hdc, x, y, flags, lpRect, debugstr_wn(str,count), count, lpDx);
366 367 368 369 370 371 372 373

  return TRUE;
#endif /* defined(WINE_CURSES) */
}

/***********************************************************************
 *		TTYDRV_DC_GetCharWidth
 */
374
BOOL TTYDRV_DC_GetCharWidth(TTYDRV_PDEVICE *physDev, UINT firstChar, UINT lastChar,
375 376 377 378
			    LPINT buffer)
{
  UINT c;

379
  FIXME("(%x, %u, %u, %p): semistub\n", physDev->hdc, firstChar, lastChar, buffer);
380 381 382 383 384 385 386 387 388 389 390

  for(c=firstChar; c<=lastChar; c++) {
    buffer[c-firstChar] = physDev->cellWidth;
  }

  return TRUE;
}

/***********************************************************************
 *		TTYDRV_DC_GetTextExtentPoint
 */
391
BOOL TTYDRV_DC_GetTextExtentPoint(TTYDRV_PDEVICE *physDev, LPCWSTR str, INT count,
392 393
				  LPSIZE size)
{
394
  TRACE("(%x, %s, %d, %p)\n", physDev->hdc, debugstr_wn(str, count), count, size);
395 396 397 398 399 400 401 402 403 404

  size->cx = count * physDev->cellWidth;
  size->cy = physDev->cellHeight;

  return TRUE;
}

/***********************************************************************
 *		TTYDRV_DC_GetTextMetrics
 */
405
BOOL TTYDRV_DC_GetTextMetrics(TTYDRV_PDEVICE *physDev, LPTEXTMETRICW lptm)
406
{
407
  TRACE("(%x, %p)\n", physDev->hdc, lptm);
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431

  lptm->tmHeight = physDev->cellHeight;
  lptm->tmAscent = 0;
  lptm->tmDescent = 0;
  lptm->tmInternalLeading = 0;
  lptm->tmExternalLeading = 0;
  lptm->tmAveCharWidth = physDev->cellWidth; 
  lptm->tmMaxCharWidth = physDev->cellWidth;
  lptm->tmWeight = FW_MEDIUM;
  lptm->tmOverhang = 0;
  lptm->tmDigitizedAspectX = physDev->cellWidth;
  lptm->tmDigitizedAspectY = physDev->cellHeight;
  lptm->tmFirstChar = 32;
  lptm->tmLastChar = 255;
  lptm->tmDefaultChar = 0;
  lptm->tmBreakChar = 32;
  lptm->tmItalic = FALSE;
  lptm->tmUnderlined = FALSE;
  lptm->tmStruckOut = FALSE;
  lptm->tmPitchAndFamily = TMPF_FIXED_PITCH|TMPF_DEVICE;
  lptm->tmCharSet = ANSI_CHARSET;

  return TRUE;
}