2 // Qt Example Application: drawdemo
4 // Demonstrates the painter and the printer.
24 #include <netinet/in.h>
25 #include "../head/genint1.h"
26 #include "../head/comm.h"
44 #define REQUEST_NAME "gr.req"
54 VGRMap(int n,QPixmap *m) { number=n; map = m; };
60 class VGR : public QFrame
70 int fcol,bcol,gfcol,gbcol;
73 QQueue<int> CharBuffer;
75 bool string_wait, char_wait, line_wait, mouse_wait, inkey_wait, was_line;
77 QFont *prv_font, *italic_font, *bold_font, *normal_font;
81 void SetForeground(int);
82 void SetBackground(int);
84 void ClearArea(int,int,int,int);
86 void Line(int,int,int,int);
87 void Ellipse(int x,int y,int a, int b,int alfa, int beta, int fill);
88 void Rect(int x1, int y1, int x2, int y2,int col, int fill);
89 void Point(int x, int y);
90 void TextXY(int x, int y, char *s);
91 void CharXY(int x, int y, char a);
92 void IntXY(int x, int y, int val);
94 void WriteText(char *s);
95 void WriteChar(char a);
97 void PutChar(char a); /* Write Char w/o changing position */
100 void Outstring(int x, int y, char *s, int b, int f);
101 void writeintxy(int x, int y, int val,int c);
105 int Getmap(int w, int h);
106 void Putmap(int map);
108 void MagicGraph(G_MESSAGE*);
115 void RequestMessage();
118 virtual void resizeEvent( QResizeEvent * );
119 virtual void closeEvent(QCloseEvent *);
120 virtual void keyPressEvent(QKeyEvent *);
121 virtual void mousePressEvent(QMouseEvent *);
122 virtual void paintEvent(QPaintEvent *);
123 virtual void focusInEvent(QFocusEvent *);
126 QScrollBar *hscroll,*vscroll;
127 QPushButton *close_btn;
128 int ox,oy,lstep,pstep,gx,gy;
131 bool Closed, MustRepaint,GraphRead;
132 QSocketNotifier *request;
133 char internal_buffer[256];
141 void VGR::MakeColors()
143 lcolors[0] = new QColor(0, 0, 0 ); /* black */
144 lcolors[1] = new QColor(0, 0, 139); /* blue dark */
145 lcolors[2] = new QColor(0, 100, 0 ); /* green dark */
146 lcolors[3] = new QColor(0, 197, 205 ); /* turquoise dark */
147 lcolors[4] = new QColor(205,0 , 0 ); /* red dark */
148 lcolors[5] = new QColor(238, 130,238); /* violet */
149 lcolors[6] = new QColor(139,35,35 ); /* brown */
150 lcolors[7] = new QColor(190,190,190 ); /* grey light */
151 lcolors[8] = new QColor(97, 97, 97 ); /* grey dark */
152 lcolors[9] = new QColor(0, 0, 255 ); /* blue */
153 lcolors[10] = new QColor(0, 255, 0 ); /* green */
154 lcolors[11] = new QColor(0, 229,238 ); /* turquoise */
155 lcolors[12] = new QColor(255, 0, 0 ); /* red light */
156 lcolors[13] = new QColor(255, 110,180 ); /* rose */
157 lcolors[14] = new QColor(255,255, 0 ); /* yellow */
158 lcolors[15] = new QColor(255, 255, 255 ); /* white */
162 // Construct the DrawView with buttons.
165 VGR::VGR(char *sockname)
169 struct sockaddr_un svr;
174 normal_font = new QFont("lucidatypewriter",10,QFont::Normal);
175 normal_font->setFixedPitch(TRUE);
176 bold_font = new QFont("lucidatypewriter",10,QFont::Bold);
177 bold_font->setFixedPitch(TRUE);
178 italic_font = new QFont("lucidatypewriter",10,QFont::Normal,TRUE);
179 italic_font->setFixedPitch(TRUE);
181 prv_font = normal_font;
184 setCaption( "graphic resource" );
185 setBackgroundColor( white );
186 canvas = new QPixmap(640,480);
187 canvas->fill(backgroundColor());
192 maps.setAutoDelete(TRUE);
194 Closed = FALSE;GraphRead=FALSE;
196 hscroll = new QScrollBar(0,MAXWIDTH,lstep,pstep,0,QScrollBar::Horizontal,this);
197 vscroll = new QScrollBar(0,MAXHEIGHT,lstep,pstep,0,QScrollBar::Vertical,this);
198 hscroll->setTracking(TRUE);
199 vscroll->setTracking(TRUE);
202 hscroll->setGeometry(0,height()-16,width()-16,16);
203 vscroll->setGeometry(width()-16,0,16,height()-16);
205 connect(hscroll,SIGNAL(valueChanged(int)),this,SLOT(hscrolled(int)));
206 connect(vscroll,SIGNAL(valueChanged(int)),this,SLOT(vscrolled(int)));
208 close_btn = new QPushButton(this,"close");
210 if( mp.load("pics/close.bmp"))
211 close_btn->setPixmap(mp);
213 close_btn->setText("C");
214 close_btn->setGeometry(width()-16,height()-16,16,16);
215 close_btn->setEnabled(FALSE);
216 connect(close_btn,SIGNAL(clicked()),this,SLOT(CloseMe()));
221 resp_sock = socket(AF_UNIX,SOCK_STREAM,0);
222 bzero(&svr,sizeof(svr));
223 svr.sun_family = AF_UNIX;
224 strcpy(svr.sun_path,sockname);
225 len = strlen(svr.sun_path)+sizeof(svr.sun_family);
226 i = ::connect(resp_sock,(struct sockaddr*)&svr,len);
227 if (i==0) fcntl(resp_sock,F_SETFL,O_NONBLOCK|fcntl(resp_sock,F_GETFL,0));
229 setsockopt(resp_sock,IPPROTO_TCP,TCP_NODELAY,(char*)&on,sizeof(on));
230 request = new QSocketNotifier(resp_sock,QSocketNotifier::Read);
231 connect(request,SIGNAL(activated(int)),this,SLOT(RequestMessage()));
232 optval=TCP_BUFFER_SIZE;
233 // setsockopt(resp_sock,SOL_SOCKET,SO_SNDBUF,&optval,sizeof(optval));
234 // setsockopt(resp_sock,SOL_SOCKET,SO_RCVBUF,&optval,sizeof(optval));
236 inkey_wait = FALSE;string_wait = FALSE;
237 char_wait = FALSE;line_wait = FALSE;mouse_wait = FALSE;
240 CharBuffer.setAutoDelete(TRUE);
242 setFocusPolicy(QWidget::StrongFocus);
243 hscroll->setRange(0,MAXWIDTH-width()+20);
244 vscroll->setRange(0,MAXHEIGHT-height()+20);
245 hscroll->setSteps((int)(hscroll->width()/hscroll->maxValue()),(int)((hscroll->width()/hscroll->maxValue())*4));
246 vscroll->setSteps((int)(vscroll->height()/vscroll->maxValue()),(int)((vscroll->height()/vscroll->maxValue())*4));
248 setMaximumSize(MAXWIDTH+16,MAXHEIGHT+16);
249 setUpdatesEnabled(FALSE);
260 void VGR::paintEvent(QPaintEvent *p)
262 //if (isUpdatesEnabled())
264 bitBlt(this,0,0,canvas,ox,oy,width()-16,height()-16);
269 void VGR::focusInEvent(QFocusEvent *)
271 setUpdatesEnabled(TRUE);
273 setUpdatesEnabled(FALSE);
277 void VGR::resizeEvent( QResizeEvent *ev )
279 hscroll->setGeometry(0,height()-16,width()-16,16);
280 vscroll->setGeometry(width()-16,0,16,height()-16);
281 close_btn->setGeometry(width()-16,height()-16,16,16);
282 hscroll->setRange(0,MAXWIDTH-width()+20);
283 vscroll->setRange(0,MAXHEIGHT-height()+20);
285 hscroll->setSteps(lstep,pstep);
286 vscroll->setSteps(lstep,pstep);
289 void VGR::closeEvent(QCloseEvent *ev)
291 if (Closed) QFrame::closeEvent(ev);
294 void VGR::mousePressEvent(QMouseEvent *ev)
300 msg.msg_type = MSG_GRAPH;
301 msg.param.pword[0] = GRAPH_MGETPRESS_RESPONSE;
302 msg.param.pword[2] = ev->pos().x()-ox;
303 msg.param.pword[3] = ev->pos().y()-oy;
306 case LeftButton: msg.param.pword[7] = 1;
308 case RightButton: msg.param.pword[7] = 3;
310 case MidButton:msg.param.pword[7] = 2;
312 default:msg.param.pword[7] = 0;break;
314 write(resp_sock,&msg,sizeof(G_MESSAGE));
318 QFrame::mousePressEvent(ev);
322 bool VGR::GetInput(int t)
326 if (!CharBuffer.isEmpty())
332 msg.msg_type = MSG_GRAPH;
333 msg.param.pword[0] = GRAPH_INKEY_RESPONSE;
334 msg.param.pword[3] = *(CharBuffer.dequeue());
335 write(resp_sock,&msg,sizeof(G_MESSAGE));
345 msg.msg_type = MSG_GRAPH;
346 msg.param.pword[0] = GRAPH_MAGIC_RESPONSE;
347 msg.param.pword[1]=0;
348 msg.param.pchar =(char)(*(CharBuffer.dequeue()));
349 WriteChar(msg.param.pchar);
353 msg.msg_type = MSG_GRAPH;
354 msg.param.pword[0] = GRAPH_READCHAR_RESPONSE;
355 msg.param.pchar =(char)(*(CharBuffer.dequeue()));
358 write(resp_sock,&msg,sizeof(G_MESSAGE));
366 while ( ((!CharBuffer.isEmpty()) && (!(*(CharBuffer.dequeue())=13))));
367 if (!CharBuffer.isEmpty())
369 msg.msg_type = MSG_GRAPH;
370 msg.param.pword[0] = GRAPH_READLN_RESPONSE;
371 write(resp_sock,&msg,sizeof(G_MESSAGE));
380 if ( (CharBuffer.isEmpty()) && (t==2))
382 msg.msg_type = MSG_GRAPH;
383 msg.param.pword[0] = GRAPH_INKEY_RESPONSE;
384 msg.param.pword[3] = 0;
385 write(resp_sock,&msg,sizeof(G_MESSAGE));
393 void VGR::keyPressEvent(QKeyEvent *ev)
403 case Key_F1:*pom=-10;break;
404 case Key_F2:*pom=-11;break;
405 case Key_F3:*pom=-12;break;
406 case Key_F4:*pom=-13;break;
407 case Key_F5:*pom=-14;break;
408 case Key_F6:*pom=-15;break;
409 case Key_F7:*pom=-16;break;
410 case Key_F8:*pom=-17;break;
411 case Key_F9:*pom=-18;break;
412 case Key_F10:*pom=-19;break;
413 case Key_Insert:*pom=-20;break;
414 case Key_Home:*pom=-21;break;
415 case Key_End:*pom=-22;break;
416 case Key_PageUp:*pom=-23;break;
417 case Key_PageDown:*pom=-24;break;
418 case Key_Left:*pom=-25;break;
419 case Key_Right:*pom=-26;break;
420 case Key_Up:*pom=-27;break;
421 case Key_Down:*pom=-28;break;
424 if ( (!string_wait) && (!inkey_wait) && (!char_wait) && (!line_wait) )
425 CharBuffer.enqueue(pom);
430 msg.msg_type = MSG_GRAPH;
431 msg.param.pword[0] = GRAPH_INKEY_RESPONSE;
432 msg.param.pword[3] = *pom;
433 write(resp_sock,&msg,sizeof(G_MESSAGE));
442 msg.msg_type = MSG_GRAPH;
443 msg.param.pword[0] = GRAPH_MAGIC_RESPONSE;
444 msg.param.pword[1]=0;
445 WriteChar((char)ev->ascii());
450 msg.msg_type = MSG_GRAPH;
451 msg.param.pword[0] = GRAPH_READCHAR_RESPONSE;
453 msg.param.pchar =(char)ev->ascii();
454 write(resp_sock,&msg,sizeof(G_MESSAGE));
458 if ( (line_wait) && (ev->ascii()==13) )
460 msg.msg_type = MSG_GRAPH;
461 msg.param.pword[0] = GRAPH_READLN_RESPONSE;
462 write(resp_sock,&msg,sizeof(G_MESSAGE));
470 internal_buffer[strcnt]='\0';
475 msg.msg_type = MSG_GRAPH;
476 msg.param.pword[0] = GRAPH_MAGIC_RESPONSE;
477 msg.param.pword[1]=0;
480 msg.msg_type = MSG_GRAPH;
481 msg.param.pword[0] = GRAPH_READSTR_RESPONSE;
483 strcpy(msg.param.pstr,internal_buffer);
484 write(resp_sock,&msg,sizeof(G_MESSAGE));
492 strcnt--;DelChar();DelChar();WriteChar('_');
494 {internal_buffer[strcnt]=(char)ev->ascii();strcnt++;
496 WriteChar((char)ev->ascii());WriteChar('_');}
510 void VGR::hscrolled(int val)
513 setUpdatesEnabled(TRUE);
515 setUpdatesEnabled(FALSE);
518 void VGR::vscrolled(int val)
521 setUpdatesEnabled(TRUE);
523 setUpdatesEnabled(FALSE);
527 // **************************************
529 void VGR::SetForeground(int col)
534 void VGR::SetBackground(int col)
539 void VGR::Line(int x1,int y1,int x2,int y2)
543 p.setPen(*lcolors[fcol]);
544 p.drawLine(x1,y1,x2,y2);
548 p.setPen(*lcolors[fcol]);
549 p.drawLine(x1-ox, y1-oy,x2-ox, y2-oy);
554 void VGR::Ellipse(int x,int y,int a, int b,int alfa, int beta, int fill)
559 p.setPen(*lcolors[fcol]);
560 p.setBrush(*lcolors[fcol]);
562 p.drawPie(x,y,a,b,alfa*16,(beta-alfa)*16);
564 p.drawArc(x,y,a,b,alfa*16,(beta-alfa)*16);
568 p.setPen(*lcolors[fcol]);
569 p.setBrush(*lcolors[fcol]);
571 p.drawPie(x-ox, y-oy,a,b,alfa*16,(beta-alfa)*16);
573 p.drawArc(x-ox, y-oy,a,b,alfa*16,(beta-alfa)*16);
578 void VGR::Rect(int x1, int y1, int x2, int y2,int col, int fill)
581 QBrush b(*lcolors[col]);
583 p.setPen(*lcolors[col]);
584 if (fill>0) p.fillRect(x1,y1,x2-x1,y2-y1,b);
585 else p.drawRect(x1,y1,x2-x1,y2-y1);
590 p.setPen(*lcolors[col]);
591 if (fill>0) p.fillRect(x1-ox, y1-oy,x2-x1,y2-y1,b);
592 else p.drawRect(x1-ox, y1-oy,x2-x1,y2-y1);
597 void VGR::TextXY(int x, int y, char *s)
600 QFontMetrics fm(*prv_font);
603 p.setPen(*lcolors[fcol]);
604 p.setBackgroundColor(*lcolors[bcol]);
605 p.setBackgroundMode(OpaqueMode);
606 p.setFont(*prv_font);
607 p.drawText(x,y+fm.height(),s,strlen(s));
612 p.setPen(*lcolors[fcol]);
613 p.setBackgroundColor(*lcolors[bcol]);
614 p.setBackgroundMode(OpaqueMode);
615 p.setFont(*prv_font);
616 p.drawText(x-ox, y-oy+fm.height(),s,strlen(s));
622 void VGR::CharXY(int x, int y, char a)
626 QFontMetrics fm(*prv_font);
631 p.setPen(*lcolors[fcol]);
632 p.setBackgroundColor(*lcolors[bcol]);
633 p.setBackgroundMode(OpaqueMode);
634 p.setFont(*prv_font);
635 p.drawText(x,y+fm.height(),s,strlen(s));
639 p.setPen(*lcolors[fcol]);
640 p.setBackgroundColor(*lcolors[bcol]);
641 p.setBackgroundMode(OpaqueMode);
642 p.setFont(*prv_font);
643 p.drawText(x-ox, y-oy+fm.height(),s,strlen(s));
649 void VGR::IntXY(int x, int y, int val)
653 QFontMetrics fm(*prv_font);
657 p.setPen(*lcolors[fcol]);
658 p.setBackgroundColor(*lcolors[bcol]);
659 p.setBackgroundMode(OpaqueMode);
660 p.setFont(*prv_font);
661 p.drawText(x,y+fm.height(),s,strlen(s));
666 p.setPen(*lcolors[fcol]);
667 p.setBackgroundColor(*lcolors[bcol]);
668 p.setBackgroundMode(OpaqueMode);
669 p.setFont(*prv_font);
670 p.drawText(x-ox, y-oy+fm.height(),s,strlen(s));
675 void VGR::WriteText(char *s)
678 QFontMetrics fm(*prv_font);
681 p.setPen(*lcolors[fcol]);
682 p.setBackgroundColor(*lcolors[bcol]);
683 p.setBackgroundMode(OpaqueMode);
684 p.setFont(*prv_font);
685 p.drawText(tx*fm.maxWidth(),(ty+1)*fm.height(),s,strlen(s));
689 p.setPen(*lcolors[fcol]);
690 p.setBackgroundColor(*lcolors[bcol]);
691 p.setBackgroundMode(OpaqueMode);
692 p.setFont(*prv_font);
693 p.drawText(tx*fm.maxWidth()-ox, (ty+1)*fm.height()-oy,s,strlen(s));
697 if (tx>TEXT_COLS) {tx=0;ty++;};
698 if (ty>TEXT_LINES) {ClearAll();};
702 void VGR::WriteChar(char a)
705 QFontMetrics fm(*prv_font);
714 p.setPen(*lcolors[gfcol]);
715 p.setBackgroundColor(*lcolors[gbcol]);
716 p.setBackgroundMode(OpaqueMode);
717 p.setFont(*prv_font);
718 p.drawText(gx,gy+fm.height(),s,strlen(s));
722 p.setPen(*lcolors[gfcol]);
723 p.setBackgroundColor(*lcolors[gbcol]);
724 p.setBackgroundMode(OpaqueMode);
725 p.setFont(*prv_font);
726 p.drawText(gx-ox, gy-oy+fm.height(),s,strlen(s));
729 gx = gx + strlen(s)*fm.maxWidth();
730 if (gx>MAXWIDTH) {gy=gy+fm.height();gx=0;};
731 if (gy>MAXHEIGHT) {ClearAll();};
736 p.setPen(*lcolors[fcol]);
737 p.setBackgroundColor(*lcolors[bcol]);
738 p.setBackgroundMode(OpaqueMode);
739 p.setFont(*prv_font);
740 p.drawText(tx*fm.maxWidth(),(ty+1)*fm.height(),s,strlen(s));
744 p.setPen(*lcolors[fcol]);
745 p.setBackgroundColor(*lcolors[bcol]);
746 p.setBackgroundMode(OpaqueMode);
747 p.setFont(*prv_font);
748 p.drawText(tx*fm.maxWidth()-ox, (ty+1)*fm.height()-oy,s,strlen(s));
752 if (tx>TEXT_COLS) {tx=0;ty++;};
753 if (ty>TEXT_LINES) {ClearAll();};
760 QFontMetrics fm(*prv_font);
765 p.setPen(*lcolors[fcol]);
766 p.fillRect(gx-fm.maxWidth(),gy,fm.maxWidth(),
767 fm.height()+fm.descent()+1, *lcolors[bcol]);
771 p.setPen(*lcolors[fcol]);
773 p.fillRect(gx-ox-fm.maxWidth(), gy-oy,fm.maxWidth(),
774 fm.height()+fm.descent()+1, *lcolors[bcol]);
782 p.setPen(*lcolors[fcol]);
783 p.fillRect((tx-1)*fm.maxWidth(),(ty)*fm.height(),tx*fm.maxWidth(),
784 (ty+1)*fm.height()+fm.descent()+1, *lcolors[bcol]);
788 p.setPen(*lcolors[fcol]);
789 p.fillRect((tx-1)*fm.maxWidth()-ox, (ty)*fm.height()-oy,tx*fm.maxWidth(),
790 (ty+1)*fm.height()+fm.descent()+1, *lcolors[bcol]);
798 void VGR::PutChar(char a)
801 QFontMetrics fm(*prv_font);
807 p.setPen(*lcolors[fcol]);
808 p.setBackgroundColor(*lcolors[bcol]);
809 p.setBackgroundMode(OpaqueMode);
810 p.setFont(*prv_font);
811 p.drawText(tx*fm.maxWidth(),(ty+1)*fm.height(),s,strlen(s));
815 p.setPen(*lcolors[fcol]);
816 p.setBackgroundColor(*lcolors[bcol]);
817 p.setBackgroundMode(OpaqueMode);
818 p.setFont(*prv_font);
819 p.drawText(tx*fm.maxWidth()-ox, (ty+1)*fm.height()-oy,s,strlen(s));
824 void VGR::WriteLine()
827 if (ty>TEXT_LINES) {ClearAll();};
831 void VGR::Point(int x, int y)
836 p.setPen(*lcolors[fcol]);
841 p.setPen(*lcolors[fcol]);
842 p.drawPoint(x-ox, y-oy);
848 void VGR::ClearArea(int x, int y, int w, int h)
852 p.eraseRect(x,y,w,h);
856 p.eraseRect(x-ox,y-oy,w,h);
863 QBrush b(QColor(white));
867 canvas->fill(backgroundColor());
871 p.fillRect(0,0,width()-16,height()-16,backgroundColor());
877 int VGR::Getmap(int w, int h)
881 m = new QPixmap(w,h);
882 bitBlt(m,0,0,canvas,curx,cury,w,h);
883 maps.append(new VGRMap(firstfreemap,m));
885 return(firstfreemap-1);
889 void VGR::Putmap(int map)
895 if (m->number == map)
897 bitBlt(canvas,curx,cury,m->map,0,0,m->map->width(),m->map->height());
898 bitBlt(this,curx-ox, cury-oy,m->map,0,0,m->map->width(),m->map->height());
907 void VGR::Outstring(int x, int y, char *s, int b, int f)
910 QFontMetrics fm(*prv_font);
913 p.setPen(*lcolors[f]);
914 p.setBackgroundColor(*lcolors[b]);
915 p.setBackgroundMode(OpaqueMode);
916 p.setFont(*prv_font);
917 p.drawText(x,y+fm.height(),s,strlen(s));
921 p.setPen(*lcolors[f]);
922 p.setFont(*prv_font);
923 p.setBackgroundColor(*lcolors[b]);
924 p.setBackgroundMode(OpaqueMode);
925 p.drawText(x-ox, y-oy+fm.height(),s,strlen(s));
930 void VGR::writeintxy(int x, int y, int val,int c)
934 QFontMetrics fm(*prv_font);
938 p.setPen(*lcolors[c]);
939 p.setFont(*prv_font);
940 p.drawText(x,y,s,strlen(s));
944 p.setPen(*lcolors[c]);
945 p.setFont(*prv_font);
946 p.drawText(x-ox, y-oy+fm.height(),s,strlen(s));
955 msg.msg_type = MSG_GRAPH;
956 msg.param.pword[0] = GRAPH_CURPOS_RESPONSE;
957 msg.param.pword[3] = curx;
958 msg.param.pword[4] = cury;
959 write(resp_sock,&msg,sizeof(G_MESSAGE));
963 void VGR::RequestMessage()
968 bzero(&m,sizeof(G_MESSAGE));
969 stat = read(resp_sock,&m,sizeof(G_MESSAGE));
971 if (m.msg_type == MSG_GRAPH)
973 switch(m.param.pword[0])
977 close_btn->setEnabled(TRUE);
981 case GRAPH_SET_TITLE:setCaption(m.param.pstr);break;
982 case GRAPH_WRITE:if (strcmp(m.param.pstr,"\n")==0)
984 WriteText(m.param.pstr);
986 case GRAPH_WRITEXY: TextXY(m.param.pword[3],
987 m.param.pword[4],m.param.pstr);break;
988 case GRAPH_READCHAR: if (!GetInput(0)) char_wait = TRUE;break;
989 case GRAPH_READSTR: strcpy(internal_buffer,"");strcnt=0;
990 string_wait=TRUE;WriteChar('_');break;
991 case GRAPH_READLN: if (was_line)
993 m.msg_type = MSG_GRAPH;
994 m.param.pword[0] = GRAPH_READLN_RESPONSE;
995 write(resp_sock,&m,sizeof(G_MESSAGE));
998 else { if (!GetInput(1)) line_wait = TRUE;}
1000 case GRAPH_PUTCHAR: WriteChar(m.param.pchar);break;
1001 case GRAPH_LINETO: Line(curx,cury,
1002 m.param.pword[3],m.param.pword[4]);break;
1003 case GRAPH_ELLIPSE: Ellipse(m.param.pword[3],
1004 m.param.pword[4],m.param.pword[5],m.param.pword[6],
1005 m.param.pword[7],m.param.pword[8], m.param.pword[9]);
1007 case GRAPH_RECT: Rect(m.param.pword[3],
1008 m.param.pword[4],m.param.pword[5],
1009 m.param.pword[6], m.param.pword[7],
1012 case GRAPH_FOREGROUND:SetForeground(m.param.pword[3]);break;
1013 case GRAPH_BACKGROUND:SetBackground(m.param.pword[3]);break ;
1014 case GRAPH_POINT:Point(m.param.pword[3], m.param.pword[4]);
1016 case GRAPH_CLEAR:ClearAll();
1018 case GRAPH_INKEY:if (!GetInput(2)) inkey_wait = TRUE;break;
1019 case GRAPH_CURPOS:CurPos();break;
1020 case GRAPH_OUTSTRING:Outstring( m.param.pword[2],m.param.pword[3],m.param.pstr,
1021 m.param.pword[4],m.param.pword[5]);
1023 case GRAPH_WRITEINTXY: writeintxy(m.param.pword[2],
1024 m.param.pword[3],m.param.pword[4],
1025 m.param.pword[5]);break;
1027 bzero(&mm,sizeof(G_MESSAGE));
1028 mm.msg_type = MSG_GRAPH;
1029 mm.param.pword[0] = GRAPH_GETMAP_RESPONSE;
1030 mm.param.pword[2] = Getmap(m.param.pword[2]-curx,
1031 m.param.pword[3]-cury);
1032 mm.param.pword[3] = m.param.pword[2]-curx;
1033 mm.param.pword[4] = m.param.pword[3]-cury;
1034 write(resp_sock,&mm,sizeof(G_MESSAGE));
1036 case GRAPH_PUTMAP: Putmap(m.param.pword[2]);
1038 case GRAPH_MOVE: curx = m.param.pword[2];
1039 cury = m.param.pword[3];
1041 case GRAPH_MGETPRESS:mouse_wait=TRUE;break;
1042 case GRAPH_MAGIC: MagicGraph(&m);break;
1043 case GRAPH_HASCII: if (m.param.pword[1]!=0) CharXY(curx,cury,(char)m.param.pword[1]);
1044 else CharXY(curx,cury,' ');break;
1052 void VGR::MagicGraph(G_MESSAGE *msg)
1059 switch(msg->param.pword[1])
1061 case 10:tx=msg->param.pword[2];ty=msg->param.pword[3];break; // gotoxy
1062 case 11:fcol=msg->param.pword[2];break; // forecolor
1063 case 12:bcol=msg->param.pword[2];break; // bkcolor
1064 case 13:prv_font=bold_font;break;
1065 case 14:prv_font=italic_font;break;
1066 case 15:prv_font=normal_font;break;
1067 case 16:ClearAll();break;
1068 case 303: // Draw array_of char (x,y,fcol,bcol)
1070 fcol=msg->param.pword[4];
1071 bcol=msg->param.pword[5];
1072 TextXY(msg->param.pword[2],msg->param.pword[3],
1076 case 300: // Draw int (x,y,int,fcol,bcol)
1078 fcol=msg->param.pword[5];
1079 bcol=msg->param.pword[6];
1080 IntXY(msg->param.pword[2],msg->param.pword[3],
1081 msg->param.pword[4]);
1084 case 301: // Draw char (x,y,char,fcol,bcol)
1086 fcol=msg->param.pword[5];
1087 bcol=msg->param.pword[6];
1088 CharXY(msg->param.pword[2],msg->param.pword[3],
1089 (char)(msg->param.pword[4]));
1092 case 302: // Draw real (x,y,int,frac,fcol,bcol)
1094 fcol=msg->param.pword[6];
1095 bcol=msg->param.pword[7];
1096 sprintf(ss,"%d.%d",msg->param.pword[4],msg->param.pword[5]);
1097 TextXY(msg->param.pword[2],msg->param.pword[3],ss);
1100 case -304: // ReadText (x,y,fcol,bcol)
1103 gfcol=msg->param.pword[4];
1104 gbcol=msg->param.pword[5];
1105 strcpy(internal_buffer,"");strcnt=0;
1107 gx=msg->param.pword[2];
1108 gy=msg->param.pword[3];
1109 string_wait=TRUE;WriteChar('_');
1114 gfcol=msg->param.pword[4];
1115 gbcol=msg->param.pword[5];
1116 strcpy(internal_buffer,"");strcnt=0;
1118 gx=msg->param.pword[2];
1119 gy=msg->param.pword[3];
1123 case 308: // Put image from file (x,y,fname)
1124 if (p.load(msg->param.pstr))
1126 bitBlt(canvas,msg->param.pword[2],msg->param.pword[3],&p,0,0,p.width(),p.height());
1127 bitBlt(this,msg->param.pword[2]-ox, msg->param.pword[3]-oy,&p,0,0,p.width(),p.height());
1130 case 309:// Kill map
1131 pmap = maps.first();
1134 if (msg->param.pword[2] == pmap->number)
1142 case 310: // Line (x1,y1,x2,y2,col)
1144 fcol=msg->param.pword[6];
1145 Line(msg->param.pword[2],msg->param.pword[3],
1146 msg->param.pword[4],msg->param.pword[5]);
1149 case 311: // Rectangle(x1,y1,x2,y2,fcol,icol)
1150 Rect(msg->param.pword[2],msg->param.pword[3],
1151 msg->param.pword[4],msg->param.pword[5],
1152 msg->param.pword[7],1);
1153 Rect(msg->param.pword[2],msg->param.pword[3],
1154 msg->param.pword[4],msg->param.pword[5],
1155 msg->param.pword[6],0);
1157 case 312: // ClearArea(x1,y1,w,h)
1158 ClearArea(msg->param.pword[2],msg->param.pword[3],
1159 msg->param.pword[4],msg->param.pword[5]);
1167 #include "loggraph.moc"
1169 int main( int argc, char **argv )
1171 QApplication app( argc, argv );
1173 app.setMainWidget(&gs);