Skip to content

Commit 3780158

Browse files
committed
Better segment images, global imageDirection
Created new/better? image for one image per segment tutorial and also made the imageDirection property global for the whole wheel.
1 parent 00bbfd4 commit 3780158

File tree

10 files changed

+26
-18
lines changed

10 files changed

+26
-18
lines changed

Winwheel.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ function Winwheel(options, drawWheel)
5757
'imageOverlay' : false, // If set to true in image drawing mode the outline of the segments will be displayed over the image. Does nothing in code drawMode.
5858
'drawText' : true, // By default the text of the segments is rendered in code drawMode and not in image drawMode.
5959
'pointerAngle' : 0, // Location of the pointer that indicates the prize when wheel has stopped. Default is 0 so the (corrected) 12 o'clock position.
60-
'wheelImage' : null // Must be set to image data in order to use image to draw the wheel - drawMode must also be 'image'.
60+
'wheelImage' : null, // Must be set to image data in order to use image to draw the wheel - drawMode must also be 'image'.
61+
'imageDirection' : 'N' // Used when drawMode is segmentImage. Default is north, can also be (E)ast, (S)outh, (W)est.
6162
};
6263

6364
// -----------------------------------------
@@ -493,8 +494,14 @@ Winwheel.prototype.drawSegmentImages = function()
493494
var imageLeft = 0;
494495
var imageTop = 0;
495496
var imageAngle = 0;
497+
var imageDirection = '';
496498

497-
if (seg.imageDirection == 'S')
499+
if (seg.imageDirection !== null)
500+
imageDirection = seg.imageDirection;
501+
else
502+
imageDirection = this.imageDirection;
503+
504+
if (imageDirection == 'S')
498505
{
499506
// Left set so image sits half/half over the 180 degrees point.
500507
imageLeft = (this.centerX - (seg.imgData.width / 2));
@@ -506,7 +513,7 @@ Winwheel.prototype.drawSegmentImages = function()
506513
// Here we add 180 to the angle to the segment is poistioned correctly.
507514
imageAngle = (seg.startAngle + 180 + ((seg.endAngle - seg.startAngle) / 2));
508515
}
509-
else if (seg.imageDirection == 'E')
516+
else if (imageDirection == 'E')
510517
{
511518
// Left set so image starts and the center point.
512519
imageLeft = this.centerX;
@@ -518,7 +525,7 @@ Winwheel.prototype.drawSegmentImages = function()
518525
// this time we need to add 270 to that to the segment is rendered the correct place.
519526
imageAngle = (seg.startAngle + 270 + ((seg.endAngle - seg.startAngle) / 2));
520527
}
521-
else if (seg.imageDirection == 'W')
528+
else if (imageDirection == 'W')
522529
{
523530
// Left is the centerX minus the width of the image.
524531
imageLeft = (this.centerX - seg.imgData.width);
@@ -1984,7 +1991,7 @@ function Segment(options)
19841991
'textStrokeStyle' : null,
19851992
'textLineWidth' : null,
19861993
'image' : null, // Name/path to the image
1987-
'imageDirection' : 'N', // The direction the image is facing. Can be North, South, East, West.
1994+
'imageDirection' : null, // Direction of the image, can be set globally for the whole wheel.
19881995
'imgData' : null // Image object created here and loaded with image data.
19891996
};
19901997

@@ -2032,11 +2039,6 @@ Segment.prototype.changeImage = function(image, imageDirection)
20322039
{
20332040
this.imageDirection = imageDirection;
20342041
}
2035-
else
2036-
{
2037-
// North is the default.
2038-
this.imageDirection = 'N';
2039-
}
20402042

20412043
// Set imgData to a new image object, change set callback and change src (just like in wheel constructor).
20422044
winhweelAlreadyDrawn = false;
9.24 KB
Loading
12 KB
Loading

examples/one_image_per_segment/index.html

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<div align="center">
3636
<h1>Winwheel.js example wheel - one image per segment</h1>
3737
<br />
38-
<p>Here is an example of a wheel created using one image per segment.</p>
38+
<p>Here is an example of a wheel created using one image per segment, also includes code drawn text.</p>
3939
<br />
4040
<p>Choose a power setting then press the Spin button.</p>
4141
<br />
@@ -75,13 +75,19 @@ <h1>Winwheel.js example wheel - one image per segment</h1>
7575
<script>
7676
// Create new wheel object specifying the parameters at creation time.
7777
var theWheel = new Winwheel({
78-
'numSegments' : 8, // Specify number of segments.
79-
'outerRadius' : 200, // Set outer radius so wheel fits inside the background.
80-
'textFontSize' : 28, // Set font size as desired.
81-
'imageOverlay' : true, // Not required but in this case it made the segment lines look tidier.
82-
'strokeStyle' : '#eeeeee', // Can be any valid HTML colour.
83-
'drawMode' : 'segmentImage', // Must be segmentImage to draw wheel using one image per segemnt.
84-
'segments' : // Define segments including image and text.
78+
'numSegments' : 8, // Specify number of segments.
79+
'outerRadius' : 200, // Set outer radius so wheel fits inside the background.
80+
'drawText' : true, // Code drawn text can be used with segment images.
81+
'textFontSize' : 16,
82+
'textOrientation' : 'curved',
83+
'textAlignment' : 'inner',
84+
'textMargin' : '90',
85+
'textFontFamily' : 'monospace',
86+
'textStrokeStyle' : 'black',
87+
'textLineWidth' : 3,
88+
'textFillStyle' : 'white',
89+
'drawMode' : 'segmentImage', // Must be segmentImage to draw wheel using one image per segemnt.
90+
'segments' : // Define segments including image and text.
8591
[
8692
{'image' : 'jane.png', 'text' : 'Jane'},
8793
{'image' : 'tom.png', 'text' : 'Tom'},
13 KB
Loading
11.6 KB
Loading
10.5 KB
Loading
9.29 KB
Loading
12 KB
Loading
10.9 KB
Loading

0 commit comments

Comments
 (0)