"Flat" GUI design options

preparing for "flat" GUI skins
pull/3/merge
jmoenig 2013-05-15 16:03:56 +02:00
rodzic a1ff3bfec5
commit b74695d4a0
3 zmienionych plików z 80 dodań i 33 usunięć

Wyświetl plik

@ -1709,3 +1709,5 @@ ______
130515 130515
------ ------
* Objects: Costume shrinkWrap adjustments * Objects: Costume shrinkWrap adjustments
* Morphic: Flat design preference introduced (default is off)
* Widgets: preparing for "flat GUI skins"

Wyświetl plik

@ -1035,7 +1035,7 @@
/*global window, HTMLCanvasElement, getMinimumFontHeight, FileReader, Audio, /*global window, HTMLCanvasElement, getMinimumFontHeight, FileReader, Audio,
FileList, getBlurredShadowSupport*/ FileList, getBlurredShadowSupport*/
var morphicVersion = '2013-May-06'; var morphicVersion = '2013-May-15';
var modules = {}; // keep track of additional loaded modules var modules = {}; // keep track of additional loaded modules
var useBlurredShadows = getBlurredShadowSupport(); // check for Chrome-bug var useBlurredShadows = getBlurredShadowSupport(); // check for Chrome-bug
@ -1054,7 +1054,8 @@ var standardSettings = {
useSliderForInput: false, useSliderForInput: false,
useVirtualKeyboard: true, useVirtualKeyboard: true,
isTouchDevice: false, // turned on by touch events, don't set isTouchDevice: false, // turned on by touch events, don't set
rasterizeSVGs: false rasterizeSVGs: false,
isFlat: false
}; };
var touchScreenSettings = { var touchScreenSettings = {
@ -1072,7 +1073,8 @@ var touchScreenSettings = {
useSliderForInput: true, useSliderForInput: true,
useVirtualKeyboard: true, useVirtualKeyboard: true,
isTouchDevice: false, isTouchDevice: false,
rasterizeSVGs: false rasterizeSVGs: false,
isFlat: false
}; };
var MorphicPreferences = standardSettings; var MorphicPreferences = standardSettings;
@ -5464,7 +5466,7 @@ SliderButtonMorph.prototype.init = function (orientation) {
this.color = new Color(80, 80, 80); this.color = new Color(80, 80, 80);
this.highlightColor = new Color(90, 90, 140); this.highlightColor = new Color(90, 90, 140);
this.pressColor = new Color(80, 80, 160); this.pressColor = new Color(80, 80, 160);
this.is3D = true; this.is3D = false;
this.hasMiddleDip = true; this.hasMiddleDip = true;
SliderButtonMorph.uber.init.call(this, orientation); SliderButtonMorph.uber.init.call(this, orientation);
}; };
@ -5477,21 +5479,21 @@ SliderButtonMorph.prototype.drawNew = function () {
var colorBak = this.color.copy(); var colorBak = this.color.copy();
SliderButtonMorph.uber.drawNew.call(this); SliderButtonMorph.uber.drawNew.call(this);
if (this.is3D) { if (this.is3D || !MorphicPreferences.isFlat) {
this.drawEdges(); this.drawEdges();
} }
this.normalImage = this.image; this.normalImage = this.image;
this.color = this.highlightColor.copy(); this.color = this.highlightColor.copy();
SliderButtonMorph.uber.drawNew.call(this); SliderButtonMorph.uber.drawNew.call(this);
if (this.is3D) { if (this.is3D || !MorphicPreferences.isFlat) {
this.drawEdges(); this.drawEdges();
} }
this.highlightImage = this.image; this.highlightImage = this.image;
this.color = this.pressColor.copy(); this.color = this.pressColor.copy();
SliderButtonMorph.uber.drawNew.call(this); SliderButtonMorph.uber.drawNew.call(this);
if (this.is3D) { if (this.is3D || !MorphicPreferences.isFlat) {
this.drawEdges(); this.drawEdges();
} }
this.pressImage = this.image; this.pressImage = this.image;

Wyświetl plik

@ -71,9 +71,9 @@
/*global TriggerMorph, modules, Color, Point, BoxMorph, radians, /*global TriggerMorph, modules, Color, Point, BoxMorph, radians,
newCanvas, StringMorph, Morph, TextMorph, nop, detect, StringFieldMorph, newCanvas, StringMorph, Morph, TextMorph, nop, detect, StringFieldMorph,
HTMLCanvasElement, fontHeight, SymbolMorph, localize, SpeechBubbleMorph, HTMLCanvasElement, fontHeight, SymbolMorph, localize, SpeechBubbleMorph,
ArrowMorph, MenuMorph, isString, isNil, SliderMorph*/ ArrowMorph, MenuMorph, isString, isNil, SliderMorph, MorphicPreferences*/
modules.widgets = '2013-May-10'; modules.widgets = '2013-May-15';
var PushButtonMorph; var PushButtonMorph;
var ToggleButtonMorph; var ToggleButtonMorph;
@ -144,6 +144,7 @@ PushButtonMorph.prototype.init = function (
template template
) { ) {
// additional properties: // additional properties:
this.is3D = false; // for "flat" design exceptions
this.target = target || null; this.target = target || null;
this.action = action || null; this.action = action || null;
this.environment = environment || null; this.environment = environment || null;
@ -209,6 +210,7 @@ PushButtonMorph.prototype.outlinePath = BoxMorph.prototype.outlinePath;
PushButtonMorph.prototype.drawOutline = function (context) { PushButtonMorph.prototype.drawOutline = function (context) {
var outlineStyle; var outlineStyle;
if (MorphicPreferences.isFlat && !this.is3D) {return; }
if (!this.outline) {return null; } if (!this.outline) {return null; }
if (this.outlineGradient) { if (this.outlineGradient) {
outlineStyle = context.createLinearGradient( outlineStyle = context.createLinearGradient(
@ -252,6 +254,7 @@ PushButtonMorph.prototype.drawEdges = function (
topColor, topColor,
bottomColor bottomColor
) { ) {
if (MorphicPreferences.isFlat && !this.is3D) {return; }
var minInset = Math.max(this.corner, this.outline + this.edge), var minInset = Math.max(this.corner, this.outline + this.edge),
w = this.width(), w = this.width(),
h = this.height(), h = this.height(),
@ -431,13 +434,17 @@ PushButtonMorph.prototype.createBackgrounds = function () {
}; };
PushButtonMorph.prototype.createLabel = function () { PushButtonMorph.prototype.createLabel = function () {
var shading = !MorphicPreferences.isFlat || this.is3D;
if (this.label !== null) { if (this.label !== null) {
this.label.destroy(); this.label.destroy();
} }
if (this.labelString instanceof SymbolMorph) { if (this.labelString instanceof SymbolMorph) {
this.label = this.labelString.fullCopy(); this.label = this.labelString.fullCopy();
this.label.shadowOffset = this.labelShadowOffset; if (shading) {
this.label.shadowColor = this.labelShadowColor; this.label.shadowOffset = this.labelShadowOffset;
this.label.shadowColor = this.labelShadowColor;
}
this.label.color = this.labelColor; this.label.color = this.labelColor;
this.label.drawNew(); this.label.drawNew();
} else { } else {
@ -448,7 +455,7 @@ PushButtonMorph.prototype.createLabel = function () {
true, true,
false, false,
false, false,
this.labelShadowOffset, shading ? this.labelShadowOffset : null,
this.labelShadowColor, this.labelShadowColor,
this.labelColor this.labelColor
); );
@ -717,6 +724,8 @@ ToggleButtonMorph.prototype.drawEdges = function (
topColor, topColor,
bottomColor bottomColor
) { ) {
if (MorphicPreferences.isFlat && !this.is3D) {return; }
var gradient; var gradient;
ToggleButtonMorph.uber.drawEdges.call( ToggleButtonMorph.uber.drawEdges.call(
@ -773,6 +782,9 @@ ToggleButtonMorph.prototype.previewPath = function (context, radius, inset) {
}; };
ToggleButtonMorph.prototype.createLabel = function () { ToggleButtonMorph.prototype.createLabel = function () {
var shading = !MorphicPreferences.isFlat || this.is3D,
none = new Point();
if (this.label !== null) { if (this.label !== null) {
this.label.destroy(); this.label.destroy();
} }
@ -784,12 +796,14 @@ ToggleButtonMorph.prototype.createLabel = function () {
this.label = this.labelString[0].fullCopy(); this.label = this.labelString[0].fullCopy();
this.trueStateLabel = this.labelString[1].fullCopy(); this.trueStateLabel = this.labelString[1].fullCopy();
if (!this.isPicture) { if (!this.isPicture) {
this.label.shadowOffset = this.labelShadowOffset; this.label.shadowOffset = shading ?
this.labelShadowOffset : none;
this.label.shadowColor = this.labelShadowColor; this.label.shadowColor = this.labelShadowColor;
this.label.color = this.labelColor; this.label.color = this.labelColor;
this.label.drawNew(); this.label.drawNew();
this.trueStateLabel.shadowOffset = this.labelShadowOffset; this.trueStateLabel.shadowOffset = shading ?
this.labelShadowOffset : none;
this.trueStateLabel.shadowColor = this.labelShadowColor; this.trueStateLabel.shadowColor = this.labelShadowColor;
this.trueStateLabel.color = this.labelColor; this.trueStateLabel.color = this.labelColor;
this.trueStateLabel.drawNew(); this.trueStateLabel.drawNew();
@ -805,7 +819,7 @@ ToggleButtonMorph.prototype.createLabel = function () {
true, true,
false, false,
false, false,
this.labelShadowOffset, shading ? this.labelShadowOffset : null,
this.labelShadowColor, this.labelShadowColor,
this.labelColor this.labelColor
); );
@ -816,7 +830,7 @@ ToggleButtonMorph.prototype.createLabel = function () {
true, true,
false, false,
false, false,
this.labelShadowOffset, shading ? this.labelShadowOffset : null,
this.labelShadowColor, this.labelShadowColor,
this.labelColor this.labelColor
); );
@ -825,7 +839,8 @@ ToggleButtonMorph.prototype.createLabel = function () {
if (this.labelString instanceof SymbolMorph) { if (this.labelString instanceof SymbolMorph) {
this.label = this.labelString.fullCopy(); this.label = this.labelString.fullCopy();
if (!this.isPicture) { if (!this.isPicture) {
this.label.shadowOffset = this.labelShadowOffset; this.label.shadowOffset = shading ?
this.labelShadowOffset : none;
this.label.shadowColor = this.labelShadowColor; this.label.shadowColor = this.labelShadowColor;
this.label.color = this.labelColor; this.label.color = this.labelColor;
this.label.drawNew(); this.label.drawNew();
@ -840,7 +855,7 @@ ToggleButtonMorph.prototype.createLabel = function () {
true, true,
false, false,
false, false,
this.labelShadowOffset, shading ? this.labelShadowOffset : none,
this.labelShadowColor, this.labelShadowColor,
this.labelColor this.labelColor
); );
@ -956,6 +971,8 @@ TabMorph.prototype.drawEdges = function (
topColor, topColor,
bottomColor bottomColor
) { ) {
if (MorphicPreferences.isFlat && !this.is3D) {return; }
var w = this.width(), var w = this.width(),
h = this.height(), h = this.height(),
c = this.corner, c = this.corner,
@ -1114,6 +1131,8 @@ ToggleMorph.prototype.fixLayout = function () {
}; };
ToggleMorph.prototype.createLabel = function () { ToggleMorph.prototype.createLabel = function () {
var shading = !MorphicPreferences.isFlat || this.is3D;
if (this.label === null) { if (this.label === null) {
if (this.captionString) { if (this.captionString) {
this.label = new TextMorph( this.label = new TextMorph(
@ -1133,7 +1152,7 @@ ToggleMorph.prototype.createLabel = function () {
true, true,
false, false,
false, false,
new Point(1, 1), shading ? new Point(1, 1) : null,
new Color(240, 240, 240) new Color(240, 240, 240)
); );
this.add(this.tick); this.add(this.tick);
@ -1309,23 +1328,31 @@ ToggleElementMorph.prototype.init = function (
// ToggleElementMorph drawing: // ToggleElementMorph drawing:
ToggleElementMorph.prototype.createBackgrounds = function () { ToggleElementMorph.prototype.createBackgrounds = function () {
var shading = !MorphicPreferences.isFlat || this.is3D;
this.color = this.element.color; this.color = this.element.color;
this.element.removeShadow(); this.element.removeShadow();
this.element[this.builder](); this.element[this.builder]();
this.element.addShadow(this.shadowOffset, this.shadowAlpha); if (shading) {
this.element.addShadow(this.shadowOffset, this.shadowAlpha);
}
this.silentSetExtent(this.element.fullBounds().extent()); // w/ shadow this.silentSetExtent(this.element.fullBounds().extent()); // w/ shadow
this.pressImage = this.element.fullImage(); this.pressImage = this.element.fullImage();
this.element.removeShadow(); this.element.removeShadow();
this.element.setColor(this.inactiveColor); this.element.setColor(this.inactiveColor);
this.element[this.builder](this.contrast); this.element[this.builder](this.contrast);
this.element.addShadow(this.shadowOffset, 0); if (shading) {
this.element.addShadow(this.shadowOffset, 0);
}
this.normalImage = this.element.fullImage(); this.normalImage = this.element.fullImage();
this.element.removeShadow(); this.element.removeShadow();
this.element.setColor(this.color.lighter(this.contrast)); this.element.setColor(this.color.lighter(this.contrast));
this.element[this.builder](this.contrast); this.element[this.builder](this.contrast);
this.element.addShadow(this.shadowOffset, this.shadowAlpha); if (shading) {
this.element.addShadow(this.shadowOffset, this.shadowAlpha);
}
this.highlightImage = this.element.fullImage(); this.highlightImage = this.element.fullImage();
this.element.removeShadow(); this.element.removeShadow();
@ -1443,6 +1470,7 @@ function DialogBoxMorph(target, action, environment) {
DialogBoxMorph.prototype.init = function (target, action, environment) { DialogBoxMorph.prototype.init = function (target, action, environment) {
// additional properties: // additional properties:
this.is3D = false; // for "flat" design exceptions
this.target = target || null; this.target = target || null;
this.action = action || null; this.action = action || null;
this.environment = environment || null; this.environment = environment || null;
@ -2131,6 +2159,8 @@ DialogBoxMorph.prototype.normalizeSpaces = function (string) {
// DialogBoxMorph submorph construction // DialogBoxMorph submorph construction
DialogBoxMorph.prototype.createLabel = function () { DialogBoxMorph.prototype.createLabel = function () {
var shading = !MorphicPreferences.isFlat || this.is3D;
if (this.label) { if (this.label) {
this.label.destroy(); this.label.destroy();
} }
@ -2142,7 +2172,7 @@ DialogBoxMorph.prototype.createLabel = function () {
true, true,
false, false,
false, false,
new Point(2, 1), shading ? new Point(2, 1) : null,
this.titleBarColor.darker(this.contrast) this.titleBarColor.darker(this.contrast)
); );
this.label.color = this.titleTextColor; this.label.color = this.titleTextColor;
@ -2387,16 +2417,20 @@ DialogBoxMorph.prototype.drawNew = function () {
context = this.image.getContext('2d'); context = this.image.getContext('2d');
// title bar // title bar
gradient = context.createLinearGradient(0, 0, 0, th); if (MorphicPreferences.isFlat && !this.is3D) {
gradient.addColorStop( context.fillStyle = this.titleBarColor.toString();
0, } else {
this.titleBarColor.lighter(this.contrast / 2).toString() gradient = context.createLinearGradient(0, 0, 0, th);
); gradient.addColorStop(
gradient.addColorStop( 0,
1, this.titleBarColor.lighter(this.contrast / 2).toString()
this.titleBarColor.darker(this.contrast).toString() );
); gradient.addColorStop(
context.fillStyle = gradient; 1,
this.titleBarColor.darker(this.contrast).toString()
);
context.fillStyle = gradient;
}
context.beginPath(); context.beginPath();
this.outlinePathTitle( this.outlinePathTitle(
context, context,
@ -2416,6 +2450,13 @@ DialogBoxMorph.prototype.drawNew = function () {
context.closePath(); context.closePath();
context.fill(); context.fill();
if (MorphicPreferences.isFlat && !this.is3D) {
DialogBoxMorph.uber.addShadow.call(this);
Morph.prototype.trackChanges = true;
this.fullChanged();
return;
}
// 3D-effect // 3D-effect
// bottom left corner // bottom left corner
gradient = context.createLinearGradient( gradient = context.createLinearGradient(
@ -2959,6 +3000,8 @@ InputFieldMorph.prototype.drawRectBorder = function (context) {
var shift = this.edge * 0.5, var shift = this.edge * 0.5,
gradient; gradient;
if (MorphicPreferences.isFlat && !this.is3D) {return; }
context.lineWidth = this.edge; context.lineWidth = this.edge;
context.lineJoin = 'round'; context.lineJoin = 'round';
context.lineCap = 'round'; context.lineCap = 'round';