From 014330d3a08104313feee8ce3dfed02fb79bf2d3 Mon Sep 17 00:00:00 2001 From: Andrew Hannam Date: Mon, 12 Nov 2012 17:00:26 +1000 Subject: [PATCH 1/4] gdisp Win32 Orientation support. Revert Macro gdisp Win32 orientation support. Revert to producing an error if GDISP_NEED_TEXT is not defined when GWIN_NEED_CONSOLE or GWIN_NEED_BUTTON is defined. --- drivers/gdisp/Win32/gdisp_lld.c | 507 ++++++++++++++++++++++--- drivers/gdisp/Win32/gdisp_lld_config.h | 1 + include/gwin.h | 4 +- releases.txt | 1 + src/gwin.c | 6 + 5 files changed, 458 insertions(+), 61 deletions(-) diff --git a/drivers/gdisp/Win32/gdisp_lld.c b/drivers/gdisp/Win32/gdisp_lld.c index 69e90e89..560a5f20 100644 --- a/drivers/gdisp/Win32/gdisp_lld.c +++ b/drivers/gdisp/Win32/gdisp_lld.c @@ -47,6 +47,8 @@ /* Driver local routines . */ /*===========================================================================*/ +#define WIN32_USE_MSG_REDRAW FALSE + #define APP_NAME "GDISP" #define COLOR2BGR(c) ((((c) & 0xFF)<<16)|((c) & 0xFF00)|(((c)>>16) & 0xFF)) @@ -128,6 +130,7 @@ static DWORD WINAPI WindowThread(LPVOID lpParameter) { HANDLE hInstance; WNDCLASS wc; RECT rect; + HDC dc; hInstance = GetModuleHandle(NULL); @@ -150,15 +153,16 @@ static DWORD WINAPI WindowThread(LPVOID lpParameter) { rect.right-rect.left, rect.bottom-rect.top, 0, 0, hInstance, NULL); assert(winRootWindow != NULL); - HDC dc = GetDC(winRootWindow); GetClientRect(winRootWindow, &rect); GDISP.Width = rect.right-rect.left; GDISP.Height = rect.bottom - rect.top; + + dc = GetDC(winRootWindow); dcBitmap = CreateCompatibleBitmap(dc, GDISP.Width, GDISP.Height); dcBuffer = CreateCompatibleDC(dc); - dcOldBitmap = SelectObject(dcBuffer, dcBitmap); ReleaseDC(winRootWindow, dc); + dcOldBitmap = SelectObject(dcBuffer, dcBitmap); ShowWindow(winRootWindow, SW_SHOW); UpdateWindow(winRootWindow); @@ -230,20 +234,55 @@ bool_t GDISP_LLD(init)(void) { */ void GDISP_LLD(drawpixel)(coord_t x, coord_t y, color_t color) { HDC dc; + #if WIN32_USE_MSG_REDRAW + RECT rect; + #endif + #if GDISP_NEED_CONTROL + coord_t t; + #endif #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP + // Clip pre orientation change if (x < GDISP.clipx0 || y < GDISP.clipy0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return; #endif + #if GDISP_NEED_CONTROL + switch(GDISP.Orientation) { + case GDISP_ROTATE_0: + break; + case GDISP_ROTATE_90: + t = GDISP.Height - 1 - y; + y = x; + x = t; + break; + case GDISP_ROTATE_180: + x = GDISP.Width - 1 - x; + y = GDISP.Height - 1 - y; + break; + case GDISP_ROTATE_270: + t = GDISP.Width - 1 - x; + x = y; + y = t; + break; + } + #endif + // Draw the pixel in the buffer color = COLOR2BGR(color); SetPixel(dcBuffer, x, y, color); - // Draw the pixel again directly on the screen. - // This is cheaper than invalidating a single pixel in the window - dc = GetDC(winRootWindow); - SetPixel(dc, x, y, color); - ReleaseDC(winRootWindow, dc); + #if WIN32_USE_MSG_REDRAW + rect.left = x; rect.right = x+1; + rect.top = y; rect.bottom = y+1; + InvalidateRect(winRootWindow, &rect, FALSE); + UpdateWindow(winRootWindow); + #else + // Draw the pixel again directly on the screen. + // This is cheaper than invalidating a single pixel in the window + dc = GetDC(winRootWindow); + SetPixel(dc, x, y, color); + ReleaseDC(winRootWindow, dc); + #endif } /* ---- Optional Routines ---- */ @@ -264,14 +303,75 @@ void GDISP_LLD(drawpixel)(coord_t x, coord_t y, color_t color) { HPEN pen; HDC dc; HGDIOBJ old; - HRGN clip; + #if GDISP_NEED_CLIP + HRGN clip; + #endif + #if WIN32_USE_MSG_REDRAW + RECT rect; + #endif + #if GDISP_NEED_CONTROL + coord_t t; + #endif #if GDISP_NEED_CLIP clip = NULL; - if (GDISP.clipx0 != 0 || GDISP.clipy0 != 0 || GDISP.clipx1 != GDISP.Width || GDISP.clipy1 != GDISP.Height) - clip = CreateRectRgn(GDISP.clipx0, GDISP.clipy0, GDISP.clipx1, GDISP.clipy1); #endif + #if GDISP_NEED_CONTROL + switch(GDISP.Orientation) { + case GDISP_ROTATE_0: + #if GDISP_NEED_CLIP + // Clip post orientation change + if (GDISP.clipx0 != 0 || GDISP.clipy0 != 0 || GDISP.clipx1 != GDISP.Width || GDISP.clipy1 != GDISP.Height) + clip = CreateRectRgn(GDISP.clipx0, GDISP.clipy0, GDISP.clipx1, GDISP.clipy1); + #endif + break; + case GDISP_ROTATE_90: + t = GDISP.Height - 1 - y0; + y0 = x0; + x0 = t; + t = GDISP.Height - 1 - y1; + y1 = x1; + x1 = t; + #if GDISP_NEED_CLIP + // Clip post orientation change + if (GDISP.clipx0 != 0 || GDISP.clipy0 != 0 || GDISP.clipx1 != GDISP.Width || GDISP.clipy1 != GDISP.Height) + clip = CreateRectRgn(GDISP.Height-1-GDISP.clipy1, GDISP.clipx0, GDISP.Height-1-GDISP.clipy0, GDISP.clipx1); + #endif + break; + case GDISP_ROTATE_180: + x0 = GDISP.Width - 1 - x0; + y0 = GDISP.Height - 1 - y0; + x1 = GDISP.Width - 1 - x1; + y1 = GDISP.Height - 1 - y1; + #if GDISP_NEED_CLIP + // Clip post orientation change + if (GDISP.clipx0 != 0 || GDISP.clipy0 != 0 || GDISP.clipx1 != GDISP.Width || GDISP.clipy1 != GDISP.Height) + clip = CreateRectRgn(GDISP.Width-1-GDISP.clipx1, GDISP.Height-1-GDISP.clipy1, GDISP.Width-1-GDISP.clipx0, GDISP.Height-1-GDISP.clipy0); + #endif + break; + case GDISP_ROTATE_270: + t = GDISP.Width - 1 - x0; + x0 = y0; + y0 = t; + t = GDISP.Width - 1 - x1; + x1 = y1; + y1 = t; + #if GDISP_NEED_CLIP + // Clip post orientation change + if (GDISP.clipx0 != 0 || GDISP.clipy0 != 0 || GDISP.clipx1 != GDISP.Width || GDISP.clipy1 != GDISP.Height) + clip = CreateRectRgn(GDISP.clipy0, GDISP.Width-1-GDISP.clipx1, GDISP.clipy1, GDISP.Width-1-GDISP.clipx0); + #endif + break; + } + #else + #if GDISP_NEED_CLIP + clip = NULL; + if (GDISP.clipx0 != 0 || GDISP.clipy0 != 0 || GDISP.clipx1 != GDISP.Width || GDISP.clipy1 != GDISP.Height) + clip = CreateRectRgn(GDISP.clipx0, GDISP.clipy0, GDISP.clipx1, GDISP.clipy1); + #endif + #endif + color = COLOR2BGR(color); pen = CreatePen(PS_SOLID, 1, color); if (pen) { @@ -288,20 +388,27 @@ void GDISP_LLD(drawpixel)(coord_t x, coord_t y, color_t color) { if (clip) SelectClipRgn(dcBuffer, NULL); #endif - // Redrawing the line on the screen is cheaper than invalidating the whole rectangular area - dc = GetDC(winRootWindow); - #if GDISP_NEED_CLIP - if (clip) SelectClipRgn(dc, clip); + #if WIN32_USE_MSG_REDRAW + rect.left = x0; rect.right = x1+1; + rect.top = y0; rect.bottom = y1+1; + InvalidateRect(winRootWindow, &rect, FALSE); + UpdateWindow(winRootWindow); + #else + // Redrawing the line on the screen is cheaper than invalidating the whole rectangular area + dc = GetDC(winRootWindow); + #if GDISP_NEED_CLIP + if (clip) SelectClipRgn(dc, clip); + #endif + old = SelectObject(dc, pen); + MoveToEx(dc, x0, y0, &p); + LineTo(dc, x1, y1); + SelectObject(dc, old); + SetPixel(dc, x1, y1, color); + #if GDISP_NEED_CLIP + if (clip) SelectClipRgn(dc, NULL); + #endif + ReleaseDC(winRootWindow, dc); #endif - old = SelectObject(dc, pen); - MoveToEx(dc, x0, y0, &p); - LineTo(dc, x1, y1); - SelectObject(dc, old); - SetPixel(dc, x1, y1, color); - #if GDISP_NEED_CLIP - if (clip) SelectClipRgn(dc, NULL); - #endif - ReleaseDC(winRootWindow, dc); DeleteObject(pen); } @@ -325,6 +432,7 @@ void GDISP_LLD(drawpixel)(coord_t x, coord_t y, color_t color) { HBRUSH hbr; #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP + // Clip pre orientation change if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; x = GDISP.clipx0; } if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; y = GDISP.clipy0; } if (cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return; @@ -332,22 +440,56 @@ void GDISP_LLD(drawpixel)(coord_t x, coord_t y, color_t color) { if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y; #endif + #if GDISP_NEED_CONTROL + switch(GDISP.Orientation) { + case GDISP_ROTATE_0: + rect.top = y; + rect.bottom = rect.top+cy; + rect.left = x; + rect.right = rect.left+cx; + break; + case GDISP_ROTATE_90: + rect.top = x; + rect.bottom = rect.top+cx; + rect.right = GDISP.Height - y; + rect.left = rect.right-cy; + break; + case GDISP_ROTATE_180: + rect.bottom = GDISP.Height - y; + rect.top = rect.bottom-cy; + rect.right = GDISP.Width - x; + rect.left = rect.right-cx; + break; + case GDISP_ROTATE_270: + rect.bottom = GDISP.Width - x; + rect.top = rect.bottom-cx; + rect.left = y; + rect.right = rect.left+cy; + break; + } + #else + rect.top = y; + rect.bottom = rect.top+cy; + rect.left = x; + rect.right = rect.left+cx; + #endif + color = COLOR2BGR(color); hbr = CreateSolidBrush(color); if (hbr) { - rect.bottom = y+cy; - rect.top = y; - rect.left = x; - rect.right = x+cx; - // Fill the area FillRect(dcBuffer, &rect, hbr); - // Filling the area directly on the screen is likely to be cheaper than invalidating it - dc = GetDC(winRootWindow); - FillRect(dc, &rect, hbr); - ReleaseDC(winRootWindow, dc); + #if WIN32_USE_MSG_REDRAW + InvalidateRect(winRootWindow, &rect, FALSE); + UpdateWindow(winRootWindow); + #else + // Filling the area directly on the screen is likely to be cheaper than invalidating it + dc = GetDC(winRootWindow); + FillRect(dc, &rect, hbr); + ReleaseDC(winRootWindow, dc); + #endif DeleteObject(hbr); } @@ -355,6 +497,52 @@ void GDISP_LLD(drawpixel)(coord_t x, coord_t y, color_t color) { #endif #if GDISP_HARDWARE_BITFILLS || defined(__DOXYGEN__) + static pixel_t *rotateimg(coord_t cx, coord_t cy, coord_t srcx, coord_t srccx, const pixel_t *buffer) { + pixel_t *dstbuf; + pixel_t *dst; + const pixel_t *src; + size_t sz; + coord_t i, j; + + // Shortcut. + if (GDISP.Orientation == GDISP_ROTATE_0 && srcx == 0 && cx == srccx) + return (pixel_t *)buffer; + + // Allocate the destination buffer + sz = (size_t)cx * (size_t)cy; + if (!(dstbuf = (pixel_t *)malloc(sz * sizeof(pixel_t)))) + return 0; + + // Copy the bits we need + switch(GDISP.Orientation) { + case GDISP_ROTATE_0: + for(dst = dstbuf, src = buffer+srcx, j = 0; j < cy; j++) + for(i = 0; i < cx; i++, src += srccx - cx) + *dst++ = *src++; + break; + case GDISP_ROTATE_90: + for(src = buffer+srcx, j = 0; j < cy; j++) { + dst = dstbuf+cy-j-1; + for(i = 0; i < cx; i++, src += srccx - cx, dst += cy) + *dst = *src++; + } + break; + case GDISP_ROTATE_180: + for(dst = dstbuf+sz, src = buffer+srcx, j = 0; j < cy; j++) + for(i = 0; i < cx; i++, src += srccx - cx) + *--dst = *src++; + break; + case GDISP_ROTATE_270: + for(src = buffer+srcx, j = 0; j < cy; j++) { + dst = dstbuf+sz-cy+j; + for(i = 0; i < cx; i++, src += srccx - cx, dst -= cy) + *dst = *src++; + } + break; + } + return dstbuf; + } + /** * @brief Fill an area with a bitmap. * @note Optional - The high level driver can emulate using software. @@ -370,8 +558,12 @@ void GDISP_LLD(drawpixel)(coord_t x, coord_t y, color_t color) { void GDISP_LLD(blitareaex)(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t srcx, coord_t srcy, coord_t srccx, const pixel_t *buffer) { BITMAPV4HEADER bmpInfo; RECT rect; + #if GDISP_NEED_CONTROL + pixel_t *srcimg; + #endif #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP + // Clip pre orientation change if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; srcx += GDISP.clipx0 - x; x = GDISP.clipx0; } if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; srcy += GDISP.clipy0 - y; y = GDISP.clipy0; } if (srcx+cx > srccx) cx = srccx - srcx; @@ -380,13 +572,14 @@ void GDISP_LLD(drawpixel)(coord_t x, coord_t y, color_t color) { if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y; #endif + // Make everything relative to the start of the line + buffer += srccx*srcy; + srcy = 0; + memset(&bmpInfo, 0, sizeof(bmpInfo)); bmpInfo.bV4Size = sizeof(bmpInfo); - bmpInfo.bV4Width = srccx; - bmpInfo.bV4Height = -(srcy+cy); /* top-down image */ bmpInfo.bV4Planes = 1; bmpInfo.bV4BitCount = 32; - bmpInfo.bV4SizeImage = ((srcy+cy)*srccx * 32)/8; bmpInfo.bV4AlphaMask = 0; bmpInfo.bV4RedMask = RGB2COLOR(255,0,0); bmpInfo.bV4GreenMask = RGB2COLOR(0,255,0); @@ -398,14 +591,61 @@ void GDISP_LLD(drawpixel)(coord_t x, coord_t y, color_t color) { bmpInfo.bV4ClrImportant = 0; bmpInfo.bV4CSType = 0; //LCS_sRGB; - // Draw the bitmap - SetDIBitsToDevice(dcBuffer, x, y, cx, cy, srcx, srcy, 0, cy+srcy, buffer, (BITMAPINFO*)&bmpInfo, DIB_RGB_COLORS); + #if GDISP_NEED_CONTROL + bmpInfo.bV4SizeImage = (cy*cx) * sizeof(pixel_t); + srcimg = rotateimg(cx, cy, srcx, srccx, buffer); + if (!srcimg) return; + + switch(GDISP.Orientation) { + case GDISP_ROTATE_0: + bmpInfo.bV4Width = cx; + bmpInfo.bV4Height = -cy; /* top-down image */ + rect.top = y; + rect.bottom = rect.top+cy; + rect.left = x; + rect.right = rect.left+cx; + break; + case GDISP_ROTATE_90: + bmpInfo.bV4Width = cy; + bmpInfo.bV4Height = -cx; /* top-down image */ + rect.top = x; + rect.bottom = rect.top+cx; + rect.right = GDISP.Height - y; + rect.left = rect.right-cy; + break; + case GDISP_ROTATE_180: + bmpInfo.bV4Width = cx; + bmpInfo.bV4Height = -cy; /* top-down image */ + rect.bottom = GDISP.Height - y; + rect.top = rect.bottom-cy; + rect.right = GDISP.Width - x; + rect.left = rect.right-cx; + break; + case GDISP_ROTATE_270: + bmpInfo.bV4Width = cy; + bmpInfo.bV4Height = -cx; /* top-down image */ + rect.bottom = GDISP.Width - x; + rect.top = rect.bottom-cx; + rect.left = y; + rect.right = rect.left+cy; + break; + } + SetDIBitsToDevice(dcBuffer, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, 0, 0, 0, rect.bottom-rect.top, srcimg, (BITMAPINFO*)&bmpInfo, DIB_RGB_COLORS); + if (srcimg != (pixel_t *)buffer) + free(srcimg); + + #else + bmpInfo.bV4Width = srccx; + bmpInfo.bV4Height = -cy; /* top-down image */ + bmpInfo.bV4SizeImage = (cy*srccx) * sizeof(pixel_t); + rect.top = y; + rect.bottom = rect.top+cy; + rect.left = x; + rect.right = rect.left+cx; + SetDIBitsToDevice(dcBuffer, x, y, cx, cy, srcx, 0, 0, cy, buffer, (BITMAPINFO*)&bmpInfo, DIB_RGB_COLORS); + #endif // Invalidate the region to get it on the screen. - rect.bottom = y+cy; - rect.top = y; - rect.left = x; - rect.right = x+cx; InvalidateRect(winRootWindow, &rect, FALSE); UpdateWindow(winRootWindow); } @@ -426,9 +666,29 @@ void GDISP_LLD(drawpixel)(coord_t x, coord_t y, color_t color) { color_t color; #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP + // Clip pre orientation change if (x < 0 || x >= GDISP.Width || y < 0 || y >= GDISP.Height) return 0; #endif + #if GDISP_NEED_CONTROL + switch(GDISP.Orientation) { + case GDISP_ROTATE_90: + t = GDISP.Height - 1 - y; + y = x; + x = t; + break; + case GDISP_ROTATE_180: + x = GDISP.Width - 1 - x; + y = GDISP.Height - 1 - y; + break; + case GDISP_ROTATE_270: + t = GDISP.Width - 1 - x; + x = y; + y = t; + break; + } + #endif + color = GetPixel(dcBuffer, x, y); return BGR2COLOR(color); } @@ -453,40 +713,169 @@ void GDISP_LLD(drawpixel)(coord_t x, coord_t y, color_t color) { HBRUSH hbr; #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP + // Clip pre orientation change if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; x = GDISP.clipx0; } if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; y = GDISP.clipy0; } if (!lines || cx <= 0 || cy <= 0 || x >= GDISP.clipx1 || y >= GDISP.clipy1) return; if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x; if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y; #endif + + if (lines > cy) lines = cy; + else if (-lines > cy) lines = -cy; - rect.bottom = y+cy; - rect.top = y; - rect.left = x; - rect.right = x+cx; - if (cy > lines && cy > -lines) - ScrollDC(dcBuffer, 0, -lines, &rect, 0, 0, 0); bgcolor = COLOR2BGR(bgcolor); hbr = CreateSolidBrush(bgcolor); - if (hbr) { - if (lines > 0) { - if (lines > cy) lines = cy; - frect.bottom = y+cy; - frect.top = y+cy-lines; - } else { - if (-lines > cy) lines = -cy; - frect.top = y; - frect.bottom = y-lines; + + #if GDISP_NEED_CONTROL + switch(GDISP.Orientation) { + case GDISP_ROTATE_0: + rect.top = y; + rect.bottom = rect.top+cy; + rect.left = x; + rect.right = rect.left+cx; + lines = -lines; + goto vertical_scroll; + case GDISP_ROTATE_90: + rect.top = x; + rect.bottom = rect.top+cx; + rect.right = GDISP.Height - y; + rect.left = rect.right-cy; + goto horizontal_scroll; + case GDISP_ROTATE_180: + rect.bottom = GDISP.Height - y; + rect.top = rect.bottom-cy; + rect.right = GDISP.Width - x; + rect.left = rect.right-cx; + vertical_scroll: + if (cy >= lines && cy >= -lines) + ScrollDC(dcBuffer, 0, lines, &rect, 0, 0, 0); + frect.left = rect.left; + frect.right = rect.right; + if (lines > 0) { + frect.top = rect.top; + frect.bottom = frect.top+lines; + } else { + frect.bottom = rect.bottom; + frect.top = frect.bottom+lines; + } + break; + case GDISP_ROTATE_270: + rect.bottom = GDISP.Width - x; + rect.top = rect.bottom-cx; + rect.left = y; + rect.right = rect.left+cy; + lines = -lines; + horizontal_scroll: + if (cy >= lines && cy >= -lines) + ScrollDC(dcBuffer, lines, 0, &rect, 0, 0, 0); + frect.top = rect.top; + frect.bottom = rect.bottom; + if (lines > 0) { + frect.left = rect.left; + frect.right = frect.left+lines; + } else { + frect.right = rect.right; + frect.left = frect.right+lines; + } + break; } - frect.left = x; - frect.right = x+cx; + #else + rect.top = y; + rect.bottom = rect.top+cy; + rect.left = x; + rect.right = rect.left+cx; + lines = -lines; + if (cy >= lines && cy >= -lines) + ScrollDC(dcBuffer, 0, lines, &rect, 0, 0, 0); + frect.left = rect.left; + frect.right = rect.right; + if (lines > 0) { + frect.top = rect.top; + frect.bottom = frect.top+lines; + } else { + frect.bottom = rect.bottom; + frect.top = frect.bottom+lines; + } + #endif + + if (hbr) FillRect(dcBuffer, &frect, hbr); - } InvalidateRect(winRootWindow, &rect, FALSE); UpdateWindow(winRootWindow); } #endif +#if (GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL) || defined(__DOXYGEN__) + /** + * @brief Driver Control + * @detail Unsupported control codes are ignored. + * @note The value parameter should always be typecast to (void *). + * @note There are some predefined and some specific to the low level driver. + * @note GDISP_CONTROL_POWER - Takes a gdisp_powermode_t + * GDISP_CONTROL_ORIENTATION - Takes a gdisp_orientation_t + * GDISP_CONTROL_BACKLIGHT - Takes an int from 0 to 100. For a driver + * that only supports off/on anything other + * than zero is on. + * GDISP_CONTROL_CONTRAST - Takes an int from 0 to 100. + * GDISP_CONTROL_LLD - Low level driver control constants start at + * this value. + * + * @param[in] what What to do. + * @param[in] value The value to use (always cast to a void *). + * + * @notapi + */ + void GDISP_LLD(control)(unsigned what, void *value) { + RECT rect; + + switch(what) { + case GDISP_CONTROL_ORIENTATION: + if (GDISP.Orientation == (gdisp_orientation_t)value) + return; + GetClientRect(winRootWindow, &rect); + switch((gdisp_orientation_t)value) { + case GDISP_ROTATE_0: + /* Code here */ + GDISP.Width = rect.right-rect.left; + GDISP.Height = rect.bottom - rect.top; + break; + case GDISP_ROTATE_90: + /* Code here */ + GDISP.Height = rect.right-rect.left; + GDISP.Width = rect.bottom - rect.top; + break; + case GDISP_ROTATE_180: + /* Code here */ + GDISP.Width = rect.right-rect.left; + GDISP.Height = rect.bottom - rect.top; + break; + case GDISP_ROTATE_270: + /* Code here */ + GDISP.Height = rect.right-rect.left; + GDISP.Width = rect.bottom - rect.top; + break; + default: + return; + } + + #if GDISP_NEED_CLIP || GDISP_NEED_VALIDATION + GDISP.clipx0 = 0; + GDISP.clipy0 = 0; + GDISP.clipx1 = GDISP.Width; + GDISP.clipy1 = GDISP.Height; + #endif + GDISP.Orientation = (gdisp_orientation_t)value; + return; +/* + case GDISP_CONTROL_POWER: + case GDISP_CONTROL_BACKLIGHT: + case GDISP_CONTROL_CONTRAST: +*/ + } + } +#endif + #if GFX_USE_TOUCHSCREEN /*|| defined(__DOXYGEN__)*/ void ts_store_calibration_lld(struct cal_t *cal) { diff --git a/drivers/gdisp/Win32/gdisp_lld_config.h b/drivers/gdisp/Win32/gdisp_lld_config.h index 3fa485b1..bf018eea 100644 --- a/drivers/gdisp/Win32/gdisp_lld_config.h +++ b/drivers/gdisp/Win32/gdisp_lld_config.h @@ -43,6 +43,7 @@ #define GDISP_HARDWARE_BITFILLS TRUE #define GDISP_HARDWARE_SCROLL TRUE #define GDISP_HARDWARE_PIXELREAD TRUE +#define GDISP_HARDWARE_CONTROL TRUE #define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB888 diff --git a/include/gwin.h b/include/gwin.h index 6b33a5ff..b1c644a6 100644 --- a/include/gwin.h +++ b/include/gwin.h @@ -76,11 +76,11 @@ #endif #if GWIN_NEED_CONSOLE && !GDISP_NEED_TEXT - #define GDISP_NEED_TEXT TRUE + #error "GWIN: Text support (GDISP_NEED_TEXT) is required if GWIN_NEED_CONSOLE is defined." #endif #if GWIN_NEED_BUTTON && !GDISP_NEED_TEXT - #define GDISP_NEED_TEXT TRUE + #error "GWIN: Text support (GDISP_NEED_TEXT) is required if GWIN_NEED_BUTTON is defined." #endif #if GWIN_NEED_BUTTON diff --git a/releases.txt b/releases.txt index 60456877..83680ae1 100644 --- a/releases.txt +++ b/releases.txt @@ -13,6 +13,7 @@ FEATURE: Touchscreen support added to gdisp Win32 driver FIX: gdisp Win32 driver fixes DEPRECATE: console deprecated - replaced with gwin functionality FEATURE: ILI9320 GDISP driver +FEATURE: gdisp Win32 driver - full orientation support *** changes after 1.3 *** diff --git a/src/gwin.c b/src/gwin.c index dfc4b1e0..0b3078b4 100644 --- a/src/gwin.c +++ b/src/gwin.c @@ -36,6 +36,8 @@ #include +#define GWIN_USE_FILLED_CHARS FALSE + #define GWIN_FLG_DYNAMIC 0x0001 #define GWIN_FIRST_CONTROL_FLAG 0x0002 #define GBTN_FLG_ALLOCTXT (GWIN_FIRST_CONTROL_FLAG<<0) @@ -666,7 +668,11 @@ void gwinPutChar(GHandle gh, char c) { #endif } +#if GWIN_USE_FILLED_CHARS + gdispFillChar(gh->x + gcw->cx, gh->y + gcw->cy, c, gh->font, gh->color, gh->bgcolor); +#else gdispDrawChar(gh->x + gcw->cx, gh->y + gcw->cy, c, gh->font, gh->color); +#endif /* update cursor */ gcw->cx += width; From 9566e80854c00de3ac90eb026e8c3196a5e168ad Mon Sep 17 00:00:00 2001 From: Andrew Hannam Date: Mon, 12 Nov 2012 17:10:30 +1000 Subject: [PATCH 2/4] Remove RGB565CONVERT() Remove RGB565CONVERT() macro Update madlebrot demo to use hardware independant way of setting the color. --- demos/mandelbrot/main.c | 4 ++-- include/gdisp.h | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/demos/mandelbrot/main.c b/demos/mandelbrot/main.c index 0c8dc47d..1e35ce9c 100644 --- a/demos/mandelbrot/main.c +++ b/demos/mandelbrot/main.c @@ -42,8 +42,8 @@ void mandelbrot(float x1, float y1, float x2, float y2) { y = 2.0f*x*y + cy; x = xx - yy + cx; } - color = ((iter << 8) | (iter&0xFF)); - //color = RGB565CONVERT(iter*4, iter*13, iter*10); + //color = ((iter << 8) | (iter&0xFF)); + color = RGB2COLOR(iter<<7, iter<<4, iter); gdispDrawPixel(i, j, color); } } diff --git a/include/gdisp.h b/include/gdisp.h index db865284..9be97a12 100644 --- a/include/gdisp.h +++ b/include/gdisp.h @@ -293,7 +293,6 @@ void gdispDrawBox(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color); /* Now obsolete functions */ #define gdispBlitArea(x, y, cx, cy, buffer) gdispBlitAreaEx(x, y, cx, cy, 0, 0, cx, buffer) -#define RGB565CONVERT(r,g,b) RGB2COLOR(r,g,b) /* Macro definitions for common gets and sets */ #define gdispSetPowerMode(powerMode) gdispControl(GDISP_CONTROL_POWER, (void *)(unsigned)(powerMode)) From 1c5ca344e85f23b84ce7cfd4e4ea8630f9c44c82 Mon Sep 17 00:00:00 2001 From: Andrew Hannam Date: Mon, 12 Nov 2012 17:19:09 +1000 Subject: [PATCH 3/4] Mandlebrot - remove hardware specifics Mandlebrot - remove hardware specifics --- demos/mandelbrot/main.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/demos/mandelbrot/main.c b/demos/mandelbrot/main.c index 1e35ce9c..6ab19de1 100644 --- a/demos/mandelbrot/main.c +++ b/demos/mandelbrot/main.c @@ -23,18 +23,24 @@ #include "gdisp.h" void mandelbrot(float x1, float y1, float x2, float y2) { - unsigned int i,j; + unsigned int i,j, width, height; uint16_t iter; color_t color; + float fwidth, fheight; float sy = y2 - y1; float sx = x2 - x1; const int MAX = 512; - for(i = 0; i < 320; i++) { - for(j = 0; j < 240; j++) { - float cy = j * sy / 240.0f + y1; - float cx = i * sx / 320.0f + x1; + width = (unsigned int)gdispGetWidth(); + height = (unsigned int)gdispGetHeight(); + fwidth = width; + fheight = height; + + for(i = 0; i < width; i++) { + for(j = 0; j < height; j++) { + float cy = j * sy / fheight + y1; + float cx = i * sx / fwidth + x1; float x=0.0f, y=0.0f, xx=0.0f, yy=0.0f; for(iter=0; iter <= MAX && xx+yy<4.0f; iter++) { xx = x*x; From 67ae847970aee780fb28580bd17233df5f5bb3b2 Mon Sep 17 00:00:00 2001 From: Andrew Hannam Date: Mon, 12 Nov 2012 18:49:47 +1000 Subject: [PATCH 4/4] Win32 orientation & gwin console line clear fixes Fixes to Win32 orientation for scrolling Improve the way line clearing is handled in gwin consoles. --- drivers/gdisp/Win32/gdisp_lld.c | 56 ++++++++++-------- .../MCU/.touchscreen_lld_config.h.swp | Bin 12288 -> 0 bytes src/gwin.c | 17 +++--- 3 files changed, 40 insertions(+), 33 deletions(-) delete mode 100644 drivers/touchscreen/MCU/.touchscreen_lld_config.h.swp diff --git a/drivers/gdisp/Win32/gdisp_lld.c b/drivers/gdisp/Win32/gdisp_lld.c index 560a5f20..8aff8efc 100644 --- a/drivers/gdisp/Win32/gdisp_lld.c +++ b/drivers/gdisp/Win32/gdisp_lld.c @@ -709,7 +709,7 @@ void GDISP_LLD(drawpixel)(coord_t x, coord_t y, color_t color) { * @notapi */ void GDISP_LLD(verticalscroll)(coord_t x, coord_t y, coord_t cx, coord_t cy, int lines, color_t bgcolor) { - RECT rect, frect; + RECT rect, frect, srect; HBRUSH hbr; #if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP @@ -748,17 +748,19 @@ void GDISP_LLD(drawpixel)(coord_t x, coord_t y, color_t color) { rect.right = GDISP.Width - x; rect.left = rect.right-cx; vertical_scroll: - if (cy >= lines && cy >= -lines) - ScrollDC(dcBuffer, 0, lines, &rect, 0, 0, 0); - frect.left = rect.left; - frect.right = rect.right; + srect.left = frect.left = rect.left; + srect.right = frect.right = rect.right; if (lines > 0) { - frect.top = rect.top; - frect.bottom = frect.top+lines; + srect.top = frect.top = rect.top; + frect.bottom = rect.top+lines; + srect.bottom = rect.bottom-lines; } else { - frect.bottom = rect.bottom; - frect.top = frect.bottom+lines; + srect.bottom = frect.bottom = rect.bottom; + frect.top = rect.bottom+lines; + srect.top = rect.top-lines; } + if (cy >= lines && cy >= -lines) + ScrollDC(dcBuffer, 0, lines, &srect, 0, 0, 0); break; case GDISP_ROTATE_270: rect.bottom = GDISP.Width - x; @@ -767,17 +769,19 @@ void GDISP_LLD(drawpixel)(coord_t x, coord_t y, color_t color) { rect.right = rect.left+cy; lines = -lines; horizontal_scroll: - if (cy >= lines && cy >= -lines) - ScrollDC(dcBuffer, lines, 0, &rect, 0, 0, 0); - frect.top = rect.top; - frect.bottom = rect.bottom; + srect.top = frect.top = rect.top; + srect.bottom = frect.bottom = rect.bottom; if (lines > 0) { - frect.left = rect.left; - frect.right = frect.left+lines; + srect.left = frect.left = rect.left; + frect.right = rect.left+lines; + srect.right = rect.right-lines; } else { - frect.right = rect.right; - frect.left = frect.right+lines; + srect.right = frect.right = rect.right; + frect.left = rect.right+lines; + srect.left = rect.left-lines; } + if (cy >= lines && cy >= -lines) + ScrollDC(dcBuffer, lines, 0, &srect, 0, 0, 0); break; } #else @@ -786,17 +790,19 @@ void GDISP_LLD(drawpixel)(coord_t x, coord_t y, color_t color) { rect.left = x; rect.right = rect.left+cx; lines = -lines; - if (cy >= lines && cy >= -lines) - ScrollDC(dcBuffer, 0, lines, &rect, 0, 0, 0); - frect.left = rect.left; - frect.right = rect.right; + srect.left = frect.left = rect.left; + srect.right = frect.right = rect.right; if (lines > 0) { - frect.top = rect.top; - frect.bottom = frect.top+lines; + srect.top = frect.top = rect.top; + frect.bottom = rect.top+lines; + srect.bottom = rect.bottom-lines; } else { - frect.bottom = rect.bottom; - frect.top = frect.bottom+lines; + srect.bottom = frect.bottom = rect.bottom; + frect.top = rect.bottom+lines; + srect.top = rect.top-lines; } + if (cy >= lines && cy >= -lines) + ScrollDC(dcBuffer, 0, lines, &srect, 0, 0, 0); #endif if (hbr) diff --git a/drivers/touchscreen/MCU/.touchscreen_lld_config.h.swp b/drivers/touchscreen/MCU/.touchscreen_lld_config.h.swp deleted file mode 100644 index 595c456fd2b9057efb453648640ac2b272e3f26f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2&u<$=6vrnVpau#EIB|M391=Hp)8qhZ+N!Q&$1aX-`3G%ItM%@zciQ#NYG*c% zNeWl^7x*POap1<0e*umh5S%~)i9`PcB)+>&8V8bA6}=#4q;D+yy*KmTXWk~V@`kJL zHn!=l(mKO>iLqC$FFNVD*Vr3RGp4z#)9mv{tUh<^a?Bs$#n}7#hE|-&JJ?xS30E>r zT&^rP5JMrA#rL!|^7kw+5xYE5mX@g-C^z9evbHOO`S*4hdbTSgUyMq@Bab!?hJYc! z&a?HkORE`(#S5>~D=!ZW6GOldFa!(%L%UJL<4zz{G53;{#H5HJJ`0YktLFa!(%L*PG1!0{Mson!1~0m075d#ll`*S$^~o*V7q0U#-M~q_iIZ?rX`EG7qQ_qOeorpF zt9d^OpHAx}t9WogGrZoCZEv=3?`)wT?d3e^6z=n#$`*wm!RN%qoN!=Ss}g#DKmX}? zo|dCTrty3TOu2QK2<%1kJ#a)-r9(AUnvW@z6AJk*4{0_CT*^az5%R)gPX^!86+q zXN=X6=RrUDc;oSs&?pJk>FGuy}tBG-w~4aZC}0#4*v`E}y2!gN-DKkL7& zqceiBljtm=Ik2Uf8_lnq5>Lbp>G5dnL=ic69m43nPU*@WSgxm$OvX-__3O2NB>N^+ V(3goA1)7#B%e1z7X$`;8*k7DITF(Fg diff --git a/src/gwin.c b/src/gwin.c index 0b3078b4..344252f9 100644 --- a/src/gwin.c +++ b/src/gwin.c @@ -36,7 +36,8 @@ #include -#define GWIN_USE_FILLED_CHARS FALSE +#define GWIN_CONSOLE_USE_CLEAR_LINES TRUE +#define GWIN_CONSOLE_USE_FILLED_CHARS FALSE #define GWIN_FLG_DYNAMIC 0x0001 #define GWIN_FIRST_CONTROL_FLAG 0x0002 @@ -635,19 +636,14 @@ void gwinPutChar(GHandle gh, char c) { #endif if (c == '\n') { - /* clear the text at the end of the line */ - if (gcw->cx < gh->width) - gdispFillArea(gh->x + gcw->cx, gh->y + gcw->cy, gh->width - gcw->cx, gcw->fy, gh->bgcolor); gcw->cx = 0; gcw->cy += gcw->fy; + // We use lazy scrolling here and only scroll when the next char arrives } else if (c == '\r') { // gcw->cx = 0; } else { width = gdispGetCharWidth(c, gh->font) + gcw->fp; if (gcw->cx + width >= gh->width) { - /* clear the text at the end of the line */ - if (gcw->cy + gcw->fy <= gh->height) - gdispFillArea(gh->x + gcw->cx, gh->y + gcw->cy, gh->width - (gcw->cx + width), gcw->fy, gh->bgcolor); gcw->cx = 0; gcw->cy += gcw->fy; } @@ -668,7 +664,12 @@ void gwinPutChar(GHandle gh, char c) { #endif } -#if GWIN_USE_FILLED_CHARS +#if GWIN_CONSOLE_USE_CLEAR_LINES + /* clear to the end of the line */ + if (gcw->cx == 0) + gdispFillArea(gh->x, gh->y + gcw->cy, gh->width, gcw->fy, gh->bgcolor); +#endif +#if GWIN_CONSOLE_USE_FILLED_CHARS gdispFillChar(gh->x + gcw->cx, gh->y + gcw->cy, c, gh->font, gh->color, gh->bgcolor); #else gdispDrawChar(gh->x + gcw->cx, gh->y + gcw->cy, c, gh->font, gh->color);