Project

General

Profile

1811q_strokes_4.txt

Sergey Ivanovskiy, 08/24/2015 03:04 PM

Download (6.4 KB)

 
1
=== modified file 'src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.screen.js'
2
--- src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.screen.js	2015-08-22 19:41:35 +0000
3
+++ src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.screen.js	2015-08-24 18:14:50 +0000
4
@@ -165,18 +165,17 @@
5
       // force alpha to 100% opaque
6
       this.pixData[3] = 0xFF;
7
       
8
-      // force the line width default
9
-      this.ctx.lineWidth = 1;
10
-      
11
       // eliminate anti-aliasing of images
12
       this.ctx.imageSmoothingEnabled = false;
13
       
14
-      // the current window stroke style
15
-      this.strokeStyle = strokesManager.getDefaultStrokeStyle();
16
-
17
+      // the current window stroke style id
18
+      this.strokeStyleId = strokesManager.getDefaultStrokeStyle();
19
       // the current window stroke width
20
       this.strokeWidth = 1;
21
 
22
+      //sets the default stroke for the canvas
23
+      strokesManager.applyStrokeToCanvas(this.ctx, this.strokeStyleId, this.strokeWidth);
24
+
25
       this.origin = { "x" : 0, "y" : 0 };
26
       
27
       // force all drawing to be inside pixel "cells" instead of "stradling" between two cells
28
@@ -468,9 +467,10 @@
29
    {
30
       var cur = 
31
       {
32
-         lineWidth   : this.ctx.lineWidth,
33
-         fillstyle   : this.ctx.fillStyle,
34
-         strokeStyle : this.ctx.strokeStyle
35
+         fillstyle     : this.ctx.fillStyle,
36
+         strokeStyle   : this.ctx.strokeStyle,
37
+         strokeStyleId : this.strokeStyleId,
38
+         strokeWidth   : this.strokeWidth
39
       };
40
       
41
       if (additional)
42
@@ -528,10 +528,9 @@
43
       {
44
          var next = this.state[i];
45
          
46
-         this.ctx.lineWidth   = next.lineWidth;
47
          this.ctx.fillstyle   = next.fillStyle;
48
          this.ctx.strokeStyle = next.strokeStyle;
49
-         
50
+         this.setLineStroke(next.strokeStyleId, next.strokeWidth);
51
          var x;
52
          var y;
53
          var width;
54
@@ -668,12 +667,12 @@
55
    /**
56
     * Sets the stroke style.
57
     *                              
58
-    * @param    {Number} strokeStyle
59
+    * @param    {Number} strokeStyleId
60
     *           The predefined stroke style.
61
     */
62
-   Window.prototype.setStrokeStyle = function(strokeStyle)
63
+   Window.prototype.setStrokeStyleId = function(strokeStyleId)
64
    {
65
-      this.strokeStyle = strokeStyle;
66
+      this.strokeStyleId = strokeStyleId;
67
    };
68
    
69
    /**
70
@@ -690,15 +689,16 @@
71
    /**
72
     * Sets the line stroke.
73
     * 
74
-    * @param    {Number} strokeStyle
75
-    *           The predefined stroke style.
76
+    * @param    {Number} strokeStyleId
77
+    *           The predefined stroke style id.
78
     * @param    {Number} width
79
     *           The stroke line width.
80
     */
81
-   Window.prototype.setLineStroke = function(strokeStyle, width)
82
+   Window.prototype.setLineStroke = function(strokeStyleId, width)
83
    {                               
84
-      this.setStrokeStyle(strokeStyle);
85
+      this.setStrokeStyleId(strokeStyleId);
86
       this.setStrokeWidth(width);
87
+      strokesManager.applyStrokeToCanvas(this.ctx, strokeStyleId, width);
88
    };
89
 
90
    /**
91
@@ -708,7 +708,7 @@
92
     *           The encoded list of drawing operations.
93
     */
94
    Window.prototype.draw = function(message)
95
-   {                               
96
+   {
97
       var numOps = p2j.socket.readInt32BinaryMessage(message, 5);
98
                                    
99
       console.log("START DRAWING CYCLE");
100
@@ -870,7 +870,7 @@
101
                path = this.drawLine(this.ctx, x1, y1, x2, y2, this.rawColor);
102
                
103
                strokesManager.applyStrokeToPath(this.ctx,
104
-                                                this.strokeStyle,
105
+                                                this.strokeStyleId,
106
                                                 this.strokeWidth,
107
                                                 this.rawColor,
108
                                                 path);
109
@@ -884,7 +884,7 @@
110
                path   = this.drawRect(this.ctx, x, y, width, height, this.rawColor, false);
111
                
112
                strokesManager.applyStrokeToPath(this.ctx,
113
-                                                this.strokeStyle,
114
+                                                this.strokeStyleId,
115
                                                 this.strokeWidth,
116
                                                 this.rawColor,
117
                                                 path);
118
@@ -904,6 +904,9 @@
119
                width = p2j.socket.readInt32BinaryMessage(message, idx + 9);
120
                height = p2j.socket.readInt32BinaryMessage(message, idx + 13);
121
 
122
+               extra = " x = " + x.toString() +"; y = " + y.toString() + "; width = " + width
123
+               + "; height = " + height;
124
+               //alert(extra);
125
                var encoding = message[idx + 17];
126
                var key = p2j.socket.readInt32BinaryMessage(message, idx + 18);
127
                var pixelsInBytes = width * height * 4;
128
@@ -977,9 +980,10 @@
129
                this.setColor([ r, g, b ]);
130
                break;   
131
             case ops.SET_LINE_STROKE:
132
-               var strokeStyle = p2j.socket.readInt32BinaryMessage(message, idx + 1);
133
+               var strokeStyleId = p2j.socket.readInt32BinaryMessage(message, idx + 1);
134
                var strokeWidth = p2j.socket.readInt32BinaryMessage(message, idx + 5);
135
-               this.setLineStroke(strokeStyle, strokeWidth);
136
+               this.setLineStroke(strokeStyleId, strokeWidth);
137
+               extra = " strokeStyleId = " + strokeStyleId + "; strokeWidth = " + strokeWidth;
138
                break;              
139
             case ops.SET_FONT:
140
                fontId = p2j.socket.readInt32BinaryMessage(message, idx + 1);
141
@@ -1354,7 +1358,7 @@
142
       
143
       while (true)
144
       {
145
-         if (strokesManager.isDirectDrawingStrokeStyle(this.strokeStyle))
146
+         if (strokesManager.isDirectDrawingStrokeStyle(this.strokeStyleId))
147
          {
148
             this.drawPixel(ctx, x, y, color);
149
          }
150

    
151
=== modified file 'src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.strokes.js'
152
--- src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.strokes.js	2015-08-20 16:45:52 +0000
153
+++ src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.strokes.js	2015-08-24 12:42:08 +0000
154
@@ -203,7 +203,7 @@
155
     * @param    {Number} width
156
     *           The line width.
157
     */
158
-   this.apply = function(context, strokeStyle, width)
159
+   this.applyStrokeToCanvas = function(context, strokeStyle, width)
160
    {
161
       if (context instanceof CanvasRenderingContext2D)
162
       {
163