~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/PCwin/draw.cpp

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /***************************************************************
  2 *                                                              *
  3 *        CERVIP Application    Ver. 1.1                        *
  4 *                                                              *
  5 *        Modified:                                             *
  6 *                 29 February 1996 Cs.Hegedues, PICTRON Ltd.   *
  7 *                 12 February 1996 Cs.Hegedues, PICTRON Ltd.   *
  8 *        Created:  1 February 1996, H.Bodrogi, PICTRON Ltd.    *
  9 *                                                              *
 10 *                Revised by F. Caparrelli, Sheffield 26.3.96   *
 11 *                                                              *
 12 ****************************************************************/
 13 
 14 
 15 #include <stdio.h>
 16 
 17 #include <dibapi.h>
 18 
 19 #ifdef __cplusplus
 20 extern "C" {
 21 #endif
 22 #include <tina/sys.h>
 23 #include <tina/sysfuncs.h>
 24 #include <tina/math.h>
 25 #include <tina/tv.h>
 26 #include <tina/tv_screen.h>
 27 #ifdef __cplusplus
 28 }
 29 #endif
 30 
 31 extern void (*screen_text) (char *);
 32 #define Print(x)  if(screen_text!=NULL) screen_text(x)
 33 
 34 
 35 ///////////////////////////////////////////////////////////////////////
 36 // GROUP1: creating/closing/deleting metafile
 37 // In 'tv_screen->Tv' structure, the following variables
 38 // play role:
 39 //   HDC hDC: device context ('lives' only during the creation)
 40 //   HMETAFILE hmf: handle of ready (closed) metafile - can be drawn
 41 //   HPEN hOldPen: Pen at starting metafile
 42 //   HBRUSH hOldBrush: Brush at starting metafile
 43 //   int OldROP2:  ROP2 raster operation code at starting metafile
 44 //   LOGPEN AtualPen: actual Pen
 45 //   LOGBRUSH ActualBrush: actual Brush
 46 //   int ActualROP2:  actual ROP2 raster operation code
 47 //
 48 ///////////////////////////////////////////////////////////////////////
 49 
 50 
 51 
 52 ////////////////////////////////////////////////
 53 // delete the metafile
 54 
 55 extern "C" void tv_screen_delete(Tv_screen *tv_screen)
 56 {
 57         if (tv_screen->hDC!=0)  // close if under construction
 58         {
 59                 tv_screen->hmf=CloseMetaFile(tv_screen->hDC);
 60                 tv_screen->hDC=0;
 61         }
 62 
 63         if (tv_screen->hmf!=0)
 64         {
 65                 DeleteMetaFile(tv_screen->hmf);
 66                 tv_screen->hmf=0; // clear the handle
 67         }
 68 }
 69 
 70 
 71 //////////////////////////////////////////////////////////////////////
 72 // start building a new metafile object
 73 // REM.: if previous one does exist, it will be destroyed!
 74 // If success, 'tv_screen->hDC' contains the handle
 75 //    of metafile's device context; 'tv_screen->hmf'
 76 //    gets value only after closing the metafile with
 77 //    the 'tv_screen_ready' command.
 78 //    The module saves the actual drawing settings (pen features,
 79 //    brush, ROP code) for using them at closing.
 80 
 81 extern "C" void tv_screen_new(Tv_screen *tv_screen)
 82 {
 83         if (tv_screen->hmf!=0)
 84                 tv_screen_delete(tv_screen); // destroy the previous metafile
 85         tv_screen->hDC=CreateMetaFile(NULL);    // create device context
 86 
 87                 // ROP2
 88         tv_screen->OldROP2=GetROP2(tv_screen->hDC);
 89                 tv_screen->ActualROP2=tv_screen->OldROP2;
 90 
 91                 // brush
 92                 LOGBRUSH lb;
 93                 lb.lbStyle=BS_NULL;
 94                 lb.lbColor=DIB_RGB_COLORS;
 95                 lb.lbHatch=HS_CROSS;
 96         HBRUSH hDummyBrush=CreateBrushIndirect(&lb);
 97         tv_screen->hOldBrush= (HBRUSH)
 98                 SelectObject(tv_screen->hDC, hDummyBrush);
 99                 GetObject(tv_screen->hOldBrush,
100                  sizeof(tv_screen->ActualBrush), &tv_screen->ActualBrush);
101         SelectObject(tv_screen->hDC, tv_screen->hOldBrush);
102                 DeleteObject(hDummyBrush);
103 
104                 // pen
105                 HPEN hDummyPen=CreatePen(PS_SOLID,0,RGB(255,255,255));
106         tv_screen->hOldPen=
107                 (HPEN)SelectObject(tv_screen->hDC, hDummyPen);
108         GetObject(tv_screen->hOldPen,
109                         sizeof(tv_screen->ActualPen), &tv_screen->ActualPen);
110                 SelectObject(tv_screen->hDC, tv_screen->hOldPen);
111                 DeleteObject(hDummyPen);
112 }
113 
114 ////////////////////////////////////////////////////////
115 // close the metafile
116 // REM.: 1.The 'tv_screen->hmf' metafile handle can be used from this
117 //         point to visualise or print the content of metafile,
118 //         'tv_screen->hDC' is cleared, because the metafile is ready.
119 //       2. The module restores the original Pen, Brush and ROP2 mode,
120 //         independently from their usage during the metafile creation.
121 
122 extern "C" void tv_screen_ready(Tv_screen *tv_screen)
123 {
124         SetROP2(tv_screen->hDC, tv_screen->OldROP2);
125         SelectObject(tv_screen->hDC, tv_screen->hOldBrush);
126         SelectObject(tv_screen->hDC, tv_screen->hOldPen);
127         tv_screen->hmf=CloseMetaFile(tv_screen->hDC);
128         tv_screen->hDC=0;
129 }
130 
131 
132 
133 ///////////////////////////////////////////////////////////////////////
134 // GROUP2: miscellaneous drawing functions
135 // The following variables of 'tv_screen->Tv' play role:
136 //   nZoom: zooming factor (multiplied by 1000)
137 //       width: width of area to be erased
138 //       height: height of area to be erased
139 //
140 ///////////////////////////////////////////////////////////////////////
141 
142 extern "C" void tv_screen_flush(Tv_screen *tv_screen)
143 {
144                 if (tv_screen->hmf==0) return;
145 
146                 CScrollView* pView = (CScrollView*) tv_screen->windowsView;  // fbc, 25.3.96
147                 CDocument* pDoc = pView->GetDocument();
148                 CSize DocSize;
149                 DocSize.cx=tv_screen->docwidth;
150                 DocSize.cy=tv_screen->docheight;
151                 CPoint ScrollPos = pView->GetScrollPosition();
152                 CDC* pDC = pView->GetDC();
153 
154                 int nOldMapMode=pDC->SetMapMode(MM_ISOTROPIC);
155                 pDC->SetWindowExt(DocSize.cx, DocSize.cy);
156                 DocSize.cx=(int)(((long)tv_screen->nZoom*(long)DocSize.cx)/1000);
157                 DocSize.cy=(int)(((long)tv_screen->nZoom*(long)DocSize.cy)/1000);
158                 pDC->SetViewportExt(DocSize.cx, DocSize.cy);
159                 pDC->SetViewportOrg(-ScrollPos.x, -ScrollPos.y);
160                 PlayMetaFile(pDC->m_hDC, (HMETAFILE)tv_screen->hmf);
161                 pDC->SetMapMode(nOldMapMode);
162 }
163 
164 
165 extern "C" void tv_screen_erase(Tv_screen * tv_screen)
166 {
167         Rectangle(tv_screen->hDC,0,0,tv_screen->width,tv_screen->height);
168 }
169 
170 
171 ///////////////////////////////////////////////////////////////////////
172 // GROUP3: set new pen-features, brush and raster operation code
173 // REM.: the modules do store the last  settings in the 'tv_screen->Tv';
174 //       the user can ask for them by the 'tv_screen_get...' modules
175 //
176 ///////////////////////////////////////////////////////////////////////
177 
178 // Set new pen features (together the style, width and colour params)
179 extern "C" void tv_screen_pen(Tv_screen *tv_screen, HPEN pen)
180 {
181             SelectObject(tv_screen->hDC, pen);
182 
183                 // save
184                 GetObject(pen, sizeof(tv_screen->ActualPen),
185                         &tv_screen->ActualPen);
186 }
187 
188 // Set new pen style
189 extern "C" void tv_screen_penstyle(Tv_screen *tv_screen, int nStyle)
190 {
191                 tv_screen->ActualPen.lopnStyle= nStyle;
192                 HPEN hPen=CreatePenIndirect(&tv_screen->ActualPen);
193                 SelectObject(tv_screen->hDC, hPen);
194                 DeleteObject(hPen);
195 }
196 
197 // Set new pen width
198 // REM.: if nWidth==0, the width of drawings is always 1
199 extern "C" void tv_screen_penwidth(Tv_screen *tv_screen, int nWidth)
200 {
201                 POINT pWidth;
202                 pWidth.x=nWidth;
203                 tv_screen->ActualPen.lopnWidth= pWidth;
204                 HPEN hPen=CreatePenIndirect(&tv_screen->ActualPen);
205                 SelectObject(tv_screen->hDC, hPen);
206                 DeleteObject(hPen);
207 }
208 
209 // Set new pen colour
210 extern "C" void tv_screen_pencolour(Tv_screen *tv_screen, COLORREF 
211 crColor)
212 {
213                 tv_screen->ActualPen.lopnColor= crColor;
214                 HPEN hPen=CreatePenIndirect(&tv_screen->ActualPen);
215                 SelectObject(tv_screen->hDC, hPen);
216                 DeleteObject(hPen);
217 }
218 
219 // Set new brush
220 extern "C" void tv_screen_brush(Tv_screen *tv_screen, HBRUSH brush)
221 {
222                 SelectObject(tv_screen->hDC, brush);
223 
224                 // save
225                 LOGBRUSH lb;
226                 GetObject(brush, sizeof(lb), &lb);
227                 tv_screen->ActualBrush.lbStyle= lb.lbStyle;
228                 tv_screen->ActualBrush.lbColor= lb.lbColor;
229                 tv_screen->ActualBrush.lbHatch= lb.lbHatch;
230 }
231 
232 // Set new ROP2 raster op. code
233 extern "C" void tv_screen_ROP2(Tv_screen *tv_screen, int fnDrawMode)
234 {
235                 SetROP2(tv_screen->hDC, fnDrawMode);
236 
237                 // save
238                 tv_screen->ActualROP2= fnDrawMode;
239 }
240 
241 
242 ///////////////////////////////////////////////////////////////////////
243 // GROUP4: get the actual pen-features, brush and raster operation code
244 //
245 ///////////////////////////////////////////////////////////////////////
246 
247 // Get the actual pen features (style, width and colour params)
248 extern "C" LOGPEN tv_screen_getpen(Tv_screen *tv_screen)
249 {
250                 return tv_screen->ActualPen;
251 }
252 
253 // Get the actual pen style
254 extern "C" int tv_screen_getpenstyle(Tv_screen *tv_screen)
255 {
256                 return tv_screen->ActualPen.lopnStyle;
257 }
258 
259 // Get the actual pen width
260 extern "C" int tv_screen_getpenwidth(Tv_screen *tv_screen)
261 {
262                 return tv_screen->ActualPen.lopnWidth.x;
263 }
264 
265 // Get the actual pen colour
266 extern "C" COLORREF tv_screen_getpencolour(Tv_screen *tv_screen)
267 {
268                 return tv_screen->ActualPen.lopnColor;
269 }
270 
271 // Get the actual brush
272 extern "C" LOGBRUSH tv_screen_getbrush(Tv_screen *tv_screen)
273 {
274                 return tv_screen->ActualBrush;
275 }
276 
277 // Get the actual ROP2 raster operation code
278 extern "C" int tv_screen_getROP2(Tv_screen *tv_screen)
279 {
280                 return tv_screen->ActualROP2;
281 }
282 
283 
284 ///////////////////////////////////////////////////////////////////////
285 // GROUP5: draw point, line, polygon, rect etc.
286 // 
287 ///////////////////////////////////////////////////////////////////////
288 
289 //////////////////////////////////////////////////////////////
290 // draw a point in 'pos' with actual colour
291 
292 extern "C" void tv_screen_point(Tv_screen *tv_screen, Ipos pos)
293 {
294         MoveToEx(tv_screen->hDC, pos.x, pos.y+1, NULL);
295         //REM.:  first position does not appear on screen!!!
296         LineTo(tv_screen->hDC, pos.x, pos.y);
297 }
298 
299 
300 extern "C" void tv_screen_dot(Tv_screen * tv_screen, Ipos pos)
301 {
302     if (tv_screen == NULL)
303         return;
304     Print("tv_screen_dot?");                                    
305 }
306 
307 
308 ////////////////////////////////////////////////////////////////
309 // draw a straight line segment with the actual colour and width
310 // between 'pos1' and 'pos2' positions
311 
312 extern "C" void tv_screen_line(Tv_screen *tv_screen, Ipos pos1, Ipos pos2)
313 {
314         MoveToEx(tv_screen->hDC, pos1.x, pos1.y, NULL);
315     LineTo(tv_screen->hDC, pos2.x, pos2.y);
316 }
317 
318 
319 ///////////////////////////////////////////////////////////////
320 // Draw polyline with the actual style, colour and width,
321 // according to the points, listed in 'points'
322 
323 extern "C" void tv_screen_polyline(Tv_screen *tv_screen, List *points)
324 {
325         if (tv_screen == NULL)  return;
326 
327         int i;
328         List *ptr;
329         Ipos pos = {Ipos_id};
330         
331         // work out number of points
332         int n = list_length(points);
333 
334         // allocate memory for the array
335         POINT *pPoints = (LPPOINT) malloc(n * sizeof(POINT));      
336         
337         // transform the list into an array
338         for (ptr = points, i = 0; ptr; ptr = ptr->next, ++i)
339         {                                                 
340                 pos = *((Ipos *) ptr->to);
341                 pPoints[i].x = pos.x;
342                 pPoints[i].y = pos.y;
343         }
344 
345         int iOldPolyFillMode = SetPolyFillMode(tv_screen->hDC, WINDING);
346         Polygon(tv_screen->hDC, pPoints, n);
347         SetPolyFillMode(tv_screen->hDC, iOldPolyFillMode);
348 
349         free((void*) pPoints);
350 }
351 
352 
353 //////////////////////////////////////////////////////
354 // Draw circle with the actual style, colour and width,
355 // according to 'centre' and 'radius' parameters
356 
357 extern "C" void tv_screen_circle(Tv_screen *tv_screen, Ipos centre, int 
358 radius)
359 {
360         int  aspx, aspy;
361 
362     aspx=GetDeviceCaps(tv_screen->hDC,ASPECTX);
363     aspy=GetDeviceCaps(tv_screen->hDC,ASPECTY);
364     Arc(tv_screen->hDC, centre.x-radius, centre.y-radius,
365                         centre.x+radius, centre.y+radius,
366                         centre.x, centre.y-radius,
367                         centre.x, centre.y-radius);
368 }
369 
370 
371 /////////////////////////////////////////////////////////////
372 // Draw (empty) rect with the actual style, colour and width,
373 // according to 'pos1' and 'pos2' positions
374 
375 extern "C" void tv_screen_rect(Tv_screen *tv_screen, Ipos pos1, Ipos pos2)
376 {
377         MoveToEx(tv_screen->hDC, pos1.x, pos1.y, NULL);
378         LineTo(tv_screen->hDC, pos2.x, pos1.y);
379         LineTo(tv_screen->hDC, pos2.x, pos2.y);
380         LineTo(tv_screen->hDC, pos1.x, pos2.y);
381         LineTo(tv_screen->hDC, pos1.x, pos1.y);
382 }
383 
384 
385 //////////////////////////////////////////////////////////////
386 // Draw (filled) rect with the actual style, colour and width,
387 // according to 'pos1' and 'pos2' positions
388 
389 extern "C" void tv_screen_fillrect(Tv_screen *tv_screen, Ipos pos1, Ipos 
390 pos2)
391 {
392         Rectangle(tv_screen->hDC, pos1.x, pos1.y, pos2.x, pos2.y);
393 }
394 
395 
396 ///////////////////////////////////////////////////////////////////////
397 // GROUP6: drawing text
398 // REM.: there is no reason to save/restore the BkMode, because it
399 //       plays role only at drawing text
400 // 
401 ///////////////////////////////////////////////////////////////////////
402 
403 extern "C" void tv_screen_text(Tv_screen *tv_screen, char *text, Ipos pos)
404 {
405         int OldBkMode= SetBkMode(tv_screen->hDC, TRANSPARENT);
406 
407         COLORREF OldTextColor = SetTextColor(tv_screen->hDC, tv_screen->textColor);
408     TextOut(tv_screen->hDC, pos.x, pos.y, text, lstrlen(text));
409         SetTextColor(tv_screen->hDC, OldTextColor);
410         SetBkMode(tv_screen->hDC, OldBkMode);
411 }
412 
413 
414 ///////////////////////////////////////////////////////////////////////
415 // GROUP7: drawing image
416 // The following variables of 'tv_screen->Tv' play role:
417 // 
418 ///////////////////////////////////////////////////////////////////////
419 
420 extern "C" void tv_screen_raster(Tv_screen * tv_screen, int x1, int x2, 
421 int y, char *raster)
422 {
423     if (tv_screen == NULL)
424         return;
425     Print("tv_screen_raster?");
426 }
427 
428 
429 extern "C" void tv_screen_image(Tv_screen *tv_screen, int, int, int, int, 
430 char*)
431 {
432         CPalette* pPal = (CPalette*) tv_screen->palette;  // fbc, 25.3.96
433 
434         CRect rcDIB;
435     rcDIB.top = rcDIB.left = 0;
436     rcDIB.right = tv_screen->DIBwidth;
437     rcDIB.bottom = tv_screen->DIBheight;
438    
439     CRect rcDest;
440         rcDest.top = tv_screen->DIBtop;
441         rcDest.left = tv_screen->DIBleft;
442         rcDest.right = tv_screen->DIBright;
443         rcDest.bottom = tv_screen->DIBbottom;
444 
445         ::PaintDIB(tv_screen->hDC, &rcDest, (HDIB)tv_screen->hDIB, &rcDIB, pPal);
446 }
447 
448 
449 extern "C" void tv_screen_show_picture(Tv_screen * tv_screen, 
450 Tv_picture * picture)
451 {
452     if (tv_screen == NULL)
453         return;
454     Print("tv_screen_show_picture?");
455 }
456 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.