gzz-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gzz-commits] gzz gzz/vob/CalendarVob.java gfx/librenderables...


From: Matti Katila
Subject: [Gzz-commits] gzz gzz/vob/CalendarVob.java gfx/librenderables...
Date: Wed, 30 Oct 2002 08:57:30 -0500

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Matti Katila <address@hidden>   02/10/30 08:57:30

Modified files:
        gzz/vob        : CalendarVob.java 
        gfx/librenderables: renderables.py 
        gfx/demo       : calendarvobtest.py 

Log message:
        -minor improvents.
        -17 call arguments, go renderable go!

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gzz/vob/CalendarVob.java.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/librenderables/renderables.py.diff?tr1=1.115&tr2=1.116&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/demo/calendarvobtest.py.diff?tr1=1.1&tr2=1.2&r1=text&r2=text

Patches:
Index: gzz/gfx/demo/calendarvobtest.py
diff -u gzz/gfx/demo/calendarvobtest.py:1.1 gzz/gfx/demo/calendarvobtest.py:1.2
--- gzz/gfx/demo/calendarvobtest.py:1.1 Tue Oct 29 12:34:41 2002
+++ gzz/gfx/demo/calendarvobtest.py     Wed Oct 30 08:57:29 2002
@@ -2,7 +2,8 @@
 from gzz.view import View
 from test.tools import tools
 
-style = GraphicsAPI.getInstance().getTextStyle("serif", 0, 14)
+style_date = GraphicsAPI.getInstance().getTextStyle("serif", 0, 14)
+style_n = GraphicsAPI.getInstance().getTextStyle("serif", 0, 14)
 
 class ViewScene:
     def __init__(self):
@@ -17,14 +18,31 @@
        self.bgcolor = (0.6, 0.7, 0.8)
         putnoc(vs, background(self.bgcolor))
 
+        #for i in range(1, 12):
+        #    cs_cal = vs.coords.affineCoordsys(0, 0, w/2 - ((w/3 + self.tx)  * 
(self.scale -1) ) ,
+        #                                      ((h/6) *i) - ((h/3.5 + self.ty) 
*(self.scale-1)),
+        #                                      w/7*0.2* self.scale, 0, 0, 
((h/12)/5) * self.scale)
+            #print 'w: ', w,' h: ', h 
+
+        #    vs.matcher.add(cs_cal, "cs_cal")
+        #    gzz.vob.CalendarVob.setStatics(style_date, style_n, 5)
+        #    gzz.vob.CalendarVob.setBounds(0.7, 0.5, 1.0)
+        #    vs.map.put(gzz.vob.CalendarVob(2002, i), cs_cal)
+
         cs_cal = vs.coords.affineCoordsys(0, 0, w/2 - ((w/3 + self.tx)  * 
(self.scale -1) ) ,
                                           h/2 - ((h/3.5 + self.ty) 
*(self.scale-1)),
-                                          w/6 * self.scale, 0, 0, h/7 * 
self.scale)
-        #print 'w: ', w,' h: ', h 
-
+                                          w/6 * self.scale, 0, 0, h/5 * 
self.scale)
+        print 'w: ', w,' h: ', h 
+            
         vs.matcher.add(cs_cal, "cs_cal")
-        
-        vs.map.put(gzz.vob.CalendarVob(style, 5), cs_cal)
+
+        # these don't efect
+        gzz.vob.CalendarVob.setStatics(style_date, style_n, 5)
+
+        # week number width, weekday height, month name height
+        gzz.vob.CalendarVob.setBounds(0.9, 1.1, 0.8)
+        vs.map.put(gzz.vob.CalendarVob(2002, 12), cs_cal)
+
         
     def key(self, k):
         if k == "+":
Index: gzz/gfx/librenderables/renderables.py
diff -u gzz/gfx/librenderables/renderables.py:1.115 
gzz/gfx/librenderables/renderables.py:1.116
--- gzz/gfx/librenderables/renderables.py:1.115 Wed Oct 30 03:11:03 2002
+++ gzz/gfx/librenderables/renderables.py       Wed Oct 30 08:57:29 2002
@@ -1096,16 +1096,70 @@
     "Type": "1",
     "Name": "CalendarPaper",
     "Data": """
+       TextRenderer *r_date;
        TextRenderer *r;
         float linewidth;
+
+        int empty_days;
+        int days;
+        int first_week_number;
+
+       unicodecharvector d_txt[7];
+       unicodecharvector m_txt;        
+
+        float week_num_w;
+        float weekday_h;
+        float month_name_h;
+
         """,
     "Params": """
-       Font f,
-        float linewidth
+       Font f_date,
+        Font f,
+        float linewidth,
+
+        int empty_days,
+        int days,
+        int first_week_number,
+
+        String t1,
+        String t2,
+        String t3,
+        String t4,
+        String t5,
+        String t6,
+        String t7,
+        String t8,
+ 
+        float week_num_w,
+        float weekday_h,
+        float month_name_h
+       
         """,
     "ParamCode": """
+       r_date = f_date;
        r = f;
+       
+       d_txt[0] = t1;
+       d_txt[1] = t2;
+       d_txt[2] = t3;
+       d_txt[3] = t4;
+       d_txt[4] = t5;
+       d_txt[5] = t6;
+       d_txt[6] = t7;
+
+       m_txt = t8;
+       
        this->linewidth = linewidth;
+
+       this->empty_days = empty_days;
+       this->days = days;
+       this->first_week_number = first_week_number;
+
+       this->week_num_w = week_num_w;
+       this->weekday_h = weekday_h;
+       this->month_name_h = month_name_h;
+
+
        """,
     "ExtraClass" : """
        template<class Coords> struct Vertexer {
@@ -1125,74 +1179,125 @@
            glPushAttrib(GL_ENABLE_BIT);
            glEnable(GL_BLEND);
 
-            // STILL STATIC MONTH
-            int empty = 2;
-            int days = 30;
-            int weeks = (days + empty) / 7;
-            if ( (days + empty) % 7 != 0) weeks++;
-
-            if (dbg) cout << "w" << weeks << " d " << days << " e " << empty 
<< "\\n";
+            int weeks = (days + empty_days) / 7;
+            if ( (days + empty_days) % 7 != 0) weeks++;
 
             // Coordinating system
             ZPt cs;
 
+            glDisable(GL_TEXTURE_2D);
+
             glLineWidth(linewidth);
             glColor3f(0.0, 0.0, 0.0);
 
             glBegin(GL_LINES);
 
+              // left -vert
+              cs = coords1.transform( ZPt(0.0, 0.0, 0.0) );
+              glVertex3f(cs.x, cs.y, cs.z);
+              cs = coords1.transform( ZPt(0.0, weeks + weekday_h + 
month_name_h, 0.0) );
+              glVertex3f(cs.x, cs.y, cs.z);
+
+              // right -vert
+              cs = coords1.transform( ZPt(7.0+ week_num_w, 0.0, 0.0) );
+              glVertex3f(cs.x, cs.y, cs.z);
+              cs = coords1.transform( ZPt(7.0+ week_num_w, weeks + weekday_h + 
month_name_h, 0.0) );
+              glVertex3f(cs.x, cs.y, cs.z);
+
+              // weekday - horiz
+              cs = coords1.transform( ZPt(0.0, month_name_h, 0.0) );
+              glVertex3f(cs.x, cs.y, cs.z);
+              cs = coords1.transform( ZPt(7.0+week_num_w, month_name_h, 0.0) );
+              glVertex3f(cs.x, cs.y, cs.z);
+
+              // top - horiz line
+              cs = coords1.transform( ZPt(0.0, 0.0, 0.0) );
+              glVertex3f(cs.x, cs.y, cs.z);
+              cs = coords1.transform( ZPt(7.0+week_num_w, 0.0, 0.0) );
+              glVertex3f(cs.x, cs.y, cs.z);
+              
+
+              // Calendar:
               // Vertical lines.
-              for (int i=0; i<=7; i++) {
-                  cs = coords1.transform( ZPt(i, 0.0, 0.0) );
+              for (int i=0; i<7; i++) {
+                  cs = coords1.transform( ZPt(i + week_num_w, month_name_h, 
0.0) );
                   glVertex3f(cs.x, cs.y, cs.z);
 
-                  cs = coords1.transform( ZPt(i, weeks, 0.0) );
+                  cs = coords1.transform( ZPt(i + week_num_w, month_name_h + 
weeks + weekday_h, 0.0) );
                   glVertex3f(cs.x, cs.y, cs.z);
               }
               // Horizontal lines.
               for (int i=0; i<=weeks; i++) {
-                  cs = coords1.transform( ZPt(0.0, i, 0.0) );
+                  cs = coords1.transform( ZPt(0.0, i+month_name_h+weekday_h, 
0.0) );
                   glVertex3f(cs.x, cs.y, cs.z);
 
-                  cs = coords1.transform( ZPt(7.0, i, 0.0) );
+                  cs = coords1.transform( ZPt(7.0+week_num_w, 
i+month_name_h+weekday_h, 0.0) );
                   glVertex3f(cs.x, cs.y, cs.z);
               }
             glEnd();
 
+            glEnable(GL_TEXTURE_2D);
 
-            for (int i=1; i<=days; i++) {
-                int column = (empty + i) % 7;
-                int row  = 1 + (empty + i) / 7; 
+            Vertexer<Coords> v(coords1);
 
-                Vertexer<Coords> v(coords1);
+            for (int i=1; i<=days; i++) {
+                int column = (empty_days + i -1) % 7;
+                int row  = 1 + (empty_days + i -1) / 7; 
 
                 static char buffer[64];
                 sprintf(buffer, "%i", i);
 
                 float fcol, frow;
 
+                fcol = week_num_w;
+                frow = weekday_h + month_name_h;
+
                 if (i<10) {
-                    fcol = column + 0.30;
-                    frow = row - 0.25;
+                    fcol += column + 0.30;
+                    frow += row - 0.25;
                 } else {
-                    fcol = column + 0.10;
-                    frow = row - 0.25;
+                    fcol += column + 0.10;
+                    frow += row - 0.25;
                 }
 
                 glColor3f(1.0, 1.0, 1.0);
                 
-               Text::renderIter(*r, buffer, buffer+strlen(buffer), 
+               Text::renderIter(*r_date, buffer, buffer+strlen(buffer), 
                      fcol , frow, v
                );
 
                 if (column == 6) glColor3f(1.0, 0.0, 0.0);
                 else  glColor3f(0.0, 0.0, 0.0);
 
-               Text::renderIter(*r, buffer, buffer+strlen(buffer), 
+               Text::renderIter(*r_date, buffer, buffer+strlen(buffer), 
                      fcol + 0.03 , frow + 0.03, v
                );
 
             }
+
+            glColor3f(0.0, 0.0, 0.0);
+
+            for (int i=0; i<weeks; i++) {
+                static char buffer[64];
+                sprintf(buffer, "%i", first_week_number + i);
+
+               Text::renderIter(*r, buffer, buffer+strlen(buffer), 
+                     0.1 , month_name_h + weekday_h + i + 0.8, v
+               );
+            
+            }
+
+            for (int i=0; i<7; i++) {
+               Text::renderIter(*r, d_txt[i].begin(), d_txt[i].end(), 
+                     week_num_w + i, month_name_h + weekday_h -0.1, v
+               );
+            }
+
+            Text::renderIter(*r, m_txt.begin(), m_txt.end(), 
+                week_num_w+2.0, month_name_h-0.1, v
+            );
+            
+            
            glPopAttrib();
 
             if (dbg) cout << "Calendar done\\n";
Index: gzz/gzz/vob/CalendarVob.java
diff -u gzz/gzz/vob/CalendarVob.java:1.1 gzz/gzz/vob/CalendarVob.java:1.2
--- gzz/gzz/vob/CalendarVob.java:1.1    Tue Oct 29 12:37:52 2002
+++ gzz/gzz/vob/CalendarVob.java        Wed Oct 30 08:57:29 2002
@@ -8,24 +8,143 @@
 import java.awt.*;
 import gzz.client.GraphicsAPI;
 
+import java.util.*;
 
 public class CalendarVob extends Vob {
-public static final String rcsid = "$Id: CalendarVob.java,v 1.1 2002/10/29 
17:37:52 mudyc Exp $";
+public static final String rcsid = "$Id: CalendarVob.java,v 1.2 2002/10/30 
13:57:29 mudyc Exp $";
     public static boolean dbg = true; //false;
     static final void p(String s) { if(dbg) System.out.println(s); }
     static final void pa(String s) { System.out.println(s); }
 
 
-    protected final TextStyle style;
-    private final float linewidth;
+    // final?
+    static protected TextStyle style_date;
+    static protected TextStyle style_week_numbers;
+    static private float linewidth;
+
+    static private float weeknumber_width;
+    static private float weekday_height;
+    static private float month_name_height;
+
+
+    private int year;
+    private int month;
+    private int empty_before_first_day;
+    private int days_in_month;
+    private int first_week_number;
+
+    private String text[] = {"Ma", "Ti", "Ke", "To", 
+                            "Pe", "La", "Su", "MONTH NAME" };
+
+
+    public CalendarVob(int year, int month) {
+       this.year = year;
+       this.month = month - 1;
+
+       text[7] = monthStr(this.month);
+
+
+       // 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(year);
+
+       // set first day of month
+       date.setDate(1);
+       date.setMonth(this.month);
+       calendar.setTime(date);
+
+       first_week_number = calendar.get(Calendar.WEEK_OF_YEAR);
+
+       // 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 = 6;
+       } else {
+           empty_before_first_day =
+               calendar.get(Calendar.DAY_OF_WEEK) - 2;
+       }
+
+       for (int i=0; i< empty_before_first_day; i++) {
+           System.out.print("    ");
+       }
+       
+       // 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 = day - 1;
+               break; 
+           }
+
+           System.out.print(dayStr(calendar.get(Calendar.DAY_OF_WEEK)) + " " + 
day+ ", " );
+           if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) p("");
+       }
+    }
 
-    public CalendarVob(TextStyle style, float linewidth) {
-       this.style = style;
-       this.linewidth = linewidth;
+    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";
     }
 
 
 
+    static public void setStatics(TextStyle style_date, TextStyle 
style_week_numbers, float linewidth) 
+    {
+       CalendarVob.style_date         = style_date;
+       CalendarVob.style_week_numbers = style_week_numbers;
+       CalendarVob.linewidth          = linewidth;
+    }
+
+    static public void setBounds(float weeknumber_width,
+                                float weekday_height,  
+                                float month_name_height) 
+    {
+       CalendarVob.weeknumber_width  = weeknumber_width;
+       CalendarVob.weekday_height    = weekday_height;
+       CalendarVob.month_name_height = month_name_height;
+    }
+
+
     //    public Rectangle clip;
     Color bgcolor;
 
@@ -62,9 +181,29 @@
                           int coordsys1,
                           int coordsys2) 
     {
-       GLTextStyle gls = (GLTextStyle)style;
-       GLRen.CalendarPaper cp = GLRen.createCalendarPaper( gls.theFont, 
linewidth );
-
+       GLTextStyle gls_d = (GLTextStyle)style_date;
+       GLTextStyle gls_w = (GLTextStyle)style_week_numbers;
+       GLRen.CalendarPaper cp = 
+           GLRen.createCalendarPaper( gls_d.theFont, 
+                                      gls_w.theFont,
+                                      linewidth,
+
+                                      empty_before_first_day,
+                                      days_in_month,
+                                      first_week_number,
+
+                                      text[0],
+                                      text[1],
+                                      text[2],
+                                      text[3],
+                                      text[4],
+                                      text[5],
+                                      text[6],
+                                      text[7],
+
+                                      weeknumber_width,
+                                      weekday_height,  
+                                      month_name_height);
        return  cp.addToListGL(win, list, curs, coordsys1, coordsys2);
     }
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]