Skip to content

Commit adf9332

Browse files
committed
Support for HiDPI screens aterrien#99 aterrien#93 aterrien#61
1 parent 5adb8ba commit adf9332

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

js/jquery.knob.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
this.cH = null; // change hook
6464
this.eH = null; // cancel hook
6565
this.rH = null; // release hook
66+
this.scale = 1; // scale factor
6667

6768
this.run = function () {
6869
var cf = function (e, conf) {
@@ -166,6 +167,21 @@
166167
this.o.height + 'px;"></div>'))
167168
.before(this.$c);
168169

170+
this.scale = (window.devicePixelRatio || 1) /
171+
(
172+
this.c.webkitBackingStorePixelRatio ||
173+
this.c.mozBackingStorePixelRatio ||
174+
this.c.msBackingStorePixelRatio ||
175+
this.c.oBackingStorePixelRatio ||
176+
this.c.backingStorePixelRatio || 1
177+
);
178+
if (this.scale !== 1) {
179+
this.$c[0].width = this.$c[0].width * this.scale;
180+
this.$c[0].height = this.$c[0].height * this.scale;
181+
this.$c.width(this.o.width);
182+
this.$c.height(this.o.height);
183+
}
184+
169185
if (this.v instanceof Object) {
170186
this.cv = {};
171187
this.copy(this.v, this.cv);
@@ -196,8 +212,9 @@
196212
var d = true,
197213
c = document.createElement('canvas');
198214

199-
c.width = s.o.width;
200-
c.height = s.o.height;
215+
c.width = s.o.width * s.scale;
216+
c.height = s.o.height * s.scale;
217+
201218
s.g = c.getContext('2d');
202219

203220
s.clear();
@@ -551,7 +568,7 @@
551568
this.$.val(this.v);
552569
this.w2 = this.o.width / 2;
553570
this.cursorExt = this.o.cursor / 100;
554-
this.xy = this.w2;
571+
this.xy = this.w2 * this.scale;
555572
this.lineWidth = this.xy * this.o.thickness;
556573
this.lineCap = this.o.lineCap;
557574
this.radius = this.xy - this.lineWidth / 2;

0 commit comments

Comments
 (0)