Exemple #1
0
static int			align_right(unsigned int i, int w, int p, t_format *f)
{
	char			*str;
	int				ret;

	ret = 0;
	str = (f->flags & 1) ? "0" : "";
	if (!(str = (i == 0 && p == 0) ? ft_strdup(str) : ft_itoa_un(i, 8, 'a')))
		return (-1);
	f->flags = (p >= 0 && f->flags & 2) ? f->flags ^ 2 : f->flags;
	p = (p < ft_strlen(str)) ? ft_strlen(str) : p;
	if (!(f->flags & 2) && !(f->flags & 1 && i))
		ret += filling(' ', w - p);
	else if (!(f->flags & 2))
		ret += filling(' ', w - p - 1);
	if (f->flags & 1 && i)
	{
		p--;
		ret += ft_putchar('0');
	}
	if (f->flags & 2 && !(f->flags & 1 && i))
		ret += filling('0', w - ft_strlen(str));
	else
		ret += fill(str, w, p, f);
	ret += ft_putstr(str);
	free(str);
	return (ret);
}
Exemple #2
0
	void updateVertex(QSGGeometry *geometry) {
		int size = 0;
		for (int i=0; i<rectCount; ++i) {
			auto attached = rects[i].attached;
			if (attached->filling() > 0 && (attached == pressed.attached || attached->isSelected() || attached->color().alpha()))
				size += 6;
		}
		geometry->allocate(size);
		if (size > 0) {
			auto v = geometry->vertexDataAsColoredPoint2D();
			QColor color;
			for (int i=0; i<rectCount; ++i) {
				const auto &item = rects[i]; const auto attached = item.attached;
				if (attached->filling() <= 0)
					continue;
				if (attached == pressed.attached)
					color = highlight;
				else if (attached->isSelected())
					color = selection;
				else if (!attached->color().alpha())
					continue;
				else
					color = attached->color();
				v = fillColoredPointAsTriangle(v, O::vertexRect(p, item), color);
			}
		}
	}
Exemple #3
0
static int			align_right(unsigned int i, int w, int p, t_format *f)
{
	int				ret;
	char			*str;

	ret = 0;
	if (!(str = (i == 0 && p == 0) ? ft_strdup("") : ft_itoa_un(i, 16, 'A')))
		return (-1);
	if (p >= 0 && f->flags & 2)
		f->flags ^= 2;
	p = (p < ft_strlen(str)) ? ft_strlen(str) : p;
	if (!(f->flags & 2) && !(f->flags & 1 && i))
		ret += filling(' ', w - p);
	else if (!(f->flags & 2))
		ret += filling(' ', w - p - 2);
	if (f->flags & 1 && i)
		ret += ft_putstr("0X");
	if (f->flags & 2 && !(f->flags & 1 && i))
		ret += filling('0', w - ft_strlen(str));
	else if (f->flags & 2)
		ret += filling('0', w - ft_strlen(str) - 2);
	else if (p > ft_strlen(str))
		ret += filling('0', p - ft_strlen(str));
	ret += ft_putstr(str);
	free(str);
	return (ret);
}
Exemple #4
0
static int			fill(char *str, int w, int p, t_format *f)
{
	int				ret;

	ret = 0;
	if (f->flags & 2)
		ret += filling('0', w - ft_strlen(str) - 1);
	else if (p > ft_strlen(str))
		ret += filling('0', p - ft_strlen(str));
	return (ret);
}
Exemple #5
0
static int			align_left(unsigned int i, int w, int p, t_format *format)
{
    char			*str;
    int				ret;

    ret = 0;
    if (!(str = (i == 0 && p == 0) ? ft_strdup("") : ft_itoa_un(i, 10, 'a')))
        return (-1);
    if (p >= 0 && format->flags & 2)
        format->flags ^= 2;
    p = (p < ft_strlen(str)) ? ft_strlen(str) : p;
    if (p > ft_strlen(str))
        ret += filling('0', p - ft_strlen(str));
    ret += ft_putstr(str);
    ret += filling(' ', w - p);
    free(str);
    return (ret);
}
Exemple #6
0
static int			align_left(unsigned long l, int w, int p, t_format *f)
{
	char			*str;
	int				ret;

	ret = 0;
	if (!(str = (l == 0 && p == 0) ? ft_strdup("") : ft_itoa_l(l, 16, 'a')))
		return (-1);
	if (p >= 0 && f->flags & 2)
		f->flags ^= 2;
	p = (p < ft_strlen(str)) ? ft_strlen(str) : p;
	ret += ft_putstr("0x");
	if (p > ft_strlen(str))
		ret += filling('0', p - ft_strlen(str));
	ret += ft_putstr(str);
	ret += filling(' ', w - p - 2);
	free(str);
	return (ret);
}
Exemple #7
0
void test1(int n_repit)
{
    launcher launch;
    int i;
    char *name = "name";
    for(i=0; i<n_repit; i++)
    {
	if(i % 100 == 0)
	    fprintf(stderr, "%d\n", i);
	launcher_init(&launch, name);
	filling(&launch, rand() % 100 + 10);
	launcher_delete(&launch);
    }
}
Exemple #8
0
extern void g01_enter_point (double x1, double y1, double z1, double f)
{
	int i, j;
	const double dx = 1.0;
	const double dy = 1.0;
	const double dz = 1.0;
	int size;
	double** arr;
	double** arrCoord;
	double** arrCoordVertice;
	int index = 1;
	size = sizeArr (x0, Y0, z0, x1, y1, z1, dx, dy, dz);
	arr = (double**)malloc(size*sizeof(double*));
	for (i = 0; i < size; ++i)
	{
		arr [i] = (double*)malloc(3*sizeof(double));
	}
	arr [0][0] = x0;
	arr [0][1] = Y0;
	arr [0][2] = z0;
	arr [size - 1][0] = x1;
	arr [size - 1][1] = y1;
	arr [size - 1][2] = z1;
	filling (arr, &index, dx, 'x', size);
	filling (arr, &index, dy, 'y', size);
	filling (arr, &index, dz, 'z', size);
	if (x0 != x1)
	{
		sort (arr, size, 'x');
	}
	else 
		if (Y0 != y1)
		{
			sort (arr, size, 'y');
		}
	int tmpSize = size;
	offset (arr, &size);
	arrCoord = (double**)malloc(size*sizeof(double*));
	for (i = 0; i < size; ++i)
	{
		arrCoord [i] = (double*)malloc(3*sizeof(double));
	}
	for (i = 0; i < size; ++i)
	{
		for (j = 0; j < 3; ++j)
		{
			arrCoord [i][j] = arr [i][j];
		}
	}
	coordVertice (arrCoord, size, dx, dy, dz);
	int tmpSizeCoord = size;
	offset (arrCoord, &size);
	arrCoordVertice = (double**)malloc(size*sizeof(double*));
	for (i = 0; i < size; ++i)
	{
		arrCoordVertice [i] = (double*)malloc(3*sizeof(double));
	}
	printf ("(%f, %f, %f) (%f, %f, %f)\n", x0, Y0, z0, x1, y1, z1);
	for (i = 0; i < tmpSize; ++i)
	{
		free (arr [i]);
	}
	free (arr);
	for (i = 0; i < tmpSizeCoord; ++i)
	{
		free (arrCoord [i]);
	}
	free (arrCoord);
	for (i = 0; i < size; ++i)
	{
		free (arrCoordVertice [i]);
	}
	free (arrCoordVertice);
	x0 = x1;
	Y0 = y1;
	z0 = z1;
}
Exemple #9
0
void g01_enter_point (double x1, double y1, double z1, double f) {
	int i, j;
	const double dx = 1.0;
	const double dy = 1.0;
	const double dz = 1.0;
	int size; /* Размер массива */
	double** arr;
	double** arrCoord; /* Массив точек*/
	double** arrCoordVertice; /* Массив координат вершин*/
	int index = 1;
	size = sizeArr (g_x0, g_y0, g_z0, x1, y1, z1, dx, dy, dz); /* Нахождение размера массива точек пересечения прямой с сеткой*/
	arr = (double**)malloc(size*sizeof(double*));
	for (i = 0; i < size; ++i) {
		arr [i] = (double*)malloc(3*sizeof(double));
	}
	arr [0][0] = g_x0;
	arr [0][1] = g_y0;
	arr [0][2] = g_z0;
	arr [size - 1][0] = x1;
	arr [size - 1][1] = y1;
	arr [size - 1][2] = z1;
 	/* Получение массива точек пересечения с сеткой*/
	filling (arr, &index, dx, 'x', size);
	filling (arr, &index, dy, 'y', size);
	filling (arr, &index, dz, 'z', size);
	if (g_x0 != x1) {
		sort (arr, size, 'x'); /* Сортировка массива точек по координате 'x'*/
	}
	else if (g_y0 != y1) {
		sort (arr, size, 'y'); /* Сортировка массива точек по координате 'y'*/
	}
	int tmpSize = size;
	offset (arr, &size); /* Удаление из массива одинаковых точек*/
	arrCoord = (double**)malloc(size*sizeof(double*));
	for (i = 0; i < size; ++i) {
		arrCoord [i] = (double*)malloc(3*sizeof(double));
	}
	for (i = 0; i < size; ++i) {
		for (j = 0; j < 3; ++j) {
			arrCoord [i][j] = arr [i][j];
		}
	}
	coordVertice (arrCoord, size, dx, dy, dz); /* Массив точек прямой по сетке*/
	int tmpSizeCoord = size;
	offset (arrCoord, &size); /* Удаление из массива одинаковых точек*/
	arrCoordVertice = (double**)malloc(size*sizeof(double*));
	for (i = 0; i < size; ++i) {
		arrCoordVertice [i] = (double*)malloc(3*sizeof(double));
	}
	/*printf ("\n");*/
	/*for (i = 0; i < size; ++i) {
		printf ("(%f, %f, %f)\n", arrCoord [i][0], arrCoord [i][1], arrCoord [i][2]);
	}*/
	for (i = 0; i < tmpSize; ++i) {
		free (arr [i]);
	}
	free (arr);
	for (i = 0; i < tmpSizeCoord; ++i) {
		free (arrCoord [i]);
	}
	free (arrCoord);
	for (i = 0; i < size; ++i) {
		free (arrCoordVertice [i]);
	}
	free (arrCoordVertice);
	g_x0 = x1;
	g_y0 = y1;
	g_z0 = z1;	
	/*handle result*/
	if (handler_gcommand_result)
		handler_gcommand_result (g_x0, g_y0, g_z0, f);
}
Exemple #10
0
void Block::replaceAtPos(int pos, const QString &text, const TextStyle &style, bool only_latin)
{
    m_changed = true;
    m_only_latin = m_only_latin && only_latin;

    if (pos >= m_text_line.size()) {
        if (pos > m_text_line.size()) {
            int old_size = m_text_line.size();
            QString filling(pos - m_text_line.size(), QChar(' '));
            m_text_line.append(filling);
            m_style_list.append(TextStyleLine(m_screen->defaultTextStyle(), old_size, old_size + filling.size() -1));
        }
        m_text_line.append(text);
        m_style_list.append(TextStyleLine(style, pos, pos + text.size()-1));
        return;
    } else if (pos + text.size() > m_text_line.size()) {
        m_style_list.append(TextStyleLine(m_screen->defaultTextStyle(), pos + text.size() - m_text_line.size(), pos + text.size() -1));
    }

    m_text_line.replace(pos,text.size(),text);
    bool found = false;
    for (int i = 0; i < m_style_list.size(); i++) {
        TextStyleLine &current_style = m_style_list[i];
        if (found) {
            if (current_style.end_index <= pos + text.size() - 1) {
                current_style.releaseTextSegment(m_screen);
                m_style_list.remove(i);
                i--;
            } else if (current_style.start_index <= pos + text.size()) {
                current_style.start_index = pos + text.size();
                current_style.style_dirty = true;
                current_style.text_dirty = true;
                current_style.index_dirty = true;
            } else {
                break;
            }
        } else if (pos >= current_style.start_index && pos <= current_style.end_index) {
            found = true;
            if (pos + text.size() -1 <= current_style.end_index) {
                if (current_style.isCompatible(style)) {
                    current_style.text_dirty = true;
                } else {
                    if (current_style.start_index == pos && current_style.end_index == pos + text.size() - 1) {
                        current_style.setStyle(style);
                        current_style.text_dirty = true;
                        current_style.style_dirty = true;
                    } else if (current_style.start_index == pos) {
                        current_style.start_index = pos + text.size();
                        current_style.text_dirty = true;
                        m_style_list.insert(i, TextStyleLine(style,pos, pos+text.size() -1));
                    } else if (current_style.end_index == pos + text.size() - 1) {
                        current_style.end_index = pos - 1;
                        current_style.text_dirty = true;
                        m_style_list.insert(i+1, TextStyleLine(style,pos, pos + text.size() - 1));
                    } else {
                        int old_end = current_style.end_index;
                        current_style.end_index = pos - 1;
                        current_style.text_dirty = true;
                        m_style_list.insert(i+1, TextStyleLine(style,pos, pos + text.size() - 1));
                        if (pos + text.size() < m_text_line.size()) {
                            m_style_list.insert(i+2, TextStyleLine(current_style,pos + text.size(), old_end));
                        }
                    }
                }
                break;
            } else {
                if (current_style.isCompatible(style)) {
                    current_style.end_index = pos + text.size() - 1;
                    current_style.text_dirty = true;
                } else {
                    if (current_style.start_index == pos) {
                        if (i > 0 && m_style_list.at(i-1).isCompatible(style)) {
                            TextStyleLine &previous_style = m_style_list[i -1];
                            previous_style.end_index+= text.size();
                            previous_style.text_dirty = true;
                            current_style.releaseTextSegment(m_screen);
                            m_style_list.remove(i);
                            i--;
                        } else {
                            current_style.end_index = pos + text.size() - 1;
                            current_style.style = style.style;
                            current_style.forground = style.forground;
                            current_style.background = style.background;
                            current_style.text_dirty = true;
                            current_style.style_dirty = true;
                            current_style.index_dirty = true;
                        }
                    } else {
                        current_style.end_index = pos - 1;
                        current_style.text_dirty = true;
                        m_style_list.insert(i+1, TextStyleLine(style, pos, pos + text.size() -1));
                        i++;
                    }
                }
            }
        }
    }
}