Size AbstractButton::GetPreferredSize () const { int w = 0; int h = 0; if (icon_) { w = icon_->size().width(); h = icon_->size().height(); } w += kIconTextSpace; Font font; // default font if (text_) { font = text_->font(); w += text_->size().width(); } h = std::max(h, font.height()); if (w == kIconTextSpace) { w = h; } w += pixel_size(kPadding.hsum()); h += pixel_size(kPadding.vsum()); return Size(w, h); }
void AbstractButton::DrawIconText (const float* text_color_v, short text_gamma, const float* icon_color_v, short icon_gamma) { Rect rect(pixel_size(kPadding.left()), pixel_size(kPadding.bottom()), size().width() - pixel_size(kPadding.hsum()), size().height() - pixel_size(kPadding.vsum())); if (icon_) { if (icon_->size().height() <= rect.height()) { if (icon_->size().width() <= rect.width()) { int align = AlignVerticalCenter; if (text_) { align |= AlignLeft; } else { align |= AlignHorizontalCenter; } icon_->DrawInRect(rect, align, icon_color_v, icon_gamma); rect.cut_left(icon_->size().width() + kIconTextSpace); } } } if (text_) { if (text_->size().height() <= rect.height()) { text_->DrawInRect(rect, AlignHorizontalCenter | AlignJustify | AlignBaseline, text_color_v, text_gamma); } } }
void DepthConvert2::process(void *, const ZimgImageBufferConst &src, const ZimgImageBuffer &dst, void *tmp, unsigned i, unsigned left, unsigned right) const { LineBuffer<const void> src_buf{ src }; LineBuffer<void> dst_buf{ dst }; const void *src_p = reinterpret_cast<const char *>(src_buf[i]) + left * pixel_size(m_pixel_in); void *dst_p = reinterpret_cast<char *>(dst_buf[i]) + left * pixel_size(m_pixel_out); if (!m_func && !m_f16c) { if (src_p != dst_p) std::copy_n(reinterpret_cast<const char *>(src_p), (right - left) * pixel_size(m_pixel_out), reinterpret_cast<char *>(dst_p)); } else { if (m_func) { if (m_f16c) dst_p = tmp; m_func(src_p, dst_p, m_scale, m_offset, right - left); src_p = dst_p; dst_p = reinterpret_cast<char *>(dst_buf[i]) + left * pixel_size(m_pixel_out); } if (m_f16c) m_f16c(src_p, dst_p, right - left); } }
void ToolButton::DrawAction () { if (!action_) return; Rect rect(pixel_size(kPadding.left()), pixel_size(kPadding.bottom()), size().width() - pixel_size(kPadding.hsum()), size().height() - pixel_size(kPadding.vsum())); if (action_->icon()) { if (action_->icon()->size().height() <= rect.height()) { if (action_->icon()->size().width() <= rect.width()) { int align = AlignCenter; // if (action_->text()) { // align |= AlignLeft; // } else { // align |= AlignHorizontalCenter; // } action_->icon()->DrawInRect(rect, align); rect.cut_left(action_->icon()->size().width() + kIconTextSpace); } } } // if (action_->text()) { // if (action_->text()->size().height() <= rect.height()) { // action_->text()->DrawInRect( // rect, AlignHorizontalCenter | AlignJustify | AlignBaseline); // } // } }
Slider::Slider (Orientation orientation) : AbstractSlider<int>(orientation), vao_(0), last_value_(0), pressed_(false) { slide_icon_.Resize(14, 14); if (orientation == Vertical) { set_size(18, 200); } else { set_size(200, 18); } glGenVertexArrays(1, &vao_); vbo_.generate(); glBindVertexArray(vao_); vbo_.bind(0); std::vector<GLfloat> line_verts(8, 0.f); if(orientation == Horizontal) { // line_verts[0] = 0.f; // line_verts[1] = 0.f; line_verts[2] = size().width(); // line_verts[3] = 0.f; //line_verts[4] = 0.f; line_verts[5] = pixel_size(1); line_verts[6] = size().width(); line_verts[7] = pixel_size(1); } else { // line_verts[0] = 0.f; // line_verts[1] = 0.f; line_verts[2] = pixel_size(1); // line_verts[3] = 0.f; // line_verts[4] = 0.f; line_verts[5] = size().height(); line_verts[6] = pixel_size(1); line_verts[7] = size().height(); } vbo_.set_data (sizeof(GLfloat) * line_verts.size(), &line_verts[0]); glEnableVertexAttribArray(AttributeCoord); glVertexAttribPointer(AttributeCoord, 2, GL_FLOAT, GL_FALSE, 0, 0); glBindVertexArray(0); vbo_.reset(); }
ZimgFilterFlags DepthConvert2::get_flags() const { ZimgFilterFlags flags{}; flags.same_row = true; flags.in_place = !(m_func && m_f16c) && (pixel_size(m_pixel_in) >= pixel_size(m_pixel_out)); return flags; }
Size FileButton::GetPreferredSize() const { int h = this->text()->font().height(); int w = h; w += pixel_size(kPadding.hsum()); h += pixel_size(kPadding.vsum()); return Size(w, h); }
Rect FTFont::GetSize(std::u32string const& txt) const { int const s = Font::Default()->GetSize(txt).width; if (s == -1) { Output::Warning("Text contains invalid chars. Is the encoding correct?"); return Rect(0, 0, pixel_size() * txt.length() / 2, pixel_size()); } else { return Rect(0, 0, s, pixel_size()); } }
Rect FTFont::GetSize(std::string const& txt) const { Utils::wstring tmp = Utils::ToWideString(txt); int const s = Font::Default()->GetSize(txt).width; if (s == -1) { Output::Warning("Text contains invalid chars.\n"\ "Is the encoding correct?"); return Rect(0, 0, pixel_size() * txt.size() / 2, pixel_size()); } else { return Rect(0, 0, s, pixel_size()); } }
RadioButton::RadioButton () : AbstractButton() { set_round_type(RoundAll); set_checkable(true); Font font; // default font int w = 80; int h = font.height(); set_size(w + pixel_size(kPadding.hsum()), h + pixel_size(kPadding.vsum())); InitializeRadioButtonOnce(); }
RadioButton::RadioButton (const RefPtr<AbstractIcon>& icon) : AbstractButton(icon) { set_round_type(RoundAll); set_checkable(true); int w = this->icon()->size().width(); int h = this->icon()->size().height(); w += pixel_size(kPadding.hsum()); h += pixel_size(kPadding.vsum()); set_size(w, h); InitializeRadioButtonOnce(); }
/* Performs a translation motion. * The current and target are compared; if a zoom would help move us from A to B, * we move the corners by up to @speed@ pixels. * Returns true if we did something, false if not. */ bool Movie::MotionTranslate(const Fractal::Point& centre_in, const Fractal::Point& centre_target, const Fractal::Point& size, const unsigned width, const unsigned height, const unsigned speed, Fractal::Point& centre_out) { centre_out = centre_in; // Easy case. Note BOTH must match. if ( real(centre_in) == real(centre_target) && imag(centre_in) == imag(centre_target) ) return false; // Like with zooming, if moving would take us beyond the target, we're close enough. struct signpair signs_before(calc_signs(centre_target, centre_in)); Fractal::Point tmp_out; unsigned speed_x = speed * width / 300; double speed_y = (double) speed_x * height / width; Fractal::Point pixel_size ( real(size) / width, imag(size) / height ); Fractal::Point delta ( real(pixel_size) * speed_x, imag(pixel_size) * speed_y ); if (signs_before.real < 0) delta.real(real(delta) * -1.0); if (signs_before.imag < 0) delta.imag(imag(delta) * -1.0); tmp_out = centre_in + delta; struct signpair signs_after(calc_signs(centre_target, tmp_out)); // Action on "close enough": set output dimension precisely from input; next time the Easy Case check will return false. if (signs_before.real != signs_after.real) tmp_out.real( real(centre_target) ); if (signs_before.imag != signs_after.imag) tmp_out.imag( imag(centre_target) ); centre_out = tmp_out; return true; }
/// Tries to guess the alignment of image rows based on image parameters. Kinda /// black magic and might not actually work. /// @param width in pixels of the image /// @param fmt of pixels in the image /// @param row_size the actual size in bytes of an image row, including padding static constexpr size_t guess_row_alignment(size_t width, pixel_format fmt, size_t row_size) { // Use the highest possible alignment for even-width images. if (width % 8 == 0) { return 8; } if (width % 4 == 0) { return 4; } if (width % 2 == 0) { return 2; } // The size of meaningful data in each row. size_t pix_bytes = width * pixel_size(fmt); // The size of padding. size_t padding = row_size - pix_bytes; if (padding == 0) { return 1; } if (padding <= 1) { return 2; } if (padding <= 3) { return 4; } if (padding <= 7) { return 8; } // Bail with a sane value. return 4; }
RadioButton::RadioButton (const String& text) : AbstractButton(text) { set_round_type(RoundAll); set_checkable(true); int w = this->text()->size().width(); int h = this->text()->font().height(); if(w < 80) w = 80; w += pixel_size(kPadding.hsum()); h += pixel_size(kPadding.vsum()); set_size(w, h); InitializeRadioButtonOnce(); }
bool KernelImageProcessor::initialize() { if (initialized_) { return initialized_; } StringElement element; shader_symbols_.clear(); element.text = lexical_cast<std::string>( kernel_->dataSize() ); shader_symbols_["kernel_array_size"] = element; element.text = "\n" + kernel_->toString() + "\n"; shader_symbols_["kernel_array"] = element; element.text = lexical_cast<std::string>( floor( float(kernel_->size()) / 2.0f )); shader_symbols_["kernel_half_size"] = element; element.text = (kernel_->dimensions() == 1) ? "" : "/*"; shader_symbols_["convolution_1d_begin"] = element; element.text = (kernel_->dimensions() == 1) ? "" : "*/"; shader_symbols_["convolution_1d_end"] = element; element.text = (kernel_->dimensions() == 2) ? "" : "/*"; shader_symbols_["convolution_2d_begin"] = element; element.text = (kernel_->dimensions() == 2) ? "" : "*/"; shader_symbols_["convolution_2d_end"] = element; if (ImageProcessor::initialize()) { if (quadrilateral_->states()->hasProgram() && (kernel_->dimensions() == 1)) { Vector2D pixel_size( *( (Vector2D*) quadrilateral_->states()->getProgram()->uniform("pixel_size").data() ) ); if (kernel_->orientation() == Kernel::Vertical) { pixel_size.x() = 0.0f; } if (kernel_->orientation() == Kernel::Horizontal) { pixel_size.y() = 0.0f; } quadrilateral_->states()->getProgram()->uniform("pixel_size").set(pixel_size); } } //CoreEngine::instance()->renderEngine().reportProgram( *quadrilateral_->states()->getProgram() ); return initialized_; }
void Resize::process2d(const ImagePlane<const void> &src, const ImagePlane<void> &dst, void *tmp) const { PixelType type = src.format().type; LinearAllocator alloc{ tmp }; ResizeContext ctx = get_context(alloc, type); LineBuffer<void> src_buf{ (void *)src.data(), 0, (unsigned)src.width(), (unsigned)src.stride() * pixel_size(type), UINT_MAX }; LineBuffer<void> dst_buf{ dst.data(), 0, (unsigned)dst.width(), (unsigned)dst.stride() * pixel_size(type), UINT_MAX }; bool overflow_flag = false; unsigned buffer_pos = 0; unsigned src_linesize = m_src_width * pixel_size(type); unsigned dst_linesize = m_dst_width * pixel_size(type); for (unsigned i = 0; i < m_dst_height; i += ctx.out_buffering2) { const LineBuffer<void> *in_buf = &src_buf; LineBuffer<void> *out_buf = &dst_buf; unsigned dep2_first = ctx.impl2->dependent_line(i); unsigned dep2_last = std::min(dep2_first + ctx.in_buffering2, ctx.tmp_height); for (; buffer_pos < dep2_last; buffer_pos += ctx.out_buffering1) { unsigned dep1_first = ctx.impl1->dependent_line(buffer_pos); unsigned dep1_last = dep1_first + ctx.in_buffering1; if (dep1_last > m_src_height) { if (!overflow_flag) { copy_buffer_lines(src_buf, ctx.src_border_buf, src_linesize, dep1_first, m_src_height); overflow_flag = true; } in_buf = &ctx.src_border_buf; } invoke_impl(ctx.impl1, type, *in_buf, ctx.tmp_buf, buffer_pos, ctx.tmp_data); } if (i + ctx.out_buffering2 > m_dst_height) out_buf = &ctx.dst_border_buf; invoke_impl(ctx.impl2, type, ctx.tmp_buf, *out_buf, i, ctx.tmp_data); if (i + ctx.out_buffering2 > m_dst_height) copy_buffer_lines(ctx.dst_border_buf, dst_buf, dst_linesize, i, m_dst_height); } }
FileButton::FileButton () : AbstractButton(String("...")), dialog_(0) { set_round_type(RoundAll); int h = this->text()->font().height(); int w = h; w += pixel_size(kPadding.hsum()); h += pixel_size(kPadding.vsum()); set_size(w, h); InitializeFileButtonOnce(); clicked().connect(this, &FileButton::OnClicked); }
DotIcon::DotIcon () : AbstractIcon() { int radius = pixel_size(3); set_size(radius * 2, radius * 2); std::vector<GLfloat> inner_verts; std::vector<GLfloat> outer_verts; GenerateVertices(-radius, -radius, radius, radius, pixel_size(1), RoundAll, radius, &inner_verts, &outer_verts); glGenVertexArrays(2, vao_); glBindVertexArray(vao_[0]); vbo_.generate(); vbo_.bind(0); vbo_.set_data(sizeof(GLfloat) * inner_verts.size(), &inner_verts[0]); glEnableVertexAttribArray( AbstractWindow::shaders()->location( Shaders::WIDGET_SIMPLE_TRIANGLE_COORD)); glVertexAttribPointer( AbstractWindow::shaders()->location( Shaders::WIDGET_SIMPLE_TRIANGLE_COORD), 3, GL_FLOAT, GL_FALSE, 0, 0); glBindVertexArray(vao_[1]); vbo_.bind(1); vbo_.set_data(sizeof(GLfloat) * outer_verts.size(), &outer_verts[0]); glEnableVertexAttribArray(AttributeCoord); glVertexAttribPointer(AttributeCoord, 2, GL_FLOAT, GL_FALSE, 0, 0); glBindVertexArray(0); vbo_.reset(); }
RadioButton::RadioButton (const RefPtr<AbstractIcon>& icon, const String& text) : AbstractButton(icon, text) { set_round_type(RoundAll); set_checkable(true); int w = this->icon()->size().width(); int h = this->icon()->size().height(); w += kIconTextSpace; w += this->text()->size().width(); h = std::max(h, this->text()->font().height()); if(w < 80) w = 80; w += pixel_size(kPadding.hsum()); h += pixel_size(kPadding.vsum()); set_size(w, h); InitializeRadioButtonOnce(); }
void Unresize::process(const ImagePlane<const void> &src, const ImagePlane<void> &dst, void *tmp) const { PixelType type = src.format().type; int pxsize = pixel_size(type); if (m_src_width == m_dst_width) { invoke_impl_v(src, dst, tmp); } else if (m_src_height == m_dst_height) { invoke_impl_h(src, dst, tmp); } else { double xscale = (double)m_dst_width / (double)m_src_width; double yscale = (double)m_dst_height / (double)m_src_height; // Downscaling cost is proportional to input size, whereas upscaling cost is proportional to output size. // Horizontal operation is roughly twice as costly as vertical operation for SIMD cores. double h_first_cost = std::max(xscale, 1.0) * 2.0 + xscale * std::max(yscale, 1.0); double v_first_cost = std::max(yscale, 1.0) + yscale * std::max(xscale, 1.0) * 2.0; char *tmp1 = (char *)tmp; char *tmp2 = tmp1 + max_frame_size(type) * pxsize; if (h_first_cost < v_first_cost) { int tmp_stride = align(m_dst_width, ALIGNMENT / pxsize); ImagePlane<void> tmp_plane{ tmp1, m_dst_width, m_src_height, tmp_stride, type }; invoke_impl_h(src, tmp_plane, tmp2); invoke_impl_v(tmp_plane, dst, tmp2); } else { int tmp_stride = align(m_src_width, ALIGNMENT / pxsize); ImagePlane<void> tmp_plane{ tmp1, m_src_width, m_dst_height, tmp_stride, type }; invoke_impl_v(src, tmp_plane, tmp2); invoke_impl_h(tmp_plane, dst, tmp2); } } }