void oledc_clear(int x0, int y0, int w, int h) { while(oledc_screenLock()); oledc_screenLockSet(); int x1 = x0 + w - 1; int y1 = y0 + h - 1; // check rotation, move pixel around if necessary switch (TFTROTATION) { case 1: gfx_swap(x0, y0); gfx_swap(x1, y1); x0 = TFTWIDTH - x0 - 1; x1 = TFTWIDTH - x1 - 1; gfx_swap(x0, x1); break; case 2: x0 = TFTWIDTH - x0 - 1; y0 = TFTHEIGHT - y0 - 1; x1 = TFTWIDTH - x1 - 1; y1 = TFTHEIGHT - y1 - 1; gfx_swap(x0, x1); gfx_swap(y0, y1); break; case 3: gfx_swap(x0, y0); gfx_swap(x1, y1); y0 = TFTHEIGHT - y0 - 1; y1 = TFTHEIGHT - y1 - 1; gfx_swap(y0, y1); break; } // Boundary check if ((y0 >= TFTHEIGHT) && (y1 >= TFTHEIGHT)) return; if ((x0 >= TFTWIDTH) && (x1 >= TFTWIDTH)) return; if (x0 >= TFTWIDTH) x0 = TFTWIDTH - 1; if (y0 >= TFTHEIGHT) y0 = TFTHEIGHT - 1; if (x1 >= TFTWIDTH) x1 = TFTWIDTH - 1; if (y1 >= TFTHEIGHT) y1 = TFTHEIGHT - 1; oledc_writeCommand(SSD1331_CMD_CLEAR, 0); oledc_writeCommand(x0, 0); oledc_writeCommand(y0, 0); oledc_writeCommand(x1, 0); oledc_writeCommand(y1, 0); int _tMark = CNT + (CLKFREQ / 2000); while(_tMark > CNT); // Wait for system clock target oledc_screenLockClr(); }
void oledc_scrollStart(char h, char v) { while(oledc_screenLock()); oledc_screenLockSet(); if(TFTSCROLLING) oledc_writeCommand(SSD1331_CMD_SCROLLSTOP, 0); // check rotation, move pixel around if necessary switch (TFTROTATION) { case 1: gfx_swap(v, h); break; case 2: v = -v; h = -h; break; case 3: gfx_swap(v, h); h = -h; break; } if(v < 0) v = _width + v; if(h < 0) h = _height + h; if(v > _width/2) v = _width/2; if(h > _height/2) h = _height/2; oledc_writeCommand(SSD1331_CMD_SCROLLSETUP, 0); oledc_writeCommand(h, 0); oledc_writeCommand(0, 0); oledc_writeCommand(_height, 0); oledc_writeCommand(v, 0); oledc_writeCommand(0, 0); // speed? int _tMark = CNT + (CLKFREQ / 10000); while(_tMark > CNT); // Wait for system clock target oledc_writeCommand(SSD1331_CMD_SCROLLSTART, 0); TFTSCROLLING = 1; oledc_screenLockClr(); }
void MENUS::render_loading(float percent) { static int64 last_load_render = 0; // make sure that we don't render for each little thing we load // because that will slow down loading if we have vsync if(time_get()-last_load_render < time_freq()/60) return; last_load_render = time_get(); // need up date this here to get correct vec3 rgb = hsl_to_rgb(vec3(config.ui_color_hue/255.0f, config.ui_color_sat/255.0f, config.ui_color_lht/255.0f)); gui_color = vec4(rgb.r, rgb.g, rgb.b, config.ui_color_alpha/255.0f); RECT screen = *ui_screen(); gfx_mapscreen(screen.x, screen.y, screen.w, screen.h); render_background(); float tw; float w = 700; float h = 200; float x = screen.w/2-w/2; float y = screen.h/2-h/2; gfx_blend_normal(); gfx_texture_set(-1); gfx_quads_begin(); gfx_setcolor(0,0,0,0.50f); draw_round_rect(x, y, w, h, 40.0f); gfx_quads_end(); const char *caption = localize("Loading"); tw = gfx_text_width(0, 48.0f, caption, -1); RECT r; r.x = x; r.y = y+20; r.w = w; r.h = h; ui_do_label(&r, caption, 48.0f, 0, -1); gfx_texture_set(-1); gfx_quads_begin(); gfx_setcolor(1,1,1,0.75f); draw_round_rect(x+40, y+h-75, (w-80)*percent, 25, 5.0f); gfx_quads_end(); gfx_swap(); }
void oledc_drawLinePrimative(int x0, int y0, int x1, int y1, unsigned int color) { // check rotation, move pixel around if necessary switch (TFTROTATION) { case 1: gfx_swap(x0, y0); gfx_swap(x1, y1); x0 = TFTWIDTH - x0 - 1; x1 = TFTWIDTH - x1 - 1; //gfx_swap(x0, x1); break; case 2: gfx_swap(x0, x1); gfx_swap(y0, y1); x0 = TFTWIDTH - x0 - 1; y0 = TFTHEIGHT - y0 - 1; x1 = TFTWIDTH - x1 - 1; y1 = TFTHEIGHT - y1 - 1; break; case 3: gfx_swap(x0, y0); gfx_swap(x1, y1); y0 = TFTHEIGHT - y0 - 1; y1 = TFTHEIGHT - y1 - 1; //gfx_swap(y0, y1); break; } // Cohen–Sutherland clipping algorithm clips a line from // P0 = (x0, y0) to P1 = (x1, y1) against a rectangle with // diagonal from (xmin, ymin) to (xmax, ymax). // compute outcodes for P0, P1, and whatever point lies outside the clip rectangle OutCode outcode0 = ComputeOutCode(x0, y0); OutCode outcode1 = ComputeOutCode(x1, y1); char accept = 0; while (1) { if (!(outcode0 | outcode1)) { // Bitwise OR is 0. Trivially accept and get out of loop accept = 1; break; } else if (outcode0 & outcode1) { // Bitwise AND is not 0. Trivially reject and get out of loop break; } else { // failed both tests, so calculate the line segment to clip // from an outside point to an intersection with clip edge int x, y; // At least one endpoint is outside the clip rectangle; pick it. OutCode outcodeOut = outcode0 ? outcode0 : outcode1; // Now find the intersection point; // use formulas y = y0 + slope * (x - x0), x = x0 + (1 / slope) * (y - y0) if (outcodeOut & TOP) { // point is above the clip rectangle x = x0 + (x1 - x0) * (0 - y0) / (y1 - y0); y = 0; } else if (outcodeOut & BOTTOM) { // point is below the clip rectangle x = x0 + (x1 - x0) * (TFTHEIGHT - y0 - 1) / (y1 - y0); y = TFTHEIGHT - 1; } else if (outcodeOut & RIGHT) { // point is to the right of clip rectangle y = y0 + (y1 - y0) * (TFTWIDTH - x0 - 1) / (x1 - x0); x = TFTWIDTH - 1; } else if (outcodeOut & LEFT) { // point is to the left of clip rectangle y = y0 + (y1 - y0) * (0 - x0) / (x1 - x0); x = 0; } // Now we move outside point to intersection point to clip // and get ready for next pass. if (outcodeOut == outcode0) { x0 = x; y0 = y; outcode0 = ComputeOutCode(x0, y0); } else { x1 = x; y1 = y; outcode1 = ComputeOutCode(x1, y1); } } } if (accept) { oledc_writeCommand(SSD1331_CMD_DRAWLINE, 0); oledc_writeCommand(x0, 0); oledc_writeCommand(y0, 0); oledc_writeCommand(x1, 0); oledc_writeCommand(y1, 0); oledc_writeCommand((color >> 11) << 1, 0); oledc_writeCommand((color >> 5) & 0x3F, 0); oledc_writeCommand((color << 1) & 0x3F, 0); int _tMark = CNT + (CLKFREQ / 100000); while (_tMark > CNT); // Wait for system clock target } }
void oledc_copy(int x0, int y0, int w, int h, int x2, int y2) { while(oledc_screenLock()); oledc_screenLockSet(); int x1 = x0 + w - 1; int y1 = y0 + h - 1; int x3 = x2 + w - 1; int y3 = y2 + h - 1; if (x0 >= _width || y0 >= _height || x1 < 0 || y1 < 0 || w <= 0 || h <= 0 || x2 >= _width || y2 >= _height || x3 < 0 || y3 < 0) { oledc_screenLockClr(); return; } if (x1 >= _width) { x1 = _width - 1; w = x1 - x0 + 1; } if (y1 >= _height) { y1 = _height - 1; h = y1 - y0 + 1; } if (x0 < 0) { x2 = x2 - x0; x0 = 0; } if (y0 < 0) { y2 = y2 - y0; y0 = 0; } x3 = x2 + w - 1; y3 = y2 + h - 1; if(x3 >= _width) { x3 = _width - 1; w = x3 - x2 + 1; x1 = x0 + w - 1; } if(y3 >= _height) { y3 = _height - 1; h = y3 - y2 + 1; y1 = y0 + h - 1; } // check rotation, move pixel around if necessary switch (TFTROTATION) { case 1: gfx_swap(x0, y0); gfx_swap(x1, y1); gfx_swap(x2, y2); gfx_swap(x3, y3); x0 = TFTWIDTH - x0 - 1; x1 = TFTWIDTH - x1 - 1; x2 = TFTWIDTH - x2 - 1; x3 = TFTWIDTH - x3 - 1; break; case 2: x0 = TFTWIDTH - x0 - 1; y0 = TFTHEIGHT - y0 - 1; x1 = TFTWIDTH - x1 - 1; y1 = TFTHEIGHT - y1 - 1; x2 = TFTWIDTH - x2 - 1; y2 = TFTHEIGHT - y2 - 1; x3 = TFTWIDTH - x3 - 1; y3 = TFTHEIGHT - y3 - 1; gfx_swap(x0, x1); gfx_swap(y0, y1); gfx_swap(x2, x3); gfx_swap(y2, y3); break; case 3: gfx_swap(x0, y0); gfx_swap(x1, y1); gfx_swap(x2, y2); gfx_swap(x3, y3); y0 = TFTHEIGHT - y0 - 1; y1 = TFTHEIGHT - y1 - 1; y2 = TFTHEIGHT - y2 - 1; y3 = TFTHEIGHT - y3 - 1; break; } oledc_writeCommand(SSD1331_CMD_COPY, 0); oledc_writeCommand(x0, 0); oledc_writeCommand(y0, 0); oledc_writeCommand(x1, 0); oledc_writeCommand(y1, 0); oledc_writeCommand(x2, 0); oledc_writeCommand(y2, 0); int _tMark = CNT + (CLKFREQ / 2000); while(_tMark > CNT); // Wait for system clock target oledc_screenLockClr(); }