void RiscosGui::setInvalidatedRegion(const rect& bounds) { // Note: Bounds coordinates are in TWIPS #ifdef RENDERER_AGG // forward to renderer _renderer->set_invalidated_region(bounds); if (bounds.width() > 1e10f) { // Region is entire screen. Don't convert to integer as this will // overflow. m_draw_minx = 0; m_draw_miny = 0; m_draw_maxx = _width - 1; m_draw_maxy = _height - 1; } else { // remember for renderBuffer() _renderer->world_to_pixel(&m_draw_minx, &m_draw_miny, bounds.get_x_min(), bounds.get_y_min()); _renderer->world_to_pixel(&m_draw_maxx, &m_draw_maxy, bounds.get_x_max(), bounds.get_y_max()); // add two pixels because of anti-aliasing... m_draw_minx = valid_coord(m_draw_minx - 2, _width); m_draw_miny = valid_coord(m_draw_miny - 2, _height); m_draw_maxx = valid_coord(m_draw_maxx + 2, _width); m_draw_maxy = valid_coord(m_draw_maxy + 2, _height); } // log_debug("DrawRect: (%i, %i), (%i, %i)\n", // m_draw_minx, m_draw_miny, m_draw_maxx, m_draw_maxy); #endif }
code_editor_dialog::code_editor_dialog(const rect& r) : dialog(r.x(), r.y(), r.w(), r.h()), invalidated_(0), has_error_(false), modified_(false), file_contents_set_(true), suggestions_prefix_(-1), have_close_buttons_(false) { init(); }
bool slider(int id, const rect & r, double min, double max, double step, double & value, bool disable_dragger = false) { bool changed = false; const int w = r.x1 - r.x0, h = r.y1 - r.y0; double p = (w - h) * (value - min) / (max - min); if (mouse_down && clicked_id == id) { p = std::max(0.0, std::min<double>(cursor.x - clicked_offset.x - r.x0, w - h)); double new_value = min + p * (max - min) / (w - h); if (step) new_value = std::round((new_value - min) / step) * step + min; changed = new_value != value; value = new_value; p = (w - h) * (value - min) / (max - min); } const rect dragger = { int(r.x0 + p), int(r.y0), int(r.x0 + p + h), int(r.y1) }; if (click && dragger.contains(cursor) && !disable_dragger) { clicked_offset = { cursor.x - dragger.x0, cursor.y - dragger.y0 }; clicked_id = id; } fill_rect(r, { 0.5, 0.5, 0.5 }); if (!disable_dragger) fill_rect(dragger, { 1, 1, 1 }); return changed; }
void CDX9Renderer::Box(const rect& r, const color& c) { // No support for textured lines SetTexture(NULL); BeginBatch(batch_linestrip); CBatch_Draw* draw_op = reinterpret_cast<CBatch_Draw*>(batch.back()); D3DCOLOR color = c.getD3DCOLOR(); // 4 vertices and use 5th index to repeat first vertex closing the strip as a box AddVertex(color, r.topleft(), 0.0f, 0.0f); AddVertex(color, r.topright(), 0.0f, 0.0f); AddVertex(color, r.bottomright(), 0.0f, 0.0f); AddVertex(color, r.bottomleft(), 0.0f, 0.0f); unsigned short index = draw_op->vertex_count; AddIndex(index); AddIndex(index + 1); AddIndex(index + 2); AddIndex(index + 3); AddIndex(index); draw_op->vertex_count += 4; draw_op->index_count += 5; }
message_dialog::message_dialog(const std::string& text, const rect& pos, const std::vector<std::string>* options) : text_(text), pos_(pos), line_height_(0), cur_row_(0), cur_char_(0), cur_wait_(0), selected_option_(0) { line_height_ = font::char_height(FontSize); viewable_lines_ = pos.h()/line_height_; if(viewable_lines_ < 1) { viewable_lines_ = 1; } const int max_chars_on_line = std::max<int>(1, pos.w()/font::char_width(FontSize)); std::string::const_iterator i1 = text.begin(); std::string::const_iterator i2 = i1; while(i2 != text.end()) { i2 = get_line(i2, text.end(), max_chars_on_line); if(i2 == i1) { break; } while(i1 != i2 && util::isspace(*i1)) { ++i1; } lines_.push_back(font::render_text(std::string(i1, i2), graphics::color_black(), FontSize)); i1 = i2; } if(options != NULL) { foreach(const std::string& option, *options) { options_.push_back(font::render_text(option, graphics::color_black(), FontSize)); } }
void OpenGL3RenderState::set_viewport(OpenGL3ContextState& state, const rect<int>& viewport) const { if (state.viewport == viewport) return; glViewport(viewport.ll().x(), viewport.ll().y(), viewport.width(), viewport.height()); state.viewport = viewport; }
int eval_overlap(rect r1, rect r2, branching_rule rule){ int dist_x = std::min(r1.xmax-r2.xmin, r2.xmax-r1.xmin); int dist_y = std::min(r1.ymax-r2.ymin, r2.ymax-r1.ymin); assert(dist_x > 0 and dist_y > 0); int height = r1.get_height() + r2.get_height(); int width = r1.get_width() + r2.get_width(); switch(rule){ case AREA: return rect::intersection(r1, r2).get_area(); case LMIN: return std::min(dist_x, dist_y); case LMAX: return std::max(dist_x, dist_y); case LAVG: return dist_x+dist_y; case WMIN: return std::min(height, width); case WMAX: return std::max(height, width); case WAVG: return height + width; default: abort(); } }
void ExtObject::Draw() { const point hotspot(info.HotSpotX, info.HotSpotY); const rect r = cr::rect_xywh(info.x, info.y, info.w, info.h); const rect r2 = cr::rect_xywh(info.x + 0.5f, info.y + 0.5f, info.w - 1.0f, info.h - 1.0f); const cr::color& c = info.pInfo->filter; quad q ((r2 - hotspot).rotate_to_quad(cr::to_radians(info.angle), r2.topleft())); if (!transparent) renderer->Fill(r, cr_colors.fill * c, info.angle, hotspot); // Draw if (smoothLines) { renderer->SmoothLine(q.tr, q.tl, cr_colors.c1 * c, 1.0); renderer->SmoothLine(q.tl, q.bl, cr_colors.c1 * c, 1.0); renderer->SmoothLine(q.bl, q.br, cr_colors.c2 * c, 1.0); renderer->SmoothLine(q.br, q.tr, cr_colors.c2 * c, 1.0); } else { renderer->Line(q.tr, q.tl, cr_colors.c1 * c); renderer->Line(q.tl, q.bl, cr_colors.c1 * c); renderer->Line(q.bl, q.br, cr_colors.c2 * c); renderer->Line(q.br, q.tr, cr_colors.c2 * c); } }
bool window::update_geometry( rect &r ) { SetWindowPos( _hwnd, NULL, r.x(), r.y(), r.width(), r.height(), SWP_NOOWNERZORDER | SWP_NOZORDER ); r = query_geometry(); return true; }
void context::reset_clip( const rect &r ) { glEnable( GL_SCISSOR_TEST ); glScissor( static_cast<GLint>( r.x() ), static_cast<GLint>( _last_vp[3] - ( r.y() + r.height() ) ), static_cast<GLsizei>( r.width() ), static_cast<GLsizei>( r.height() ) ); }
bool button(const rect & r, const std::string & label) { fill_rect(r, { 1, 1, 1 }); fill_rect(r.shrink(2), r.contains(cursor) ? (mouse_down ? color{ 0.3f, 0.3f, 0.3f } : color{ 0.4f, 0.4f, 0.4f }) : color{ 0.5f, 0.5f, 0.5f }); glColor3f(1, 1, 1); draw_text(r.x0 + 4, r.y1 - 8, label.c_str()); return click && r.contains(cursor); }
bool rect::Intersect( const rect& ref ) const { if( Left() > ref.Right() ) return false; if( Right() < ref.Left() ) return false; if( Top() > ref.Bottom() ) return false; if( Bottom() < ref.Top() ) return false; return true; }
inline void initialize(device_context* dc, rect pr) { dc_ = dc; rect_ = pr = pr.normalize(); poffset_ = -pr.left_top(); prect_ = pr; mask_ = nullptr; canvas_ = std::make_shared<canvas_type>(pr.width(), pr.height()); }
constexpr bool contains( rect< PositionType, SizeType > const& rect, point< DataType > const& point ){ return point.x() >= rect.left() && point.y() >= rect.top() && point.x() < rect.right() && point.y() < rect.bottom(); }
point entity::midpoint() const { if(solid()) { const rect r = solid_rect(); return point(r.x() + r.w()/2, r.y() + r.h()/2); } const frame& f = current_frame(); return point(x() + f.width()/2, y() + f.height()/2); }
void draw () { if (!inverted) w->invert_colors (); XFillRectangle (w->display, w->win, w->gc, box.ul.x, box.ul.y, box.width (), box.height ()); w->default_colors (); XDrawRectangle (w->display, w->win, w->gc, box.ul.x, box.ul.y, box.width (), box.height ()); }
void window::submit_delayed_expose( const rect &r ) { /// \todo { Need to fix the local vs screen coordinates } RECT rect = { LONG( std::floor( r.x1() ) ), LONG( std::floor( r.y1() ) ), LONG( std::ceil( r.x2() ) ), LONG( std::ceil( r.y2() ) ) }; if ( rect.left == rect.top && rect.left == rect.right && rect.left == rect.bottom ) RedrawWindow( _hwnd, NULL, NULL, RDW_INTERNALPAINT|RDW_UPDATENOW ); else RedrawWindow( _hwnd, &rect, NULL, RDW_INVALIDATE|RDW_UPDATENOW ); }
jitter::jitter(rect<float> &context, rect<float> &jit, int spatial_norm) : jitts(JITTERS) { h = jit.hcenter() - context.hcenter(); w = jit.wcenter() - context.wcenter(); r = 0; s = context.height / (float) jit.height; jitts.set(s, 0); jitts.set(h / (float) spatial_norm, 1); jitts.set(w / (float) spatial_norm, 2); jitts.set(r, 3); }
void dark_style::slider_button( const std::shared_ptr<draw::canvas> &c, const rect &r, bool pressed, coord val ) { construct( c ); coord rad = 9.0; //r.radius(); rect tmp( rad * 2, rad * 2 ); tmp.set_center( { r.x( val, rad ), r.y( 0.5, rad ) } ); _slider_button->set( c, tmp ); _slider_button->draw( *c ); }
bool checkbox(const rect & r, bool & value) { bool changed = false; if (click && r.contains(cursor)) { value = !value; changed = true; } fill_rect(r, { 1, 1, 1 }); fill_rect(r.shrink(1), { 0.5, 0.5, 0.5 }); if (value) fill_rect(r.shrink(3), { 1, 1, 1 }); return changed; }
bool rect::Intersects(const rect& r) { if (Intersects(r.x, r.y)) return true; if (Intersects(r.x + r.w-1, r.y + r.h-1)) return true; if (Intersects(r.x, r.y + r.h-1)) return true; if (Intersects(r.x + r.w-1, r.y)) return true; if (r.Intersects(x, y)) return true; if (r.Intersects(x + w-1, y + h-1)) return true; if (r.Intersects(x, y + h-1)) return true; if (r.Intersects(x + w-1, y)) return true; return false; }
rect intersection_rect(const rect& a, const rect& b) { const int x = std::max(a.x(), b.x()); const int y = std::max(a.y(), b.y()); const int w = std::max(0, std::min(a.x2(), b.x2()) - x); const int h = std::max(0, std::min(a.y2(), b.y2()) - y); return rect(x, y, w, h); }
inline pos2<T> clop(const pos2<T>& pos, const rect<T>& r, T resolution=1) { pos2<T> cloped(pos); if (cloped.x_ >= r.right()) cloped.x_ = r.right() - resolution; if (cloped.y_ >= r.bottom()) cloped.y_ = r.bottom() - resolution; if (cloped.x_ < r.left()) cloped.x_ = r.left(); if (cloped.y_ < r.top()) cloped.y_ = r.top(); return cloped; }
void CDX9Renderer::Box(const rect& r, cr_float angle, point hotspot, const color& c) { // No support for textured lines SetTexture(NULL); quad q((r - hotspot).rotate_to_quad(angle, r.topleft())); BeginBatch(batch_linestrip); CBatch_Draw* draw_op = reinterpret_cast<CBatch_Draw*>(batch.back()); D3DCOLOR color = c.getD3DCOLOR(); // 4 vertices and use 5th index to repeat first vertex closing the strip as a box AddVertex(color, q.tl, 0.0f, 0.0f); AddVertex(color, q.tr, 0.0f, 0.0f); AddVertex(color, q.br, 0.0f, 0.0f); AddVertex(color, q.bl, 0.0f, 0.0f); unsigned short index = draw_op->vertex_count; AddIndex(index); AddIndex(index + 1); AddIndex(index + 2); AddIndex(index + 3); AddIndex(index); draw_op->vertex_count += 4; draw_op->index_count += 5; }
void mouseup (point p) { if (box.contains (p)) { invert (); (*cb) (); } }
int draw::input(bool redraw) { //auto temp_hotkey = hot::key; auto temp_command = current_command; // Очистим данные current_command = 0; hot::key = 0; command_clear_render->execute(); // Если была команда, надо ее выполнить if(temp_command) { hot::key = temp_command; return hot::key; } if(hot::key) return hot::key; // Нарисуем функционал расширения после выполнения всех комманд. // Таким образм скриншот, если он делается по команде не будет иметь // Такие вещи как строка сообщения и подсказка. command_after_render->execute(); int id = InputUpdate; if(redraw) draw::sysredraw(); else id = draw::rawinput(); if(hot::mouse.x < 0 || hot::mouse.y < 0) sys_static_area.clear(); else sys_static_area = {0, 0, draw::getwidth(), draw::getheight()}; hot::cursor = CursorArrow; return id; }
void CDX9Renderer::Fill(const rect& r, cr_float angle, point hotspot, const color& c) { quad q((r - hotspot).rotate_to_quad(angle, r.topleft())); SetTexture(NULL); Quad(q, c, NULL); }
void CDX9Renderer::FillGradient(const rect& r, cr_float angle, point hotspot, const color& c1, const color& c2, gradient_direction dir) { quad q((r - hotspot).rotate_to_quad(angle, r.topleft())); SetTexture(NULL); color vs[4]; switch (dir) { case dir_up: SetVertices(vs, c2, c2, c1, c1); Quad(r, vs); break; case dir_down: SetVertices(vs, c1, c1, c2, c2); Quad(r, vs); break; case dir_left: SetVertices(vs, c2, c1, c2, c1); Quad(r, vs); break; case dir_right: SetVertices(vs, c1, c2, c1, c2); Quad(r, vs); break; } }
void CDX9Renderer::Quad(const rect& r, cr_float angle, point hotspot, const color& filter, const rect* _uv) { // Avoid math for unrotated rects if (angle == 0.0) Quad(r - hotspot, filter, _uv); else Quad((r - hotspot).rotate_to_quad(angle, r.topleft()), filter, _uv); }
void ui_container::arrange_layout(rect granted_rect) { ui_element::arrange_layout(granted_rect); for (ui_iterator it = begin(); it != end(); ++it) { auto child_rect = it->measure(granted_rect); if (it->get_height() == auto_height && it->get_valign() == vertical_alignment::bottom) { child_rect.position.y = granted_rect.get_bottom() - it->get_margin_bottom() - child_rect.size.height; } if (it->get_width() == auto_width && it->get_halign() == horizontal_alignment::right) { child_rect.position.x = granted_rect.get_right() - it->get_margin_right() - child_rect.size.width; } update_child_layout(*it, child_rect, it->visibility.is_visible); } }