Exemplo n.º 1
0
void Label::regenerate_word_cache() {
	
	while (word_cache) {
		
		WordCache *current=word_cache;
		word_cache=current->next;
		memdelete( current );
	}
	
	
	int width=autowrap?get_size().width:get_longest_line_width();
	Ref<Font> font = get_font("font");

	int current_word_size=0;
	int word_pos=0;
	int line_width=0;
	int space_count=0;
	int space_width=font->get_char_size(' ').width;
	line_count=1;
	total_char_cache=0;
	
	WordCache *last=NULL;
	
	for (int i=0;i<text.size()+1;i++) {
		
		CharType current=i<text.length()?text[i]:' '; //always a space at the end, so the algo works

		if (uppercase)
			current=String::char_uppercase(current);

		bool not_latin = current>=33 && (current < 65||current >90) && (current<97||current>122) && (current<48||current>57);
		bool insert_newline=false;
		int char_width;

		if (current<33) {

			if (current_word_size>0) {
				WordCache *wc = memnew( WordCache );
				if (word_cache) {
					last->next=wc;
				} else {
					word_cache=wc;
				}
				last=wc;

				wc->pixel_width=current_word_size;
				wc->char_pos=word_pos;
				wc->word_len=i-word_pos;
				wc->space_count = space_count;
				current_word_size=0;
				space_count=0;

			}


			if (current=='\n') {
				insert_newline=true;
			} else {
				total_char_cache++;
			}

			if (i<text.length() && text[i] == ' ') {
				total_char_cache--;  // do not count spaces
				if (line_width > 0 || last==NULL || last->char_pos!=WordCache::CHAR_WRAPLINE) {
					space_count++;
					line_width+=space_width;
				}else {
					space_count=0;
				}
			}


		} else {
			// latin characters
			if (current_word_size==0) {
				word_pos=i;
			}
			
			char_width=font->get_char_size(current).width;
			current_word_size+=char_width;
			line_width+=char_width;
			total_char_cache++;
			
		}

		if ((autowrap && (line_width >= width) && ((last && last->char_pos >= 0) || not_latin)) || insert_newline) {
			if (not_latin) {
				if (current_word_size>0) {
					WordCache *wc = memnew( WordCache );
					if (word_cache) {
						last->next=wc;
					} else {
						word_cache=wc;
					}
					last=wc;

					wc->pixel_width=current_word_size-char_width;
					wc->char_pos=word_pos;
					wc->word_len=i-word_pos;
					wc->space_count = space_count;
					current_word_size=char_width;
					space_count=0;
					word_pos=i;
				}
			}

			WordCache *wc = memnew( WordCache );
			if (word_cache) {
				last->next=wc;
			} else {
				word_cache=wc;
			}
			last=wc;

			wc->pixel_width=0;
			wc->char_pos=insert_newline?WordCache::CHAR_NEWLINE:WordCache::CHAR_WRAPLINE;

			line_width=current_word_size;
			line_count++;
			space_count=0;

		}
		
	}
	
	//total_char_cache -= line_count + 1; // do not count new lines (including the first one)
	
	if (!autowrap) {
		
		minsize.width=width;
		minsize.height=font->get_height()*line_count;
		set_page( line_count );
		
	} else {
	
		set_page( get_size().height / font->get_height() );
	}
	
	set_max(line_count);
	
	word_cache_dirty=false;

}
Exemplo n.º 2
0
std::pair<float,float> Text::get_size_ratio() {
    return window->get_ratio_from_pixels(get_size());
}
Exemplo n.º 3
0
	TITANIUM_PROPERTY_GETTER(Blob, size)	
	{
		return get_context().CreateNumber(get_size());
	}
 iterator iterator_all() const { return iterator(this, 0, get_size()); }
Exemplo n.º 5
0
void MavlinkFTP::send(const hrt_abstime t)
{

	if (_work_buffer1 || _work_buffer2) {
		// free the work buffers if they are not used for a while
		if (hrt_elapsed_time(&_last_work_buffer_access) > 2000000) {
			if (_work_buffer1) {
				delete[] _work_buffer1;
				_work_buffer1 = nullptr;
			}

			if (_work_buffer2) {
				delete[] _work_buffer2;
				_work_buffer2 = nullptr;
			}
		}
	}

	// Anything to stream?
	if (!_session_info.stream_download) {
		return;
	}

#ifndef MAVLINK_FTP_UNIT_TEST
	// Skip send if not enough room
	unsigned max_bytes_to_send = _mavlink->get_free_tx_buf();
#ifdef MAVLINK_FTP_DEBUG
	warnx("MavlinkFTP::send max_bytes_to_send(%d) get_free_tx_buf(%d)", max_bytes_to_send, _mavlink->get_free_tx_buf());
#endif

	if (max_bytes_to_send < get_size()) {
		return;
	}

#endif

	// Send stream packets until buffer is full

	bool more_data;

	do {
		more_data = false;

		ErrorCode error_code = kErrNone;

		mavlink_file_transfer_protocol_t ftp_msg;
		PayloadHeader *payload = reinterpret_cast<PayloadHeader *>(&ftp_msg.payload[0]);

		payload->seq_number = _session_info.stream_seq_number;
		payload->session = 0;
		payload->opcode = kRspAck;
		payload->req_opcode = kCmdBurstReadFile;
		payload->offset = _session_info.stream_offset;
		_session_info.stream_seq_number++;

#ifdef MAVLINK_FTP_DEBUG
		warnx("stream send: offset %d", _session_info.stream_offset);
#endif

		// We have to test seek past EOF ourselves, lseek will allow seek past EOF
		if (_session_info.stream_offset >= _session_info.file_size) {
			error_code = kErrEOF;
#ifdef MAVLINK_FTP_DEBUG
			warnx("stream download: sending Nak EOF");
#endif
		}

		if (error_code == kErrNone) {
			if (lseek(_session_info.fd, payload->offset, SEEK_SET) < 0) {
				error_code = kErrFailErrno;
#ifdef MAVLINK_FTP_DEBUG
				warnx("stream download: seek fail");
#endif
			}
		}

		if (error_code == kErrNone) {
			int bytes_read = ::read(_session_info.fd, &payload->data[0], kMaxDataLength);

			if (bytes_read < 0) {
				// Negative return indicates error other than eof
				error_code = kErrFailErrno;
#ifdef MAVLINK_FTP_DEBUG
				warnx("stream download: read fail");
#endif

			} else {
				payload->size = bytes_read;
				_session_info.stream_offset += bytes_read;
				_session_info.stream_chunk_transmitted += bytes_read;
			}
		}

		if (error_code != kErrNone) {
			payload->opcode = kRspNak;
			payload->size = 1;
			uint8_t *pData = &payload->data[0];
			*pData = error_code; // Straight reference to data[0] is causing bogus gcc array subscript error

			if (error_code == kErrFailErrno) {
				int r_errno = errno;
				payload->size = 2;
				payload->data[1] = r_errno;
			}

			_session_info.stream_download = false;

		} else {
#ifndef MAVLINK_FTP_UNIT_TEST

			if (max_bytes_to_send < (get_size() * 2)) {
				more_data = false;

				/* perform transfers in 35K chunks - this is determined empirical */
				if (_session_info.stream_chunk_transmitted > 35000) {
					payload->burst_complete = true;
					_session_info.stream_download = false;
					_session_info.stream_chunk_transmitted = 0;
				}

			} else {
#endif
				more_data = true;
				payload->burst_complete = false;
#ifndef MAVLINK_FTP_UNIT_TEST
				max_bytes_to_send -= get_size();
			}

#endif
		}

		ftp_msg.target_system = _session_info.stream_target_system_id;
		_reply(&ftp_msg);
	} while (more_data);
}
Exemplo n.º 6
0
void Tabs::_gui_input(const Ref<InputEvent> &p_event) {

	Ref<InputEventMouseMotion> mm = p_event;

	if (mm.is_valid()) {

		Point2 pos = mm->get_position();

		highlight_arrow = -1;
		if (buttons_visible) {

			Ref<Texture> incr = get_icon("increment");
			Ref<Texture> decr = get_icon("decrement");

			int limit = get_size().width - incr->get_width() - decr->get_width();

			if (pos.x > limit + decr->get_width()) {
				highlight_arrow = 1;
			} else if (pos.x > limit) {
				highlight_arrow = 0;
			}
		}

		// test hovering to display right or close button
		int hover_now = -1;
		int hover_buttons = -1;
		for (int i = 0; i < tabs.size(); i++) {

			if (i < offset)
				continue;

			Rect2 rect = get_tab_rect(i);
			if (rect.has_point(pos)) {
				hover_now = i;
			}
			if (tabs[i].rb_rect.has_point(pos)) {
				rb_hover = i;
				cb_hover = -1;
				hover_buttons = i;
				break;
			} else if (!tabs[i].disabled && tabs[i].cb_rect.has_point(pos)) {
				cb_hover = i;
				rb_hover = -1;
				hover_buttons = i;
				break;
			}
		}
		if (hover != hover_now) {
			hover = hover_now;
			emit_signal("tab_hover", hover);
		}

		if (hover_buttons == -1) { // no hover
			rb_hover = hover_buttons;
			cb_hover = hover_buttons;
		}
		update();

		return;
	}

	Ref<InputEventMouseButton> mb = p_event;

	if (mb.is_valid()) {

		if (mb->is_pressed() && mb->get_button_index() == BUTTON_WHEEL_UP && !mb->get_command()) {

			if (scrolling_enabled && buttons_visible) {
				if (offset > 0) {
					offset--;
					update();
				}
			}
		}

		if (mb->is_pressed() && mb->get_button_index() == BUTTON_WHEEL_DOWN && !mb->get_command()) {
			if (scrolling_enabled && buttons_visible) {
				if (missing_right) {
					offset++;
					update();
				}
			}
		}

		if (rb_pressing && !mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {

			if (rb_hover != -1) {
				//pressed
				emit_signal("right_button_pressed", rb_hover);
			}

			rb_pressing = false;
			update();
		}

		if (cb_pressing && !mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {

			if (cb_hover != -1) {
				//pressed
				emit_signal("tab_close", cb_hover);
			}

			cb_pressing = false;
			update();
		}

		if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {

			// clicks
			Point2 pos(mb->get_position().x, mb->get_position().y);

			if (buttons_visible) {

				Ref<Texture> incr = get_icon("increment");
				Ref<Texture> decr = get_icon("decrement");

				int limit = get_size().width - incr->get_width() - decr->get_width();

				if (pos.x > limit + decr->get_width()) {
					if (missing_right) {
						offset++;
						update();
					}
					return;
				} else if (pos.x > limit) {
					if (offset > 0) {
						offset--;
						update();
					}
					return;
				}
			}

			int found = -1;
			for (int i = 0; i < tabs.size(); i++) {

				if (i < offset)
					continue;

				if (tabs[i].rb_rect.has_point(pos)) {
					rb_pressing = true;
					update();
					return;
				}

				if (tabs[i].cb_rect.has_point(pos)) {
					cb_pressing = true;
					update();
					return;
				}

				if (pos.x >= tabs[i].ofs_cache && pos.x < tabs[i].ofs_cache + tabs[i].size_cache) {
					if (!tabs[i].disabled) {
						found = i;
					}
					break;
				}
			}

			if (found != -1) {

				set_current_tab(found);
				emit_signal("tab_clicked", found);
			}
		}
	}
}
Exemplo n.º 7
0
int ttext::get_width() const
{
	return get_size().x;
}
Exemplo n.º 8
0
/* opens `path' using given options and returns a fec_handle in `handle' if
   successful */
int fec_open(struct fec_handle **handle, const char *path, int mode, int flags,
        int roots)
{
    check(path);
    check(handle);
    check(roots > 0 && roots < FEC_RSM);

    debug("path = %s, mode = %d, flags = %d, roots = %d", path, mode, flags,
        roots);

    if (mode & (O_CREAT | O_TRUNC | O_EXCL | O_WRONLY)) {
        /* only reading and updating existing files is supported */
        error("failed to open '%s': (unsupported mode %d)", path, mode);
        errno = EACCES;
        return -1;
    }

    fec::handle f(new (std::nothrow) fec_handle, fec_close);

    if (unlikely(!f)) {
        error("failed to allocate file handle");
        errno = ENOMEM;
        return -1;
    }

    reset_handle(f.get());

    f->mode = mode;
    f->ecc.roots = roots;
    f->ecc.rsn = FEC_RSM - roots;
    f->flags = flags;

    if (unlikely(pthread_mutex_init(&f->mutex, NULL) != 0)) {
        error("failed to create a mutex: %s", strerror(errno));
        return -1;
    }

    f->fd = TEMP_FAILURE_RETRY(open(path, mode | O_CLOEXEC));

    if (f->fd == -1) {
        error("failed to open '%s': %s", path, strerror(errno));
        return -1;
    }

    if (get_size(f.get()) == -1) {
        error("failed to get size for '%s': %s", path, strerror(errno));
        return -1;
    }

    f->data_size = f->size; /* until ecc and/or verity are loaded */

    if (load_ecc(f.get()) == -1) {
        debug("error-correcting codes not found from '%s'", path);
    }

    if (load_verity(f.get()) == -1) {
        debug("verity metadata not found from '%s'", path);
    }

    *handle = f.release();
    return 0;
}
Exemplo n.º 9
0
void OutputStrings::_notification(int p_what) {

	switch (p_what) {

		case NOTIFICATION_DRAW: {

			if (following) {

				updating = true;
				v_scroll->set_value(v_scroll->get_max() - v_scroll->get_page());
				updating = false;
			}

			RID ci = get_canvas_item();
			Size2 size = get_size();

			Ref<Font> font = get_font("font", "Tree");
			Ref<StyleBox> tree_st = get_stylebox("bg", "Tree");
			tree_st->draw(ci, Rect2(Point2(), size));
			Color color = get_color("font_color", "Tree");
			Ref<Texture> icon_error = get_icon("Error", "EditorIcons");
			Ref<Texture> icon_warning = get_icon("Warning", "EditorIcons");

			//int lines = (size_height-(int)margin.y) / font_height;
			Point2 ofs = tree_st->get_offset();

			LineMap::Element *E = line_map.find(v_scroll->get_value());
			float h_ofs = (int)h_scroll->get_value();
			Point2 icon_ofs = Point2(0, (font_height - (int)icon_error->get_height()) / 2);

			FontDrawer drawer(font, Color(1, 1, 1));
			while (E && ofs.y < (size_height - (int)margin.y)) {

				String str = E->get().text;
				Point2 line_ofs = ofs;

				switch (E->get().type) {

					case LINE_WARNING: {
						icon_warning->draw(ci, line_ofs + icon_ofs);

					} break;
					case LINE_ERROR: {
						icon_error->draw(ci, line_ofs + icon_ofs);
					} break;
					case LINE_LINK: {

					} break;
					default: {
					}
				}

				line_ofs.y += font->get_ascent();
				line_ofs.x += icon_error->get_width() + 4;

				for (int i = 0; i < str.length(); i++) {
					if (line_ofs.x - h_ofs < 0) {
						line_ofs.x += font->get_char_size(str[i], str[i + 1]).width;
					} else if (line_ofs.x - h_ofs > size.width - margin.width) {
						break;
					} else {
						line_ofs.x += font->draw_char(ci, Point2(line_ofs.x - h_ofs, line_ofs.y), str[i], str[i + 1], color);
					}
				}

				ofs.y += font_height;
				E = E->next();
			}

		} break;

		case NOTIFICATION_ENTER_TREE:
		case NOTIFICATION_RESIZED: {

			font_height = get_font("font", "Tree")->get_height();
			size_height = get_size().height;
			update_scrollbars();
		} break;
	}
}
Exemplo n.º 10
0
osd_dim sdl_window_info::blit_surface_size()
{
	osd_dim window_dim = get_size();

	int newwidth, newheight;
	int xscale = 1, yscale = 1;
	float desired_aspect = 1.0f;
	INT32 target_width = window_dim.width();
	INT32 target_height = window_dim.height();

	// start with the minimum size
	m_target->compute_minimum_size(newwidth, newheight);

	// compute the appropriate visible area if we're trying to keepaspect
	if (video_config.keepaspect)
	{
		// make sure the monitor is up-to-date
		m_target->compute_visible_area(target_width, target_height, m_monitor->aspect(), m_target->orientation(), target_width, target_height);
		desired_aspect = (float)target_width / (float)target_height;
	}

	// non-integer scaling - often gives more pleasing results in full screen
	if (!video_config.fullstretch)
	{
		// compute maximum integral scaling to fit the window
		xscale = (target_width + 2) / newwidth;
		yscale = (target_height + 2) / newheight;

		// try a little harder to keep the aspect ratio if desired
		if (video_config.keepaspect)
		{
			// if we could stretch more in the X direction, and that makes a better fit, bump the xscale
			while (newwidth * (xscale + 1) <= window_dim.width() &&
				better_mode(newwidth * xscale, newheight * yscale, newwidth * (xscale + 1), newheight * yscale, desired_aspect))
				xscale++;

			// if we could stretch more in the Y direction, and that makes a better fit, bump the yscale
			while (newheight * (yscale + 1) <= window_dim.height() &&
				better_mode(newwidth * xscale, newheight * yscale, newwidth * xscale, newheight * (yscale + 1), desired_aspect))
				yscale++;

			// now that we've maxed out, see if backing off the maximally stretched one makes a better fit
			if (window_dim.width() - newwidth * xscale < window_dim.height() - newheight * yscale)
			{
				while (better_mode(newwidth * xscale, newheight * yscale, newwidth * (xscale - 1), newheight * yscale, desired_aspect) && (xscale >= 0))
					xscale--;
			}
			else
			{
				while (better_mode(newwidth * xscale, newheight * yscale, newwidth * xscale, newheight * (yscale - 1), desired_aspect) && (yscale >= 0))
					yscale--;
			}
		}

		// ensure at least a scale factor of 1
		if (xscale <= 0) xscale = 1;
		if (yscale <= 0) yscale = 1;

		// apply the final scale
		newwidth *= xscale;
		newheight *= yscale;
	}
	else
	{
		newwidth = target_width;
		newheight = target_height;
	}

	//FIXME: really necessary to distinguish for yuv_modes ?
	if (m_target->zoom_to_screen()
		&& (video_config.scale_mode == VIDEO_SCALE_MODE_NONE ))
		newwidth = window_dim.width();

	return osd_dim(newwidth, newheight);
}
Exemplo n.º 11
0
void LineEdit::_input_event(InputEvent p_event) {


    switch(p_event.type) {

    case InputEvent::MOUSE_BUTTON: {

        const InputEventMouseButton &b = p_event.mouse_button;

        if (b.pressed && b.button_index==BUTTON_RIGHT) {
            menu->set_pos(get_global_transform().xform(get_local_mouse_pos()));
            menu->set_size(Vector2(1,1));
            menu->popup();
            grab_focus();
            return;
        }

        if (b.button_index!=BUTTON_LEFT)
            break;

        _reset_caret_blink_timer();
        if (b.pressed) {

            shift_selection_check_pre(b.mod.shift);

            set_cursor_at_pixel_pos(b.x);

            if (b.mod.shift) {

                selection_fill_at_cursor();
                selection.creating=true;

            } else {

                if (b.doubleclick) {

                    selection.enabled=true;
                    selection.begin=0;
                    selection.end=text.length();
                    selection.doubleclick=true;
                }

                selection.drag_attempt=false;

                if ((cursor_pos<selection.begin) || (cursor_pos>selection.end) || !selection.enabled)  {

                    selection_clear();
                    selection.cursor_start=cursor_pos;
                    selection.creating=true;
                } else if (selection.enabled) {

                    selection.drag_attempt=true;
                }
            }

            //			if (!editable)
            //	non_editable_clicked_signal.call();
            update();

        } else {

            if ( (!selection.creating) && (!selection.doubleclick)) {
                selection_clear();
            }
            selection.creating=false;
            selection.doubleclick=false;

            if (OS::get_singleton()->has_virtual_keyboard())
                OS::get_singleton()->show_virtual_keyboard(text,get_global_rect());
        }

        update();
    }
    break;
    case InputEvent::MOUSE_MOTION: {

        const InputEventMouseMotion& m=p_event.mouse_motion;

        if (m.button_mask&BUTTON_LEFT) {

            if (selection.creating) {
                set_cursor_at_pixel_pos(m.x);
                selection_fill_at_cursor();
            }
        }

    }
    break;
    case InputEvent::KEY: {

        const InputEventKey &k =p_event.key;

        if (!k.pressed)
            return;
        unsigned int code  = k.scancode;


        if (k.mod.command) {

            bool handled=true;

            switch (code) {

            case (KEY_X): { // CUT

                if(editable) {
                    cut_text();
                }

            }
            break;

            case (KEY_C): { // COPY

                copy_text();

            }
            break;

            case (KEY_V): { // PASTE

                if(editable) {

                    paste_text();
                }

            }
            break;

            case (KEY_Z): { // Simple One level undo

                if(editable) {

                    undo();

                }


            }
            break;

            case (KEY_U): { // Delete from start to cursor

                if(editable) {

                    selection_clear();
                    undo_text = text;
                    text = text.substr(cursor_pos,text.length()-cursor_pos);

                    Ref<Font> font = get_font("font");

                    cached_width = 0;
                    if (font != NULL) {
                        for (int i = 0; i < text.length(); i++)
                            cached_width += font->get_char_size(text[i]).width;
                    }

                    set_cursor_pos(0);
                    _text_changed();

                }


            }
            break;

            case (KEY_Y): { // PASTE (Yank for unix users)

                if(editable) {

                    paste_text();
                }

            }
            break;
            case (KEY_K): { // Delete from cursor_pos to end

                if(editable) {

                    selection_clear();
                    undo_text = text;
                    text = text.substr(0,cursor_pos);
                    _text_changed();
                }

            }
            break;
            case (KEY_A): { //Select All
                select();
            }
            break;
            default: {
                handled=false;
            }
            }

            if (handled) {
                accept_event();
                return;
            }
        }

        _reset_caret_blink_timer();
        if (!k.mod.meta) {

            bool handled=true;
            switch (code) {

            case KEY_ENTER:
            case KEY_RETURN: {

                emit_signal( "text_entered",text );
                if (OS::get_singleton()->has_virtual_keyboard())
                    OS::get_singleton()->hide_virtual_keyboard();

                return;
            }
            break;

            case KEY_BACKSPACE: {

                if (!editable)
                    break;

                if (selection.enabled) {
                    undo_text=text;
                    selection_delete();
                    break;
                }

#ifdef APPLE_STYLE_KEYS
                if (k.mod.alt) {
#else
                if (k.mod.alt) {
                    handled=false;
                    break;
                } else if (k.mod.command) {
#endif
                    int cc=cursor_pos;
                    bool prev_char=false;

                    while (cc>0) {
                        bool ischar=_is_text_char(text[cc-1]);

                        if (prev_char && !ischar)
                            break;

                        prev_char=ischar;
                        cc--;
                    }

                    delete_text(cc, cursor_pos);

                    set_cursor_pos(cc);

                } else {
                    undo_text=text;
                    delete_char();
                }

            }
            break;
            case KEY_KP_4: {
                if (k.unicode != 0) {
                    handled = false;
                    break;
                }
                // numlock disabled. fallthrough to key_left
            }
            case KEY_LEFT: {

#ifndef APPLE_STYLE_KEYS
                if (!k.mod.alt)
#endif
                    shift_selection_check_pre(k.mod.shift);

#ifdef APPLE_STYLE_KEYS
                if (k.mod.command) {
                    set_cursor_pos(0);
                } else if (k.mod.alt) {

#else
                if (k.mod.alt) {
                    handled=false;
                    break;
                } else if (k.mod.command) {
#endif
                    bool prev_char=false;
                    int cc=cursor_pos;

                    while (cc>0) {
                        bool ischar=_is_text_char(text[cc-1]);

                        if (prev_char && !ischar)
                            break;

                        prev_char=ischar;
                        cc--;
                    }

                    set_cursor_pos(cc);

                } else {
                    set_cursor_pos(get_cursor_pos()-1);
                }

                shift_selection_check_post(k.mod.shift);

            }
            break;
            case KEY_KP_6: {
                if (k.unicode != 0) {
                    handled = false;
                    break;
                }
                // numlock disabled. fallthrough to key_right
            }
            case KEY_RIGHT: {

                shift_selection_check_pre(k.mod.shift);

#ifdef APPLE_STYLE_KEYS
                if (k.mod.command) {
                    set_cursor_pos(text.length());
                } else if (k.mod.alt) {
#else
                if (k.mod.alt) {
                    handled=false;
                    break;
                } else if (k.mod.command) {
#endif
                    bool prev_char=false;
                    int cc=cursor_pos;

                    while (cc<text.length()) {
                        bool ischar=_is_text_char(text[cc]);

                        if (prev_char && !ischar)
                            break;

                        prev_char=ischar;
                        cc++;
                    }

                    set_cursor_pos(cc);

                } else {
                    set_cursor_pos(get_cursor_pos()+1);
                }

                shift_selection_check_post(k.mod.shift);

            }
            break;
            case KEY_DELETE: {

                if (!editable)
                    break;

                if (k.mod.shift && !k.mod.command && !k.mod.alt) {
                    cut_text();
                    break;
                }

                if (selection.enabled) {
                    undo_text=text;
                    selection_delete();
                    break;
                }

                int text_len = text.length();

                if (cursor_pos==text_len)
                    break; // nothing to do

#ifdef APPLE_STYLE_KEYS
                if (k.mod.alt) {
#else
                if (k.mod.alt) {
                    handled=false;
                    break;
                } else if (k.mod.command) {
#endif
                    int cc=cursor_pos;

                    bool prev_char=false;

                    while (cc<text.length()) {

                        bool ischar=_is_text_char(text[cc]);

                        if (prev_char && !ischar)
                            break;
                        prev_char=ischar;
                        cc++;
                    }

                    delete_text(cursor_pos,cc);

                } else {
                    undo_text=text;
                    set_cursor_pos(cursor_pos+1);
                    delete_char();
                }

            }
            break;
            case KEY_KP_7: {
                if (k.unicode != 0) {
                    handled = false;
                    break;
                }
                // numlock disabled. fallthrough to key_home
            }
            case KEY_HOME: {

                shift_selection_check_pre(k.mod.shift);
                set_cursor_pos(0);
                shift_selection_check_post(k.mod.shift);
            }
            break;
            case KEY_KP_1: {
                if (k.unicode != 0) {
                    handled = false;
                    break;
                }
                // numlock disabled. fallthrough to key_end
            }
            case KEY_END: {

                shift_selection_check_pre(k.mod.shift);
                set_cursor_pos(text.length());
                shift_selection_check_post(k.mod.shift);
            }
            break;


            default: {

                handled=false;
            }
            break;
        }

        if (handled) {
            accept_event();
        } else if (!k.mod.alt && !k.mod.command) {
            if (k.unicode>=32 && k.scancode!=KEY_DELETE) {

                if (editable) {
                    selection_delete();
                    CharType ucodestr[2]= {(CharType)k.unicode,0};
                    append_at_cursor(ucodestr);
                    _text_changed();
                    accept_event();
                }

            } else {
                return;
            }
        }

        update();

    }


    return;

}
break;

    }
}

void LineEdit::set_align(Align p_align) {

ERR_FAIL_INDEX(p_align, 4);
align = p_align;
update();
}

LineEdit::Align LineEdit::get_align() const {

return align;
}

Variant LineEdit::get_drag_data(const Point2& p_point) {

if (selection.drag_attempt && selection.enabled) {
    String t = text.substr(selection.begin, selection.end - selection.begin);
    Label *l = memnew( Label );
    l->set_text(t);
    set_drag_preview(l);
    return 	t;
}

return Variant();

}
bool LineEdit::can_drop_data(const Point2& p_point,const Variant& p_data) const {

return p_data.get_type()==Variant::STRING;
}
void LineEdit::drop_data(const Point2& p_point,const Variant& p_data) {

if (p_data.get_type()==Variant::STRING) {
    set_cursor_at_pixel_pos(p_point.x);
    int selected = selection.end - selection.begin;

    Ref<Font> font = get_font("font");
    if (font != NULL) {
        for (int i = selection.begin; i < selection.end; i++)
            cached_width -= font->get_char_size(text[i]).width;
    }

    text.erase(selection.begin, selected);

    append_at_cursor(p_data);
    selection.begin = cursor_pos-selected;
    selection.end = cursor_pos;
}
}


void LineEdit::_notification(int p_what) {

switch(p_what) {
#ifdef TOOLS_ENABLED
case NOTIFICATION_ENTER_TREE: {
    if (get_tree()->is_editor_hint()) {
        cursor_set_blink_enabled(EDITOR_DEF("text_editor/caret_blink", false));
        cursor_set_blink_speed(EDITOR_DEF("text_editor/caret_blink_speed", 0.65));

        if (!EditorSettings::get_singleton()->is_connected("settings_changed",this,"_editor_settings_changed")) {
            EditorSettings::get_singleton()->connect("settings_changed",this,"_editor_settings_changed");
        }
    }
}
break;
#endif
case NOTIFICATION_RESIZED: {

    set_cursor_pos( get_cursor_pos() );

}
break;
case MainLoop::NOTIFICATION_WM_FOCUS_IN: {
    window_has_focus = true;
    draw_caret = true;
    update();
}
break;
case MainLoop::NOTIFICATION_WM_FOCUS_OUT: {
    window_has_focus = false;
    draw_caret = false;
    update();
}
break;
case NOTIFICATION_DRAW: {

    if ((!has_focus() && !menu->has_focus()) || !window_has_focus) {
        draw_caret = false;
    }

    int width,height;

    Size2 size=get_size();
    width=size.width;
    height=size.height;

    RID ci = get_canvas_item();

    Ref<StyleBox> style = get_stylebox("normal");
    if (!is_editable())
        style=get_stylebox("read_only");

    Ref<Font> font=get_font("font");

    style->draw( ci, Rect2( Point2(), size ) );

    if (has_focus()) {

        get_stylebox("focus")->draw( ci, Rect2( Point2(), size ) );
    }

    int x_ofs=0;

    switch (align) {

    case ALIGN_FILL:
    case ALIGN_LEFT: {

        x_ofs=style->get_offset().x;
    }
    break;
    case ALIGN_CENTER: {

        x_ofs=int(size.width-(cached_width))/2;
    }
    break;
    case ALIGN_RIGHT: {

        x_ofs=int(size.width-style->get_offset().x-(cached_width));
    }
    break;
    }

    int ofs_max=width-style->get_minimum_size().width;
    int char_ofs=window_pos;

    int y_area=height-style->get_minimum_size().height;
    int y_ofs=style->get_offset().y;

    int font_ascent=font->get_ascent();

    Color selection_color=get_color("selection_color");
    Color font_color=get_color("font_color");
    Color font_color_selected=get_color("font_color_selected");
    Color cursor_color=get_color("cursor_color");

    const String& t = text.empty() ? placeholder : text;
    // draw placeholder color
    if(text.empty())
        font_color.a *= placeholder_alpha;

    int caret_height = font->get_height() > y_area ? y_area : font->get_height();
    while(true) {

        //end of string, break!
        if (char_ofs>=t.length())
            break;

        CharType cchar=pass?'*':t[char_ofs];
        CharType next=pass?'*':t[char_ofs+1];
        int char_width=font->get_char_size( cchar,next ).width;

        // end of widget, break!
        if ((x_ofs + char_width) > ofs_max)
            break;


        bool selected=selection.enabled && char_ofs>=selection.begin && char_ofs<selection.end;

        if (selected)
            VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs), Size2(char_width, caret_height)), selection_color);


        font->draw_char(ci, Point2(x_ofs, y_ofs + font_ascent), cchar, next, selected ? font_color_selected : font_color);

        if (char_ofs==cursor_pos && draw_caret) {
            VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(
                        Point2( x_ofs , y_ofs ), Size2( 1, caret_height ) ), cursor_color );
        }

        x_ofs+=char_width;
        char_ofs++;
    }

    if (char_ofs==cursor_pos && draw_caret) {//may be at the end
        VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(
                    Point2( x_ofs , y_ofs ), Size2( 1, caret_height ) ), cursor_color );
    }
}
break;
case NOTIFICATION_FOCUS_ENTER: {

    if (!caret_blink_enabled) {
        draw_caret = true;
    }

    if (OS::get_singleton()->has_virtual_keyboard())
        OS::get_singleton()->show_virtual_keyboard(text,get_global_rect());

}
break;
case NOTIFICATION_FOCUS_EXIT: {

    if (OS::get_singleton()->has_virtual_keyboard())
        OS::get_singleton()->hide_virtual_keyboard();

}
break;

}
}

void LineEdit::copy_text() {

if(selection.enabled) {

    OS::get_singleton()->set_clipboard(text.substr(selection.begin, selection.end - selection.begin));
}
}

void LineEdit::cut_text() {

if(selection.enabled) {
    undo_text = text;
    OS::get_singleton()->set_clipboard(text.substr(selection.begin, selection.end - selection.begin));
    selection_delete();
}
}

void LineEdit::paste_text() {

String paste_buffer = OS::get_singleton()->get_clipboard();

if(paste_buffer != "") {

    if(selection.enabled) selection_delete();
    append_at_cursor(paste_buffer);

    _text_changed();
}



}

void LineEdit::undo() {

int old_cursor_pos = cursor_pos;
text = undo_text;

Ref<Font> font = get_font("font");

cached_width = 0;
for (int i = 0; i<text.length(); i++)
    cached_width += font->get_char_size(text[i]).width;

if(old_cursor_pos > text.length()) {
    set_cursor_pos(text.length());
} else {
    set_cursor_pos(old_cursor_pos);
}

_text_changed();
}
Exemplo n.º 12
0
void Label::_notification(int p_what) {

	if (p_what==NOTIFICATION_DRAW) {

		if (clip || autowrap)
			VisualServer::get_singleton()->canvas_item_set_clip(get_canvas_item(),true);

		if (word_cache_dirty)
			regenerate_word_cache();


		RID ci = get_canvas_item();

		Size2 string_size;
		Size2 size=get_size();

		Ref<Font> font = get_font("font");
		Color font_color = get_color("font_color");
		Color font_color_shadow = get_color("font_color_shadow");
		bool use_outlinde = get_constant("shadow_as_outline");
		Point2 shadow_ofs(get_constant("shadow_offset_x"),get_constant("shadow_offset_y"));
		int line_spacing = get_constant("line_spacing");

		VisualServer::get_singleton()->canvas_item_set_distance_field_mode(get_canvas_item(),font.is_valid() && font->is_distance_field_hint());

		int font_h = font->get_height()+line_spacing;

		int lines_visible = (size.y+line_spacing)/font_h;

		int space_w=font->get_char_size(' ').width;
		int chars_total=0;

		int vbegin=0,vsep=0;

		if (lines_visible > line_count) {
			lines_visible = line_count;

		}

		if (max_lines_visible >= 0 && lines_visible > max_lines_visible) {
			lines_visible = max_lines_visible;

		}

		if (lines_visible > 0) {

			switch(valign) {

				case VALIGN_TOP: {
					//nothing
				} break;
				case VALIGN_CENTER: {
					vbegin=(size.y - lines_visible * font_h) / 2;
					vsep=0;

				} break;
				case VALIGN_BOTTOM: {
					vbegin=size.y - lines_visible * font_h;
					vsep=0;

				} break;
				case VALIGN_FILL: {
					vbegin=0;
					if (lines_visible>1) {
						vsep=(size.y - lines_visible * font_h) / (lines_visible - 1);
					} else {
						vsep=0;
					}

				} break;
			}
		}


		WordCache *wc = word_cache;
		if (!wc)
			return;

		int line=0;
		int line_to=lines_skipped + (lines_visible>0?lines_visible:1);
		while(wc) {
		/* handle lines not meant to be drawn quickly */
			if  (line>=line_to)
				break;
			if  (line<lines_skipped) {

				while (wc && wc->char_pos>=0)
					wc=wc->next;
				if (wc)
					wc=wc->next;
				line++;
				continue;
			}

		/* handle lines normally */

			if (wc->char_pos<0) {
			//empty line
				wc=wc->next;
				line++;
				continue;
			}

			WordCache *from=wc;
			WordCache *to=wc;

			int taken=0;
			int spaces=0;
			while(to && to->char_pos>=0) {

				taken+=to->pixel_width;
				if (to!=from && to->space_count) {
					spaces+=to->space_count;
				}
				to=to->next;
			}

			bool can_fill = to && to->char_pos==WordCache::CHAR_WRAPLINE;

			float x_ofs=0;

			switch (align) {

				case ALIGN_FILL:
				case ALIGN_LEFT: {

					x_ofs=0;
				} break;
				case ALIGN_CENTER: {

					x_ofs=int(size.width-(taken+spaces*space_w))/2;;

				} break;
				case ALIGN_RIGHT: {


					x_ofs=int(size.width-(taken+spaces*space_w));

				} break;
				}

			int y_ofs=(line-lines_skipped)*font_h + font->get_ascent();
			y_ofs+=vbegin + line*vsep;

			while(from!=to) {

			// draw a word
				int pos = from->char_pos;
				if (from->char_pos<0) {

					ERR_PRINT("BUG");
					return;
				}
				if (from->space_count) {
				/* spacing */
					x_ofs+=space_w*from->space_count;
					if (can_fill && align==ALIGN_FILL && spaces) {

						x_ofs+=int((size.width-(taken+space_w*spaces))/spaces);
					}


				}



				if (font_color_shadow.a>0) {

					int chars_total_shadow = chars_total; //save chars drawn
					float x_ofs_shadow=x_ofs;
					for (int i=0;i<from->word_len;i++) {

						if (visible_chars < 0 || chars_total_shadow<visible_chars) {
							CharType c = text[i+pos];
							CharType n = text[i+pos+1];
							if (uppercase) {
								c=String::char_uppercase(c);
								n=String::char_uppercase(c);
							}

							float move=font->draw_char(ci, Point2( x_ofs_shadow, y_ofs )+shadow_ofs, c, n,font_color_shadow );
							if (use_outlinde) {
								font->draw_char(ci, Point2( x_ofs_shadow, y_ofs )+Vector2(-shadow_ofs.x,shadow_ofs.y), c, n,font_color_shadow );
								font->draw_char(ci, Point2( x_ofs_shadow, y_ofs )+Vector2(shadow_ofs.x,-shadow_ofs.y), c, n,font_color_shadow );
								font->draw_char(ci, Point2( x_ofs_shadow, y_ofs )+Vector2(-shadow_ofs.x,-shadow_ofs.y), c, n,font_color_shadow );
							}
							x_ofs_shadow+=move;
							chars_total_shadow++;
						}
					}


				}
				for (int i=0;i<from->word_len;i++) {

					if (visible_chars < 0 || chars_total<visible_chars) {
						CharType c = text[i+pos];
						CharType n = text[i+pos+1];
						if (uppercase) {
							c=String::char_uppercase(c);
							n=String::char_uppercase(c);
						}

						x_ofs+=font->draw_char(ci,Point2( x_ofs, y_ofs ), c, n, font_color );
						chars_total++;
					}

				}
				from=from->next;
			}

			wc=to?to->next:0;
			line++;

		}
	}

	if (p_what==NOTIFICATION_THEME_CHANGED) {

		word_cache_dirty=true;
		update();
	}
	if (p_what==NOTIFICATION_RESIZED) {

		word_cache_dirty=true;
	}

}
Exemplo n.º 13
0
void Label::regenerate_word_cache() {

	while (word_cache) {

		WordCache *current=word_cache;
		word_cache=current->next;
		memdelete( current );
	}


	int width=autowrap?get_size().width:get_longest_line_width();
	Ref<Font> font = get_font("font");

	int current_word_size=0;
	int word_pos=0;
	int line_width=0;
	int space_count=0;
	int space_width=font->get_char_size(' ').width;
	int line_spacing = get_constant("line_spacing");
	line_count=1;
	total_char_cache=0;

	WordCache *last=NULL;

	for (int i=0;i<text.size()+1;i++) {

		CharType current=i<text.length()?text[i]:' '; //always a space at the end, so the algo works

		if (uppercase)
			current=String::char_uppercase(current);

		// ranges taken from http://www.unicodemap.org/
		// if your language is not well supported, consider helping improve
		// the unicode support in Godot.
		bool separatable = (current>=0x2E08 && current<=0xFAFF) || (current>=0xFE30 && current<=0xFE4F);
				//current>=33 && (current < 65||current >90) && (current<97||current>122) && (current<48||current>57);
		bool insert_newline=false;
		int char_width;

		if (current<33) {

			if (current_word_size>0) {
				WordCache *wc = memnew( WordCache );
				if (word_cache) {
					last->next=wc;
				} else {
					word_cache=wc;
				}
				last=wc;

				wc->pixel_width=current_word_size;
				wc->char_pos=word_pos;
				wc->word_len=i-word_pos;
				wc->space_count = space_count;
				current_word_size=0;
				space_count=0;

			}


			if (current=='\n') {
				insert_newline=true;
			} else {
				total_char_cache++;
			}

			if (i<text.length() && text[i] == ' ') {
				total_char_cache--;  // do not count spaces
				if (line_width > 0 || last==NULL || last->char_pos!=WordCache::CHAR_WRAPLINE) {
					space_count++;
					line_width+=space_width;
				}else {
					space_count=0;
				}
			}


		} else {
			// latin characters
			if (current_word_size==0) {
				word_pos=i;
			}

			char_width=font->get_char_size(current).width;
			current_word_size+=char_width;
			line_width+=char_width;
			total_char_cache++;

		}

		if ((autowrap && (line_width >= width) && ((last && last->char_pos >= 0) || separatable)) || insert_newline) {
			if (separatable) {
				if (current_word_size>0) {
					WordCache *wc = memnew( WordCache );
					if (word_cache) {
						last->next=wc;
					} else {
						word_cache=wc;
					}
					last=wc;

					wc->pixel_width=current_word_size-char_width;
					wc->char_pos=word_pos;
					wc->word_len=i-word_pos;
					wc->space_count = space_count;
					current_word_size=char_width;
					space_count=0;
					word_pos=i;
				}
			}

			WordCache *wc = memnew( WordCache );
			if (word_cache) {
				last->next=wc;
			} else {
				word_cache=wc;
			}
			last=wc;

			wc->pixel_width=0;
			wc->char_pos=insert_newline?WordCache::CHAR_NEWLINE:WordCache::CHAR_WRAPLINE;

			line_width=current_word_size;
			line_count++;
			space_count=0;

		}

	}

	if (!autowrap) {
		minsize.width=width;
		if (max_lines_visible > 0 && line_count > max_lines_visible) {
			minsize.height=(font->get_height() * max_lines_visible) + (line_spacing * (max_lines_visible - 1));
		} else {
			minsize.height=(font->get_height() * line_count)+(line_spacing * (line_count - 1));
		}
	}

	word_cache_dirty=false;

}
Exemplo n.º 14
0
void Button::_notification(int p_what) {
	
	if (p_what==NOTIFICATION_DRAW) {
		
		RID ci = get_canvas_item();
		Size2 size=get_size();
		Color color;

		//print_line(get_text()+": "+itos(is_flat())+" hover "+itos(get_draw_mode()));
		
		switch( get_draw_mode() ) {
		
			case DRAW_NORMAL: {
			
				if (!flat)
					get_stylebox("normal" )->draw(  ci, Rect2(Point2(0,0), size) );
				color=get_color("font_color");			
			} break;
			case DRAW_PRESSED: {
			
				get_stylebox("pressed" )->draw(  ci, Rect2(Point2(0,0), size) );
				if (has_color("font_color_pressed"))
					color=get_color("font_color_pressed");
				else
					color=get_color("font_color");
			
			} break;
			case DRAW_HOVER: {
			
				get_stylebox("hover" )->draw(  ci, Rect2(Point2(0,0), size) );
				color=get_color("font_color_hover");
				
			} break;
			case DRAW_DISABLED: {

				get_stylebox("disabled" )->draw(  ci, Rect2(Point2(0,0), size) );
				color=get_color("font_color_disabled");
			
			} break;
		}

		if (has_focus()) {

			Ref<StyleBox> style = get_stylebox("focus");
			style->draw(ci,Rect2(Point2(),size));
		}

		Ref<StyleBox> style = get_stylebox("normal" );
		Ref<Font> font=get_font("font");
		Ref<Texture> _icon;
		if (icon.is_null() && has_icon("icon"))
			_icon=Control::get_icon("icon");
		else
			_icon=icon;

		Point2 icon_ofs = (!_icon.is_null())?Point2( _icon->get_width() + get_constant("hseparation"), 0):Point2();
		int text_clip=size.width - style->get_minimum_size().width - icon_ofs.width;
		Point2 text_ofs = (size - style->get_minimum_size() - icon_ofs - font->get_string_size( text ) )/2.0;

		switch(align) {
			case ALIGN_LEFT: {
				text_ofs.x = style->get_margin(MARGIN_LEFT) + icon_ofs.x;
				text_ofs.y+=style->get_offset().y;
			} break;
			case ALIGN_CENTER: {
				if (text_ofs.x<0)
					text_ofs.x=0;
				text_ofs+=icon_ofs;
				text_ofs+=style->get_offset();
			} break;
			case ALIGN_RIGHT: {
				text_ofs.x=size.x - style->get_margin(MARGIN_RIGHT) - font->get_string_size( text ).x;
				text_ofs.y+=style->get_offset().y;
			} break;
		}


		text_ofs.y+=font->get_ascent();
		font->draw( ci, text_ofs.floor(), text, color,clip_text?text_clip:-1);
		if (!_icon.is_null()) {

			int valign = size.height-style->get_minimum_size().y;
		
			_icon->draw(ci,style->get_offset()+Point2(0, Math::floor( (valign-_icon->get_height())/2.0 ) ),is_disabled()?Color(1,1,1,0.4):Color(1,1,1) );
		}


				
	}
}
Exemplo n.º 15
0
void Tabs::_update_cache() {
	Ref<StyleBox> tab_disabled = get_stylebox("tab_disabled");
	Ref<StyleBox> tab_bg = get_stylebox("tab_bg");
	Ref<StyleBox> tab_fg = get_stylebox("tab_fg");
	Ref<Font> font = get_font("font");
	Ref<Texture> incr = get_icon("increment");
	Ref<Texture> decr = get_icon("decrement");
	int limit = get_size().width - incr->get_width() - decr->get_width();

	int w = 0;
	int mw = 0;
	int size_fixed = 0;
	int count_resize = 0;
	for (int i = 0; i < tabs.size(); i++) {
		tabs[i].ofs_cache = mw;
		tabs[i].size_cache = get_tab_width(i);
		tabs[i].size_text = font->get_string_size(tabs[i].text).width;
		mw += tabs[i].size_cache;
		if (tabs[i].size_cache <= min_width || i == current) {
			size_fixed += tabs[i].size_cache;
		} else {
			count_resize++;
		}
	}
	int m_width = min_width;
	if (count_resize > 0) {
		m_width = MAX((limit - size_fixed) / count_resize, min_width);
	}
	for (int i = 0; i < tabs.size(); i++) {
		if (i < offset)
			continue;
		Ref<StyleBox> sb;
		if (tabs[i].disabled) {
			sb = tab_disabled;
		} else if (i == current) {
			sb = tab_fg;
		} else {
			sb = tab_bg;
		}
		int lsize = tabs[i].size_cache;
		int slen = tabs[i].size_text;
		if (min_width > 0 && mw > limit && i != current) {
			if (lsize > m_width) {
				slen = m_width - (sb->get_margin(MARGIN_LEFT) + sb->get_margin(MARGIN_RIGHT));
				if (tabs[i].icon.is_valid()) {
					slen -= tabs[i].icon->get_width();
					slen -= get_constant("hseparation");
				}
				if (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && i == current)) {
					Ref<Texture> cb = get_icon("close");
					slen -= cb->get_width();
					slen -= get_constant("hseparation");
				}
				slen = MAX(slen, 1);
				lsize = m_width;
			}
		}
		tabs[i].ofs_cache = w;
		tabs[i].size_cache = lsize;
		tabs[i].size_text = slen;
		w += lsize;
	}
}
Exemplo n.º 16
0
void SplitContainer::_resort() {

	/** First pass, determine minimum size AND amount of stretchable elements */

	int axis = vertical?1:0;

	bool has_first=_getch(0);
	bool has_second=_getch(1);

	if (!has_first && !has_second) {
		return;
	} else if (! (has_first && has_second)) {
		if (has_first)
			fit_child_in_rect(_getch(0),Rect2(Point2(),get_size()));
		else
			fit_child_in_rect(_getch(1),Rect2(Point2(),get_size()));

		return;
	}



	Control *first=_getch(0);
	Control *second=_getch(1);


	bool ratiomode=false;
	bool expand_first_mode=false;




	if (vertical) {

		ratiomode=first->get_v_size_flags()&SIZE_EXPAND && second->get_v_size_flags()&SIZE_EXPAND;
		expand_first_mode=first->get_v_size_flags()&SIZE_EXPAND && !(second->get_v_size_flags()&SIZE_EXPAND);
	} else {

		ratiomode=first->get_h_size_flags()&SIZE_EXPAND && second->get_h_size_flags()&SIZE_EXPAND;
		expand_first_mode=first->get_h_size_flags()&SIZE_EXPAND && !(second->get_h_size_flags()&SIZE_EXPAND);
	}


	int sep=get_constant("separation");
	Ref<Texture> g = get_icon("grabber");

	if (collapsed || !dragger_visible) {
		sep=0;
	} else {
		sep=MAX(sep,vertical?g->get_height():g->get_width());
	}

	int total = vertical?get_size().height:get_size().width;

	total-=sep;

	int minimum=0;

	Size2 ms_first = first->get_combined_minimum_size();
	Size2 ms_second = second->get_combined_minimum_size();

	if (vertical) {

		minimum=ms_first.height+ms_second.height;
	} else {

		minimum=ms_first.width+ms_second.width;
	}

	int available=total-minimum;
	if (available<0)
		available=0;


	middle_sep=0;

	if (collapsed) {


		if (ratiomode) {

			middle_sep=ms_first[axis]+available/2;


		} else if (expand_first_mode) {

			middle_sep=get_size()[axis]-ms_second[axis]-sep;

		} else {

			middle_sep=ms_first[axis];
		}


	} else if (ratiomode) {

		if (expand_ofs<-(available/2))
			expand_ofs=-(available/2);
		else if (expand_ofs>(available/2))
			expand_ofs=(available/2);

		middle_sep=ms_first[axis]+available/2+expand_ofs;


	} else if (expand_first_mode) {

		if (expand_ofs>0)
			expand_ofs=0;

		if (expand_ofs < -available)
			expand_ofs=-available;

		middle_sep=get_size()[axis]-ms_second[axis]-sep+expand_ofs;

	} else {

		if (expand_ofs<0)
			expand_ofs=0;

		if (expand_ofs > available)
			expand_ofs=available;

		middle_sep=ms_first[axis]+expand_ofs;

	}



	if (vertical) {

		fit_child_in_rect(first,Rect2(Point2(0,0),Size2(get_size().width,middle_sep)));
		int sofs=middle_sep+sep;
		fit_child_in_rect(second,Rect2(Point2(0,sofs),Size2(get_size().width,get_size().height-sofs)));

	} else {


		fit_child_in_rect(first,Rect2(Point2(0,0),Size2(middle_sep,get_size().height)));
		int sofs=middle_sep+sep;
		fit_child_in_rect(second,Rect2(Point2(sofs,0),Size2(get_size().width-sofs,get_size().height)));
	}

	update();
	_change_notify("split/offset");

}
Exemplo n.º 17
0
Rect2 Tabs::get_tab_rect(int p_tab) const {
	return Rect2(tabs[p_tab].ofs_cache, 0, tabs[p_tab].size_cache, get_size().height);
}
Exemplo n.º 18
0
void DockedFrame::on_resized()
{
    dockable->set_geometry(get_size());
}
Exemplo n.º 19
0
static loff_t get_loop_size(struct loop_device *lo, struct file *file)
{
	return get_size(lo->lo_offset, lo->lo_sizelimit, file);
}
Exemplo n.º 20
0
int main()
{
    for(int sz = get_size(); sz <= 0; sz = get_size())
        ;//ûÓÐÒƶ¯
}
Exemplo n.º 21
0
int ttext::get_height() const
{
	return get_size().y;
}
Exemplo n.º 22
0
int
gdbm_setopt (GDBM_FILE dbf, int optflag, void *optval, int optlen)
{
  int n;
  size_t sz;
  
  switch (optflag)
    {
      /* Cache size: */
      
      case GDBM_SETCACHESIZE:
        /* Optval will point to the new size of the cache. */
        if (dbf->bucket_cache != NULL)
          {
            gdbm_errno = GDBM_OPT_ALREADY_SET;
            return -1;
          }

	if (get_size (optval, optlen, &sz))
	  return -1;
        return _gdbm_init_cache (dbf, (sz > 9) ? sz : 10);

      case GDBM_GETCACHESIZE:
	if (!optval || optlen != sizeof (size_t))
	  {
	    gdbm_errno = GDBM_OPT_ILLEGAL;
	    return -1;
	  }
	*(size_t*) optval = dbf->cache_size;
	break;
	
      	/* Obsolete form of GDBM_SETSYNCMODE. */
      case GDBM_FASTMODE:
	if ((n = getbool (optval, optlen)) == -1)
	  return -1;
	dbf->fast_write = n;
	break;

	/* SYNC mode: */
	
      case GDBM_SETSYNCMODE:
      	/* Optval will point to either true or false. */
	if ((n = getbool (optval, optlen)) == -1)
	  return -1;
	dbf->fast_write = !n;
	break;

      case GDBM_GETSYNCMODE:
	if (!optval || optlen != sizeof (int))
	  {
	    gdbm_errno = GDBM_OPT_ILLEGAL;
	    return -1;
	  }
	*(int*) optval = !dbf->fast_write;
	break;

	/* CENTFREE - set or get the stat of the central block repository */
      case GDBM_SETCENTFREE:
      	/* Optval will point to either true or false. */
	if ((n = getbool (optval, optlen)) == -1)
	  return -1;
	dbf->central_free = n;
	break;

      case GDBM_GETCENTFREE:
	if (!optval || optlen != sizeof (int))
	  {
	    gdbm_errno = GDBM_OPT_ILLEGAL;
	    return -1;
	  }
	*(int*) optval = !dbf->central_free;
	break;

	/* Coalesce state: */
      case GDBM_SETCOALESCEBLKS:
      	/* Optval will point to either true or false. */
	if ((n = getbool (optval, optlen)) == -1)
	  return -1;
	dbf->coalesce_blocks = n;
	break;

      case GDBM_GETCOALESCEBLKS:
	if (!optval || optlen != sizeof (int))
	  {
	    gdbm_errno = GDBM_OPT_ILLEGAL;
	    return -1;
	  }
	*(int*) optval = dbf->coalesce_blocks;
	break;

	/* Mmap mode */
      case GDBM_SETMMAP:
#if HAVE_MMAP
	if ((n = getbool (optval, optlen)) == -1)
	  return -1;
	__fsync (dbf);
	if (n == dbf->memory_mapping)
	  return 0;
	if (n)
	  {
	    if (_gdbm_mapped_init (dbf) == 0)
	      dbf->memory_mapping = TRUE;
	    else
	      return -1;
	  }
	else
	  {
	    _gdbm_mapped_unmap (dbf);
	    dbf->memory_mapping = FALSE;
	  }
#else
	gdbm_errno = GDBM_OPT_ILLEGAL;
	return -1;
#endif
	break;
	
      case GDBM_GETMMAP:
	if (!optval || optlen != sizeof (int))
	  {
	    gdbm_errno = GDBM_OPT_ILLEGAL;
	    return -1;
	  }
	*(int*) optval = dbf->memory_mapping;
	break;

	/* Maximum size of a memory mapped region */
      case GDBM_SETMAXMAPSIZE:
#if HAVE_MMAP
	{
	  size_t page_size = sysconf (_SC_PAGESIZE);

	  if (get_size (optval, optlen, &sz))
	    return -1;
	  dbf->mapped_size_max = ((sz + page_size - 1) / page_size) *
	                          page_size;
	  _gdbm_mapped_init (dbf);
	  break;
	}
#else
	gdbm_errno = GDBM_OPT_ILLEGAL;
	return -1;
#endif
	
      case GDBM_GETMAXMAPSIZE:
	if (!optval || optlen != sizeof (size_t))
	  {
	    gdbm_errno = GDBM_OPT_ILLEGAL;
	    return -1;
	  }
	*(size_t*) optval = dbf->mapped_size_max;
	break;

	/* Flags */
      case GDBM_GETFLAGS:
	if (!optval || optlen != sizeof (int))
	  {
	    gdbm_errno = GDBM_OPT_ILLEGAL;
	    return -1;
	  }
	else
	  {
	    int flags = dbf->read_write;
	    if (!dbf->fast_write)
	      flags |= GDBM_SYNC;
	    if (!dbf->file_locking)
	      flags |= GDBM_NOLOCK;
	    if (!dbf->memory_mapping)
	      flags |= GDBM_NOMMAP;
	    *(int*) optval = flags;
	  }
	break;

      case GDBM_GETDBNAME:
	if (!optval || optlen != sizeof (char*))
	  {
	    gdbm_errno = GDBM_OPT_ILLEGAL;
	    return -1;
	  }
	else
	  {
	    char *p = strdup (dbf->name);
	    if (!p)
	      {
		gdbm_errno = GDBM_MALLOC_ERROR;
		return -1;
	      }
	    *(char**) optval = p;
	  }
	break;
	
      default:
        gdbm_errno = GDBM_OPT_ILLEGAL;
        return -1;
    }

  return 0;
}
 iterator iterator_slice(size_t slice_number, size_t number_of_slice) const {
   std::pair<size_t, size_t> res = slice(slice_number, number_of_slice, get_size());
   return iterator(this, res.first, res.second);
 }
Exemplo n.º 24
0
int mkswap_main(int argc, char **argv)
{
	char *tmp;
	struct stat statbuf;
	int sz;
	int maxpages;
	int goodpages;
	int offset;
	int force = 0;

	init_signature_page();		/* get pagesize */

	while (argc-- > 1) {
		argv++;
		if (argv[0][0] != '-') {
			if (device_name) {
				int blocks_per_page = pagesize / 1024;

				PAGES = strtol(argv[0], &tmp, 0) / blocks_per_page;
				if (*tmp)
					bb_show_usage();
			} else
				device_name = argv[0];
		} else {
			switch (argv[0][1]) {
			case 'c':
				check = 1;
				break;
			case 'f':
				force = 1;
				break;
			case 'v':
				version = atoi(argv[0] + 2);
				break;
			default:
				bb_show_usage();
			}
		}
	}
	if (!device_name) {
		bb_error_msg("error: Nowhere to set up swap on?");
		bb_show_usage();
	}
	sz = get_size(device_name);
	if (!PAGES) {
		PAGES = sz;
	} else if (PAGES > sz && !force) {
		bb_error_msg("error: size %ld is larger than device size %d",
				PAGES * (pagesize / 1024), sz * (pagesize / 1024));
		return EXIT_FAILURE;
	}

	if (version == -1) {
		if (PAGES <= V0_MAX_PAGES)
			version = 0;
		else if (get_kernel_revision() < MAKE_VERSION(2, 1, 117))
			version = 0;
		else if (pagesize < 2048)
			version = 0;
		else
			version = 1;
	}
	if (version != 0 && version != 1) {
		bb_error_msg("error: unknown version %d", version);
		bb_show_usage();
	}
	if (PAGES < 10) {
		bb_error_msg("error: swap area needs to be at least %ldkB",
				(long) (10 * pagesize / 1024));
		bb_show_usage();
	}
#if 0
	maxpages = ((version == 0) ? V0_MAX_PAGES : V1_MAX_PAGES);
#else
	if (!version)
		maxpages = V0_MAX_PAGES;
	else if (get_kernel_revision() >= MAKE_VERSION(2, 2, 1))
		maxpages = V1_MAX_PAGES;
	else {
		maxpages = V1_OLD_MAX_PAGES;
		if (maxpages > V1_MAX_PAGES)
			maxpages = V1_MAX_PAGES;
	}
#endif
	if (PAGES > maxpages) {
		PAGES = maxpages;
		bb_error_msg("warning: truncating swap area to %ldkB",
				PAGES * pagesize / 1024);
	}

	DEV = open(device_name, O_RDWR);
	if (DEV < 0 || fstat(DEV, &statbuf) < 0)
		bb_perror_msg_and_die("%s", device_name);
	if (!S_ISBLK(statbuf.st_mode))
		check = 0;
	else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340)
		bb_error_msg_and_die("Will not try to make swapdevice on '%s'", device_name);

#ifdef __sparc__
	if (!force && version == 0) {
		/* Don't overwrite partition table unless forced */
		unsigned char *buffer = (unsigned char *) signature_page;
		unsigned short *q, sum;

		if (read(DEV, buffer, 512) != 512)
			bb_error_msg_and_die("fatal: first page unreadable");
		if (buffer[508] == 0xDA && buffer[509] == 0xBE) {
			q = (unsigned short *) (buffer + 510);
			for (sum = 0; q >= (unsigned short *) buffer;)
				sum ^= *q--;
			if (!sum) {
				bb_error_msg("Device '%s' contains a valid Sun disklabel.\n"
"This probably means creating v0 swap would destroy your partition table\n"
"No swap created. If you really want to create swap v0 on that device, use\n"
"the -f option to force it.", device_name);
				return EXIT_FAILURE;
			}
		}
	}
#endif

	if (version == 0 || check)
		check_blocks();
	if (version == 0 && !bit_test_and_clear(signature_page, 0))
		bb_error_msg_and_die("fatal: first page unreadable");
	if (version == 1) {
		p->version = version;
		p->last_page = PAGES - 1;
		p->nr_badpages = badpages;
	}

	goodpages = PAGES - badpages - 1;
	if (goodpages <= 0)
		bb_error_msg_and_die("Unable to set up swap-space: unreadable");
	printf("Setting up swapspace version %d, size = %ld bytes\n",
		   version, (long) (goodpages * pagesize));
	write_signature((version == 0) ? "SWAP-SPACE" : "SWAPSPACE2");

	offset = ((version == 0) ? 0 : 1024);
	if (lseek(DEV, offset, SEEK_SET) != offset)
		bb_error_msg_and_die("unable to rewind swap-device");
	if (write(DEV, (char *) signature_page + offset, pagesize - offset)
		!= pagesize - offset)
		bb_error_msg_and_die("unable to write signature page");

	/*
	 * A subsequent swapon() will fail if the signature
	 * is not actually on disk. (This is a kernel bug.)
	 */
	if (fsync(DEV))
		bb_error_msg_and_die("fsync failed");
	return EXIT_SUCCESS;
}
static int red_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
{
    struct tc_nred_qopt opt;
    unsigned burst = 0;
    unsigned avpkt = 0;
    double probability = 0.02;
    unsigned rate = 0;
    int wlog;
    char a[10];
    int len,i,result;
   
    __u8 sbuf[256];
    __u32 max_P;
    struct rtattr *tail;

    memset(&opt, 0, sizeof(opt));

    while (argc > 0) {
        if (strcmp(*argv, "limit") == 0) {
            NEXT_ARG();
            if (get_size(&opt.limit, *argv)) {
                fprintf(stderr, "Illegal \"limit\"\n");
                return -1;
            }
        } else if (strcmp(*argv, "min") == 0) {
            NEXT_ARG();
            if (get_size(&opt.qth_min, *argv)) {
                fprintf(stderr, "Illegal \"min\"\n");
                return -1;
            }
        }else if (strcmp(*argv, "factor") == 0) {
            NEXT_ARG();
            strcpy(a,*argv);
           
        len = strlen(a);

        for(i=0; i<len; i++){

            result = result * 10 + ( a[i] - '0' );

                }
               
            opt.factor=result;
            //fprintf(stderr, "Illegal \"decre\ %d\n",opt.decrement);
                //return -1;
           
        }
        else if (strcmp(*argv, "max") == 0) {
            NEXT_ARG();
            if (get_size(&opt.qth_max, *argv)) {
                fprintf(stderr, "Illegal \"max\"\n");
                return -1;
            }
        } else if (strcmp(*argv, "burst") == 0) {
            NEXT_ARG();
            if (get_unsigned(&burst, *argv, 0)) {
                fprintf(stderr, "Illegal \"burst\"\n");
                return -1;
            }
        } else if (strcmp(*argv, "avpkt") == 0) {
            NEXT_ARG();
            if (get_size(&avpkt, *argv)) {
                fprintf(stderr, "Illegal \"avpkt\"\n");
                return -1;
            }
        } else if (strcmp(*argv, "probability") == 0) {
            NEXT_ARG();
            if (sscanf(*argv, "%lg", &probability) != 1) {
                fprintf(stderr, "Illegal \"probability\"\n");
                return -1;
            }
        } else if (strcmp(*argv, "bandwidth") == 0) {
            NEXT_ARG();
            if (get_rate(&rate, *argv)) {
                fprintf(stderr, "Illegal \"bandwidth\"\n");
                return -1;
            }
        } else if (strcmp(*argv, "ecn") == 0) {
            opt.flags |= TC_RED_ECN;
        } else if (strcmp(*argv, "harddrop") == 0) {
            opt.flags |= TC_RED_HARDDROP;
        } else if (strcmp(*argv, "adaptative") == 0) {
            opt.flags |= TC_RED_ADAPTATIVE;
        } else if (strcmp(*argv, "adaptive") == 0) {
            opt.flags |= TC_RED_ADAPTATIVE;
        } else if (strcmp(*argv, "help") == 0) {
            explain();
            return -1;
        } else {
            fprintf(stderr, "What is \"%s\"?\n", *argv);
            explain();
            return -1;
        }
        argc--; argv++;
    }

    if (rate == 0)
        get_rate(&rate, "10Mbit");

    if (!opt.limit || !avpkt) {
        fprintf(stderr, "RED: Required parameter (limit, avpkt) is missing\n");
        return -1;
    }
    /* Compute default min/max thresholds based on
     * Sally Floyd's recommendations:
     * http://www.icir.org/floyd/REDparameters.txt
     */
    if (!opt.qth_max)
        opt.qth_max = opt.qth_min ? opt.qth_min * 3 : opt.limit / 4;
    if (!opt.qth_min)
        opt.qth_min = opt.qth_max / 3;
    if (!burst)
        burst = (2 * opt.qth_min + opt.qth_max) / (3 * avpkt);
    if ((wlog = tc_red_eval_ewma(opt.qth_min, burst, avpkt)) < 0) {
        fprintf(stderr, "RED: failed to calculate EWMA constant.\n");
        return -1;
    }
    if (wlog >= 10)
        fprintf(stderr, "RED: WARNING. Burst %d seems to be too large.\n", burst);
    opt.Wlog = wlog;
    if ((wlog = tc_red_eval_P(opt.qth_min, opt.qth_max, probability)) < 0) {
        fprintf(stderr, "RED: failed to calculate probability.\n");
        return -1;
    }
    opt.Plog = wlog;
   
    if ((wlog = tc_red_eval_idle_damping(opt.Wlog, avpkt, rate, sbuf)) < 0) {
        fprintf(stderr, "RED: failed to calculate idle damping table.\n");
        return -1;
    }
    opt.Scell_log = wlog;
    //opt.decrement=opt.qth_min/10;
    tail = NLMSG_TAIL(n);
    addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
    addattr_l(n, 1024, TCA_NRED_PARMS, &opt, sizeof(opt));
    addattr_l(n, 1024, TCA_NRED_STAB, sbuf, 256);
    max_P = probability * pow(2, 32);
    addattr_l(n, 1024, TCA_NRED_MAX_P, &max_P, sizeof(max_P));
    tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
    return 0;
}
Exemplo n.º 26
0
		TITANIUM_PROPERTY_GETTER(File, size)
		{
			return get_context().CreateNumber(static_cast<double>(get_size()));
		}
Exemplo n.º 27
0
int main(int argc, char **argv)
{
	int    l, i, j;
	int    dim, num;
	int    step;
	int    level;
	char   name[NAMELEN];
	double min, max, shift, threshold;
	double **data;
	FILE   *fp;

	if(argc != 4){
		fprintf(stderr, "\n[使用法] : contour <file> <step> <level>\n");
		exit(1);
	}

	get_size(argv[1], &dim, &num);

	if(dim != DIM + 1){
		fprintf(stderr, "\n[エラー] : このプログラムは2次元データのみ対応\n");
		exit(1);
	}

	step = atoi(argv[2]);
	level = atoi(argv[3]);
	data = new_double_matrix(num, dim);

	if((fp = fopen(argv[1], "r")) == NULL){
		fprintf(stderr, "\n[エラー] : %s が開けません\n", argv[1]);
		exit(1);
	}
	
	for(i = 0; i < num; i++)
		for(j = 0; j < dim; j++)
			fscanf(fp, "%lf", &data[i][j]);
	
	fclose(fp);
	
	min = DBL_MAX;
	max = -DBL_MAX;
	for(i = 0; i < num; i++){
		if(min > data[i][2])
			min = data[i][2];
		if(max < data[i][2])
			max = data[i][2];
	}

	shift = (max - min) / ((double)level + 1.0);
	threshold = min + shift;
	
	for(l = 1; l <= level; l++){
	
		sprintf(name, "level%d.dat", l);
		if((fp = fopen(name, "w")) == NULL){
			fprintf(stderr, "\n[エラー] : %sが用意できませんでした\n", name);
			exit(1);
		}

		for(i = 0; i < num; i++){

			if(((i+1) % step) != 1){

				/* 指定された等高線かどうか判定 */
				if((data[i][2] - threshold) * (data[i-1][2] - threshold) < 0.0){

					for(j = 0; j < 2; j++)
						fprintf(fp, "%f ", (data[i][j] + data[i-1][j]) / 2.0);
					fprintf(fp, "\n");

				}

			}

		}

		threshold += shift;
		fclose(fp);
	}

	free_double_matrix(data);

	exit(0);
}
Exemplo n.º 28
0
void Tabs::_notification(int p_what) {

	switch (p_what) {

		case NOTIFICATION_MOUSE_EXIT: {
			rb_hover = -1;
			cb_hover = -1;
			hover = -1;
			update();
		} break;
		case NOTIFICATION_RESIZED: {
			_update_cache();
			_ensure_no_over_offset();
			ensure_tab_visible(current);

		} break;
		case NOTIFICATION_DRAW: {
			_update_cache();
			RID ci = get_canvas_item();

			Ref<StyleBox> tab_bg = get_stylebox("tab_bg");
			Ref<StyleBox> tab_fg = get_stylebox("tab_fg");
			Ref<StyleBox> tab_disabled = get_stylebox("tab_disabled");
			Ref<Font> font = get_font("font");
			Color color_fg = get_color("font_color_fg");
			Color color_bg = get_color("font_color_bg");
			Color color_disabled = get_color("font_color_disabled");
			Ref<Texture> close = get_icon("close");

			int h = get_size().height;
			int w = 0;
			int mw = 0;

			for (int i = 0; i < tabs.size(); i++) {

				tabs[i].ofs_cache = mw;
				mw += get_tab_width(i);
			}

			if (tab_align == ALIGN_CENTER) {
				w = (get_size().width - mw) / 2;
			} else if (tab_align == ALIGN_RIGHT) {
				w = get_size().width - mw;
			}

			if (w < 0) {
				w = 0;
			}

			Ref<Texture> incr = get_icon("increment");
			Ref<Texture> decr = get_icon("decrement");
			Ref<Texture> incr_hl = get_icon("increment_highlight");
			Ref<Texture> decr_hl = get_icon("decrement_highlight");

			int limit = get_size().width - incr->get_size().width - decr->get_size().width;

			missing_right = false;

			for (int i = 0; i < tabs.size(); i++) {

				if (i < offset)
					continue;

				tabs[i].ofs_cache = w;

				int lsize = tabs[i].size_cache;

				Ref<StyleBox> sb;
				Color col;

				if (tabs[i].disabled) {
					sb = tab_disabled;
					col = color_disabled;
				} else if (i == current) {
					sb = tab_fg;
					col = color_fg;
				} else {
					sb = tab_bg;
					col = color_bg;
				}

				if (w + lsize > limit) {
					max_drawn_tab = i - 1;
					missing_right = true;
					break;
				} else {
					max_drawn_tab = i;
				}

				Rect2 sb_rect = Rect2(w, 0, tabs[i].size_cache, h);
				sb->draw(ci, sb_rect);

				w += sb->get_margin(MARGIN_LEFT);

				Size2i sb_ms = sb->get_minimum_size();
				Ref<Texture> icon = tabs[i].icon;
				if (icon.is_valid()) {

					icon->draw(ci, Point2i(w, sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - icon->get_height()) / 2));
					if (tabs[i].text != "")
						w += icon->get_width() + get_constant("hseparation");
				}

				font->draw(ci, Point2i(w, sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - font->get_height()) / 2 + font->get_ascent()), tabs[i].text, col, tabs[i].size_text);

				w += tabs[i].size_text;

				if (tabs[i].right_button.is_valid()) {

					Ref<StyleBox> style = get_stylebox("button");
					Ref<Texture> rb = tabs[i].right_button;

					w += get_constant("hseparation");

					Rect2 rb_rect;
					rb_rect.size = style->get_minimum_size() + rb->get_size();
					rb_rect.position.x = w;
					rb_rect.position.y = sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - (rb_rect.size.y)) / 2;

					if (rb_hover == i) {
						if (rb_pressing)
							get_stylebox("button_pressed")->draw(ci, rb_rect);
						else
							style->draw(ci, rb_rect);
					}

					rb->draw(ci, Point2i(w + style->get_margin(MARGIN_LEFT), rb_rect.position.y + style->get_margin(MARGIN_TOP)));
					w += rb->get_width();
					tabs[i].rb_rect = rb_rect;
				}

				if (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && i == current)) {

					Ref<StyleBox> style = get_stylebox("button");
					Ref<Texture> cb = close;

					w += get_constant("hseparation");

					Rect2 cb_rect;
					cb_rect.size = style->get_minimum_size() + cb->get_size();
					cb_rect.position.x = w;
					cb_rect.position.y = sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - (cb_rect.size.y)) / 2;

					if (!tabs[i].disabled && cb_hover == i) {
						if (cb_pressing)
							get_stylebox("button_pressed")->draw(ci, cb_rect);
						else
							style->draw(ci, cb_rect);
					}

					cb->draw(ci, Point2i(w + style->get_margin(MARGIN_LEFT), cb_rect.position.y + style->get_margin(MARGIN_TOP)));
					w += cb->get_width();
					tabs[i].cb_rect = cb_rect;
				}

				w += sb->get_margin(MARGIN_RIGHT);
			}

			if (offset > 0 || missing_right) {

				int vofs = (get_size().height - incr->get_size().height) / 2;

				if (offset > 0)
					draw_texture(highlight_arrow == 0 ? decr_hl : decr, Point2(limit, vofs));
				else
					draw_texture(decr, Point2(limit, vofs), Color(1, 1, 1, 0.5));

				if (missing_right)
					draw_texture(highlight_arrow == 1 ? incr_hl : incr, Point2(limit + decr->get_size().width, vofs));
				else
					draw_texture(incr, Point2(limit + decr->get_size().width, vofs), Color(1, 1, 1, 0.5));

				buttons_visible = true;
			} else {
				buttons_visible = false;
			}

		} break;
	}
}
Exemplo n.º 29
0
/*
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
*/
static int gred_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
{
	int ok=0;
	struct tc_gred_qopt opt = { 0 };
	unsigned burst = 0;
	unsigned avpkt = 0;
	double probability = 0.02;
	unsigned rate = 0;
	int parm;
	__u8 sbuf[256];
	struct rtattr *tail;
	__u32 max_P;

	opt.DP = MAX_DPs;

	while (argc > 0) {
		if (strcmp(*argv, "limit") == 0) {
			NEXT_ARG();
			if (get_size(&opt.limit, *argv)) {
				fprintf(stderr, "Illegal \"limit\"\n");
				return -1;
			}
			ok++;
		} else if (strcmp(*argv, "setup") == 0) {
			if (ok) {
				fprintf(stderr, "Illegal \"setup\"\n");
				return -1;
			}
			return init_gred(qu, argc-1, argv+1, n);
		} else if (strcmp(*argv, "min") == 0) {
			NEXT_ARG();
			if (get_size(&opt.qth_min, *argv)) {
				fprintf(stderr, "Illegal \"min\"\n");
				return -1;
			}
			ok++;
		} else if (strcmp(*argv, "max") == 0) {
			NEXT_ARG();
			if (get_size(&opt.qth_max, *argv)) {
				fprintf(stderr, "Illegal \"max\"\n");
				return -1;
			}
			ok++;
		} else if (strcmp(*argv, "vq") == 0 ||
			   strcmp(*argv, "DP") == 0) {
			NEXT_ARG();
			if (get_unsigned(&opt.DP, *argv, 10)) {
				fprintf(stderr, "Illegal \"vq\"\n");
				return -1;
			} else if (opt.DP >= MAX_DPs) {
				fprintf(stderr, "GRED: only %u VQs are "
					"currently supported\n", MAX_DPs);
				return -1;
			} /* need a better error check */
			ok++;
		} else if (strcmp(*argv, "burst") == 0) {
			NEXT_ARG();
			if (get_unsigned(&burst, *argv, 0)) {
				fprintf(stderr, "Illegal \"burst\"\n");
				return -1;
			}
			ok++;
		} else if (strcmp(*argv, "avpkt") == 0) {
			NEXT_ARG();
			if (get_size(&avpkt, *argv)) {
				fprintf(stderr, "Illegal \"avpkt\"\n");
				return -1;
			}
			ok++;
		} else if (strcmp(*argv, "probability") == 0) {
			NEXT_ARG();
			if (sscanf(*argv, "%lg", &probability) != 1) {
				fprintf(stderr, "Illegal \"probability\"\n");
				return -1;
			}
			ok++;
		} else if (strcmp(*argv, "prio") == 0) {
			NEXT_ARG();
			opt.prio=strtol(*argv, (char **)NULL, 10);
			/* some error check here */
			ok++;
		} else if (strcmp(*argv, "bandwidth") == 0) {
			NEXT_ARG();
			if (get_rate(&rate, *argv)) {
				fprintf(stderr, "Illegal \"bandwidth\"\n");
				return -1;
			}
			ok++;
		} else if (strcmp(*argv, "help") == 0) {
			explain();
			return -1;
		} else {
			fprintf(stderr, "What is \"%s\"?\n", *argv);
			explain();
			return -1;
		}
		argc--; argv++;
	}

	if (!ok) {
		explain();
		return -1;
	}
	if (opt.DP == MAX_DPs || !opt.limit || !opt.qth_min || !opt.qth_max ||
	    !avpkt) {
		fprintf(stderr, "Required parameter (vq, limit, min, max, "
			"avpkt) is missing\n");
		return -1;
	}
	if (!burst) {
		burst = (2 * opt.qth_min + opt.qth_max) / (3 * avpkt);
		fprintf(stderr, "GRED: set burst to %u\n", burst);
	}
	if (!rate) {
		get_rate(&rate, "10Mbit");
		fprintf(stderr, "GRED: set bandwidth to 10Mbit\n");
	}
	if ((parm = tc_red_eval_ewma(opt.qth_min, burst, avpkt)) < 0) {
		fprintf(stderr, "GRED: failed to calculate EWMA constant.\n");
		return -1;
	}
	if (parm >= 10)
		fprintf(stderr, "GRED: WARNING. Burst %u seems to be too "
		    "large.\n", burst);
	opt.Wlog = parm;
	if ((parm = tc_red_eval_P(opt.qth_min, opt.qth_max, probability)) < 0) {
		fprintf(stderr, "GRED: failed to calculate probability.\n");
		return -1;
	}
	opt.Plog = parm;
	if ((parm = tc_red_eval_idle_damping(opt.Wlog, avpkt, rate, sbuf)) < 0)
	    {
		fprintf(stderr, "GRED: failed to calculate idle damping "
		    "table.\n");
		return -1;
	}
	opt.Scell_log = parm;

	tail = NLMSG_TAIL(n);
	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
	addattr_l(n, 1024, TCA_GRED_PARMS, &opt, sizeof(opt));
	addattr_l(n, 1024, TCA_GRED_STAB, sbuf, 256);
	max_P = probability * pow(2, 32);
	addattr32(n, 1024, TCA_GRED_MAX_P, max_P);
	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
	return 0;
}
Exemplo n.º 30
0
void TextureButton::_notification(int p_what) {

	switch (p_what) {

		case NOTIFICATION_DRAW: {
			DrawMode draw_mode = get_draw_mode();

			Ref<Texture> texdraw;

			switch (draw_mode) {
				case DRAW_NORMAL: {

					if (normal.is_valid())
						texdraw = normal;
				} break;
				case DRAW_PRESSED: {

					if (pressed.is_null()) {
						if (hover.is_null()) {
							if (normal.is_valid())
								texdraw = normal;
						} else
							texdraw = hover;

					} else
						texdraw = pressed;
				} break;
				case DRAW_HOVER: {

					if (hover.is_null()) {
						if (pressed.is_valid() && is_pressed())
							texdraw = pressed;
						else if (normal.is_valid())
							texdraw = normal;
					} else
						texdraw = hover;
				} break;
				case DRAW_DISABLED: {

					if (disabled.is_null()) {
						if (normal.is_valid())
							texdraw = normal;
					} else
						texdraw = disabled;
				} break;
			}

			if (texdraw.is_valid()) {
				Point2 ofs;
				Size2 size = texdraw->get_size();
				Rect2 tex_regin = Rect2(Point2(), texdraw->get_size());
				bool tile = false;
				if (expand) {
					switch (stretch_mode) {
						case STRETCH_KEEP:
							size = texdraw->get_size();
							break;
						case STRETCH_SCALE:
							size = get_size();
							break;
						case STRETCH_TILE:
							size = get_size();
							tile = true;
							break;
						case STRETCH_KEEP_CENTERED:
							ofs = (get_size() - texdraw->get_size()) / 2;
							size = texdraw->get_size();
							break;
						case STRETCH_KEEP_ASPECT_CENTERED:
						case STRETCH_KEEP_ASPECT: {
							Size2 _size = get_size();
							float tex_width = texdraw->get_width() * _size.height / texdraw->get_height();
							float tex_height = _size.height;

							if (tex_width > _size.width) {
								tex_width = _size.width;
								tex_height = texdraw->get_height() * tex_width / texdraw->get_width();
							}

							if (stretch_mode == STRETCH_KEEP_ASPECT_CENTERED) {
								ofs.x = (_size.width - tex_width) / 2;
								ofs.y = (_size.height - tex_height) / 2;
							}
							size.width = tex_width;
							size.height = tex_height;
						} break;
						case STRETCH_KEEP_ASPECT_COVERED: {
							size = get_size();
							Size2 tex_size = texdraw->get_size();
							Size2 scaleSize(size.width / tex_size.width, size.height / tex_size.height);
							float scale = scaleSize.width > scaleSize.height ? scaleSize.width : scaleSize.height;
							Size2 scaledTexSize = tex_size * scale;
							Point2 ofs = ((scaledTexSize - size) / scale).abs() / 2.0f;
							tex_regin = Rect2(ofs, size / scale);
						} break;
					}
				}
				if (tile)
					draw_texture_rect(texdraw, Rect2(ofs, size), tile);
				else
					draw_texture_rect_region(texdraw, Rect2(ofs, size), tex_regin);
			}
			if (has_focus() && focused.is_valid()) {

				Rect2 drect(Point2(), get_size());
				draw_texture_rect(focused, drect, false);
			};
		} break;
	}
}