3 // Qt Example Application: drawdemo
5 // Demonstrates the painter and the printer.
10 #include <QtGui/QPainter>
11 #include <QtGui/QPrinter>
12 #include <QtGui/QPushButton>
13 #include <QtGui/QRadioButton>
14 #include <QtGui/QButtonGroup>
15 #include <QtGui/QApplication>
16 #include <QtGui/QMainWindow>
18 #include <QtGui/QPixmap>
19 #include <QtGui/QScrollBar>
20 #include <QtGui/QColor>
22 #include <QtGui/QFont>
23 #include <QtGui/QFontMetrics>
24 #include <QtCore/QList>
27 #include <netinet/in.h>
32 #include <QtCore/QSocketNotifier>
33 #include <QtCore/QObject>
35 #include <QtCore/QQueue>
36 #include <QtGui/QMessageBox>
37 #include <QtGui/QMenuBar>
38 // #include <qpopmenu.h>
39 #include <QtCore/qnamespace.h>
45 #define REQUEST_NAME "gr.req"
53 VGRMap(int n, QPixmap *m) {
59 class VGR : public QMainWindow {
74 QQueue<int> CharBuffer;
90 void SetForeground(int);
91 void SetBackground(int);
93 void ClearArea(int, int, int, int);
95 void Line(int, int, int, int);
96 void Ellipse(int x, int y, int a, int b, int alfa, int beta, int fill);
97 void Rect(int x1, int y1, int x2, int y2, int col, int fill);
98 void Point(int x, int y);
99 void TextXY(int x, int y, char *s);
100 void CharXY(int x, int y, char a);
101 void IntXY(int x, int y, int val);
103 void WriteText(char *s);
104 void WriteChar(char a);
107 /* Write Char w/o changing position */
108 void PutChar(char a);
111 void Outstring(int x, int y, char *s, int b, int f);
112 void writeintxy(int x, int y, int val, int c);
115 int Getmap(int w, int h);
116 void Putmap(int map);
118 void MagicGraph(G_MESSAGE*);
125 void RequestMessage();
128 virtual void resizeEvent(QResizeEvent *);
129 virtual void closeEvent(QCloseEvent *);
130 virtual void keyPressEvent(QKeyEvent *);
131 virtual void mousePressEvent(QMouseEvent *);
132 virtual void paintEvent(QPaintEvent *);
133 virtual void focusInEvent(QFocusEvent *);
139 QPushButton *close_btn;
140 int ox,oy,lstep,pstep,gx,gy;
146 QSocketNotifier *request;
147 char internal_buffer[256];
151 void VGR::MakeColors()
154 lcolors[0] = new QColor(0, 0, 0);
156 lcolors[1] = new QColor(0, 0, 139);
158 lcolors[2] = new QColor(0, 100, 0);
160 lcolors[3] = new QColor(0, 197, 205);
162 lcolors[4] = new QColor(205, 0, 0);
164 lcolors[5] = new QColor(238, 130, 238);
166 lcolors[6] = new QColor(139,35, 35);
168 lcolors[7] = new QColor(190, 190, 190);
170 lcolors[8] = new QColor(97, 97, 97);
172 lcolors[9] = new QColor(0, 0, 255);
174 lcolors[10] = new QColor(0, 255, 0);
176 lcolors[11] = new QColor(0, 229, 238);
178 lcolors[12] = new QColor(255, 0, 0);
180 lcolors[13] = new QColor(255, 110, 180);
182 lcolors[14] = new QColor(255, 255, 0);
184 lcolors[15] = new QColor(255, 255, 255);
188 * Construct the DrawView with buttons.
190 VGR::VGR(char *sockname)
194 struct sockaddr_un svr;
195 int len, i, optval, on;
197 normal_font = new QFont("lucidatypewriter", 10, QFont::Normal);
198 normal_font->setFixedPitch(TRUE);
199 bold_font = new QFont("lucidatypewriter", 10, QFont::Bold);
200 bold_font->setFixedPitch(TRUE);
201 italic_font = new QFont("lucidatypewriter", 10, QFont::Normal,TRUE);
202 italic_font->setFixedPitch(TRUE);
204 prv_font = normal_font;
207 setCaption("graphic resource");
208 // setBackgroundColor(white);
209 canvas = new QPixmap(640, 480);
210 canvas->fill(backgroundColor());
217 maps.setAutoDelete(TRUE);
223 hscroll = new QScrollBar(0, MAXWIDTH, lstep, pstep, 0, QScrollBar::Horizontal, this);
224 vscroll = new QScrollBar(0, MAXHEIGHT, lstep, pstep, 0, QScrollBar::Vertical, this);
225 hscroll->setTracking(TRUE);
226 vscroll->setTracking(TRUE);
229 hscroll->setGeometry(0, height() - 16, width() - 16, 16);
230 vscroll->setGeometry(width() - 16, 0, 16, height() - 16);
232 connect(hscroll, SIGNAL(valueChanged(int)), this, SLOT(hscrolled(int)));
233 connect(vscroll, SIGNAL(valueChanged(int)), this, SLOT(vscrolled(int)));
235 close_btn = new QPushButton(this, "close");
237 if (mp.load("pics/close.bmp"))
238 close_btn->setPixmap(mp);
240 close_btn->setText("C");
242 close_btn->setGeometry(width()-16,height()-16,16,16);
243 close_btn->setEnabled(FALSE);
244 connect(close_btn, SIGNAL(clicked()), this, SLOT(CloseMe()));
249 resp_sock = socket(AF_UNIX, SOCK_STREAM, 0);
250 bzero(&svr, sizeof(svr));
251 svr.sun_family = AF_UNIX;
252 strcpy(svr.sun_path, sockname);
253 len = strlen(svr.sun_path) + sizeof(svr.sun_family);
254 i = ::connect(resp_sock, (struct sockaddr*)&svr, len);
256 fcntl(resp_sock, F_SETFL, O_NONBLOCK |
257 fcntl(resp_sock , F_GETFL, 0));
259 setsockopt(resp_sock, IPPROTO_TCP, TCP_NODELAY, (char*)&on, sizeof(on));
260 request = new QSocketNotifier(resp_sock, QSocketNotifier::Read);
261 connect(request, SIGNAL(activated(int)), this, SLOT(RequestMessage()));
262 optval=TCP_BUFFER_SIZE;
264 setsockopt(resp_sock,SOL_SOCKET,SO_SNDBUF,&optval,sizeof(optval));
265 setsockopt(resp_sock,SOL_SOCKET,SO_RCVBUF,&optval,sizeof(optval));
268 inkey_wait = string_wait = FALSE;
269 char_wait = line_wait = mouse_wait = FALSE;
272 CharBuffer.setAutoDelete(TRUE);
274 setFocusPolicy(QWidget::StrongFocus);
275 hscroll->setRange(0, MAXWIDTH - width() + 20);
276 vscroll->setRange(0, MAXHEIGHT - height() + 20);
277 hscroll->setSteps((int)(hscroll->width() / hscroll->maxValue()),
278 (int)((hscroll->width() / hscroll->maxValue()) * 4));
279 vscroll->setSteps((int)(vscroll->height() / vscroll->maxValue()),
280 (int)((vscroll->height() / vscroll->maxValue()) * 4));
282 setMaximumSize(MAXWIDTH + 16, MAXHEIGHT + 16);
283 setUpdatesEnabled(FALSE);
292 void VGR::paintEvent(QPaintEvent *p)
294 /*if (isUpdatesEnabled()) {*/
295 bitBlt(this, 0, 0, canvas, ox, oy, width() - 16, height() - 16);
300 void VGR::focusInEvent(QFocusEvent *)
302 setUpdatesEnabled(TRUE);
304 setUpdatesEnabled(FALSE);
308 void VGR::resizeEvent( QResizeEvent *ev )
310 hscroll->setGeometry(0, height() - 16, width() - 16, 16);
311 vscroll->setGeometry(width() - 16, 0, 16, height() - 16);
312 close_btn->setGeometry(width() - 16, height() - 16, 16, 16);
313 hscroll->setRange(0, MAXWIDTH - width() + 20);
314 vscroll->setRange(0, MAXHEIGHT - height() + 20);
315 pstep = height() - 32;
316 hscroll->setSteps(lstep, pstep);
317 vscroll->setSteps(lstep, pstep);
320 void VGR::closeEvent(QCloseEvent *ev)
323 QFrame::closeEvent(ev);
326 void VGR::mousePressEvent(QMouseEvent *ev)
331 msg.msg_type = MSG_GRAPH;
332 msg.param.pword[0] = GRAPH_MGETPRESS_RESPONSE;
333 msg.param.pword[2] = ev->pos().x() - ox;
334 msg.param.pword[3] = ev->pos().y() - oy;
335 switch(ev->button()) {
337 msg.param.pword[7] = 1;
340 msg.param.pword[7] = 3;
343 msg.param.pword[7] = 2;
346 msg.param.pword[7] = 0;
349 write(resp_sock, &msg, sizeof(G_MESSAGE));
353 QFrame::mousePressEvent(ev);
357 bool VGR::GetInput(int t)
361 if (!CharBuffer.isEmpty()) {
364 msg.msg_type = MSG_GRAPH;
365 msg.param.pword[0] = GRAPH_INKEY_RESPONSE;
366 msg.param.pword[3] = *(CharBuffer.dequeue());
367 write(resp_sock,&msg,sizeof(G_MESSAGE));
375 msg.msg_type = MSG_GRAPH;
376 msg.param.pword[0] = GRAPH_MAGIC_RESPONSE;
377 msg.param.pword[1] = 0;
379 (char)(*(CharBuffer.dequeue()));
380 WriteChar(msg.param.pchar);
383 msg.msg_type = MSG_GRAPH;
384 msg.param.pword[0] = GRAPH_READCHAR_RESPONSE;
386 (char)(*(CharBuffer.dequeue()));
389 write(resp_sock,&msg,sizeof(G_MESSAGE));
394 while ( ((!CharBuffer.isEmpty()) &&
395 (!(*(CharBuffer.dequeue()) = 13))));
397 if (!CharBuffer.isEmpty()) {
398 msg.msg_type = MSG_GRAPH;
399 msg.param.pword[0] = GRAPH_READLN_RESPONSE;
400 write(resp_sock, &msg, sizeof(G_MESSAGE));
409 if (CharBuffer.isEmpty() && (t == 2)) {
410 msg.msg_type = MSG_GRAPH;
411 msg.param.pword[0] = GRAPH_INKEY_RESPONSE;
412 msg.param.pword[3] = 0;
413 write(resp_sock, &msg, sizeof(G_MESSAGE));
421 void VGR::keyPressEvent(QKeyEvent *ev)
472 case Qt::Key_PageDown:
489 if ((!string_wait) && (!inkey_wait) && (!char_wait) && (!line_wait))
490 CharBuffer.enqueue(pom);
494 msg.msg_type = MSG_GRAPH;
495 msg.param.pword[0] = GRAPH_INKEY_RESPONSE;
496 msg.param.pword[3] = *pom;
497 write(resp_sock, &msg, sizeof(G_MESSAGE));
503 msg.msg_type = MSG_GRAPH;
504 msg.param.pword[0] = GRAPH_MAGIC_RESPONSE;
505 msg.param.pword[1] = 0;
506 WriteChar((char)ev->ascii());
509 msg.msg_type = MSG_GRAPH;
510 msg.param.pword[0] = GRAPH_READCHAR_RESPONSE;
512 msg.param.pchar = (char)ev->ascii();
513 write(resp_sock, &msg, sizeof(G_MESSAGE));
517 if ((line_wait) && (ev->ascii() == 13)) {
518 msg.msg_type = MSG_GRAPH;
519 msg.param.pword[0] = GRAPH_READLN_RESPONSE;
520 write(resp_sock, &msg, sizeof(G_MESSAGE));
525 if (ev->ascii() == 13) {
526 internal_buffer[strcnt] = '\0';
530 msg.msg_type = MSG_GRAPH;
531 msg.param.pword[0] = GRAPH_MAGIC_RESPONSE;
532 msg.param.pword[1] = 0;
534 msg.msg_type = MSG_GRAPH;
535 msg.param.pword[0] = GRAPH_READSTR_RESPONSE;
537 strcpy(msg.param.pstr, internal_buffer);
538 write(resp_sock, &msg, sizeof(G_MESSAGE));
543 else if (ev->ascii() == 8) {
549 internal_buffer[strcnt] = (char)ev->ascii();
552 WriteChar((char)ev->ascii());
566 void VGR::hscrolled(int val)
569 setUpdatesEnabled(TRUE);
571 setUpdatesEnabled(FALSE);
574 void VGR::vscrolled(int val)
577 setUpdatesEnabled(TRUE);
579 setUpdatesEnabled(FALSE);
583 /****************************************/
585 void VGR::SetForeground(int col)
590 void VGR::SetBackground(int col)
595 void VGR::Line(int x1, int y1, int x2, int y2)
599 p.setPen(*lcolors[fcol]);
600 p.drawLine(x1, y1, x2, y2);
604 p.setPen(*lcolors[fcol]);
605 p.drawLine(x1 - ox, y1 - oy, x2 - ox, y2 - oy);
609 void VGR::Ellipse(int x, int y, int a, int b, int alfa, int beta, int fill)
614 p.setPen(*lcolors[fcol]);
615 p.setBrush(*lcolors[fcol]);
617 p.drawPie(x, y, a, b, alfa * 16, (beta - alfa) * 16);
619 p.drawArc(x, y, a, b, alfa * 16, (beta - alfa) * 16);
624 p.setPen(*lcolors[fcol]);
625 p.setBrush(*lcolors[fcol]);
627 p.drawPie(x - ox, y - oy, a, b, alfa * 16, (beta - alfa) * 16);
629 p.drawArc(x - ox, y - oy, a, b, alfa * 16, (beta - alfa) * 16);
634 void VGR::Rect(int x1, int y1, int x2, int y2,int col, int fill)
637 QBrush b(*lcolors[col]);
639 p.setPen(*lcolors[col]);
641 p.fillRect(x1 , y1 , x2 - x1, y2 - y1, b);
643 p.drawRect(x1,y1,x2-x1,y2-y1);
648 p.setPen(*lcolors[col]);
650 p.fillRect(x1 - ox, y1 - oy, x2 - x1, y2 - y1, b);
652 p.drawRect(x1 - ox, y1 - oy, x2 - x1, y2 - y1);
656 void VGR::TextXY(int x, int y, char *s)
659 QFontMetrics fm(*prv_font);
662 p.setPen(*lcolors[fcol]);
663 p.setBackgroundColor(*lcolors[bcol]);
664 p.setBackgroundMode(Qt::OpaqueMode);
665 p.setFont(*prv_font);
666 p.drawText(x, y + fm.height(), s, strlen(s));
671 p.setPen(*lcolors[fcol]);
672 p.setBackgroundColor(*lcolors[bcol]);
673 p.setBackgroundMode(Qt::OpaqueMode);
674 p.setFont(*prv_font);
675 p.drawText(x - ox, y - oy + fm.height(), s, strlen(s));
680 void VGR::CharXY(int x, int y, char a)
684 QFontMetrics fm(*prv_font);
689 p.setPen(*lcolors[fcol]);
690 p.setBackgroundColor(*lcolors[bcol]);
691 p.setBackgroundMode(Qt::OpaqueMode);
692 p.setFont(*prv_font);
693 p.drawText(x , y + fm.height(), s, strlen(s));
697 p.setPen(*lcolors[fcol]);
698 p.setBackgroundColor(*lcolors[bcol]);
699 p.setBackgroundMode(Qt::OpaqueMode);
700 p.setFont(*prv_font);
701 p.drawText(x - ox, y - oy + fm.height(), s, strlen(s));
706 void VGR::IntXY(int x, int y, int val)
710 QFontMetrics fm(*prv_font);
712 sprintf(s, "%d", val);
714 p.setPen(*lcolors[fcol]);
715 p.setBackgroundColor(*lcolors[bcol]);
716 p.setBackgroundMode(Qt::OpaqueMode);
717 p.setFont(*prv_font);
718 p.drawText(x, y + fm.height(), s, strlen(s));
722 p.setPen(*lcolors[fcol]);
723 p.setBackgroundColor(*lcolors[bcol]);
724 p.setBackgroundMode(Qt::OpaqueMode);
725 p.setFont(*prv_font);
726 p.drawText(x - ox, y - oy + fm.height(), s, strlen(s));
730 void VGR::WriteText(char *s)
733 QFontMetrics fm(*prv_font);
736 p.setPen(*lcolors[fcol]);
737 p.setBackgroundColor(*lcolors[bcol]);
738 p.setBackgroundMode(Qt::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(Qt::OpaqueMode);
747 p.setFont(*prv_font);
748 p.drawText(tx * fm.maxWidth() - ox, (ty + 1) * fm.height() - oy, s,
753 if (tx > TEXT_COLS) {
757 if (ty > TEXT_LINES) {
762 void VGR::WriteChar(char a)
765 QFontMetrics fm(*prv_font);
773 p.setPen(*lcolors[gfcol]);
774 p.setBackgroundColor(*lcolors[gbcol]);
775 p.setBackgroundMode(Qt::OpaqueMode);
776 p.setFont(*prv_font);
777 p.drawText(gx, gy + fm.height(), s, strlen(s));
781 p.setPen(*lcolors[gfcol]);
782 p.setBackgroundColor(*lcolors[gbcol]);
783 p.setBackgroundMode(Qt::OpaqueMode);
784 p.setFont(*prv_font);
785 p.drawText(gx - ox, gy - oy + fm.height(), s, strlen(s));
788 gx = gx + strlen(s) * fm.maxWidth();
790 gy = gy + fm.height();
793 if (gy > MAXHEIGHT) {
798 p.setPen(*lcolors[fcol]);
799 p.setBackgroundColor(*lcolors[bcol]);
800 p.setBackgroundMode(Qt::OpaqueMode);
801 p.setFont(*prv_font);
802 p.drawText(tx * fm.maxWidth(), (ty + 1) * fm.height(), s,
807 p.setPen(*lcolors[fcol]);
808 p.setBackgroundColor(*lcolors[bcol]);
809 p.setBackgroundMode(Qt::OpaqueMode);
810 p.setFont(*prv_font);
811 p.drawText(tx * fm.maxWidth() - ox, (ty + 1) * fm.height() - oy,
816 if (tx > TEXT_COLS) {
820 if (ty > TEXT_LINES) {
829 QFontMetrics fm(*prv_font);
833 p.setPen(*lcolors[fcol]);
834 p.fillRect(gx - fm.maxWidth(), gy, fm.maxWidth(),
835 fm.height() + fm.descent() + 1, *lcolors[bcol]);
839 p.setPen(*lcolors[fcol]);
841 p.fillRect(gx - ox - fm.maxWidth(), gy - oy, fm.maxWidth(),
842 fm.height() + fm.descent() + 1, *lcolors[bcol]);
844 gx = gx - fm.maxWidth();
848 p.setPen(*lcolors[fcol]);
849 p.fillRect((tx - 1) * fm.maxWidth(), (ty) * fm.height(),
851 (ty + 1) * fm.height() + fm.descent() + 1,
856 p.setPen(*lcolors[fcol]);
857 p.fillRect((tx - 1) * fm.maxWidth() - ox, (ty) * fm.height() - oy,
859 (ty + 1) * fm.height() + fm.descent() + 1,
869 void VGR::PutChar(char a)
872 QFontMetrics fm(*prv_font);
878 p.setPen(*lcolors[fcol]);
879 p.setBackgroundColor(*lcolors[bcol]);
880 p.setBackgroundMode(Qt::OpaqueMode);
881 p.setFont(*prv_font);
882 p.drawText(tx * fm.maxWidth(), (ty + 1) * fm.height(), s, strlen(s));
886 p.setPen(*lcolors[fcol]);
887 p.setBackgroundColor(*lcolors[bcol]);
888 p.setBackgroundMode(Qt::OpaqueMode);
889 p.setFont(*prv_font);
890 p.drawText(tx * fm.maxWidth() - ox, (ty + 1) * fm.height() - oy, s,
895 void VGR::WriteLine()
899 if (ty > TEXT_LINES) {
905 void VGR::Point(int x, int y)
910 p.setPen(*lcolors[fcol]);
915 p.setPen(*lcolors[fcol]);
916 p.drawPoint(x - ox, y - oy);
920 void VGR::ClearArea(int x, int y, int w, int h)
924 p.eraseRect(x, y, w, h);
928 p.eraseRect(x - ox, y - oy, w, h);
935 QBrush b(QColor(white));
939 canvas->fill(backgroundColor());
942 p.fillRect(0, 0, width() - 16, height() - 16, backgroundColor());
946 int VGR::Getmap(int w, int h)
950 m = new QPixmap(w, h);
951 bitBlt(m, 0, 0, canvas, curx, cury, w, h);
952 maps.append(new VGRMap(firstfreemap, m));
954 return(firstfreemap - 1);
958 void VGR::Putmap(int map)
963 if (m->number == map) {
964 bitBlt(canvas, curx, cury, m->map, 0, 0,
965 m->map->width(), m->map->height());
966 bitBlt(this, curx - ox, cury - oy, m->map, 0, 0,
967 m->map->width(), m->map->height());
974 void VGR::Outstring(int x, int y, char *s, int b, int f)
977 QFontMetrics fm(*prv_font);
980 p.setPen(*lcolors[f]);
981 p.setBackgroundColor(*lcolors[b]);
982 p.setBackgroundMode(Qt::OpaqueMode);
983 p.setFont(*prv_font);
984 p.drawText(x, y + fm.height(), s, strlen(s));
988 p.setPen(*lcolors[f]);
989 p.setFont(*prv_font);
990 p.setBackgroundColor(*lcolors[b]);
991 p.setBackgroundMode(Qt::OpaqueMode);
992 p.drawText(x - ox, y - oy + fm.height(), s, strlen(s));
997 void VGR::writeintxy(int x, int y, int val,int c)
1001 QFontMetrics fm(*prv_font);
1003 sprintf(s, "%d", val);
1005 p.setPen(*lcolors[c]);
1006 p.setFont(*prv_font);
1007 p.drawText(x, y, s, strlen(s));
1011 p.setPen(*lcolors[c]);
1012 p.setFont(*prv_font);
1013 p.drawText(x - ox, y - oy + fm.height(), s, strlen(s));
1021 msg.msg_type = MSG_GRAPH;
1022 msg.param.pword[0] = GRAPH_CURPOS_RESPONSE;
1023 msg.param.pword[3] = curx;
1024 msg.param.pword[4] = cury;
1025 write(resp_sock, &msg, sizeof(G_MESSAGE));
1029 void VGR::RequestMessage()
1034 bzero(&m, sizeof(G_MESSAGE));
1035 stat = read(resp_sock, &m, sizeof(G_MESSAGE));
1037 if (m.msg_type == MSG_GRAPH) {
1038 switch(m.param.pword[0]) {
1040 close_btn->setEnabled(TRUE);
1044 case GRAPH_SET_TITLE:
1045 setCaption(m.param.pstr);
1048 if (strcmp(m.param.pstr,"\n") == 0)
1051 WriteText(m.param.pstr);
1055 TextXY(m.param.pword[3], m.param.pword[4],
1058 case GRAPH_READCHAR:
1064 strcpy(internal_buffer, "");
1071 m.msg_type = MSG_GRAPH;
1072 m.param.pword[0] = GRAPH_READLN_RESPONSE;
1073 write(resp_sock, &m, sizeof(G_MESSAGE));
1075 } else if (!GetInput(1))
1079 WriteChar(m.param.pchar);
1082 Line(curx,cury, m.param.pword[3],
1086 Ellipse(m.param.pword[3], m.param.pword[4],
1087 m.param.pword[5], m.param.pword[6],
1088 m.param.pword[7], m.param.pword[8],
1092 Rect(m.param.pword[3], m.param.pword[4],
1093 m.param.pword[5], m.param.pword[6],
1094 m.param.pword[7], m.param.pword[8]);
1096 case GRAPH_FOREGROUND:
1097 SetForeground(m.param.pword[3]);
1099 case GRAPH_BACKGROUND:
1100 SetBackground(m.param.pword[3]);
1103 Point(m.param.pword[3], m.param.pword[4]);
1116 case GRAPH_OUTSTRING:
1117 Outstring(m.param.pword[2], m.param.pword[3],
1118 m.param.pstr, m.param.pword[4],
1121 case GRAPH_WRITEINTXY:
1122 writeintxy(m.param.pword[2], m.param.pword[3],
1123 m.param.pword[4], m.param.pword[5]);
1126 bzero(&mm, sizeof(G_MESSAGE));
1127 mm.msg_type = MSG_GRAPH;
1128 mm.param.pword[0] = GRAPH_GETMAP_RESPONSE;
1129 mm.param.pword[2] = Getmap(m.param.pword[2] - curx, m.param.pword[3] - cury);
1130 mm.param.pword[3] = m.param.pword[2] - curx;
1131 mm.param.pword[4] = m.param.pword[3] - cury;
1132 write(resp_sock, &mm, sizeof(G_MESSAGE));
1135 Putmap(m.param.pword[2]);
1138 curx = m.param.pword[2];
1139 cury = m.param.pword[3];
1141 case GRAPH_MGETPRESS:
1148 if (m.param.pword[1] != 0)
1149 CharXY(curx, cury, (char)m.param.pword[1]);
1151 CharXY(curx, cury, ' ');
1161 void VGR::MagicGraph(G_MESSAGE *msg)
1168 switch(msg->param.pword[1]) {
1171 tx = msg->param.pword[2];
1172 ty = msg->param.pword[3];
1176 fcol = msg->param.pword[2];
1180 bcol = msg->param.pword[2];
1183 prv_font = bold_font;
1186 prv_font = italic_font;
1189 prv_font = normal_font;
1194 /* Draw array_of char (x,y,fcol,bcol) */
1198 fcol = msg->param.pword[4];
1199 bcol = msg->param.pword[5];
1200 TextXY(msg->param.pword[2], msg->param.pword[3], msg->param.pstr);
1204 /* Draw int (x,y,int,fcol,bcol) */
1208 fcol = msg->param.pword[5];
1209 bcol = msg->param.pword[6];
1210 IntXY(msg->param.pword[2], msg->param.pword[3], msg->param.pword[4]);
1214 /* Draw char (x,y,char,fcol,bcol) */
1218 fcol = msg->param.pword[5];
1219 bcol = msg->param.pword[6];
1220 CharXY(msg->param.pword[2], msg->param.pword[3],
1221 (char)(msg->param.pword[4]));
1225 /* Draw real (x,y,int,frac,fcol,bcol) */
1229 fcol = msg->param.pword[6];
1230 bcol = msg->param.pword[7];
1231 sprintf(ss, "%d.%d", msg->param.pword[4], msg->param.pword[5]);
1232 TextXY(msg->param.pword[2], msg->param.pword[3], ss);
1236 /* ReadText (x,y,fcol,bcol) */
1240 gfcol = msg->param.pword[4];
1241 gbcol = msg->param.pword[5];
1242 strcpy(internal_buffer, "");
1245 gx = msg->param.pword[2];
1246 gy = msg->param.pword[3];
1252 gfcol = msg->param.pword[4];
1253 gbcol = msg->param.pword[5];
1254 strcpy(internal_buffer, "");
1257 gx = msg->param.pword[2];
1258 gy = msg->param.pword[3];
1262 /* Put image from file (x,y,fname) */
1264 if (p.load(msg->param.pstr)) {
1265 bitBlt(canvas, msg->param.pword[2],
1266 msg->param.pword[3], &p,
1267 0, 0, p.width(), p.height());
1268 bitBlt(this, msg->param.pword[2] - ox,
1269 msg->param.pword[3] - oy, &p,
1270 0, 0, p.width(), p.height());
1275 pmap = maps.first();
1276 while (pmap != NULL) {
1277 if (msg->param.pword[2] == pmap->number) {
1284 /* Line (x1,y1,x2,y2,col) */
1287 fcol = msg->param.pword[6];
1288 Line(msg->param.pword[2], msg->param.pword[3],
1289 msg->param.pword[4], msg->param.pword[5]);
1292 /* Rectangle(x1,y1,x2,y2,fcol,icol) */
1294 Rect(msg->param.pword[2], msg->param.pword[3],
1295 msg->param.pword[4], msg->param.pword[5],
1296 msg->param.pword[7], 1);
1297 Rect(msg->param.pword[2], msg->param.pword[3],
1298 msg->param.pword[4],msg->param.pword[5],
1299 msg->param.pword[6], 0);
1301 /* ClearArea(x1,y1,w,h) */
1303 ClearArea(msg->param.pword[2],msg->param.pword[3],
1304 msg->param.pword[4], msg->param.pword[5]);
1309 #include "loggraph.moc"
1311 int main(int argc, char **argv)
1313 QApplication app(argc, argv);
1315 // app.setMainWidget(&gs);