home *** CD-ROM | disk | FTP | other *** search
- /********************************************************************/
- /**** ****/
- /**** ****/
- /**** Program : Intui.c ****/
- /**** ****/
- /**** Version : 01.00 ****/
- /**** ****/
- /**** Erstversion : 01.07.1990 ****/
- /**** ****/
- /**** Letzte Änderung : 08.08.1990 ****/
- /**** ****/
- /**** Compiliert mit : siehe MAKEFILE ****/
- /**** ****/
- /**** Gelinkt mit : siehe MAKEFILE ****/
- /**** ****/
- /********************************************************************/
- /**** ****/
- /**** ****/
- /**** Copyright by Rüdiger Dreier ****/
- /**** ****/
- /**** ****/
- /********************************************************************/
-
- /* Einbinden der Include-Files */
-
-
- struct IntuitionBase *IntuitionBase; /* Zeiger auf IntuitionBase */
- struct GfxBase *GfxBase; /* Zeiger auf Grafik-Library */
- struct ToolBase *ToolBase;
- struct Library *MathIeeeDoubTransBase;
- struct Library *MathIeeeDoubBasBase;
- struct Window *Window; /* Zeiger auf Fenster */
- struct RastPort *RastPort; /* Zeiger auf RastPort */
- struct Screen *Screen; /* Zeiger auf Screen */
- struct info msgInfo;
- struct Menu *Menu;
- extern struct NewWindow Fenster2;
-
- extern DOUBLE MatrixA[20][20];
- VOID NeueZahl(SHORT AlteZeile,SHORT AlteSpalte);
- VOID Loeschen(VOID);
-
- LONG Breite,Hoehe;
- SHORT AlteZeile=0,NeueZeile,AlteSpalte=0,NeueSpalte;
- char ZahlenWert[20];
- DOUBLE ZahlW;
-
- struct NewScreen Schirm=
- {
- 0,0,640,YSCREEN,2,2,1,HIRES,CUSTOMSCREEN,NULL,"Matrix",NULL,NULL
- };
-
- SHORT paare2[]=
- {
- -2,-1,121,-1,121,8,-2,8,-2,-1
- };
- struct Border Rand2=
- {
- 0,0,2,3,JAM2,5,(SHORT *)&paare2,NULL
- };
- struct IntuiText RechnenT=
- {
- 2,3,JAM2,0,0,NULL,"Gleichung lösen",NULL
- };
- struct StringInfo ZahlenWertS=
- {
- ZahlenWert,NULL,0,19,0,0,5,0,0,0,NULL,0,NULL
- };
- struct Gadget ZahlenWertG=
- {
- NULL,230,LINE3+5,120,10,GADGHCOMP,GADGIMMEDIATE|RELVERIFY,STRGADGET,(APTR)&Rand2,0,NULL,0,(APTR)&ZahlenWertS,2,0
- };
- struct Gadget RechnenG=
- {
- &ZahlenWertG,500,LINE3+5,120,8,GADGHCOMP,RELVERIFY|GADGIMMEDIATE,BOOLGADGET,(APTR)&Rand2,0,&RechnenT,NULL,NULL,4,0
- };
-
- struct NewWindow Fenster=
- {
- 0,10,640,YSCREEN-10,0,1,GADGETUP|MOUSEBUTTONS|MENUPICK,
- BORDERLESS|ACTIVATE,
- &RechnenG,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
- CUSTOMSCREEN
- };
-
- VOID _main(VOID)
- {
- if(oeffne()) /* Öffnen der Libraries, Screen, Fenster */
- {
- Move(RastPort,0,LINE1);
- Draw(RastPort,640,LINE1);
-
- Move(RastPort,0,LINE2);
- Draw(RastPort,640,LINE2);
-
- Move(RastPort,0,LINE3);
- Draw(RastPort,640,LINE3);
-
- NeueWerte();
- Darstellen(1,0); /* Stelle wird automatisch markiert */
- Eingabebereich();
-
- ActivateGadget(&ZahlenWertG,Window,NULL);
- Events(); /* Verwertet die Intuition-Messages */
- }
- ende(); /* Gibt den belegten Speicher wieder frei */
- }
-
- /* Öffnet Libraries, Screen, Window */
- SHORT oeffne(VOID)
- {
- SHORT Failed=0;
- if((ToolBase=(struct ToolBase *)OpenLibrary("tool.library",0)))
- {
- IntuitionBase =ToolBase->IntuitionBase;
- GfxBase =ToolBase->GfxBase;
- MathIeeeDoubBasBase =ToolBase->MathIeeeDoubBasBase;
- MathIeeeDoubTransBase=ToolBase->MathIeeeDoubTransBase;
- if((Screen=(struct Screen *)OpenScreen(&Schirm)))
- {
- Fenster.Screen=Screen; /* Fenster soll auf Screen erscheinen */
- if((Window=(struct Window *)OpenWindow(&Fenster)))
- {
- struct MenuItem *item;
- /* Zuweisung von Variablen, Einfärben des Windows */
- RastPort=Window->RPort; /* Variablenzuweisung */
- Failed=1; /* Nur wenn alles geklappt hat */
- Fenster3.Screen=Fenster2.Screen=Screen;
- Menu=AddMenu(Menu," Gleichungen",MENUENABLED);
- item=AddItem(Menu,"Neue Anzahl",ITEMTEXT|ITEMENABLED|HIGHCOMP,0);
- ((struct IntuiText *)item->ItemFill)->FrontPen=2;
- AddItem(Menu,"Löschen",ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ,'C');
- AddItem(Menu,"Lösen",ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ,'L');
- AddItem(Menu,"Laden",ITEMTEXT|ITEMENABLED|HIGHCOMP,0);
- AddItem(Menu,"Speichern",ITEMTEXT|ITEMENABLED|HIGHCOMP,0);
- AddItem(Menu,"About",ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ,'I');
- AddItem(Menu,"E N D E",ITEMTEXT|ITEMENABLED|HIGHCOMP,0);
- NewSetMenuStrip(Window,Menu);
- }
- }
- }
- return(Failed);
- }
-
-
- /* Routine, die alles wieder schließt */
- VOID ende(VOID)
- {
- LONG H;
- Delay(20);
-
- /* Wenn offen -> schließen */
- if(Window)
- {
- if(Window->MenuStrip)
- {
- ClearMenu(Window->MenuStrip);
- ClearMenuStrip(Window);
- }
- while(H=EventAbfrage(Window,&msgInfo));
- CloseWindow(Window);
- }
-
- if(Screen)CloseScreen(Screen);
-
- if(ToolBase)CloseLibrary((struct Library *)ToolBase);
- }
-
-
- /* Wertet Mausklick aus */
- VOID Events(VOID)
- {
- long item;
- USHORT menunr;
- LONG Mx,My;
- struct MenuItem *Item;
- char ENDE=1;
-
- while(ENDE)
- {
- /* Wartet auf Event */
- Wait(1L<<Window->UserPort->mp_SigBit);
- /* Arbeitet ab, bis keine Events mehr */
- while(EventAbfrage(Window,&msgInfo))
- {
- Mx=msgInfo.MouseX;
- My=msgInfo.MouseY;
- /* Verzweigt entsprechend der Events */
- switch(msgInfo.NachrichtenArt)
- {
- /* Menupunkt gewählt */
- case MENUPICK:
- {
- menunr=msgInfo.code;
-
- /* Wurde wirklich ein Menu gewählt ? */
- while(menunr!=MENUNULL)
- {
- item=ITEMNUM(menunr);
- /* Entsprechend des Menus verzweigen */
- switch (item)
- {
- case 0:
- {
- NeueWerte();
- }
- case 1:
- {
- Loeschen();
- Einsprung_I1:
- AlteSpalte=AlteZeile=0;
- Darstellen(1,0); /* Stelle wird automatisch markiert */
- Eingabebereich();
- ActivateGadget(&ZahlenWertG,Window,NULL);
- break;
- }
- case 2:
- {
- SHORT L;
- L=Loesen();
- Darstellen(0,L);
- ActivateGadget(&ZahlenWertG,Window,NULL);
- break;
- }
- case 3:
- {
- /* Laden */
- char Name[50];
- if(FileRequest(Window,"Laden",160,100,Name))
- {
- Werte_Laden(Name);
- }
- goto Einsprung_I1;
- }
- case 4:
- {
- /* Speichern */
- char Name[50];
- if(FileRequest(Window,"Speichern",160,100,Name))
- {
- Werte_Speichern(Name);
- }
- goto Einsprung_I1;
- }
- case 5:
- {
- About();
- break;
- }
- case 6:
- {
- ENDE=0;
- break;
- }
- }
- Item=ItemAddress(Menu,(LONG)menunr);
- menunr=Item->NextSelect;
- Item->NextSelect=MENUNULL;
- }
- break;
- }
- case GADGETUP:
- {
- if( (((struct Gadget *)msgInfo.IAddress)->GadgetID) ==4)
- {
- SHORT L;
- L=Loesen();
- Darstellen(0,L);
- ActivateGadget(&ZahlenWertG,Window,NULL);
- }
- else
- {
- UmwStoF(&ZahlW,ZahlenWert);
- MatrixE[AlteZeile][AlteSpalte]=ZahlW;
-
- /* Zahl ausgeben */
- NeueZahl(AlteZeile,AlteSpalte);
-
- AlteSpalte++;
- if(AlteSpalte==Spalten)
- {
- AlteZeile++;
- AlteSpalte=0;
- }
- if(AlteZeile==Zeilen)AlteZeile=0;
- Mark(AlteZeile,AlteSpalte);
- Eingabebereich();
- ActivateGadget(&ZahlenWertG,Window,NULL);
- }
- break;
- }
- case MOUSEBUTTONS:
- {
- if(My<97)
- {
- NeueSpalte=(Mx-12)/Breite;
- NeueZeile =(My-LINE1-1)/Hoehe;
- NeueZeile=min(NeueZeile,Zeilen-1);
- NeueZeile=max(0,NeueZeile); /* Um negative Werte zu verhindern */
- NeueSpalte=min(NeueSpalte,Spalten-1);
- if(NeueSpalte!=AlteSpalte || NeueZeile!=AlteZeile)
- {
- Mark(AlteZeile,AlteSpalte);
- AlteZeile=NeueZeile;
- AlteSpalte=NeueSpalte;
- Mark(AlteZeile,AlteSpalte);
- Eingabebereich();
- }
- ActivateGadget(&ZahlenWertG,Window,NULL);
- }
- break;
- }
- }
- }
- }
- }
-
-
- VOID Mark(SHORT y,SHORT x)
- {
- LONG xp,yp;
-
- xp=x*Breite+ABSTANDL;
- if(AlteSpalte==Spalten-1)
- {
- xp+=ABSTAND;
- }
- yp=y*Hoehe +LINE1+1;
- SetDrMd(RastPort,COMPLEMENT);
- RectFill(RastPort,xp,yp,xp+Breite-1,yp+Hoehe-1);
- SetDrMd(RastPort,JAM1);
- }
-
- VOID NeueZahl(SHORT AlteZeile,SHORT AlteSpalte)
- {
- LONG xp,yp;
- char Zahlen[20];
- /* Mark(AlteZeile,AlteSpalte); */
-
-
- xp=AlteSpalte*Breite+ABSTANDL;
- if(AlteSpalte==Spalten-1)
- {
- xp+=ABSTAND;
- }
- yp=AlteZeile*Hoehe +LINE1+1;
- SetAPen(RastPort,0);
- RectFill(RastPort,xp,yp,xp+Breite-1,yp+Hoehe-1);
-
- UmwFtoS(Zahlen,&MatrixE[AlteZeile][AlteSpalte],3);
- xp=xp+Breite-4-strlen(Zahlen)*8;
- yp=yp+6+(Hoehe-8)/2;
- Print(RastPort,Zahlen,1,xp,yp);
- }
-
- VOID Darstellen(SHORT y,SHORT L)
- {
- char Zahlen[20];
- SHORT i,j;
- LONG xp,yp;
- Mark(AlteZeile,AlteSpalte);
-
- if(y==0)
- {
- SetAPen(RastPort,0);
- RectFill(RastPort,0,LINE2+1,640,LINE3-1);
- SetAPen(RastPort,1);
- Move(RastPort,Breite*(Spalten-1)+15,LINE2+1);
- Draw(RastPort,Breite*(Spalten-1)+15,LINE3-24);
- Center(Window,"L ö s u n g",1,LINE2+12);
- for(i=0;i<Zeilen;i++)
- {
- for(j=0;j<Spalten;j++)
- {
- UmwFtoS(Zahlen,&MatrixA[i][j],3);
- xp=j*Breite+ABSTANDL+Breite-4-strlen(Zahlen)*8;
- if(j==Spalten-1)
- {
- xp+=ABSTAND;
- }
- yp=i*Hoehe +32+LINE2+(Hoehe-8)/2;
- Print(RastPort,Zahlen,1,xp,yp);
- }
- }
- if(L)
- {
- if(L==1)
- {
- Center(Window,"Nicht lösbar !",1,LINE3-6);
- }
- else
- {
- Center(Window,"Nicht eindeutig lösbar !",1,LINE3-6);
- }
- }
-
- }
- else
- {
- SetAPen(RastPort,0);
- RectFill(RastPort,0,LINE1+1,640,LINE2-1);
-
- SetAPen(RastPort,1);
- Move(RastPort,Breite*(Spalten-1)+15,LINE1+1);
- Draw(RastPort,Breite*(Spalten-1)+15,LINE2-1);
- for(i=0;i<Zeilen;i++)
- {
- for(j=0;j<Spalten;j++)
- {
- UmwFtoS(Zahlen,&MatrixE[i][j],3);
- NeueZahl(i,j);
- }
- }
- }
- Mark(AlteZeile,AlteSpalte);
- }
-
- VOID Eingabebereich(VOID)
- {
- char xs[8],ys[8];
- char Ausgabe[256];
- SetAPen(RastPort,0);
- RectFill(RastPort,154,LINE3+5,229,LINE3+15);
- UmwFtoS(ZahlenWert,&MatrixE[AlteZeile][AlteSpalte],3);
- if(!strcmp(ZahlenWert,"0"))ZahlenWert[0]=0;
- ZahlenWertS.BufferPos=0;
-
- stci_d(xs,AlteSpalte+1);
- stci_d(ys,AlteZeile+1);
- Print(RastPort,"Eingabe für : ",1,50,LINE3+13);
- strcpy(Ausgabe,ys);
- if(AlteZeile<9)
- {
- strcat(Ausgabe," ");
- }
- strcat(Ausgabe,", ");
- strcat(Ausgabe,xs);
- Print(RastPort,Ausgabe,1,155,LINE3+13);
- RefreshGList(&ZahlenWertG,Window,NULL,1);
- }
-
- VOID Loeschen(VOID)
- {
- SHORT i,j;
- SetAPen(RastPort,0);
- RectFill(RastPort,0,LINE2+1,640,LINE3-1);
- SetAPen(RastPort,1);
- Move(RastPort,Breite*(Spalten-1)+15,LINE2+1);
- Draw(RastPort,Breite*(Spalten-1)+15,LINE3-24);
- for(i=0;i<19;i++)
- {
- for(j=0;j<19;j++)
- {
- MatrixE[i][j]=0.0;
- }
- }
- }
-
-
- VOID MemCleanup(VOID)
- {
- }
-
-
- VOID chkabort(VOID)
- {
- }
-
-
-