void InfoBoxWindow::Paint(Canvas &canvas) { canvas.Clear(pressed ? look.pressed_background_color : (HasFocus() || dragging || force_draw_selector ? look.focused_background_color : look.background_color)); if (data.GetCustom() && content != NULL) { /* if there's no comment, the content object may paint that area, too */ const PixelRect &rc = data.comment.empty() ? value_and_comment_rect : value_rect; content->OnCustomPaint(canvas, rc); } canvas.SetBackgroundTransparent(); PaintTitle(canvas); PaintComment(canvas); PaintValue(canvas); if (border_kind != 0) { canvas.Select(look.border_pen); const UPixelScalar width = canvas.GetWidth(), height = canvas.GetHeight(); if (border_kind & BORDERTOP) { canvas.DrawExactLine(0, 0, width - 1, 0); } if (border_kind & BORDERRIGHT) { canvas.DrawExactLine(width - 1, 0, width - 1, height); } if (border_kind & BORDERBOTTOM) { canvas.DrawExactLine(0, height - 1, width - 1, height - 1); } if (border_kind & BORDERLEFT) { canvas.DrawExactLine(0, 0, 0, height - 1); } } }
/** * This function is called when the Radar needs repainting. * @param canvas The canvas to paint on */ void FlarmTrafficWindow::OnPaintBuffer(Canvas &canvas) { #ifdef ENABLE_OPENGL if (small) { const ScopeAlphaBlend alpha_blend; canvas.SelectBlackPen(); canvas.Select(Brush(look.background_color.WithAlpha(0xd0))); canvas.DrawCircle(radar_mid.x, radar_mid.y, radius); } else #endif canvas.Clear(look.background_color); Paint(canvas); }
/** * This function is called when the Radar needs repainting. * @param canvas The canvas to paint on */ void FlarmTrafficWindow::OnPaint(Canvas &canvas) { #ifdef ENABLE_OPENGL if (small) { const GLBlend blend(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); canvas.SelectBlackPen(); canvas.Select(Brush(look.background_color.WithAlpha(0xd0))); canvas.DrawCircle(radar_mid.x, radar_mid.y, radius); } else #endif canvas.Clear(look.background_color); Paint(canvas); }
void TopWindow::OnDestroy() { /* clear the screen before exiting XCSoar */ Canvas canvas = screen->Lock(); if (canvas.IsDefined()) { canvas.Clear(COLOR_BLACK); screen->Flip(); screen->Wait(); canvas.ClearWhite(); screen->Unlock(); screen->Flip(); } ContainerWindow::OnDestroy(); }
void WndFrame::OnPaint(Canvas &canvas) { if (HaveClipping()) canvas.Clear(look.background_brush); canvas.SetTextColor(caption_color); canvas.SetBackgroundTransparent(); canvas.Select(look.text_font); PixelRect rc = GetClientRect(); const int padding = Layout::GetTextPadding(); rc.Grow(-padding); text_renderer.Draw(canvas, rc, text.c_str()); }
int main(int argc, char** argv) { /* enable FreeType anti-aliasing, because we don't use dithering in this program */ FreeType::mono = false; ScreenGlobalInit screen_init; Font::Initialise(); Display::Rotate(DisplayOrientation_t::PORTRAIT); { TopCanvas screen; screen.Create(PixelSize(100, 100), true, false); Canvas canvas = screen.Lock(); if (canvas.IsDefined()) { /* all black first, to eliminate E-ink ghost images */ canvas.Clear(COLOR_BLACK); screen.Flip(); screen.Wait(); /* disable dithering, render with 16 shades of gray, to make the (static) display more pretty */ screen.SetEnableDither(false); /* draw the picture */ canvas.ClearWhite(); Draw(canvas); /* finish */ screen.Unlock(); screen.Flip(); screen.Wait(); } } /* now we can power off the Kobo; the picture remains on the screen */ if (DetectKoboModel() == KoboModel::GLOHD) //The GloHD needs -f to not clear screen execl("/sbin/poweroff", "poweroff", "-f", nullptr); else execl("/sbin/poweroff", "poweroff", nullptr); return 0; }
virtual result DrawButton(Canvas& canvas) { canvas.SetBackgroundColor(Color(0, 0, 0, 0)); canvas.Clear(); if (_state == BUTTON_STATE_NORMAL) { canvas.FillRoundRectangle(_pallete[BUTTON_COLOR_BG_NORMAL], Rectangle(0, 0 , _bounds.width, _bounds.height), Dimension(5, 5)); } else { canvas.FillRoundRectangle(_pallete[BUTTON_COLOR_BG_PRESSED], Rectangle(0, 0 , _bounds.width, _bounds.height), Dimension(5, 5)); } Font font; font.Construct(FONT_STYLE_PLAIN, 18); canvas.SetFont(font); if (_text != L"") { EnrichedText enriched; enriched.Construct(Dimension(_bounds.width, _bounds.height)); enriched.SetVerticalAlignment(TEXT_ALIGNMENT_MIDDLE); enriched.SetHorizontalAlignment(TEXT_ALIGNMENT_CENTER); TextElement element; element.Construct(_text); if (_state == BUTTON_STATE_NORMAL) { element.SetTextColor(_pallete[BUTTON_COLOR_FG_NORMAL]); } else { element.SetTextColor(_pallete[BUTTON_COLOR_FG_PRESSED]); } enriched.Add(element); canvas.DrawText(Point(0, 0), enriched); enriched.RemoveAll(false); } return E_SUCCESS; }
void WndCustomButton::OnPaint(Canvas &canvas) { #ifdef HAVE_CLIPPING /* background and selector */ canvas.Clear(look.background_brush); #endif PixelRect rc = GetClientRect(); // Draw focus rectangle if (HasFocus()) { canvas.DrawFilledRectangle(rc, look.focused.background_color); canvas.SetTextColor(IsEnabled() ? look.focused.text_color : look.button.disabled.color); } else { canvas.DrawFilledRectangle(rc, look.background_color); canvas.SetTextColor(IsEnabled() ? look.text_color : look.button.disabled.color); } // If button has text on it tstring caption = get_text(); if (caption.empty()) return; // If button is pressed, offset the text for 3D effect if (is_down()) OffsetRect(&rc, 1, 1); canvas.SelectNullPen(); canvas.SetBackgroundTransparent(); #ifndef USE_GDI canvas.formatted_text(&rc, caption.c_str(), GetTextStyle()); #else unsigned s = DT_CENTER | DT_NOCLIP | DT_WORDBREAK; canvas.Select(*(look.button.font)); canvas.formatted_text(&rc, caption.c_str(), s); #endif }
void KnobTextEntryWindow::OnPaint(Canvas &canvas) { const PixelRect rc = GetClientRect(); canvas.Clear(Color(0x40, 0x40, 0x00)); // Do the actual painting of the text const DialogLook &look = UIGlobals::GetDialogLook(); canvas.Select(look.text_font); PixelSize tsize = canvas.CalcTextSize(buffer); PixelSize tsizec = canvas.CalcTextSize(buffer, cursor); PixelSize tsizea = canvas.CalcTextSize(buffer, cursor + 1); BulkPixelPoint p[5]; p[0].x = 10; p[0].y = (rc.GetHeight() - tsize.cy - 5) / 2; p[2].x = p[0].x + tsizec.cx; p[2].y = p[0].y + tsize.cy + 5; p[3].x = p[0].x + tsizea.cx; p[3].y = p[0].y + tsize.cy + 5; p[1].x = p[2].x; p[1].y = p[2].y - 2; p[4].x = p[3].x; p[4].y = p[3].y - 2; canvas.SelectWhitePen(); canvas.DrawPolyline(p + 1, 4); canvas.SetBackgroundTransparent(); canvas.SetTextColor(COLOR_WHITE); canvas.DrawText(p[0].x, p[0].y, buffer); }
static void OnTextPaint(gcc_unused WndOwnerDrawFrame *Sender, Canvas &canvas) { const PixelRect rc = Sender->GetClientRect(); canvas.Clear(Color(0x40, 0x40, 0x00)); // Do the actual painting of the text const DialogLook &look = UIGlobals::GetDialogLook(); canvas.Select(*look.text_font); PixelSize tsize = canvas.CalcTextSize(edittext); PixelSize tsizec = canvas.CalcTextSize(edittext, cursor); PixelSize tsizea = canvas.CalcTextSize(edittext, cursor + 1); RasterPoint p[5]; p[0].x = 10; p[0].y = (rc.bottom - rc.top - tsize.cy - 5) / 2; p[2].x = p[0].x + tsizec.cx; p[2].y = p[0].y + tsize.cy + 5; p[3].x = p[0].x + tsizea.cx; p[3].y = p[0].y + tsize.cy + 5; p[1].x = p[2].x; p[1].y = p[2].y - 2; p[4].x = p[3].x; p[4].y = p[3].y - 2; canvas.SelectWhitePen(); canvas.DrawPolyline(p + 1, 4); canvas.SetBackgroundTransparent(); canvas.SetTextColor(COLOR_WHITE); canvas.DrawText(p[0].x, p[0].y, edittext); }
result CropForm::OnDraw(void) { Canvas *pCanvas = null; pCanvas = GetCanvasN(); if(!pCanvas) return GetLastResult(); if (__pBitmapOriginal) { pCanvas->Clear(); pCanvas->DrawBitmap(GetClientAreaBounds(), *__pBitmapOriginal); pCanvas->SetForegroundColor(Color::GetColor(COLOR_ID_BLACK)); pCanvas->SetLineWidth(5); pCanvas->SetLineStyle(LINE_STYLE_SOLID); if(__Croprectangle.width > 0) pCanvas->DrawRectangle(__Croprectangle); } delete pCanvas; return E_SUCCESS; }
void ProgressWindow::OnPaint(Canvas &canvas) { canvas.Clear(background_color); // Determine window size const unsigned window_width = canvas.GetWidth(); const unsigned window_height = canvas.GetHeight(); PixelRect logo_rect; logo_rect.left = 0; logo_rect.top = 0; logo_rect.right = window_width; logo_rect.bottom = window_height - progress_border_height; logo.draw(canvas, logo_rect); // Draw progress bar background canvas.Stretch(0, (window_height - progress_border_height), window_width, progress_border_height, bitmap_progress_border); ContainerWindow::OnPaint(canvas); }
void ChartControl::OnPaint(Canvas &canvas) { assert(glide_computer != NULL); const ComputerSettings &settings_computer = blackboard->GetComputerSettings(); const MapSettings &settings_map = blackboard->GetMapSettings(); const MoreData &basic = blackboard->Basic(); const DerivedInfo &calculated = blackboard->Calculated(); #ifdef ENABLE_OPENGL /* enable clipping */ GLCanvasScissor scissor(canvas); #endif canvas.Clear(COLOR_WHITE); canvas.SetTextColor(COLOR_BLACK); PixelRect rcgfx = GetClientRect(); // background is painted in the base-class switch (page) { case AnalysisPage::BAROGRAPH: RenderBarograph(canvas, rcgfx, chart_look, look->cross_section, glide_computer->GetFlightStats(), basic, calculated, protected_task_manager); break; case AnalysisPage::CLIMB: RenderClimbChart(canvas, rcgfx, chart_look, glide_computer->GetFlightStats(), settings_computer.polar.glide_polar_task); break; case AnalysisPage::THERMAL_BAND: { OrderedTaskSettings otb; if (protected_task_manager != NULL) { otb = protected_task_manager->GetOrderedTaskSettings(); } ThermalBandRenderer renderer(thermal_band_look, chart_look); renderer.DrawThermalBand(basic, calculated, settings_computer, canvas, rcgfx, settings_computer.task, false, &otb); } break; case AnalysisPage::WIND: RenderWindChart(canvas, rcgfx, chart_look, glide_computer->GetFlightStats(), basic, glide_computer->GetWindStore()); break; case AnalysisPage::POLAR: RenderGlidePolar(canvas, rcgfx, look->chart, calculated.climb_history, settings_computer, settings_computer.polar.glide_polar_task); break; case AnalysisPage::TEMPTRACE: RenderTemperatureChart(canvas, rcgfx, chart_look, glide_computer->GetCuSonde()); break; case AnalysisPage::TASK: if (protected_task_manager != NULL) { const TraceComputer *trace_computer = glide_computer != NULL ? &glide_computer->GetTraceComputer() : NULL; const FlightStatisticsRenderer fs(chart_look, look->map); fs.RenderTask(canvas, rcgfx, basic, settings_computer, settings_map, *protected_task_manager, trace_computer); } break; case AnalysisPage::OLC: if (glide_computer != NULL) { const FlightStatisticsRenderer fs(chart_look, look->map); fs.RenderOLC(canvas, rcgfx, basic, settings_computer, settings_map, calculated.contest_stats, glide_computer->GetTraceComputer(), glide_computer->GetRetrospective()); } break; case AnalysisPage::TASK_SPEED: if (protected_task_manager != NULL) { ProtectedTaskManager::Lease task(*protected_task_manager); RenderSpeed(canvas, rcgfx, chart_look, glide_computer->GetFlightStats(), basic, calculated, task); } break; default: // should never get here! break; } }
result CameraRecorderForm::__updateTimeSize( bool reset ) { result r = E_SUCCESS; int textXinWide = 520, textXinNarrow = 280, textYinWide = 410, textYinNarrow = 200, textWidth = 280, textHeight = 80; Canvas* pOverlayCanvas = GetOverlayCanvas(); long recSizeInByte = 0, recTimeInMsec = 0; int recSizeInKb = 0, maxRecSizeInKb = 0, recTimeInSec = 0, maxRecTimeInSec = 0; maxRecSizeInKb = __pCameraRecorder->GetMaxRecordingSize(); maxRecTimeInSec = __pCameraRecorder->GetMaxRecordingTime()/1000; if ( !reset ) { recSizeInByte = __pCameraRecorder->GetRecordingSize(); recTimeInMsec = __pCameraRecorder->GetRecordingTime(); } r = pOverlayCanvas->Clear(Rectangle(_SelectivePosition(textXinWide,textXinNarrow) ,_SelectivePosition(textYinWide,textYinNarrow) ,textWidth,textHeight)); if (IsFailed(r)) { AppLogException( " Canvas' Clear failed."); return r; } /* * Recording size */ if ( recSizeInByte >= 1024 ) recSizeInKb = recSizeInByte/1024; // byte to kilobyte else recSizeInKb = 0; r = pOverlayCanvas->DrawText( Point(_SelectivePosition(textXinWide,textXinNarrow) ,_SelectivePosition(textYinWide,textYinNarrow)), L" " + Integer(recSizeInKb).ToString() + L" / " + Integer(maxRecSizeInKb).ToString() + L" KBytes",25,Color::COLOR_BLACK); if (IsFailed(r)) { AppLogException( " DrawText, recording size failed."); return r; } /* * Recording time */ if ( recTimeInMsec >= 1000 ) recTimeInSec = recTimeInMsec/1000; // msec to sec else recTimeInSec = 0; r = pOverlayCanvas->DrawText( Point(_SelectivePosition(textXinWide,textXinNarrow) ,_SelectivePosition(textYinWide,textYinNarrow)+30), L" " + Integer(recTimeInSec).ToString() + L" / " + Integer(maxRecTimeInSec).ToString() + L" second",25,Color::COLOR_BLACK); if (IsFailed(r)) { AppLogException( " DrawText, recording time failed."); return r; } pOverlayCanvas->Show(Rectangle(_SelectivePosition(textXinWide,textXinNarrow) ,_SelectivePosition(textYinWide,textYinNarrow) ,textWidth,textHeight)); if (IsFailed(r)) { AppLogException( " Canvas' Show failed."); return r; } return r; }
void GridView::OnPaint(Canvas &canvas) { canvas.Clear(look.background_color); }
/** * Draw the final glide groundline (and shading) to the buffer * and copy the transparent buffer to the canvas * @param canvas The drawing canvas * @param rc The area to draw in * @param buffer The drawing buffer */ void MapWindow::DrawTerrainAbove(Canvas &canvas) { // Don't draw at all if // .. no GPS fix // .. not flying // .. feature disabled // .. feature inaccessible if (!Basic().location_available || !Calculated().flight.flying || GetComputerSettings().features.final_glide_terrain == FeaturesSettings::FinalGlideTerrain::OFF || route_planner == nullptr) return; // Create a visitor for the Reach code TriangleCompound visitor(render_projection); // Fill the TriangleCompound with all TriangleFans in range route_planner->AcceptInRange(render_projection.GetScreenBounds(), visitor); // Exit early if not fans found if (visitor.fans.empty()) return; // @todo: update this rendering // Don't draw shade if // .. shade feature disabled // .. pan mode activated if (GetComputerSettings().features.final_glide_terrain == FeaturesSettings::FinalGlideTerrain::SHADE && IsNearSelf()) { #ifdef ENABLE_OPENGL const ScopeVertexPointer vp(&visitor.fans.points[0]); const GLEnable stencil_test(GL_STENCIL_TEST); glClear(GL_STENCIL_BUFFER_BIT); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); glStencilFunc(GL_ALWAYS, 1, 1); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); COLOR_WHITE.Set(); visitor.fans.DrawFill(canvas); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glStencilFunc(GL_NOTEQUAL, 1, 1); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); const GLBlend blend(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); canvas.Clear(Color(255, 255, 255, 77)); #elif defined(USE_GDI) // Get a buffer for drawing a mask Canvas &buffer = buffer_canvas; // Set the pattern colors buffer.SetBackgroundOpaque(); buffer.SetBackgroundColor(COLOR_WHITE); buffer.SetTextColor(Color(0xd0, 0xd0, 0xd0)); // Paint the whole buffer canvas with a pattern brush (small dots) buffer.Clear(look.above_terrain_brush); // Select the TerrainLine pen buffer.SelectHollowBrush(); buffer.Select(look.reach_pen_thick); buffer.SetBackgroundColor(Color(0xf0, 0xf0, 0xf0)); // Draw the TerrainLine polygons visitor.fans.DrawOutline(buffer); // Select a white brush (will later be transparent) buffer.SelectNullPen(); buffer.SelectWhiteBrush(); // Draw the TerrainLine polygons to remove the // brush pattern from the polygon areas visitor.fans.DrawFill(buffer); // Copy everything non-white to the buffer canvas.CopyTransparentWhite(0, 0, render_projection.GetScreenWidth(), render_projection.GetScreenHeight(), buffer, 0, 0); /* skip the separate terrain line step below, because we have done it already */ return; #endif } if (visitor.fans.size() == 1) { /* only one fan: we can draw a simple polygon */ #ifdef ENABLE_OPENGL const ScopeVertexPointer vp(&visitor.fans.points[0]); look.reach_pen.Bind(); #else // Select the TerrainLine pen canvas.SelectHollowBrush(); canvas.Select(look.reach_pen); canvas.SetBackgroundOpaque(); canvas.SetBackgroundColor(COLOR_WHITE); // drop out extraneous line from origin #endif // Draw the TerrainLine polygon visitor.fans.DrawOutline(canvas); #ifdef ENABLE_OPENGL look.reach_pen.Unbind(); #endif } else { /* more than one fan (turning reach enabled): we have to use a stencil to draw the outline, because the fans may overlap */ #ifdef ENABLE_OPENGL const ScopeVertexPointer vp(&visitor.fans.points[0]); glEnable(GL_STENCIL_TEST); glClear(GL_STENCIL_BUFFER_BIT); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); glStencilFunc(GL_ALWAYS, 1, 1); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); COLOR_WHITE.Set(); visitor.fans.DrawFill(canvas); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glStencilFunc(GL_NOTEQUAL, 1, 1); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); look.reach_pen_thick.Bind(); visitor.fans.DrawOutline(canvas); look.reach_pen_thick.Unbind(); glDisable(GL_STENCIL_TEST); #elif defined(USE_GDI) || defined(USE_MEMORY_CANVAS) // Get a buffer for drawing a mask Canvas &buffer = buffer_canvas; // Paint the whole buffer canvas white ( = transparent) buffer.ClearWhite(); // Select the TerrainLine pen buffer.SelectHollowBrush(); buffer.Select(look.reach_pen_thick); buffer.SetBackgroundOpaque(); buffer.SetBackgroundColor(Color(0xf0, 0xf0, 0xf0)); // Draw the TerrainLine polygons visitor.fans.DrawOutline(buffer); // Select a white brush (will later be transparent) buffer.SelectNullPen(); buffer.SelectWhiteBrush(); // Draw the TerrainLine polygons again to remove // the lines connecting all the polygons // // This removes half of the TerrainLine line width !! visitor.fans.DrawFill(buffer); // Copy everything non-white to the buffer canvas.CopyTransparentWhite(0, 0, render_projection.GetScreenWidth(), render_projection.GetScreenHeight(), buffer, 0, 0); #endif } }
void DigitEntry::OnPaint(Canvas &canvas) { assert(cursor < length); const bool focused = HasCursorKeys() && HasFocus(); if (HaveClipping()) canvas.Clear(look.background_color); canvas.Select(look.text_font); canvas.SetBackgroundOpaque(); const unsigned text_height = look.text_font.GetHeight(); const int y = (top + bottom - text_height) / 2; PixelRect rc; rc.top = top; rc.bottom = bottom; TCHAR buffer[4]; for (unsigned i = 0; i < length; ++i) { const Column &c = columns[i]; rc.left = c.left; rc.right = c.right; if (focused && i == cursor) { canvas.SetTextColor(look.list.focused.text_color); canvas.SetBackgroundColor(look.list.focused.background_color); } else if (c.IsEditable()) { canvas.SetTextColor(look.list.text_color); canvas.SetBackgroundColor(look.list.background_color); } else { canvas.SetTextColor(look.list.text_color); canvas.SetBackgroundColor(look.background_color); } const TCHAR *text = buffer; buffer[1] = _T('\0'); switch (c.type) { case Column::Type::DIGIT: case Column::Type::DIGIT6: assert(c.value < 10); buffer[0] = _T('0') + c.value; break; case Column::Type::HOUR: assert(c.value < 24); _stprintf(buffer, _T("%02u"), c.value); break; case Column::Type::DIGIT36: assert(c.value < 36); _stprintf(buffer, _T("%02u"), c.value); break; case Column::Type::DIGIT19: assert(c.value < 19); _stprintf(buffer, _T("%02u"), c.value); break; case Column::Type::SIGN: buffer[0] = c.IsNegative() ? _T('-') : _T('+'); break; case Column::Type::DECIMAL_POINT: buffer[0] = _T('.'); break; case Column::Type::COLON: buffer[0] = _T(':'); break; case Column::Type::NORTH_SOUTH: buffer[0] = c.IsNegative() ? _T('S') : _T('N'); break; case Column::Type::EAST_WEST: buffer[0] = c.IsNegative() ? _T('W') : _T('E'); break; case Column::Type::DEGREES: text = _T("°"); break; case Column::Type::APOSTROPHE: text = _T("'"); break; case Column::Type::QUOTE: text = _T("\""); break; case Column::Type::UNIT: // TODO: render unit symbol? text = Units::unit_descriptors[c.value].name; break; } if (c.IsEditable() && !valid) buffer[0] = _T('\0'); const int x = (c.left + c.right - canvas.CalcTextWidth(text)) / 2; canvas.DrawOpaqueText(x, y, rc, text); } canvas.SetBackgroundTransparent(); canvas.SetTextColor(look.text_color); unsigned control_height = Layout::GetMaximumControlHeight(); PixelRect plus_rc(0, top - control_height, 0, top); PixelRect minus_rc(0, bottom, 0, bottom + control_height); for (unsigned i = 0; i < length; ++i) { const Column &c = columns[i]; if (!c.IsEditable()) continue; plus_rc.left = minus_rc.left = c.left; plus_rc.right = minus_rc.right = c.right; button_renderer.DrawButton(canvas, plus_rc, false, false); button_renderer.DrawButton(canvas, minus_rc, false, false); canvas.SelectNullPen(); canvas.Select(look.button.standard.foreground_brush); SymbolRenderer::DrawArrow(canvas, plus_rc, SymbolRenderer::UP); SymbolRenderer::DrawArrow(canvas, minus_rc, SymbolRenderer::DOWN); } }
void MainLoop() { unsigned int prev_time=0; unsigned int cur_time = clock(); unsigned int sleep_time = 1000/20; while(1) { canvas.Clear('-'); Draw(); Output_To_Buffer(); if(kbhit()) { char c = getch(); switch(c) { case 'W': case 'w': cam.walk(0.2, 0, 0); break; case 'S': case 's': cam.walk(-0.2, 0, 0); break; case 'A': case 'a': cam.walk(0, 0.2, 0); break; case 'D': case 'd': cam.walk(0, -0.1, 0); break; case '5': cam.turn_U(5); break; case '2': cam.turn_D(5); break; case '1': cam.turn_L(5); break; case '3': cam.turn_R(5); break; case 'p': system("pause"); break; } } prev_time = cur_time; cur_time = clock(); if(cur_time-prev_time < sleep_time) Sleep(sleep_time - (cur_time-prev_time)); system("cls"); Display(); } }
//------------------------------------------------------------------------------ int main(int argc, char *argv[]) { QApplication app(argc, argv); Canvas c; Pen(Pen::SOLID, 1, Color(0, 0, 0)); { c.Select(Brush(Color(128, 128, 0, Color::TRANSPARENT))); c.DrawKeyhole(200, 100, 50, 100, Angle::Degrees(-20), Angle::Degrees(20)); c.DrawKeyhole(400, 100, 50, 100, Angle::Degrees(70), Angle::Degrees(110)); c.DrawKeyhole(200, 300, 50, 100, Angle::Degrees(160), Angle::Degrees(200)); c.DrawKeyhole(400, 300, 50, 100, Angle::Degrees(-110), Angle::Degrees(-70)); c.show(); app.exec(); } { c.Clear(); c.DrawKeyhole(200, 100, 50, 100, Angle::Degrees(35), Angle::Degrees(55)); c.DrawKeyhole(400, 100, 50, 100, Angle::Degrees(125), Angle::Degrees(145)); c.DrawKeyhole(200, 300, 50, 100, Angle::Degrees(215), Angle::Degrees(235)); c.DrawKeyhole(400, 300, 50, 100, Angle::Degrees(305), Angle::Degrees(325)); c.show(); app.exec(); } { c.Clear(); c.DrawFilledRectangle(0, 0, 100, 100, Color(128, 128, 128, Color::TRANSPARENT)); c.DrawFilledRectangle(100, 100, 200, 200, Color(128, 0, 0, Color::TRANSPARENT)); c.DrawFilledRectangle(150, 150, 250, 250, Color(0, 128, 0, Color::TRANSPARENT)); c.DrawFilledRectangle(200, 200, 300, 300, Color(0, 0, 128, Color::TRANSPARENT)); c.DrawTransparentText(0, 0, "0"); c.DrawTransparentText(0, 100, "100"); c.DrawTransparentText(0, 200, "200"); c.DrawTransparentText(0, 300, "300"); c.DrawTransparentText(0, 400, "400"); c.DrawTransparentText(0, 500, "500"); c.DrawTransparentText(100, c.GetFontHeight(), "100"); c.DrawTransparentText(200, c.GetFontHeight(), "200"); c.DrawTransparentText(300, c.GetFontHeight(), "300"); c.DrawTransparentText(400, c.GetFontHeight(), "400"); c.DrawTransparentText(500, c.GetFontHeight(), "500"); c.show(); app.exec(); } { c.Clear(); c.DrawOutlineRectangle(100, 100, 200, 200, Color(255, 0, 0)); c.show(); app.exec(); } { c.Clear(); c.DrawRoundRectangle(100, 100, 200, 200, 10, 10); c.DrawRoundRectangle(200, 200, 300, 300, 100, 100); c.DrawRoundRectangle(300, 300, 400, 400, 50, 50); c.show(); app.exec(); } { c.Clear(); PixelRect rc; rc.left = 100; rc.top = 100; rc.right = 200; rc.bottom = 200; c.DrawRaisedEdge(rc); c.show(); app.exec(); } { c.Clear(); RasterPoint rp[4]; rp[0] = {100, 100}; rp[1] = {200, 200}; rp[2] = {200, 300}; rp[3] = {300, 400}; c.DrawPolyline(rp, 4); c.show(); app.exec(); } { c.Clear(); RasterPoint rp[6]; rp[0] = {100, 100}; rp[1] = {150, 50}; rp[2] = {200, 100}; rp[3] = {200, 200}; rp[4] = {150, 200}; rp[5] = {100, 100}; c.DrawPolygon(rp, 6); c.show(); app.exec(); } { c.Clear(); RasterPoint rp[4]; rp[0] = {100, 100}; rp[1] = {200, 50}; rp[2] = {200, 150}; rp[3] = {150, 200}; c.DrawTriangleFan(rp, 4); c.show(); app.exec(); } { c.Clear(); c.DrawHLine(100, 200, 100, Color(255, 0, 0)); c.DrawHLine(100, 200, 200, Color(0, 255, 0)); c.DrawHLine(100, 200, 300, Color(0, 0, 255)); c.show(); app.exec(); } { c.Clear(); c.DrawLine(100, 100, 200, 200); c.DrawCircle(250, 250, 50); c.DrawSegment(100, 250, 50, Angle::Degrees(10), Angle::Degrees(30), false); c.show(); app.exec(); } { c.Clear(); c.DrawAnnulus(100, 100, 50, 100, Angle::Degrees(10), Angle::Degrees(60)); c.DrawAnnulus(300, 100, 50, 100, Angle::Degrees(0), Angle::Degrees(360)); c.DrawAnnulus(100, 300, 50, 100, Angle::Degrees(0), Angle::Degrees(0)); c.show(); app.exec(); } { PixelSize rc = c.CalcTextSize("Hello"); std::cout << "Size of \"Hello\": " << rc.cx << ", " << rc.cy << std::endl; c.DrawClippedText(100, 100, rc.cx / 2, "Hello"); c.show(); app.exec(); } { std::cout << "Height of font: " << c.GetFontHeight() << std::endl; } { c.Clear(); c.DrawText(0, 50, "50"); c.Clear(); c.show(); return app.exec(); } }
int main() { int sizeX = 1980; int sizeY = 1080; ng::SDLBackend::SetupSDLWindow("SDL test", 100, 100, sizeX, sizeY); std::cout << "size of control: " << sizeof(Control) << "\n"; gui = Gui(sizeX, sizeY); ng::SDLBackend::SetSDLBackend(&gui); gui.SetDefaultFont("/usr/share/fonts/TTF/Ubuntu-B.ttf", 10); // ng::Fonts::PutFont("hehe1", new ng::TiledFont( ng::Images::GetImage("data/ow.png"), Size(19,27), 0x0000ffff, 13), 7 ); // gui.LoadXml("data/rect_test.xml"); gui.LoadXml("data/gui-test.xml"); // gui.LoadXml("data/basic.xml"); gui.SetTooltipDelay(0.5); gui.AddFunction("clear_canvas", [](Args& args) { Canvas *c = gui.Get<Canvas>("canvas2"); c->Clear(0); }); // gui.GetCursor().SetCursorImage("Hand.png", Point(-50,-37)); // ng::Image* curs_input = ng::Images::GetImage("Hand.png"); // gui.GetCursor().SetCursorImage( CursorType::textinput, curs_input, Point(-50,-38) ); // ng::Image* curs = new ng::TiledImage( ng::Images::GetImage( "data/AppStarting.png" ), Size(128,128) ); // curs->SetAnimated(true); // curs->SetAnimationSpeed(10); // gui.GetCursor().SetCursorImage( CursorType::pointer, curs, Point(-50,-38) ); // gui.HideOSCursor(); // gui.GetCursor().SetCursorImage( CursorType::textinput, "data/Hand.png", Point(-50,-38) ); // gui.GetCursor().SetCursorImage( CursorType::pointer, "data/Hand.png", Point(-50,-38) ); gui.SetTooltipDelay(1.0); // gui.GetCursor().SetCursorImage( curs, Point(0,0) ); gui.AddFunction("changetheme", [&](Args& a) { auto *c = (ComboBox*)a.control; gui.DisableAllStyles(); gui.EnableStyleGroup(c->GetText()); gui.ForEachControl([](Control* c) { c->ApplyStyle(); }); }); gui.EnableStyleGroup("awesome_looks"); gui.ForEachControl([](Control* c) { c->ApplyStyle(); }); // gui.GetCursor().SetSize(400,400); // curs->SetTile(13); gui.OnEvent("curs", "change", [&](Args& args) { int val = static_cast<ng::TrackBar*>(args.control)->GetValue(); gui.GetCursor().SetSize(val,val); }); gui.OnEvent("put_here", "drag", [](Args args) { cout << "drag evt\n"; }); gui.OnEvent("combo", "drag", [&](Args& args) { cout << "drag combo\n"; ng::Control* wgt = gui.GetSelectedControl(); cout << "drop on: " << wgt->GetId() << "\n"; if(wgt->GetId() == "put_here" || wgt->GetId() == "or_here") { args.control->Unattach(); wgt->AddControl(args.control); args.control->SetDraggable(false); } }); gui.OnEvent("term", "enter", [](Args& args) { Terminal* t = static_cast<Terminal*>(args.control); t->AppendLog(t->GetLastCommand()); }); // cv::VideoCapture vcap; // cv::VideoCapture vcap2; // cv::Mat image(cv::Size(640,480), CV_8UC3); // cv::Mat image2(cv::Size(640,480), CV_8UC3); // vcap.set(CV_CAP_PROP_MODE, CV_CAP_MODE_RGB); // vcap2.set(CV_CAP_PROP_MODE, CV_CAP_MODE_RGB); const std::string videoStreamAddress = "/dev/video0"; // const std::string videoStreamAddress2 = "udp://224.0.1.2:5004"; const std::string videoStreamAddress2 = "udp://192.168.1.100:5004"; // const std::string videoStreamAddress = "/home/nikola/Downloads/Ip Man (2008) - 1080p/Ip.Man.2008.1080p.BluRay.x264.VPPV.mp4"; // const std::string videoStreamAddress = "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov"; //open the video stream and make sure it's opened bool quit =false; // Canvas *canv2 = gui.Get<Canvas>("canvas2"); // Canvas *canv3 = gui.Get<Canvas>("canvas3"); // Canvas *canv4 = gui.Get<Canvas>("canvas4"); // auto &cnv2 = canv3->GetLayer(0); // auto &cnv3 = canv4->GetLayer(0); // cnv2.Resize(640,480); /* std::thread t([&]() { if(!vcap2.open(videoStreamAddress2)) { std::cout << "Error opening video stream or file" << std::endl; return -1; } while(!quit) { if(vcap2.read(image2)) { for(int y = 0; y < image2.rows; y++) { // const uint32_t* p = (uint32_t*)image2.ptr<uint32_t>(y); const uint8_t* p = (uint8_t*)image2.ptr<uint32_t>(y); for(int x = 0; x < image2.cols; x++) { // cnv.Pixel(ng::Point(x,y), Color(image.at<uint8_t>(y,x,0), image.at<uint8_t>(y,x,1), image.at<uint8_t>(y,x,2)).GetUint32()); cnv2.Pixel(ng::Point(x,y), Color(p[2+x*3], p[1+x*3], p[0+x*3]).GetUint32()); } } cnv2.Refresh(); } } }); t.detach(); */ /* std::thread t2([&]() { // cnv.Resize(641,481); if(!vcap.open(videoStreamAddress)) { std::cout << "Error opening video stream or file" << std::endl; return -1; } while(!quit) { auto &cnv = canv2->GetLayer(0); if(vcap.read(image)) { // std::cout << "cols: " << image.cols << ", " << image.rows << "\n"; for(int y = 0; y < image.rows; y++) { const uint8_t* p = (uint8_t*)image.ptr<uint32_t>(y); for(int x = 0; x < image.cols; x++) { // cnv.Pixel(ng::Point(x,y), Color(image.at<uint8_t>(y,x,0), image.at<uint8_t>(y,x,1), image.at<uint8_t>(y,x,2)).GetUint32()); cnv.Pixel(ng::Point(x,y), Color(p[2+x*3], 0, 0).GetUint32()); cnv2.Pixel(ng::Point(x,y), Color(0, p[1+x*3], 0).GetUint32()); cnv3.Pixel(ng::Point(x,y), Color(0, 0, p[0+x*3]).GetUint32()); } } cnv.Refresh(); cnv2.Refresh(); cnv3.Refresh(); } } }); t2.detach(); */ gui.OnRender([&]() { }); auto lbfps = gui.Get<ng::Label>("fps"); gui.OnFpsChange([&](uint32_t fps) { static int val = 0; lbfps->SetText("fps: " + std::to_string(fps)); // std::cout << "fps: " << fps << "\n"; gui.Get<ProgressBar>("progress")->SetValue(val++); }); ng::SDLBackend::SDLMainLoop(&gui); ng::SDLBackend::CloseBackend(); quit = true; // std::this_thread::sleep_for(std::chrono::milliseconds( usleep(1000); }