home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
-
- #include <Xos.h>
- #include <Intrinsic.h>
- #include <StringDefs.h>
- #include <Xaw/Command.h>
- #include <Xaw/Label.h>
- #include <Xaw/Form.h>
- #include <Composite.h>
- #include "defs.h"
- #include "externs.h"
-
- Widget toplevel,form,quitbutton,statusline;
- Widget gradedisplay;
- Widget currentkanjiForm,currentkanjiGrade,currentkanjiFreq,currentkanjiNum;
- Widget kanjimode,englishmode,togglekana;
- Widget englishWidget[4],kanjiWidget[4];
-
- int gradelevel=0;
-
- char *gradelist[8] = {
- "Grade: All ",
- "Grade: One ",
- "Grade: Two ",
- "Grade: Three",
- "Grade: Four ",
- "Grade: Five ",
- "Grade: Six ",
- "Grade: ERROR!"
- };
- void changegrade(widget,data,calldata)
- Widget widget;
- XtPointer data; XtPointer calldata;
- {
- gradelevel = gradelevel +1;
- if(gradelevel ==7) gradelevel = 0;
-
- XtVaSetValues(widget,
- XtNlabel,gradelist[gradelevel],
- NULL);
-
- /* need to recount all kanji equal or below the current level */
- CountKanji();
- if(numberofkanji<9){
- XtVaSetValues(statusline,XtNlabel,"Too Few Kanji",NULL);
- fprintf(stderr,"Too Few Kanji\n");
- if(gradelevel==0){
- fprintf("You must have either a too-small usefile,or a corrupted kanjidic\n");
- exit(0);
- }
- changegrade(0,0,0);
- return;
- }
- /* and make another puzzle... */
- kanjitoenglish(Kanji2English);
- return;
- }
-
- /* DescribeCurrent()
- * Sets labels to display difficulty of
- * Current "true" kanji"
- */
- void DescribeCurrent(kanjinum)
- int kanjinum;
- {
- char gradelabel[10],freqlabel[10],numlabel[10];
-
-
-
- if(translations[kanjinum]->grade_level !=0){
- sprintf(gradelabel,"G: %4d",translations[kanjinum]->grade_level);
- } else {
- sprintf(gradelabel,"G: ");
- }
- if(translations[kanjinum]->frequency !=0){
- sprintf(freqlabel,"F: %4d",translations[kanjinum]->frequency);
- #ifdef DEBUG
- printf("Describing %x\n",kanjinum);
- printf("Freqnum %d\n",translations[kanjinum]->frequency);
- #endif
-
- } else {
- sprintf(freqlabel,"F: ");
- }
- sprintf(numlabel,"#: %4x",kanjinum);
-
- XtVaSetValues(currentkanjiGrade,XtNlabel,gradelabel,NULL);
- XtVaSetValues(currentkanjiFreq,XtNlabel,freqlabel,NULL);
- XtVaSetValues(currentkanjiNum,XtNlabel,numlabel,NULL);
- }
-
- /* MakeKanjiButtons()
- * set up kanji button widgets at initialization
- */
- void MakeKanjiButtons(){
- int i;
- /* make KANJI buttons */
- for(i=0;i<4;i++){
- char labl[20];
- sprintf(labl,"kanji%d",i);
-
- kanjiWidget[i]=XtVaCreateManagedWidget(
- labl,commandWidgetClass,
- form,
- XtNlabel,"",
- XtNwidth,50, XtNheight,50,
- XtNshapeStyle,XawShapeOval,
- XtNencoding,XawTextEncodingChar2b,
- XtNfont,largekfont,
- NULL);
- XtAddCallback(kanjiWidget[i],XtNcallback,kanjicallback,(XtPointer)i);
- if(i>0){
- XtVaSetValues(kanjiWidget[i],
- XtNfromHoriz,kanjiWidget[i-1],
- NULL);
- }
-
- }
- currentkanjiForm = XtVaCreateManagedWidget(
- "curkanjiForm",formWidgetClass,form,
- XtNhorizDistance,40,
- XtNright,XawChainRight,XtNleft,XawChainRight,
- XtNfromHoriz,kanjiWidget[3],NULL);
- currentkanjiGrade = XtVaCreateManagedWidget(
- "curkanjiGrade",labelWidgetClass,currentkanjiForm,
- XtNlabel,"G: ",
- NULL);
- currentkanjiFreq = XtVaCreateManagedWidget(
- "curkanjiFreq",labelWidgetClass,currentkanjiForm,
- XtNlabel,"F: ",
- XtNfromVert,currentkanjiGrade,
- NULL);
- currentkanjiNum = XtVaCreateManagedWidget(
- "curkanjiNum",labelWidgetClass,currentkanjiForm,
- XtNlabel,"#: ",
- XtNfromVert,currentkanjiFreq,
- NULL);
- }
- /* MakeEnglishButtons:
- * Just that. initialize the english buttons that display the possible
- * guesses.
- */
- void MakeEnglishButtons(){
- int i;
- for(i=0;i<4;i++){
- char labl[20];
- sprintf(labl,"english%d",i);
-
- englishWidget[i]=XtVaCreateManagedWidget(
- labl,commandWidgetClass,form,
- XtNwidth,320,
- XtNright,XawChainRight,
- XtNleft,XawChainLeft,
- XtNfont,fixedfont,
- NULL);
-
- XtAddCallback(englishWidget[i],XtNcallback,englishcallback,(XtPointer) i);
-
- if(i==0){
- XtVaSetValues(englishWidget[0],
- XtNfromVert,currentkanjiForm,
- XtNvertDistance,10,
- NULL);
- } else {
- XtVaSetValues(englishWidget[i],
- XtNfromVert,englishWidget[i-1],
- NULL);
- }
-
-
- }
- }
-
- void initfonts(){
- char LargeKname[100],SmallKname[100],Fixedname[100];
-
- GetXtString("kanjifont","Kanjifont",LargeKname);
- GetXtString("smallkanji","Smallkanji",SmallKname);
- GetXtString("font","Font",Fixedname);
-
- #ifdef DEBUG
- printf("kanjifont from resources is \"%s\"\n",LargeKname);
- printf("smallkanjifont from resources is \"%s\"\n",SmallKname);
- printf("regular font from resources is \"%s\"\n",Fixedname);
- #endif
- largekfont = XLoadQueryFont(display,LargeKname);
- smallkfont = XLoadQueryFont(display,SmallKname);
- fixedfont = XLoadQueryFont(display,Fixedname);
- if(largekfont == NULL){
- fprintf(stderr,"could not load large kanji font\n");
- exit(0);
- }
- if(smallkfont == NULL){
- fprintf(stderr,"could not load small kanji font\n");
- exit(0);
- }
- if(fixedfont == NULL){
- fprintf(stderr,"could not load english font??\n");
- exit(0);
- }
-
-
- }
-
- int MakeWidgets(){
- /* I suppose I shouldn't hard-code window-width and height..
- but it makes things easier for now.
- */
- form = XtVaCreateManagedWidget("kdrill",formWidgetClass,
- toplevel,
- XtNx,200, XtNy,100,
- NULL);
-
-
- display = XtDisplay(toplevel);
-
- initfonts();
-
- MakeKanjiButtons();
- MakeEnglishButtons();
-
- kanjimode = XtVaCreateManagedWidget(
- "kanjimode",commandWidgetClass, form,
- XtNlabel,"Guess kanji",
- XtNvertDistance,20,
- XtNfromVert,englishWidget[3],
- XtNshapeStyle,XawShapeOval,
- NULL);
- XtAddCallback(kanjimode,XtNcallback,ChangeMode,(XtPointer) GUESSKANJI);
-
- englishmode = XtVaCreateManagedWidget(
- "englishmode",commandWidgetClass, form,
- XtNlabel,"Guess Meaning",
- XtNvertDistance,20,
- XtNfromVert,englishWidget[3],
- XtNshapeStyle,XawShapeOval,
- XtNfromHoriz,kanjimode,
- NULL);
- XtAddCallback(englishmode,XtNcallback,ChangeMode,(XtPointer) GUESSMEANING);
-
- togglekana = XtVaCreateManagedWidget("togglekana",commandWidgetClass,
- form,
- XtNlabel,"English/Kana",
- XtNvertDistance,20,
- XtNfromVert,englishWidget[3],
- XtNshapeStyle,XawShapeOval,
- XtNfromHoriz,englishmode,
- NULL);
- XtAddCallback(togglekana,XtNcallback,ChangeMode,(XtPointer) TOGGLEKANA);
-
-
- quitbutton = XtVaCreateManagedWidget("quit",commandWidgetClass,
- form,
- XtNlabel,"quit",
- XtNfromVert,kanjimode,
- XtNshapeStyle,XawShapeEllipse,
- NULL);
-
- XtAddCallback(quitbutton,XtNcallback,quit,NULL);
-
- statusline = XtVaCreateManagedWidget("status",labelWidgetClass,
- form,
- XtNlabel,"Welcome to kanjidrill",
- XtNfromHoriz,quitbutton,
- XtNfromVert,kanjimode,
- XtNresize,True,
- NULL);
-
- gradedisplay = XtVaCreateManagedWidget(
- "gradedisplay",commandWidgetClass,form,
- XtNlabel,gradelist[gradelevel],
- XtNresize,False,
- XtNfromVert,kanjimode,
- XtNfromHoriz,statusline,
- NULL);
- XtAddCallback(gradedisplay,XtNcallback,changegrade,NULL);
-
- return 0;
- }
-