· 8 years ago · Feb 02, 2018, 10:28 AM
1How to make a Graphical User Interface.
2Jari Tuominen
3jari.t.tuominen@gmail.com
4God Bless
5
6***
7
8// collision.c
9#include <stdio.h>
10#include "graos.h"
11#include "collision.h"
12
13// Redraw all collisioned windows
14int RedrawCollisionedWindows(VMODE *v)
15{
16 int i,i2;
17 WINDOW *w;
18
19 // Go through all windows
20 for(i=0; i<wdb.n_windows; i++)
21 {
22 // Get window
23 w = &wdb.w[i];
24
25 // Got collision?
26 if(w->collision)
27 {
28 // Order redraw
29
30 // Zero collision counter
31 w->collision = 0;
32
33 // Set refresh
34 w->refresh = 1|2; // window + components
35 }
36 }
37}
38
39//
40int EstimateWindowCollision(WINDOW *ww)
41{
42 int i,i2;
43 WINDOW *w;
44
45 //
46 for(i=0; i<wdb.n_windows; i++)
47 {
48 // Get window
49 w = &wdb.w[i];
50
51 // Skip our window
52 if(w==ww)
53 continue;
54
55 // Check if cursor is within this window's area
56 if( rectInsideRect(
57 ww->x, ww->y, ww->x+ww->width, ww->y+ww->height,
58 w->x, w->y, w->x+w->width, w->y+w->height) )
59 {
60 // Set window on collision
61 if(w->collision<MAX_COLLISION)
62 w->collision++;
63 }
64 }
65
66 //
67 return 0;
68}
69
70//=========================================================
71// framebuf.c
72// Frame buffer and EGA terminal emulation.
73// (C) 2003 by Jari Tuominen
74//=========================================================
75#include <stdio.h>
76#include <conio.h>
77#include "graos.h"
78#include "framebuf.h"
79
80// Calculate 32-bit checksum
81DWORD chksum(BYTE *buf, int len)
82{
83 int i,val;
84
85 //
86 for(i=0,val=0; i<len; i++)
87 val+=buf[i]+1; // count zeroes too
88
89 //
90 return val;
91}
92
93// Get a new frame buffer
94FRAMEBUF *newFrameBuf(WINDOW *w)
95{
96 int i;
97 FRAMEBUF *fb;
98
99 // Look for old unused framebuffer
100 for(i=0; i<w->n_framebuffers; i++)
101 {
102 //
103 fb = &w->framebuf[i];
104
105 //
106 if(fb->isfree)
107 {
108 //
109 goto resv;
110 }
111 }
112
113 // Get a new one
114 fb = &w->framebuf[w->n_framebuffers];
115 w->n_framebuffers++;
116
117resv:
118 // Reserve frame buffer
119 fb->isfree = FALSE;
120
121 // Return FB PTR
122 return fb;
123}
124
125// Create a new frame buffer inside
126// the window's client region.
127int guiAddFrameBuffer(WINDOW *w,
128 BYTE *buf, int x, int y,
129 int width, int height, int bpp,
130 int type,
131 int terID)
132{
133 FRAMEBUF *fb;
134
135 // Get new frame buffer
136 fb = newFrameBuf(w);
137
138 // Define location
139 fb->x = x;
140 fb->y = y;
141
142 // Define width & height
143 fb->width = width;
144 fb->height = height;
145
146 // Define bits per pixel
147 fb->bpp = bpp;
148
149 // Define buffer PTR
150 fb->buf = buf;
151
152 // Set type
153 fb->type = type;
154
155 // Set terminal ID
156 fb->terID = terID;
157
158 // Return OK
159 return 0;
160}
161
162// Draw emulated EGA terminal.
163void guiDrawEGATerminal(VMODE *v,
164 WINDOW *w, FRAMEBUF *fb, BYTE *tmp)
165{
166 static char str[256],colmap[256];
167 static int i,i2,ad,ad2,x,y,l,xx,yy,x2,y2,clx,cly,cursor,cx,cy;
168
169 //-----------------------------------------------------
170 // Get corner of client area
171 xx = w->x + w->client.x + fb->x;
172 yy = w->y + w->client.y + fb->y;
173
174 // Get client area limit boundary
175 x2 = w->x + w->client.x + w->client.width;
176 y2 = w->y + w->client.y + w->client.height;
177
178 // First sanity check
179 if( (xx+8)>=x2 )
180 return;
181 if( (yy+8)>=y2 )
182 return;
183
184 //------------------------------------------------------------
185 // Get cursor location
186 // (this needs to be done before terminal drawing)
187 cursor = GetCursorLocation(fb->terID);
188 // Store last cursor position
189 fb->lcx = fb->cx;
190 fb->lcy = fb->cy;
191 // Store current cursor position
192 fb->cx = cursor&255;
193 fb->cy = (cursor>>8)&255;
194 // Calculate location of the cursor in graphical screen
195 cx=fb->cx<<3; cy=fb->cy<<3;
196 cx+=xx; cy+=yy;
197
198 // Refresh the line where cursor is
199 fb->rtab[fb->cy] = 1;
200 // Also refresh the line where cursor last time was
201 fb->rtab[fb->lcy % 50] = 1;
202
203 //-----------------------------------------------------
204 // Draw terminal, line by line
205 //
206 for(y=0,ad=0; y<fb->height; y++,ad+=fb->width<<1)
207 {
208 // Skip line if it does not contain updated content
209 if(fb->rtab[y]==FALSE && (w->refresh&1)==0)
210 continue;
211
212 // Declare it done
213 fb->rtab[y] = FALSE;
214
215 // Break loop if we exceed boundary
216 // if( (yy+y*8+8)>=y2 )
217 // break;
218
219 // Copy a single line to buffer
220 l = fb->width;
221 for(i=0; i<l; i++)
222 str[i] = tmp[ad+(i<<1)];
223 str[i]=0;
224 // Copy colors
225 for(i=0; i<l; i++)
226 colmap[i] = tmp[ad+(i<<1)+1];
227
228 // Trim string
229 if( (strlen(str)*8)>=(w->width-w->client.x) )
230 {
231 str[(w->width>>3)-1] = 0;
232 }
233
234 // First wipe the area with black
235 fillRect(v, xx,yy+y*8,x2,yy+y*8 +8, colmap[0]>>4);
236
237 // Draw text line
238 DrawTextColorful(v,
239 &v->font[0],
240 str, xx,yy+y*8,
241 NON_TRANSPARENT | NON_THIN,
242 colmap, 0x07);
243 }
244
245 // Cursor draw if it resides within the client region
246 if( !((cx+8)>=x2) ) // && !((cy)>=y2) )
247 {
248 // Draw cursor
249 fillRect(v, cx,cy,cx+8,cy+8, 10);
250 }
251}
252
253// Automatically refresh a single window on terminal updates
254int automaticallyRefreshTerminalWindow(VMODE *v, WINDOW *w)
255{
256 int i,chk,x,y,ad,ad2;
257 FRAMEBUF *fb;
258
259 //
260 for(i=0; i<w->n_framebuffers; i++)
261 {
262 // Get framebuf PTR
263 fb = &w->framebuf[i];
264
265 // Skip deallocated entries
266 if(fb->isfree)
267 continue;
268
269 // Only terminal emulation FBs
270 if(fb->type!=TYPE_TERMINAL_EMULATION)
271 continue;
272
273 // Get updated terminal data
274 CopyTerminal(fb->terID, v->tmp);
275
276 // We need to redraw the content entirely?
277 if(w->refresh)
278 {
279 // Set all lines to being refreshed
280 for(y=0; y<fb->height; y++)
281 fb->rtab[y] = TRUE;
282 }
283 else
284 // Check all lines for updated data
285 for(y=0; y<fb->height; y++)
286 {
287 // No refresh for this line as default
288 fb->rtab[y] = FALSE;
289
290 //
291 chk = chksum(v->tmp+y*fb->width*2, fb->width*2);
292 if(chk!=fb->chksum[y])
293 {
294 // Checksum differs:
295 // Update checksum
296 fb->chksum[y] = chk;
297
298 // Trigger line refresh
299 fb->rtab[y] = TRUE;
300
301 // Trigger window refresh
302 // (2 = components only)
303 w->refresh |= 2;
304 }
305 }
306 }
307}
308
309//
310int automaticallyRefreshTerminalWindows(VMODE *v)
311{
312 int i;
313 WINDOW *w;
314
315 // Go through all windows
316 for(i=0; i<wdb.n_windows; i++)
317 {
318 // Get window PTR
319 w = &wdb.w[i];
320
321 // Skip deallocated windows
322 if(w->isfree)
323 continue;
324
325 // Got frame buffer(s)?
326 if(w->n_framebuffers)
327 automaticallyRefreshTerminalWindow(v, w);
328 }
329}
330
331// Draw a single frame buffer
332int drawFB(VMODE *v, WINDOW *w, FRAMEBUF *fb)
333{
334 static int i,i2,x,y,xx,yy,ad,ad2,x1,y1,x2,y2;
335
336 //
337 switch(fb->type)
338 {
339 //------------------------------------------
340 case TYPE_BITMAP_SCREEN:
341
342 // Copy updated buffer
343 globalcopy(w->pid,fb->buf,
344 GetCurrentThread(),v->tmp,
345 fb->width*fb->height*2);
346
347 // Define rectangle
348 x1 = fb->x+w->client.x+w->x;
349 y1 = fb->y+w->client.y+w->y;
350 x2 = fb->x+w->client.x+fb->width+w->x;
351 y2 = fb->y+w->client.y+fb->height+w->y;
352
353 // Draw frame buffer
354 guiWriteArea(v,
355 x1,y1,x2,y2,
356 v->tmp);
357 break;
358
359 //------------------------------------------
360 case TYPE_TERMINAL_EMULATION:
361
362 // Copy updated buffer
363 CopyTerminal(fb->terID, v->tmp);
364 // fb->chksum = chksum(v->tmp, fb->width*fb->height*2);
365
366 // Draw frame buffer
367 guiDrawEGATerminal(v, w, fb, v->tmp);
368 break;
369
370 // Unknown frame buffer
371 default:
372 break;
373 }
374}
375
376// Draw all frame buffers of the window
377int drawWindowFrameBuffers(VMODE *v, WINDOW *w)
378{
379 int i,i2;
380 FRAMEBUF *fb;
381
382 // Draw all frame buffers
383 for(i=0; i<w->n_framebuffers; i++)
384 {
385 // Get PTR
386 fb = &w->framebuf[i];
387
388 // Skip free entries
389 if(fb->isfree)
390 continue;
391
392 // Draw FB
393 drawFB(v, w, fb);
394 }
395}
396
397// **********************************************
398// * *
399// * JTMOS Window System Server. *
400// * (C) 2002-2005 by Jari Tuominen. *
401// * *
402// **********************************************
403#include <stdio.h>
404#include <jtmos/video.h>
405#include <math.h>
406#include "graos.h"
407#include "guiStart.h"
408#include "guiLoop.h"
409#include "guiEnd.h"
410
411// Request 1024K of static RAM.
412SYSMEMREQ(APPRAM_1024K)
413
414// Graos main function
415int main(int argc, const char **argv)
416{
417 int i;
418 VMODE *v;
419
420 //
421 if(GetThreadPID(GRAOS_SERVER_PID_NAME)!=-1)
422 {
423 //
424 printf("Graos server is already running.\n");
425 return 0;
426 }
427
428 //
429 printf("Graos Windowing System Server.\n");
430 printf(" Host OS: %s\n", HOST_OS);
431 printf(" (C) 1997-2005 by Jari Tuominen\n");
432 //waitkey();
433
434 //
435 if( !(v=guiStart()) ) return 1;
436 guiLoop(v);
437 guiEnd(v);
438 return 0;
439}
440
441// ============================================
442// guiApp.c
443// Internal applications for GUI.
444// (APPCALL -based)
445// ============================================
446#include <stdio.h>
447#include <math.h>
448#include "graos.h"
449#include "guiApp.h"
450#include "guiArrow.h"
451
452int guiApp_virgin=1;
453int wid,wid2, appCyc=0;
454
455//
456void app_move(VMODE *v)
457{
458 int i,i2,i3,i4;
459 WINDOW *w;
460
461 //
462 for(i=0; i<64; i++)
463 {
464 // Movement (Make both windows follow
465 // at mouse cursor's location)
466 if( !((v->cycle>>3)&1) )
467 {
468 // w = GetWindowPTR(wid);
469 // windowFollow(w, v->x, v->y);
470 }
471
472 // Movement II
473 w = GetWindowPTR(wid2);
474 windowFollow(w, v->x, v->y);
475 }
476}
477
478//
479void guiApplicationCall(VMODE *v)
480{
481 int x,y,mx,my, i,i2,i3,i4;
482 char str[256];
483 static char *prgs[]={
484 "wintest0.bin",
485 "wintest.bin",
486 "wintest2.bin",
487 "wintest3.bin",
488 "wintest4.bin",
489 "wintest5.bin",
490 "wintest6.bin",
491 "wintest7.bin",
492 "wintest8.bin",
493 "wintest9.bin",
494 "wintest10.bin"
495 };
496
497 // Close window
498 // (ALT+F4)
499 if(v->keyPressed==JKEY_F4
500 && v->alt)
501 {
502 // If currently selected window is not NULL
503 if(v->selwin!=NULL)
504 {
505 //
506 guiCloseWindow(v, v->selwin);
507 v->selwin=NULL;
508 }
509 }
510
511 // Allow switching to new window
512 // (CTRL+TAB)
513 if(v->keyPressed=='\t'
514 && v->alt)
515 {
516 //
517 DebugMessage("********* switch to new window **********\n");
518 // Switch to next window
519 switchToNextWindow(v);
520 }
521
522 // Run test program 1
523 if(v->keyPressed=='s'
524 && v->ctrl)
525 {
526 // Run test program
527 if( bgexec("winshell sqsh", "/bin")==0 )
528 {
529 // Pop error window
530 PopUpWindow(v, "cannot run winshell",
531 "winshell binary corrupted or not found?");
532 }
533 else
534 {
535 // Pop success window
536 // PopUpWindow(v, "success",
537 // "winshell was launched successfully");
538 }
539 }
540 else
541 // Run test program 1
542 if(v->keyPressed>='a' && v->keyPressed<='j'
543 && v->ctrl)
544 {
545 // Run test program
546 if( bgexec(prgs[v->keyPressed-'a'], "/bin")==0 )
547 {
548 // Pop error window
549 PopUpWindow(v, "run error",
550 "cannot run wintestX.bin, file probably not found");
551 }
552 }
553
554/* //
555 if(guiApp_virgin || (v->buttons&2 && (v->cycle&7)==0))
556 {
557 // Creation
558 guiApp_virgin=0;
559 //
560 sprintf(str, "Window %d", GetSeconds());
561 wid = guiCreateWindow(32,32, 160,120,
562 str, STANDARD_WINDOW);
563 }
564 else
565 {
566 // if( !(v->cycle&7) && v->buttons&1 )app_move(v);
567 }*/
568
569 //
570 if((v->cycle&7)==0 && XON_SYSTEM_METERS)
571 {
572 // Report different meters
573 sprintf(str, "x,y: %d,%d tick: %d cycle: %d n_windows: %d buttons: 0x%x\nlx,ly: %d,%d ulines: %d seconds: %d underwin: %x selwin: %x\nmovwin: %x moving: %d",
574 v->x,v->y, GetTickCount(), v->cycle,
575 wdb.n_windows, v->buttons,
576 v->lx,v->ly,
577 v->ulines, GetSeconds(),
578 v->underwin, v->selwin, v->movwin, v->movingWindow);
579 DrawText(v,str, 0,0, NON_TRANSPARENT, 0x07);
580 }
581}
582
583//
584void guiApplicationCall3(VMODE *v)
585{
586 int x,y,mx,my;
587
588 //
589 my = v->cycle;
590
591 //
592 for(y=0; y<v->height; y+=2)
593 {
594 for(x=v->width>>2; x<v->width; x+=2)
595 {
596 DrawDot( v, x,y, (x>>2)&((y>>2) + (my>>3)) );
597 }
598 }
599}
600
601void guiApplicationCall2(VMODE *v)
602{
603 int x,y,mx,my,text_my;
604 float fa;
605
606 /************ CALCULATE MOVEMENT **************************/
607 fa=GetTickCount(); fa=fa/100;
608// fa=v->cycle; fa=fa/10;
609 my = (v->height>>1) + (((v->height>>1)-40)*sin(fa));
610 text_my = (v->height>>1) + (((v->height>>2)-20)*sin(fa));
611
612 /************ START DRAWING *******************************/
613 gui_ClearScreen(v);
614
615 /************ SOME PIXELS *********************************/
616 for(y=0; y<v->height; y+=2)
617 {
618 for(x=v->width>>2; x<v->width; x+=2)
619 {
620 DrawDot(v, x,y, (x>>2)&((y>>2) + (my>>3)) );
621 }
622 }
623
624 /************ MOVING TEXT *********************************/
625 DrawText(v, "welcome to graos windowing system", 0,text_my,
626 NON_TRANSPARENT, 0x07);
627}
628
629// ============================================
630// guiArrow.c
631// ============================================
632#include <stdio.h>
633#include <math.h>
634#include "graos.h"
635#include "guiApp.h"
636#include "guiArrow.h"
637
638void UndoOldArrow(VMODE *v)
639{
640 if(v->cursorBehindActive)
641 {
642 guiWriteArea(v, v->lx+0,v->ly+0, v->lx+32,v->ly+32,
643 v->cursorBehind);
644 }
645}
646
647void StoreNewArrow(VMODE *v)
648{
649 // 1) Indicate that we have got slice of original area
650 v->cursorBehindActive=1;
651 // 2) Read original area
652 guiReadArea(v, v->x+0,v->y+0, v->x+32,v->y+32,
653 v->cursorBehind);
654 // 3) Write new arrow area on it
655 guiWriteArea1(v, v->x+0,v->y+0, v->x+32,v->y+32,
656 v->cursorRaw);
657}
658
659// ============================================
660// guiBlit.c - GRAOS Windowing System
661// (C) 2002-2003 by Jari Tuominen
662// ============================================
663#include <stdio.h>
664#include <math.h>
665#include "graos.h"
666#include "guiApp.h"
667#include "guiArrow.h"
668#include "guidot.h"
669#include "guiBlit.h"
670
671// Mark
672void guiMark(VMODE *v,
673 int _x1, int _x2, int y1, int y2)
674{
675 int i,i2,i3,i4,ii,x1,x2,x,y;
676 BYTE bits[16]={128,64,32,16,8,4,2,1,
677 0,0,0,0, 0,0,0,0};
678
679 //
680 i = v->width/RADI;
681
682 //
683 x1=_x1/i;
684 x2=_x2/i;
685
686 //
687 for(y=y1; y<(y2+1); y++)
688 {
689 //
690 for(x=x1; x<(x2+1); x++)
691 {
692 //
693 v->dtab[y] |= bits[x&15];
694 }
695 }
696}
697
698//
699int guiReadArea(VMODE *v, int x1,int y1, int x2,int y2, BYTE *buf)
700{
701 int x,y,ad;
702
703 //
704 for(y=y1,ad=0; y<y2; y++)
705 {
706 for(x=x1; x<x2; x++,ad++)
707 {
708 buf[ad] = gui_dotGet(v, x,y);
709 }
710 }
711}
712
713// Specifically coded for arrows
714int guiWriteArea1(VMODE *v, int x1,int y1, int x2,int y2, BYTE *buf)
715{
716 int x,y,ad;
717
718 // Order update for the rectangle area
719 guiMark(v, x1,x2, y1,y2);
720
721 //
722 for(y=y1,ad=0; y<y2; y++)
723 {
724 //
725 for(x=x1; x<x2; x++,ad++)
726 {
727 if(buf[ad]!=255)
728 gui_dotPut(v, x,y, buf[ad]);
729 }
730 }
731}
732
733//
734int guiWriteArea(VMODE *v, int x1,int y1, int x2,int y2, BYTE *buf)
735{
736 int x,y,ad,ad2;
737
738 // Order update for the rectangle area
739 guiMark(v, x1,x2, y1,y2);
740
741 //
742 for(y=y1,ad=0; y<y2; y++)
743 {
744 //
745 for(x=x1; x<x2; x++,ad++)
746 {
747 //
748 gui_dotPut(v, x,y, buf[ad]);
749 }
750 }
751}
752
753//
754int guiBlit(VMODE *v,
755 int x1,int y1,int x2,int y2,
756 BYTE *src,int swidth,int sheight)
757{
758 int x,y,ad,ad2,xx,yy;
759 BYTE *s;
760
761 // Order update for the rectangle area
762 guiMark(v, x1,x2, y1,y2);
763
764 //
765 for(y=y1; y<y2 && y<v->height; y++)
766 {
767 //
768 ad = swidth*(y-y1);
769 ad2 = v->mtab[y];
770
771 //
772 for(s=src+x1,x=x1,xx=0; x<x2 && x<v->width; x++,xx++)
773 {
774 //
775 v->buf[ad2+x] = src[ad+xx];
776 }
777 }
778}
779
780// =========================================================
781// GRAOS CONFIGURATION FILE
782// =========================================================
783#include <stdio.h>
784#include "config.h"
785
786// Show system meters on the top of the screen
787int XON_SYSTEM_METERS = FALSE;
788
789//
790
791
792
793// -------------------------------------------------
794// guiDesktopDraw.c - GRAOS Windowing System
795// (C) 2002-2003 by Jari Tuominen
796// -------------------------------------------------
797#include <stdio.h>
798#include "graos.h"
799#include "guiDesktopDraw.h"
800
801//
802int guiDesktopDraw8(VMODE *v, int x1,int y1, int x2,int y2)
803{
804 //
805 int x,y,xx,yy,ad;
806 char pal[8]={
807 0,8,7,14,15,
808 14,7,8,0
809 };
810
811 //
812 if(v->background || 1)
813 {
814 //
815 guiBlit(v, x1,y1,x2,y2,
816 v->background+x1+y1*v->width, 640,480);
817 // guiWriteArea(v,
818 // x1,y1,x2,y2,
819 // v->background+x1+y1*v->width);
820 }
821 else
822 {
823 //
824 for(y=y1; y<(y2+1); y++)
825 {
826 //
827 for(x=x1; x<(x2+1); x++)
828 {
829 //
830 // xx = x;
831 // yy = y;
832 // gui_dotPut(v, x,y,
833 // pal[((xx*yy)>>12) & 0x7] );
834 }
835 }
836 }
837}
838
839//
840int guiDesktopDraw(VMODE *v, int x1,int y1, int x2,int y2)
841{
842 //
843 switch(v->bpp)
844 {
845 case 1:
846 break;
847
848 case 8:
849 guiDesktopDraw8(v, x1,y1,x2,y2);
850 }
851 return 0;
852}
853// -----------------------------------------------------------
854// guidot.c - GRAOS Window System
855// (C) 2002 by Jari Tuominen
856// -----------------------------------------------------------
857#include <stdio.h>
858#include "graos.h"
859#include "guidot.h"
860
861/******** BPP 1 MONOCHROME FUNCTIONS ******************/
862static BYTE bits[]={128,64,32,16,8,4,2,1};
863
864void DrawDot(VMODE *v, int x,int y, char state)
865{
866 //
867 if(state)
868 gui_dotPut(v, x,y, 1);
869 else
870 gui_dotPut(v, x,y, 0);
871}
872
873/********* 1-BIT DRAWING FUNCTIONS ************************/
874inline int gui_dotGetBPP1(VMODE *v, int x,int y)
875{
876 int ad;
877
878 if(x<0 || x>=v->width ||
879 y<0 || y>=v->height)
880 return 1;
881
882 //
883 v->change++;
884
885 //
886 ad = (v->mtab[y] + x)>>3;
887 return v->buf[ad] & bits[x&7];
888}
889
890//
891inline int gui_dotSetBPP1(VMODE *v, int x,int y, int state)
892{
893 int ad;
894
895 //
896 if(x<0 || x>=v->width ||
897 y<0 || y>=v->height)
898 return 1;
899
900 //
901 v->change++;
902
903 //
904 ad = (v->mtab[y] + x)>>3;
905 if(state)
906 v->buf[ad] |= bits[x&7];
907 else
908 v->buf[ad] &= (255-bits[x&7]);
909 return 0;
910}
911
912/********* 8-BIT DRAWING FUNCTIONS ************************/
913inline int gui_dotGetBPP8(VMODE *v, int x,int y)
914{
915 int ad;
916
917 //
918 if(x<0 || x>=v->width ||
919 y<0 || y>=v->height)
920 return 0;
921
922 //
923 v->change++;
924
925 //
926 ad = (v->mtab[y] + x);
927 return v->buf[ad];
928}
929
930// Dot put for 8-bit mode
931inline int gui_dotPutBPP8(VMODE *v, int x,int y, int va)
932{
933 int ad;
934
935 //
936 if(x<0 || x>=v->width ||
937 y<0 || y>=v->height)
938 return 1;
939
940 //
941 v->change++;
942
943 //
944 ad = (v->mtab[y] + x);
945 v->buf[ad] = va;
946 return 0;
947}
948
949/***************** WRAPPERS ***************************/
950inline int gui_dotGet(VMODE *v, int x,int y)
951{
952 // Choose dotter routine upon BPP
953 switch(v->bpp)
954 {
955 // -----------------------------------
956 // MONOCHROME MODE
957 case 1:
958 if( gui_dotGetBPP1(v, x,y) )
959 return 1;
960 else
961 return 0;
962
963 // -----------------------------------
964 // 8-BIT VGA
965 case 8:
966 return gui_dotGetBPP8(v, x,y);
967
968 default:
969 return 0;
970 }
971 return 0;
972}
973
974//
975inline int gui_dotPut(VMODE *v, int x,int y, int va)
976{
977 // Choose dotter routine upon BPP
978 switch(v->bpp)
979 {
980 // --- 8-BIT VGA MODE -------------------
981 case 8:
982 gui_dotPutBPP8(v, x,y, va);
983 break;
984
985 // --- MONOCHROME MODE -------------------
986 case 1:
987 if(va)
988 gui_dotSetBPP1(v, x,y, 1);
989 else
990 gui_dotSetBPP1(v, x,y, 0);
991 break;
992
993 default:
994 return 0;
995 }
996 return 0;
997}
998
999/*
1000int gui_dotSet(VMODE *v, int x,int y)
1001{
1002 // Choose dotter routine upon BPP
1003 switch(v->bpp)
1004 {
1005 case 1:
1006 gui_dotSetBPP1(v, x,y, 1);
1007 break;
1008
1009 default:
1010 return 1;
1011 }
1012 return 0;
1013}
1014
1015//
1016inline int gui_dotRemove(VMODE *v, int x,int y)
1017{
1018 // Choose dotter routine upon BPP
1019 switch(v->bpp)
1020 {
1021 case 1:
1022 gui_dotRemoveBPP1(v, x,y);
1023 break;
1024
1025 default:
1026 return 1;
1027 }
1028 return 0;
1029}
1030
1031*/
1032/******************************************************/
1033
1034// =====================================================
1035// guiStart.c
1036// =====================================================
1037#include <stdio.h>
1038#include "guiEnd.h"
1039
1040//
1041void guiEnd(VMODE *v)
1042{
1043 //
1044 exitAllApplications(v);
1045
1046 // Restore default video mode
1047 setmode(3);
1048
1049 // Close debug stream
1050 CloseDebugStream();
1051}
1052
1053// ******************************************
1054// guifunc.c - font renderation functions.
1055// (C) 2002-2003 by Jari Tuominen
1056// ******************************************
1057#include <stdio.h>
1058#include <jtmos/video.h>
1059#include <math.h>
1060#include <conio.h> // Colors
1061#include "guifont.h"
1062#define FONTCOLOR RED
1063
1064// Load 512x16 font with 32x2 fonts
1065int LoadFont(const char *fname, FONT *fon, int invert)
1066{
1067 FILE *f;
1068 int i,d,l,lines;
1069
1070 // Open font file
1071 f=fopen(fname, "rb");
1072 if(f==NULL)
1073 // File not found!
1074 return 1;
1075
1076
1077 // Read font
1078 lines = 2;
1079 l = 512*8 * lines;
1080
1081 // Allocate font bitmap buffer
1082 fon->buf = malloc(l);
1083
1084 //
1085 for(i=0; i<l; i++)
1086 {
1087 // Get data
1088 d = fgetc(f); if(d==EOF)break;
1089
1090 // Filter
1091 if(d==15)
1092 d=FONTCOLOR;
1093 else
1094 d=0;
1095
1096 // Invert
1097 if(invert)
1098 {
1099 if(d==15)
1100 d = 0;
1101 else
1102 d = FONTCOLOR;
1103 }
1104
1105 // Store data
1106 fon->buf[i]=d;
1107 }
1108
1109 //
1110 fon->l_buf = i;
1111 fon->width = 512;
1112 fon->height = 8;
1113 fon->bpp = 8;
1114 fclose(f);
1115 return 0;
1116}
1117
1118// Draw text
1119void DrawText(VMODE *v, const char *s, int tx,int ty,
1120 int t,
1121 int color)
1122{
1123 //
1124 DrawTextEx(v, &v->font[0], s,tx,ty, t, color);
1125}
1126
1127// Draw text (2)
1128void DrawTextEx(VMODE *v, FONT *f, const char *s, int tx,int ty,
1129 int transparency,
1130 int color)
1131{
1132 //
1133 _DrawText(v, s,tx,ty,
1134 f->buf, f->width, f->height,
1135 transparency,
1136 NULL,
1137 color);
1138}
1139
1140// Draw text, with possibility to define a seperate
1141// forgeground and background color for each of
1142// the letters.
1143// Used by EGA terminal emulation.
1144void DrawTextColorful(VMODE *v,
1145 FONT *f,
1146 const char *s, int tx,int ty,
1147 int transparency,
1148 char *colmap,
1149 int color)
1150{
1151 //
1152 _DrawText(v,
1153 s,tx,ty,
1154 f->buf, f->width, f->height,
1155 transparency,
1156 colmap,
1157 color);
1158}
1159
1160// Draw text (3)
1161// Render graphic text
1162void _DrawText(VMODE *v,
1163 const char *s,long x,long y,
1164 const char *font,long font_width,long font_height,
1165 int transparency,
1166 char *colmap, int color)
1167{
1168 // Font configuration
1169 static char *contab= "abcdefghijklmnopqrstuvwxyz0123456789_ ()-+.,%/#':;$[]<>=@*\\_^¨½§!?|~öäå!?|~öäå";
1170 static char *contab2="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_ ()-+.,%/#':;$[]<>=@*\\_^¨½§!?|~öäå!?|~öäå";
1171 static char *thinchars="iI,.()[]:;' <>!|";
1172 //
1173 int i,i2,i3,i4,xp,yp,line,xx,xplus,yplus,l,checkThins,col;
1174 int c,c2,c3,c4,ch;
1175
1176 // Thin chars option
1177 checkThins = transparency & 2 ^ 2;
1178
1179 //
1180 xp=x; yp=y;
1181
1182 // Spring text!
1183 for(i=0,xplus=0,line=0,xx=0; i<strlen(s); i++,xx++)
1184 {
1185 // Read mark
1186 c = s[i]; ch=c;
1187
1188 // End of string?
1189 if(!c)break;
1190
1191 //
1192 if(c=='\r')continue;
1193
1194 // New line?
1195 if(c=='\n')
1196 {
1197 xplus=0;
1198 xx=-1;
1199 line++;
1200 continue;
1201 }
1202
1203 //
1204 l = strlen(contab);
1205 for(i2=0,i3=0; i2<l; i2++)
1206 {
1207 //
1208 if( contab[i2]==c || contab2[i2]==c )
1209 {
1210 //
1211 c=i2;
1212 i3=1;
1213 break;
1214 }
1215 }
1216
1217 // No matching? => Just empty.
1218 if(!i3)continue;
1219
1220 // Scroll over thinchars(4 pixels width)
1221 // Regular is 8 pixels.
1222 if(checkThins)
1223 {
1224 l = strlen(thinchars);
1225 for(i2=0,i3=8; i2<l; i2++)
1226 {
1227 // End of thinchars?
1228 if(!thinchars[i2])break;
1229 // Is it a thinchar?
1230 if(ch==thinchars[i2]){i3=4; break;}
1231 }
1232 }
1233 else i3=8; // 8 pixels wide letter
1234
1235 //
1236 if(colmap!=NULL)
1237 col = colmap[i];
1238 else
1239 col = color;
1240
1241 // Draw single letter.
1242 if(!transparency)
1243 {
1244 DrawMonoBitmapColor(v, (BYTE*)font,font_width,font_height,NULL,
1245 xp+xplus,yp+(line*font_height),
1246 // write coordinates
1247 font_height,font_height,
1248 (c%64)*8, (c/64)*8,
1249 col,
1250 FALSE);
1251 }
1252 else
1253 {
1254 DrawMonoBitmapColor(v, (BYTE*)font,font_width,font_height,NULL,
1255 xp+xplus,yp+(line*font_height),
1256 // write coordinates
1257 font_height,font_height,
1258 (c%64)*8, (c/64)*8,
1259 col,
1260 TRUE);
1261 }
1262
1263 //
1264 xplus += i3;
1265 }
1266}
1267
1268//*******************************************
1269// guifunc.c
1270// (C) 2002-2003 by Jari Tuominen
1271//*******************************************
1272#include <stdio.h>
1273#include <jtmos/video.h>
1274#include <math.h>
1275#include <conio.h> // Colors
1276#include "graos.h"
1277#include "guifunc.h"
1278
1279//
1280int follow(int what, int dest)
1281{
1282 //
1283 if(what==dest)
1284 return what;
1285 else
1286 if(what<dest)
1287 return what+1;
1288 else
1289 if(what>dest)
1290 return what-1;
1291}
1292
1293//
1294int LoadBin(const char *fname, BYTE *buf, int limit)
1295{
1296 FILE *f;
1297 int i,d;
1298
1299 //
1300 f=fopen(fname, "rb");
1301 if(!f) return 1;
1302 for(i=0; i<limit; i++) {
1303 d = fgetc(f);
1304 if(d==EOF)break;
1305 buf[i] = d;
1306 }
1307 fclose(f);
1308 return 0;
1309}
1310
1311int waitkey(void)
1312{
1313 int key;
1314 printf("Press any key to continue ... ");
1315 key = getch();
1316 printf("\r \r");
1317 return key;
1318}
1319
1320// A fast clear screen function which clears with black color
1321void gui_FastClearScreen(VMODE *v)
1322{
1323 int i;
1324
1325 //
1326 memset(v->buf, BLACK, v->l_buf);
1327 memset(v->dtab, 0xFF, v->height);
1328 v->change=1;
1329}
1330
1331// Appropriate clear screen -function
1332void gui_ClearScreen(VMODE *v)
1333{
1334 int i;
1335
1336 //
1337 eraseArea(v, 0,0,v->width,v->height);
1338}
1339
1340//
1341void DrawTransparentMonoBitmap(VMODE *v,
1342 BYTE *srcbuf,long s_width,long s_height,BYTE *pal,
1343 long target_x, long target_y,
1344 long wanted_width,long wanted_height,
1345 long source_x, long source_y)
1346{
1347 //
1348 DrawMonoBitmapEx(v, srcbuf, s_width,s_height, pal,
1349 target_x,target_y,
1350 wanted_width,wanted_height,
1351 source_x,source_y,
1352 1);
1353}
1354
1355//
1356void DrawMonoBitmap(VMODE *v,
1357 BYTE *srcbuf,long s_width,long s_height,BYTE *pal,
1358 long target_x, long target_y,
1359 long wanted_width,long wanted_height,
1360 long source_x, long source_y)
1361{
1362 //
1363 DrawMonoBitmapEx(v, srcbuf, s_width,s_height, pal,
1364 target_x,target_y,
1365 wanted_width,wanted_height,
1366 source_x,source_y,
1367 0);
1368}
1369
1370//
1371void DrawMonoBitmapEx(VMODE *v,
1372 BYTE *srcbuf,long s_width,long s_height,BYTE *pal,
1373 long target_x, long target_y,
1374 long wanted_width,long wanted_height,
1375 long source_x, long source_y,
1376 int tr)
1377{
1378 int x,y,ad,ad2,ad3,ad4;
1379 int xx,yy,xp,yp,rx,ry,i,i2,i3,i4;
1380
1381 //
1382 for(y=target_y,yy=0; y<target_y+wanted_height; y++,yy++)
1383 {
1384 //
1385 if( (y>-1 && y<v->height) && (yy+source_y)>-1 && (yy+source_y)<s_height )
1386 {
1387 //
1388 guiMark(v, target_x,target_x+wanted_width, y, y+1);
1389
1390 //
1391 ad=(yy+source_y)*s_width;
1392 ad2=y*v->width;
1393 for(x=target_x,xx=0; x<target_x+wanted_width; x++,xx++)
1394 {
1395 //
1396 if(x<v->width && x>-1 && (xx+source_x)>-1 && (xx+source_x)<s_width )
1397 {
1398 if( srcbuf[ad+xx+source_x] )
1399 gui_dotPut(v, x,y, WHITE);
1400 else
1401 if(!tr)gui_dotPut(v, x,y, 0);
1402 // if
1403 }
1404 // if
1405 }
1406 // for
1407 }
1408 // if
1409 }
1410 // for
1411
1412 //
1413 return;
1414}
1415
1416// Draw color bitmap.
1417// Options for:
1418// - Transparency.
1419// - Color.
1420void DrawMonoBitmapColor(VMODE *v,
1421 BYTE *srcbuf,long s_width,long s_height,BYTE *pal,
1422 long target_x, long target_y,
1423 long wanted_width,long wanted_height,
1424 long source_x, long source_y,
1425 int color,
1426 char drawbackground)
1427{
1428 int x,y,ad,ad2,ad3,ad4;
1429 int xx,yy,xp,yp,rx,ry,i,i2,i3,i4;
1430
1431 //
1432 for(y=target_y,yy=0; y<target_y+wanted_height; y++,yy++)
1433 {
1434 //
1435 if( (y>-1 && y<v->height) )
1436 //&& (yy+source_y)>-1 && (yy+source_y)<s_height )
1437 {
1438 //
1439 guiMark(v, target_x,target_x+wanted_width, y, y+1);
1440
1441 //
1442 ad=(yy+source_y)*s_width;
1443 ad2=y*v->width;
1444 for(x=target_x,xx=0; x<target_x+wanted_width; x++,xx++)
1445 {
1446 //
1447 if(x<v->width && x>-1)
1448 //***&& (xx+source_x)>-1 && (xx+source_x)<s_width )
1449 {
1450 if( srcbuf[ad+xx+source_x] )
1451 gui_dotPut(v, x,y, color&15);
1452 else
1453 if(drawbackground)gui_dotPut(v, x,y, color>>4);
1454 // if
1455 }
1456 // if
1457 }
1458 // for
1459 }
1460 // if
1461 }
1462 // for
1463
1464 //
1465 return;
1466}
1467
1468//
1469void gui_DrawBitmap(VMODE *v,
1470 BYTE *src, int swidth, int sheight, BYTE *pal,
1471 int xp, int yp,
1472 int lenx,int leny,
1473 int Xread,int Yread)
1474{
1475 DrawMonoBitmap(v, src, swidth,sheight, pal,
1476 xp,yp,
1477 lenx,leny,
1478 Xread,Yread);
1479}
1480
1481//
1482
1483// =====================================================
1484// guiStart.c
1485// =====================================================
1486#include <stdio.h>
1487#include "guiLoop.h"
1488#include "guiUpdate.h"
1489#include "guiApp.h"
1490#include "windowMoving.h"
1491#include "jtmos/mouse.h"
1492
1493//
1494void guiGetInput(VMODE *v)
1495{
1496 //
1497 v->lx = v->x;
1498 v->ly = v->y;
1499 v->x = GetMouseX();
1500 v->y = GetMouseY();
1501 v->buttons = GetMouseButtons();
1502
1503 //
1504 v->alt = GetALT();
1505 v->ctrl = GetCTRL();
1506}
1507
1508//
1509void guiLoop(VMODE *v)
1510{
1511 int key;
1512
1513 //
1514 while(1)
1515 {
1516 // -------------------------------
1517 guiServerPoll(v);
1518 //
1519 guiGetInput(v);
1520 //
1521 UndoOldArrow(v);
1522 //
1523 automaticallyRefreshTerminalWindows();
1524
1525 // -------------------------------
1526 windowMoving(v);
1527 // -------------------------------
1528 guiApplicationCall(v);
1529 // -------------------------------
1530 guiWindowSystemCall(v);
1531 // -------------------------------
1532 // TASKBAR now exists as an application
1533 // guiTaskbarCall(v);
1534 // -------------------------------
1535
1536 // Store new arrow
1537 StoreNewArrow(v);
1538 // Update screen
1539 guiUpdate(v);
1540
1541 // Input user
1542 key = getch1();
1543 if(key==27 && v->ctrl)break;
1544 v->keyPressed = key;
1545 v->cycle++;
1546 }
1547}
1548
1549
1550// ---------------------------------------------------------
1551// guiRect.c - GRAOS Windowing System
1552// (C) 2002-2003 by Jari Tuominen
1553// ---------------------------------------------------------
1554#include <stdio.h>
1555#include "graos.h"
1556
1557// Erases specified area
1558int eraseArea(VMODE *v, int x1,int y1, int x2,int y2)
1559{
1560 //
1561 switch(v->bpp)
1562 {
1563 //
1564 case 1:
1565 return fillRect(v, x1,y1,x2,y2, 0);
1566
1567 //
1568 case 8:
1569 return guiDesktopDraw(v, x1,y1,x2,y2);
1570 }
1571}
1572
1573// Fill a rectangle
1574int fillRect(VMODE *v, int x1,int y1, int x2,int y2, int vari)
1575{
1576 int x,y,i,i2,i3,i4;
1577
1578 // Mark update area
1579 guiMark(v, x1,x2+1, y1,y2+1);
1580
1581 //
1582 for(y=y1; y<(y2+1); y++)
1583 {
1584 //
1585 for(x=x1; x<(x2+1); x++)
1586 {
1587 gui_dotPut(v, x,y, vari);
1588 }
1589 }
1590}
1591
1592// Draw a rectangle
1593int drawRect(VMODE *v, int x1,int y1, int x2,int y2, int vari)
1594{
1595 int x,y,i,i2,i3,i4;
1596
1597 //
1598 guiMark(v, x1,x1+1, y1,y2);
1599
1600 // 1
1601 for(y=y1; y<(y2+1); y++)
1602 {
1603 //
1604 gui_dotPut(v, x1,y, vari);
1605 }
1606
1607 // 2
1608 for(y=y1; y<(y2+1); y++)
1609 {
1610 gui_dotPut(v, x2,y, vari);
1611 }
1612
1613 // 3
1614 for(x=x1; x<(x2+1); x++)
1615 {
1616 gui_dotPut(v, x,y1, vari);
1617 }
1618
1619 // 4
1620 for(x=x1; x<(x2+1); x++)
1621 {
1622 gui_dotPut(v, x,y2, vari);
1623 }
1624}
1625
1626
1627// guiServer.c
1628#include <stdio.h>
1629#include "graos.h"
1630#include "guiServer.h"
1631
1632// Initialize GRAOS server communication system
1633void guiServerInit(void)
1634{
1635 // Correctly identify itself as Graos server
1636 IdentifyThread(GetCurrentThread(), GRAOS_SERVER_PID_NAME);
1637
1638 // Enable our message box
1639 startMessageBox();
1640}
1641
1642// Process a single client message
1643int guiServerProcessMessage(VMODE *v, MSG *m)
1644{
1645 GUICMD *cmd,*newcmd;
1646 static MSG newMessage;
1647 int wid;
1648 static char str[256];
1649 WINDOW *w;
1650 int rval,rwid;
1651
1652 // Get CMD PTR
1653 cmd = &m->buf;
1654
1655 // Report
1656 sprintf(str, "%s: packet received from PID%d\n",
1657 __FUNCTION__, m->sndPID); DebugMessage(str);
1658
1659 // Set default return value
1660 rval = 0;
1661
1662 // Process CMD ID
1663 switch(cmd->id)
1664 {
1665 //--------------------------------------------------
1666 // Create new frame buffer
1667 case GSID_ADDFRAMEBUFFER:
1668
1669 //
1670 sprintf(str, "%s: I received ADD FRAME BUFFER -request\nwid=%d, buf=%x, x=%d,y=%d, width=%d,height=%d, bpp=%d\n",
1671 __FUNCTION__,
1672 cmd->v[0], cmd->ptr[0], cmd->v[1], cmd->v[2],
1673 cmd->v[3], cmd->v[4], cmd->v[5]);
1674 DebugMessage(str);
1675
1676 //
1677 guiAddFrameBuffer(GetWindowPTR(cmd->v[0]), // wid
1678 cmd->ptr[0], cmd->v[1], cmd->v[2], // buf, x,y,
1679 cmd->v[3], cmd->v[4], cmd->v[5], // width, height, bpp
1680 cmd->v[6], // type
1681 cmd->v[7]); // terminal ID
1682 break;
1683
1684 //--------------------------------------------------
1685 // Create window
1686 case GSID_OPENWINDOW:
1687 sprintf(str, "%s: I received OPEN WINDOW -request\n",
1688 __FUNCTION__); DebugMessage(str);
1689 wid = guiCreateWindow(v,
1690 cmd->v[0],cmd->v[1],
1691 cmd->v[2],cmd->v[3],
1692 cmd->str,
1693 cmd->v[4]); // type
1694 // Define rval
1695 rval = wid;
1696 // Define owner PID
1697 w = getWindowPTR(wid);
1698 w->pid = m->sndPID;
1699 rwid = wid;
1700 break;
1701
1702 //--------------------------------------------------
1703 // Close window
1704 case GSID_CLOSEWINDOW:
1705 // Report
1706 sprintf(str, "%s: I received CLOSE WINDOW -request\nWID to close = %d\n",
1707 __FUNCTION__, cmd->v[0]);
1708 DebugMessage(str);
1709 // Close window
1710 guiCloseWindow(v, &wdb.w[ cmd->v[0] ]);
1711 sprintf(str, "window's isfree variable after closing = %d\n",
1712 wdb.w[cmd->v[0]].isfree);
1713 DebugMessage(str);
1714 rwid = cmd->v[0];
1715 break;
1716
1717 //--------------------------------------------------
1718 // Refresh window
1719 case GSID_REQUESTREFRESH:
1720 // Refresh window
1721 wdb.w[cmd->v[0]].refresh |= 1|2; // window + components
1722 rwid = cmd->v[0];
1723 break;
1724
1725 //--------------------------------------------------
1726 // Create a button
1727 case GSID_CREATEBUTTON:
1728 guiCreateButton(&wdb.w[cmd->v[0]],
1729 cmd->v[1],cmd->v[2], cmd->v[3],cmd->v[4],
1730 cmd->v[5], // type
1731 cmd->str);
1732 /* BUTTON *guiCreateButton(WINDOW *w,
1733 int x1,int y1,int x2,int y2,
1734 int type,
1735 const char *caption) */
1736 break;
1737
1738 //--------------------------------------------------
1739 // Unknown cmd, request will be ignored,
1740 // but still an empty answer will be sent,
1741 // to prevent sender from jamming up.
1742 default:
1743 sprintf(str, "%s: I received unknown request(ID=%d), request ignored.\n",
1744 __FUNCTION__, cmd->id); DebugMessage(str);
1745 return 2;
1746 }
1747
1748 // Send a response packet
1749 memset(&newMessage, 0, sizeof(MSG));
1750 newcmd = &newMessage.buf;
1751 newcmd->id = GSID_RESPONSE;
1752 newcmd->rval = rval;
1753 newcmd->wid = rwid; // which window's message
1754 sprintf(str, "%s: sending response of open window to PID%d\n",
1755 __FUNCTION__, m->sndPID); DebugMessage(str);
1756 sendMessage(&newMessage, m->sndPID);
1757
1758 //
1759 return 0;
1760}
1761
1762//
1763void transmitInterfaceToApp(VMODE *v, WINDOW *w)
1764{
1765 GUICMD *cmd,*newcmd;
1766 static MSG newMessage;
1767 static MSG m;
1768
1769 //--------------------------------------------------
1770 // Get CMD PTR
1771 cmd = &m.buf;
1772
1773 //--------------------------------------------------
1774 // When key is hit
1775 // New: ignoring all key hits when CTRL or ALT is hit,
1776 // this makes it possible to system keys work properly.
1777 if(v->keyPressed>0 && !v->ctrl && !v->alt)
1778 {
1779 // Send keyboard output to the window
1780 cmd->id = GSID_KEYPRESSED;
1781 cmd->v[0] = v->keyPressed;
1782 sendMessage(&m, w->pid);
1783 }
1784}
1785
1786// Polling function called by graos loop
1787void guiServerPoll(VMODE *v)
1788{
1789 static MSG m;
1790
1791 // Send all proper messages to the application
1792 if(v->selwin)
1793 transmitInterfaceToApp(v, v->selwin);
1794
1795 // Receive new message
1796 if( receiveMessage(&m) )
1797 {
1798 // Message received, process it:
1799 guiServerProcessMessage(v, &m);
1800 }
1801}
1802
1803//
1804
1805
1806// =====================================================
1807// guiStart.c - GRAOS Windowing System
1808// (C) 2002-2003 by Jari Tuominen
1809// =====================================================
1810#include <stdio.h>
1811#include "graos.h"
1812#include "guiStart.h"
1813
1814//
1815int gui_LoadSystemFont(VMODE *v)
1816{
1817 // Regular
1818 LoadFont("guifont.raw", &v->font[0], 0);
1819 // Inverted
1820 LoadFont("guifont.raw", &v->font[1], 1);
1821}
1822
1823//
1824void guiVideoModeAlloc(VMODE *v, int width,int height, int bpp)
1825{
1826 // Video frame buffer
1827 v->buf = malloc(width*height);
1828 // Temporary buffer for directBlit conversions
1829 v->tmp = malloc(width*height);
1830 // Geometrics
1831 v->width = width;
1832 v->height = height;
1833 v->bpp = bpp;
1834 v->l_buf = width*height;
1835}
1836
1837//
1838void guiPrecalculate(VMODE *v)
1839{
1840 int i;
1841
1842 //
1843 for(i=0; i<v->height; i++)
1844 {
1845 //
1846 v->mtab[i] = i*v->width;
1847 }
1848}
1849
1850// Return value:
1851// Zero = No error
1852// Non-zero = Error
1853int guiVideoMode(VMODE *v, int width,int height, int bpp)
1854{
1855 static char str[256];
1856
1857 //
1858 sprintf(str, "%s: GUI video mode = %dx%d %d BPP\n",
1859 __FUNCTION__,
1860 width, height, bpp); DebugMessage(str);
1861
1862 // 640x480 256c emulation with 640x480 16c VGA
1863 if(width==640 && height==480 && bpp==8)
1864 {
1865 setmode(0x12);
1866 guiVideoModeAlloc(v, 640,480,8);
1867 guiPrecalculate(v);
1868 gui_FastClearScreen();
1869 return 0;
1870 }
1871
1872 // 640x480 monochrome
1873 if(width==640 && height==480 && bpp==1)
1874 {
1875 setmode(0x11);
1876 guiVideoModeAlloc(v, 640,480,1);
1877 guiPrecalculate(v);
1878 gui_FastClearScreen();
1879 return 0;
1880 }
1881
1882 // Failed to setup the video mode?
1883 printf("guiVideoMode: Unknown video mode '%dx%d %d BPP'\n",
1884 width,height, bpp);
1885 return 1;
1886}
1887
1888//
1889void InitVMODEStruct(VMODE *v)
1890{
1891 //
1892 memset(v, 0, sizeof(VMODE));
1893}
1894
1895// Start GUI
1896int guiStart(void)
1897{
1898 int i;
1899 VMODE *v;
1900
1901 // Open debug stream
1902 OpenDebugStream("graos.log");
1903
1904 //---------------------------------------------------------------------
1905 // Init general
1906 v = malloc( sizeof(VMODE) );
1907 InitVMODEStruct(v);
1908 v->cycle = 0;
1909 // Init window database
1910 wdbInit();
1911
1912 //---------------------------------------------------------------------
1913 if( (i=guiVideoMode(v, 640,480,8)) ) return NULL;
1914 gui_LoadSystemFont(v);
1915 LoadBin("mousecursor.raw", v->cursorRaw, 32*32);
1916 if(v->bpp==8)
1917 LoadBin("taskbar8.raw", v->taskbarRaw, 640*30);
1918 else
1919 LoadBin("taskbar.raw", v->taskbarRaw, 640*30);
1920 v->change=1;
1921
1922 //---------------------------------------------------------------------
1923 // Load background(if any)
1924 if(0)
1925 {
1926nullbk:
1927 printf("Background image = NULL\n");
1928 v->background = NULL;
1929 v->l_background = 0;
1930 }
1931 else
1932 {
1933 printf("Loading background image\n");
1934 v->l_background = 640*480;
1935 v->background = malloc(v->l_background);
1936 if(LoadBin("background.raw", v->background, 640*480))
1937 goto nullbk;
1938 }
1939
1940 //---------------------------------------------------------------------
1941 // Clear screen after background image is available
1942 gui_ClearScreen(v);
1943
1944 //---------------------------------------------------------------------
1945 // Start GUI server
1946 //
1947 guiServerInit();
1948
1949 //---------------------------------------------------------------------
1950 // Start taskbar application
1951 //
1952 if( bgexec("taskbar", "/bin")==0 )
1953 {
1954 PopUpWindow(v, "Error",
1955 "Error while trying to run taskbar program.");
1956 }
1957
1958 //---------------------------------------------------------------------
1959 // Pop up some demo windows
1960 //
1961// PopUpWindow(v, "System installation",
1962// "This is just a test version of the installer.\nClick window to close it.");
1963
1964
1965 //
1966 return v;
1967}
1968
1969
1970
1971
1972// ============================================
1973// guiTaskbar.c - Taskbar Renderation Program
1974// (C) 2002-2003 by Jari Tuominen
1975// ============================================
1976#include <stdio.h>
1977#include <math.h>
1978#include <time.h> // DATE -structure & getdate -function
1979#include "graos.h"
1980#include "guiTaskbar.h"
1981#include "guiArrow.h"
1982
1983//
1984int taskbarVirgin=1;
1985
1986//
1987struct
1988{
1989 int update;
1990 int lt;
1991}taskbar;
1992
1993//
1994void guiTaskbarCall(VMODE *v)
1995{
1996 int x,y,mx,my;
1997 char str[256];
1998 DATE d;
1999
2000 // Init on first run
2001 if(taskbarVirgin)
2002 {
2003 //
2004 taskbar.update = 1;
2005 taskbarVirgin = 0;
2006 taskbar.lt = GetSeconds();
2007 }
2008
2009 // Trigger taskbar refresh
2010 if( (GetSeconds()-taskbar.lt)>=4 )
2011 {
2012 //
2013 taskbar.lt = GetSeconds();
2014 taskbar.update = 1;
2015 }
2016
2017 // If refresh requested render taskbar
2018 if(taskbar.update)
2019 {
2020 //
2021 taskbar.update = 0;
2022
2023 // Get date
2024 getdate(&d);
2025
2026 // Draw taskbar
2027 guiWriteArea(v, 0,v->height-30, 640,v->height,
2028 v->taskbarRaw);
2029
2030 // Render clock
2031 sprintf(str, "%d:%d:%d",
2032 d.hour, d.minute, d.second);
2033 // Draw clock -string with inverted font
2034 DrawTextEx(v, &v->font[0],
2035 str,
2036 v->width - (strlen(str)+1)*8, v->height-8-10,
2037 TRANSPARENT,
2038 0x07);
2039 }
2040}
2041
2042//
2043
2044
2045// -------------------------------------------------------
2046// guiUpdate.c - GRAOS Windowing System
2047// (C) 2002-2003 by Jari Tuominen
2048// -------------------------------------------------------
2049#include <stdio.h>
2050#include <jtmos/video.h>
2051#include "graos.h"
2052#include "guiUpdate.h"
2053
2054// src ptr, dst offs, length
2055//
2056// Simulates 640x480 8-bit mode blit with 640x480 16c planed mode
2057void directBlit8(VMODE *v, int srcoffs, int dstoffs, int len)
2058{
2059 static int x,y,i,i2,i3,i4,pl;
2060 static BYTE *s,*o;
2061 static BYTE *plane[4];
2062 static BYTE *tmp;
2063 static BYTE bits[8]={128,64,32,16,8,4,2,1};
2064 static BYTE Xbits[8]={255-128,255-64,255-32,
2065 255-16,255-8,255-4,255-2,255-1};
2066 static BYTE *src;
2067
2068 //
2069 tmp = v->tmp;
2070 src=v->buf+srcoffs;
2071
2072 // Define planes
2073 for(i=0; i<4; i++) { plane[i] = v->tmp + i*len; }
2074
2075 // Render each planes
2076 // 4 planes(bits per color) = 16 colors
2077 for(pl=0; pl<4; pl++)
2078 {
2079 //
2080 for(i=0,s=src; i<len; i++)
2081 {
2082 //
2083 if( s[i]>15 ) s[i]=15;
2084 if( (s[i]&bits[7-pl])!=0 )
2085 plane[pl][i>>3] |= bits[i&7];
2086 else
2087 plane[pl][i>>3] &= Xbits[i&7];
2088 }
2089 }
2090
2091 // Copy planes to VGA ram
2092 for(pl=0; pl<4; pl++)
2093 {
2094 // Select appropriate VGA plane
2095 vgaselectplane(pl);
2096 // Copy to VGA RAM
2097 drawframe(plane[pl], dstoffs>>3, len>>3);
2098 }
2099}
2100
2101// 8 bpp
2102void guiUpdate8(VMODE *v)
2103{
2104 static int i,i2,i3,i4,x,y,ad,ii;
2105 static BYTE bits[8]={128,64,32,16,8,4,2,1,0,0,0,0,0,0,0,0};
2106
2107 //
2108 for(i=0,v->ulines=0; i<v->height; i++)
2109 if(v->dtab[i])v->ulines++;
2110
2111 //
2112 for(y=0,ad=0; y<v->height; y++,ad+=v->width)
2113 {
2114 //
2115 for(ii=0,i4=0; ii<(RADI+1); ii++,i4+=(v->width/RADI))
2116 {
2117 //
2118 //if(v->dtab[y]) // & bits[ii])
2119 if(v->dtab[y] & bits[ii])
2120 {
2121 //
2122 v->dtab[y] &= bits[ii]^0xFF;
2123 // src offs, dst offs, length
2124 directBlit8(v, ad+i4, ad+i4, v->width/RADI);
2125 }
2126 }
2127 }
2128}
2129
2130// 1 bpp
2131void guiUpdate1(VMODE *v)
2132{
2133 int i,i2,x,y,ad;
2134
2135 //
2136 for(y=0,ad=0; y<v->height; y++,ad+=(v->width>>3))
2137 {
2138 //
2139 if(v->dtab[y])
2140 {
2141 //
2142 v->dtab[y]=0;
2143 drawframe-(v->buf+ad, ad, v->width);
2144 }
2145 }
2146}
2147
2148// Update visible screen
2149void guiUpdate(VMODE *v)
2150{
2151 waitretrace();
2152 if(v->change)
2153 {
2154 v->change = 0;
2155 switch(v->bpp)
2156 {
2157 // --: Monochrome
2158 case 1:
2159 guiUpdate1(v);
2160 break;
2161 // --: VGA 8-bit
2162 case 8:
2163 guiUpdate8(v);
2164 break;
2165 // --: UNKNOWN
2166 default:
2167 break;
2168 }
2169 }
2170}
2171
2172#include <stdio.h>
2173main()
2174{
2175 printf("Test\b\b\b\b\n");
2176}
2177// ----------------------------------------------------------------
2178// wdb.c - GRAOS Window Database
2179// (C) 2002-2003 by Jari Tuominen(jari.tuominen@kanetti.net)
2180// ----------------------------------------------------------------
2181#include <stdio.h>
2182#include <conio.h> // Color defs
2183#include "graos.h"
2184#include "wdb.h"
2185
2186//--------------------------------------------------------------
2187// Create Window Database Structure
2188WDB wdb;
2189
2190//
2191static winposx=0,winposy=0;
2192
2193// Get window automatic position
2194void autoGetWinPos(VMODE *v,
2195 int *x,int *y, int width,int height)
2196{
2197 // Rewind back on boundary skips
2198 if( (winposx+width) >= v->width )
2199 winposx=0;
2200 if( (winposy+height) >= v->height )
2201 winposy=0;
2202
2203 // Set auto position
2204 *x = winposx;
2205 *y = winposy;
2206
2207 // Increase autoposition for next time
2208 winposx+=16; winposy+=16;
2209}
2210
2211//--------------------------------------------------------------
2212// Switch to next window on list
2213// (CTRL+TAB)
2214//
2215void switchToNextWindow(VMODE *v)
2216{
2217 WINDOW *w,*nw;
2218
2219 // Get current window
2220 if( (w = v->selwin)==NULL )
2221 {
2222 // If no window selected, get any window from the WDB
2223 w = getAnyWindow(0);
2224 }
2225
2226 // Get next window on the list
2227 nw = getNextWindow(w);
2228
2229 //------------------------------------------
2230 // Select the window
2231 if(nw)
2232 SelectWindow(v, nw);
2233}
2234
2235//--------------------------------------------------------------
2236// Return pointer to specified
2237// window pointed by window ID.
2238WINDOW *getWindowPTR(int wid)
2239{
2240 //
2241 return &wdb.w[wid];
2242}
2243
2244// Searches for a window and returns PTR to it,
2245// begID defines the first window entry
2246// to begin the search at.
2247WINDOW *getAnyWindow(int begID)
2248{
2249 int id,i;
2250 WINDOW *ww;
2251
2252 // Get ID
2253 id = begID;
2254
2255 // Exceeding amount of windows?
2256 if(id >= wdb.n_windows)
2257 {
2258 // Rewind to 0
2259 id = 0;
2260 }
2261
2262 // Search for first non-free window
2263 for(i=id; i<wdb.n_windows; i++)
2264 {
2265 // Get window PTR
2266 ww = &wdb.w[i];
2267
2268 // This window is active?
2269 if(ww->isfree==FALSE)
2270 // Return the window PTR
2271 return ww;
2272 }
2273
2274 //
2275 return NULL;
2276}
2277
2278// Get next window, starting from the specified window
2279// Returns NULL if none found
2280WINDOW *getNextWindow(WINDOW *w)
2281{
2282 int nid;
2283 WINDOW *ww;
2284
2285 // Handle NULL PTRs
2286 if(w==NULL)
2287 // Begin from zero
2288 nid = 0;
2289 else
2290 // Get next linear ID
2291 nid = w->id+1;
2292
2293 // Search for the window
2294 if( (ww=getAnyWindow(nid))!=NULL )
2295 // Return handle
2296 return ww;
2297 else
2298 // Try searching from the beginning
2299 return getAnyWindow(0);
2300}
2301
2302// Select a window, so it becomes on top
2303void SelectWindow(VMODE *v, WINDOW *w)
2304{
2305 // Set previously selwin (if any) to refresh status
2306 if(v->selwin)
2307 v->selwin->refresh = 1|2; // window + components
2308
2309 // Move window on top of all windows
2310 putWindowOnTop(v, w);
2311
2312 // Select new window
2313 v->selwin = w;
2314
2315 // Set window to refresh
2316 w->refresh = 1|2; // window + components
2317}
2318
2319// Returns window ID(wid)
2320int guiCreateWindow(VMODE *v,
2321 int x,int y,
2322 int width,int height,
2323 const char *caption,
2324 int type)
2325{
2326 int id,i,i2,i3,i4;
2327 WINDOW *w;
2328 static char str[256];
2329
2330 //
2331 sprintf(str, "%s: creating new window:\n",
2332 __FUNCTION__); DebugMessage(str);
2333 sprintf(str, "%s: x=%d, y=%d, width=%d, height=%d, caption='%s'\n",
2334 __FUNCTION__,
2335 x,y,width,height,caption); DebugMessage(str);
2336
2337 //
2338 if(caption==NULL)return 2;
2339
2340 // Get new window ID
2341 id = emptyWDB(); if(id==-1)return 1;
2342 if( (w=GetWindowPTR(id))==NULL )return 3;
2343 //
2344 printf("Window ID = %d\n", id);
2345
2346 // -------------------------------------------
2347 // Clear structure at the first place
2348 memset(w, 0, sizeof(WINDOW));
2349
2350 // -------------------------------------------
2351 // Set window type
2352 w->type = type;
2353
2354 // Define window ID
2355 w->id = id;
2356
2357 // Define window geometric parameters
2358 if(x==-1 || y==-1)
2359 {
2360 //
2361 autoGetWinPos(v, &w->x,&w->y, width,height);
2362 }
2363 else
2364 {
2365 w->x = x; w->y = y;
2366 }
2367
2368 //
2369 w->width = width; w->height = height;
2370 // Define last coordinates as "none" (-1, -1)
2371 w->lx=-1;
2372 w->ly=-1;
2373 // Define Z-coordinate
2374 wdb.top_z++; w->z = wdb.top_z;
2375
2376 // -------------------------------------------
2377 // Define parameters according settings
2378 //
2379
2380 // Set border width
2381 if(w->type&WINDOW_HAS_BORDER)
2382 {
2383 // Define border width
2384 w->borderWidth = DEF_BORDERWIDTH;
2385 }
2386 else
2387 {
2388 // Define empty border
2389 w->borderWidth = 0;
2390 }
2391
2392 // Define client area according does
2393 // window have a caption or not.
2394 if( (w->type&WINDOW_HAS_CAPTION) )
2395 {
2396 // Define client area
2397 w->client.x = 0;
2398 w->client.y = 22-3;
2399 // II
2400 w->client.width = w->width-(w->client.x*2);
2401 w->client.height = w->height-(w->client.y*2);
2402 }
2403 else
2404 {
2405 // Define client area
2406 w->client.x = 0;
2407 w->client.y = 0;
2408 // II
2409 w->client.width = w->width-(w->client.x*2);
2410 w->client.height = w->height-(w->client.y*2);
2411 }
2412
2413 // Copy caption string
2414 strcpy(w->caption, caption);
2415
2416 // Request refresh for this window
2417 w->refresh = 1|2; // window + components
2418
2419 // Create window close button if requested
2420 if(w->type&WINDOW_CLOSE_BUTTON)
2421 {
2422 // Close button creation
2423 guiCreateButton(w, 0,0,0,0,
2424 WINDOW_CLOSE_BUTTON | EXIT_ON_CLICK,
2425 "");
2426 }
2427
2428 // Select new window as default
2429 SelectWindow(v, w);
2430
2431 // Return window ID
2432 return id;
2433}
2434
2435// Init window database
2436void wdbInit(void)
2437{
2438 int i,i2,i3,i4;
2439
2440 //
2441 memset(&wdb, 0, sizeof(WDB));
2442
2443 //
2444 for(i=0; i<N_MAX_WINDOWS; i++)
2445 {
2446 // Set window ID
2447 wdb.w[i].id = i;
2448
2449 // Set window entry as free
2450 wdb.w[i].isfree = 1;
2451 }
2452}
2453
2454// Create new window
2455int newWDB(void)
2456{
2457 //
2458 if( (wdb.n_windows+2)>=N_MAX_WINDOWS )return -1;
2459 wdb.n_windows++;
2460 return wdb.n_windows-1;
2461}
2462
2463// Other values = New Window ID
2464int emptyWDB(void)
2465{
2466 int i,i2,i3,i4;
2467
2468 //
2469 for(i=0; i<wdb.n_windows; i++)
2470 {
2471 if(wdb.w[i].isfree)
2472 {
2473def:
2474 wdb.w[i].isfree=0;
2475 return i;
2476 }
2477 }
2478
2479 //
2480 i = newWDB();
2481 goto def;
2482}
2483
2484// Get count of windows
2485int GetNWindows(void)
2486{
2487 //
2488 return wdb.n_windows;
2489}
2490
2491//
2492void *GetWindowPTR(int id)
2493{
2494 //
2495 if(id<0 || id>wdb.n_windows) return NULL;
2496 return &wdb.w[id];
2497}
2498
2499//
2500int DeleteWindow(int id)
2501{
2502 //
2503 if(id<0 || (id+2)>=wdb.n_windows) return 1;
2504
2505 //
2506 wdb.w[id].isfree=1;
2507
2508 //
2509 return 0;
2510}
2511
2512//
2513
2514//==================================================
2515// windowDraw.c
2516// Functions that draw the core window on screen.
2517// (C) 2003 by Jari Tuominen
2518//==================================================
2519#include <stdio.h>
2520#include <conio.h> // Color defs
2521#include "graos.h"
2522#include "wdb.h" // Window Database
2523#include "windowDraw.h"
2524#include "framebuf.h"
2525
2526// Draw a window
2527int windowDraw(VMODE *v, WINDOW *w)
2528{
2529 int x1,y1,x2,y2,color,
2530 i,i2,i3,i4;
2531
2532 // Ignore freed windows
2533 if(w->isfree)
2534 return 1;
2535
2536 //--------------------------------------------------------------------
2537 // WINDOW BORDER + CAPTION + ETC. (1)
2538
2539 // If window refresh needed
2540 if( (w->refresh&1) )
2541 {
2542 // Restore old window area, if one
2543 // exists at the present moment.
2544 if(w->lx!=-1 && w->ly!=-1)
2545 eraseArea(v,
2546 w->lx-w->borderWidth, w->ly-w->borderWidth,
2547 w->lx+w->width+w->borderWidth+1, w->ly+w->height+w->borderWidth+1);
2548
2549 // Define last x,y
2550 w->lx=w->x;
2551 w->ly=w->y;
2552
2553 // Get rectangle area
2554 x1 = w->x; y1 = w->y;
2555 x2 = x1+w->width; y2 = y1+w->height;
2556
2557 // Fill window area
2558 if(w->type&WINDOW_AUTOCLEAR)
2559 // Automatically clear window area
2560 fillRect(v, x1,y1,x2,y2, 7);
2561
2562 //----------------------------------------------------------
2563 // Fill headline area
2564
2565 //
2566 if(w->type&WINDOW_HAS_CAPTION)
2567 {
2568 // Active or deactive window? (BLUE or GREY)
2569 if(w==v->selwin)
2570 color = BLUE;
2571 else
2572 color = 8;
2573 fillRect(v, x1,y1,x2,y1+2+16, color);
2574 }
2575
2576 //----------------------------------------------------------
2577 // Write headline text
2578 //
2579 if(strlen(w->caption))
2580 DrawText(v, w->caption, x1+2+2,y1+2+4, TRANSPARENT, 0x0f);
2581
2582 //----------------------------------------------------------
2583 // Draw border
2584 //
2585 if(w->type&WINDOW_HAS_BORDER)
2586 {
2587 //
2588 for(i=1; i<2; i++)
2589 {
2590 //
2591 drawRect(v, x1-i,y1-i,x2+i,y2+i, BLACK);
2592 }
2593 }
2594
2595 // Draw quick message if one exists
2596 if(strlen(w->qmsg))
2597 DrawText(v, w->qmsg, x1+w->client.x, y1+w->client.y,
2598 TRANSPARENT, 0x0f);
2599 }
2600
2601 //--------------------------------------------------------------------
2602 // COMPONENTS (2)
2603 if( w->refresh&2 )
2604 {
2605 // Draw all frame buffers
2606 drawWindowFrameBuffers(v, w);
2607 }
2608
2609 // If window's button(s) refresh is needed
2610 if(w->refreshButtons || (w->refresh&2) )
2611 {
2612 // Draw all buttons that this window has
2613 drawWindowButtons(v, w);
2614 }
2615
2616 //
2617 return 0;
2618}
2619
2620// Draw all buttons that the window has
2621int drawWindowButtons(VMODE *v, WINDOW *w)
2622{
2623 int i,i2,x1,y1,x2,y2;
2624 BUTTON *b;
2625
2626 // Get rectangle area
2627 x1 = w->x; y1 = w->y;
2628 x2 = x1+w->width; y2 = y1+w->height;
2629
2630 //
2631 for(i=0; i<w->n_buttons; i++)
2632 {
2633 // Get button
2634 b = &w->button[i];
2635 if(b->isfree)continue;
2636
2637 /* // Check for refresh requirement
2638 if(b->refresh==0 && !w->refresh)
2639 continue;
2640 else
2641 // Flag as refreshed
2642 b->refresh=0;*/
2643
2644 // Draw button
2645 if( (b->type&WINDOW_CLOSE_BUTTON) )
2646 {
2647 // Define button's area
2648 b->x1 = (x2-14-2)-x1;
2649 b->y1 = (y1+2+2)-y1;
2650 b->x2 = (x2-2-2)-x1;
2651 b->y2 = (y1+14+2)-y1;
2652 b->x1+=2;
2653 b->x2+=2;
2654 b->y1-=1;
2655 b->y2-=1;
2656 // Draw button
2657 buttonDraw(v, b->x1+x1,b->y1+y1,b->x2+x1,b->y2+y1,
2658 b->pressed, b->caption);
2659 }
2660 else
2661 {
2662 // Custom button
2663
2664 // Draw button
2665 buttonDraw(v, b->x1+x1,b->y1+y1,b->x2+x1,b->y2+y1,
2666 b->pressed, b->caption);
2667 }
2668 }
2669
2670 //
2671 return 0;
2672}
2673
2674// Draw a button
2675int buttonDraw(VMODE *v,
2676 int x1,int y1,int x2,int y2,
2677 int pressed,
2678 const char *caption)
2679{
2680 int color,
2681 i,i2,i3,i4,c1,c2,c3,x,y;
2682
2683 //
2684 if(pressed==0)
2685 {
2686 c1 = 15;
2687 c2 = 7;
2688 c3 = 0;
2689 }
2690 else
2691 {
2692 c1 = 0;
2693 c2 = 7;
2694 c3 = 15;
2695 }
2696
2697 // Draw button main color
2698 fillRect(v, x1,y1,x2,y2, c2);
2699
2700 // Draw outlines
2701 fillRect(v, x1,y1,x2,y1, c1);
2702 fillRect(v, x1,y1,x1,y2, c1);
2703 fillRect(v, x2,y1,x2,y2, c3);
2704 fillRect(v, x1,y2,x2,y2, c3);
2705
2706 // Draw button message
2707 if(strlen(caption))
2708 {
2709 //
2710 x = ((x2-x1)>>1) - (strlen(caption)>>1)*8;
2711 y = ((y2-y1)>>1)-4;
2712
2713 //
2714 DrawText(v, caption, x1+x,y1+y,
2715 TRANSPARENT,
2716 BLACK);
2717 }
2718}
2719
2720
2721
2722// windowFunc.c
2723#include <stdio.h>
2724#include "graos.h"
2725#include "windowFunc.h"
2726#include "graosprotocol.h"
2727#include "framebuf.h"
2728
2729// Handle button click events
2730void onButtonClick(VMODE *v, WINDOW *w, BUTTON *b)
2731{
2732 // If exit on click
2733 if( (b->type&EXIT_ON_CLICK) )
2734 {
2735 // Close the window
2736 guiCloseWindow(v, w);
2737 }
2738}
2739
2740// Posts exit request to the owner of the window
2741void PostQuitToWindowOwner(WINDOW *w)
2742{
2743 GUICMD *cmd;
2744 static MSG m;
2745
2746 // Get GUICMD PTR
2747 cmd = &m.buf;
2748
2749 // Define "exit"
2750 cmd->id = GSID_EXIT;
2751
2752 // Send GSID_EXIT to the application
2753 sendMessage(&m, w->pid);
2754}
2755
2756// Unpress all buttons in specified window
2757void unpressAllButtons1(WINDOW *w)
2758{
2759 int i,i2;
2760 BUTTON *b;
2761
2762 //
2763 for(i=0; i<w->n_buttons; i++)
2764 {
2765 // Get PTR
2766 b = &w->button[i];
2767
2768 // Skip deallocated buttons
2769 if(b->isfree)
2770 continue;
2771
2772 // unpress it
2773 if(b->pressed!=0)
2774 {
2775 //
2776 b->pressed = 0;
2777 b->refresh = 1;
2778 w->refreshButtons=1;
2779 w->refresh |= 2; // refresh components
2780 }
2781 }
2782}
2783
2784// Unpress buttons in all windows
2785void unpressAllButtons(VMODE *v)
2786{
2787 int i,i2;
2788 WINDOW *w;
2789
2790 //
2791 for(i=0; i<wdb.n_windows; i++)
2792 {
2793 // Get window PTR
2794 w = &wdb.w[i];
2795
2796 // Skip deallocated windows
2797 if(w->isfree)
2798 continue;
2799
2800 //
2801 unpressAllButtons1(w);
2802 }
2803}
2804
2805// Find an empty button entry
2806BUTTON *getNewButton(WINDOW *w)
2807{
2808 int i,i2;
2809 BUTTON *b;
2810
2811 //
2812 for(i=0; i<w->n_buttons; i++)
2813 {
2814 //
2815 b = &w->button[i];
2816
2817 //
2818 if(b->isfree)
2819 {
2820 //
2821 b->isfree=0;
2822 return b;
2823 }
2824 }
2825
2826 // Reserve new button entry
2827 b = &w->button[w->n_buttons];
2828 w->n_buttons++;
2829 b->isfree = 0;
2830 return b;
2831}
2832
2833// Create a button to a window
2834BUTTON *guiCreateButton(WINDOW *w,
2835 int x1,int y1,int x2,int y2,
2836 int type,
2837 const char *caption)
2838{
2839 BUTTON *b;
2840
2841 // Get new button entry PTR
2842 if( (b=getNewButton(w))==NULL )
2843 return NULL;
2844
2845 // Store caption
2846 strcpy(b->caption, caption);
2847
2848 // Store type
2849 b->type = type;
2850
2851 // Store coordinates
2852 b->x1 = x1;
2853 b->x2 = x2;
2854 b->y1 = y1;
2855 b->y2 = y2;
2856
2857 // Return PTR
2858 return b;
2859}
2860
2861// Close window
2862void guiCloseWindow(VMODE *v, WINDOW *w)
2863{
2864 //
2865 if(w==NULL || v==NULL)
2866 return;
2867
2868 // Already closed?
2869 if(w->isfree)
2870 // Already closed, return back...
2871 // (prevents infinite loop)
2872 return;
2873
2874 // Hide window
2875 HideDrawWindow(v, w);
2876
2877 // Post "exit now" message to the application
2878 PostQuitToWindowOwner(w);
2879
2880 // Free window
2881 w->isfree = TRUE;
2882}
2883
2884
2885// Hide window from screen by drawing
2886// (used by close window e.g.)
2887void HideDrawWindow(VMODE *v, WINDOW *w)
2888{
2889 // Erase window's area
2890 eraseArea(v,
2891 w->x-w->borderWidth, w->y-w->borderWidth,
2892 w->x+w->width+w->borderWidth+1, w->y+w->height+w->borderWidth+1);
2893
2894 // Estimate which windows needs to be redrawn after the operation
2895 EstimateWindowCollision(w);
2896}
2897
2898// Set window to close on click
2899void WindowClickQuit(int wid)
2900{
2901 //
2902 wdb.w[wid].clickQuit = TRUE;
2903}
2904
2905// Set window quick message
2906void SetQuickMessage(int wid, const char *msg)
2907{
2908 //
2909 if(strlen(msg)<200)
2910 strcpy(wdb.w[wid].qmsg, msg);
2911}
2912
2913// Create a new pop up window (used for quick system messages)
2914int PopUpWindow(VMODE *v, const char *caption, const char *msg)
2915{
2916 int wid,width,height;
2917
2918 // Define size
2919 width=400;
2920 height=64;
2921
2922 // Create the window
2923 wid = guiCreateWindow(v,
2924 (v->width>>1)-(width>>1), (v->height>>1)-(height>>1),
2925 width,height,
2926 caption,
2927 STANDARD_WINDOW);
2928
2929 // Set quick message
2930 SetQuickMessage(wid, msg);
2931
2932 // Set window so that it closes on click
2933 WindowClickQuit(wid);
2934
2935 // Return window ID
2936 return wid;
2937}
2938
2939//
2940int rectInsideRect(int x1,int y1,int x2,int y2,
2941 int xx1,int yy1,int xx2,int yy2)
2942{
2943 //
2944 if( pointInsideRect(xx1, yy1,
2945 x1,y1,x2,y2) )
2946 return 1;
2947
2948 //
2949 if( pointInsideRect(xx1, yy2,
2950 x1,y1,x2,y2) )
2951 return 1;
2952
2953 //
2954 if( pointInsideRect(xx2, yy1,
2955 x1,y1,x2,y2) )
2956 return 1;
2957
2958 //
2959 if( pointInsideRect(xx2, yy2,
2960 x1,y1,x2,y2) )
2961 return 1;
2962
2963 //
2964 return 0;
2965}
2966
2967//
2968int pointInsideRect(int x,int y,
2969 int x1,int y1,int x2,int y2)
2970{
2971 //
2972 if(x>=x1 && y>=y1
2973 &&
2974 x<x2 && y<y2)
2975 {
2976 //
2977 return 1;
2978 }
2979 else return 0;
2980}
2981
2982// Checks whether if there is a button under cursor,
2983// if so, it'll return handle to the button,
2984// if not it'll return NULL.
2985BUTTON *getButtonUnderCursor(VMODE *v)
2986{
2987 WINDOW *w;
2988 BUTTON *b;
2989 int i,i2;
2990
2991 // Get the window
2992 w = getWindowUnderCursor(v);
2993
2994 // Check which button
2995 for(i=0; i<w->n_buttons; i++)
2996 {
2997 // Get button
2998 b = &w->button[i];
2999
3000 // Check cursor x,y to it's region
3001 if( pointInsideRect(v->x, v->y,
3002 b->x1+w->x, b->y1+w->y, b->x2+w->x, b->y2+w->y) )
3003 {
3004 // Found button under cursor
3005 return b;
3006 }
3007 }
3008
3009 // No button found under cursor
3010 return NULL;
3011}
3012
3013// Returns handle to the window under mouse cursor
3014WINDOW *getWindowUnderCursor(VMODE *v)
3015{
3016 //
3017 return getWindowUnderCursorEx(v, 0);
3018}
3019
3020// Returns handle to a window that is under the mouse cursor,
3021// if none detected then it returns NULL.
3022WINDOW *getWindowUnderCursorEx(VMODE *v, int headline)
3023{
3024 int i,i2,level;
3025 WINDOW *w,*found;
3026
3027 //
3028 for(i=0,level=-1,found=NULL; i<wdb.n_windows; i++)
3029 {
3030 // Get window
3031 w = &wdb.w[i];
3032
3033 // Skip deallocated windows
3034 if(w->isfree)
3035 continue;
3036
3037 // Check if cursor is within this window's area
3038 if(
3039 (!headline && pointInsideRect(v->x, v->y,
3040 w->x, w->y, w->x+w->width, w->y+w->height))
3041 ||
3042 (headline && pointInsideRect(v->x, v->y,
3043 w->x, w->y, w->x+w->width, w->y+16))
3044 )
3045 {
3046 // If we have got a
3047 // greater level window then pick it first
3048 if(w->z > level)
3049 {
3050 // Cursor inside this window
3051 found = w;
3052
3053 //
3054 level = w->z;
3055 }
3056 }
3057 }
3058
3059 // None of windows inside the cursor
3060 return found;
3061}
3062
3063//
3064
3065
3066
3067// windowMoving.c
3068#include <stdio.h>
3069#include "graos.h"
3070#include "windowMoving.h"
3071
3072// Window moving functionallity
3073int windowMoving(VMODE *v)
3074{
3075 // CONTROL PART
3076 //--------------------------------------------
3077
3078
3079 //--------------------------------------------
3080 // Initially unpress all buttons
3081 unpressAllButtons(v);
3082
3083
3084 //--------------------------------------------
3085 // Get button under cursor
3086 v->underbut = getButtonUnderCursor(v);
3087 // Get window too (needed later)
3088 v->underwin = getWindowUnderCursorEx(v, AREA_WINDOW);
3089
3090 // We have got a button under cursor?
3091 if(v->underbut)
3092 {
3093 //
3094 if(v->buttons&1)
3095 {
3096 // Press button
3097 if(v->underbut->pressed==0)
3098 {
3099 //
3100 v->underbut->pressed=1;
3101 v->underbut->refresh=1;
3102 //
3103 v->underwin->refreshButtons=1;
3104 v->underwin->refresh |= 2; // refresh components
3105
3106 // Click click handler
3107 onButtonClick(v, v->underwin, v->underbut);
3108 }
3109 }
3110 else
3111 {
3112 // Unpress button
3113 if(v->underbut->pressed!=0)
3114 {
3115 //
3116 v->underbut->pressed=0;
3117 v->underbut->refresh=1;
3118 //
3119 v->underwin->refreshButtons=1;
3120 v->underwin->refresh |= 2; // refresh components
3121 }
3122 }
3123
3124 //
3125 return 0;
3126 }
3127
3128
3129
3130
3131 //--------------------------------------------
3132 // Get window under cursor
3133 v->underwin = getWindowUnderCursorEx(v, AREA_WINDOW);
3134
3135 // Window under cursor?
3136 if(v->underwin)
3137 {
3138 // Single click to close window?
3139 if(v->buttons&1 && v->underwin->clickQuit)
3140 {
3141 //
3142 guiCloseWindow(v, v->underwin);
3143 return 0;
3144 }
3145 }
3146
3147
3148
3149
3150 //--------------------------------------------
3151 // Get window headline under cursor
3152 v->underwin = getWindowUnderCursorEx(v, AREA_CAPTION);
3153
3154 // If window under cursor
3155 if(v->underwin)
3156 {
3157 // Enable moving
3158 //---------------
3159
3160 // If mouse button 1 hit:
3161 if(v->buttons&1 && !v->movingWindow)
3162 {
3163 // Make window selected
3164
3165 // Got old selwin and it's not same as this?
3166 if(v->selwin && v->selwin!=v->underwin)
3167 // Set it to refresh
3168 v->selwin->refresh = 1|2; // window & components
3169
3170 // Assign selwin
3171 v->selwin = v->underwin;
3172
3173
3174 // Start moving the window
3175
3176 // Set moving on
3177 v->movingWindow=1;
3178 // Assign window
3179 v->movwin = v->underwin;
3180 // Define origo
3181 v->origx = v->x;
3182 v->origy = v->y;
3183 // Define old position
3184 v->oldx = v->underwin->x;
3185 v->oldy = v->underwin->y;
3186
3187 // Put window on top
3188 putWindowOnTop(v, v->movwin);
3189 }
3190
3191 // Release window from moving after the button is released
3192 if((v->buttons&1)==0)
3193 {
3194 // If we were moving a window
3195 if(v->movingWindow && v->movwin)
3196 {
3197 // Set movwin to refresh
3198 v->movwin->refresh = 1|2;
3199
3200 // Undefine movwin
3201 v->movwin=NULL;
3202 }
3203
3204 // Moving mode off
3205 v->movingWindow=0;
3206
3207 // Redraw needed windows
3208 RedrawCollisionedWindows(v);
3209 }
3210 }
3211
3212 // MOVER PART
3213 //--------------------------------------------
3214
3215 // If we're now moving a window
3216 if(v->movingWindow)
3217 {
3218 // Move the window
3219 v->movwin->x = (v->x - v->origx) + v->oldx;
3220 v->movwin->y = (v->y - v->origy) + v->oldy;
3221 // Trigger refresh
3222 v->movwin->refresh=1|2;
3223
3224 // Put other windows on redraw
3225 // which are collisioned with
3226 EstimateWindowCollision(v->movwin);
3227 }
3228
3229 //
3230 return 0;
3231}
3232
3233//
3234
3235
3236// windowOrder.c
3237#include <stdio.h>
3238#include "graos.h"
3239#include "windowOrder.h"
3240
3241// Put window on top (visibility)
3242int putWindowOnTop(VMODE *v, WINDOW *w)
3243{
3244 // Increase top Z-coordinate
3245 wdb.top_z++;
3246
3247 // Define window on top
3248 w->z = wdb.top_z;
3249}
3250
3251//
3252
3253
3254
3255//=======================================================
3256// WINDOWS SYSTEM CALL
3257// windows.c
3258//=======================================================
3259#include <stdio.h>
3260#include "graos.h"
3261#include "windows.h"
3262
3263//
3264static FILE *dbg;
3265
3266// Called in the end
3267void exitAllApplications(VMODE *v)
3268{
3269 int i;
3270 WINDOW *w;
3271
3272 // Send QUIT message to all windows
3273 for(i=0; i<wdb.n_windows; i++)
3274 {
3275 // Get PTR
3276 w = GetWindowPTR(i);
3277
3278 // Skip empty entries
3279 if(w->isfree)
3280 continue;
3281
3282 // Post quit message
3283 PostQuitToWindowOwner(w);
3284 }
3285
3286 // Wait 2 seconds
3287 sleep(2);
3288
3289 // Terminate all windows
3290 for(i=0; i<wdb.n_windows; i++)
3291 {
3292 // Get PTR
3293 w = GetWindowPTR(i);
3294
3295 // Skip empty entries
3296 if(w->isfree)
3297 continue;
3298
3299 // Terminate PID
3300 KillThread(w->pid);
3301 }
3302}
3303
3304// Open debug stream
3305void OpenDebugStream(const char *name)
3306{
3307 //
3308 dbg = fopen(name, "wb");
3309}
3310
3311// Close debug stream
3312void CloseDebugStream(void)
3313{
3314 //
3315 fclose(dbg);
3316}
3317
3318// Output debug message to the debug stream
3319void DebugMessage(const char *s)
3320{
3321 //
3322 fputs(s, dbg);
3323}
3324
3325// Draws all windows, and so on..
3326int guiWindowSystemCall(VMODE *v)
3327{
3328 int i,i2,i3,i4;
3329 WINDOW *w;
3330 void *p1,*p2;
3331
3332 //------------------------------------------------------
3333 // Build a list of windows to draw
3334 // and sort list according Z-coordinate
3335 // of all windows.
3336
3337 // Rest list
3338 for(i=0; i<wdb.n_windows; i++)
3339 wdb.o[i] = NULL;
3340
3341 // Get all windows which require a refresh
3342 for(i=0,wdb.n_o=0; i<wdb.n_windows; i++)
3343 {
3344 // Get window PTR
3345 w = &wdb.w[i];
3346
3347 // Skip deallocated entries
3348 if(w->isfree)
3349 continue;
3350
3351 // Requires a refresh?
3352 if(w->refresh || w->refreshButtons)
3353 {
3354 // Add to the list
3355 wdb.o[wdb.n_o] = w;
3356 wdb.n_o++;
3357 }
3358 }
3359
3360 // Sort the list according Z-coordinates
3361 for(i2=0; i2<wdb.n_o; i2++)
3362 {
3363 // Go through all entries
3364 for(i=0; i<wdb.n_o; i++)
3365 {
3366 // Skip NULL entries
3367 if(wdb.o[i+1]==NULL || wdb.o[i]==NULL)
3368 continue;
3369
3370 // Compare Z-coordinates
3371 if(wdb.o[i]->z > wdb.o[i+1]->z)
3372 {
3373 // Swap entries
3374 p1 = wdb.o[i+0];
3375 p2 = wdb.o[i+1];
3376 wdb.o[i+1] = p1;
3377 wdb.o[i+0] = p2;
3378 }
3379 }
3380 }
3381
3382 //------------------------------------------------------
3383 // Trigger refresh on windows which might get below
3384 // lesser priority windows. This is a fix.
3385 //
3386 // Note: disable this handling if window refreshing
3387 // is too slow.
3388 //
3389/** for(i=0; i<wdb.n_o; i++)
3390 {
3391 //
3392 EstimateWindowCollision(wdb.o[i]);
3393 }**/
3394
3395 //-----------------------------------------------------
3396 // Draw all windows in correct order
3397 //
3398 for(i=0; i<wdb.n_o; i++)
3399 {
3400 // Get window PTR
3401 w = wdb.o[i];
3402
3403 // Skip deallocated windows
3404 if(w->isfree)
3405 continue;
3406
3407 // Process if it is not a NULL PTR
3408 if(w)
3409 {
3410 // Redraw if [refresh] is set
3411 if(w->refresh)
3412 {
3413 // Window draw
3414 windowDraw(v, w);
3415
3416 // Zero refresh
3417 w->refresh=0;
3418 }
3419 }
3420 }
3421
3422 //
3423 return 0;
3424}
3425
3426//
3427int windowFollow(WINDOW *w, int x,int y)
3428{
3429 int ox,oy;
3430
3431 // Get old coords
3432 ox=windowX(w); oy=windowY(w);
3433 // Follow
3434 ox=follow(ox, x); oy=follow(oy, y);
3435 // Set new coords
3436 moveWindowAt(w, ox,oy);
3437}
3438
3439//
3440int windowX(WINDOW *w)
3441{
3442 //
3443 return w->x;
3444}
3445
3446//
3447int windowY(WINDOW *w)
3448{
3449 //
3450 return w->y;
3451}
3452
3453//
3454int moveWindowAt(WINDOW *w, int x,int y)
3455{
3456 //
3457 w->x = x;
3458 w->y = y;
3459 w->refresh = 1;
3460}
3461
3462
3463
3464#ifndef __INCLUDED_COLLISION_H__
3465#define __INCLUDED_COLLISION_H__
3466
3467//
3468int EstimateWindowCollision(WINDOW *ww);
3469int RedrawCollisionedWindows(VMODE *v);
3470
3471#endif
3472
3473
3474#ifndef __INCLUDED_FRAMEBUF_H__
3475#define __INCLUDED_FRAMEBUF_H__
3476
3477//
3478FRAMEBUF *newFrameBuf(WINDOW *w);
3479int drawFB(VMODE *v, WINDOW *w, FRAMEBUF *fb);
3480int drawWindowFrameBuffers(VMODE *v, WINDOW *w);
3481int guiAddFrameBuffer(WINDOW *w,
3482 BYTE *buf, int x, int y,
3483 int width, int height, int bpp,
3484 int type,
3485 int terID);
3486DWORD chksum(BYTE *buf, int len);
3487int automaticallyRefreshTerminalWindows(VMODE *v);
3488
3489#endif
3490
3491
3492#ifndef __INCLUDED_GRAOS_H__
3493#define __INCLUDED_GRAOS_H__
3494
3495#include <stdio.h>
3496#include "window.h" // WINDOW -structure
3497#include "config.h" // Configuration
3498
3499// Max. window collisions to indicate at once
3500#define MAX_COLLISION 1024
3501
3502//
3503#define RADI 8
3504
3505//
3506#define dprintf printf
3507
3508//
3509#ifdef DJGPP
3510#define HOST_OS "DOS (DJGPP)"
3511#endif
3512
3513#ifdef WINDOWS
3514#define HOST_OS "Windows"
3515#endif
3516
3517#ifdef LINUX
3518#define HOST_OS "Linux"
3519#endif
3520
3521#ifdef UNIX
3522#define HOST_OS "UNIX (unknown)"
3523#endif
3524
3525#ifdef JTMOS
3526#define HOST_OS "JTMOS"
3527#endif
3528
3529//
3530typedef struct
3531{
3532 BYTE *buf;
3533 int l_buf,width,height,bpp;
3534}FONT;
3535
3536// Video mode aka display structure
3537typedef struct
3538{
3539 // Null space
3540 long long nothing,nothing2;
3541 // Key pressed
3542 int keyPressed,alt,ctrl;
3543 // Data space
3544 int width,height,bpp,ulines;
3545 BYTE *buf,*tmp;
3546 int l_buf;
3547 FONT font[10];
3548 int change;
3549 int cycle;
3550 // Y-lines update values
3551 BYTE dtab[1280];
3552 // Multiplying table for width*y
3553 DWORD mtab[1280];
3554 // 640x480 background image(NULL if none)
3555 BYTE *background;
3556 int l_background;
3557 //
3558 BYTE taskbarRaw[(640*30)+10];
3559 BYTE cursorRaw[(32*32+10)];
3560 BYTE cursorBehind[(32*32+10)];
3561 char cursorBehindActive;
3562 //
3563 int lx,ly, buttons, x,y;
3564
3565 // Window under cursor
3566 WINDOW *underwin;
3567
3568 // Button under cursor
3569 BUTTON *underbut;
3570
3571 // Currently selected window
3572 WINDOW *selwin;
3573
3574 // Currently moving window
3575 WINDOW *movwin;
3576
3577 // Currently moving a window: [TRUE or FALSE]
3578 int movingWindow;
3579 // Origo for cursor movement
3580 int origx,origy;
3581 // Old window position for moving
3582 int oldx,oldy;
3583}VMODE;
3584
3585int main(int argc, const char **argv);
3586
3587#include "guiApp.h"
3588#include "guiTaskbar.h"
3589#include "guiEnd.h"
3590#include "guiLoop.h"
3591#include "guiStart.h"
3592#include "guiUpdate.h"
3593#include "guidot.h"
3594#include "guifont.h"
3595#include "guifunc.h"
3596#include "guiBlit.h"
3597#include "guiRect.h"
3598#include "wdb.h"
3599#include "guiDesktopDraw.h"
3600#include "windowMoving.h"
3601#include "windowOrder.h"
3602#include "windowFunc.h"
3603#include "graosprotocol.h"
3604
3605#endif
3606
3607//-------------------------------------------------------------------------
3608// GRAOS PROTOCOL STRUCTURE AND TYPE DEFINITIONS
3609//-------------------------------------------------------------------------
3610#ifndef __INCLUDED_GRAOSPROTOCOL_H__
3611#define __INCLUDED_GRAOSPROTOCOL_H__
3612
3613
3614//-----------------------------------------------------------------
3615// Window types
3616//
3617
3618// Window type options
3619#define WINDOW_CLOSE_BUTTON 1
3620#define EXIT_ON_CLICK 2
3621#define WINDOW_HAS_CAPTION 4
3622#define WINDOW_HAS_BORDER 8
3623#define WINDOW_AUTOCLEAR 16
3624
3625//
3626#define STANDARD_BUTTON 0
3627
3628// Standard window type
3629#define STANDARD_WINDOW WINDOW_HAS_CAPTION \
3630 | WINDOW_CLOSE_BUTTON \
3631 | WINDOW_HAS_BORDER \
3632 | WINDOW_AUTOCLEAR
3633
3634// Taskbar window (stand-alone)
3635#define TASKBAR_WINDOW 0
3636
3637//-----------------------------------------------------------------
3638// Frame buffer type
3639//
3640#define TYPE_TERMINAL_EMULATION 1
3641#define TYPE_BITMAP_SCREEN 2
3642
3643//-----------------------------------------------------------------
3644// GUI server responds with this command
3645//
3646#define GSID_RESPONSE 1
3647// Application sent "open window" -command
3648#define GSID_OPENWINDOW 2
3649// Application sent "close window" -command
3650#define GSID_CLOSEWINDOW 3
3651// User commanded program to exit
3652// (this message is sent to application,
3653// graos closes the window before sending it.)
3654#define GSID_EXIT 4
3655// Add a bitmap image buffer region
3656// within window's client area
3657#define GSID_ADDFRAMEBUFFER 5
3658// Window contents have changed,
3659// therefore this command will be
3660// sent to the GUI server.
3661#define GSID_REQUESTREFRESH 6
3662// When key is pressed on the selected
3663// window, this message is sent to
3664// the application.
3665#define GSID_KEYPRESSED 7
3666// Button creation.
3667#define GSID_CREATEBUTTON 8
3668
3669//-----------------------------------------------------------------
3670// GUICMD packet structure
3671//
3672typedef struct
3673{
3674 // 0xFCE2E37B
3675 DWORD magic;
3676
3677 // Which window
3678 int wid;
3679
3680 // Command ID
3681 int id;
3682
3683 // Return value (used for answer packets)
3684 DWORD rval;
3685
3686 // Misc. string (e.g. caption)
3687 char str[256];
3688
3689 // Values
3690 int v[20];
3691
3692 // Pointers
3693 BYTE *ptr[20];
3694}GUICMD;
3695
3696#endif
3697
3698#ifndef __INCLUDED_GUIAPP_H__
3699#define __INCLUDED_GUIAPP_H__
3700
3701#include "graos.h"
3702void guiApplicationCall(VMODE *v);
3703
3704#endif
3705#ifndef __INCLUDED_GUIARROW_H__
3706#define __INCLUDED_GUIARROW_H__
3707
3708void UndoOldArrow(VMODE *v);
3709void StoreNewArrow(VMODE *v);
3710
3711#endif
3712
3713#ifndef __INCLUDED_GUIBLIT_H__
3714#define __INCLUDED_GUIBLIT_H__
3715
3716//
3717int guiReadArea(VMODE *v, int x1,int y1, int x2,int y2, BYTE *buf);
3718int guiWriteArea(VMODE *v, int x1,int y1, int x2,int y2, BYTE *buf);
3719int guiWriteArea1(VMODE *v, int x1,int y1, int x2,int y2, BYTE *buf);
3720void guiMark(VMODE *v,
3721 int _x1, int _x2, int y1, int y2);
3722int guiBlit(VMODE *v,
3723 int x1,int y1,int x2,int y2,
3724 BYTE *src,int swidth,int sheight);
3725
3726#endif
3727
3728#ifndef __INCLUDED_CONFIG_H__
3729#define __INCLUDED_CONFIG_H__
3730
3731//
3732extern int XON_SYSTEM_METERS;
3733
3734#endif
3735
3736
3737#ifndef __INCLUDED_GUIDESKTOPDRAW_H__
3738#define __INCLUDED_GUIDESKTOPDRAW_H__
3739
3740int guiDesktopDraw(VMODE *v, int x1,int y1, int x2,int y2);
3741int guiDesktopDraw8(VMODE *v, int x1,int y1, int x2,int y2);
3742
3743#endif
3744
3745#ifndef __INCLUDED_GUIDOT_H__
3746#define __INCLUDED_GUIDOT_H__
3747
3748#include "graos.h"
3749
3750int gui_dotSetBPP1(VMODE *v, int x,int y, int state);
3751int gui_dotRemoveBPP1(VMODE *v, int x,int y);
3752int gui_dotSet(VMODE *v, int x,int y);
3753int gui_dotRemove(VMODE *v, int x,int y);
3754int gui_dotGetBPP1(VMODE *v, int x,int y);
3755int gui_dotGet(VMODE *v, int x,int y);
3756int gui_dotPut(VMODE *v, int x,int y, int va);
3757void DrawDot(VMODE *v, int x,int y, char state);
3758int gui_dotPutBPP8(VMODE *v, int x,int y, int va);
3759int gui_dotGetBPP8(VMODE *v, int x,int y);
3760
3761#endif
3762
3763#ifndef __INCLUDED_GUIEND_H__
3764#define __INCLUDED_GUIEND_H__
3765
3766#include <stdio.h>
3767#include "graos.h"
3768
3769void guiEnd(VMODE *v);
3770
3771#endif
3772
3773#ifndef __INCLUDED_GUIFONT_H__
3774#define __INCLUDED_GUIFONT_H__
3775
3776// For font renderation function
3777#define NON_TRANSPARENT 0
3778#define TRANSPARENT 1
3779#define NON_THIN 2
3780
3781//
3782#include <stdio.h>
3783#include "graos.h"
3784
3785int LoadFont(const char *fname, FONT *fon, int invert);
3786void DrawText(VMODE *v, const char *s, int tx,int ty,
3787 int t, int color);
3788void DrawTextEx(VMODE *v, FONT *f, const char *s, int tx,int ty,
3789 int transparency, int color);
3790void DrawTextColorful(VMODE *v,
3791 FONT *f,
3792 const char *s, int tx,int ty,
3793 int transparency,
3794 char *colmap, int color);
3795void _DrawText(VMODE *v,
3796 const char *s,long x,long y,
3797 const char *font,long font_width,long font_height,
3798 int transparency,
3799 char *colmap, int color);
3800
3801#endif
3802#ifndef __INCLUDED_GUIFUNC_H__
3803#define __INCLUDED_GUIFUNC_H__
3804
3805#include <stdio.h>
3806#include "graos.h"
3807
3808void DrawMonoBitmapEx(VMODE *v,
3809 BYTE *srcbuf,long s_width,long s_height,BYTE *pal,
3810 long target_x, long target_y,
3811 long wanted_width,long wanted_height,
3812 long source_x, long source_y,
3813 int tr);
3814
3815void DrawMonoBitmap(VMODE *v,
3816 BYTE *srcbuf,long s_width,long s_height,BYTE *pal,
3817 long target_x, long target_y,
3818 long wanted_width,long wanted_height,
3819 long source_x, long source_y);
3820void DrawTransparentMonoBitmap(VMODE *v,
3821 BYTE *srcbuf,long s_width,long s_height,BYTE *pal,
3822 long target_x, long target_y,
3823 long wanted_width,long wanted_height,
3824 long source_x, long source_y);
3825
3826void gui_DrawBitmap(VMODE *v,
3827 BYTE *src, int swidth, int sheight, BYTE *pal,
3828 int xp, int yp,
3829 int lenx,int leny,
3830 int Xread,int Yread);
3831
3832void gui_ClearScreen(VMODE *v);
3833int waitkey(void);
3834int LoadBin(const char *fname, BYTE *buf, int limit);
3835int follow(int what, int dest);
3836void DrawMonoBitmapColor(VMODE *v,
3837 BYTE *srcbuf,long s_width,long s_height,BYTE *pal,
3838 long target_x, long target_y,
3839 long wanted_width,long wanted_height,
3840 long source_x, long source_y,
3841 int color,
3842 char drawbackground);
3843
3844#endif
3845#ifndef __INCLUDED_GUILOOP_H__
3846#define __INCLUDED_GUILOOP_H__
3847
3848#include <stdio.h>
3849#include "graos.h"
3850void guiLoop(VMODE *v);
3851
3852#endif
3853
3854#ifndef __INCLUDED_GUIRECT_H__
3855#define __INCLUDED_GUIRECT_H__
3856
3857#include <stdio.h>
3858#include "graos.h"
3859
3860int fillRect(VMODE *v, int x1,int y1, int x2, int y2, int vari);
3861int drawRect(VMODE *v, int x1,int y1, int x2, int y2, int vari);
3862int eraseArea(VMODE *v, int x1,int y1, int x2,int y2);
3863
3864#endif
3865
3866
3867#ifndef __INCLUDED_GUISERVER_H__
3868#define __INCLUDED_GUISERVER_H__
3869
3870//
3871#include "graosprotocol.h"
3872
3873//
3874void guiServerInit(void);
3875int guiServerProcessMessage(VMODE *v, MSG *m);
3876void guiServerPoll(VMODE *v);
3877
3878#endif
3879
3880
3881#ifndef __INCLUDED_GUISTART_H__
3882#define __INCLUDED_GUISTART_H__
3883
3884extern VMODE vmode;
3885
3886int guiStart(void);
3887
3888#endif
3889
3890#ifndef __INCLUDED_GUITASKBAR_H__
3891#define __INCLUDED_GUITASKBAR_H__
3892
3893#include "graos.h"
3894void guiTaskbarCall(VMODE *v);
3895
3896#endif
3897#ifndef __INCLUDED_GUIUPDATE_H__
3898#define __INCLUDED_GUIUPDATE_H__
3899
3900#include <stdio.h>
3901#include "graos.h"
3902void guiUpdate(VMODE *v);
3903
3904#endif
3905
3906#ifndef __INCLUDED_WDB_H__
3907#define __INCLUDED_WDB_H__
3908
3909//
3910#define DEF_BORDERWIDTH 1
3911#define N_MAX_WINDOWS 50
3912
3913//
3914#include "window.h"
3915
3916//
3917typedef struct
3918{
3919 // Window structures
3920 WINDOW w[N_MAX_WINDOWS];
3921
3922 // Number of windows registered
3923 int n_windows;
3924
3925 // Top Z-coordinate for a window
3926 int top_z;
3927
3928 // Ordered windows list
3929 WINDOW *o[N_MAX_WINDOWS];
3930 int n_o;
3931}WDB;
3932extern WDB wdb;
3933
3934// Window manipulation functions prototypes
3935void wdbInit(void);
3936int newWDB(void);
3937int emptyWDB(void);
3938int GetNWindows(void);
3939void *GetWindowPTR(int id);
3940int DeleteWindow(int id);
3941int guiCreateWindow(VMODE *v,
3942 int x,int y,
3943 int width,int height,
3944 const char *caption,
3945 int type);
3946WINDOW *getWindowPTR(int wid);
3947WINDOW *getNextWindow(WINDOW *w);
3948WINDOW *getAnyWindow(int begID);
3949void SelectWindow(VMODE *v, WINDOW *W);
3950void autoGetWinPos(VMODE *v,
3951 int *x,int *y, int width,int height);
3952
3953#endif
3954
3955
3956#ifndef __INCLUDED_WINDOWDRAW_H__
3957#define __INCLUDED_WINDOWDRAW_H__
3958
3959//
3960int buttonDraw(VMODE *v,
3961 int x1,int y1,int x2,int y2,
3962 int pressed,
3963 const char *caption);
3964int windowDraw(VMODE *v, WINDOW *w);
3965int drawFB(VMODE *v, WINDOW *w, FRAMEBUF *fb);
3966int drawWindowFrameBuffers(VMODE *v, WINDOW *w);
3967
3968#endif
3969#ifndef __INCLUDED_WINDOWFUNC_H__
3970#define __INCLUDED_WINDOWFUNC_H__
3971
3972// for getWindowUnderCursorEx:
3973#define AREA_CAPTION 1
3974#define AREA_WINDOW 0
3975
3976//
3977#include <stdio.h>
3978#include "graos.h"
3979#include "window.h"
3980
3981//
3982void WindowClickQuit(int wid);
3983void SetQuickMessage(int wid, const char *msg);
3984int PopUpWindow(VMODE *v, const char *caption, const char *msg);
3985void HideDrawWindow(VMODE *v, WINDOW *w);
3986void guiCloseWindow(VMODE *v, WINDOW *w);
3987void onButtonClick(VMODE *v, WINDOW *w, BUTTON *b);
3988void PostQuitToWindowOwner(WINDOW *w);
3989
3990//
3991int pointInsideRect(int x,int y,
3992 int x1,int y1,int x2,int y2);
3993int rectInsideRect(int x1,int y1,int x2,int y2,
3994 int xx1,int yy1,int xx2,int yy2);
3995WINDOW *getWindowUnderCursor(VMODE *v);
3996WINDOW *getWindowUnderCursorEx(VMODE *v, int headline);
3997BUTTON *guiCreateButton(WINDOW *w,
3998 int x1,int y1,int x2,int y2,
3999 int type,
4000 const char *caption);
4001BUTTON *getNewButton(WINDOW *w);
4002void unpressAllButtons(VMODE *v);
4003void unpressAllButtons1(WINDOW *w);
4004
4005#endif
4006#ifndef __INCLUDED_WINDOW_H__
4007#define __INCLUDED_WINDOW_H__
4008
4009
4010// Frame buffer structure
4011typedef struct
4012{
4013 // Free: TRUE or FALSE
4014 char isfree;
4015
4016 // Frame buffer location inside
4017 // the window client area
4018 int x,y;
4019
4020 // Frame buffer width, height
4021 int width,height;
4022
4023 // Bits per pixel
4024 int bpp;
4025
4026 // PTR to the frame buffer
4027 BYTE *buf;
4028
4029 // Frame buffer type
4030 int type;
4031
4032 // Terminal ID
4033 int terID;
4034
4035 // 32-bit checksum values for each scanline
4036 // in the text terminal.
4037 // (only used in text terminals)
4038 DWORD chksum[50];
4039
4040 // Refresh table for all text lines
4041 DWORD rtab[50];
4042
4043 // Last cursor position
4044 int lcx,lcy;
4045
4046 // Current cursor position
4047 int cx,cy;
4048}FRAMEBUF;
4049
4050// Button structure
4051typedef struct
4052{
4053 // Properties
4054 char isfree;
4055 int pressed;
4056 int type; // WINDOW_CLOSE_BUTTON, EXIT_ON_CLICK
4057 char caption[100];
4058 char refresh;
4059 // Coordinates
4060 // (not always used)
4061 int x1,y1,x2,y2;
4062}BUTTON;
4063
4064// Button structure
4065typedef struct
4066{
4067 // Window ID ( same as wdb.w[ID] )
4068 int id;
4069 // Added to the size of the actual window
4070 int borderWidth;
4071 // Used by buttons mostly
4072 int pressed;
4073 //
4074 char isfree;
4075 int x,y, lx,ly;
4076 int width,height;
4077 DWORD type;
4078 char caption[100];
4079 char qmsg[210];
4080 // Drawing priority, windows with lower priority value
4081 // will be drawn last on the list, and so forth
4082 // the specified window will be also shown at the bottom
4083 // of the "window pool".
4084 // You could also call this "priority" variable as
4085 // one kind of Z-coordinate for the window.
4086 int z; // aka priority
4087 // This variable is triggered to 1 when
4088 // the window contents or other parameters
4089 // that affect it's visual approach have
4090 // been changed.
4091 // 1 = refresh whole window (borders, caption, etc.)
4092 // 2 = refresh window's components
4093 char refresh;
4094 char refreshButtons;
4095 // Collision indicator:
4096 // Indicates that another object has overwritten
4097 // this window's area, and the window needs to be
4098 // redrawn in a while.
4099 int collision;
4100 // Size of the caption area(height, default=20 pixels)
4101 int captionHeight;
4102 // Window closes on click? Values: TRUE / FALSE
4103 char clickQuit;
4104
4105 // Client area definition
4106 struct
4107 {
4108 int x,y;
4109 int width,height;
4110 }client;
4111
4112 //
4113 struct
4114 {
4115 //
4116 BYTE *buf; int l_buf;
4117 int width,height;
4118 }clientarea;
4119
4120 // All buttons this window has
4121 BUTTON button[10];
4122 int n_buttons;
4123
4124 // PID of the owner of this window
4125 int pid;
4126
4127 // Frame buffers
4128 FRAMEBUF framebuf[10];
4129 int n_framebuffers;
4130}WINDOW;
4131
4132//
4133#include "graosprotocol.h"
4134
4135#endif
4136
4137#ifndef __INCLUDED_WINDOWMOVING_H__
4138#define __INCLUDED_WINDOWMOVING_H__
4139
4140//
4141#include "graos.h"
4142
4143//
4144int windowMoving(VMODE *v);
4145
4146#endif
4147
4148#ifndef __INCLUDED_WINDOWORDER_H__
4149#define __INCLUDED_WINDOWORDER_H__
4150
4151//
4152int putWindowOnTop(VMODE *v, WINDOW *w);
4153
4154#endif
4155
4156
4157#ifndef __INCLUDED_WINDOWS_H__
4158#define __INCLUDED_WINDOWS_H__
4159
4160//
4161#include <stdio.h>
4162#include "graos.h"
4163
4164//
4165int guiWindowSystemCall(VMODE *v);
4166int moveWindowAt(WINDOW *w, int x,int y);
4167int windowX(WINDOW *w);
4168int windowY(WINDOW *w);
4169int windowFollow(WINDOW *w, int x,int y);
4170void CloseDebugStream(void);
4171void OpenDebugStream(const char *name);
4172void DebugMessage(const char *s);
4173void exitAllApplications(VMODE *v);
4174
4175#endif