Merge pull request #167 from g4z3r/master

little optimizations
This commit is contained in:
Vadim Lopatin 2016-01-29 11:51:10 +03:00
commit 3c5573aba0
4 changed files with 34 additions and 50 deletions

View File

@ -46,10 +46,8 @@ class GLDrawBuf : DrawBuf, GLConfigCallback {
@property Scene scene() { return _scene; } @property Scene scene() { return _scene; }
this(int dx, int dy, bool framebuffer = false) { this(int dx, int dy, bool framebuffer = false) {
_dx = dx; resize(dx, dy);
_dy = dy;
_framebuffer = framebuffer; _framebuffer = framebuffer;
resetClipping();
} }
/// returns current width /// returns current width
@ -65,7 +63,6 @@ class GLDrawBuf : DrawBuf, GLConfigCallback {
/// reserved for hardware-accelerated drawing - begins drawing batch /// reserved for hardware-accelerated drawing - begins drawing batch
override void beforeDrawing() { override void beforeDrawing() {
resetClipping();
_alpha = 0; _alpha = 0;
if (_scene !is null) { if (_scene !is null) {
_scene.reset(); _scene.reset();

View File

@ -422,12 +422,13 @@ class SDLWindow : Window {
float b = ((_backgroundColor >> 0) & 255) / 255.0f; float b = ((_backgroundColor >> 0) & 255) / 255.0f;
glClearColor(r, g, b, a); glClearColor(r, g, b, a);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
GLDrawBuf buf = new GLDrawBuf(_dx, _dy, false); if (!_drawbuf)
buf.beforeDrawing(); _drawbuf = new GLDrawBuf(_dx, _dy);
onDraw(buf); _drawbuf.resize(_dx, _dy);
buf.afterDrawing(); _drawbuf.beforeDrawing();
onDraw(_drawbuf);
_drawbuf.afterDrawing();
SDL_GL_SwapWindow(_win); SDL_GL_SwapWindow(_win);
destroy(buf);
} }
} else { } else {
// Select the color for drawing. // Select the color for drawing.
@ -441,10 +442,9 @@ class SDLWindow : Window {
if (!_drawbuf) if (!_drawbuf)
_drawbuf = new ColorDrawBuf(_dx, _dy); _drawbuf = new ColorDrawBuf(_dx, _dy);
_drawbuf.resize(_dx, _dy); _drawbuf.resize(_dx, _dy);
_drawbuf.resetClipping();
_drawbuf.fill(_backgroundColor); _drawbuf.fill(_backgroundColor);
onDraw(_drawbuf); onDraw(_drawbuf);
draw(_drawbuf); draw(cast(ColorDrawBuf)_drawbuf);
// Up until now everything was drawn behind the scenes. // Up until now everything was drawn behind the scenes.
// This will show the new, red contents of the window. // This will show the new, red contents of the window.
@ -452,7 +452,7 @@ class SDLWindow : Window {
} }
} }
ColorDrawBuf _drawbuf; DrawBuf _drawbuf;
//bool _exposeSent; //bool _exposeSent;
void processExpose() { void processExpose() {

View File

@ -960,12 +960,10 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction
// draw caret // draw caret
Rect caretRc = caretRect(); Rect caretRc = caretRect();
if (caretRc.intersects(_clientRect)) { if (caretRc.intersects(_clientRect)) {
Rect rc1 = caretRc;
rc1.right = rc1.left + 1;
caretRc.left++; caretRc.left++;
if (_replaceMode) if (_replaceMode)
buf.fillRect(caretRc, _caretColorReplace); buf.fillRect(caretRc, _caretColorReplace);
buf.fillRect(rc1, _caretColor); buf.drawLine(Point(caretRc.left, caretRc.bottom), Point(caretRc.left, caretRc.top), _caretColor);
} }
} }
} }

View File

@ -1407,11 +1407,6 @@ class StringGridWidget : StringGridWidgetBase {
/// draw cell background /// draw cell background
protected override void drawHeaderCellBackground(DrawBuf buf, Rect rc, int c, int r) { protected override void drawHeaderCellBackground(DrawBuf buf, Rect rc, int c, int r) {
Rect vborder = rc;
Rect hborder = rc;
vborder.left = vborder.right - 1;
hborder.top = hborder.bottom - 1;
hborder.right--;
bool selectedCol = (c == col) && !_rowSelect; bool selectedCol = (c == col) && !_rowSelect;
bool selectedRow = r == row; bool selectedRow = r == row;
bool selectedCell = selectedCol && selectedRow; bool selectedCell = selectedCol && selectedRow;
@ -1426,8 +1421,30 @@ class StringGridWidget : StringGridWidgetBase {
cl = _cellHeaderSelectedBackgroundColor; cl = _cellHeaderSelectedBackgroundColor;
} }
buf.fillRect(rc, cl); buf.fillRect(rc, cl);
buf.fillRect(vborder, _cellHeaderBorderColor); buf.drawLine(Point(rc.right, rc.bottom), Point(rc.right, rc.top), _cellHeaderBorderColor); // vertical
buf.fillRect(hborder, _cellHeaderBorderColor); buf.drawLine(Point(rc.left, rc.bottom), Point(rc.right - 1, rc.bottom), _cellHeaderBorderColor); // horizontal
}
/// draw cell background
protected override void drawCellBackground(DrawBuf buf, Rect rc, int c, int r) {
bool selectedCol = c == col;
bool selectedRow = r == row;
bool selectedCell = selectedCol && selectedRow;
if (_rowSelect && selectedRow)
selectedCell = true;
// normal cell background
if (c < fixedCols || r < fixedRows) {
// fixed cell background
buf.fillRect(rc, _fixedCellBackgroundColor);
}
buf.drawLine(Point(rc.left, rc.bottom + 1), Point(rc.left, rc.top), _cellBorderColor); // vertical
buf.drawLine(Point(rc.left, rc.bottom), Point(rc.right - 1, rc.bottom), _cellBorderColor); // horizontal
if (selectedCell) {
if (_rowSelect)
buf.drawFrame(rc, _selectionColorRowSelect, Rect(0,1,0,1), _cellBorderColor);
else
buf.drawFrame(rc, _selectionColor, Rect(1,1,1,1), _cellBorderColor);
}
} }
@ -1442,34 +1459,6 @@ class StringGridWidget : StringGridWidgetBase {
_cellHeaderSelectedBackgroundColor = style.customColor("grid_cell_background_header_selected", 0x80FFC040); _cellHeaderSelectedBackgroundColor = style.customColor("grid_cell_background_header_selected", 0x80FFC040);
super.onThemeChanged(); super.onThemeChanged();
} }
/// draw cell background
protected override void drawCellBackground(DrawBuf buf, Rect rc, int c, int r) {
Rect vborder = rc;
Rect hborder = rc;
vborder.left = vborder.right - 1;
hborder.top = hborder.bottom - 1;
hborder.right--;
bool selectedCol = c == col;
bool selectedRow = r == row;
bool selectedCell = selectedCol && selectedRow;
if (_rowSelect && selectedRow)
selectedCell = true;
// normal cell background
if (c < fixedCols || r < fixedRows) {
// fixed cell background
buf.fillRect(rc, _fixedCellBackgroundColor);
}
buf.fillRect(vborder, _cellBorderColor);
buf.fillRect(hborder, _cellBorderColor);
if (selectedCell) {
if (_rowSelect)
buf.drawFrame(rc, _selectionColorRowSelect, Rect(0,1,0,1), _cellBorderColor);
else
buf.drawFrame(rc, _selectionColor, Rect(1,1,1,1), _cellBorderColor);
}
}
} }
import dlangui.widgets.metadata; import dlangui.widgets.metadata;