lineHeight, showImage, splitImage
This commit is contained in:
1 parent
ff45cfdca3
commit
9813dc3115
7 files changed
+108
-54
No files matched your search
+16
-11
@@ -885,7 +885,7 @@ events.prototype._action_autoText = function (data, x, y, prefix) {
|
||||
|
||||
events.prototype._action_scrollText = function (data, x, y, prefix) {
|
||||
if (this.__action_checkReplaying()) return;
|
||||
this.__action_doAsyncFunc(data.async, core.ui.drawScrollText, data.text, data.time || 5000);
|
||||
this.__action_doAsyncFunc(data.async, core.ui.drawScrollText, data.text, data.lineHeight || 1.4, data.time || 5000);
|
||||
}
|
||||
|
||||
events.prototype._action_comment = function (data, x, y, prefix) {
|
||||
@@ -893,7 +893,7 @@ events.prototype._action_comment = function (data, x, y, prefix) {
|
||||
}
|
||||
|
||||
events.prototype._action_setText = function (data, x, y, prefix) {
|
||||
["position", "offset", "bold", "titlefont", "textfont", "time"].forEach(function (t) {
|
||||
["position", "offset", "align", "bold", "titlefont", "textfont", "time"].forEach(function (t) {
|
||||
if (data[t] != null) core.status.textAttribute[t] = data[t];
|
||||
});
|
||||
["background", "title", "text"].forEach(function (t) {
|
||||
@@ -1030,10 +1030,9 @@ events.prototype._action_changePos = function (data, x, y, prefix) {
|
||||
}
|
||||
|
||||
events.prototype._action_showImage = function (data, x, y, prefix) {
|
||||
var loc = this.__action_getLoc(data.loc, 0, 0, prefix);
|
||||
if (core.isReplaying()) data.time = 0;
|
||||
this.__action_doAsyncFunc(data.async || data.time == 0, this.showImage,
|
||||
data.code, data.image, loc[0], loc[1], data.dw, data.dh, data.opacity, data.time);
|
||||
data.code, data.image, data.sloc, data.loc, data.opacity, data.time);
|
||||
}
|
||||
|
||||
events.prototype._action_showTextImage = function (data, x, y, prefix) {
|
||||
@@ -1815,21 +1814,27 @@ events.prototype.closeDoor = function (x, y, id, callback) {
|
||||
}
|
||||
|
||||
////// 显示图片 //////
|
||||
events.prototype.showImage = function (code, image, x, y, dw, dh, opacityVal, time, callback) {
|
||||
dw /= 100;
|
||||
dh /= 100;
|
||||
x = core.calValue(x) || 0;
|
||||
y = core.calValue(y) || 0;
|
||||
events.prototype.showImage = function (code, image, sloc, loc, opacityVal, time, callback) {
|
||||
if (typeof image == 'string') image = core.material.images.images[image];
|
||||
if (!image) {
|
||||
if (callback) callback();
|
||||
return;
|
||||
}
|
||||
sloc = sloc || [];
|
||||
var sx = core.calValue(sloc[0]) || 0, sy = core.calValue(sloc[1]) || 0;
|
||||
var sw = core.calValue(sloc[2]), sh = core.calValue(sloc[3]);
|
||||
if (sw == null) sw = image.width;
|
||||
if (sh == null) sh = image.height;
|
||||
loc = loc || [];
|
||||
var x = core.calValue(loc[0]) || 0, y = core.calValue(loc[1]) || 0;
|
||||
var w = core.calValue(loc[2]), h = core.calValue(loc[3]);
|
||||
if (w == null) w = sw;
|
||||
if (h == null) h = sh;
|
||||
var zIndex = code + 100;
|
||||
time = time || 0;
|
||||
var name = "image" + zIndex;
|
||||
var ctx = core.createCanvas(name, x, y, image.width * dw, image.height * dh, zIndex);
|
||||
ctx.drawImage(image, 0, 0, image.width * dw, image.height * dh);
|
||||
var ctx = core.createCanvas(name, x, y, w, h, zIndex);
|
||||
ctx.drawImage(image, sx, sy, sw, sh, 0, 0, w, h);
|
||||
if (time == 0) {
|
||||
core.setOpacity(name, opacityVal);
|
||||
if (callback) callback();
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ loader.prototype._load = function (callback) {
|
||||
|
||||
loader.prototype._loadIcons = function () {
|
||||
this.loadImage("icons.png", function (id, image) {
|
||||
var images = core.cropImage(image);
|
||||
var images = core.splitImage(image);
|
||||
for (var key in core.statusBar.icons) {
|
||||
if (typeof core.statusBar.icons[key] == 'number') {
|
||||
core.statusBar.icons[key] = images[core.statusBar.icons[key]];
|
||||
|
||||
+11
-8
@@ -873,29 +873,31 @@ ui.prototype._createTextCanvas = function (content, lineHeight) {
|
||||
ctx.canvas.width = width;
|
||||
ctx.canvas.height = height;
|
||||
ctx.clearRect(0, 0, width, height);
|
||||
return ctx;
|
||||
}
|
||||
|
||||
////// 绘制滚动字幕 //////
|
||||
ui.prototype.drawScrollText = function (content, time, callback) {
|
||||
ui.prototype.drawScrollText = function (content, time, lineHeight, callback) {
|
||||
content = core.replaceText(content || "");
|
||||
lineHeight = lineHeight || 1.4;
|
||||
time = time || 5000;
|
||||
clearInterval(core.status.event.interval);
|
||||
core.status.event.interval = null;
|
||||
var offset = core.status.textAttribute.offset || 15;
|
||||
var lineHeight = core.status.textAttribute.textfont * 1.4;
|
||||
lineHeight *= core.status.textAttribute.textfont;
|
||||
var ctx = this._createTextCanvas(content, lineHeight);
|
||||
var obj = { align: core.status.textAttribute.align, lineHeight: lineHeight };
|
||||
if (obj.align == 'right') obj.left = this.PIXEL - offset;
|
||||
else if (obj.align != 'center') obj.left = offset;
|
||||
this.drawTextContent(ctx, content, obj);
|
||||
this._drawScrollText_animate(ctx, height, time, callback);
|
||||
this._drawScrollText_animate(ctx, time, callback);
|
||||
}
|
||||
|
||||
ui.prototype._drawScrollText_animate = function (ctx, height, time, callback) {
|
||||
ui.prototype._drawScrollText_animate = function (ctx, time, callback) {
|
||||
// 开始绘制到UI上
|
||||
core.clearMap('ui');
|
||||
var per_pixel = 1, per_time = time * per_pixel / (416+height);
|
||||
var currH = 416;
|
||||
var per_pixel = 1, height = ctx.canvas.height, per_time = time * per_pixel / (this.PIXEL+height);
|
||||
var currH = this.PIXEL;
|
||||
core.drawImage('ui', ctx.canvas, 0, currH);
|
||||
var animate = setInterval(function () {
|
||||
core.clearMap('ui');
|
||||
@@ -913,9 +915,10 @@ ui.prototype._drawScrollText_animate = function (ctx, height, time, callback) {
|
||||
}
|
||||
|
||||
////// 文本图片化 //////
|
||||
ui.prototype.textImage = function (content) {
|
||||
ui.prototype.textImage = function (content, lineHeight) {
|
||||
content = core.replaceText(content || "");
|
||||
var lineHeight = core.status.textAttribute.textfont * 1.4;
|
||||
lineHeight = lineHeight || 1.4;
|
||||
lineHeight *= core.status.textAttribute.textfont;
|
||||
var ctx = this._createTextCanvas(content, lineHeight);
|
||||
this.drawTextContent(ctx, content, { align: core.status.textAttribute.align, lineHeight: lineHeight });
|
||||
return ctx.canvas;
|
||||
|
||||
+16
-10
@@ -311,19 +311,25 @@ utils.prototype.clone = function (data) {
|
||||
}
|
||||
|
||||
////// 裁剪图片 //////
|
||||
utils.prototype.cropImage = function (image, size) {
|
||||
size = size || 32;
|
||||
utils.prototype.splitImage = function (image, width, height) {
|
||||
if (typeof image == "string")
|
||||
image = core.material.images.images[image];
|
||||
if (!image) return [];
|
||||
width = width || 32;
|
||||
height = height || width;
|
||||
var canvas = document.createElement("canvas");
|
||||
var context = canvas.getContext("2d");
|
||||
canvas.width = size;
|
||||
canvas.height = size;
|
||||
canvas.width = width;
|
||||
canvas.height = height;
|
||||
var ans = [];
|
||||
for (var i = 0; i < image.height; i += size) {
|
||||
context.drawImage(image, 0, i, size, size, 0, 0, size, size);
|
||||
var img = new Image();
|
||||
img.src = canvas.toDataURL("image/png");
|
||||
ans.push(img);
|
||||
context.clearRect(0, 0, size, size);
|
||||
for (var j = 0; j < image.height; j += height) {
|
||||
for (var i = 0; i < image.width; i += width) {
|
||||
context.drawImage(image, i, j, width, height, 0, 0, width, height);
|
||||
var img = new Image();
|
||||
img.src = canvas.toDataURL("image/png");
|
||||
ans.push(img);
|
||||
context.clearRect(0, 0, width, height);
|
||||
}
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user