Merge branch 'master' of github.com:buggins/dlangui

This commit is contained in:
Vadim Lopatin 2015-12-19 07:52:34 +03:00
commit 872b77241b
5 changed files with 77 additions and 107 deletions

View File

@ -216,8 +216,13 @@ class FileDialog : Dialog, CustomGridCellAdapter {
else else
resname = "text-plain"; resname = "text-plain";
_fileList.setCellText(0, i, toUTF32(resname)); _fileList.setCellText(0, i, toUTF32(resname));
sz = to!string(_entries[i].size); double size = _entries[i].size;
date = "2014-01-01 00:00:00"; import std.format : format;
sz = size < 1024 ? to!string(size) ~ " B" :
(size < 1024*1024 ? "%.1f".format(size/1024) ~ " KB" :
(size < 1024*1024*1024 ? "%.1f".format(size/(1024*1024)) ~ " MB" :
"%.1f".format(size/(1024*1024*1024)) ~ " GB"));
date = _entries[i].timeLastModified.toSimpleString();
} }
_fileList.setCellText(2, i, toUTF32(sz)); _fileList.setCellText(2, i, toUTF32(sz));
_fileList.setCellText(3, i, toUTF32(date)); _fileList.setCellText(3, i, toUTF32(date));

View File

@ -45,20 +45,6 @@ derelict.util.exception.ShouldThrow gl3MissingSymFunc( string symName ) {
return derelict.util.exception.ShouldThrow.No; return derelict.util.exception.ShouldThrow.No;
} }
// utility function to fill 4-float array of vertex colors with converted CR 32bit color
private void LVGLFillColor(uint color, float * buf, int count) {
float r = ((color >> 16) & 255) / 255.0f;
float g = ((color >> 8) & 255) / 255.0f;
float b = ((color >> 0) & 255) / 255.0f;
float a = (((color >> 24) & 255) ^ 255) / 255.0f;
for (int i=0; i<count; i++) {
*buf++ = r;
*buf++ = g;
*buf++ = b;
*buf++ = a;
}
}
/* For reporting OpenGL errors, it's nicer to get a human-readable symbolic name for the /* For reporting OpenGL errors, it's nicer to get a human-readable symbolic name for the
* error instead of the numeric form. Derelict's GLenum is just an alias for uint, so we * error instead of the numeric form. Derelict's GLenum is just an alias for uint, so we
* can't depend on D's nice toString() for enums. * can't depend on D's nice toString() for enums.
@ -103,14 +89,14 @@ bool checkError(string context="", string functionName=__FUNCTION__, int line=__
class GLProgram { class GLProgram {
@property abstract string vertexSource(); @property abstract string vertexSource();
@property abstract string fragmentSource(); @property abstract string fragmentSource();
protected GLuint vertexShader; private GLuint vertexShader;
protected GLuint fragmentShader; private GLuint fragmentShader;
protected GLuint program; protected GLuint program;
protected bool initialized; protected bool initialized;
protected bool error; protected bool error;
protected string glslversion; private string glslversion;
protected int glslversionInt; private int glslversionInt;
protected char[] glslversionString; private char[] glslversionString;
this() { this() {
} }
@ -133,7 +119,7 @@ class GLProgram {
sourceCode ~= src; sourceCode ~= src;
compatibilityFixes(sourceCode, type); compatibilityFixes(sourceCode, type);
Log.d("compileShader glsl=", glslversion, " type:", (type == GL_VERTEX_SHADER ? "GL_VERTEX_SHADER" : (type == GL_FRAGMENT_SHADER ? "GL_FRAGMENT_SHADER" : "UNKNOWN")), " code:\n", sourceCode); Log.d("compileShader: glsl = ", glslversion, ", type: ", (type == GL_VERTEX_SHADER ? "GL_VERTEX_SHADER" : (type == GL_FRAGMENT_SHADER ? "GL_FRAGMENT_SHADER" : "UNKNOWN")));//, " code:\n", sourceCode);
GLuint shader = glCreateShader(type); GLuint shader = glCreateShader(type);
const char * psrc = sourceCode.toStringz; const char * psrc = sourceCode.toStringz;
glShaderSource(shader, 1, &psrc, null); glShaderSource(shader, 1, &psrc, null);
@ -192,40 +178,18 @@ class GLProgram {
return false; return false;
} }
Log.d("Program linked successfully"); Log.d("Program linked successfully");
Log.v("trying glUseProgram with 0");
glUseProgram(0);
Log.v("before useProgram");
glUseProgram(program);
checkError("glUseProgram " ~ to!string(program));
Log.v("after useProgram");
if (!initLocations()) { if (!initLocations()) {
Log.e("some of locations were not found"); Log.e("some of locations were not found");
error = true; error = true;
} }
initialized = true; initialized = true;
Log.v("Program is initialized successfully"); Log.v("Program is initialized successfully");
checkgl!glUseProgram(0);
return !error; return !error;
} }
bool initLocations() { abstract bool initLocations();
return true;
}
bool bind() {
if (!initialized)
return false;
if (!glIsProgram(program))
Log.e("!glIsProgram(program)");
glUseProgram(program);
checkError("glUseProgram " ~ to!string(program));
return true;
}
void release() {
checkgl!glUseProgram(0);
}
~this() { ~this() {
clear();
}
void clear() {
// TODO: cleanup // TODO: cleanup
if (program) if (program)
glDeleteProgram(program); glDeleteProgram(program);
@ -278,27 +242,29 @@ class SolidFillProgram : GLProgram {
return true; return true;
} }
void bind() {
checkgl!glUseProgram(program);
}
void unbind() {
checkgl!glUseProgram(0);
}
void beforeExecute() { void beforeExecute() {
glEnable(GL_BLEND); glEnable(GL_BLEND);
checkgl!glDisable(GL_CULL_FACE); checkgl!glDisable(GL_CULL_FACE);
checkgl!glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); checkgl!glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
bind(); bind();
//glUniformMatrix4fv(matrixLocation, 1, false, m.value_ptr);
//glUniformMatrix4fv(matrixLocation, 1, false, matrix.ptr);
checkgl!glUniformMatrix4fv(matrixLocation, 1, false, glSupport.qtmatrix.ptr); checkgl!glUniformMatrix4fv(matrixLocation, 1, false, glSupport.qtmatrix.ptr);
} }
void afterExecute() { void afterExecute() {
release(); unbind();
} }
protected GLint matrixLocation; protected GLint matrixLocation;
protected GLint vertexLocation; protected GLint vertexLocation;
protected GLint colAttrLocation; protected GLint colAttrLocation;
override bool initLocations() { override bool initLocations() {
bool res = super.initLocations();
matrixLocation = checkgl!glGetUniformLocation(program, toStringz("matrix")); matrixLocation = checkgl!glGetUniformLocation(program, toStringz("matrix"));
if (matrixLocation == -1) if (matrixLocation == -1)
Log.e("glGetUniformLocation failed for matrixLocation"); Log.e("glGetUniformLocation failed for matrixLocation");
@ -308,7 +274,7 @@ class SolidFillProgram : GLProgram {
colAttrLocation = checkgl!glGetAttribLocation(program, toStringz("colAttr")); colAttrLocation = checkgl!glGetAttribLocation(program, toStringz("colAttr"));
if (colAttrLocation == -1) if (colAttrLocation == -1)
Log.e("glGetUniformLocation failed for colAttrLocation"); Log.e("glGetUniformLocation failed for colAttrLocation");
return res && matrixLocation >= 0 && vertexLocation >= 0 && colAttrLocation >= 0; return matrixLocation >= 0 && vertexLocation >= 0 && colAttrLocation >= 0;
} }
bool execute(float[] vertices, float[] colors) { bool execute(float[] vertices, float[] colors) {
@ -329,9 +295,6 @@ class SolidFillProgram : GLProgram {
checkgl!glDrawArrays(GL_TRIANGLES, 0, cast(int)vertices.length/3); checkgl!glDrawArrays(GL_TRIANGLES, 0, cast(int)vertices.length/3);
glDisableVertexAttribArray(vertexLocation);
glDisableVertexAttribArray(colAttrLocation);
afterExecute(); afterExecute();
destroy(vbo); destroy(vbo);
@ -359,9 +322,6 @@ class LineProgram : SolidFillProgram {
checkgl!glDrawArrays(GL_LINES, 0, cast(int)vertices.length/3); checkgl!glDrawArrays(GL_LINES, 0, cast(int)vertices.length/3);
glDisableVertexAttribArray(vertexLocation);
glDisableVertexAttribArray(colAttrLocation);
afterExecute(); afterExecute();
destroy(vbo); destroy(vbo);
@ -408,7 +368,7 @@ class TextureProgram : SolidFillProgram {
return res && texCoordLocation >= 0; return res && texCoordLocation >= 0;
} }
bool execute(float[] vertices, float[] texcoords, float[] colors, Tex2D texture, bool linear) { bool execute(float[] vertices, float[] colors, float[] texcoords, Tex2D texture, bool linear) {
if(!check()) if(!check())
return false; return false;
beforeExecute(); beforeExecute();
@ -484,15 +444,8 @@ class FontProgram : SolidFillProgram {
} }
override void beforeExecute() { override void beforeExecute() {
glEnable(GL_BLEND); super.beforeExecute();
checkgl!glDisable(GL_CULL_FACE);
checkgl!glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glBlendFunc(GL_ONE, GL_SRC_COLOR);
//glBlendFunc(GL_ONE, GL_SRC_COLOR);
//glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR); //glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR);
//glBlendFunc(GL_ONE_MINUS_SRC_COLOR, GL_SRC_COLOR);
bind();
checkgl!glUniformMatrix4fv(matrixLocation, 1, false, glSupport.qtmatrix.ptr);
} }
override void afterExecute() { override void afterExecute() {
@ -500,7 +453,7 @@ class FontProgram : SolidFillProgram {
super.afterExecute(); super.afterExecute();
} }
bool execute(float[] vertices, float[] texcoords, float[] colors, Tex2D texture, bool linear) { bool execute(float[] vertices, float[] colors, float[] texcoords, Tex2D texture, bool linear) {
if(!check()) if(!check())
return false; return false;
beforeExecute(); beforeExecute();
@ -523,10 +476,6 @@ class FontProgram : SolidFillProgram {
checkgl!glDrawArrays(GL_TRIANGLES, 0, cast(int)vertices.length/3); checkgl!glDrawArrays(GL_TRIANGLES, 0, cast(int)vertices.length/3);
glDisableVertexAttribArray(vertexLocation);
glDisableVertexAttribArray(colAttrLocation);
glDisableVertexAttribArray(texCoordLocation);
afterExecute(); afterExecute();
destroy(vbo); destroy(vbo);
@ -537,6 +486,26 @@ class FontProgram : SolidFillProgram {
} }
} }
struct Color
{
float r, g, b, a;
}
// utility function to fill 4-float array of vertex colors with converted CR 32bit color
private void FillColor(uint color, Color[] buf_slice) {
float r = ((color >> 16) & 255) / 255.0;
float g = ((color >> 8) & 255) / 255.0;
float b = ((color >> 0) & 255) / 255.0;
float a = (((color >> 24) & 255) ^ 255) / 255.0;
foreach(ref col; buf_slice) {
col.r = r;
col.g = g;
col.b = b;
col.a = a;
}
}
__gshared GLSupport _glSupport; __gshared GLSupport _glSupport;
@property GLSupport glSupport() { @property GLSupport glSupport() {
if (!_glSupport) { if (!_glSupport) {
@ -638,9 +607,9 @@ class GLSupport {
} }
void drawLine(Point p1, Point p2, uint color1, uint color2) { void drawLine(Point p1, Point p2, uint color1, uint color2) {
float[2 * 4] colors; Color[2] colors;
LVGLFillColor(color1, colors.ptr + 4*0, 1); FillColor(color1, colors[0..1]);
LVGLFillColor(color2, colors.ptr + 4*1, 1); FillColor(color2, colors[1..2]);
float x0 = cast(float)(p1.x); float x0 = cast(float)(p1.x);
float y0 = cast(float)(bufferDy-p1.y); float y0 = cast(float)(bufferDy-p1.y);
float x1 = cast(float)(p2.x); float x1 = cast(float)(p2.x);
@ -657,21 +626,20 @@ class GLSupport {
x1,y1,Z_2D x1,y1,Z_2D
]; ];
if (_lineProgram !is null) { if (_lineProgram !is null) {
//Log.d("solid fill: vertices ", vertices, " colors ", colors); _lineProgram.execute(vertices, cast(float[])colors);
_lineProgram.execute(vertices, colors);
} else } else
Log.e("No program"); Log.e("No program");
} }
static immutable float Z_2D = -2.0f; static immutable float Z_2D = -2.0f;
void drawSolidFillRect(Rect rc, uint color1, uint color2, uint color3, uint color4) { void drawSolidFillRect(Rect rc, uint color1, uint color2, uint color3, uint color4) {
float[6 * 4] colors; Color[6] colors;
LVGLFillColor(color1, colors.ptr + 4*0, 1); FillColor(color1, colors[0..1]);
LVGLFillColor(color4, colors.ptr + 4*1, 1); FillColor(color4, colors[1..2]);
LVGLFillColor(color3, colors.ptr + 4*2, 1); FillColor(color3, colors[2..3]);
LVGLFillColor(color1, colors.ptr + 4*3, 1); FillColor(color1, colors[3..4]);
LVGLFillColor(color3, colors.ptr + 4*4, 1); FillColor(color3, colors[4..5]);
LVGLFillColor(color2, colors.ptr + 4*5, 1); FillColor(color2, colors[5..6]);
float x0 = cast(float)(rc.left); float x0 = cast(float)(rc.left);
float y0 = cast(float)(bufferDy-rc.top); float y0 = cast(float)(bufferDy-rc.top);
float x1 = cast(float)(rc.right); float x1 = cast(float)(rc.right);
@ -710,21 +678,19 @@ class GLSupport {
glDisable(GL_BLEND); glDisable(GL_BLEND);
} else { } else {
if (_solidFillProgram !is null) { if (_solidFillProgram !is null) {
//Log.d("solid fill: vertices ", vertices, " colors ", colors); _solidFillProgram.execute(vertices, cast(float[])colors);
_solidFillProgram.execute(vertices, colors);
} else } else
Log.e("No program"); Log.e("No program");
} }
} }
void drawColorAndTextureGlyphRect(Tex2D texture, int tdx, int tdy, Rect srcrc, Rect dstrc, uint color) { void drawColorAndTextureGlyphRect(Tex2D texture, int tdx, int tdy, Rect srcrc, Rect dstrc, uint color) {
//Log.v("drawColorAndGlyphRect tx=", texture.ID, " src=", srcrc, " dst=", dstrc);
drawColorAndTextureGlyphRect(texture, tdx, tdy, srcrc.left, srcrc.top, srcrc.width(), srcrc.height(), dstrc.left, dstrc.top, dstrc.width(), dstrc.height(), color); drawColorAndTextureGlyphRect(texture, tdx, tdy, srcrc.left, srcrc.top, srcrc.width(), srcrc.height(), dstrc.left, dstrc.top, dstrc.width(), dstrc.height(), color);
} }
void drawColorAndTextureGlyphRect(Tex2D texture, int tdx, int tdy, int srcx, int srcy, int srcdx, int srcdy, int xx, int yy, int dx, int dy, uint color) { void drawColorAndTextureGlyphRect(Tex2D texture, int tdx, int tdy, int srcx, int srcy, int srcdx, int srcdy, int xx, int yy, int dx, int dy, uint color) {
float[6*4] colors; Color[6] colors;
LVGLFillColor(color, colors.ptr, 6); FillColor(color, colors);
float dstx0 = cast(float)xx; float dstx0 = cast(float)xx;
float dsty0 = cast(float)(bufferDy - (yy)); float dsty0 = cast(float)(bufferDy - (yy));
float dstx1 = cast(float)(xx + dx); float dstx1 = cast(float)(xx + dx);
@ -740,8 +706,8 @@ class GLSupport {
float srcy0 = srcy / cast(float)tdy; float srcy0 = srcy / cast(float)tdy;
float srcx1 = (srcx + srcdx) / cast(float)tdx; float srcx1 = (srcx + srcdx) / cast(float)tdx;
float srcy1 = (srcy + srcdy) / cast(float)tdy; float srcy1 = (srcy + srcdy) / cast(float)tdy;
float[3 * 6] vertices = float[3 * 6] vertices = [
[dstx0, dsty0, Z_2D, dstx0, dsty0, Z_2D,
dstx0, dsty1, Z_2D, dstx0, dsty1, Z_2D,
dstx1, dsty1, Z_2D, dstx1, dsty1, Z_2D,
dstx0, dsty0, Z_2D, dstx0, dsty0, Z_2D,
@ -778,19 +744,18 @@ class GLSupport {
glDisable(GL_ALPHA_TEST); glDisable(GL_ALPHA_TEST);
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
} else { } else {
_fontProgram.execute(vertices, texcoords, colors, texture, false); _fontProgram.execute(vertices, cast(float[])colors, texcoords, texture, false);
} }
//drawColorAndTextureRect(vertices, texcoords, colors, texture, linear); //drawColorAndTextureRect(vertices, texcoords, colors, texture, linear);
} }
void drawColorAndTextureRect(Tex2D texture, int tdx, int tdy, Rect srcrc, Rect dstrc, uint color, bool linear) { void drawColorAndTextureRect(Tex2D texture, int tdx, int tdy, Rect srcrc, Rect dstrc, uint color, bool linear) {
//Log.v("drawColorAndTextureRect tx=", texture.ID, " src=", srcrc, " dst=", dstrc);
drawColorAndTextureRect(texture, tdx, tdy, srcrc.left, srcrc.top, srcrc.width(), srcrc.height(), dstrc.left, dstrc.top, dstrc.width(), dstrc.height(), color, linear); drawColorAndTextureRect(texture, tdx, tdy, srcrc.left, srcrc.top, srcrc.width(), srcrc.height(), dstrc.left, dstrc.top, dstrc.width(), dstrc.height(), color, linear);
} }
void drawColorAndTextureRect(Tex2D texture, int tdx, int tdy, int srcx, int srcy, int srcdx, int srcdy, int xx, int yy, int dx, int dy, uint color, bool linear) { void drawColorAndTextureRect(Tex2D texture, int tdx, int tdy, int srcx, int srcy, int srcdx, int srcdy, int xx, int yy, int dx, int dy, uint color, bool linear) {
float[6*4] colors; Color[6] colors;
LVGLFillColor(color, colors.ptr, 6); FillColor(color, colors);
float dstx0 = cast(float)xx; float dstx0 = cast(float)xx;
float dsty0 = cast(float)(bufferDy - (yy)); float dsty0 = cast(float)(bufferDy - (yy));
float dstx1 = cast(float)(xx + dx); float dstx1 = cast(float)(xx + dx);
@ -806,12 +771,13 @@ class GLSupport {
float srcy0 = srcy / cast(float)tdy; float srcy0 = srcy / cast(float)tdy;
float srcx1 = (srcx + srcdx) / cast(float)tdx; float srcx1 = (srcx + srcdx) / cast(float)tdx;
float srcy1 = (srcy + srcdy) / cast(float)tdy; float srcy1 = (srcy + srcdy) / cast(float)tdy;
float[3 * 6] vertices = [dstx0,dsty0,Z_2D, float[3 * 6] vertices = [
dstx0,dsty1,Z_2D, dstx0,dsty0,Z_2D,
dstx1,dsty1,Z_2D, dstx0,dsty1,Z_2D,
dstx0,dsty0,Z_2D, dstx1,dsty1,Z_2D,
dstx1,dsty1,Z_2D, dstx0,dsty0,Z_2D,
dstx1,dsty0,Z_2D]; dstx1,dsty1,Z_2D,
dstx1,dsty0,Z_2D];
float[2 * 6] texcoords = [srcx0,srcy0, srcx0,srcy1, srcx1,srcy1, srcx0,srcy0, srcx1,srcy1, srcx1,srcy0]; float[2 * 6] texcoords = [srcx0,srcy0, srcx0,srcy1, srcx1,srcy1, srcx0,srcy0, srcx1,srcy1, srcx1,srcy0];
if (_legacyMode) { if (_legacyMode) {
@ -842,7 +808,7 @@ class GLSupport {
glDisable(GL_ALPHA_TEST); glDisable(GL_ALPHA_TEST);
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
} else { } else {
_textureProgram.execute(vertices, texcoords, colors, texture, linear); _textureProgram.execute(vertices, cast(float[])colors, texcoords, texture, linear);
} }
//drawColorAndTextureRect(vertices, texcoords, colors, texture, linear); //drawColorAndTextureRect(vertices, texcoords, colors, texture, linear);
} }

View File

@ -180,7 +180,7 @@ class Window {
_mainWidget.window = this; _mainWidget.window = this;
} }
// Abstract methods : override in platform implementatino // Abstract methods : override in platform implementation
/// show window /// show window
abstract void show(); abstract void show();

View File

@ -182,7 +182,6 @@ class SDLWindow : Window {
static if (ENABLE_OPENGL) { static if (ENABLE_OPENGL) {
if (_enableOpengl) { if (_enableOpengl) {
Log.i("Trying to create OpenGL 3.2 context");
createContext(3, 2); createContext(3, 2);
//_context = SDL_GL_CreateContext(_win); // Create the actual context and make it current //_context = SDL_GL_CreateContext(_win); // Create the actual context and make it current
if (!_context) { if (!_context) {

View File

@ -1696,7 +1696,7 @@ class WidgetGroupDefaultDrawing : WidgetGroup {
} }
} }
immutable long ONE_SECOND = 10000000L; immutable long ONE_SECOND = 10_000_000L;
/// Helper to handle animation progress /// Helper to handle animation progress
struct AnimationHelper { struct AnimationHelper {