/[gzz]/gzz/doc/pegboard/1020/PEG_1020.rst
ViewVC logotype

Diff of /gzz/doc/pegboard/1020/PEG_1020.rst

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by tjl, Fri Oct 25 08:17:06 2002 UTC revision 1.6 by mudyc, Fri Oct 25 11:25:06 2002 UTC
# Line 11  PEG 1020: Calendar rendering Line 11  PEG 1020: Calendar rendering
11  Overview  Overview
12  --------  --------
13    
14  Calendar is a renderable which generates an annual calendar.  Calendar is a renderable which can be used to generate an annual calendar.
15  This is one of the vital components in PP-module/project.  This is one of the vital components in PP-module/project.
16    
17    
18  Basics  Basics
19  ------  ------
20    
21  One calendar is one year. Usually only parts of it are shown.  One calendar is one month. Usually only parts of it are shown.
22    The whole month is rendered every time.
23    
24    
25  Issues  Issues
26  ------  ------
27    
28  What is needed for Calendar?  What is needed from framework to render Calendar?
29    
30      -Coordinating system::      -Coordinating system:
31                               _______________
32                                              .......                                 |___________|_|
33          ----------                          . ----.-------          ----------         |_|_|_|_|_|_|_|
34          | Screen |    <----  mapping  <---  . | Ja.uary  |          | Screen |   <---  |_|_|_|_|_|_|_|
35          |        |                          . | Fe.r.    |          |        |         |_|_|_|_|_|_|_|
36          ----------                          .......ch    |          ----------         |_|_|_|_|_|_|_|
37                                                | Aprill   |                             |_|_|_________|
38                                                | May..    |          -object => window
39                                                --- -- - - ­  
40          -Summarum:  
41              -Two coordinating systems(cs) needed:      -Text ratio, (Form/layout):
42                  -Calendar cs          -Text's ratio to month's calendar skeleton *must* be
43                  -Screen cs           changeable from java side.
44    
45      -Localization:      -Localization:
46          -Months and Weekdays.          -Months and Weekdays.
47          -Solve in java side.          -Solve in java side.
48    
     -Speed  
         -Render with OpenGL in C++ side  
         -Use cpu wisely and draw only needed parts.  
   
   
     -Format/layout? ::  
   
           |---|  
           |   |  
           |---|      -----------...-------------  
           |   |      |   |   |     |   |   |   |  
           |---|      -----------...-------------  
           |   |            horizontal  
           |---|  
           .   .  
           .   .  
           .   .         -----------------  
           |---|         |   |   |   |   |  
           |   |         -----------------  
           |---|         |   |   |   |   |  
                         -----------------  
         vertical        |   |   |   |   |  
                         -----------------  
                              matrix  
   
   
 New Object  
 ----------  
   
     -Calendar object                
         -Year :int  
         -Months: string[12]  
         -Weekdays: string[7]  
49    
50          -these must be countable:  What is needed to make Calendar look good?
51              -first weekday of the Month ::  
52        -Month (and year)
53        -Weeknumbers
54        -Weekdays
55        -Date(s)
56        -Colors
57        -LineWidth
58        -Text:
59    
60    ------------------------------------------------------------------------------
61    |                                                                            |
62    |                             October 2002                                   |
63    |                                                                            |
64    |       Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Sunday |
65    +-----+--------+---------+-----------+----------+--------+----------+--------+
66    |x    |        |         |           |          |        |          |        |
67    |     |        |         |           |          |        |          |        |
68    |     |        |    1    |     2     |     3    |   4    |    5     |   6    |
69    |     |        |         |           |          |        |          |        |
70    +-----+--------+---------+-----------+----------+--------+----------+--------+
71    |x+1  |        |         |           |          |        |          |        |
72    |     |        |         |           |          |        |          |        |
73    |     |   7    |    8    |     9     |    10    |   11   |    12    |   13   |
74    |     |        |         |           |          |        |          |        |
75    +-----+--------+---------+-----------+----------+--------+----------+--------+
76    |x+2  |        |         |           |          |        |          |        |
77    |     |        |         |           |          |        |          |        |
78    |     |  etc.. |         |           |          |        |          |        |
79    
80    
81    |<-w->|<--d1-->|
82      
83            -w's ratio to d1
84            
85    ---------------------------   ---
86    |                             /|\
87    |                              m
88    |                              |
89    |       Monday | Tuesday |    \|/
90    +-----+--------+---------+-   ---
91    |x    |        |         |    /|\
92    |     |        |         |     d2
93    |     | empty  |    1    |     |
94    |     |        |         |    \|/
95    +-----+--------+---------+-  ----
96    
97            -m's ratio to d2
98    
99            -must know how many empty days,
100            -must know how many days and
101            -must know how many weeks in month:
102    
103    
104             April             December
105          ______________     _______________  
106          |_|_|_|_|_|_|_|    |___________|_|  
107          |_|_|_|_|_|_|_|    |_|_|_|_|_|_|_|
108          |_|_|_|_|_|_|_|    |_|_|_|_|_|_|_|
109          |_|_|_|_|_|_|_|    |_|_|_|_|_|_|_|
110          . here is     .    |_|_|_|_|_|_|_|
111          ....emptynes...    |_|_|_________|
112    
113    
114    
115                   _______________                     _______________  
116                   |___________|_|  /|\                   |___________|_|  /|\
# Line 90  New Object Line 120  New Object
120                   |_|_|_|_|_|_|_|   |                   |_|_|_|_|_|_|_|   |
121                   |_|_|_________|  \|/                   |_|_|_________|  \|/
122    
             -also days per month is needed  
   
   
 Prototypes etc.  
 ---------------  
   
     Open for comments.  
   
   
 TextPrototype  
 -------------  
   
 Code::  
   
     import java.util.*;  
   
     public class TextCalendar {  
         static void p(String s) { System.out.print(s); }  
         static void pln(String s) { System.out.println(s); }  
   
         // notice common factor, 12  
         private int weeks_in_month[] = new int[12];  
         private int empty_before_first_day[] = new int[12];  
         private int days_in_month[] = new int[12];  
   
           
         public TextCalendar() {  
   
             // get the supported ids for GMT-08:00 (Pacific Standard Time)  
             String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000);  
   
             // if no ids were returned, something is wrong. get out.  
             if (ids.length == 0)  
                 System.exit(0);  
   
             // create a Pacific Standard Time time zone  
             SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]);  
   
             // set up rules for daylight savings time  
             pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);  
             pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);  
             Calendar calendar = new GregorianCalendar(pdt);  
             calendar.setFirstDayOfWeek(Calendar.MONDAY);  
   
             Date date = new Date();  
             date.setYear(calendar.YEAR);  
   
             pln(" * Year: " + calendar.get(calendar.YEAR));  
   
             for (int month = 0; month < 12; month++) {  
   
                 // set first day of month  
                 date.setDate(1);  
                 date.setMonth(month);  
                 calendar.setTime(date);  
   
                 // print month  
                 p("\n" +  
                   monthStr(calendar.get(Calendar.MONTH)) +  
                   " " + (calendar.get(Calendar.MONTH)+1) +  
                   "\n   ");  
                   
                 // count empty day at the beginning of the month.  
                 if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {  
                     empty_before_first_day[month] = 6;  
                 } else {  
                     empty_before_first_day[month] =  
                         calendar.get(Calendar.DAY_OF_WEEK) - 2;  
                 }  
   
                 // print empty spaces at the beginning of month if needed..  
                 for (int i=0; i< empty_before_first_day[month]; i++) {  
                     p("      ");  
                 }  
   
   
                 // generate one month a day by day  
                 for (int day=1; day<33; day++) {  
                     date.setDate(day);  
                     calendar.setTime(date);  
   
                     // over-month checking  
                     if (date.getDate() < day) {  
                         days_in_month[month] = day - 1;  
                         break;  
                     }  
   
                     // print weekday and date  
                     p(dayStr(calendar.get(Calendar.DAY_OF_WEEK))+  
                       " " +  
                       calendar.get(Calendar.DATE) + ", "  
                       );  
   
                     // if sunday, print "\n" and increment weeks  
                     if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {  
                         p("\n   ");  
                         weeks_in_month[month] += 1;  
                     }  
                 }  
                 pln("\n **  Weeks: " + weeks_in_month[month] +  
                     ", " + empty_before_first_day[month] +  
                     " - empty days at the beginning of the month, " +  
                     days_in_month[month] +" days in month");  
             }  
   
         }  
   
   
         private String dayStr(int day) {  
   
             if ( day < Calendar.SUNDAY || day > Calendar.SATURDAY ) return "ERROR";  
   
             switch(day) {  
             case Calendar.MONDAY: return "Ma";  
             case Calendar.TUESDAY: return "Ti";  
             case Calendar.WEDNESDAY: return "Ke";  
             case Calendar.THURSDAY: return "To";  
             case Calendar.FRIDAY: return "Pe";  
             case Calendar.SATURDAY: return "La";  
             case Calendar.SUNDAY: return "Su";  
             }  
             return "Error";  
         }  
   
         private String monthStr(int month) {  
             if ( month < 0 || month > 11) return "ERROR";  
               
             String ret ="";  
   
             switch(month) {  
             case 0: ret = "Tammi"; break;  
             case 1: ret = "Helmi"; break;  
             case 2: ret = "Maalis"; break;  
             case 3: ret = "Huhti"; break;  
             case 4: ret = "Touko"; break;  
             case 5: ret = "Kesä";  break;  
             case 6: ret = "Heinä"; break;  
             case 7: ret = "Elo"; break;  
             case 8: ret = "Syys"; break;  
             case 9: ret = "Loka"; break;  
             case 10: ret = "Marras"; break;  
             case 11: ret = "Joulu"; break;  
             }  
             return ret + "kuu";  
         }  
   
   
         public static void main(String [] arg) {  
             TextCalendar c = new TextCalendar();  
         }  
     }  
   
   
   
 Still Very Problematic  
 ----------------------  
   
   _Coordinating system._  
   
   
 What is really needed with calendar?  
   
   
    while (yearHasMonthsLeft):  
   
       // draw month skeleton  
       draw skeleton( height[month] )  
       // height(weeks) is one of the arguments  
   
   
       // put text in correct places  
       move to non empty day from beginning  
   
       while ( monthHasDaysLeft):  
          putText ( date)  
   
          etc..  
   
123    
  * So, where is scaling done?  
  * Is calendar fixed size?  
124    
125  How it is used?  Why CalendarVob isn't made with CallGL?
126    
127     -Someone needs a piece of calendar(x0,y0, x1,y1)      -Text is very problematic - can't be done.
128        -Calculate what part needs rendering      
       -Render  
       -Put on screen with right coordinates.  
         
129    
   ** Talk to Tjl about coordinate systems. **  

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26