mirror of
https://github.com/godotengine/godot.git
synced 2025-12-07 22:00:10 +00:00
Bring that Whole New World to the Old Continent too
Applies the clang-format style to the 2.1 branch as done for master in
5dbf1809c6.
This commit is contained in:
parent
1d418afe86
commit
f8db8a3faa
1308 changed files with 147754 additions and 174357 deletions
|
|
@ -27,25 +27,24 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "base_button.h"
|
||||
#include "button_group.h"
|
||||
#include "os/keyboard.h"
|
||||
#include "print_string.h"
|
||||
#include "button_group.h"
|
||||
#include "scene/scene_string_names.h"
|
||||
#include "scene/main/viewport.h"
|
||||
#include "scene/scene_string_names.h"
|
||||
|
||||
void BaseButton::_input_event(InputEvent p_event) {
|
||||
|
||||
|
||||
if (status.disabled) // no interaction with disabled button
|
||||
return;
|
||||
|
||||
switch(p_event.type) {
|
||||
switch (p_event.type) {
|
||||
|
||||
case InputEvent::MOUSE_BUTTON: {
|
||||
|
||||
const InputEventMouseButton &b=p_event.mouse_button;
|
||||
const InputEventMouseButton &b = p_event.mouse_button;
|
||||
|
||||
if ( status.disabled || b.button_index!=1 )
|
||||
if (status.disabled || b.button_index != 1)
|
||||
return;
|
||||
|
||||
if (status.pressing_button)
|
||||
|
|
@ -59,42 +58,40 @@ void BaseButton::_input_event(InputEvent p_event) {
|
|||
|
||||
if (!toggle_mode) { //mouse press attempt
|
||||
|
||||
status.press_attempt=true;
|
||||
status.pressing_inside=true;
|
||||
status.press_attempt = true;
|
||||
status.pressing_inside = true;
|
||||
|
||||
pressed();
|
||||
if (get_script_instance()) {
|
||||
Variant::CallError ce;
|
||||
get_script_instance()->call(SceneStringNames::get_singleton()->_pressed,NULL,0,ce);
|
||||
get_script_instance()->call(SceneStringNames::get_singleton()->_pressed, NULL, 0, ce);
|
||||
}
|
||||
|
||||
emit_signal("pressed");
|
||||
|
||||
} else {
|
||||
|
||||
status.pressed=!status.pressed;
|
||||
status.pressed = !status.pressed;
|
||||
pressed();
|
||||
if (get_script_instance()) {
|
||||
Variant::CallError ce;
|
||||
get_script_instance()->call(SceneStringNames::get_singleton()->_pressed,NULL,0,ce);
|
||||
get_script_instance()->call(SceneStringNames::get_singleton()->_pressed, NULL, 0, ce);
|
||||
}
|
||||
emit_signal("pressed");
|
||||
|
||||
toggled(status.pressed);
|
||||
emit_signal("toggled",status.pressed);
|
||||
|
||||
emit_signal("toggled", status.pressed);
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
emit_signal("button_up");
|
||||
|
||||
if (status.press_attempt && status.pressing_inside) {
|
||||
// released();
|
||||
// released();
|
||||
emit_signal("released");
|
||||
}
|
||||
status.press_attempt=false;
|
||||
status.press_attempt = false;
|
||||
}
|
||||
update();
|
||||
break;
|
||||
|
|
@ -102,56 +99,52 @@ void BaseButton::_input_event(InputEvent p_event) {
|
|||
|
||||
if (b.pressed) {
|
||||
|
||||
status.press_attempt=true;
|
||||
status.pressing_inside=true;
|
||||
status.press_attempt = true;
|
||||
status.pressing_inside = true;
|
||||
emit_signal("button_down");
|
||||
|
||||
} else {
|
||||
|
||||
emit_signal("button_up");
|
||||
|
||||
if (status.press_attempt &&status.pressing_inside) {
|
||||
if (status.press_attempt && status.pressing_inside) {
|
||||
|
||||
if (!toggle_mode) { //mouse press attempt
|
||||
|
||||
pressed();
|
||||
if (get_script_instance()) {
|
||||
Variant::CallError ce;
|
||||
get_script_instance()->call(SceneStringNames::get_singleton()->_pressed,NULL,0,ce);
|
||||
get_script_instance()->call(SceneStringNames::get_singleton()->_pressed, NULL, 0, ce);
|
||||
}
|
||||
|
||||
emit_signal("pressed");
|
||||
|
||||
} else {
|
||||
|
||||
status.pressed=!status.pressed;
|
||||
status.pressed = !status.pressed;
|
||||
|
||||
pressed();
|
||||
emit_signal("pressed");
|
||||
|
||||
toggled(status.pressed);
|
||||
emit_signal("toggled",status.pressed);
|
||||
emit_signal("toggled", status.pressed);
|
||||
if (get_script_instance()) {
|
||||
get_script_instance()->call(SceneStringNames::get_singleton()->_toggled,status.pressed);
|
||||
get_script_instance()->call(SceneStringNames::get_singleton()->_toggled, status.pressed);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
status.press_attempt=false;
|
||||
|
||||
status.press_attempt = false;
|
||||
}
|
||||
|
||||
update();
|
||||
} break;
|
||||
case InputEvent::MOUSE_MOTION: {
|
||||
|
||||
if (status.press_attempt && status.pressing_button==0) {
|
||||
bool last_press_inside=status.pressing_inside;
|
||||
status.pressing_inside=has_point(Point2(p_event.mouse_motion.x,p_event.mouse_motion.y));
|
||||
if (last_press_inside!=status.pressing_inside)
|
||||
if (status.press_attempt && status.pressing_button == 0) {
|
||||
bool last_press_inside = status.pressing_inside;
|
||||
status.pressing_inside = has_point(Point2(p_event.mouse_motion.x, p_event.mouse_motion.y));
|
||||
if (last_press_inside != status.pressing_inside)
|
||||
update();
|
||||
}
|
||||
} break;
|
||||
|
|
@ -159,7 +152,6 @@ void BaseButton::_input_event(InputEvent p_event) {
|
|||
case InputEvent::JOYSTICK_BUTTON:
|
||||
case InputEvent::KEY: {
|
||||
|
||||
|
||||
if (p_event.is_echo()) {
|
||||
break;
|
||||
}
|
||||
|
|
@ -168,7 +160,7 @@ void BaseButton::_input_event(InputEvent p_event) {
|
|||
break;
|
||||
}
|
||||
|
||||
if (status.press_attempt && status.pressing_button==0) {
|
||||
if (status.press_attempt && status.pressing_button == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -177,8 +169,8 @@ void BaseButton::_input_event(InputEvent p_event) {
|
|||
if (p_event.is_pressed()) {
|
||||
|
||||
status.pressing_button++;
|
||||
status.press_attempt=true;
|
||||
status.pressing_inside=true;
|
||||
status.press_attempt = true;
|
||||
status.pressing_inside = true;
|
||||
emit_signal("button_down");
|
||||
|
||||
} else if (status.press_attempt) {
|
||||
|
|
@ -189,8 +181,8 @@ void BaseButton::_input_event(InputEvent p_event) {
|
|||
if (status.pressing_button)
|
||||
break;
|
||||
|
||||
status.press_attempt=false;
|
||||
status.pressing_inside=false;
|
||||
status.press_attempt = false;
|
||||
status.pressing_inside = false;
|
||||
|
||||
emit_signal("button_up");
|
||||
|
||||
|
|
@ -200,92 +192,89 @@ void BaseButton::_input_event(InputEvent p_event) {
|
|||
emit_signal("pressed");
|
||||
} else {
|
||||
|
||||
status.pressed=!status.pressed;
|
||||
status.pressed = !status.pressed;
|
||||
|
||||
pressed();
|
||||
emit_signal("pressed");
|
||||
|
||||
toggled(status.pressed);
|
||||
if (get_script_instance()) {
|
||||
get_script_instance()->call(SceneStringNames::get_singleton()->_toggled,status.pressed);
|
||||
get_script_instance()->call(SceneStringNames::get_singleton()->_toggled, status.pressed);
|
||||
}
|
||||
emit_signal("toggled",status.pressed);
|
||||
emit_signal("toggled", status.pressed);
|
||||
}
|
||||
}
|
||||
|
||||
accept_event();
|
||||
update();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void BaseButton::_notification(int p_what) {
|
||||
|
||||
if (p_what == NOTIFICATION_MOUSE_ENTER) {
|
||||
|
||||
if (p_what==NOTIFICATION_MOUSE_ENTER) {
|
||||
|
||||
status.hovering=true;
|
||||
status.hovering = true;
|
||||
update();
|
||||
}
|
||||
|
||||
if (p_what==NOTIFICATION_MOUSE_EXIT) {
|
||||
status.hovering=false;
|
||||
if (p_what == NOTIFICATION_MOUSE_EXIT) {
|
||||
status.hovering = false;
|
||||
update();
|
||||
}
|
||||
if (p_what==NOTIFICATION_DRAG_BEGIN) {
|
||||
if (p_what == NOTIFICATION_DRAG_BEGIN) {
|
||||
|
||||
if (status.press_attempt) {
|
||||
status.press_attempt=false;
|
||||
status.pressing_button=0;
|
||||
status.press_attempt = false;
|
||||
status.pressing_button = 0;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
if (p_what==NOTIFICATION_FOCUS_ENTER) {
|
||||
|
||||
status.hovering=true;
|
||||
|
||||
if (p_what == NOTIFICATION_FOCUS_ENTER) {
|
||||
|
||||
status.hovering = true;
|
||||
update();
|
||||
}
|
||||
|
||||
if (p_what==NOTIFICATION_FOCUS_EXIT) {
|
||||
if (p_what == NOTIFICATION_FOCUS_EXIT) {
|
||||
|
||||
if (status.pressing_button && status.press_attempt) {
|
||||
status.press_attempt=false;
|
||||
status.pressing_button=0;
|
||||
status.hovering=false;
|
||||
status.press_attempt = false;
|
||||
status.pressing_button = 0;
|
||||
status.hovering = false;
|
||||
update();
|
||||
} else if (status.hovering) {
|
||||
status.hovering=false;
|
||||
status.hovering = false;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
if (p_what==NOTIFICATION_ENTER_TREE) {
|
||||
if (p_what == NOTIFICATION_ENTER_TREE) {
|
||||
|
||||
CanvasItem *ci=this;
|
||||
while(ci) {
|
||||
CanvasItem *ci = this;
|
||||
while (ci) {
|
||||
|
||||
ButtonGroup *bg = ci->cast_to<ButtonGroup>();
|
||||
if (bg) {
|
||||
|
||||
group=bg;
|
||||
group = bg;
|
||||
group->_add_button(this);
|
||||
}
|
||||
|
||||
ci=ci->get_parent_item();
|
||||
ci = ci->get_parent_item();
|
||||
}
|
||||
}
|
||||
|
||||
if (p_what==NOTIFICATION_EXIT_TREE) {
|
||||
if (p_what == NOTIFICATION_EXIT_TREE) {
|
||||
|
||||
if (group)
|
||||
group->_remove_button(this);
|
||||
}
|
||||
|
||||
if (p_what==NOTIFICATION_VISIBILITY_CHANGED && !is_visible()) {
|
||||
if (p_what == NOTIFICATION_VISIBILITY_CHANGED && !is_visible()) {
|
||||
|
||||
if (!toggle_mode) {
|
||||
status.pressed = false;
|
||||
|
|
@ -306,11 +295,9 @@ void BaseButton::pressed() {
|
|||
void BaseButton::toggled(bool p_pressed) {
|
||||
|
||||
if (get_script_instance())
|
||||
get_script_instance()->call("toggled",p_pressed);
|
||||
|
||||
get_script_instance()->call("toggled", p_pressed);
|
||||
}
|
||||
|
||||
|
||||
void BaseButton::set_disabled(bool p_disabled) {
|
||||
|
||||
status.disabled = p_disabled;
|
||||
|
|
@ -331,21 +318,21 @@ void BaseButton::set_pressed(bool p_pressed) {
|
|||
|
||||
if (!toggle_mode)
|
||||
return;
|
||||
if (status.pressed==p_pressed)
|
||||
if (status.pressed == p_pressed)
|
||||
return;
|
||||
_change_notify("pressed");
|
||||
status.pressed=p_pressed;
|
||||
status.pressed = p_pressed;
|
||||
update();
|
||||
}
|
||||
|
||||
bool BaseButton::is_pressing() const{
|
||||
bool BaseButton::is_pressing() const {
|
||||
|
||||
return status.press_attempt;
|
||||
}
|
||||
|
||||
bool BaseButton::is_pressed() const {
|
||||
|
||||
return toggle_mode?status.pressed:status.press_attempt;
|
||||
return toggle_mode ? status.pressed : status.press_attempt;
|
||||
}
|
||||
|
||||
bool BaseButton::is_hovered() const {
|
||||
|
|
@ -360,8 +347,7 @@ BaseButton::DrawMode BaseButton::get_draw_mode() const {
|
|||
};
|
||||
|
||||
//print_line("press attempt: "+itos(status.press_attempt)+" hover: "+itos(status.hovering)+" pressed: "+itos(status.pressed));
|
||||
if (status.press_attempt==false && status.hovering && !status.pressed) {
|
||||
|
||||
if (status.press_attempt == false && status.hovering && !status.pressed) {
|
||||
|
||||
return DRAW_HOVER;
|
||||
} else {
|
||||
|
|
@ -370,12 +356,12 @@ BaseButton::DrawMode BaseButton::get_draw_mode() const {
|
|||
bool pressing;
|
||||
if (status.press_attempt) {
|
||||
|
||||
pressing=status.pressing_inside;
|
||||
pressing = status.pressing_inside;
|
||||
if (status.pressed)
|
||||
pressing=!pressing;
|
||||
pressing = !pressing;
|
||||
} else {
|
||||
|
||||
pressing=status.pressed;
|
||||
pressing = status.pressed;
|
||||
}
|
||||
|
||||
if (pressing)
|
||||
|
|
@ -389,7 +375,7 @@ BaseButton::DrawMode BaseButton::get_draw_mode() const {
|
|||
|
||||
void BaseButton::set_toggle_mode(bool p_on) {
|
||||
|
||||
toggle_mode=p_on;
|
||||
toggle_mode = p_on;
|
||||
}
|
||||
|
||||
bool BaseButton::is_toggle_mode() const {
|
||||
|
|
@ -399,7 +385,7 @@ bool BaseButton::is_toggle_mode() const {
|
|||
|
||||
void BaseButton::set_click_on_press(bool p_click_on_press) {
|
||||
|
||||
status.click_on_press=p_click_on_press;
|
||||
status.click_on_press = p_click_on_press;
|
||||
}
|
||||
|
||||
bool BaseButton::get_click_on_press() const {
|
||||
|
|
@ -411,7 +397,7 @@ void BaseButton::set_enabled_focus_mode(FocusMode p_mode) {
|
|||
|
||||
enabled_focus_mode = p_mode;
|
||||
if (!status.disabled) {
|
||||
set_focus_mode( p_mode );
|
||||
set_focus_mode(p_mode);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -420,16 +406,16 @@ Control::FocusMode BaseButton::get_enabled_focus_mode() const {
|
|||
return enabled_focus_mode;
|
||||
}
|
||||
|
||||
void BaseButton::set_shortcut(const Ref<ShortCut>& p_shortcut) {
|
||||
void BaseButton::set_shortcut(const Ref<ShortCut> &p_shortcut) {
|
||||
|
||||
if (shortcut.is_null() == p_shortcut.is_null())
|
||||
return;
|
||||
|
||||
shortcut=p_shortcut;
|
||||
shortcut = p_shortcut;
|
||||
set_process_unhandled_input(shortcut.is_valid());
|
||||
}
|
||||
|
||||
Ref<ShortCut> BaseButton:: get_shortcut() const {
|
||||
Ref<ShortCut> BaseButton::get_shortcut() const {
|
||||
return shortcut;
|
||||
}
|
||||
|
||||
|
|
@ -442,21 +428,21 @@ void BaseButton::_unhandled_input(InputEvent p_event) {
|
|||
|
||||
if (is_toggle_mode()) {
|
||||
set_pressed(!is_pressed());
|
||||
emit_signal("toggled",is_pressed());
|
||||
emit_signal("toggled", is_pressed());
|
||||
}
|
||||
|
||||
emit_signal("pressed");
|
||||
}
|
||||
}
|
||||
|
||||
String BaseButton::get_tooltip(const Point2& p_pos) const {
|
||||
String BaseButton::get_tooltip(const Point2 &p_pos) const {
|
||||
|
||||
String tooltip=Control::get_tooltip(p_pos);
|
||||
String tooltip = Control::get_tooltip(p_pos);
|
||||
if (shortcut.is_valid() && shortcut->is_valid()) {
|
||||
if (tooltip.find("$sc")!=-1) {
|
||||
tooltip=tooltip.replace_first("$sc","("+shortcut->get_as_text()+")");
|
||||
if (tooltip.find("$sc") != -1) {
|
||||
tooltip = tooltip.replace_first("$sc", "(" + shortcut->get_as_text() + ")");
|
||||
} else {
|
||||
tooltip+=" ("+shortcut->get_as_text()+")";
|
||||
tooltip += " (" + shortcut->get_as_text() + ")";
|
||||
}
|
||||
}
|
||||
return tooltip;
|
||||
|
|
@ -464,65 +450,58 @@ String BaseButton::get_tooltip(const Point2& p_pos) const {
|
|||
|
||||
void BaseButton::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("_input_event"),&BaseButton::_input_event);
|
||||
ObjectTypeDB::bind_method(_MD("_unhandled_input"),&BaseButton::_unhandled_input);
|
||||
ObjectTypeDB::bind_method(_MD("set_pressed","pressed"),&BaseButton::set_pressed);
|
||||
ObjectTypeDB::bind_method(_MD("is_pressed"),&BaseButton::is_pressed);
|
||||
ObjectTypeDB::bind_method(_MD("is_hovered"),&BaseButton::is_hovered);
|
||||
ObjectTypeDB::bind_method(_MD("set_toggle_mode","enabled"),&BaseButton::set_toggle_mode);
|
||||
ObjectTypeDB::bind_method(_MD("is_toggle_mode"),&BaseButton::is_toggle_mode);
|
||||
ObjectTypeDB::bind_method(_MD("set_disabled","disabled"),&BaseButton::set_disabled);
|
||||
ObjectTypeDB::bind_method(_MD("is_disabled"),&BaseButton::is_disabled);
|
||||
ObjectTypeDB::bind_method(_MD("set_click_on_press","enable"),&BaseButton::set_click_on_press);
|
||||
ObjectTypeDB::bind_method(_MD("get_click_on_press"),&BaseButton::get_click_on_press);
|
||||
ObjectTypeDB::bind_method(_MD("get_draw_mode"),&BaseButton::get_draw_mode);
|
||||
ObjectTypeDB::bind_method(_MD("set_enabled_focus_mode","mode"),&BaseButton::set_enabled_focus_mode);
|
||||
ObjectTypeDB::bind_method(_MD("get_enabled_focus_mode"),&BaseButton::get_enabled_focus_mode);
|
||||
ObjectTypeDB::bind_method(_MD("set_shortcut","shortcut"),&BaseButton::set_shortcut);
|
||||
ObjectTypeDB::bind_method(_MD("get_shortcut"),&BaseButton::get_shortcut);
|
||||
ObjectTypeDB::bind_method(_MD("_input_event"), &BaseButton::_input_event);
|
||||
ObjectTypeDB::bind_method(_MD("_unhandled_input"), &BaseButton::_unhandled_input);
|
||||
ObjectTypeDB::bind_method(_MD("set_pressed", "pressed"), &BaseButton::set_pressed);
|
||||
ObjectTypeDB::bind_method(_MD("is_pressed"), &BaseButton::is_pressed);
|
||||
ObjectTypeDB::bind_method(_MD("is_hovered"), &BaseButton::is_hovered);
|
||||
ObjectTypeDB::bind_method(_MD("set_toggle_mode", "enabled"), &BaseButton::set_toggle_mode);
|
||||
ObjectTypeDB::bind_method(_MD("is_toggle_mode"), &BaseButton::is_toggle_mode);
|
||||
ObjectTypeDB::bind_method(_MD("set_disabled", "disabled"), &BaseButton::set_disabled);
|
||||
ObjectTypeDB::bind_method(_MD("is_disabled"), &BaseButton::is_disabled);
|
||||
ObjectTypeDB::bind_method(_MD("set_click_on_press", "enable"), &BaseButton::set_click_on_press);
|
||||
ObjectTypeDB::bind_method(_MD("get_click_on_press"), &BaseButton::get_click_on_press);
|
||||
ObjectTypeDB::bind_method(_MD("get_draw_mode"), &BaseButton::get_draw_mode);
|
||||
ObjectTypeDB::bind_method(_MD("set_enabled_focus_mode", "mode"), &BaseButton::set_enabled_focus_mode);
|
||||
ObjectTypeDB::bind_method(_MD("get_enabled_focus_mode"), &BaseButton::get_enabled_focus_mode);
|
||||
ObjectTypeDB::bind_method(_MD("set_shortcut", "shortcut"), &BaseButton::set_shortcut);
|
||||
ObjectTypeDB::bind_method(_MD("get_shortcut"), &BaseButton::get_shortcut);
|
||||
|
||||
BIND_VMETHOD(MethodInfo("_pressed"));
|
||||
BIND_VMETHOD(MethodInfo("_toggled",PropertyInfo(Variant::BOOL,"pressed")));
|
||||
BIND_VMETHOD(MethodInfo("_toggled", PropertyInfo(Variant::BOOL, "pressed")));
|
||||
|
||||
ADD_SIGNAL( MethodInfo("pressed" ) );
|
||||
ADD_SIGNAL( MethodInfo("released" ) );
|
||||
ADD_SIGNAL( MethodInfo("button_up") );
|
||||
ADD_SIGNAL( MethodInfo("button_down") );
|
||||
ADD_SIGNAL( MethodInfo("toggled", PropertyInfo( Variant::BOOL,"pressed") ) );
|
||||
ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "disabled"), _SCS("set_disabled"), _SCS("is_disabled"));
|
||||
ADD_PROPERTY( PropertyInfo( Variant::BOOL, "toggle_mode"), _SCS("set_toggle_mode"), _SCS("is_toggle_mode"));
|
||||
ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "is_pressed"), _SCS("set_pressed"), _SCS("is_pressed"));
|
||||
ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "click_on_press"), _SCS("set_click_on_press"), _SCS("get_click_on_press"));
|
||||
ADD_PROPERTY( PropertyInfo( Variant::INT,"enabled_focus_mode", PROPERTY_HINT_ENUM, "None,Click,All" ), _SCS("set_enabled_focus_mode"), _SCS("get_enabled_focus_mode") );
|
||||
ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "shortcut",PROPERTY_HINT_RESOURCE_TYPE,"ShortCut"), _SCS("set_shortcut"), _SCS("get_shortcut"));
|
||||
|
||||
|
||||
BIND_CONSTANT( DRAW_NORMAL );
|
||||
BIND_CONSTANT( DRAW_PRESSED );
|
||||
BIND_CONSTANT( DRAW_HOVER );
|
||||
BIND_CONSTANT( DRAW_DISABLED );
|
||||
ADD_SIGNAL(MethodInfo("pressed"));
|
||||
ADD_SIGNAL(MethodInfo("released"));
|
||||
ADD_SIGNAL(MethodInfo("button_up"));
|
||||
ADD_SIGNAL(MethodInfo("button_down"));
|
||||
ADD_SIGNAL(MethodInfo("toggled", PropertyInfo(Variant::BOOL, "pressed")));
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "disabled"), _SCS("set_disabled"), _SCS("is_disabled"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "toggle_mode"), _SCS("set_toggle_mode"), _SCS("is_toggle_mode"));
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "is_pressed"), _SCS("set_pressed"), _SCS("is_pressed"));
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "click_on_press"), _SCS("set_click_on_press"), _SCS("get_click_on_press"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "enabled_focus_mode", PROPERTY_HINT_ENUM, "None,Click,All"), _SCS("set_enabled_focus_mode"), _SCS("get_enabled_focus_mode"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shortcut", PROPERTY_HINT_RESOURCE_TYPE, "ShortCut"), _SCS("set_shortcut"), _SCS("get_shortcut"));
|
||||
|
||||
BIND_CONSTANT(DRAW_NORMAL);
|
||||
BIND_CONSTANT(DRAW_PRESSED);
|
||||
BIND_CONSTANT(DRAW_HOVER);
|
||||
BIND_CONSTANT(DRAW_DISABLED);
|
||||
}
|
||||
|
||||
BaseButton::BaseButton() {
|
||||
|
||||
toggle_mode=false;
|
||||
status.pressed=false;
|
||||
status.press_attempt=false;
|
||||
status.hovering=false;
|
||||
status.pressing_inside=false;
|
||||
toggle_mode = false;
|
||||
status.pressed = false;
|
||||
status.press_attempt = false;
|
||||
status.hovering = false;
|
||||
status.pressing_inside = false;
|
||||
status.disabled = false;
|
||||
status.click_on_press=false;
|
||||
status.pressing_button=0;
|
||||
set_focus_mode( FOCUS_ALL );
|
||||
status.click_on_press = false;
|
||||
status.pressing_button = 0;
|
||||
set_focus_mode(FOCUS_ALL);
|
||||
enabled_focus_mode = FOCUS_ALL;
|
||||
group=NULL;
|
||||
|
||||
|
||||
group = NULL;
|
||||
}
|
||||
|
||||
BaseButton::~BaseButton()
|
||||
{
|
||||
BaseButton::~BaseButton() {
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -34,12 +34,11 @@
|
|||
@author Juan Linietsky <reduzio@gmail.com>
|
||||
*/
|
||||
|
||||
|
||||
class ButtonGroup;
|
||||
|
||||
class BaseButton : public Control {
|
||||
|
||||
OBJ_TYPE( BaseButton, Control );
|
||||
OBJ_TYPE(BaseButton, Control);
|
||||
|
||||
bool toggle_mode;
|
||||
FocusMode enabled_focus_mode;
|
||||
|
|
@ -58,15 +57,9 @@ class BaseButton : public Control {
|
|||
|
||||
} status;
|
||||
|
||||
|
||||
ButtonGroup *group;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
|
||||
|
||||
virtual void pressed();
|
||||
virtual void toggled(bool p_pressed);
|
||||
static void _bind_methods();
|
||||
|
|
@ -75,7 +68,6 @@ protected:
|
|||
void _notification(int p_what);
|
||||
|
||||
public:
|
||||
|
||||
enum DrawMode {
|
||||
DRAW_NORMAL,
|
||||
DRAW_PRESSED,
|
||||
|
|
@ -104,16 +96,15 @@ public:
|
|||
void set_enabled_focus_mode(FocusMode p_mode);
|
||||
FocusMode get_enabled_focus_mode() const;
|
||||
|
||||
void set_shortcut(const Ref<ShortCut>& p_shortcut);
|
||||
void set_shortcut(const Ref<ShortCut> &p_shortcut);
|
||||
Ref<ShortCut> get_shortcut() const;
|
||||
|
||||
virtual String get_tooltip(const Point2& p_pos) const;
|
||||
virtual String get_tooltip(const Point2 &p_pos) const;
|
||||
|
||||
BaseButton();
|
||||
~BaseButton();
|
||||
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST( BaseButton::DrawMode );
|
||||
VARIANT_ENUM_CAST(BaseButton::DrawMode);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "box_container.h"
|
||||
#include "margin_container.h"
|
||||
#include "label.h"
|
||||
#include "margin_container.h"
|
||||
|
||||
struct _MinSizeCache {
|
||||
|
||||
|
|
@ -41,110 +41,105 @@ void BoxContainer::_resort() {
|
|||
|
||||
/** First pass, determine minimum size AND amount of stretchable elements */
|
||||
|
||||
Size2i new_size = get_size();
|
||||
|
||||
Size2i new_size=get_size();
|
||||
int sep = get_constant("separation"); //,vertical?"VBoxContainer":"HBoxContainer");
|
||||
|
||||
int sep=get_constant("separation");//,vertical?"VBoxContainer":"HBoxContainer");
|
||||
bool first = true;
|
||||
int children_count = 0;
|
||||
int stretch_min = 0;
|
||||
int stretch_avail = 0;
|
||||
float stretch_ratio_total = 0;
|
||||
Map<Control *, _MinSizeCache> min_size_cache;
|
||||
|
||||
bool first=true;
|
||||
int children_count=0;
|
||||
int stretch_min=0;
|
||||
int stretch_avail=0;
|
||||
float stretch_ratio_total=0;
|
||||
Map<Control*,_MinSizeCache> min_size_cache;
|
||||
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
Control *c=get_child(i)->cast_to<Control>();
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c || !c->is_visible())
|
||||
continue;
|
||||
if (c->is_set_as_toplevel())
|
||||
continue;
|
||||
|
||||
Size2i size=c->get_combined_minimum_size();
|
||||
Size2i size = c->get_combined_minimum_size();
|
||||
_MinSizeCache msc;
|
||||
|
||||
if (vertical) { /* VERTICAL */
|
||||
stretch_min+=size.height;
|
||||
msc.min_size=size.height;
|
||||
msc.will_stretch=c->get_v_size_flags() & SIZE_EXPAND;
|
||||
stretch_min += size.height;
|
||||
msc.min_size = size.height;
|
||||
msc.will_stretch = c->get_v_size_flags() & SIZE_EXPAND;
|
||||
|
||||
} else { /* HORIZONTAL */
|
||||
stretch_min+=size.width;
|
||||
msc.min_size=size.width;
|
||||
msc.will_stretch=c->get_h_size_flags() & SIZE_EXPAND;
|
||||
stretch_min += size.width;
|
||||
msc.min_size = size.width;
|
||||
msc.will_stretch = c->get_h_size_flags() & SIZE_EXPAND;
|
||||
}
|
||||
|
||||
if (msc.will_stretch) {
|
||||
stretch_avail+=msc.min_size;
|
||||
stretch_ratio_total+=c->get_stretch_ratio();
|
||||
stretch_avail += msc.min_size;
|
||||
stretch_ratio_total += c->get_stretch_ratio();
|
||||
}
|
||||
msc.final_size=msc.min_size;
|
||||
min_size_cache[c]=msc;
|
||||
msc.final_size = msc.min_size;
|
||||
min_size_cache[c] = msc;
|
||||
children_count++;
|
||||
}
|
||||
|
||||
if (children_count==0)
|
||||
if (children_count == 0)
|
||||
return;
|
||||
|
||||
int stretch_max = (vertical? new_size.height : new_size.width ) - (children_count-1) * sep;
|
||||
int stretch_max = (vertical ? new_size.height : new_size.width) - (children_count - 1) * sep;
|
||||
int stretch_diff = stretch_max - stretch_min;
|
||||
if (stretch_diff<0) {
|
||||
if (stretch_diff < 0) {
|
||||
//avoid negative stretch space
|
||||
stretch_max=stretch_min;
|
||||
stretch_diff=0;
|
||||
stretch_max = stretch_min;
|
||||
stretch_diff = 0;
|
||||
}
|
||||
|
||||
stretch_avail+=stretch_diff; //available stretch space.
|
||||
stretch_avail += stretch_diff; //available stretch space.
|
||||
/** Second, pass sucessively to discard elements that can't be stretched, this will run while stretchable
|
||||
elements exist */
|
||||
|
||||
|
||||
bool has_stretched = false;
|
||||
while(stretch_ratio_total>0) { // first of all, dont even be here if no stretchable objects exist
|
||||
while (stretch_ratio_total > 0) { // first of all, dont even be here if no stretchable objects exist
|
||||
|
||||
has_stretched = true;
|
||||
bool refit_successful=true; //assume refit-test will go well
|
||||
bool refit_successful = true; //assume refit-test will go well
|
||||
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
|
||||
Control *c=get_child(i)->cast_to<Control>();
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c || !c->is_visible())
|
||||
continue;
|
||||
if (c->is_set_as_toplevel())
|
||||
continue;
|
||||
|
||||
ERR_FAIL_COND(!min_size_cache.has(c));
|
||||
_MinSizeCache &msc=min_size_cache[c];
|
||||
_MinSizeCache &msc = min_size_cache[c];
|
||||
|
||||
if (msc.will_stretch) { //wants to stretch
|
||||
//let's see if it can really stretch
|
||||
|
||||
int final_pixel_size=stretch_avail * c->get_stretch_ratio() / stretch_ratio_total;
|
||||
if (final_pixel_size<msc.min_size) {
|
||||
int final_pixel_size = stretch_avail * c->get_stretch_ratio() / stretch_ratio_total;
|
||||
if (final_pixel_size < msc.min_size) {
|
||||
//if available stretching area is too small for widget,
|
||||
//then remove it from stretching area
|
||||
msc.will_stretch=false;
|
||||
stretch_ratio_total-=c->get_stretch_ratio();
|
||||
refit_successful=false;
|
||||
stretch_avail-=msc.min_size;
|
||||
msc.final_size=msc.min_size;
|
||||
msc.will_stretch = false;
|
||||
stretch_ratio_total -= c->get_stretch_ratio();
|
||||
refit_successful = false;
|
||||
stretch_avail -= msc.min_size;
|
||||
msc.final_size = msc.min_size;
|
||||
break;
|
||||
} else {
|
||||
msc.final_size=final_pixel_size;
|
||||
msc.final_size = final_pixel_size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (refit_successful) //uf refit went well, break
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/** Final pass, draw and stretch elements **/
|
||||
|
||||
|
||||
int ofs=0;
|
||||
int ofs = 0;
|
||||
if (!has_stretched) {
|
||||
switch (align) {
|
||||
case ALIGN_BEGIN:
|
||||
|
|
@ -158,70 +153,64 @@ void BoxContainer::_resort() {
|
|||
}
|
||||
}
|
||||
|
||||
first=true;
|
||||
int idx=0;
|
||||
first = true;
|
||||
int idx = 0;
|
||||
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
|
||||
Control *c=get_child(i)->cast_to<Control>();
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c || !c->is_visible())
|
||||
continue;
|
||||
if (c->is_set_as_toplevel())
|
||||
continue;
|
||||
|
||||
_MinSizeCache &msc=min_size_cache[c];
|
||||
|
||||
_MinSizeCache &msc = min_size_cache[c];
|
||||
|
||||
if (first)
|
||||
first=false;
|
||||
first = false;
|
||||
else
|
||||
ofs+=sep;
|
||||
ofs += sep;
|
||||
|
||||
int from=ofs;
|
||||
int to=ofs+msc.final_size;
|
||||
int from = ofs;
|
||||
int to = ofs + msc.final_size;
|
||||
|
||||
|
||||
if (msc.will_stretch && idx==children_count-1) {
|
||||
if (msc.will_stretch && idx == children_count - 1) {
|
||||
//adjust so the last one always fits perfect
|
||||
//compensating for numerical imprecision
|
||||
|
||||
to=vertical?new_size.height:new_size.width;
|
||||
|
||||
to = vertical ? new_size.height : new_size.width;
|
||||
}
|
||||
|
||||
int size=to-from;
|
||||
int size = to - from;
|
||||
|
||||
Rect2 rect;
|
||||
|
||||
if (vertical) {
|
||||
|
||||
rect=Rect2(0,from,new_size.width,size);
|
||||
rect = Rect2(0, from, new_size.width, size);
|
||||
} else {
|
||||
|
||||
rect=Rect2(from,0,size,new_size.height);
|
||||
|
||||
rect = Rect2(from, 0, size, new_size.height);
|
||||
}
|
||||
|
||||
fit_child_in_rect(c,rect);
|
||||
fit_child_in_rect(c, rect);
|
||||
|
||||
ofs=to;
|
||||
ofs = to;
|
||||
idx++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Size2 BoxContainer::get_minimum_size() const {
|
||||
|
||||
|
||||
/* Calculate MINIMUM SIZE */
|
||||
|
||||
Size2i minimum;
|
||||
int sep=get_constant("separation");//,vertical?"VBoxContainer":"HBoxContainer");
|
||||
int sep = get_constant("separation"); //,vertical?"VBoxContainer":"HBoxContainer");
|
||||
|
||||
bool first=true;
|
||||
bool first = true;
|
||||
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
Control *c=get_child(i)->cast_to<Control>();
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c)
|
||||
continue;
|
||||
if (c->is_set_as_toplevel())
|
||||
|
|
@ -231,27 +220,26 @@ Size2 BoxContainer::get_minimum_size() const {
|
|||
continue;
|
||||
}
|
||||
|
||||
Size2i size=c->get_combined_minimum_size();
|
||||
Size2i size = c->get_combined_minimum_size();
|
||||
|
||||
if (vertical) { /* VERTICAL */
|
||||
|
||||
if ( size.width > minimum.width ) {
|
||||
minimum.width=size.width;
|
||||
if (size.width > minimum.width) {
|
||||
minimum.width = size.width;
|
||||
}
|
||||
|
||||
minimum.height+=size.height+(first?0:sep);
|
||||
minimum.height += size.height + (first ? 0 : sep);
|
||||
|
||||
} else { /* HORIZONTAL */
|
||||
|
||||
if ( size.height > minimum.height ) {
|
||||
minimum.height=size.height;
|
||||
if (size.height > minimum.height) {
|
||||
minimum.height = size.height;
|
||||
}
|
||||
|
||||
minimum.width+=size.width+(first?0:sep);
|
||||
|
||||
minimum.width += size.width + (first ? 0 : sep);
|
||||
}
|
||||
|
||||
first=false;
|
||||
first = false;
|
||||
}
|
||||
|
||||
return minimum;
|
||||
|
|
@ -259,7 +247,7 @@ Size2 BoxContainer::get_minimum_size() const {
|
|||
|
||||
void BoxContainer::_notification(int p_what) {
|
||||
|
||||
switch(p_what) {
|
||||
switch (p_what) {
|
||||
|
||||
case NOTIFICATION_SORT_CHILDREN: {
|
||||
|
||||
|
|
@ -279,7 +267,7 @@ BoxContainer::AlignMode BoxContainer::get_alignment() const {
|
|||
|
||||
void BoxContainer::add_spacer(bool p_begin) {
|
||||
|
||||
Control *c = memnew( Control );
|
||||
Control *c = memnew(Control);
|
||||
c->set_stop_mouse(false);
|
||||
if (vertical)
|
||||
c->set_v_size_flags(SIZE_EXPAND_FILL);
|
||||
|
|
@ -288,37 +276,36 @@ void BoxContainer::add_spacer(bool p_begin) {
|
|||
|
||||
add_child(c);
|
||||
if (p_begin)
|
||||
move_child(c,0);
|
||||
move_child(c, 0);
|
||||
}
|
||||
|
||||
BoxContainer::BoxContainer(bool p_vertical) {
|
||||
|
||||
vertical=p_vertical;
|
||||
vertical = p_vertical;
|
||||
align = ALIGN_BEGIN;
|
||||
// set_ignore_mouse(true);
|
||||
// set_ignore_mouse(true);
|
||||
set_stop_mouse(false);
|
||||
}
|
||||
|
||||
void BoxContainer::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("add_spacer","begin"),&BoxContainer::add_spacer);
|
||||
ObjectTypeDB::bind_method(_MD("get_alignment"),&BoxContainer::get_alignment);
|
||||
ObjectTypeDB::bind_method(_MD("set_alignment","alignment"),&BoxContainer::set_alignment);
|
||||
ObjectTypeDB::bind_method(_MD("add_spacer", "begin"), &BoxContainer::add_spacer);
|
||||
ObjectTypeDB::bind_method(_MD("get_alignment"), &BoxContainer::get_alignment);
|
||||
ObjectTypeDB::bind_method(_MD("set_alignment", "alignment"), &BoxContainer::set_alignment);
|
||||
|
||||
BIND_CONSTANT( ALIGN_BEGIN );
|
||||
BIND_CONSTANT( ALIGN_CENTER );
|
||||
BIND_CONSTANT( ALIGN_END );
|
||||
|
||||
ADD_PROPERTY( PropertyInfo(Variant::INT,"alignment", PROPERTY_HINT_ENUM, "Begin,Center,End"), _SCS("set_alignment"),_SCS("get_alignment") );
|
||||
BIND_CONSTANT(ALIGN_BEGIN);
|
||||
BIND_CONSTANT(ALIGN_CENTER);
|
||||
BIND_CONSTANT(ALIGN_END);
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "alignment", PROPERTY_HINT_ENUM, "Begin,Center,End"), _SCS("set_alignment"), _SCS("get_alignment"));
|
||||
}
|
||||
|
||||
MarginContainer* VBoxContainer::add_margin_child(const String& p_label,Control *p_control,bool p_expand) {
|
||||
MarginContainer *VBoxContainer::add_margin_child(const String &p_label, Control *p_control, bool p_expand) {
|
||||
|
||||
Label *l = memnew( Label );
|
||||
Label *l = memnew(Label);
|
||||
l->set_text(p_label);
|
||||
add_child(l);
|
||||
MarginContainer *mc = memnew( MarginContainer );
|
||||
MarginContainer *mc = memnew(MarginContainer);
|
||||
mc->add_child(p_control);
|
||||
add_child(mc);
|
||||
if (p_expand)
|
||||
|
|
|
|||
|
|
@ -33,10 +33,9 @@
|
|||
|
||||
class BoxContainer : public Container {
|
||||
|
||||
OBJ_TYPE(BoxContainer,Container);
|
||||
OBJ_TYPE(BoxContainer, Container);
|
||||
|
||||
public:
|
||||
|
||||
enum AlignMode {
|
||||
ALIGN_BEGIN,
|
||||
ALIGN_CENTER,
|
||||
|
|
@ -48,44 +47,42 @@ private:
|
|||
AlignMode align;
|
||||
|
||||
void _resort();
|
||||
protected:
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
|
||||
static void _bind_methods();
|
||||
public:
|
||||
|
||||
void add_spacer(bool p_begin=false);
|
||||
public:
|
||||
void add_spacer(bool p_begin = false);
|
||||
|
||||
void set_alignment(AlignMode p_align);
|
||||
AlignMode get_alignment() const;
|
||||
|
||||
virtual Size2 get_minimum_size() const;
|
||||
|
||||
BoxContainer(bool p_vertical=false);
|
||||
BoxContainer(bool p_vertical = false);
|
||||
};
|
||||
|
||||
|
||||
class HBoxContainer : public BoxContainer {
|
||||
|
||||
OBJ_TYPE(HBoxContainer,BoxContainer);
|
||||
OBJ_TYPE(HBoxContainer, BoxContainer);
|
||||
|
||||
public:
|
||||
|
||||
HBoxContainer() : BoxContainer(false) {}
|
||||
HBoxContainer()
|
||||
: BoxContainer(false) {}
|
||||
};
|
||||
|
||||
|
||||
class MarginContainer;
|
||||
class VBoxContainer : public BoxContainer {
|
||||
|
||||
OBJ_TYPE(VBoxContainer,BoxContainer);
|
||||
OBJ_TYPE(VBoxContainer, BoxContainer);
|
||||
|
||||
public:
|
||||
MarginContainer *add_margin_child(const String &p_label, Control *p_control, bool p_expand = false);
|
||||
|
||||
MarginContainer* add_margin_child(const String& p_label,Control *p_control,bool p_expand=false);
|
||||
|
||||
VBoxContainer() : BoxContainer(true) {}
|
||||
VBoxContainer()
|
||||
: BoxContainer(true) {}
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST(BoxContainer::AlignMode);
|
||||
|
|
|
|||
|
|
@ -27,79 +27,76 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "button.h"
|
||||
#include "servers/visual_server.h"
|
||||
#include "print_string.h"
|
||||
#include "servers/visual_server.h"
|
||||
#include "translation.h"
|
||||
|
||||
|
||||
Size2 Button::get_minimum_size() const {
|
||||
|
||||
Size2 minsize=get_font("font")->get_string_size( text );
|
||||
Size2 minsize = get_font("font")->get_string_size(text);
|
||||
if (clip_text)
|
||||
minsize.width=0;
|
||||
minsize.width = 0;
|
||||
|
||||
Ref<Texture> _icon;
|
||||
if (icon.is_null() && has_icon("icon"))
|
||||
_icon=Control::get_icon("icon");
|
||||
_icon = Control::get_icon("icon");
|
||||
else
|
||||
_icon=icon;
|
||||
_icon = icon;
|
||||
|
||||
if (!_icon.is_null()) {
|
||||
|
||||
minsize.height=MAX( minsize.height, _icon->get_height() );
|
||||
minsize.width+=_icon->get_width();
|
||||
if (text!="")
|
||||
minsize.width+=get_constant("hseparation");
|
||||
minsize.height = MAX(minsize.height, _icon->get_height());
|
||||
minsize.width += _icon->get_width();
|
||||
if (text != "")
|
||||
minsize.width += get_constant("hseparation");
|
||||
}
|
||||
|
||||
return get_stylebox("normal" )->get_minimum_size() + minsize;
|
||||
|
||||
return get_stylebox("normal")->get_minimum_size() + minsize;
|
||||
}
|
||||
|
||||
|
||||
void Button::_notification(int p_what) {
|
||||
|
||||
if (p_what==NOTIFICATION_DRAW) {
|
||||
if (p_what == NOTIFICATION_DRAW) {
|
||||
|
||||
RID ci = get_canvas_item();
|
||||
Size2 size=get_size();
|
||||
Size2 size = get_size();
|
||||
Color color;
|
||||
|
||||
//print_line(get_text()+": "+itos(is_flat())+" hover "+itos(get_draw_mode()));
|
||||
|
||||
Ref<StyleBox> style = get_stylebox("normal");
|
||||
|
||||
switch( get_draw_mode() ) {
|
||||
switch (get_draw_mode()) {
|
||||
|
||||
case DRAW_NORMAL: {
|
||||
|
||||
style = get_stylebox("normal");
|
||||
if (!flat)
|
||||
style->draw( ci, Rect2(Point2(0,0), size) );
|
||||
color=get_color("font_color");
|
||||
style->draw(ci, Rect2(Point2(0, 0), size));
|
||||
color = get_color("font_color");
|
||||
} break;
|
||||
case DRAW_PRESSED: {
|
||||
|
||||
style = get_stylebox("pressed");
|
||||
style->draw( ci, Rect2(Point2(0,0), size) );
|
||||
style->draw(ci, Rect2(Point2(0, 0), size));
|
||||
if (has_color("font_color_pressed"))
|
||||
color=get_color("font_color_pressed");
|
||||
color = get_color("font_color_pressed");
|
||||
else
|
||||
color=get_color("font_color");
|
||||
color = get_color("font_color");
|
||||
|
||||
} break;
|
||||
case DRAW_HOVER: {
|
||||
|
||||
style = get_stylebox("hover");
|
||||
style->draw( ci, Rect2(Point2(0,0), size) );
|
||||
color=get_color("font_color_hover");
|
||||
style->draw(ci, Rect2(Point2(0, 0), size));
|
||||
color = get_color("font_color_hover");
|
||||
|
||||
} break;
|
||||
case DRAW_DISABLED: {
|
||||
|
||||
style = get_stylebox("disabled");
|
||||
style->draw( ci, Rect2(Point2(0,0), size) );
|
||||
color=get_color("font_color_disabled");
|
||||
style->draw(ci, Rect2(Point2(0, 0), size));
|
||||
color = get_color("font_color_disabled");
|
||||
|
||||
} break;
|
||||
}
|
||||
|
|
@ -107,57 +104,53 @@ void Button::_notification(int p_what) {
|
|||
if (has_focus()) {
|
||||
|
||||
Ref<StyleBox> style = get_stylebox("focus");
|
||||
style->draw(ci,Rect2(Point2(),size));
|
||||
style->draw(ci, Rect2(Point2(), size));
|
||||
}
|
||||
|
||||
Ref<Font> font=get_font("font");
|
||||
Ref<Font> font = get_font("font");
|
||||
Ref<Texture> _icon;
|
||||
if (icon.is_null() && has_icon("icon"))
|
||||
_icon=Control::get_icon("icon");
|
||||
_icon = Control::get_icon("icon");
|
||||
else
|
||||
_icon=icon;
|
||||
_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;
|
||||
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) {
|
||||
switch (align) {
|
||||
case ALIGN_LEFT: {
|
||||
text_ofs.x = style->get_margin(MARGIN_LEFT) + icon_ofs.x;
|
||||
text_ofs.y+=style->get_offset().y;
|
||||
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();
|
||||
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;
|
||||
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);
|
||||
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;
|
||||
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) );
|
||||
_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));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void Button::set_text(const String& p_text) {
|
||||
void Button::set_text(const String &p_text) {
|
||||
|
||||
if (text==p_text)
|
||||
if (text == p_text)
|
||||
return;
|
||||
text=XL_MESSAGE(p_text);
|
||||
text = XL_MESSAGE(p_text);
|
||||
update();
|
||||
_change_notify("text");
|
||||
minimum_size_changed();
|
||||
|
|
@ -167,12 +160,11 @@ String Button::get_text() const {
|
|||
return text;
|
||||
}
|
||||
|
||||
void Button::set_icon(const Ref<Texture> &p_icon) {
|
||||
|
||||
void Button::set_icon(const Ref<Texture>& p_icon) {
|
||||
|
||||
if (icon==p_icon)
|
||||
if (icon == p_icon)
|
||||
return;
|
||||
icon=p_icon;
|
||||
icon = p_icon;
|
||||
update();
|
||||
_change_notify("icon");
|
||||
minimum_size_changed();
|
||||
|
|
@ -185,7 +177,7 @@ Ref<Texture> Button::get_icon() const {
|
|||
|
||||
void Button::set_flat(bool p_flat) {
|
||||
|
||||
flat=p_flat;
|
||||
flat = p_flat;
|
||||
update();
|
||||
_change_notify("flat");
|
||||
}
|
||||
|
|
@ -197,7 +189,7 @@ bool Button::is_flat() const {
|
|||
|
||||
void Button::set_clip_text(bool p_clip_text) {
|
||||
|
||||
clip_text=p_clip_text;
|
||||
clip_text = p_clip_text;
|
||||
update();
|
||||
minimum_size_changed();
|
||||
}
|
||||
|
|
@ -209,7 +201,7 @@ bool Button::get_clip_text() const {
|
|||
|
||||
void Button::set_text_align(TextAlign p_align) {
|
||||
|
||||
align=p_align;
|
||||
align = p_align;
|
||||
update();
|
||||
}
|
||||
|
||||
|
|
@ -220,41 +212,36 @@ Button::TextAlign Button::get_text_align() const {
|
|||
|
||||
void Button::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_text","text"),&Button::set_text);
|
||||
ObjectTypeDB::bind_method(_MD("get_text"),&Button::get_text);
|
||||
ObjectTypeDB::bind_method(_MD("set_button_icon","texture:Texture"),&Button::set_icon);
|
||||
ObjectTypeDB::bind_method(_MD("get_button_icon:Texture"),&Button::get_icon);
|
||||
ObjectTypeDB::bind_method(_MD("set_flat","enabled"),&Button::set_flat);
|
||||
ObjectTypeDB::bind_method(_MD("set_clip_text","enabled"),&Button::set_clip_text);
|
||||
ObjectTypeDB::bind_method(_MD("get_clip_text"),&Button::get_clip_text);
|
||||
ObjectTypeDB::bind_method(_MD("set_text_align","align"),&Button::set_text_align);
|
||||
ObjectTypeDB::bind_method(_MD("get_text_align"),&Button::get_text_align);
|
||||
ObjectTypeDB::bind_method(_MD("is_flat"),&Button::is_flat);
|
||||
ObjectTypeDB::bind_method(_MD("set_text", "text"), &Button::set_text);
|
||||
ObjectTypeDB::bind_method(_MD("get_text"), &Button::get_text);
|
||||
ObjectTypeDB::bind_method(_MD("set_button_icon", "texture:Texture"), &Button::set_icon);
|
||||
ObjectTypeDB::bind_method(_MD("get_button_icon:Texture"), &Button::get_icon);
|
||||
ObjectTypeDB::bind_method(_MD("set_flat", "enabled"), &Button::set_flat);
|
||||
ObjectTypeDB::bind_method(_MD("set_clip_text", "enabled"), &Button::set_clip_text);
|
||||
ObjectTypeDB::bind_method(_MD("get_clip_text"), &Button::get_clip_text);
|
||||
ObjectTypeDB::bind_method(_MD("set_text_align", "align"), &Button::set_text_align);
|
||||
ObjectTypeDB::bind_method(_MD("get_text_align"), &Button::get_text_align);
|
||||
ObjectTypeDB::bind_method(_MD("is_flat"), &Button::is_flat);
|
||||
|
||||
BIND_CONSTANT( ALIGN_LEFT );
|
||||
BIND_CONSTANT( ALIGN_CENTER );
|
||||
BIND_CONSTANT( ALIGN_RIGHT );
|
||||
|
||||
ADD_PROPERTYNZ( PropertyInfo( Variant::STRING, "text", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_DEFAULT_INTL ), _SCS("set_text"),_SCS("get_text") );
|
||||
ADD_PROPERTYNZ( PropertyInfo( Variant::OBJECT, "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture" ), _SCS("set_button_icon"),_SCS("get_button_icon") );
|
||||
ADD_PROPERTY( PropertyInfo( Variant::BOOL, "flat" ), _SCS("set_flat"),_SCS("is_flat") );
|
||||
ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "clip_text" ), _SCS("set_clip_text"),_SCS("get_clip_text") );
|
||||
ADD_PROPERTYNO( PropertyInfo( Variant::INT, "align",PROPERTY_HINT_ENUM,"Left,Center,Right" ), _SCS("set_text_align"),_SCS("get_text_align") );
|
||||
BIND_CONSTANT(ALIGN_LEFT);
|
||||
BIND_CONSTANT(ALIGN_CENTER);
|
||||
BIND_CONSTANT(ALIGN_RIGHT);
|
||||
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::STRING, "text", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT_INTL), _SCS("set_text"), _SCS("get_text"));
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), _SCS("set_button_icon"), _SCS("get_button_icon"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "flat"), _SCS("set_flat"), _SCS("is_flat"));
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "clip_text"), _SCS("set_clip_text"), _SCS("get_clip_text"));
|
||||
ADD_PROPERTYNO(PropertyInfo(Variant::INT, "align", PROPERTY_HINT_ENUM, "Left,Center,Right"), _SCS("set_text_align"), _SCS("get_text_align"));
|
||||
}
|
||||
|
||||
Button::Button(const String &p_text) {
|
||||
|
||||
flat=false;
|
||||
clip_text=false;
|
||||
flat = false;
|
||||
clip_text = false;
|
||||
set_stop_mouse(true);
|
||||
set_text(p_text);
|
||||
align=ALIGN_CENTER;
|
||||
align = ALIGN_CENTER;
|
||||
}
|
||||
|
||||
|
||||
Button::~Button()
|
||||
{
|
||||
Button::~Button() {
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -35,10 +35,9 @@
|
|||
*/
|
||||
class Button : public BaseButton {
|
||||
|
||||
OBJ_TYPE( Button, BaseButton );
|
||||
OBJ_TYPE(Button, BaseButton);
|
||||
|
||||
public:
|
||||
|
||||
|
||||
enum TextAlign {
|
||||
ALIGN_LEFT,
|
||||
ALIGN_CENTER,
|
||||
|
|
@ -46,27 +45,24 @@ public:
|
|||
};
|
||||
|
||||
private:
|
||||
|
||||
bool flat;
|
||||
String text;
|
||||
Ref<Texture> icon;
|
||||
bool clip_text;
|
||||
TextAlign align;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
virtual Size2 get_minimum_size() const;
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
void set_text(const String& p_text);
|
||||
void set_text(const String &p_text);
|
||||
String get_text() const;
|
||||
|
||||
void set_icon(const Ref<Texture>& p_icon);
|
||||
void set_icon(const Ref<Texture> &p_icon);
|
||||
Ref<Texture> get_icon() const;
|
||||
|
||||
void set_flat(bool p_flat);
|
||||
|
|
@ -78,13 +74,10 @@ public:
|
|||
void set_text_align(TextAlign p_align);
|
||||
TextAlign get_text_align() const;
|
||||
|
||||
|
||||
Button(const String& p_text=String());
|
||||
Button(const String &p_text = String());
|
||||
~Button();
|
||||
|
||||
};
|
||||
|
||||
|
||||
VARIANT_ENUM_CAST(Button::TextAlign);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -28,46 +28,44 @@
|
|||
/*************************************************************************/
|
||||
#include "button_array.h"
|
||||
|
||||
bool ButtonArray::_set(const StringName &p_name, const Variant &p_value) {
|
||||
|
||||
bool ButtonArray::_set(const StringName& p_name, const Variant& p_value) {
|
||||
|
||||
String n=String(p_name);
|
||||
String n = String(p_name);
|
||||
if (n.begins_with("button/")) {
|
||||
|
||||
String what = n.get_slicec('/',1);
|
||||
if (what=="count") {
|
||||
int new_size=p_value;
|
||||
if (new_size>0 && buttons.size()==0) {
|
||||
selected=0;
|
||||
String what = n.get_slicec('/', 1);
|
||||
if (what == "count") {
|
||||
int new_size = p_value;
|
||||
if (new_size > 0 && buttons.size() == 0) {
|
||||
selected = 0;
|
||||
}
|
||||
|
||||
if (new_size < buttons.size()) {
|
||||
if (selected>=new_size)
|
||||
selected=new_size-1;
|
||||
if (selected >= new_size)
|
||||
selected = new_size - 1;
|
||||
}
|
||||
buttons.resize(new_size);
|
||||
_change_notify();
|
||||
minimum_size_changed();
|
||||
} else if (what=="align") {
|
||||
} else if (what == "align") {
|
||||
set_align(Align(p_value.operator int()));
|
||||
} else if (what=="selected") {
|
||||
} else if (what == "selected") {
|
||||
set_selected(p_value);
|
||||
} else if (what == "min_button_size") {
|
||||
min_button_size = p_value;
|
||||
} else {
|
||||
int idx=what.to_int();
|
||||
ERR_FAIL_INDEX_V(idx,buttons.size(),false);
|
||||
String f = n.get_slicec('/',2);
|
||||
if (f=="text") {
|
||||
buttons[idx].text=p_value;
|
||||
buttons[idx].xl_text=XL_MESSAGE(p_value);
|
||||
} else if (f=="tooltip")
|
||||
buttons[idx].tooltip=p_value;
|
||||
else if (f=="icon")
|
||||
buttons[idx].icon=p_value;
|
||||
int idx = what.to_int();
|
||||
ERR_FAIL_INDEX_V(idx, buttons.size(), false);
|
||||
String f = n.get_slicec('/', 2);
|
||||
if (f == "text") {
|
||||
buttons[idx].text = p_value;
|
||||
buttons[idx].xl_text = XL_MESSAGE(p_value);
|
||||
} else if (f == "tooltip")
|
||||
buttons[idx].tooltip = p_value;
|
||||
else if (f == "icon")
|
||||
buttons[idx].icon = p_value;
|
||||
else
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
update();
|
||||
|
|
@ -75,36 +73,34 @@ bool ButtonArray::_set(const StringName& p_name, const Variant& p_value) {
|
|||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
bool ButtonArray::_get(const StringName& p_name,Variant &r_ret) const {
|
||||
bool ButtonArray::_get(const StringName &p_name, Variant &r_ret) const {
|
||||
|
||||
String n=String(p_name);
|
||||
String n = String(p_name);
|
||||
if (n.begins_with("button/")) {
|
||||
|
||||
String what = n.get_slicec('/',1);
|
||||
if (what=="count") {
|
||||
r_ret=buttons.size();
|
||||
} else if (what=="align") {
|
||||
r_ret=get_align();
|
||||
} else if (what=="selected") {
|
||||
r_ret=get_selected();
|
||||
} else if (what == "min_button_size"){
|
||||
String what = n.get_slicec('/', 1);
|
||||
if (what == "count") {
|
||||
r_ret = buttons.size();
|
||||
} else if (what == "align") {
|
||||
r_ret = get_align();
|
||||
} else if (what == "selected") {
|
||||
r_ret = get_selected();
|
||||
} else if (what == "min_button_size") {
|
||||
r_ret = min_button_size;
|
||||
} else {
|
||||
int idx=what.to_int();
|
||||
ERR_FAIL_INDEX_V(idx,buttons.size(),false);
|
||||
String f = n.get_slicec('/',2);
|
||||
if (f=="text")
|
||||
r_ret=buttons[idx].text;
|
||||
else if (f=="tooltip")
|
||||
r_ret=buttons[idx].tooltip;
|
||||
else if (f=="icon")
|
||||
r_ret=buttons[idx].icon;
|
||||
int idx = what.to_int();
|
||||
ERR_FAIL_INDEX_V(idx, buttons.size(), false);
|
||||
String f = n.get_slicec('/', 2);
|
||||
if (f == "text")
|
||||
r_ret = buttons[idx].text;
|
||||
else if (f == "tooltip")
|
||||
r_ret = buttons[idx].tooltip;
|
||||
else if (f == "icon")
|
||||
r_ret = buttons[idx].icon;
|
||||
else
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
@ -112,24 +108,22 @@ bool ButtonArray::_get(const StringName& p_name,Variant &r_ret) const {
|
|||
|
||||
return false;
|
||||
}
|
||||
void ButtonArray::_get_property_list( List<PropertyInfo> *p_list) const {
|
||||
void ButtonArray::_get_property_list(List<PropertyInfo> *p_list) const {
|
||||
|
||||
p_list->push_back( PropertyInfo( Variant::INT, "button/count",PROPERTY_HINT_RANGE,"0,512,1"));
|
||||
p_list->push_back( PropertyInfo( Variant::INT, "button/min_button_size",PROPERTY_HINT_RANGE,"0,1024,1"));
|
||||
p_list->push_back( PropertyInfo( Variant::INT, "button/align",PROPERTY_HINT_ENUM,"Begin,Center,End,Fill,Expand"));
|
||||
for(int i=0;i<buttons.size();i++) {
|
||||
String base="button/"+itos(i)+"/";
|
||||
p_list->push_back( PropertyInfo( Variant::STRING, base+"text"));
|
||||
p_list->push_back( PropertyInfo( Variant::STRING, base+"tooltip"));
|
||||
p_list->push_back( PropertyInfo( Variant::OBJECT, base+"icon",PROPERTY_HINT_RESOURCE_TYPE,"Texture"));
|
||||
p_list->push_back(PropertyInfo(Variant::INT, "button/count", PROPERTY_HINT_RANGE, "0,512,1"));
|
||||
p_list->push_back(PropertyInfo(Variant::INT, "button/min_button_size", PROPERTY_HINT_RANGE, "0,1024,1"));
|
||||
p_list->push_back(PropertyInfo(Variant::INT, "button/align", PROPERTY_HINT_ENUM, "Begin,Center,End,Fill,Expand"));
|
||||
for (int i = 0; i < buttons.size(); i++) {
|
||||
String base = "button/" + itos(i) + "/";
|
||||
p_list->push_back(PropertyInfo(Variant::STRING, base + "text"));
|
||||
p_list->push_back(PropertyInfo(Variant::STRING, base + "tooltip"));
|
||||
p_list->push_back(PropertyInfo(Variant::OBJECT, base + "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture"));
|
||||
}
|
||||
if (buttons.size()>0) {
|
||||
p_list->push_back( PropertyInfo( Variant::INT, "button/selected",PROPERTY_HINT_RANGE,"0,"+itos(buttons.size()-1)+",1"));
|
||||
if (buttons.size() > 0) {
|
||||
p_list->push_back(PropertyInfo(Variant::INT, "button/selected", PROPERTY_HINT_RANGE, "0," + itos(buttons.size() - 1) + ",1"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Size2 ButtonArray::get_minimum_size() const {
|
||||
|
||||
Ref<StyleBox> style_normal = get_stylebox("normal");
|
||||
|
|
@ -141,54 +135,51 @@ Size2 ButtonArray::get_minimum_size() const {
|
|||
|
||||
Size2 minsize;
|
||||
|
||||
for(int i=0;i<buttons.size();i++) {
|
||||
for (int i = 0; i < buttons.size(); i++) {
|
||||
|
||||
Ref<StyleBox> sb = i==selected ? style_selected : style_normal;
|
||||
Ref<Font> f = i==selected ? font_selected : font_normal;
|
||||
Ref<StyleBox> sb = i == selected ? style_selected : style_normal;
|
||||
Ref<Font> f = i == selected ? font_selected : font_normal;
|
||||
|
||||
Size2 ms;
|
||||
ms = f->get_string_size(buttons[i].xl_text);
|
||||
if (buttons[i].icon.is_valid()) {
|
||||
|
||||
Size2 bs = buttons[i].icon->get_size();
|
||||
ms.height = MAX(ms.height,bs.height);
|
||||
ms.width+=bs.width+icon_sep;
|
||||
ms.height = MAX(ms.height, bs.height);
|
||||
ms.width += bs.width + icon_sep;
|
||||
}
|
||||
|
||||
ms+=sb->get_minimum_size();
|
||||
ms += sb->get_minimum_size();
|
||||
|
||||
buttons[i]._ms_cache=ms[orientation];
|
||||
|
||||
minsize[orientation]+=ms[orientation];
|
||||
if (i>0)
|
||||
minsize[orientation]+=button_sep;
|
||||
minsize[!orientation] = MAX(minsize[!orientation],ms[!orientation]);
|
||||
buttons[i]._ms_cache = ms[orientation];
|
||||
|
||||
minsize[orientation] += ms[orientation];
|
||||
if (i > 0)
|
||||
minsize[orientation] += button_sep;
|
||||
minsize[!orientation] = MAX(minsize[!orientation], ms[!orientation]);
|
||||
}
|
||||
|
||||
return minsize;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void ButtonArray::_notification(int p_what) {
|
||||
|
||||
switch(p_what) {
|
||||
case NOTIFICATION_MOUSE_EXIT:{
|
||||
hover=-1;
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_MOUSE_EXIT: {
|
||||
hover = -1;
|
||||
update();
|
||||
}break;
|
||||
case NOTIFICATION_READY:{
|
||||
} break;
|
||||
case NOTIFICATION_READY: {
|
||||
MethodInfo mi;
|
||||
mi.name="mouse_sub_enter";
|
||||
mi.name = "mouse_sub_enter";
|
||||
|
||||
add_user_signal(mi);
|
||||
|
||||
}break;
|
||||
} break;
|
||||
case NOTIFICATION_DRAW: {
|
||||
|
||||
Size2 size=get_size();
|
||||
Size2 minsize=get_combined_minimum_size();
|
||||
Size2 size = get_size();
|
||||
Size2 minsize = get_combined_minimum_size();
|
||||
Ref<StyleBox> style_normal = get_stylebox("normal");
|
||||
Ref<StyleBox> style_selected = get_stylebox("selected");
|
||||
Ref<StyleBox> style_focus = get_stylebox("focus");
|
||||
|
|
@ -200,188 +191,174 @@ void ButtonArray::_notification(int p_what) {
|
|||
Color color_normal = get_color("font_color");
|
||||
Color color_selected = get_color("font_color_selected");
|
||||
|
||||
int sep=button_sep;
|
||||
int ofs=0;
|
||||
int expand=0;
|
||||
int sep = button_sep;
|
||||
int ofs = 0;
|
||||
int expand = 0;
|
||||
|
||||
switch(align) {
|
||||
switch (align) {
|
||||
case ALIGN_BEGIN: {
|
||||
|
||||
ofs=0;
|
||||
ofs = 0;
|
||||
} break;
|
||||
case ALIGN_CENTER: {
|
||||
|
||||
ofs=Math::floor((size[orientation] - minsize[orientation])/2);
|
||||
ofs = Math::floor((size[orientation] - minsize[orientation]) / 2);
|
||||
} break;
|
||||
case ALIGN_END: {
|
||||
|
||||
ofs=Math::floor((size[orientation] - minsize[orientation]));
|
||||
ofs = Math::floor((size[orientation] - minsize[orientation]));
|
||||
} break;
|
||||
case ALIGN_FILL: {
|
||||
|
||||
if (buttons.size()>1)
|
||||
sep+=Math::floor((size[orientation]- minsize[orientation])/(buttons.size()-1.0));
|
||||
ofs=0;
|
||||
if (buttons.size() > 1)
|
||||
sep += Math::floor((size[orientation] - minsize[orientation]) / (buttons.size() - 1.0));
|
||||
ofs = 0;
|
||||
} break;
|
||||
case ALIGN_EXPAND_FILL: {
|
||||
|
||||
ofs=0;
|
||||
expand=size[orientation] - minsize[orientation];
|
||||
ofs = 0;
|
||||
expand = size[orientation] - minsize[orientation];
|
||||
} break;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
int op_size = orientation==VERTICAL ? size.width : size.height;
|
||||
int op_size = orientation == VERTICAL ? size.width : size.height;
|
||||
|
||||
|
||||
for(int i=0;i<buttons.size();i++) {
|
||||
for (int i = 0; i < buttons.size(); i++) {
|
||||
|
||||
int ms = buttons[i]._ms_cache;
|
||||
int s=ms;
|
||||
if (expand>0) {
|
||||
s+=expand/buttons.size();
|
||||
int s = ms;
|
||||
if (expand > 0) {
|
||||
s += expand / buttons.size();
|
||||
}
|
||||
if(min_button_size != -1 && s < min_button_size){
|
||||
if (min_button_size != -1 && s < min_button_size) {
|
||||
s = min_button_size;
|
||||
}
|
||||
|
||||
Rect2 r;
|
||||
r.pos[orientation]=ofs;
|
||||
r.pos[!orientation]=0;
|
||||
r.size[orientation]=s;
|
||||
r.size[!orientation]=op_size;
|
||||
r.pos[orientation] = ofs;
|
||||
r.pos[!orientation] = 0;
|
||||
r.size[orientation] = s;
|
||||
r.size[!orientation] = op_size;
|
||||
|
||||
Ref<Font> f;
|
||||
Color c;
|
||||
Point2 sbsize;
|
||||
Point2 sbofs;
|
||||
if (i==selected) {
|
||||
draw_style_box(style_selected,r);
|
||||
sbsize=style_selected->get_minimum_size();
|
||||
sbofs=style_selected->get_offset();
|
||||
f=font_selected;
|
||||
c=color_selected;
|
||||
if (i == selected) {
|
||||
draw_style_box(style_selected, r);
|
||||
sbsize = style_selected->get_minimum_size();
|
||||
sbofs = style_selected->get_offset();
|
||||
f = font_selected;
|
||||
c = color_selected;
|
||||
if (has_focus())
|
||||
draw_style_box(style_focus,r);
|
||||
draw_style_box(style_focus, r);
|
||||
} else {
|
||||
if (hover==i)
|
||||
draw_style_box(style_hover,r);
|
||||
if (hover == i)
|
||||
draw_style_box(style_hover, r);
|
||||
else if (!flat)
|
||||
draw_style_box(style_normal,r);
|
||||
sbsize=style_normal->get_minimum_size();
|
||||
sbofs=style_normal->get_offset();
|
||||
f=font_normal;
|
||||
c=color_normal;
|
||||
draw_style_box(style_normal, r);
|
||||
sbsize = style_normal->get_minimum_size();
|
||||
sbofs = style_normal->get_offset();
|
||||
f = font_normal;
|
||||
c = color_normal;
|
||||
}
|
||||
|
||||
Size2 ssize = f->get_string_size(buttons[i].xl_text);
|
||||
if (buttons[i].icon.is_valid()) {
|
||||
|
||||
ssize.x+=buttons[i].icon->get_width();
|
||||
ssize.x += buttons[i].icon->get_width();
|
||||
}
|
||||
Point2 text_ofs=((r.size-ssize-sbsize)/2.0+Point2(0,f->get_ascent())).floor()+sbofs;
|
||||
Point2 text_ofs = ((r.size - ssize - sbsize) / 2.0 + Point2(0, f->get_ascent())).floor() + sbofs;
|
||||
if (buttons[i].icon.is_valid()) {
|
||||
|
||||
draw_texture(buttons[i].icon,r.pos+Point2(text_ofs.x,Math::floor((r.size.height-buttons[i].icon->get_height())/2.0)));
|
||||
text_ofs.x+=buttons[i].icon->get_width()+icon_sep;
|
||||
|
||||
draw_texture(buttons[i].icon, r.pos + Point2(text_ofs.x, Math::floor((r.size.height - buttons[i].icon->get_height()) / 2.0)));
|
||||
text_ofs.x += buttons[i].icon->get_width() + icon_sep;
|
||||
}
|
||||
draw_string(f,text_ofs+r.pos,buttons[i].xl_text,c);
|
||||
buttons[i]._pos_cache=ofs;
|
||||
buttons[i]._size_cache=s;
|
||||
draw_string(f, text_ofs + r.pos, buttons[i].xl_text, c);
|
||||
buttons[i]._pos_cache = ofs;
|
||||
buttons[i]._size_cache = s;
|
||||
|
||||
ofs+=s;
|
||||
ofs+=sep;
|
||||
ofs += s;
|
||||
ofs += sep;
|
||||
}
|
||||
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ButtonArray::_input_event(const InputEvent& p_event) {
|
||||
void ButtonArray::_input_event(const InputEvent &p_event) {
|
||||
|
||||
if (
|
||||
( (orientation==HORIZONTAL && p_event.is_action("ui_left") ) ||
|
||||
(orientation==VERTICAL && p_event.is_action("ui_up") ) )
|
||||
&& p_event.is_pressed() && selected>0) {
|
||||
set_selected(selected-1);
|
||||
accept_event();
|
||||
emit_signal("button_selected",selected);
|
||||
return;
|
||||
|
||||
((orientation == HORIZONTAL && p_event.is_action("ui_left")) ||
|
||||
(orientation == VERTICAL && p_event.is_action("ui_up"))) &&
|
||||
p_event.is_pressed() && selected > 0) {
|
||||
set_selected(selected - 1);
|
||||
accept_event();
|
||||
emit_signal("button_selected", selected);
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
( (orientation==HORIZONTAL && p_event.is_action("ui_right") ) ||
|
||||
(orientation==VERTICAL && p_event.is_action("ui_down") ) )
|
||||
&& p_event.is_pressed() && selected<(buttons.size()-1)) {
|
||||
set_selected(selected+1);
|
||||
accept_event();
|
||||
emit_signal("button_selected",selected);
|
||||
return;
|
||||
|
||||
((orientation == HORIZONTAL && p_event.is_action("ui_right")) ||
|
||||
(orientation == VERTICAL && p_event.is_action("ui_down"))) &&
|
||||
p_event.is_pressed() && selected < (buttons.size() - 1)) {
|
||||
set_selected(selected + 1);
|
||||
accept_event();
|
||||
emit_signal("button_selected", selected);
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.pressed && p_event.mouse_button.button_index==BUTTON_LEFT) {
|
||||
if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.pressed && p_event.mouse_button.button_index == BUTTON_LEFT) {
|
||||
|
||||
int ofs = orientation==HORIZONTAL ? p_event.mouse_button.x: p_event.mouse_button.y;
|
||||
int ofs = orientation == HORIZONTAL ? p_event.mouse_button.x : p_event.mouse_button.y;
|
||||
|
||||
for(int i=0;i<buttons.size();i++) {
|
||||
for (int i = 0; i < buttons.size(); i++) {
|
||||
|
||||
if (ofs>=buttons[i]._pos_cache && ofs<buttons[i]._pos_cache+buttons[i]._size_cache) {
|
||||
if (ofs >= buttons[i]._pos_cache && ofs < buttons[i]._pos_cache + buttons[i]._size_cache) {
|
||||
|
||||
set_selected(i);
|
||||
emit_signal("button_selected",i);
|
||||
emit_signal("button_selected", i);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (p_event.type==InputEvent::MOUSE_MOTION) {
|
||||
if (p_event.type == InputEvent::MOUSE_MOTION) {
|
||||
|
||||
int ofs = orientation==HORIZONTAL ? p_event.mouse_motion.x: p_event.mouse_motion.y;
|
||||
int new_hover=-1;
|
||||
for(int i=0;i<buttons.size();i++) {
|
||||
int ofs = orientation == HORIZONTAL ? p_event.mouse_motion.x : p_event.mouse_motion.y;
|
||||
int new_hover = -1;
|
||||
for (int i = 0; i < buttons.size(); i++) {
|
||||
|
||||
if (ofs>=buttons[i]._pos_cache && ofs<buttons[i]._pos_cache+buttons[i]._size_cache) {
|
||||
if (ofs >= buttons[i]._pos_cache && ofs < buttons[i]._pos_cache + buttons[i]._size_cache) {
|
||||
|
||||
new_hover=i;
|
||||
new_hover = i;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (new_hover!=hover) {
|
||||
hover=new_hover;
|
||||
if (new_hover != hover) {
|
||||
hover = new_hover;
|
||||
emit_signal("mouse_sub_enter");
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
String ButtonArray::get_tooltip(const Point2& p_pos) const {
|
||||
String ButtonArray::get_tooltip(const Point2 &p_pos) const {
|
||||
|
||||
int ofs = orientation==HORIZONTAL ? p_pos.x: p_pos.y;
|
||||
for(int i=0;i<buttons.size();i++) {
|
||||
int ofs = orientation == HORIZONTAL ? p_pos.x : p_pos.y;
|
||||
for (int i = 0; i < buttons.size(); i++) {
|
||||
|
||||
if (ofs>=buttons[i]._pos_cache && ofs<buttons[i]._pos_cache+buttons[i]._size_cache)
|
||||
if (ofs >= buttons[i]._pos_cache && ofs < buttons[i]._pos_cache + buttons[i]._size_cache)
|
||||
return buttons[i].tooltip;
|
||||
|
||||
}
|
||||
return Control::get_tooltip(p_pos);
|
||||
}
|
||||
|
||||
void ButtonArray::set_align(Align p_align) {
|
||||
|
||||
align=p_align;
|
||||
align = p_align;
|
||||
update();
|
||||
|
||||
}
|
||||
|
||||
ButtonArray::Align ButtonArray::get_align() const {
|
||||
|
|
@ -391,7 +368,7 @@ ButtonArray::Align ButtonArray::get_align() const {
|
|||
|
||||
void ButtonArray::set_flat(bool p_flat) {
|
||||
|
||||
flat=p_flat;
|
||||
flat = p_flat;
|
||||
update();
|
||||
}
|
||||
|
||||
|
|
@ -400,79 +377,74 @@ bool ButtonArray::is_flat() const {
|
|||
return flat;
|
||||
}
|
||||
|
||||
|
||||
void ButtonArray::add_button(const String& p_text,const String& p_tooltip) {
|
||||
void ButtonArray::add_button(const String &p_text, const String &p_tooltip) {
|
||||
|
||||
Button button;
|
||||
button.text=p_text;
|
||||
button.xl_text=XL_MESSAGE(p_text);
|
||||
button.tooltip=p_tooltip;
|
||||
button.text = p_text;
|
||||
button.xl_text = XL_MESSAGE(p_text);
|
||||
button.tooltip = p_tooltip;
|
||||
buttons.push_back(button);
|
||||
update();
|
||||
|
||||
if (selected==-1)
|
||||
selected=0;
|
||||
if (selected == -1)
|
||||
selected = 0;
|
||||
|
||||
minimum_size_changed();
|
||||
}
|
||||
|
||||
void ButtonArray::add_icon_button(const Ref<Texture>& p_icon,const String& p_text,const String& p_tooltip) {
|
||||
void ButtonArray::add_icon_button(const Ref<Texture> &p_icon, const String &p_text, const String &p_tooltip) {
|
||||
|
||||
Button button;
|
||||
button.text=p_text;
|
||||
button.xl_text=XL_MESSAGE(p_text);
|
||||
button.icon=p_icon;
|
||||
button.tooltip=p_tooltip;
|
||||
button.text = p_text;
|
||||
button.xl_text = XL_MESSAGE(p_text);
|
||||
button.icon = p_icon;
|
||||
button.tooltip = p_tooltip;
|
||||
buttons.push_back(button);
|
||||
if (selected==-1)
|
||||
selected=0;
|
||||
if (selected == -1)
|
||||
selected = 0;
|
||||
|
||||
update();
|
||||
|
||||
}
|
||||
|
||||
void ButtonArray::set_button_text(int p_button, const String& p_text) {
|
||||
void ButtonArray::set_button_text(int p_button, const String &p_text) {
|
||||
|
||||
ERR_FAIL_INDEX(p_button,buttons.size());
|
||||
buttons[p_button].text=p_text;
|
||||
buttons[p_button].xl_text=XL_MESSAGE(p_text);
|
||||
ERR_FAIL_INDEX(p_button, buttons.size());
|
||||
buttons[p_button].text = p_text;
|
||||
buttons[p_button].xl_text = XL_MESSAGE(p_text);
|
||||
update();
|
||||
minimum_size_changed();
|
||||
|
||||
}
|
||||
|
||||
void ButtonArray::set_button_tooltip(int p_button, const String& p_text) {
|
||||
|
||||
ERR_FAIL_INDEX(p_button,buttons.size());
|
||||
buttons[p_button].tooltip=p_text;
|
||||
void ButtonArray::set_button_tooltip(int p_button, const String &p_text) {
|
||||
|
||||
ERR_FAIL_INDEX(p_button, buttons.size());
|
||||
buttons[p_button].tooltip = p_text;
|
||||
}
|
||||
|
||||
void ButtonArray::set_button_icon(int p_button, const Ref<Texture>& p_icon) {
|
||||
void ButtonArray::set_button_icon(int p_button, const Ref<Texture> &p_icon) {
|
||||
|
||||
ERR_FAIL_INDEX(p_button,buttons.size());
|
||||
buttons[p_button].icon=p_icon;
|
||||
ERR_FAIL_INDEX(p_button, buttons.size());
|
||||
buttons[p_button].icon = p_icon;
|
||||
update();
|
||||
minimum_size_changed();
|
||||
}
|
||||
|
||||
String ButtonArray::get_button_text(int p_button) const {
|
||||
|
||||
ERR_FAIL_INDEX_V(p_button,buttons.size(),"");
|
||||
ERR_FAIL_INDEX_V(p_button, buttons.size(), "");
|
||||
return buttons[p_button].text;
|
||||
}
|
||||
|
||||
String ButtonArray::get_button_tooltip(int p_button) const {
|
||||
|
||||
ERR_FAIL_INDEX_V(p_button,buttons.size(),"");
|
||||
ERR_FAIL_INDEX_V(p_button, buttons.size(), "");
|
||||
return buttons[p_button].tooltip;
|
||||
}
|
||||
|
||||
Ref<Texture> ButtonArray::get_button_icon(int p_button) const {
|
||||
|
||||
ERR_FAIL_INDEX_V(p_button,buttons.size(),Ref<Texture>());
|
||||
ERR_FAIL_INDEX_V(p_button, buttons.size(), Ref<Texture>());
|
||||
return buttons[p_button].icon;
|
||||
|
||||
}
|
||||
|
||||
int ButtonArray::get_selected() const {
|
||||
|
|
@ -487,30 +459,29 @@ int ButtonArray::get_hovered() const {
|
|||
|
||||
void ButtonArray::set_selected(int p_selected) {
|
||||
|
||||
ERR_FAIL_INDEX(p_selected,buttons.size());
|
||||
selected=p_selected;
|
||||
ERR_FAIL_INDEX(p_selected, buttons.size());
|
||||
selected = p_selected;
|
||||
update();
|
||||
|
||||
}
|
||||
|
||||
void ButtonArray::erase_button(int p_button) {
|
||||
|
||||
ERR_FAIL_INDEX(p_button,buttons.size());
|
||||
ERR_FAIL_INDEX(p_button, buttons.size());
|
||||
buttons.remove(p_button);
|
||||
if (p_button>=selected)
|
||||
if (p_button >= selected)
|
||||
selected--;
|
||||
if (selected<0)
|
||||
selected=0;
|
||||
if (selected>=buttons.size())
|
||||
selected=buttons.size()-1;
|
||||
if (selected < 0)
|
||||
selected = 0;
|
||||
if (selected >= buttons.size())
|
||||
selected = buttons.size() - 1;
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void ButtonArray::clear(){
|
||||
void ButtonArray::clear() {
|
||||
|
||||
buttons.clear();
|
||||
selected=-1;
|
||||
selected = -1;
|
||||
update();
|
||||
}
|
||||
|
||||
|
|
@ -521,53 +492,50 @@ int ButtonArray::get_button_count() const {
|
|||
|
||||
void ButtonArray::get_translatable_strings(List<String> *p_strings) const {
|
||||
|
||||
|
||||
for(int i=0;i<buttons.size();i++) {
|
||||
for (int i = 0; i < buttons.size(); i++) {
|
||||
p_strings->push_back(buttons[i].text);
|
||||
p_strings->push_back(buttons[i].tooltip);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ButtonArray::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("add_button","text","tooltip"),&ButtonArray::add_button,DEFVAL(""));
|
||||
ObjectTypeDB::bind_method(_MD("add_icon_button","icon:Texture","text","tooltip"),&ButtonArray::add_icon_button,DEFVAL(""),DEFVAL(""));
|
||||
ObjectTypeDB::bind_method(_MD("set_button_text","button_idx","text"),&ButtonArray::set_button_text);
|
||||
ObjectTypeDB::bind_method(_MD("set_button_tooltip","button_idx","text"),&ButtonArray::set_button_tooltip);
|
||||
ObjectTypeDB::bind_method(_MD("set_button_icon","button_idx","icon:Texture"),&ButtonArray::set_button_icon);
|
||||
ObjectTypeDB::bind_method(_MD("get_button_text","button_idx"),&ButtonArray::get_button_text);
|
||||
ObjectTypeDB::bind_method(_MD("get_button_tooltip","button_idx"),&ButtonArray::get_button_tooltip);
|
||||
ObjectTypeDB::bind_method(_MD("get_button_icon:Texture","button_idx"),&ButtonArray::get_button_icon);
|
||||
ObjectTypeDB::bind_method(_MD("get_button_count"),&ButtonArray::get_button_count);
|
||||
ObjectTypeDB::bind_method(_MD("set_flat","enabled"),&ButtonArray::set_flat);
|
||||
ObjectTypeDB::bind_method(_MD("is_flat"),&ButtonArray::is_flat);
|
||||
ObjectTypeDB::bind_method(_MD("get_selected"),&ButtonArray::get_selected);
|
||||
ObjectTypeDB::bind_method(_MD("get_hovered"),&ButtonArray::get_hovered);
|
||||
ObjectTypeDB::bind_method(_MD("set_selected","button_idx"),&ButtonArray::set_selected);
|
||||
ObjectTypeDB::bind_method(_MD("erase_button","button_idx"),&ButtonArray::erase_button);
|
||||
ObjectTypeDB::bind_method(_MD("clear"),&ButtonArray::clear);
|
||||
ObjectTypeDB::bind_method(_MD("add_button", "text", "tooltip"), &ButtonArray::add_button, DEFVAL(""));
|
||||
ObjectTypeDB::bind_method(_MD("add_icon_button", "icon:Texture", "text", "tooltip"), &ButtonArray::add_icon_button, DEFVAL(""), DEFVAL(""));
|
||||
ObjectTypeDB::bind_method(_MD("set_button_text", "button_idx", "text"), &ButtonArray::set_button_text);
|
||||
ObjectTypeDB::bind_method(_MD("set_button_tooltip", "button_idx", "text"), &ButtonArray::set_button_tooltip);
|
||||
ObjectTypeDB::bind_method(_MD("set_button_icon", "button_idx", "icon:Texture"), &ButtonArray::set_button_icon);
|
||||
ObjectTypeDB::bind_method(_MD("get_button_text", "button_idx"), &ButtonArray::get_button_text);
|
||||
ObjectTypeDB::bind_method(_MD("get_button_tooltip", "button_idx"), &ButtonArray::get_button_tooltip);
|
||||
ObjectTypeDB::bind_method(_MD("get_button_icon:Texture", "button_idx"), &ButtonArray::get_button_icon);
|
||||
ObjectTypeDB::bind_method(_MD("get_button_count"), &ButtonArray::get_button_count);
|
||||
ObjectTypeDB::bind_method(_MD("set_flat", "enabled"), &ButtonArray::set_flat);
|
||||
ObjectTypeDB::bind_method(_MD("is_flat"), &ButtonArray::is_flat);
|
||||
ObjectTypeDB::bind_method(_MD("get_selected"), &ButtonArray::get_selected);
|
||||
ObjectTypeDB::bind_method(_MD("get_hovered"), &ButtonArray::get_hovered);
|
||||
ObjectTypeDB::bind_method(_MD("set_selected", "button_idx"), &ButtonArray::set_selected);
|
||||
ObjectTypeDB::bind_method(_MD("erase_button", "button_idx"), &ButtonArray::erase_button);
|
||||
ObjectTypeDB::bind_method(_MD("clear"), &ButtonArray::clear);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("_input_event"),&ButtonArray::_input_event);
|
||||
ObjectTypeDB::bind_method(_MD("_input_event"), &ButtonArray::_input_event);
|
||||
|
||||
BIND_CONSTANT( ALIGN_BEGIN );
|
||||
BIND_CONSTANT( ALIGN_CENTER );
|
||||
BIND_CONSTANT( ALIGN_END );
|
||||
BIND_CONSTANT( ALIGN_FILL );
|
||||
BIND_CONSTANT( ALIGN_EXPAND_FILL );
|
||||
BIND_CONSTANT(ALIGN_BEGIN);
|
||||
BIND_CONSTANT(ALIGN_CENTER);
|
||||
BIND_CONSTANT(ALIGN_END);
|
||||
BIND_CONSTANT(ALIGN_FILL);
|
||||
BIND_CONSTANT(ALIGN_EXPAND_FILL);
|
||||
|
||||
ADD_PROPERTY( PropertyInfo( Variant::BOOL, "flat" ), _SCS("set_flat"),_SCS("is_flat") );
|
||||
|
||||
ADD_SIGNAL( MethodInfo("button_selected",PropertyInfo(Variant::INT,"button_idx")));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "flat"), _SCS("set_flat"), _SCS("is_flat"));
|
||||
|
||||
ADD_SIGNAL(MethodInfo("button_selected", PropertyInfo(Variant::INT, "button_idx")));
|
||||
}
|
||||
|
||||
ButtonArray::ButtonArray(Orientation p_orientation) {
|
||||
|
||||
orientation=p_orientation;
|
||||
selected=-1;
|
||||
orientation = p_orientation;
|
||||
selected = -1;
|
||||
set_focus_mode(FOCUS_ALL);
|
||||
hover=-1;
|
||||
flat=false;
|
||||
hover = -1;
|
||||
flat = false;
|
||||
min_button_size = -1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@
|
|||
class ButtonArray : public Control {
|
||||
|
||||
OBJ_TYPE(ButtonArray, Control);
|
||||
|
||||
public:
|
||||
enum Align {
|
||||
ALIGN_BEGIN,
|
||||
|
|
@ -42,8 +43,8 @@ public:
|
|||
ALIGN_FILL,
|
||||
ALIGN_EXPAND_FILL
|
||||
};
|
||||
private:
|
||||
|
||||
private:
|
||||
Orientation orientation;
|
||||
Align align;
|
||||
|
||||
|
|
@ -64,19 +65,17 @@ private:
|
|||
double min_button_size;
|
||||
|
||||
Vector<Button> buttons;
|
||||
protected:
|
||||
|
||||
bool _set(const StringName& p_name, const Variant& p_value);
|
||||
bool _get(const StringName& p_name,Variant &r_ret) const;
|
||||
void _get_property_list( List<PropertyInfo> *p_list) const;
|
||||
protected:
|
||||
bool _set(const StringName &p_name, const Variant &p_value);
|
||||
bool _get(const StringName &p_name, Variant &r_ret) const;
|
||||
void _get_property_list(List<PropertyInfo> *p_list) const;
|
||||
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
|
||||
void _input_event(const InputEvent& p_event);
|
||||
|
||||
void _input_event(const InputEvent &p_event);
|
||||
|
||||
void set_align(Align p_align);
|
||||
Align get_align() const;
|
||||
|
|
@ -84,13 +83,12 @@ public:
|
|||
void set_flat(bool p_flat);
|
||||
bool is_flat() const;
|
||||
|
||||
void add_button(const String& p_button,const String& p_tooltip="");
|
||||
void add_icon_button(const Ref<Texture>& p_icon,const String& p_button="",const String& p_tooltip="");
|
||||
|
||||
void set_button_text(int p_button, const String& p_text);
|
||||
void set_button_tooltip(int p_button, const String& p_text);
|
||||
void set_button_icon(int p_button, const Ref<Texture>& p_icon);
|
||||
void add_button(const String &p_button, const String &p_tooltip = "");
|
||||
void add_icon_button(const Ref<Texture> &p_icon, const String &p_button = "", const String &p_tooltip = "");
|
||||
|
||||
void set_button_text(int p_button, const String &p_text);
|
||||
void set_button_tooltip(int p_button, const String &p_text);
|
||||
void set_button_icon(int p_button, const Ref<Texture> &p_icon);
|
||||
|
||||
String get_button_text(int p_button) const;
|
||||
String get_button_tooltip(int p_button) const;
|
||||
|
|
@ -108,25 +106,25 @@ public:
|
|||
virtual Size2 get_minimum_size() const;
|
||||
|
||||
virtual void get_translatable_strings(List<String> *p_strings) const;
|
||||
virtual String get_tooltip(const Point2& p_pos) const;
|
||||
virtual String get_tooltip(const Point2 &p_pos) const;
|
||||
|
||||
|
||||
ButtonArray(Orientation p_orientation=HORIZONTAL);
|
||||
ButtonArray(Orientation p_orientation = HORIZONTAL);
|
||||
};
|
||||
|
||||
class HButtonArray : public ButtonArray {
|
||||
OBJ_TYPE(HButtonArray,ButtonArray);
|
||||
public:
|
||||
OBJ_TYPE(HButtonArray, ButtonArray);
|
||||
|
||||
HButtonArray() : ButtonArray(HORIZONTAL) {};
|
||||
public:
|
||||
HButtonArray()
|
||||
: ButtonArray(HORIZONTAL){};
|
||||
};
|
||||
|
||||
class VButtonArray : public ButtonArray {
|
||||
OBJ_TYPE(VButtonArray,ButtonArray);
|
||||
public:
|
||||
OBJ_TYPE(VButtonArray, ButtonArray);
|
||||
|
||||
VButtonArray() : ButtonArray(VERTICAL) {};
|
||||
public:
|
||||
VButtonArray()
|
||||
: ButtonArray(VERTICAL){};
|
||||
};
|
||||
|
||||
|
||||
#endif // BUTTON_ARRAY_H
|
||||
|
|
|
|||
|
|
@ -34,15 +34,13 @@ void ButtonGroup::_add_button(BaseButton *p_button) {
|
|||
buttons.insert(p_button);
|
||||
p_button->set_toggle_mode(true);
|
||||
p_button->set_click_on_press(true);
|
||||
p_button->connect("pressed",this,"_pressed",make_binds(p_button));
|
||||
|
||||
p_button->connect("pressed", this, "_pressed", make_binds(p_button));
|
||||
}
|
||||
|
||||
void ButtonGroup::_remove_button(BaseButton *p_button){
|
||||
void ButtonGroup::_remove_button(BaseButton *p_button) {
|
||||
|
||||
buttons.erase(p_button);
|
||||
p_button->disconnect("pressed",this,"_pressed");
|
||||
|
||||
p_button->disconnect("pressed", this, "_pressed");
|
||||
}
|
||||
|
||||
void ButtonGroup::set_pressed_button(BaseButton *p_button) {
|
||||
|
|
@ -53,14 +51,14 @@ void ButtonGroup::set_pressed_button(BaseButton *p_button) {
|
|||
void ButtonGroup::_pressed(Object *p_button) {
|
||||
|
||||
ERR_FAIL_NULL(p_button);
|
||||
BaseButton *b=p_button->cast_to<BaseButton>();
|
||||
BaseButton *b = p_button->cast_to<BaseButton>();
|
||||
ERR_FAIL_COND(!b);
|
||||
|
||||
for(Set<BaseButton*>::Element *E=buttons.front();E;E=E->next()) {
|
||||
for (Set<BaseButton *>::Element *E = buttons.front(); E; E = E->next()) {
|
||||
|
||||
BaseButton *bb=E->get();
|
||||
bb->set_pressed( b==bb );
|
||||
if (b==bb){
|
||||
BaseButton *bb = E->get();
|
||||
bb->set_pressed(b == bb);
|
||||
if (b == bb) {
|
||||
emit_signal("button_selected", b);
|
||||
}
|
||||
}
|
||||
|
|
@ -68,7 +66,7 @@ void ButtonGroup::_pressed(Object *p_button) {
|
|||
|
||||
Array ButtonGroup::_get_button_list() const {
|
||||
|
||||
List<BaseButton*> b;
|
||||
List<BaseButton *> b;
|
||||
get_button_list(&b);
|
||||
|
||||
b.sort_custom<Node::Comparator>();
|
||||
|
|
@ -76,19 +74,19 @@ Array ButtonGroup::_get_button_list() const {
|
|||
Array arr;
|
||||
arr.resize(b.size());
|
||||
|
||||
int idx=0;
|
||||
int idx = 0;
|
||||
|
||||
for(List<BaseButton*>::Element *E=b.front();E;E=E->next(),idx++) {
|
||||
for (List<BaseButton *>::Element *E = b.front(); E; E = E->next(), idx++) {
|
||||
|
||||
arr[idx]=E->get();
|
||||
arr[idx] = E->get();
|
||||
}
|
||||
|
||||
return arr;
|
||||
}
|
||||
|
||||
void ButtonGroup::get_button_list(List<BaseButton*> *p_buttons) const {
|
||||
void ButtonGroup::get_button_list(List<BaseButton *> *p_buttons) const {
|
||||
|
||||
for(Set<BaseButton*>::Element *E=buttons.front();E;E=E->next()) {
|
||||
for (Set<BaseButton *>::Element *E = buttons.front(); E; E = E->next()) {
|
||||
|
||||
p_buttons->push_back(E->get());
|
||||
}
|
||||
|
|
@ -96,7 +94,7 @@ void ButtonGroup::get_button_list(List<BaseButton*> *p_buttons) const {
|
|||
|
||||
BaseButton *ButtonGroup::get_pressed_button() const {
|
||||
|
||||
for(Set<BaseButton*>::Element *E=buttons.front();E;E=E->next()) {
|
||||
for (Set<BaseButton *>::Element *E = buttons.front(); E; E = E->next()) {
|
||||
|
||||
if (E->get()->is_pressed())
|
||||
return E->get();
|
||||
|
|
@ -105,40 +103,38 @@ BaseButton *ButtonGroup::get_pressed_button() const {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
BaseButton *ButtonGroup::get_focused_button() const{
|
||||
BaseButton *ButtonGroup::get_focused_button() const {
|
||||
|
||||
for(Set<BaseButton*>::Element *E=buttons.front();E;E=E->next()) {
|
||||
for (Set<BaseButton *>::Element *E = buttons.front(); E; E = E->next()) {
|
||||
|
||||
if (E->get()->has_focus())
|
||||
return E->get();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
int ButtonGroup::get_pressed_button_index() const {
|
||||
//in tree order, this is bizarre
|
||||
|
||||
ERR_FAIL_COND_V(!is_inside_tree(),0);
|
||||
ERR_FAIL_COND_V(!is_inside_tree(), 0);
|
||||
|
||||
BaseButton *pressed = get_pressed_button();
|
||||
if (!pressed)
|
||||
return -1;
|
||||
|
||||
List<BaseButton*> blist;
|
||||
for(Set<BaseButton*>::Element *E=buttons.front();E;E=E->next()) {
|
||||
List<BaseButton *> blist;
|
||||
for (Set<BaseButton *>::Element *E = buttons.front(); E; E = E->next()) {
|
||||
|
||||
blist.push_back(E->get());
|
||||
|
||||
}
|
||||
|
||||
blist.sort_custom<Node::Comparator>();
|
||||
|
||||
int idx=0;
|
||||
for(List<BaseButton*>::Element *E=blist.front();E;E=E->next()) {
|
||||
int idx = 0;
|
||||
for (List<BaseButton *>::Element *E = blist.front(); E; E = E->next()) {
|
||||
|
||||
if (E->get()==pressed)
|
||||
if (E->get() == pressed)
|
||||
return idx;
|
||||
|
||||
idx++;
|
||||
|
|
@ -149,16 +145,16 @@ int ButtonGroup::get_pressed_button_index() const {
|
|||
|
||||
void ButtonGroup::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("get_pressed_button:BaseButton"),&ButtonGroup::get_pressed_button);
|
||||
ObjectTypeDB::bind_method(_MD("get_pressed_button_index"),&ButtonGroup::get_pressed_button_index);
|
||||
ObjectTypeDB::bind_method(_MD("get_focused_button:BaseButton"),&ButtonGroup::get_focused_button);
|
||||
ObjectTypeDB::bind_method(_MD("get_button_list"),&ButtonGroup::_get_button_list);
|
||||
ObjectTypeDB::bind_method(_MD("_pressed"),&ButtonGroup::_pressed);
|
||||
ObjectTypeDB::bind_method(_MD("set_pressed_button","button:BaseButton"),&ButtonGroup::_pressed);
|
||||
ObjectTypeDB::bind_method(_MD("get_pressed_button:BaseButton"), &ButtonGroup::get_pressed_button);
|
||||
ObjectTypeDB::bind_method(_MD("get_pressed_button_index"), &ButtonGroup::get_pressed_button_index);
|
||||
ObjectTypeDB::bind_method(_MD("get_focused_button:BaseButton"), &ButtonGroup::get_focused_button);
|
||||
ObjectTypeDB::bind_method(_MD("get_button_list"), &ButtonGroup::_get_button_list);
|
||||
ObjectTypeDB::bind_method(_MD("_pressed"), &ButtonGroup::_pressed);
|
||||
ObjectTypeDB::bind_method(_MD("set_pressed_button", "button:BaseButton"), &ButtonGroup::_pressed);
|
||||
|
||||
ADD_SIGNAL( MethodInfo("button_selected",PropertyInfo(Variant::OBJECT,"button",PROPERTY_HINT_RESOURCE_TYPE,"BaseButton")));
|
||||
ADD_SIGNAL(MethodInfo("button_selected", PropertyInfo(Variant::OBJECT, "button", PROPERTY_HINT_RESOURCE_TYPE, "BaseButton")));
|
||||
}
|
||||
|
||||
ButtonGroup::ButtonGroup() : BoxContainer(true)
|
||||
{
|
||||
ButtonGroup::ButtonGroup()
|
||||
: BoxContainer(true) {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,30 +31,27 @@
|
|||
|
||||
#include "scene/gui/box_container.h"
|
||||
|
||||
|
||||
class BaseButton;
|
||||
|
||||
class ButtonGroup : public BoxContainer {
|
||||
|
||||
OBJ_TYPE(ButtonGroup,BoxContainer);
|
||||
|
||||
|
||||
Set<BaseButton*> buttons;
|
||||
OBJ_TYPE(ButtonGroup, BoxContainer);
|
||||
|
||||
Set<BaseButton *> buttons;
|
||||
|
||||
Array _get_button_list() const;
|
||||
void _pressed(Object *p_button);
|
||||
|
||||
protected:
|
||||
friend class BaseButton;
|
||||
friend class BaseButton;
|
||||
|
||||
void _add_button(BaseButton *p_button);
|
||||
void _remove_button(BaseButton *p_button);
|
||||
|
||||
static void _bind_methods();
|
||||
public:
|
||||
|
||||
void get_button_list(List<BaseButton*> *p_buttons) const;
|
||||
public:
|
||||
void get_button_list(List<BaseButton *> *p_buttons) const;
|
||||
BaseButton *get_pressed_button() const;
|
||||
BaseButton *get_focused_button() const;
|
||||
void set_pressed_button(BaseButton *p_button);
|
||||
|
|
|
|||
|
|
@ -28,14 +28,12 @@
|
|||
/*************************************************************************/
|
||||
#include "center_container.h"
|
||||
|
||||
|
||||
Size2 CenterContainer::get_minimum_size() const {
|
||||
|
||||
|
||||
if (use_top_left)
|
||||
return Size2();
|
||||
Size2 ms;
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c)
|
||||
|
|
@ -45,22 +43,17 @@ Size2 CenterContainer::get_minimum_size() const {
|
|||
if (c->is_hidden())
|
||||
continue;
|
||||
Size2 minsize = c->get_combined_minimum_size();
|
||||
ms.width = MAX(ms.width , minsize.width);
|
||||
ms.height = MAX(ms.height , minsize.height);
|
||||
|
||||
|
||||
ms.width = MAX(ms.width, minsize.width);
|
||||
ms.height = MAX(ms.height, minsize.height);
|
||||
}
|
||||
|
||||
return ms;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void CenterContainer::set_use_top_left(bool p_enable) {
|
||||
|
||||
use_top_left=p_enable;
|
||||
use_top_left = p_enable;
|
||||
queue_sort();
|
||||
|
||||
}
|
||||
|
||||
bool CenterContainer::is_using_top_left() const {
|
||||
|
|
@ -68,13 +61,12 @@ bool CenterContainer::is_using_top_left() const {
|
|||
return use_top_left;
|
||||
}
|
||||
|
||||
|
||||
void CenterContainer::_notification(int p_what) {
|
||||
|
||||
if (p_what==NOTIFICATION_SORT_CHILDREN) {
|
||||
if (p_what == NOTIFICATION_SORT_CHILDREN) {
|
||||
|
||||
Size2 size = get_size();
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c)
|
||||
|
|
@ -83,22 +75,21 @@ void CenterContainer::_notification(int p_what) {
|
|||
continue;
|
||||
|
||||
Size2 minsize = c->get_combined_minimum_size();
|
||||
Point2 ofs = use_top_left ? (-minsize*0.5).floor() : ((size - minsize)/2.0).floor();
|
||||
fit_child_in_rect(c,Rect2(ofs,minsize));
|
||||
|
||||
Point2 ofs = use_top_left ? (-minsize * 0.5).floor() : ((size - minsize) / 2.0).floor();
|
||||
fit_child_in_rect(c, Rect2(ofs, minsize));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CenterContainer::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_use_top_left","enable"),&CenterContainer::set_use_top_left);
|
||||
ObjectTypeDB::bind_method(_MD("is_using_top_left"),&CenterContainer::is_using_top_left);
|
||||
ObjectTypeDB::bind_method(_MD("set_use_top_left", "enable"), &CenterContainer::set_use_top_left);
|
||||
ObjectTypeDB::bind_method(_MD("is_using_top_left"), &CenterContainer::is_using_top_left);
|
||||
|
||||
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"use_top_left"),_SCS("set_use_top_left"),_SCS("is_using_top_left"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_top_left"), _SCS("set_use_top_left"), _SCS("is_using_top_left"));
|
||||
}
|
||||
|
||||
CenterContainer::CenterContainer() {
|
||||
|
||||
use_top_left=false;
|
||||
use_top_left = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,20 +29,19 @@
|
|||
#ifndef CENTER_CONTAINER_H
|
||||
#define CENTER_CONTAINER_H
|
||||
|
||||
|
||||
#include "scene/gui/container.h"
|
||||
|
||||
class CenterContainer : public Container {
|
||||
|
||||
OBJ_TYPE( CenterContainer, Container );
|
||||
OBJ_TYPE(CenterContainer, Container);
|
||||
|
||||
bool use_top_left;
|
||||
protected:
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
public:
|
||||
|
||||
public:
|
||||
void set_use_top_left(bool p_enable);
|
||||
bool is_using_top_left() const;
|
||||
|
||||
|
|
|
|||
|
|
@ -28,52 +28,45 @@
|
|||
/*************************************************************************/
|
||||
#include "check_box.h"
|
||||
|
||||
#include "servers/visual_server.h"
|
||||
#include "button_group.h"
|
||||
|
||||
#include "servers/visual_server.h"
|
||||
|
||||
void CheckBox::_notification(int p_what) {
|
||||
|
||||
if (p_what==NOTIFICATION_DRAW) {
|
||||
if (p_what == NOTIFICATION_DRAW) {
|
||||
|
||||
RID ci = get_canvas_item();
|
||||
RID ci = get_canvas_item();
|
||||
|
||||
Ref<Texture> on=Control::get_icon(is_radio() ? "radio_checked" : "checked");
|
||||
Ref<Texture> off=Control::get_icon(is_radio() ? "radio_unchecked" : "unchecked");
|
||||
Ref<Texture> on = Control::get_icon(is_radio() ? "radio_checked" : "checked");
|
||||
Ref<Texture> off = Control::get_icon(is_radio() ? "radio_unchecked" : "unchecked");
|
||||
|
||||
Vector2 ofs;
|
||||
ofs.x = 0;
|
||||
ofs.y = int((get_size().height - on->get_height())/2);
|
||||
Vector2 ofs;
|
||||
ofs.x = 0;
|
||||
ofs.y = int((get_size().height - on->get_height()) / 2);
|
||||
|
||||
if (is_pressed())
|
||||
on->draw(ci,ofs);
|
||||
else
|
||||
off->draw(ci,ofs);
|
||||
|
||||
|
||||
}
|
||||
if (is_pressed())
|
||||
on->draw(ci, ofs);
|
||||
else
|
||||
off->draw(ci, ofs);
|
||||
}
|
||||
}
|
||||
|
||||
bool CheckBox::is_radio()
|
||||
{
|
||||
Node* parent = this;
|
||||
do {
|
||||
parent = parent->get_parent();
|
||||
if (parent->cast_to<ButtonGroup>())
|
||||
break;
|
||||
} while (parent);
|
||||
bool CheckBox::is_radio() {
|
||||
Node *parent = this;
|
||||
do {
|
||||
parent = parent->get_parent();
|
||||
if (parent->cast_to<ButtonGroup>())
|
||||
break;
|
||||
} while (parent);
|
||||
|
||||
return (parent != 0);
|
||||
return (parent != 0);
|
||||
}
|
||||
|
||||
CheckBox::CheckBox(const String &p_text):
|
||||
Button(p_text)
|
||||
{
|
||||
set_toggle_mode(true);
|
||||
set_text_align(ALIGN_LEFT);
|
||||
|
||||
CheckBox::CheckBox(const String &p_text)
|
||||
: Button(p_text) {
|
||||
set_toggle_mode(true);
|
||||
set_text_align(ALIGN_LEFT);
|
||||
}
|
||||
|
||||
CheckBox::~CheckBox()
|
||||
{
|
||||
CheckBox::~CheckBox() {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,27 +29,22 @@
|
|||
#ifndef CHECK_BOX_H
|
||||
#define CHECK_BOX_H
|
||||
|
||||
|
||||
#include "scene/gui/button.h"
|
||||
/**
|
||||
@author Mariano Suligoy <marianognu.esyrpg@gmail.com>
|
||||
*/
|
||||
class CheckBox : public Button {
|
||||
|
||||
OBJ_TYPE( CheckBox, Button );
|
||||
|
||||
OBJ_TYPE(CheckBox, Button);
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
|
||||
bool is_radio();
|
||||
void _notification(int p_what);
|
||||
|
||||
bool is_radio();
|
||||
|
||||
public:
|
||||
|
||||
CheckBox(const String& p_text=String());
|
||||
~CheckBox();
|
||||
|
||||
CheckBox(const String &p_text = String());
|
||||
~CheckBox();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -28,45 +28,34 @@
|
|||
/*************************************************************************/
|
||||
#include "check_button.h"
|
||||
|
||||
#include "servers/visual_server.h"
|
||||
#include "print_string.h"
|
||||
|
||||
#include "servers/visual_server.h"
|
||||
|
||||
void CheckButton::_notification(int p_what) {
|
||||
|
||||
if (p_what==NOTIFICATION_DRAW) {
|
||||
if (p_what == NOTIFICATION_DRAW) {
|
||||
|
||||
RID ci = get_canvas_item();
|
||||
|
||||
Ref<Texture> on=Control::get_icon("on");
|
||||
Ref<Texture> off=Control::get_icon("off");
|
||||
Ref<Texture> on = Control::get_icon("on");
|
||||
Ref<Texture> off = Control::get_icon("off");
|
||||
|
||||
Vector2 ofs;
|
||||
ofs.x = get_size().width - on->get_width();
|
||||
ofs.y = int((get_size().height - on->get_height())/2);
|
||||
ofs.y = int((get_size().height - on->get_height()) / 2);
|
||||
|
||||
if (is_pressed())
|
||||
on->draw(ci,ofs);
|
||||
on->draw(ci, ofs);
|
||||
else
|
||||
off->draw(ci,ofs);
|
||||
|
||||
|
||||
off->draw(ci, ofs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CheckButton::CheckButton() {
|
||||
|
||||
set_toggle_mode(true);
|
||||
set_text_align(ALIGN_LEFT);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
CheckButton::~CheckButton()
|
||||
{
|
||||
CheckButton::~CheckButton() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -29,24 +29,20 @@
|
|||
#ifndef CHECK_BUTTON_H
|
||||
#define CHECK_BUTTON_H
|
||||
|
||||
|
||||
#include "scene/gui/button.h"
|
||||
/**
|
||||
@author Juan Linietsky <reduzio@gmail.com>
|
||||
*/
|
||||
class CheckButton : public Button {
|
||||
|
||||
OBJ_TYPE( CheckButton, Button );
|
||||
|
||||
OBJ_TYPE(CheckButton, Button);
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
|
||||
public:
|
||||
|
||||
CheckButton();
|
||||
~CheckButton();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -28,51 +28,48 @@
|
|||
/*************************************************************************/
|
||||
#include "color_picker.h"
|
||||
|
||||
#include "scene/gui/separator.h"
|
||||
#include "scene/main/viewport.h"
|
||||
#include "os/os.h"
|
||||
#include "os/input.h"
|
||||
#include "os/keyboard.h"
|
||||
#include "os/os.h"
|
||||
#include "scene/gui/separator.h"
|
||||
#include "scene/main/viewport.h"
|
||||
|
||||
void update_material(Ref<CanvasItemMaterial>mat,const Color& p_color,float h,float s,float v) {
|
||||
void update_material(Ref<CanvasItemMaterial> mat, const Color &p_color, float h, float s, float v) {
|
||||
if (!mat.is_valid())
|
||||
return;
|
||||
Ref<Shader> sdr = mat->get_shader();
|
||||
if (!sdr.is_valid())
|
||||
return;
|
||||
|
||||
mat->set_shader_param("R",p_color.r);
|
||||
mat->set_shader_param("G",p_color.g);
|
||||
mat->set_shader_param("B",p_color.b);
|
||||
mat->set_shader_param("H",h);
|
||||
mat->set_shader_param("S",s);
|
||||
mat->set_shader_param("V",v);
|
||||
mat->set_shader_param("A",p_color.a);
|
||||
mat->set_shader_param("R", p_color.r);
|
||||
mat->set_shader_param("G", p_color.g);
|
||||
mat->set_shader_param("B", p_color.b);
|
||||
mat->set_shader_param("H", h);
|
||||
mat->set_shader_param("S", s);
|
||||
mat->set_shader_param("V", v);
|
||||
mat->set_shader_param("A", p_color.a);
|
||||
}
|
||||
|
||||
void ColorPicker::_notification(int p_what) {
|
||||
|
||||
|
||||
switch(p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_THEME_CHANGED: {
|
||||
uv_material->set_shader(get_shader("uv_editor"));
|
||||
w_material->set_shader(get_shader("w_editor"));
|
||||
update_material(uv_material,color,h,s,v);
|
||||
update_material(w_material,color,h,s,v);
|
||||
update_material(uv_material, color, h, s, v);
|
||||
update_material(w_material, color, h, s, v);
|
||||
_update_controls();
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_ENTER_TREE: {
|
||||
btn_pick->set_icon(get_icon("screen_picker", "ColorPicker"));
|
||||
update_material(uv_material, color,h,s,v);
|
||||
update_material(w_material, color,h,s,v);
|
||||
update_material(uv_material, color, h, s, v);
|
||||
update_material(w_material, color, h, s, v);
|
||||
|
||||
uv_edit->get_child(0)->cast_to<Control>()->update();
|
||||
w_edit->get_child(0)->cast_to<Control>()->update();
|
||||
_update_color();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -93,34 +90,32 @@ void ColorPicker::_update_controls() {
|
|||
scroll[3]->hide();
|
||||
labels[3]->hide();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ColorPicker::set_color(const Color& p_color) {
|
||||
void ColorPicker::set_color(const Color &p_color) {
|
||||
|
||||
color=p_color;
|
||||
color = p_color;
|
||||
if (color != last_hsv) {
|
||||
h=color.get_h();
|
||||
s=color.get_s();
|
||||
v=color.get_v();
|
||||
h = color.get_h();
|
||||
s = color.get_s();
|
||||
v = color.get_v();
|
||||
last_hsv = color;
|
||||
}
|
||||
|
||||
if (!is_inside_tree())
|
||||
return;
|
||||
|
||||
update_material(uv_material, color,h,s,v);
|
||||
update_material(w_material, color,h,s,v);
|
||||
update_material(uv_material, color, h, s, v);
|
||||
update_material(w_material, color, h, s, v);
|
||||
|
||||
uv_edit->get_child(0)->cast_to<Control>()->update();
|
||||
w_edit->get_child(0)->cast_to<Control>()->update();
|
||||
_update_color();
|
||||
|
||||
}
|
||||
|
||||
void ColorPicker::set_edit_alpha(bool p_show) {
|
||||
|
||||
edit_alpha=p_show;
|
||||
edit_alpha = p_show;
|
||||
_update_controls();
|
||||
|
||||
if (!is_inside_tree())
|
||||
|
|
@ -140,19 +135,18 @@ void ColorPicker::_value_changed(double) {
|
|||
if (updating)
|
||||
return;
|
||||
|
||||
for(int i=0;i<4;i++) {
|
||||
color.components[i] = scroll[i]->get_val()/(raw_mode_enabled?1.0:255.0);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
color.components[i] = scroll[i]->get_val() / (raw_mode_enabled ? 1.0 : 255.0);
|
||||
}
|
||||
|
||||
set_color(color);
|
||||
|
||||
_update_text_value();
|
||||
|
||||
emit_signal("color_changed",color);
|
||||
|
||||
emit_signal("color_changed", color);
|
||||
}
|
||||
|
||||
void ColorPicker::_html_entered(const String& p_html) {
|
||||
void ColorPicker::_html_entered(const String &p_html) {
|
||||
|
||||
if (updating)
|
||||
return;
|
||||
|
|
@ -163,14 +157,14 @@ void ColorPicker::_html_entered(const String& p_html) {
|
|||
return;
|
||||
|
||||
set_color(color);
|
||||
emit_signal("color_changed",color);
|
||||
emit_signal("color_changed", color);
|
||||
}
|
||||
|
||||
void ColorPicker::_update_color() {
|
||||
|
||||
updating=true;
|
||||
updating = true;
|
||||
|
||||
for(int i=0;i<4;i++) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
scroll[i]->set_max(255);
|
||||
scroll[i]->set_step(0.01);
|
||||
if (raw_mode_enabled) {
|
||||
|
|
@ -185,25 +179,23 @@ void ColorPicker::_update_color() {
|
|||
_update_text_value();
|
||||
|
||||
sample->update();
|
||||
updating=false;
|
||||
updating = false;
|
||||
}
|
||||
|
||||
void ColorPicker::_update_presets()
|
||||
{
|
||||
Size2 size=bt_add_preset->get_size();
|
||||
preset->set_custom_minimum_size(Size2(size.width*presets.size(),size.height));
|
||||
Image i(size.x*presets.size(),size.y, false, Image::FORMAT_RGB);
|
||||
for (int y=0;y<size.y;y++)
|
||||
for (int x=0;x<size.x*presets.size();x++)
|
||||
i.put_pixel(x,y,presets[(int)x/size.x]);
|
||||
void ColorPicker::_update_presets() {
|
||||
Size2 size = bt_add_preset->get_size();
|
||||
preset->set_custom_minimum_size(Size2(size.width * presets.size(), size.height));
|
||||
Image i(size.x * presets.size(), size.y, false, Image::FORMAT_RGB);
|
||||
for (int y = 0; y < size.y; y++)
|
||||
for (int x = 0; x < size.x * presets.size(); x++)
|
||||
i.put_pixel(x, y, presets[(int)x / size.x]);
|
||||
Ref<ImageTexture> t;
|
||||
t.instance();
|
||||
t->create_from_image(i);
|
||||
preset->set_texture(t);
|
||||
}
|
||||
|
||||
void ColorPicker::_text_type_toggled()
|
||||
{
|
||||
void ColorPicker::_text_type_toggled() {
|
||||
if (!get_tree()->is_editor_hint())
|
||||
return;
|
||||
text_is_constructor = !text_is_constructor;
|
||||
|
|
@ -222,25 +214,23 @@ Color ColorPicker::get_color() const {
|
|||
return color;
|
||||
}
|
||||
|
||||
void ColorPicker::add_preset(const Color &p_color)
|
||||
{
|
||||
void ColorPicker::add_preset(const Color &p_color) {
|
||||
if (presets.find(p_color)) {
|
||||
presets.move_to_back(presets.find(p_color));
|
||||
} else {
|
||||
presets.push_back(p_color);
|
||||
}
|
||||
_update_presets();
|
||||
if (presets.size()==10)
|
||||
if (presets.size() == 10)
|
||||
bt_add_preset->hide();
|
||||
}
|
||||
|
||||
|
||||
void ColorPicker::set_raw_mode(bool p_enabled) {
|
||||
|
||||
if (raw_mode_enabled==p_enabled)
|
||||
if (raw_mode_enabled == p_enabled)
|
||||
return;
|
||||
raw_mode_enabled=p_enabled;
|
||||
if (btn_mode->is_pressed()!=p_enabled)
|
||||
raw_mode_enabled = p_enabled;
|
||||
if (btn_mode->is_pressed() != p_enabled)
|
||||
btn_mode->set_pressed(p_enabled);
|
||||
|
||||
if (!is_inside_tree())
|
||||
|
|
@ -255,54 +245,52 @@ bool ColorPicker::is_raw_mode() const {
|
|||
return raw_mode_enabled;
|
||||
}
|
||||
|
||||
|
||||
void ColorPicker::_update_text_value() {
|
||||
if (text_is_constructor) {
|
||||
String t = "Color("+String::num(color.r)+","+String::num(color.g)+","+String::num(color.b);
|
||||
if (edit_alpha && color.a<1)
|
||||
t+=(","+String::num(color.a)+")") ;
|
||||
String t = "Color(" + String::num(color.r) + "," + String::num(color.g) + "," + String::num(color.b);
|
||||
if (edit_alpha && color.a < 1)
|
||||
t += ("," + String::num(color.a) + ")");
|
||||
else
|
||||
t+=")";
|
||||
t += ")";
|
||||
c_text->set_text(t);
|
||||
} else {
|
||||
c_text->set_text(color.to_html(edit_alpha && color.a<1));
|
||||
c_text->set_text(color.to_html(edit_alpha && color.a < 1));
|
||||
}
|
||||
}
|
||||
|
||||
void ColorPicker::_sample_draw() {
|
||||
sample->draw_rect(Rect2(Point2(),Size2(256,20)),color);
|
||||
sample->draw_rect(Rect2(Point2(), Size2(256, 20)), color);
|
||||
}
|
||||
|
||||
void ColorPicker::_hsv_draw(int p_wich,Control* c)
|
||||
{
|
||||
void ColorPicker::_hsv_draw(int p_wich, Control *c) {
|
||||
if (!c)
|
||||
return;
|
||||
if (p_wich==0) {
|
||||
if (p_wich == 0) {
|
||||
int x = CLAMP(c->get_size().x * s, 0, c->get_size().x);
|
||||
int y = CLAMP(c->get_size().y-c->get_size().y * v, 0, c->get_size().y);
|
||||
int y = CLAMP(c->get_size().y - c->get_size().y * v, 0, c->get_size().y);
|
||||
Color col = color;
|
||||
col.a=1;
|
||||
c->draw_line(Point2(x,0),Point2(x,c->get_size().y),col.inverted());
|
||||
c->draw_line(Point2(0, y),Point2(c->get_size().x, y),col.inverted());
|
||||
c->draw_line(Point2(x,y),Point2(x,y),Color(1,1,1),2);
|
||||
} else if (p_wich==1) {
|
||||
int y=c->get_size().y-c->get_size().y*h;
|
||||
Color col=Color();
|
||||
col.set_hsv(h,1,1);
|
||||
c->draw_line(Point2(0,y),Point2(c->get_size().x,y),col.inverted());
|
||||
col.a = 1;
|
||||
c->draw_line(Point2(x, 0), Point2(x, c->get_size().y), col.inverted());
|
||||
c->draw_line(Point2(0, y), Point2(c->get_size().x, y), col.inverted());
|
||||
c->draw_line(Point2(x, y), Point2(x, y), Color(1, 1, 1), 2);
|
||||
} else if (p_wich == 1) {
|
||||
int y = c->get_size().y - c->get_size().y * h;
|
||||
Color col = Color();
|
||||
col.set_hsv(h, 1, 1);
|
||||
c->draw_line(Point2(0, y), Point2(c->get_size().x, y), col.inverted());
|
||||
}
|
||||
}
|
||||
|
||||
void ColorPicker::_uv_input(const InputEvent &ev) {
|
||||
if (ev.type == InputEvent::MOUSE_BUTTON) {
|
||||
const InputEventMouseButton &bev = ev.mouse_button;
|
||||
if (bev.pressed && bev.button_index==BUTTON_LEFT) {
|
||||
if (bev.pressed && bev.button_index == BUTTON_LEFT) {
|
||||
changing_color = true;
|
||||
float x = CLAMP((float)bev.x,0,256);
|
||||
float y = CLAMP((float)bev.y,0,256);
|
||||
s=x/256;
|
||||
v=1.0-y/256.0;
|
||||
color.set_hsv(h,s,v,color.a);
|
||||
float x = CLAMP((float)bev.x, 0, 256);
|
||||
float y = CLAMP((float)bev.y, 0, 256);
|
||||
s = x / 256;
|
||||
v = 1.0 - y / 256.0;
|
||||
color.set_hsv(h, s, v, color.a);
|
||||
last_hsv = color;
|
||||
set_color(color);
|
||||
_update_color();
|
||||
|
|
@ -314,11 +302,11 @@ void ColorPicker::_uv_input(const InputEvent &ev) {
|
|||
const InputEventMouse &bev = ev.mouse_motion;
|
||||
if (!changing_color)
|
||||
return;
|
||||
float x = CLAMP((float)bev.x,0,256);
|
||||
float y = CLAMP((float)bev.y,0,256);
|
||||
s=x/256;
|
||||
v=1.0-y/256.0;
|
||||
color.set_hsv(h,s,v,color.a);
|
||||
float x = CLAMP((float)bev.x, 0, 256);
|
||||
float y = CLAMP((float)bev.y, 0, 256);
|
||||
s = x / 256;
|
||||
v = 1.0 - y / 256.0;
|
||||
color.set_hsv(h, s, v, color.a);
|
||||
last_hsv = color;
|
||||
set_color(color);
|
||||
_update_color();
|
||||
|
|
@ -329,14 +317,14 @@ void ColorPicker::_uv_input(const InputEvent &ev) {
|
|||
void ColorPicker::_w_input(const InputEvent &ev) {
|
||||
if (ev.type == InputEvent::MOUSE_BUTTON) {
|
||||
const InputEventMouseButton &bev = ev.mouse_button;
|
||||
if (bev.pressed && bev.button_index==BUTTON_LEFT) {
|
||||
if (bev.pressed && bev.button_index == BUTTON_LEFT) {
|
||||
changing_color = true;
|
||||
h=1-((float)bev.y)/256.0;
|
||||
h = 1 - ((float)bev.y) / 256.0;
|
||||
|
||||
} else {
|
||||
changing_color = false;
|
||||
}
|
||||
color.set_hsv(h,s,v,color.a);
|
||||
color.set_hsv(h, s, v, color.a);
|
||||
last_hsv = color;
|
||||
set_color(color);
|
||||
_update_color();
|
||||
|
|
@ -345,9 +333,9 @@ void ColorPicker::_w_input(const InputEvent &ev) {
|
|||
const InputEventMouse &bev = ev.mouse_motion;
|
||||
if (!changing_color)
|
||||
return;
|
||||
float y = CLAMP((float)bev.y,0,256);
|
||||
h=1.0-y/256.0;
|
||||
color.set_hsv(h,s,v,color.a);
|
||||
float y = CLAMP((float)bev.y, 0, 256);
|
||||
h = 1.0 - y / 256.0;
|
||||
color.set_hsv(h, s, v, color.a);
|
||||
last_hsv = color;
|
||||
set_color(color);
|
||||
_update_color();
|
||||
|
|
@ -358,11 +346,11 @@ void ColorPicker::_w_input(const InputEvent &ev) {
|
|||
void ColorPicker::_preset_input(const InputEvent &ev) {
|
||||
if (ev.type == InputEvent::MOUSE_BUTTON) {
|
||||
const InputEventMouseButton &bev = ev.mouse_button;
|
||||
if (bev.pressed && bev.button_index==BUTTON_LEFT) {
|
||||
int index = bev.x/(preset->get_size().x/presets.size());
|
||||
if (bev.pressed && bev.button_index == BUTTON_LEFT) {
|
||||
int index = bev.x / (preset->get_size().x / presets.size());
|
||||
set_color(presets[index]);
|
||||
} else if (bev.pressed && bev.button_index==BUTTON_RIGHT) {
|
||||
int index = bev.x/(preset->get_size().x/presets.size());
|
||||
} else if (bev.pressed && bev.button_index == BUTTON_RIGHT) {
|
||||
int index = bev.x / (preset->get_size().x / presets.size());
|
||||
presets.erase(presets[index]);
|
||||
_update_presets();
|
||||
bt_add_preset->show();
|
||||
|
|
@ -372,36 +360,35 @@ void ColorPicker::_preset_input(const InputEvent &ev) {
|
|||
} else if (ev.type == InputEvent::MOUSE_MOTION) {
|
||||
const InputEventMouse &mev = ev.mouse_motion;
|
||||
int index = mev.x * presets.size();
|
||||
if( preset->get_size().x != 0 ) {
|
||||
if (preset->get_size().x != 0) {
|
||||
index /= preset->get_size().x;
|
||||
}
|
||||
if (index<0 || index >= presets.size())
|
||||
if (index < 0 || index >= presets.size())
|
||||
return;
|
||||
preset->set_tooltip("Color: #"+presets[index].to_html(presets[index].a<1)+"\n"
|
||||
"LMB: Set color\n"
|
||||
"RMB: Remove preset");
|
||||
preset->set_tooltip("Color: #" + presets[index].to_html(presets[index].a < 1) + "\n"
|
||||
"LMB: Set color\n"
|
||||
"RMB: Remove preset");
|
||||
}
|
||||
}
|
||||
|
||||
void ColorPicker::_screen_input(const InputEvent &ev)
|
||||
{
|
||||
if (ev.type==InputEvent::MOUSE_BUTTON) {
|
||||
void ColorPicker::_screen_input(const InputEvent &ev) {
|
||||
if (ev.type == InputEvent::MOUSE_BUTTON) {
|
||||
const InputEventMouseButton &bev = ev.mouse_button;
|
||||
if (bev.button_index==BUTTON_LEFT&&!bev.pressed) {
|
||||
if (bev.button_index == BUTTON_LEFT && !bev.pressed) {
|
||||
emit_signal("color_changed", color);
|
||||
screen->hide();
|
||||
}
|
||||
} else if (ev.type==InputEvent::MOUSE_MOTION) {
|
||||
} else if (ev.type == InputEvent::MOUSE_MOTION) {
|
||||
const InputEventMouse &mev = ev.mouse_motion;
|
||||
Viewport *r=get_tree()->get_root();
|
||||
if (!r->get_rect().has_point(Point2(mev.global_x,mev.global_y)))
|
||||
Viewport *r = get_tree()->get_root();
|
||||
if (!r->get_rect().has_point(Point2(mev.global_x, mev.global_y)))
|
||||
return;
|
||||
Image img =r->get_screen_capture();
|
||||
Image img = r->get_screen_capture();
|
||||
if (!img.empty())
|
||||
last_capture=img;
|
||||
r->queue_screen_capture();
|
||||
last_capture = img;
|
||||
r->queue_screen_capture();
|
||||
if (!last_capture.empty())
|
||||
set_color(last_capture.get_pixel(mev.global_x,mev.global_y));
|
||||
set_color(last_capture.get_pixel(mev.global_x, mev.global_y));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -409,15 +396,14 @@ void ColorPicker::_add_preset_pressed() {
|
|||
add_preset(color);
|
||||
}
|
||||
|
||||
void ColorPicker::_screen_pick_pressed()
|
||||
{
|
||||
Viewport *r=get_tree()->get_root();
|
||||
void ColorPicker::_screen_pick_pressed() {
|
||||
Viewport *r = get_tree()->get_root();
|
||||
if (!screen) {
|
||||
screen=memnew( Control );
|
||||
screen = memnew(Control);
|
||||
r->add_child(screen);
|
||||
screen->set_as_toplevel(true);
|
||||
screen->set_area_as_parent_rect();
|
||||
screen->connect("input_event",this,"_screen_input");
|
||||
screen->connect("input_event", this, "_screen_input");
|
||||
}
|
||||
screen->raise();
|
||||
screen->show_modal();
|
||||
|
|
@ -426,158 +412,155 @@ void ColorPicker::_screen_pick_pressed()
|
|||
|
||||
void ColorPicker::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_color","color"),&ColorPicker::set_color);
|
||||
ObjectTypeDB::bind_method(_MD("get_color"),&ColorPicker::get_color);
|
||||
ObjectTypeDB::bind_method(_MD("set_raw_mode","mode"),&ColorPicker::set_raw_mode);
|
||||
ObjectTypeDB::bind_method(_MD("is_raw_mode"),&ColorPicker::is_raw_mode);
|
||||
ObjectTypeDB::bind_method(_MD("set_edit_alpha","show"),&ColorPicker::set_edit_alpha);
|
||||
ObjectTypeDB::bind_method(_MD("is_editing_alpha"),&ColorPicker::is_editing_alpha);
|
||||
ObjectTypeDB::bind_method(_MD("set_color", "color"), &ColorPicker::set_color);
|
||||
ObjectTypeDB::bind_method(_MD("get_color"), &ColorPicker::get_color);
|
||||
ObjectTypeDB::bind_method(_MD("set_raw_mode", "mode"), &ColorPicker::set_raw_mode);
|
||||
ObjectTypeDB::bind_method(_MD("is_raw_mode"), &ColorPicker::is_raw_mode);
|
||||
ObjectTypeDB::bind_method(_MD("set_edit_alpha", "show"), &ColorPicker::set_edit_alpha);
|
||||
ObjectTypeDB::bind_method(_MD("is_editing_alpha"), &ColorPicker::is_editing_alpha);
|
||||
ObjectTypeDB::bind_method(_MD("add_preset"), &ColorPicker::add_preset);
|
||||
ObjectTypeDB::bind_method(_MD("_value_changed"),&ColorPicker::_value_changed);
|
||||
ObjectTypeDB::bind_method(_MD("_html_entered"),&ColorPicker::_html_entered);
|
||||
ObjectTypeDB::bind_method(_MD("_text_type_toggled"),&ColorPicker::_text_type_toggled);
|
||||
ObjectTypeDB::bind_method(_MD("_value_changed"), &ColorPicker::_value_changed);
|
||||
ObjectTypeDB::bind_method(_MD("_html_entered"), &ColorPicker::_html_entered);
|
||||
ObjectTypeDB::bind_method(_MD("_text_type_toggled"), &ColorPicker::_text_type_toggled);
|
||||
ObjectTypeDB::bind_method(_MD("_add_preset_pressed"), &ColorPicker::_add_preset_pressed);
|
||||
ObjectTypeDB::bind_method(_MD("_screen_pick_pressed"), &ColorPicker::_screen_pick_pressed);
|
||||
ObjectTypeDB::bind_method(_MD("_sample_draw"),&ColorPicker::_sample_draw);
|
||||
ObjectTypeDB::bind_method(_MD("_hsv_draw"),&ColorPicker::_hsv_draw);
|
||||
ObjectTypeDB::bind_method(_MD("_uv_input"),&ColorPicker::_uv_input);
|
||||
ObjectTypeDB::bind_method(_MD("_w_input"),&ColorPicker::_w_input);
|
||||
ObjectTypeDB::bind_method(_MD("_preset_input"),&ColorPicker::_preset_input);
|
||||
ObjectTypeDB::bind_method(_MD("_screen_input"),&ColorPicker::_screen_input);
|
||||
ObjectTypeDB::bind_method(_MD("_sample_draw"), &ColorPicker::_sample_draw);
|
||||
ObjectTypeDB::bind_method(_MD("_hsv_draw"), &ColorPicker::_hsv_draw);
|
||||
ObjectTypeDB::bind_method(_MD("_uv_input"), &ColorPicker::_uv_input);
|
||||
ObjectTypeDB::bind_method(_MD("_w_input"), &ColorPicker::_w_input);
|
||||
ObjectTypeDB::bind_method(_MD("_preset_input"), &ColorPicker::_preset_input);
|
||||
ObjectTypeDB::bind_method(_MD("_screen_input"), &ColorPicker::_screen_input);
|
||||
|
||||
ADD_SIGNAL( MethodInfo("color_changed",PropertyInfo(Variant::COLOR,"color")));
|
||||
ADD_SIGNAL(MethodInfo("color_changed", PropertyInfo(Variant::COLOR, "color")));
|
||||
}
|
||||
|
||||
ColorPicker::ColorPicker() :
|
||||
BoxContainer(true) {
|
||||
ColorPicker::ColorPicker()
|
||||
: BoxContainer(true) {
|
||||
|
||||
updating=true;
|
||||
edit_alpha=true;
|
||||
updating = true;
|
||||
edit_alpha = true;
|
||||
text_is_constructor = false;
|
||||
raw_mode_enabled=false;
|
||||
changing_color=false;
|
||||
screen=NULL;
|
||||
raw_mode_enabled = false;
|
||||
changing_color = false;
|
||||
screen = NULL;
|
||||
|
||||
HBoxContainer *hb_smpl = memnew( HBoxContainer );
|
||||
btn_pick = memnew( ToolButton );
|
||||
btn_pick->connect("pressed",this,"_screen_pick_pressed");
|
||||
HBoxContainer *hb_smpl = memnew(HBoxContainer);
|
||||
btn_pick = memnew(ToolButton);
|
||||
btn_pick->connect("pressed", this, "_screen_pick_pressed");
|
||||
|
||||
sample = memnew( TextureFrame );
|
||||
sample = memnew(TextureFrame);
|
||||
sample->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
sample->connect("draw",this,"_sample_draw");
|
||||
sample->connect("draw", this, "_sample_draw");
|
||||
|
||||
hb_smpl->add_child(sample);
|
||||
hb_smpl->add_child(btn_pick);
|
||||
add_child(hb_smpl);
|
||||
|
||||
HBoxContainer *hb_edit = memnew( HBoxContainer );
|
||||
HBoxContainer *hb_edit = memnew(HBoxContainer);
|
||||
|
||||
uv_edit= memnew ( TextureFrame );
|
||||
uv_edit = memnew(TextureFrame);
|
||||
Image i(256, 256, false, Image::FORMAT_RGB);
|
||||
for (int y=0;y<256;y++)
|
||||
for (int x=0;x<256;x++)
|
||||
i.put_pixel(x,y,Color());
|
||||
for (int y = 0; y < 256; y++)
|
||||
for (int x = 0; x < 256; x++)
|
||||
i.put_pixel(x, y, Color());
|
||||
Ref<ImageTexture> t;
|
||||
t.instance();
|
||||
t->create_from_image(i);
|
||||
uv_edit->set_texture(t);
|
||||
uv_edit->set_ignore_mouse(false);
|
||||
uv_edit->set_custom_minimum_size(Size2(256,256));
|
||||
uv_edit->set_custom_minimum_size(Size2(256, 256));
|
||||
uv_edit->connect("input_event", this, "_uv_input");
|
||||
Control *c= memnew( Control );
|
||||
Control *c = memnew(Control);
|
||||
uv_edit->add_child(c);
|
||||
c->set_area_as_parent_rect();
|
||||
c->set_stop_mouse(false);
|
||||
c->set_material(memnew ( CanvasItemMaterial ));
|
||||
Vector<Variant> args=Vector<Variant>();
|
||||
c->set_material(memnew(CanvasItemMaterial));
|
||||
Vector<Variant> args = Vector<Variant>();
|
||||
args.push_back(0);
|
||||
args.push_back(c);
|
||||
c->connect("draw",this,"_hsv_draw",args);
|
||||
c->connect("draw", this, "_hsv_draw", args);
|
||||
|
||||
add_child(hb_edit);
|
||||
w_edit= memnew( TextureFrame );
|
||||
w_edit = memnew(TextureFrame);
|
||||
i = Image(15, 256, false, Image::FORMAT_RGB);
|
||||
for (int y=0;y<256;y++)
|
||||
for (int x=0;x<15;x++)
|
||||
i.put_pixel(x,y,Color());
|
||||
for (int y = 0; y < 256; y++)
|
||||
for (int x = 0; x < 15; x++)
|
||||
i.put_pixel(x, y, Color());
|
||||
Ref<ImageTexture> tw;
|
||||
tw.instance();
|
||||
tw->create_from_image(i);
|
||||
w_edit->set_texture(tw);
|
||||
w_edit->set_ignore_mouse(false);
|
||||
w_edit->set_custom_minimum_size(Size2(15,256));
|
||||
w_edit->set_custom_minimum_size(Size2(15, 256));
|
||||
w_edit->connect("input_event", this, "_w_input");
|
||||
c= memnew( Control );
|
||||
c = memnew(Control);
|
||||
w_edit->add_child(c);
|
||||
c->set_area_as_parent_rect();
|
||||
c->set_stop_mouse(false);
|
||||
c->set_material(memnew ( CanvasItemMaterial ));
|
||||
c->set_material(memnew(CanvasItemMaterial));
|
||||
args.clear();
|
||||
args.push_back(1);
|
||||
args.push_back(c);
|
||||
c->connect("draw",this,"_hsv_draw",args);
|
||||
c->connect("draw", this, "_hsv_draw", args);
|
||||
|
||||
hb_edit->add_child(uv_edit);
|
||||
hb_edit->add_child(memnew( VSeparator ));
|
||||
hb_edit->add_child(memnew(VSeparator));
|
||||
hb_edit->add_child(w_edit);
|
||||
|
||||
VBoxContainer *vbl = memnew( VBoxContainer );
|
||||
VBoxContainer *vbl = memnew(VBoxContainer);
|
||||
add_child(vbl);
|
||||
|
||||
add_child(memnew( HSeparator ));
|
||||
add_child(memnew(HSeparator));
|
||||
|
||||
VBoxContainer *vbr = memnew( VBoxContainer );
|
||||
VBoxContainer *vbr = memnew(VBoxContainer);
|
||||
add_child(vbr);
|
||||
vbr->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
const char* lt[4] = {"R","G","B","A"};
|
||||
const char *lt[4] = { "R", "G", "B", "A" };
|
||||
|
||||
for(int i=0;i<4;i++) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
|
||||
HBoxContainer *hbc = memnew( HBoxContainer );
|
||||
HBoxContainer *hbc = memnew(HBoxContainer);
|
||||
|
||||
labels[i]=memnew( Label(lt[i]) );
|
||||
labels[i] = memnew(Label(lt[i]));
|
||||
hbc->add_child(labels[i]);
|
||||
|
||||
scroll[i]=memnew( HSlider );
|
||||
scroll[i] = memnew(HSlider);
|
||||
hbc->add_child(scroll[i]);
|
||||
|
||||
values[i]=memnew( SpinBox );
|
||||
values[i] = memnew(SpinBox);
|
||||
scroll[i]->share(values[i]);
|
||||
hbc->add_child(values[i]);
|
||||
|
||||
|
||||
scroll[i]->set_min(0);
|
||||
scroll[i]->set_page(0);
|
||||
scroll[i]->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
|
||||
scroll[i]->connect("value_changed",this,"_value_changed");
|
||||
scroll[i]->connect("value_changed", this, "_value_changed");
|
||||
|
||||
vbr->add_child(hbc);
|
||||
|
||||
}
|
||||
|
||||
HBoxContainer *hhb = memnew( HBoxContainer );
|
||||
HBoxContainer *hhb = memnew(HBoxContainer);
|
||||
|
||||
btn_mode = memnew( CheckButton );
|
||||
btn_mode = memnew(CheckButton);
|
||||
btn_mode->set_text("RAW Mode");
|
||||
btn_mode->connect("toggled", this, "set_raw_mode");
|
||||
hhb->add_child(btn_mode);
|
||||
vbr->add_child(hhb);
|
||||
text_type = memnew( Button );
|
||||
text_type = memnew(Button);
|
||||
text_type->set_flat(true);
|
||||
text_type->connect("pressed", this, "_text_type_toggled");
|
||||
hhb->add_child(text_type);
|
||||
|
||||
c_text = memnew( LineEdit );
|
||||
c_text = memnew(LineEdit);
|
||||
hhb->add_child(c_text);
|
||||
c_text->connect("text_entered",this,"_html_entered");
|
||||
c_text->connect("text_entered", this, "_html_entered");
|
||||
text_type->set_text("#");
|
||||
c_text->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
|
||||
|
||||
_update_controls();
|
||||
//_update_color();
|
||||
updating=false;
|
||||
updating = false;
|
||||
|
||||
uv_material.instance();
|
||||
Ref<Shader> s_uv = get_shader("uv_editor");
|
||||
|
|
@ -591,76 +574,67 @@ ColorPicker::ColorPicker() :
|
|||
uv_edit->set_material(uv_material);
|
||||
w_edit->set_material(w_material);
|
||||
|
||||
set_color(Color(1,1,1));
|
||||
set_color(Color(1, 1, 1));
|
||||
|
||||
i.create(256,20,false,Image::FORMAT_RGB);
|
||||
for (int y=0;y<20;y++)
|
||||
for(int x=0;x<256;x++)
|
||||
if ((x/4+y/4)%2)
|
||||
i.put_pixel(x,y,Color(1,1,1));
|
||||
i.create(256, 20, false, Image::FORMAT_RGB);
|
||||
for (int y = 0; y < 20; y++)
|
||||
for (int x = 0; x < 256; x++)
|
||||
if ((x / 4 + y / 4) % 2)
|
||||
i.put_pixel(x, y, Color(1, 1, 1));
|
||||
else
|
||||
i.put_pixel(x,y,Color(0.6,0.6,0.6));
|
||||
i.put_pixel(x, y, Color(0.6, 0.6, 0.6));
|
||||
Ref<ImageTexture> t_smpl;
|
||||
t_smpl.instance();
|
||||
t_smpl->create_from_image(i);
|
||||
sample->set_texture(t_smpl);
|
||||
|
||||
HBoxContainer *bbc = memnew( HBoxContainer );
|
||||
HBoxContainer *bbc = memnew(HBoxContainer);
|
||||
add_child(bbc);
|
||||
|
||||
preset = memnew( TextureFrame );
|
||||
preset = memnew(TextureFrame);
|
||||
bbc->add_child(preset);
|
||||
preset->set_ignore_mouse(false);
|
||||
preset->connect("input_event", this, "_preset_input");
|
||||
|
||||
bt_add_preset = memnew ( Button );
|
||||
bt_add_preset = memnew(Button);
|
||||
bt_add_preset->set_icon(get_icon("add_preset"));
|
||||
bt_add_preset->set_tooltip("Add current color as a preset");
|
||||
bt_add_preset->connect("pressed", this, "_add_preset_pressed");
|
||||
bbc->add_child(bt_add_preset);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/////////////////
|
||||
|
||||
|
||||
void ColorPickerButton::_color_changed(const Color& p_color) {
|
||||
void ColorPickerButton::_color_changed(const Color &p_color) {
|
||||
|
||||
update();
|
||||
emit_signal("color_changed",p_color);
|
||||
emit_signal("color_changed", p_color);
|
||||
}
|
||||
|
||||
|
||||
void ColorPickerButton::pressed() {
|
||||
|
||||
Size2 ms = Size2(300, picker->get_combined_minimum_size().height+10);
|
||||
popup->set_pos(get_global_pos()-Size2(0,ms.height));
|
||||
Size2 ms = Size2(300, picker->get_combined_minimum_size().height + 10);
|
||||
popup->set_pos(get_global_pos() - Size2(0, ms.height));
|
||||
popup->set_size(ms);
|
||||
popup->popup();
|
||||
picker->set_focus_on_line_edit();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void ColorPickerButton::_notification(int p_what) {
|
||||
|
||||
if (p_what == NOTIFICATION_DRAW) {
|
||||
|
||||
if (p_what==NOTIFICATION_DRAW) {
|
||||
|
||||
Ref<StyleBox> normal = get_stylebox("normal" );
|
||||
draw_rect(Rect2(normal->get_offset(),get_size()-normal->get_minimum_size()),picker->get_color());
|
||||
Ref<StyleBox> normal = get_stylebox("normal");
|
||||
draw_rect(Rect2(normal->get_offset(), get_size() - normal->get_minimum_size()), picker->get_color());
|
||||
}
|
||||
}
|
||||
|
||||
void ColorPickerButton::set_color(const Color& p_color){
|
||||
|
||||
void ColorPickerButton::set_color(const Color &p_color) {
|
||||
|
||||
picker->set_color(p_color);
|
||||
update();
|
||||
}
|
||||
Color ColorPickerButton::get_color() const{
|
||||
Color ColorPickerButton::get_color() const {
|
||||
|
||||
return picker->get_color();
|
||||
}
|
||||
|
|
@ -670,37 +644,35 @@ void ColorPickerButton::set_edit_alpha(bool p_show) {
|
|||
picker->set_edit_alpha(p_show);
|
||||
}
|
||||
|
||||
bool ColorPickerButton::is_editing_alpha() const{
|
||||
bool ColorPickerButton::is_editing_alpha() const {
|
||||
|
||||
return picker->is_editing_alpha();
|
||||
|
||||
}
|
||||
|
||||
ColorPicker *ColorPickerButton::get_picker() {
|
||||
return picker;
|
||||
}
|
||||
|
||||
void ColorPickerButton::_bind_methods(){
|
||||
void ColorPickerButton::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_color","color"),&ColorPickerButton::set_color);
|
||||
ObjectTypeDB::bind_method(_MD("get_color"),&ColorPickerButton::get_color);
|
||||
ObjectTypeDB::bind_method(_MD("get_picker:ColorPicker"),&ColorPickerButton::get_picker);
|
||||
ObjectTypeDB::bind_method(_MD("set_edit_alpha","show"),&ColorPickerButton::set_edit_alpha);
|
||||
ObjectTypeDB::bind_method(_MD("is_editing_alpha"),&ColorPickerButton::is_editing_alpha);
|
||||
ObjectTypeDB::bind_method(_MD("_color_changed"),&ColorPickerButton::_color_changed);
|
||||
|
||||
ADD_SIGNAL( MethodInfo("color_changed",PropertyInfo(Variant::COLOR,"color")));
|
||||
ADD_PROPERTY( PropertyInfo(Variant::COLOR,"color"),_SCS("set_color"),_SCS("get_color") );
|
||||
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"edit_alpha"),_SCS("set_edit_alpha"),_SCS("is_editing_alpha") );
|
||||
ObjectTypeDB::bind_method(_MD("set_color", "color"), &ColorPickerButton::set_color);
|
||||
ObjectTypeDB::bind_method(_MD("get_color"), &ColorPickerButton::get_color);
|
||||
ObjectTypeDB::bind_method(_MD("get_picker:ColorPicker"), &ColorPickerButton::get_picker);
|
||||
ObjectTypeDB::bind_method(_MD("set_edit_alpha", "show"), &ColorPickerButton::set_edit_alpha);
|
||||
ObjectTypeDB::bind_method(_MD("is_editing_alpha"), &ColorPickerButton::is_editing_alpha);
|
||||
ObjectTypeDB::bind_method(_MD("_color_changed"), &ColorPickerButton::_color_changed);
|
||||
|
||||
ADD_SIGNAL(MethodInfo("color_changed", PropertyInfo(Variant::COLOR, "color")));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), _SCS("set_color"), _SCS("get_color"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "edit_alpha"), _SCS("set_edit_alpha"), _SCS("is_editing_alpha"));
|
||||
}
|
||||
|
||||
ColorPickerButton::ColorPickerButton() {
|
||||
|
||||
popup = memnew( PopupPanel );
|
||||
picker = memnew( ColorPicker );
|
||||
popup = memnew(PopupPanel);
|
||||
picker = memnew(ColorPicker);
|
||||
popup->add_child(picker);
|
||||
popup->set_child_rect(picker);
|
||||
picker->connect("color_changed",this,"_color_changed");
|
||||
picker->connect("color_changed", this, "_color_changed");
|
||||
add_child(popup);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,24 +29,23 @@
|
|||
#ifndef COLOR_PICKER_H
|
||||
#define COLOR_PICKER_H
|
||||
|
||||
#include "scene/gui/slider.h"
|
||||
#include "scene/gui/line_edit.h"
|
||||
#include "scene/gui/spin_box.h"
|
||||
#include "scene/gui/label.h"
|
||||
#include "scene/gui/button.h"
|
||||
#include "scene/gui/popup.h"
|
||||
#include "scene/gui/box_container.h"
|
||||
#include "scene/gui/button.h"
|
||||
#include "scene/gui/check_button.h"
|
||||
#include "scene/gui/label.h"
|
||||
#include "scene/gui/line_edit.h"
|
||||
#include "scene/gui/popup.h"
|
||||
#include "scene/gui/slider.h"
|
||||
#include "scene/gui/spin_box.h"
|
||||
#include "scene/gui/texture_frame.h"
|
||||
#include "scene/gui/tool_button.h"
|
||||
#include "scene/gui/check_button.h"
|
||||
#include "scene/resources/material.h"
|
||||
|
||||
class ColorPicker : public BoxContainer {
|
||||
|
||||
OBJ_TYPE(ColorPicker,BoxContainer);
|
||||
OBJ_TYPE(ColorPicker, BoxContainer);
|
||||
|
||||
private:
|
||||
|
||||
Control *screen;
|
||||
Image last_capture;
|
||||
TextureFrame *uv_edit;
|
||||
|
|
@ -72,10 +71,10 @@ private:
|
|||
bool raw_mode_enabled;
|
||||
bool updating;
|
||||
bool changing_color;
|
||||
float h,s,v;
|
||||
float h, s, v;
|
||||
Color last_hsv;
|
||||
|
||||
void _html_entered(const String& p_html);
|
||||
void _html_entered(const String &p_html);
|
||||
void _value_changed(double);
|
||||
void _update_controls();
|
||||
void _update_color();
|
||||
|
|
@ -83,28 +82,27 @@ private:
|
|||
void _update_text_value();
|
||||
void _text_type_toggled();
|
||||
void _sample_draw();
|
||||
void _hsv_draw(int p_wich,Control *c);
|
||||
void _hsv_draw(int p_wich, Control *c);
|
||||
|
||||
void _uv_input(const InputEvent& p_input);
|
||||
void _w_input(const InputEvent& p_input);
|
||||
void _preset_input(const InputEvent& p_input);
|
||||
void _screen_input(const InputEvent& p_input);
|
||||
void _uv_input(const InputEvent &p_input);
|
||||
void _w_input(const InputEvent &p_input);
|
||||
void _preset_input(const InputEvent &p_input);
|
||||
void _screen_input(const InputEvent &p_input);
|
||||
void _add_preset_pressed();
|
||||
void _screen_pick_pressed();
|
||||
|
||||
protected:
|
||||
|
||||
void _notification(int);
|
||||
static void _bind_methods();
|
||||
public:
|
||||
|
||||
public:
|
||||
void set_edit_alpha(bool p_show);
|
||||
bool is_editing_alpha() const;
|
||||
|
||||
void set_color(const Color& p_color);
|
||||
void set_color(const Color &p_color);
|
||||
Color get_color() const;
|
||||
|
||||
void add_preset(const Color& p_color);
|
||||
void add_preset(const Color &p_color);
|
||||
void set_raw_mode(bool p_enabled);
|
||||
bool is_raw_mode() const;
|
||||
|
||||
|
|
@ -115,21 +113,20 @@ public:
|
|||
|
||||
class ColorPickerButton : public Button {
|
||||
|
||||
OBJ_TYPE(ColorPickerButton,Button);
|
||||
OBJ_TYPE(ColorPickerButton, Button);
|
||||
|
||||
PopupPanel *popup;
|
||||
ColorPicker *picker;
|
||||
|
||||
void _color_changed(const Color& p_color);
|
||||
void _color_changed(const Color &p_color);
|
||||
virtual void pressed();
|
||||
|
||||
protected:
|
||||
|
||||
void _notification(int);
|
||||
static void _bind_methods();
|
||||
public:
|
||||
|
||||
void set_color(const Color& p_color);
|
||||
public:
|
||||
void set_color(const Color &p_color);
|
||||
Color get_color() const;
|
||||
|
||||
void set_edit_alpha(bool p_show);
|
||||
|
|
|
|||
|
|
@ -29,74 +29,72 @@
|
|||
#include "color_ramp_edit.h"
|
||||
#include "os/keyboard.h"
|
||||
|
||||
ColorRampEdit::ColorRampEdit(){
|
||||
grabbed=-1;
|
||||
grabbing=false;
|
||||
ColorRampEdit::ColorRampEdit() {
|
||||
grabbed = -1;
|
||||
grabbing = false;
|
||||
set_focus_mode(FOCUS_ALL);
|
||||
|
||||
popup = memnew( PopupPanel );
|
||||
picker = memnew( ColorPicker );
|
||||
popup = memnew(PopupPanel);
|
||||
picker = memnew(ColorPicker);
|
||||
popup->add_child(picker);
|
||||
popup->set_child_rect(picker);
|
||||
add_child(popup);
|
||||
|
||||
checker = Ref<ImageTexture>(memnew( ImageTexture ));
|
||||
checker->create_from_image( Image(checker_bg_png),ImageTexture::FLAG_REPEAT );
|
||||
checker = Ref<ImageTexture>(memnew(ImageTexture));
|
||||
checker->create_from_image(Image(checker_bg_png), ImageTexture::FLAG_REPEAT);
|
||||
}
|
||||
|
||||
int ColorRampEdit::_get_point_from_pos(int x) {
|
||||
int result = -1;
|
||||
int total_w = get_size().width-get_size().height-3;
|
||||
for(int i=0;i<points.size();i++) {
|
||||
int total_w = get_size().width - get_size().height - 3;
|
||||
for (int i = 0; i < points.size(); i++) {
|
||||
//Check if we clicked at point
|
||||
if (ABS(x-points[i].offset*total_w+1)<(POINT_WIDTH/2+1)) {
|
||||
result=i;
|
||||
if (ABS(x - points[i].offset * total_w + 1) < (POINT_WIDTH / 2 + 1)) {
|
||||
result = i;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void ColorRampEdit::_show_color_picker() {
|
||||
if (grabbed==-1)
|
||||
if (grabbed == -1)
|
||||
return;
|
||||
Size2 ms = Size2(350, picker->get_combined_minimum_size().height+10);
|
||||
Size2 ms = Size2(350, picker->get_combined_minimum_size().height + 10);
|
||||
picker->set_color(points[grabbed].color);
|
||||
popup->set_pos(get_global_pos()-Vector2(ms.width-get_size().width,ms.height));
|
||||
popup->set_pos(get_global_pos() - Vector2(ms.width - get_size().width, ms.height));
|
||||
popup->set_size(ms);
|
||||
popup->popup();
|
||||
}
|
||||
|
||||
ColorRampEdit::~ColorRampEdit() {
|
||||
|
||||
}
|
||||
|
||||
void ColorRampEdit::_input_event(const InputEvent& p_event) {
|
||||
void ColorRampEdit::_input_event(const InputEvent &p_event) {
|
||||
|
||||
if (p_event.type==InputEvent::KEY && p_event.key.pressed && p_event.key.scancode==KEY_DELETE && grabbed!=-1) {
|
||||
if (p_event.type == InputEvent::KEY && p_event.key.pressed && p_event.key.scancode == KEY_DELETE && grabbed != -1) {
|
||||
|
||||
points.remove(grabbed);
|
||||
grabbed=-1;
|
||||
grabbing=false;
|
||||
grabbed = -1;
|
||||
grabbing = false;
|
||||
update();
|
||||
emit_signal("ramp_changed");
|
||||
accept_event();
|
||||
}
|
||||
|
||||
//Show color picker on double click.
|
||||
if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1 && p_event.mouse_button.doubleclick && p_event.mouse_button.pressed) {
|
||||
grabbed=_get_point_from_pos(p_event.mouse_button.x);
|
||||
if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == 1 && p_event.mouse_button.doubleclick && p_event.mouse_button.pressed) {
|
||||
grabbed = _get_point_from_pos(p_event.mouse_button.x);
|
||||
_show_color_picker();
|
||||
accept_event();
|
||||
}
|
||||
|
||||
//Delete point on right click
|
||||
if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==2 && p_event.mouse_button.pressed) {
|
||||
grabbed=_get_point_from_pos(p_event.mouse_button.x);
|
||||
if(grabbed != -1)
|
||||
{
|
||||
if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == 2 && p_event.mouse_button.pressed) {
|
||||
grabbed = _get_point_from_pos(p_event.mouse_button.x);
|
||||
if (grabbed != -1) {
|
||||
points.remove(grabbed);
|
||||
grabbed=-1;
|
||||
grabbing=false;
|
||||
grabbed = -1;
|
||||
grabbing = false;
|
||||
update();
|
||||
emit_signal("ramp_changed");
|
||||
accept_event();
|
||||
|
|
@ -104,21 +102,21 @@ void ColorRampEdit::_input_event(const InputEvent& p_event) {
|
|||
}
|
||||
|
||||
//Hold alt key to duplicate selected color
|
||||
if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1 && p_event.mouse_button.pressed && p_event.key.mod.alt ) {
|
||||
if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == 1 && p_event.mouse_button.pressed && p_event.key.mod.alt) {
|
||||
|
||||
int x = p_event.mouse_button.x;
|
||||
grabbed=_get_point_from_pos(x);
|
||||
grabbed = _get_point_from_pos(x);
|
||||
|
||||
if( grabbed != -1 ) {
|
||||
int total_w = get_size().width-get_size().height-3;
|
||||
if (grabbed != -1) {
|
||||
int total_w = get_size().width - get_size().height - 3;
|
||||
ColorRamp::Point newPoint = points[grabbed];
|
||||
newPoint.offset=CLAMP(x/float(total_w),0,1);
|
||||
newPoint.offset = CLAMP(x / float(total_w), 0, 1);
|
||||
|
||||
points.push_back(newPoint);
|
||||
points.sort();
|
||||
for(int i=0;i<points.size();++i) {
|
||||
if (points[i].offset==newPoint.offset) {
|
||||
grabbed=i;
|
||||
for (int i = 0; i < points.size(); ++i) {
|
||||
if (points[i].offset == newPoint.offset) {
|
||||
grabbed = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -128,91 +126,89 @@ void ColorRampEdit::_input_event(const InputEvent& p_event) {
|
|||
}
|
||||
}
|
||||
|
||||
if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1 && p_event.mouse_button.pressed) {
|
||||
if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == 1 && p_event.mouse_button.pressed) {
|
||||
|
||||
update();
|
||||
int x = p_event.mouse_button.x;
|
||||
int total_w = get_size().width-get_size().height-3;
|
||||
int total_w = get_size().width - get_size().height - 3;
|
||||
|
||||
//Check if color selector was clicked.
|
||||
if (x>total_w+3) {
|
||||
if (x > total_w + 3) {
|
||||
_show_color_picker();
|
||||
return;
|
||||
}
|
||||
|
||||
grabbing=true;
|
||||
grabbing = true;
|
||||
|
||||
grabbed=_get_point_from_pos(x);
|
||||
grabbed = _get_point_from_pos(x);
|
||||
//grab or select
|
||||
if (grabbed!=-1) {
|
||||
if (grabbed != -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
//insert
|
||||
ColorRamp::Point newPoint;
|
||||
newPoint.offset=CLAMP(x/float(total_w),0,1);
|
||||
newPoint.offset = CLAMP(x / float(total_w), 0, 1);
|
||||
|
||||
ColorRamp::Point prev;
|
||||
ColorRamp::Point next;
|
||||
|
||||
int pos=-1;
|
||||
for(int i=0;i<points.size();i++) {
|
||||
if (points[i].offset<newPoint.offset)
|
||||
pos=i;
|
||||
int pos = -1;
|
||||
for (int i = 0; i < points.size(); i++) {
|
||||
if (points[i].offset < newPoint.offset)
|
||||
pos = i;
|
||||
}
|
||||
|
||||
if (pos==-1) {
|
||||
if (pos == -1) {
|
||||
|
||||
prev.color=Color(0,0,0);
|
||||
prev.offset=0;
|
||||
prev.color = Color(0, 0, 0);
|
||||
prev.offset = 0;
|
||||
if (points.size()) {
|
||||
next=points[0];
|
||||
next = points[0];
|
||||
} else {
|
||||
next.color=Color(1,1,1);
|
||||
next.offset=1.0;
|
||||
next.color = Color(1, 1, 1);
|
||||
next.offset = 1.0;
|
||||
}
|
||||
} else {
|
||||
} else {
|
||||
|
||||
if (pos==points.size()-1) {
|
||||
next.color=Color(1,1,1);
|
||||
next.offset=1.0;
|
||||
if (pos == points.size() - 1) {
|
||||
next.color = Color(1, 1, 1);
|
||||
next.offset = 1.0;
|
||||
} else {
|
||||
next=points[pos+1];
|
||||
next = points[pos + 1];
|
||||
}
|
||||
prev=points[pos];
|
||||
|
||||
prev = points[pos];
|
||||
}
|
||||
|
||||
newPoint.color=prev.color.linear_interpolate(next.color,(newPoint.offset-prev.offset)/(next.offset-prev.offset));
|
||||
newPoint.color = prev.color.linear_interpolate(next.color, (newPoint.offset - prev.offset) / (next.offset - prev.offset));
|
||||
|
||||
points.push_back(newPoint);
|
||||
points.sort();
|
||||
for(int i=0;i<points.size();i++) {
|
||||
if (points[i].offset==newPoint.offset) {
|
||||
grabbed=i;
|
||||
for (int i = 0; i < points.size(); i++) {
|
||||
if (points[i].offset == newPoint.offset) {
|
||||
grabbed = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
emit_signal("ramp_changed");
|
||||
|
||||
}
|
||||
|
||||
if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1 && !p_event.mouse_button.pressed) {
|
||||
if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == 1 && !p_event.mouse_button.pressed) {
|
||||
|
||||
if (grabbing) {
|
||||
grabbing=false;
|
||||
grabbing = false;
|
||||
emit_signal("ramp_changed");
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
if (p_event.type==InputEvent::MOUSE_MOTION && grabbing) {
|
||||
if (p_event.type == InputEvent::MOUSE_MOTION && grabbing) {
|
||||
|
||||
int total_w = get_size().width-get_size().height-3;
|
||||
int total_w = get_size().width - get_size().height - 3;
|
||||
|
||||
int x = p_event.mouse_motion.x;
|
||||
float newofs = CLAMP(x/float(total_w),0,1);
|
||||
float newofs = CLAMP(x / float(total_w), 0, 1);
|
||||
|
||||
//Snap to nearest point if holding shift
|
||||
if (p_event.key.mod.shift) {
|
||||
|
|
@ -220,7 +216,7 @@ void ColorRampEdit::_input_event(const InputEvent& p_event) {
|
|||
float smallest_ofs = snap_treshhold;
|
||||
bool founded = false;
|
||||
int nearest_point;
|
||||
for(int i=0;i<points.size();++i) {
|
||||
for (int i = 0; i < points.size(); ++i) {
|
||||
if (i != grabbed) {
|
||||
float temp_ofs = ABS(points[i].offset - newofs);
|
||||
if (temp_ofs < smallest_ofs) {
|
||||
|
|
@ -234,30 +230,30 @@ void ColorRampEdit::_input_event(const InputEvent& p_event) {
|
|||
}
|
||||
if (founded) {
|
||||
if (points[nearest_point].offset < newofs)
|
||||
newofs = points[nearest_point].offset+0.00001;
|
||||
newofs = points[nearest_point].offset + 0.00001;
|
||||
else
|
||||
newofs = points[nearest_point].offset-0.00001;
|
||||
newofs = CLAMP(newofs,0,1);
|
||||
newofs = points[nearest_point].offset - 0.00001;
|
||||
newofs = CLAMP(newofs, 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
bool valid=true;
|
||||
for(int i=0;i<points.size();i++) {
|
||||
bool valid = true;
|
||||
for (int i = 0; i < points.size(); i++) {
|
||||
|
||||
if (points[i].offset==newofs && i!=grabbed) {
|
||||
valid=false;
|
||||
if (points[i].offset == newofs && i != grabbed) {
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!valid)
|
||||
return;
|
||||
|
||||
points[grabbed].offset=newofs;
|
||||
points[grabbed].offset = newofs;
|
||||
|
||||
points.sort();
|
||||
for(int i=0;i<points.size();i++) {
|
||||
if (points[i].offset==newofs) {
|
||||
grabbed=i;
|
||||
for (int i = 0; i < points.size(); i++) {
|
||||
if (points[i].offset == newofs) {
|
||||
grabbed = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -270,12 +266,12 @@ void ColorRampEdit::_input_event(const InputEvent& p_event) {
|
|||
|
||||
void ColorRampEdit::_notification(int p_what) {
|
||||
|
||||
if (p_what==NOTIFICATION_ENTER_TREE) {
|
||||
if (!picker->is_connected("color_changed",this,"_color_changed")) {
|
||||
picker->connect("color_changed",this,"_color_changed");
|
||||
if (p_what == NOTIFICATION_ENTER_TREE) {
|
||||
if (!picker->is_connected("color_changed", this, "_color_changed")) {
|
||||
picker->connect("color_changed", this, "_color_changed");
|
||||
}
|
||||
}
|
||||
if (p_what==NOTIFICATION_DRAW) {
|
||||
if (p_what == NOTIFICATION_DRAW) {
|
||||
|
||||
int w = get_size().x;
|
||||
int h = get_size().y;
|
||||
|
|
@ -283,89 +279,86 @@ void ColorRampEdit::_notification(int p_what) {
|
|||
if (w == 0 || h == 0)
|
||||
return; //Safety check. We have division by 'h'. And in any case there is nothing to draw with such size
|
||||
|
||||
int total_w = get_size().width-get_size().height-3;
|
||||
int total_w = get_size().width - get_size().height - 3;
|
||||
|
||||
//Draw checker pattern for ramp
|
||||
_draw_checker(0,0, total_w, h);
|
||||
_draw_checker(0, 0, total_w, h);
|
||||
|
||||
//Draw color ramp
|
||||
ColorRamp::Point prev;
|
||||
prev.offset=0;
|
||||
if(points.size() == 0)
|
||||
prev.color=Color(0,0,0); //Draw black rectangle if we have no points
|
||||
prev.offset = 0;
|
||||
if (points.size() == 0)
|
||||
prev.color = Color(0, 0, 0); //Draw black rectangle if we have no points
|
||||
else
|
||||
prev.color = points[0].color; //Extend color of first point to the beginning.
|
||||
prev.color = points[0].color; //Extend color of first point to the beginning.
|
||||
|
||||
for(int i=-1;i<points.size();i++) {
|
||||
for (int i = -1; i < points.size(); i++) {
|
||||
|
||||
ColorRamp::Point next;
|
||||
//If there is no next point
|
||||
if (i+1 == points.size()) {
|
||||
if(points.size() == 0)
|
||||
next.color=Color(0,0,0); //Draw black rectangle if we have no points
|
||||
if (i + 1 == points.size()) {
|
||||
if (points.size() == 0)
|
||||
next.color = Color(0, 0, 0); //Draw black rectangle if we have no points
|
||||
else
|
||||
next.color=points[i].color; //Extend color of last point to the end.
|
||||
next.offset=1;
|
||||
next.color = points[i].color; //Extend color of last point to the end.
|
||||
next.offset = 1;
|
||||
} else {
|
||||
next=points[i+1];
|
||||
next = points[i + 1];
|
||||
}
|
||||
|
||||
if (prev.offset==next.offset) {
|
||||
prev=next;
|
||||
if (prev.offset == next.offset) {
|
||||
prev = next;
|
||||
continue;
|
||||
}
|
||||
|
||||
Vector<Vector2> points;
|
||||
Vector<Color> colors;
|
||||
points.push_back(Vector2(prev.offset*total_w,h));
|
||||
points.push_back(Vector2(prev.offset*total_w,0));
|
||||
points.push_back(Vector2(next.offset*total_w,0));
|
||||
points.push_back(Vector2(next.offset*total_w,h));
|
||||
points.push_back(Vector2(prev.offset * total_w, h));
|
||||
points.push_back(Vector2(prev.offset * total_w, 0));
|
||||
points.push_back(Vector2(next.offset * total_w, 0));
|
||||
points.push_back(Vector2(next.offset * total_w, h));
|
||||
colors.push_back(prev.color);
|
||||
colors.push_back(prev.color);
|
||||
colors.push_back(next.color);
|
||||
colors.push_back(next.color);
|
||||
draw_primitive(points,colors,Vector<Point2>());
|
||||
prev=next;
|
||||
draw_primitive(points, colors, Vector<Point2>());
|
||||
prev = next;
|
||||
}
|
||||
|
||||
//Draw point markers
|
||||
for(int i=0;i<points.size();i++) {
|
||||
for (int i = 0; i < points.size(); i++) {
|
||||
|
||||
Color col = i==grabbed?Color(1,0.0,0.0,0.9):points[i].color.contrasted();
|
||||
Color col = i == grabbed ? Color(1, 0.0, 0.0, 0.9) : points[i].color.contrasted();
|
||||
col.a = 0.9;
|
||||
|
||||
draw_line(Vector2(points[i].offset*total_w,0),Vector2(points[i].offset*total_w,h/2),col);
|
||||
draw_rect(Rect2(points[i].offset*total_w-POINT_WIDTH/2, h/2, POINT_WIDTH, h/2), Color(0.6, 0.6, 0.6, i==grabbed?0.9:0.4));
|
||||
draw_line(Vector2(points[i].offset*total_w-POINT_WIDTH/2,h/2),Vector2(points[i].offset*total_w-POINT_WIDTH/2,h-1),col);
|
||||
draw_line(Vector2(points[i].offset*total_w+POINT_WIDTH/2,h/2),Vector2(points[i].offset*total_w+POINT_WIDTH/2,h-1),col);
|
||||
draw_line(Vector2(points[i].offset*total_w-POINT_WIDTH/2,h/2),Vector2(points[i].offset*total_w+POINT_WIDTH/2,h/2),col);
|
||||
draw_line(Vector2(points[i].offset*total_w-POINT_WIDTH/2,h-1),Vector2(points[i].offset*total_w+POINT_WIDTH/2,h-1),col);
|
||||
|
||||
draw_line(Vector2(points[i].offset * total_w, 0), Vector2(points[i].offset * total_w, h / 2), col);
|
||||
draw_rect(Rect2(points[i].offset * total_w - POINT_WIDTH / 2, h / 2, POINT_WIDTH, h / 2), Color(0.6, 0.6, 0.6, i == grabbed ? 0.9 : 0.4));
|
||||
draw_line(Vector2(points[i].offset * total_w - POINT_WIDTH / 2, h / 2), Vector2(points[i].offset * total_w - POINT_WIDTH / 2, h - 1), col);
|
||||
draw_line(Vector2(points[i].offset * total_w + POINT_WIDTH / 2, h / 2), Vector2(points[i].offset * total_w + POINT_WIDTH / 2, h - 1), col);
|
||||
draw_line(Vector2(points[i].offset * total_w - POINT_WIDTH / 2, h / 2), Vector2(points[i].offset * total_w + POINT_WIDTH / 2, h / 2), col);
|
||||
draw_line(Vector2(points[i].offset * total_w - POINT_WIDTH / 2, h - 1), Vector2(points[i].offset * total_w + POINT_WIDTH / 2, h - 1), col);
|
||||
}
|
||||
|
||||
|
||||
//Draw "button" for color selector
|
||||
_draw_checker(total_w+3,0, h, h);
|
||||
if (grabbed!=-1) {
|
||||
_draw_checker(total_w + 3, 0, h, h);
|
||||
if (grabbed != -1) {
|
||||
//Draw with selection color
|
||||
draw_rect(Rect2(total_w+3,0,h,h),points[grabbed].color);
|
||||
draw_rect(Rect2(total_w + 3, 0, h, h), points[grabbed].color);
|
||||
} else {
|
||||
//if no color selected draw grey color with 'X' on top.
|
||||
draw_rect(Rect2(total_w+3,0,h,h), Color(0.5, 0.5, 0.5, 1));
|
||||
draw_line(Vector2(total_w+3,0),Vector2(total_w+3+h,h),Color(1,1,1,0.6));
|
||||
draw_line(Vector2(total_w+3,h),Vector2(total_w+3+h,0),Color(1,1,1,0.6));
|
||||
draw_rect(Rect2(total_w + 3, 0, h, h), Color(0.5, 0.5, 0.5, 1));
|
||||
draw_line(Vector2(total_w + 3, 0), Vector2(total_w + 3 + h, h), Color(1, 1, 1, 0.6));
|
||||
draw_line(Vector2(total_w + 3, h), Vector2(total_w + 3 + h, 0), Color(1, 1, 1, 0.6));
|
||||
}
|
||||
|
||||
//Draw borders around color ramp if in focus
|
||||
if (has_focus()) {
|
||||
|
||||
draw_line(Vector2(-1,-1),Vector2(total_w+1,-1),Color(1,1,1,0.6));
|
||||
draw_line(Vector2(total_w+1,-1),Vector2(total_w+1,h+1),Color(1,1,1,0.6));
|
||||
draw_line(Vector2(total_w+1,h+1),Vector2(-1,h+1),Color(1,1,1,0.6));
|
||||
draw_line(Vector2(-1,-1),Vector2(-1,h+1),Color(1,1,1,0.6));
|
||||
draw_line(Vector2(-1, -1), Vector2(total_w + 1, -1), Color(1, 1, 1, 0.6));
|
||||
draw_line(Vector2(total_w + 1, -1), Vector2(total_w + 1, h + 1), Color(1, 1, 1, 0.6));
|
||||
draw_line(Vector2(total_w + 1, h + 1), Vector2(-1, h + 1), Color(1, 1, 1, 0.6));
|
||||
draw_line(Vector2(-1, -1), Vector2(-1, h + 1), Color(1, 1, 1, 0.6));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -373,9 +366,9 @@ void ColorRampEdit::_draw_checker(int x, int y, int w, int h) {
|
|||
//Draw it with polygon to insert UVs for scale
|
||||
Vector<Vector2> backPoints;
|
||||
backPoints.push_back(Vector2(x, y));
|
||||
backPoints.push_back(Vector2(x, y+h));
|
||||
backPoints.push_back(Vector2(x+w, y+h));
|
||||
backPoints.push_back(Vector2(x+w, y));
|
||||
backPoints.push_back(Vector2(x, y + h));
|
||||
backPoints.push_back(Vector2(x + w, y + h));
|
||||
backPoints.push_back(Vector2(x + w, y));
|
||||
Vector<Color> colorPoints;
|
||||
colorPoints.push_back(Color(1, 1, 1, 1));
|
||||
colorPoints.push_back(Color(1, 1, 1, 1));
|
||||
|
|
@ -384,35 +377,34 @@ void ColorRampEdit::_draw_checker(int x, int y, int w, int h) {
|
|||
Vector<Vector2> uvPoints;
|
||||
//Draw checker pattern pixel-perfect and scale it by 2.
|
||||
uvPoints.push_back(Vector2(x, y));
|
||||
uvPoints.push_back(Vector2(x, y+h*.5f/checker->get_height()));
|
||||
uvPoints.push_back(Vector2(x+w*.5f/checker->get_width(), y+h*.5f/checker->get_height()));
|
||||
uvPoints.push_back(Vector2(x+w*.5f/checker->get_width(), y));
|
||||
uvPoints.push_back(Vector2(x, y + h * .5f / checker->get_height()));
|
||||
uvPoints.push_back(Vector2(x + w * .5f / checker->get_width(), y + h * .5f / checker->get_height()));
|
||||
uvPoints.push_back(Vector2(x + w * .5f / checker->get_width(), y));
|
||||
draw_polygon(backPoints, colorPoints, uvPoints, checker);
|
||||
}
|
||||
|
||||
Size2 ColorRampEdit::get_minimum_size() const {
|
||||
|
||||
return Vector2(0,16);
|
||||
return Vector2(0, 16);
|
||||
}
|
||||
|
||||
void ColorRampEdit::_color_changed(const Color& p_color) {
|
||||
void ColorRampEdit::_color_changed(const Color &p_color) {
|
||||
|
||||
if (grabbed==-1)
|
||||
if (grabbed == -1)
|
||||
return;
|
||||
points[grabbed].color=p_color;
|
||||
points[grabbed].color = p_color;
|
||||
update();
|
||||
emit_signal("ramp_changed");
|
||||
|
||||
}
|
||||
|
||||
void ColorRampEdit::set_ramp(const Vector<float>& p_offsets,const Vector<Color>& p_colors) {
|
||||
void ColorRampEdit::set_ramp(const Vector<float> &p_offsets, const Vector<Color> &p_colors) {
|
||||
|
||||
ERR_FAIL_COND(p_offsets.size()!=p_colors.size());
|
||||
ERR_FAIL_COND(p_offsets.size() != p_colors.size());
|
||||
points.clear();
|
||||
for(int i=0;i<p_offsets.size();i++) {
|
||||
for (int i = 0; i < p_offsets.size(); i++) {
|
||||
ColorRamp::Point p;
|
||||
p.offset=p_offsets[i];
|
||||
p.color=p_colors[i];
|
||||
p.offset = p_offsets[i];
|
||||
p.color = p_colors[i];
|
||||
points.push_back(p);
|
||||
}
|
||||
|
||||
|
|
@ -422,31 +414,31 @@ void ColorRampEdit::set_ramp(const Vector<float>& p_offsets,const Vector<Color>&
|
|||
|
||||
Vector<float> ColorRampEdit::get_offsets() const {
|
||||
Vector<float> ret;
|
||||
for(int i=0;i<points.size();i++)
|
||||
for (int i = 0; i < points.size(); i++)
|
||||
ret.push_back(points[i].offset);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Vector<Color> ColorRampEdit::get_colors() const {
|
||||
Vector<Color> ret;
|
||||
for(int i=0;i<points.size();i++)
|
||||
for (int i = 0; i < points.size(); i++)
|
||||
ret.push_back(points[i].color);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ColorRampEdit::set_points(Vector<ColorRamp::Point>& p_points) {
|
||||
if(points.size() != p_points.size())
|
||||
void ColorRampEdit::set_points(Vector<ColorRamp::Point> &p_points) {
|
||||
if (points.size() != p_points.size())
|
||||
grabbed = -1;
|
||||
points.clear();
|
||||
points = p_points;
|
||||
}
|
||||
|
||||
Vector<ColorRamp::Point>& ColorRampEdit::get_points() {
|
||||
Vector<ColorRamp::Point> &ColorRampEdit::get_points() {
|
||||
return points;
|
||||
}
|
||||
|
||||
void ColorRampEdit::_bind_methods() {
|
||||
ObjectTypeDB::bind_method(_MD("_input_event"),&ColorRampEdit::_input_event);
|
||||
ObjectTypeDB::bind_method(_MD("_color_changed"),&ColorRampEdit::_color_changed);
|
||||
ObjectTypeDB::bind_method(_MD("_input_event"), &ColorRampEdit::_input_event);
|
||||
ObjectTypeDB::bind_method(_MD("_color_changed"), &ColorRampEdit::_color_changed);
|
||||
ADD_SIGNAL(MethodInfo("ramp_changed"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,8 +29,8 @@
|
|||
#ifndef SCENE_GUI_COLOR_RAMP_EDIT_H_
|
||||
#define SCENE_GUI_COLOR_RAMP_EDIT_H_
|
||||
|
||||
#include "scene/gui/popup.h"
|
||||
#include "scene/gui/color_picker.h"
|
||||
#include "scene/gui/popup.h"
|
||||
#include "scene/resources/color_ramp.h"
|
||||
#include "scene/resources/default_theme/theme_data.h"
|
||||
|
||||
|
|
@ -38,7 +38,7 @@
|
|||
|
||||
class ColorRampEdit : public Control {
|
||||
|
||||
OBJ_TYPE(ColorRampEdit,Control);
|
||||
OBJ_TYPE(ColorRampEdit, Control);
|
||||
|
||||
PopupPanel *popup;
|
||||
ColorPicker *picker;
|
||||
|
|
@ -50,21 +50,21 @@ class ColorRampEdit : public Control {
|
|||
Vector<ColorRamp::Point> points;
|
||||
|
||||
void _draw_checker(int x, int y, int w, int h);
|
||||
void _color_changed(const Color& p_color);
|
||||
void _color_changed(const Color &p_color);
|
||||
int _get_point_from_pos(int x);
|
||||
void _show_color_picker();
|
||||
|
||||
protected:
|
||||
void _input_event(const InputEvent& p_event);
|
||||
void _input_event(const InputEvent &p_event);
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
void set_ramp(const Vector<float>& p_offsets,const Vector<Color>& p_colors);
|
||||
void set_ramp(const Vector<float> &p_offsets, const Vector<Color> &p_colors);
|
||||
Vector<float> get_offsets() const;
|
||||
Vector<Color> get_colors() const;
|
||||
void set_points(Vector<ColorRamp::Point>& p_points);
|
||||
Vector<ColorRamp::Point>& get_points();
|
||||
void set_points(Vector<ColorRamp::Point> &p_points);
|
||||
Vector<ColorRamp::Point> &get_points();
|
||||
virtual Size2 get_minimum_size() const;
|
||||
|
||||
ColorRampEdit();
|
||||
|
|
@ -76,5 +76,4 @@ public:
|
|||
OBJ_TYPE(ColorRampEditPanel, Panel );
|
||||
};*/
|
||||
|
||||
|
||||
#endif /* SCENE_GUI_COLOR_RAMP_EDIT_H_ */
|
||||
|
|
|
|||
|
|
@ -1,36 +1,32 @@
|
|||
#include "color_rect.h"
|
||||
|
||||
void ColorFrame::set_frame_color(const Color &p_color) {
|
||||
|
||||
|
||||
|
||||
void ColorFrame::set_frame_color(const Color& p_color) {
|
||||
|
||||
color=p_color;
|
||||
color = p_color;
|
||||
update();
|
||||
}
|
||||
|
||||
Color ColorFrame::get_frame_color() const{
|
||||
Color ColorFrame::get_frame_color() const {
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
void ColorFrame::_notification(int p_what) {
|
||||
|
||||
if (p_what==NOTIFICATION_DRAW) {
|
||||
draw_rect(Rect2(Point2(),get_size()),color);
|
||||
if (p_what == NOTIFICATION_DRAW) {
|
||||
draw_rect(Rect2(Point2(), get_size()), color);
|
||||
}
|
||||
}
|
||||
|
||||
void ColorFrame::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_frame_color","color"),&ColorFrame::set_frame_color);
|
||||
ObjectTypeDB::bind_method(_MD("get_frame_color"),&ColorFrame::get_frame_color);
|
||||
ObjectTypeDB::bind_method(_MD("set_frame_color", "color"), &ColorFrame::set_frame_color);
|
||||
ObjectTypeDB::bind_method(_MD("get_frame_color"), &ColorFrame::get_frame_color);
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::COLOR,"color"),_SCS("set_frame_color"),_SCS("get_frame_color") );
|
||||
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), _SCS("set_frame_color"), _SCS("get_frame_color"));
|
||||
}
|
||||
|
||||
ColorFrame::ColorFrame() {
|
||||
|
||||
color=Color(1,1,1);
|
||||
color = Color(1, 1, 1);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,17 +3,17 @@
|
|||
|
||||
#include "scene/gui/control.h"
|
||||
|
||||
class ColorFrame : public Control {
|
||||
OBJ_TYPE(ColorFrame,Control)
|
||||
class ColorFrame : public Control {
|
||||
OBJ_TYPE(ColorFrame, Control)
|
||||
|
||||
Color color;
|
||||
protected:
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
public:
|
||||
|
||||
void set_frame_color(const Color& p_color);
|
||||
public:
|
||||
void set_frame_color(const Color &p_color);
|
||||
Color get_frame_color() const;
|
||||
|
||||
ColorFrame();
|
||||
|
|
|
|||
|
|
@ -27,9 +27,8 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "container.h"
|
||||
#include "scene/scene_string_names.h"
|
||||
#include "message_queue.h"
|
||||
|
||||
#include "scene/scene_string_names.h"
|
||||
|
||||
void Container::_child_minsize_changed() {
|
||||
|
||||
|
|
@ -45,11 +44,10 @@ void Container::add_child_notify(Node *p_child) {
|
|||
if (!control)
|
||||
return;
|
||||
|
||||
control->connect("size_flags_changed",this,"queue_sort");
|
||||
control->connect("minimum_size_changed",this,"_child_minsize_changed");
|
||||
control->connect("visibility_changed",this,"_child_minsize_changed");
|
||||
control->connect("size_flags_changed", this, "queue_sort");
|
||||
control->connect("minimum_size_changed", this, "_child_minsize_changed");
|
||||
control->connect("visibility_changed", this, "_child_minsize_changed");
|
||||
queue_sort();
|
||||
|
||||
}
|
||||
|
||||
void Container::move_child_notify(Node *p_child) {
|
||||
|
|
@ -62,14 +60,13 @@ void Container::move_child_notify(Node *p_child) {
|
|||
|
||||
void Container::remove_child_notify(Node *p_child) {
|
||||
|
||||
|
||||
Control *control = p_child->cast_to<Control>();
|
||||
if (!control)
|
||||
return;
|
||||
|
||||
control->disconnect("size_flags_changed",this,"queue_sort");
|
||||
control->disconnect("minimum_size_changed",this,"_child_minsize_changed");
|
||||
control->disconnect("visibility_changed",this,"_child_minsize_changed");
|
||||
control->disconnect("size_flags_changed", this, "queue_sort");
|
||||
control->disconnect("minimum_size_changed", this, "_child_minsize_changed");
|
||||
control->disconnect("visibility_changed", this, "_child_minsize_changed");
|
||||
queue_sort();
|
||||
}
|
||||
|
||||
|
|
@ -80,33 +77,33 @@ void Container::_sort_children() {
|
|||
|
||||
notification(NOTIFICATION_SORT_CHILDREN);
|
||||
emit_signal(SceneStringNames::get_singleton()->sort_children);
|
||||
pending_sort=false;
|
||||
pending_sort = false;
|
||||
}
|
||||
|
||||
void Container::fit_child_in_rect(Control *p_child,const Rect2& p_rect) {
|
||||
void Container::fit_child_in_rect(Control *p_child, const Rect2 &p_rect) {
|
||||
|
||||
ERR_FAIL_COND(p_child->get_parent()!=this);
|
||||
ERR_FAIL_COND(p_child->get_parent() != this);
|
||||
|
||||
Size2 minsize = p_child->get_combined_minimum_size();
|
||||
Rect2 r=p_rect;
|
||||
Rect2 r = p_rect;
|
||||
|
||||
if (!(p_child->get_h_size_flags()&SIZE_FILL)) {
|
||||
r.size.x=minsize.x;
|
||||
r.pos.x += Math::floor((p_rect.size.x - minsize.x)/2);
|
||||
if (!(p_child->get_h_size_flags() & SIZE_FILL)) {
|
||||
r.size.x = minsize.x;
|
||||
r.pos.x += Math::floor((p_rect.size.x - minsize.x) / 2);
|
||||
}
|
||||
|
||||
if (!(p_child->get_v_size_flags()&SIZE_FILL)) {
|
||||
r.size.y=minsize.y;
|
||||
r.pos.y += Math::floor((p_rect.size.y - minsize.y)/2);
|
||||
if (!(p_child->get_v_size_flags() & SIZE_FILL)) {
|
||||
r.size.y = minsize.y;
|
||||
r.pos.y += Math::floor((p_rect.size.y - minsize.y) / 2);
|
||||
}
|
||||
|
||||
for(int i=0;i<4;i++)
|
||||
p_child->set_anchor(Margin(i),ANCHOR_BEGIN);
|
||||
for (int i = 0; i < 4; i++)
|
||||
p_child->set_anchor(Margin(i), ANCHOR_BEGIN);
|
||||
|
||||
p_child->set_pos(r.pos);
|
||||
p_child->set_size(r.size);
|
||||
p_child->set_rotation(0);
|
||||
p_child->set_scale(Vector2(1,1));
|
||||
p_child->set_scale(Vector2(1, 1));
|
||||
}
|
||||
|
||||
void Container::queue_sort() {
|
||||
|
|
@ -117,16 +114,16 @@ void Container::queue_sort() {
|
|||
if (pending_sort)
|
||||
return;
|
||||
|
||||
MessageQueue::get_singleton()->push_call(this,"_sort_children");
|
||||
pending_sort=true;
|
||||
MessageQueue::get_singleton()->push_call(this, "_sort_children");
|
||||
pending_sort = true;
|
||||
}
|
||||
|
||||
void Container::_notification(int p_what) {
|
||||
|
||||
switch(p_what) {
|
||||
switch (p_what) {
|
||||
|
||||
case NOTIFICATION_ENTER_TREE: {
|
||||
pending_sort=false;
|
||||
pending_sort = false;
|
||||
queue_sort();
|
||||
} break;
|
||||
case NOTIFICATION_RESIZED: {
|
||||
|
|
@ -148,17 +145,17 @@ void Container::_notification(int p_what) {
|
|||
|
||||
void Container::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("_sort_children"),&Container::_sort_children);
|
||||
ObjectTypeDB::bind_method(_MD("_child_minsize_changed"),&Container::_child_minsize_changed);
|
||||
ObjectTypeDB::bind_method(_MD("_sort_children"), &Container::_sort_children);
|
||||
ObjectTypeDB::bind_method(_MD("_child_minsize_changed"), &Container::_child_minsize_changed);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("queue_sort"),&Container::queue_sort);
|
||||
ObjectTypeDB::bind_method(_MD("fit_child_in_rect","child:Control","rect"),&Container::fit_child_in_rect);
|
||||
ObjectTypeDB::bind_method(_MD("queue_sort"), &Container::queue_sort);
|
||||
ObjectTypeDB::bind_method(_MD("fit_child_in_rect", "child:Control", "rect"), &Container::fit_child_in_rect);
|
||||
|
||||
BIND_CONSTANT( NOTIFICATION_SORT_CHILDREN );
|
||||
BIND_CONSTANT(NOTIFICATION_SORT_CHILDREN);
|
||||
ADD_SIGNAL(MethodInfo("sort_children"));
|
||||
}
|
||||
|
||||
Container::Container() {
|
||||
|
||||
pending_sort=false;
|
||||
pending_sort = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,13 +33,13 @@
|
|||
|
||||
class Container : public Control {
|
||||
|
||||
OBJ_TYPE(Container,Control);
|
||||
OBJ_TYPE(Container, Control);
|
||||
|
||||
bool pending_sort;
|
||||
void _sort_children();
|
||||
void _child_minsize_changed();
|
||||
protected:
|
||||
|
||||
protected:
|
||||
void queue_sort();
|
||||
virtual void add_child_notify(Node *p_child);
|
||||
virtual void move_child_notify(Node *p_child);
|
||||
|
|
@ -47,12 +47,13 @@ protected:
|
|||
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
enum {
|
||||
NOTIFICATION_SORT_CHILDREN=50
|
||||
NOTIFICATION_SORT_CHILDREN = 50
|
||||
};
|
||||
|
||||
void fit_child_in_rect(Control *p_child,const Rect2& p_rect);
|
||||
void fit_child_in_rect(Control *p_child, const Rect2 &p_rect);
|
||||
|
||||
Container();
|
||||
};
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -29,13 +29,13 @@
|
|||
#ifndef CONTROL_H
|
||||
#define CONTROL_H
|
||||
|
||||
#include "scene/main/node.h"
|
||||
#include "scene/resources/theme.h"
|
||||
#include "scene/main/timer.h"
|
||||
#include "scene/2d/canvas_item.h"
|
||||
#include "math_2d.h"
|
||||
#include "rid.h"
|
||||
#include "scene/2d/canvas_item.h"
|
||||
#include "scene/gui/input_action.h"
|
||||
#include "scene/main/node.h"
|
||||
#include "scene/main/timer.h"
|
||||
#include "scene/resources/theme.h"
|
||||
/**
|
||||
@author Juan Linietsky <reduzio@gmail.com>
|
||||
*/
|
||||
|
|
@ -46,11 +46,10 @@ class Panel;
|
|||
|
||||
class Control : public CanvasItem {
|
||||
|
||||
OBJ_TYPE( Control, CanvasItem );
|
||||
OBJ_TYPE(Control, CanvasItem);
|
||||
OBJ_CATEGORY("GUI Nodes");
|
||||
|
||||
public:
|
||||
|
||||
enum AnchorType {
|
||||
ANCHOR_BEGIN,
|
||||
ANCHOR_END,
|
||||
|
|
@ -66,9 +65,9 @@ public:
|
|||
|
||||
enum SizeFlags {
|
||||
|
||||
SIZE_EXPAND=1,
|
||||
SIZE_FILL=2,
|
||||
SIZE_EXPAND_FILL=SIZE_EXPAND|SIZE_FILL
|
||||
SIZE_EXPAND = 1,
|
||||
SIZE_FILL = 2,
|
||||
SIZE_EXPAND_FILL = SIZE_EXPAND | SIZE_FILL
|
||||
|
||||
};
|
||||
|
||||
|
|
@ -94,11 +93,10 @@ public:
|
|||
};
|
||||
|
||||
private:
|
||||
|
||||
struct CComparator {
|
||||
|
||||
bool operator()(const Control* p_a, const Control* p_b) const {
|
||||
if (p_a->get_canvas_layer()==p_b->get_canvas_layer())
|
||||
bool operator()(const Control *p_a, const Control *p_b) const {
|
||||
if (p_a->get_canvas_layer() == p_b->get_canvas_layer())
|
||||
return p_b->is_greater_than(p_a);
|
||||
else
|
||||
return p_a->get_canvas_layer() < p_b->get_canvas_layer();
|
||||
|
|
@ -138,9 +136,9 @@ private:
|
|||
String tooltip;
|
||||
CursorShape default_cursor;
|
||||
|
||||
List<Control*>::Element *MI; //modal item
|
||||
List<Control*>::Element *SI;
|
||||
List<Control*>::Element *RI;
|
||||
List<Control *>::Element *MI; //modal item
|
||||
List<Control *>::Element *SI;
|
||||
List<Control *>::Element *RI;
|
||||
|
||||
CanvasItem *parent_canvas_item;
|
||||
|
||||
|
|
@ -148,39 +146,36 @@ private:
|
|||
|
||||
NodePath focus_neighbour[4];
|
||||
|
||||
HashMap<StringName, Ref<Texture>, StringNameHasher > icon_override;
|
||||
HashMap<StringName, Ref<Shader>, StringNameHasher > shader_override;
|
||||
HashMap<StringName, Ref<StyleBox>, StringNameHasher > style_override;
|
||||
HashMap<StringName, Ref<Font>, StringNameHasher > font_override;
|
||||
HashMap<StringName, Color, StringNameHasher > color_override;
|
||||
HashMap<StringName, int, StringNameHasher > constant_override;
|
||||
Map< Ref<Font>, int> font_refcount;
|
||||
HashMap<StringName, Ref<Texture>, StringNameHasher> icon_override;
|
||||
HashMap<StringName, Ref<Shader>, StringNameHasher> shader_override;
|
||||
HashMap<StringName, Ref<StyleBox>, StringNameHasher> style_override;
|
||||
HashMap<StringName, Ref<Font>, StringNameHasher> font_override;
|
||||
HashMap<StringName, Color, StringNameHasher> color_override;
|
||||
HashMap<StringName, int, StringNameHasher> constant_override;
|
||||
Map<Ref<Font>, int> font_refcount;
|
||||
|
||||
} data;
|
||||
|
||||
// used internally
|
||||
Control* _find_control_at_pos(CanvasItem* p_node,const Point2& p_pos,const Matrix32& p_xform,Matrix32& r_inv_xform);
|
||||
Control *_find_control_at_pos(CanvasItem *p_node, const Point2 &p_pos, const Matrix32 &p_xform, Matrix32 &r_inv_xform);
|
||||
|
||||
void _window_find_focus_neighbour(const Vector2 &p_dir, Node *p_at, const Point2 *p_points, float p_min, float &r_closest_dist, Control **r_closest);
|
||||
Control *_get_focus_neighbour(Margin p_margin, int p_count = 0);
|
||||
|
||||
void _window_find_focus_neighbour(const Vector2& p_dir, Node *p_at, const Point2* p_points ,float p_min,float &r_closest_dist,Control **r_closest);
|
||||
Control *_get_focus_neighbour(Margin p_margin,int p_count=0);
|
||||
|
||||
|
||||
void _set_anchor(Margin p_margin,AnchorType p_anchor);
|
||||
void _set_anchor(Margin p_margin, AnchorType p_anchor);
|
||||
|
||||
float _get_parent_range(int p_idx) const;
|
||||
float _get_range(int p_idx) const;
|
||||
float _s2a(float p_val, AnchorType p_anchor,float p_range) const;
|
||||
float _a2s(float p_val, AnchorType p_anchor,float p_range) const;
|
||||
void _propagate_theme_changed(CanvasItem *p_at, Control *p_owner, bool p_assign=true);
|
||||
float _s2a(float p_val, AnchorType p_anchor, float p_range) const;
|
||||
float _a2s(float p_val, AnchorType p_anchor, float p_range) const;
|
||||
void _propagate_theme_changed(CanvasItem *p_at, Control *p_owner, bool p_assign = true);
|
||||
void _theme_changed();
|
||||
|
||||
|
||||
void _change_notify_margins();
|
||||
void _update_minimum_size();
|
||||
|
||||
void _update_scroll();
|
||||
void _resize(const Size2& p_size);
|
||||
void _resize(const Size2 &p_size);
|
||||
|
||||
void _size_changed();
|
||||
String _get_tooltip() const;
|
||||
|
|
@ -190,65 +185,60 @@ private:
|
|||
float _get_rotation_deg() const;
|
||||
|
||||
void _ref_font(Ref<Font> p_sc);
|
||||
void _unref_font( Ref<Font> p_sc);
|
||||
void _unref_font(Ref<Font> p_sc);
|
||||
void _font_changed();
|
||||
|
||||
|
||||
friend class Viewport;
|
||||
friend class Viewport;
|
||||
void _modal_stack_remove();
|
||||
void _modal_set_prev_focus_owner(ObjectID p_prev);
|
||||
|
||||
protected:
|
||||
|
||||
//virtual void _window_input_event(InputEvent p_event);
|
||||
|
||||
bool _set(const StringName& p_name, const Variant& p_value);
|
||||
bool _get(const StringName& p_name,Variant &r_ret) const;
|
||||
void _get_property_list( List<PropertyInfo> *p_list) const;
|
||||
bool _set(const StringName &p_name, const Variant &p_value);
|
||||
bool _get(const StringName &p_name, Variant &r_ret) const;
|
||||
void _get_property_list(List<PropertyInfo> *p_list) const;
|
||||
|
||||
void _notification(int p_notification);
|
||||
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
//bind helpers
|
||||
|
||||
public:
|
||||
|
||||
enum {
|
||||
|
||||
/* NOTIFICATION_DRAW=30,
|
||||
/* NOTIFICATION_DRAW=30,
|
||||
NOTIFICATION_VISIBILITY_CHANGED=38*/
|
||||
NOTIFICATION_RESIZED=40,
|
||||
NOTIFICATION_MOUSE_ENTER=41,
|
||||
NOTIFICATION_MOUSE_EXIT=42,
|
||||
NOTIFICATION_FOCUS_ENTER=43,
|
||||
NOTIFICATION_FOCUS_EXIT=44,
|
||||
NOTIFICATION_THEME_CHANGED=45,
|
||||
NOTIFICATION_MODAL_CLOSE=46,
|
||||
|
||||
NOTIFICATION_RESIZED = 40,
|
||||
NOTIFICATION_MOUSE_ENTER = 41,
|
||||
NOTIFICATION_MOUSE_EXIT = 42,
|
||||
NOTIFICATION_FOCUS_ENTER = 43,
|
||||
NOTIFICATION_FOCUS_EXIT = 44,
|
||||
NOTIFICATION_THEME_CHANGED = 45,
|
||||
NOTIFICATION_MODAL_CLOSE = 46,
|
||||
|
||||
};
|
||||
|
||||
virtual Variant edit_get_state() const;
|
||||
virtual void edit_set_state(const Variant& p_state);
|
||||
virtual void edit_set_rect(const Rect2& p_edit_rect);
|
||||
virtual void edit_set_state(const Variant &p_state);
|
||||
virtual void edit_set_rect(const Rect2 &p_edit_rect);
|
||||
virtual Size2 edit_get_minimum_size() const;
|
||||
|
||||
void accept_event();
|
||||
|
||||
virtual Size2 get_minimum_size() const;
|
||||
virtual Size2 get_combined_minimum_size() const;
|
||||
virtual bool has_point(const Point2& p_point) const;
|
||||
virtual bool has_point(const Point2 &p_point) const;
|
||||
virtual bool clips_input() const;
|
||||
virtual void set_drag_forwarding(Control* p_target);
|
||||
virtual Variant get_drag_data(const Point2& p_point);
|
||||
virtual bool can_drop_data(const Point2& p_point,const Variant& p_data) const;
|
||||
virtual void drop_data(const Point2& p_point,const Variant& p_data);
|
||||
virtual void set_drag_forwarding(Control *p_target);
|
||||
virtual Variant get_drag_data(const Point2 &p_point);
|
||||
virtual bool can_drop_data(const Point2 &p_point, const Variant &p_data) const;
|
||||
virtual void drop_data(const Point2 &p_point, const Variant &p_data);
|
||||
void set_drag_preview(Control *p_control);
|
||||
void force_drag(const Variant& p_data,Control *p_control);
|
||||
void force_drag(const Variant &p_data, Control *p_control);
|
||||
|
||||
void set_custom_minimum_size(const Size2& p_custom);
|
||||
void set_custom_minimum_size(const Size2 &p_custom);
|
||||
Size2 get_custom_minimum_size() const;
|
||||
|
||||
bool is_window_modal_on_top() const;
|
||||
|
|
@ -256,29 +246,25 @@ public:
|
|||
|
||||
Control *get_parent_control() const;
|
||||
|
||||
|
||||
|
||||
/* POSITIONING */
|
||||
|
||||
void set_anchor(Margin p_margin,AnchorType p_anchor, bool p_keep_margin=false);
|
||||
void set_anchor_and_margin(Margin p_margin,AnchorType p_anchor, float p_pos);
|
||||
void set_anchor(Margin p_margin, AnchorType p_anchor, bool p_keep_margin = false);
|
||||
void set_anchor_and_margin(Margin p_margin, AnchorType p_anchor, float p_pos);
|
||||
|
||||
AnchorType get_anchor(Margin p_margin) const;
|
||||
|
||||
void set_margin(Margin p_margin,float p_value);
|
||||
|
||||
void set_begin(const Point2& p_point); // helper
|
||||
void set_end(const Point2& p_point); // helper
|
||||
|
||||
void set_margin(Margin p_margin, float p_value);
|
||||
|
||||
void set_begin(const Point2 &p_point); // helper
|
||||
void set_end(const Point2 &p_point); // helper
|
||||
|
||||
float get_margin(Margin p_margin) const;
|
||||
Point2 get_begin() const;
|
||||
Point2 get_end() const;
|
||||
|
||||
void set_pos(const Point2& p_point);
|
||||
void set_size(const Size2& p_size);
|
||||
void set_global_pos(const Point2& p_point);
|
||||
void set_pos(const Point2 &p_point);
|
||||
void set_size(const Size2 &p_size);
|
||||
void set_global_pos(const Point2 &p_point);
|
||||
|
||||
Point2 get_pos() const;
|
||||
Point2 get_global_pos() const;
|
||||
|
|
@ -292,15 +278,14 @@ public:
|
|||
float get_rotation() const;
|
||||
float get_rotation_deg() const;
|
||||
|
||||
void set_scale(const Vector2& p_scale);
|
||||
void set_scale(const Vector2 &p_scale);
|
||||
Vector2 get_scale() const;
|
||||
|
||||
void set_area_as_parent_rect(int p_margin = 0);
|
||||
|
||||
void set_area_as_parent_rect(int p_margin=0);
|
||||
void show_modal(bool p_exclusive = false);
|
||||
|
||||
void show_modal(bool p_exclusive=false);
|
||||
|
||||
void set_theme(const Ref<Theme>& p_theme);
|
||||
void set_theme(const Ref<Theme> &p_theme);
|
||||
Ref<Theme> get_theme() const;
|
||||
|
||||
void set_h_size_flags(int p_flags);
|
||||
|
|
@ -338,44 +323,44 @@ public:
|
|||
|
||||
/* SKINNING */
|
||||
|
||||
void add_icon_override(const StringName& p_name, const Ref<Texture>& p_icon);
|
||||
void add_shader_override(const StringName& p_name, const Ref<Shader>& p_shader);
|
||||
void add_style_override(const StringName& p_name, const Ref<StyleBox>& p_style);
|
||||
void add_font_override(const StringName& p_name, const Ref<Font>& p_font);
|
||||
void add_color_override(const StringName& p_name, const Color& p_color);
|
||||
void add_constant_override(const StringName& p_name, int p_constant);
|
||||
void add_icon_override(const StringName &p_name, const Ref<Texture> &p_icon);
|
||||
void add_shader_override(const StringName &p_name, const Ref<Shader> &p_shader);
|
||||
void add_style_override(const StringName &p_name, const Ref<StyleBox> &p_style);
|
||||
void add_font_override(const StringName &p_name, const Ref<Font> &p_font);
|
||||
void add_color_override(const StringName &p_name, const Color &p_color);
|
||||
void add_constant_override(const StringName &p_name, int p_constant);
|
||||
|
||||
Ref<Texture> get_icon(const StringName& p_name,const StringName& p_type=StringName()) const;
|
||||
Ref<Shader> get_shader(const StringName &p_name, const StringName &p_type=StringName()) const;
|
||||
Ref<StyleBox> get_stylebox(const StringName& p_name,const StringName& p_type=StringName()) const;
|
||||
Ref<Font> get_font(const StringName& p_name,const StringName& p_type=StringName()) const;
|
||||
Color get_color(const StringName& p_name,const StringName& p_type=StringName()) const;
|
||||
int get_constant(const StringName& p_name,const StringName& p_type=StringName()) const;
|
||||
Ref<Texture> get_icon(const StringName &p_name, const StringName &p_type = StringName()) const;
|
||||
Ref<Shader> get_shader(const StringName &p_name, const StringName &p_type = StringName()) const;
|
||||
Ref<StyleBox> get_stylebox(const StringName &p_name, const StringName &p_type = StringName()) const;
|
||||
Ref<Font> get_font(const StringName &p_name, const StringName &p_type = StringName()) const;
|
||||
Color get_color(const StringName &p_name, const StringName &p_type = StringName()) const;
|
||||
int get_constant(const StringName &p_name, const StringName &p_type = StringName()) const;
|
||||
|
||||
bool has_icon_override(const StringName& p_name) const;
|
||||
bool has_shader_override(const StringName& p_name) const;
|
||||
bool has_stylebox_override(const StringName& p_name) const;
|
||||
bool has_font_override(const StringName& p_name) const;
|
||||
bool has_color_override(const StringName& p_name) const;
|
||||
bool has_constant_override(const StringName& p_name) const;
|
||||
bool has_icon_override(const StringName &p_name) const;
|
||||
bool has_shader_override(const StringName &p_name) const;
|
||||
bool has_stylebox_override(const StringName &p_name) const;
|
||||
bool has_font_override(const StringName &p_name) const;
|
||||
bool has_color_override(const StringName &p_name) const;
|
||||
bool has_constant_override(const StringName &p_name) const;
|
||||
|
||||
bool has_icon(const StringName& p_name,const StringName& p_type=StringName()) const;
|
||||
bool has_shader(const StringName& p_name,const StringName& p_type=StringName()) const;
|
||||
bool has_stylebox(const StringName& p_name,const StringName& p_type=StringName()) const;
|
||||
bool has_font(const StringName& p_name,const StringName& p_type=StringName()) const;
|
||||
bool has_color(const StringName& p_name,const StringName& p_type=StringName()) const;
|
||||
bool has_constant(const StringName& p_name,const StringName& p_type=StringName()) const;
|
||||
bool has_icon(const StringName &p_name, const StringName &p_type = StringName()) const;
|
||||
bool has_shader(const StringName &p_name, const StringName &p_type = StringName()) const;
|
||||
bool has_stylebox(const StringName &p_name, const StringName &p_type = StringName()) const;
|
||||
bool has_font(const StringName &p_name, const StringName &p_type = StringName()) const;
|
||||
bool has_color(const StringName &p_name, const StringName &p_type = StringName()) const;
|
||||
bool has_constant(const StringName &p_name, const StringName &p_type = StringName()) const;
|
||||
|
||||
/* TOOLTIP */
|
||||
|
||||
void set_tooltip(const String& p_tooltip);
|
||||
virtual String get_tooltip(const Point2& p_pos) const;
|
||||
void set_tooltip(const String &p_tooltip);
|
||||
virtual String get_tooltip(const Point2 &p_pos) const;
|
||||
|
||||
/* CURSOR */
|
||||
|
||||
void set_default_cursor_shape(CursorShape p_shape);
|
||||
CursorShape get_default_cursor_shape() const;
|
||||
virtual CursorShape get_cursor_shape(const Point2& p_pos=Point2i()) const;
|
||||
virtual CursorShape get_cursor_shape(const Point2 &p_pos = Point2i()) const;
|
||||
|
||||
virtual Rect2 get_item_rect() const;
|
||||
virtual Matrix32 get_transform() const;
|
||||
|
|
@ -386,7 +371,7 @@ public:
|
|||
|
||||
void grab_click_focus();
|
||||
|
||||
void warp_mouse(const Point2& p_to_pos);
|
||||
void warp_mouse(const Point2 &p_to_pos);
|
||||
|
||||
virtual bool is_text_field() const;
|
||||
|
||||
|
|
@ -394,7 +379,6 @@ public:
|
|||
|
||||
Control();
|
||||
~Control();
|
||||
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST(Control::AnchorType);
|
||||
|
|
|
|||
|
|
@ -27,46 +27,43 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "dialogs.h"
|
||||
#include "print_string.h"
|
||||
#include "line_edit.h"
|
||||
#include "print_string.h"
|
||||
#include "translation.h"
|
||||
|
||||
void WindowDialog::_post_popup() {
|
||||
|
||||
dragging=false; //just in case
|
||||
dragging = false; //just in case
|
||||
}
|
||||
|
||||
bool WindowDialog::has_point(const Point2& p_point) const {
|
||||
bool WindowDialog::has_point(const Point2 &p_point) const {
|
||||
|
||||
|
||||
int extra = get_constant("titlebar_height","WindowDialog");
|
||||
Rect2 r( Point2(), get_size() );
|
||||
r.pos.y-=extra;
|
||||
r.size.y+=extra;
|
||||
int extra = get_constant("titlebar_height", "WindowDialog");
|
||||
Rect2 r(Point2(), get_size());
|
||||
r.pos.y -= extra;
|
||||
r.size.y += extra;
|
||||
return r.has_point(p_point);
|
||||
|
||||
}
|
||||
|
||||
void WindowDialog::_input_event(const InputEvent& p_event) {
|
||||
void WindowDialog::_input_event(const InputEvent &p_event) {
|
||||
|
||||
if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==BUTTON_LEFT) {
|
||||
if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == BUTTON_LEFT) {
|
||||
|
||||
if (p_event.mouse_button.pressed && p_event.mouse_button.y < 0)
|
||||
dragging=true;
|
||||
dragging = true;
|
||||
else if (dragging && !p_event.mouse_button.pressed)
|
||||
dragging=false;
|
||||
dragging = false;
|
||||
}
|
||||
|
||||
|
||||
if (p_event.type == InputEvent::MOUSE_MOTION && dragging) {
|
||||
|
||||
Point2 rel( p_event.mouse_motion.relative_x, p_event.mouse_motion.relative_y );
|
||||
Point2 rel(p_event.mouse_motion.relative_x, p_event.mouse_motion.relative_y);
|
||||
Point2 pos = get_pos();
|
||||
|
||||
pos+=rel;
|
||||
pos += rel;
|
||||
|
||||
if (pos.y<0)
|
||||
pos.y=0;
|
||||
if (pos.y < 0)
|
||||
pos.y = 0;
|
||||
|
||||
set_pos(pos);
|
||||
}
|
||||
|
|
@ -74,35 +71,33 @@ void WindowDialog::_input_event(const InputEvent& p_event) {
|
|||
|
||||
void WindowDialog::_notification(int p_what) {
|
||||
|
||||
switch(p_what) {
|
||||
switch (p_what) {
|
||||
|
||||
case NOTIFICATION_DRAW: {
|
||||
|
||||
RID ci = get_canvas_item();
|
||||
Size2 s = get_size();
|
||||
Ref<StyleBox> st = get_stylebox("panel","WindowDialog");
|
||||
st->draw(ci,Rect2(Point2(),s));
|
||||
int th = get_constant("title_height","WindowDialog");
|
||||
Color tc = get_color("title_color","WindowDialog");
|
||||
Ref<Font> font = get_font("title_font","WindowDialog");
|
||||
int ofs = (s.width-font->get_string_size(title).width)/2;
|
||||
Ref<StyleBox> st = get_stylebox("panel", "WindowDialog");
|
||||
st->draw(ci, Rect2(Point2(), s));
|
||||
int th = get_constant("title_height", "WindowDialog");
|
||||
Color tc = get_color("title_color", "WindowDialog");
|
||||
Ref<Font> font = get_font("title_font", "WindowDialog");
|
||||
int ofs = (s.width - font->get_string_size(title).width) / 2;
|
||||
//int ofs = st->get_margin(MARGIN_LEFT);
|
||||
draw_string(font,Point2(ofs,-th+font->get_ascent()),title,tc,s.width - st->get_minimum_size().width);
|
||||
|
||||
draw_string(font, Point2(ofs, -th + font->get_ascent()), title, tc, s.width - st->get_minimum_size().width);
|
||||
|
||||
} break;
|
||||
case NOTIFICATION_THEME_CHANGED:
|
||||
case NOTIFICATION_ENTER_TREE: {
|
||||
|
||||
close_button->set_normal_texture( get_icon("close","WindowDialog"));
|
||||
close_button->set_pressed_texture( get_icon("close","WindowDialog"));
|
||||
close_button->set_hover_texture( get_icon("close_hilite","WindowDialog"));
|
||||
close_button->set_anchor(MARGIN_LEFT,ANCHOR_END);
|
||||
close_button->set_begin( Point2( get_constant("close_h_ofs","WindowDialog"), -get_constant("close_v_ofs","WindowDialog") ));
|
||||
close_button->set_normal_texture(get_icon("close", "WindowDialog"));
|
||||
close_button->set_pressed_texture(get_icon("close", "WindowDialog"));
|
||||
close_button->set_hover_texture(get_icon("close_hilite", "WindowDialog"));
|
||||
close_button->set_anchor(MARGIN_LEFT, ANCHOR_END);
|
||||
close_button->set_begin(Point2(get_constant("close_h_ofs", "WindowDialog"), -get_constant("close_v_ofs", "WindowDialog")));
|
||||
|
||||
} break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void WindowDialog::_closed() {
|
||||
|
|
@ -111,103 +106,90 @@ void WindowDialog::_closed() {
|
|||
hide();
|
||||
}
|
||||
|
||||
void WindowDialog::set_title(const String& p_title) {
|
||||
void WindowDialog::set_title(const String &p_title) {
|
||||
|
||||
title=XL_MESSAGE(p_title);
|
||||
title = XL_MESSAGE(p_title);
|
||||
update();
|
||||
}
|
||||
|
||||
Size2 WindowDialog::get_minimum_size() const {
|
||||
|
||||
Ref<Font> font = get_font("title_font","WindowDialog");
|
||||
int msx=close_button->get_combined_minimum_size().x;
|
||||
msx+=font->get_string_size(title).x;
|
||||
Ref<Font> font = get_font("title_font", "WindowDialog");
|
||||
int msx = close_button->get_combined_minimum_size().x;
|
||||
msx += font->get_string_size(title).x;
|
||||
|
||||
return Size2(msx,1);
|
||||
return Size2(msx, 1);
|
||||
}
|
||||
|
||||
|
||||
String WindowDialog::get_title() const {
|
||||
|
||||
return title;
|
||||
}
|
||||
|
||||
|
||||
TextureButton *WindowDialog::get_close_button() {
|
||||
|
||||
|
||||
return close_button;
|
||||
}
|
||||
|
||||
void WindowDialog::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method( _MD("_input_event"),&WindowDialog::_input_event);
|
||||
ObjectTypeDB::bind_method( _MD("set_title","title"),&WindowDialog::set_title);
|
||||
ObjectTypeDB::bind_method( _MD("get_title"),&WindowDialog::get_title);
|
||||
ObjectTypeDB::bind_method( _MD("_closed"),&WindowDialog::_closed);
|
||||
ObjectTypeDB::bind_method( _MD("get_close_button:TextureButton"),&WindowDialog::get_close_button);
|
||||
ObjectTypeDB::bind_method(_MD("_input_event"), &WindowDialog::_input_event);
|
||||
ObjectTypeDB::bind_method(_MD("set_title", "title"), &WindowDialog::set_title);
|
||||
ObjectTypeDB::bind_method(_MD("get_title"), &WindowDialog::get_title);
|
||||
ObjectTypeDB::bind_method(_MD("_closed"), &WindowDialog::_closed);
|
||||
ObjectTypeDB::bind_method(_MD("get_close_button:TextureButton"), &WindowDialog::get_close_button);
|
||||
|
||||
ADD_PROPERTY( PropertyInfo(Variant::STRING,"window/title",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_DEFAULT_INTL),_SCS("set_title"),_SCS("get_title"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "window/title", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT_INTL), _SCS("set_title"), _SCS("get_title"));
|
||||
}
|
||||
|
||||
WindowDialog::WindowDialog() {
|
||||
|
||||
//title="Hello!";
|
||||
dragging=false;
|
||||
close_button = memnew( TextureButton );
|
||||
dragging = false;
|
||||
close_button = memnew(TextureButton);
|
||||
add_child(close_button);
|
||||
close_button->connect("pressed",this,"_closed");
|
||||
|
||||
close_button->connect("pressed", this, "_closed");
|
||||
}
|
||||
|
||||
WindowDialog::~WindowDialog(){
|
||||
|
||||
|
||||
WindowDialog::~WindowDialog() {
|
||||
}
|
||||
|
||||
|
||||
void PopupDialog::_notification(int p_what) {
|
||||
|
||||
if (p_what==NOTIFICATION_DRAW) {
|
||||
if (p_what == NOTIFICATION_DRAW) {
|
||||
|
||||
RID ci = get_canvas_item();
|
||||
get_stylebox("panel","PopupMenu")->draw(ci,Rect2(Point2(),get_size()));
|
||||
get_stylebox("panel", "PopupMenu")->draw(ci, Rect2(Point2(), get_size()));
|
||||
}
|
||||
}
|
||||
|
||||
PopupDialog::PopupDialog() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
PopupDialog::~PopupDialog() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
|
||||
|
||||
void AcceptDialog::_post_popup() {
|
||||
|
||||
WindowDialog::_post_popup();
|
||||
get_ok()->grab_focus();
|
||||
|
||||
}
|
||||
|
||||
void AcceptDialog::_notification(int p_what) {
|
||||
|
||||
if (p_what==NOTIFICATION_MODAL_CLOSE) {
|
||||
if (p_what == NOTIFICATION_MODAL_CLOSE) {
|
||||
|
||||
cancel_pressed();
|
||||
} if (p_what==NOTIFICATION_RESIZED) {
|
||||
}
|
||||
if (p_what == NOTIFICATION_RESIZED) {
|
||||
|
||||
_update_child_rect();
|
||||
}
|
||||
}
|
||||
|
||||
void AcceptDialog::_builtin_text_entered(const String& p_text) {
|
||||
void AcceptDialog::_builtin_text_entered(const String &p_text) {
|
||||
|
||||
_ok_pressed();
|
||||
}
|
||||
|
|
@ -218,7 +200,6 @@ void AcceptDialog::_ok_pressed() {
|
|||
hide();
|
||||
ok_pressed();
|
||||
emit_signal("confirmed");
|
||||
|
||||
}
|
||||
void AcceptDialog::_close_pressed() {
|
||||
|
||||
|
|
@ -238,7 +219,7 @@ void AcceptDialog::set_text(String p_text) {
|
|||
|
||||
void AcceptDialog::set_hide_on_ok(bool p_hide) {
|
||||
|
||||
hide_on_ok=p_hide;
|
||||
hide_on_ok = p_hide;
|
||||
}
|
||||
|
||||
bool AcceptDialog::get_hide_on_ok() const {
|
||||
|
|
@ -246,24 +227,23 @@ bool AcceptDialog::get_hide_on_ok() const {
|
|||
return hide_on_ok;
|
||||
}
|
||||
|
||||
|
||||
void AcceptDialog::register_text_enter(Node *p_line_edit) {
|
||||
|
||||
ERR_FAIL_NULL(p_line_edit);
|
||||
p_line_edit->connect("text_entered", this,"_builtin_text_entered");
|
||||
p_line_edit->connect("text_entered", this, "_builtin_text_entered");
|
||||
}
|
||||
|
||||
void AcceptDialog::_update_child_rect() {
|
||||
Size2 label_size=label->get_minimum_size();
|
||||
Size2 label_size = label->get_minimum_size();
|
||||
if (label->get_text().empty()) {
|
||||
label_size.height = 0;
|
||||
}
|
||||
int margin = get_constant("margin","Dialogs");
|
||||
int margin = get_constant("margin", "Dialogs");
|
||||
Size2 size = get_size();
|
||||
Size2 hminsize = hbc->get_combined_minimum_size();
|
||||
|
||||
Vector2 cpos(margin,margin+label_size.height);
|
||||
Vector2 csize(size.x-margin*2,size.y-margin*3-hminsize.y-label_size.height);
|
||||
Vector2 cpos(margin, margin + label_size.height);
|
||||
Vector2 csize(size.x - margin * 2, size.y - margin * 3 - hminsize.y - label_size.height);
|
||||
|
||||
if (child) {
|
||||
|
||||
|
|
@ -271,64 +251,61 @@ void AcceptDialog::_update_child_rect() {
|
|||
child->set_size(csize);
|
||||
}
|
||||
|
||||
cpos.y+=csize.y+margin;
|
||||
csize.y=hminsize.y;
|
||||
cpos.y += csize.y + margin;
|
||||
csize.y = hminsize.y;
|
||||
|
||||
hbc->set_pos(cpos);
|
||||
hbc->set_size(csize);
|
||||
|
||||
}
|
||||
|
||||
Size2 AcceptDialog::get_minimum_size() const {
|
||||
|
||||
int margin = get_constant("margin","Dialogs");
|
||||
int margin = get_constant("margin", "Dialogs");
|
||||
Size2 minsize = label->get_combined_minimum_size();
|
||||
if (child) {
|
||||
|
||||
Size2 cminsize = child->get_combined_minimum_size();
|
||||
minsize.x=MAX(cminsize.x,minsize.x);
|
||||
minsize.y=MAX(cminsize.y,minsize.y);
|
||||
minsize.x = MAX(cminsize.x, minsize.x);
|
||||
minsize.y = MAX(cminsize.y, minsize.y);
|
||||
}
|
||||
|
||||
Size2 hminsize = hbc->get_combined_minimum_size();
|
||||
minsize.x = MAX(hminsize.x,minsize.x);
|
||||
minsize.y+=hminsize.y;
|
||||
minsize.x+=margin*2;
|
||||
minsize.y+=margin*3; //one as separation between hbc and child
|
||||
minsize.x = MAX(hminsize.x, minsize.x);
|
||||
minsize.y += hminsize.y;
|
||||
minsize.x += margin * 2;
|
||||
minsize.y += margin * 3; //one as separation between hbc and child
|
||||
|
||||
Size2 wmsize = WindowDialog::get_minimum_size();
|
||||
minsize.x=MAX(wmsize.x,minsize.x);
|
||||
minsize.x = MAX(wmsize.x, minsize.x);
|
||||
return minsize;
|
||||
}
|
||||
|
||||
|
||||
void AcceptDialog::set_child_rect(Control *p_child) {
|
||||
|
||||
ERR_FAIL_COND(p_child->get_parent()!=this);
|
||||
ERR_FAIL_COND(p_child->get_parent() != this);
|
||||
|
||||
//p_child->set_area_as_parent_rect(get_constant("margin","Dialogs"));
|
||||
child=p_child;
|
||||
child = p_child;
|
||||
minimum_size_changed();
|
||||
_update_child_rect();
|
||||
}
|
||||
|
||||
void AcceptDialog::remove_child_notify(Node *p_child) {
|
||||
|
||||
if (p_child==child) {
|
||||
child=NULL;
|
||||
if (p_child == child) {
|
||||
child = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void AcceptDialog::_custom_action(const String& p_action) {
|
||||
void AcceptDialog::_custom_action(const String &p_action) {
|
||||
|
||||
emit_signal("custom_action",p_action);
|
||||
emit_signal("custom_action", p_action);
|
||||
custom_action(p_action);
|
||||
}
|
||||
|
||||
Button* AcceptDialog::add_button(const String& p_text,bool p_right,const String& p_action) {
|
||||
Button *AcceptDialog::add_button(const String &p_text, bool p_right, const String &p_action) {
|
||||
|
||||
|
||||
Button *button = memnew( Button );
|
||||
Button *button = memnew(Button);
|
||||
button->set_text(p_text);
|
||||
if (p_right) {
|
||||
hbc->add_child(button);
|
||||
|
|
@ -336,99 +313,92 @@ Button* AcceptDialog::add_button(const String& p_text,bool p_right,const String&
|
|||
} else {
|
||||
|
||||
hbc->add_child(button);
|
||||
hbc->move_child(button,0);
|
||||
hbc->move_child(button, 0);
|
||||
hbc->add_spacer(true);
|
||||
}
|
||||
|
||||
if (p_action!="") {
|
||||
button->connect("pressed",this,"_custom_action",varray(p_action));
|
||||
if (p_action != "") {
|
||||
button->connect("pressed", this, "_custom_action", varray(p_action));
|
||||
}
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
Button* AcceptDialog::add_cancel(const String &p_cancel) {
|
||||
Button *AcceptDialog::add_cancel(const String &p_cancel) {
|
||||
|
||||
String c = p_cancel;
|
||||
if (p_cancel=="")
|
||||
c=RTR("Cancel");
|
||||
Button *b = swap_ok_cancel ? add_button(c,true) : add_button(c);
|
||||
b->connect("pressed",this,"_closed");
|
||||
if (p_cancel == "")
|
||||
c = RTR("Cancel");
|
||||
Button *b = swap_ok_cancel ? add_button(c, true) : add_button(c);
|
||||
b->connect("pressed", this, "_closed");
|
||||
return b;
|
||||
}
|
||||
|
||||
void AcceptDialog::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("_ok"),&AcceptDialog::_ok_pressed);
|
||||
ObjectTypeDB::bind_method(_MD("get_ok"),&AcceptDialog::get_ok);
|
||||
ObjectTypeDB::bind_method(_MD("get_label"),&AcceptDialog::get_label);
|
||||
ObjectTypeDB::bind_method(_MD("set_hide_on_ok","enabled"),&AcceptDialog::set_hide_on_ok);
|
||||
ObjectTypeDB::bind_method(_MD("get_hide_on_ok"),&AcceptDialog::get_hide_on_ok);
|
||||
ObjectTypeDB::bind_method(_MD("add_button:Button","text","right","action"),&AcceptDialog::add_button,DEFVAL(false),DEFVAL(""));
|
||||
ObjectTypeDB::bind_method(_MD("add_cancel:Button","name"),&AcceptDialog::add_cancel);
|
||||
ObjectTypeDB::bind_method(_MD("_builtin_text_entered"),&AcceptDialog::_builtin_text_entered);
|
||||
ObjectTypeDB::bind_method(_MD("register_text_enter:LineEdit","line_edit"),&AcceptDialog::register_text_enter);
|
||||
ObjectTypeDB::bind_method(_MD("_custom_action"),&AcceptDialog::_custom_action);
|
||||
ObjectTypeDB::bind_method(_MD("set_text","text"),&AcceptDialog::set_text);
|
||||
ObjectTypeDB::bind_method(_MD("get_text"),&AcceptDialog::get_text);
|
||||
ObjectTypeDB::bind_method(_MD("_ok"), &AcceptDialog::_ok_pressed);
|
||||
ObjectTypeDB::bind_method(_MD("get_ok"), &AcceptDialog::get_ok);
|
||||
ObjectTypeDB::bind_method(_MD("get_label"), &AcceptDialog::get_label);
|
||||
ObjectTypeDB::bind_method(_MD("set_hide_on_ok", "enabled"), &AcceptDialog::set_hide_on_ok);
|
||||
ObjectTypeDB::bind_method(_MD("get_hide_on_ok"), &AcceptDialog::get_hide_on_ok);
|
||||
ObjectTypeDB::bind_method(_MD("add_button:Button", "text", "right", "action"), &AcceptDialog::add_button, DEFVAL(false), DEFVAL(""));
|
||||
ObjectTypeDB::bind_method(_MD("add_cancel:Button", "name"), &AcceptDialog::add_cancel);
|
||||
ObjectTypeDB::bind_method(_MD("_builtin_text_entered"), &AcceptDialog::_builtin_text_entered);
|
||||
ObjectTypeDB::bind_method(_MD("register_text_enter:LineEdit", "line_edit"), &AcceptDialog::register_text_enter);
|
||||
ObjectTypeDB::bind_method(_MD("_custom_action"), &AcceptDialog::_custom_action);
|
||||
ObjectTypeDB::bind_method(_MD("set_text", "text"), &AcceptDialog::set_text);
|
||||
ObjectTypeDB::bind_method(_MD("get_text"), &AcceptDialog::get_text);
|
||||
|
||||
ADD_SIGNAL( MethodInfo("confirmed") );
|
||||
ADD_SIGNAL( MethodInfo("custom_action",PropertyInfo(Variant::STRING,"action")) );
|
||||
|
||||
ADD_PROPERTYNZ( PropertyInfo(Variant::STRING,"dialog/text",PROPERTY_HINT_MULTILINE_TEXT,"",PROPERTY_USAGE_DEFAULT_INTL),_SCS("set_text"),_SCS("get_text"));
|
||||
ADD_PROPERTY( PropertyInfo(Variant::BOOL, "dialog/hide_on_ok"),_SCS("set_hide_on_ok"),_SCS("get_hide_on_ok") );
|
||||
ADD_SIGNAL(MethodInfo("confirmed"));
|
||||
ADD_SIGNAL(MethodInfo("custom_action", PropertyInfo(Variant::STRING, "action")));
|
||||
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::STRING, "dialog/text", PROPERTY_HINT_MULTILINE_TEXT, "", PROPERTY_USAGE_DEFAULT_INTL), _SCS("set_text"), _SCS("get_text"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "dialog/hide_on_ok"), _SCS("set_hide_on_ok"), _SCS("get_hide_on_ok"));
|
||||
}
|
||||
|
||||
|
||||
bool AcceptDialog::swap_ok_cancel=false;
|
||||
bool AcceptDialog::swap_ok_cancel = false;
|
||||
void AcceptDialog::set_swap_ok_cancel(bool p_swap) {
|
||||
|
||||
swap_ok_cancel=p_swap;
|
||||
swap_ok_cancel = p_swap;
|
||||
}
|
||||
|
||||
AcceptDialog::AcceptDialog() {
|
||||
|
||||
int margin = get_constant("margin","Dialogs");
|
||||
int button_margin = get_constant("button_margin","Dialogs");
|
||||
int margin = get_constant("margin", "Dialogs");
|
||||
int button_margin = get_constant("button_margin", "Dialogs");
|
||||
|
||||
|
||||
label = memnew( Label );
|
||||
label->set_anchor(MARGIN_RIGHT,ANCHOR_END);
|
||||
label->set_anchor(MARGIN_BOTTOM,ANCHOR_END);
|
||||
label->set_begin( Point2( margin, margin) );
|
||||
label->set_end( Point2( margin, button_margin+10) );
|
||||
label = memnew(Label);
|
||||
label->set_anchor(MARGIN_RIGHT, ANCHOR_END);
|
||||
label->set_anchor(MARGIN_BOTTOM, ANCHOR_END);
|
||||
label->set_begin(Point2(margin, margin));
|
||||
label->set_end(Point2(margin, button_margin + 10));
|
||||
//label->set_autowrap(true);
|
||||
add_child(label);
|
||||
|
||||
hbc = memnew( HBoxContainer );
|
||||
hbc = memnew(HBoxContainer);
|
||||
add_child(hbc);
|
||||
|
||||
hbc->add_spacer();
|
||||
ok = memnew( Button );
|
||||
ok = memnew(Button);
|
||||
ok->set_text(RTR("OK"));
|
||||
hbc->add_child(ok);
|
||||
hbc->add_spacer();
|
||||
|
||||
|
||||
ok->connect("pressed", this,"_ok");
|
||||
ok->connect("pressed", this, "_ok");
|
||||
set_as_toplevel(true);
|
||||
|
||||
hide_on_ok=true;
|
||||
hide_on_ok = true;
|
||||
set_title(RTR("Alert!"));
|
||||
|
||||
child=NULL;
|
||||
child = NULL;
|
||||
}
|
||||
|
||||
|
||||
AcceptDialog::~AcceptDialog()
|
||||
{
|
||||
AcceptDialog::~AcceptDialog() {
|
||||
}
|
||||
|
||||
|
||||
void ConfirmationDialog::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("get_cancel:Button"),&ConfirmationDialog::get_cancel);
|
||||
ObjectTypeDB::bind_method(_MD("get_cancel:Button"), &ConfirmationDialog::get_cancel);
|
||||
}
|
||||
|
||||
Button *ConfirmationDialog::get_cancel() {
|
||||
|
|
|
|||
|
|
@ -29,110 +29,101 @@
|
|||
#ifndef DIALOGS_H
|
||||
#define DIALOGS_H
|
||||
|
||||
#include "scene/gui/label.h"
|
||||
#include "box_container.h"
|
||||
#include "scene/gui/button.h"
|
||||
#include "scene/gui/texture_button.h"
|
||||
#include "scene/gui/label.h"
|
||||
#include "scene/gui/panel.h"
|
||||
#include "scene/gui/popup.h"
|
||||
#include "box_container.h"
|
||||
#include "scene/gui/texture_button.h"
|
||||
/**
|
||||
@author Juan Linietsky <reduzio@gmail.com>
|
||||
*/
|
||||
|
||||
|
||||
class WindowDialog : public Popup {
|
||||
|
||||
OBJ_TYPE(WindowDialog,Popup);
|
||||
OBJ_TYPE(WindowDialog, Popup);
|
||||
|
||||
TextureButton *close_button;
|
||||
String title;
|
||||
bool dragging;
|
||||
|
||||
void _input_event(const InputEvent& p_event);
|
||||
void _input_event(const InputEvent &p_event);
|
||||
void _closed();
|
||||
|
||||
protected:
|
||||
virtual void _post_popup();
|
||||
|
||||
virtual void _close_pressed() {}
|
||||
virtual bool has_point(const Point2& p_point) const;
|
||||
virtual void _close_pressed() {}
|
||||
virtual bool has_point(const Point2 &p_point) const;
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
public:
|
||||
|
||||
public:
|
||||
TextureButton *get_close_button();
|
||||
|
||||
void set_title(const String& p_title);
|
||||
void set_title(const String &p_title);
|
||||
String get_title() const;
|
||||
|
||||
Size2 get_minimum_size() const;
|
||||
|
||||
WindowDialog();
|
||||
~WindowDialog();
|
||||
|
||||
};
|
||||
|
||||
class PopupDialog : public Popup {
|
||||
|
||||
OBJ_TYPE(PopupDialog,Popup);
|
||||
OBJ_TYPE(PopupDialog, Popup);
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
public:
|
||||
|
||||
public:
|
||||
PopupDialog();
|
||||
~PopupDialog();
|
||||
|
||||
};
|
||||
|
||||
|
||||
class LineEdit;
|
||||
|
||||
class AcceptDialog : public WindowDialog {
|
||||
|
||||
OBJ_TYPE(AcceptDialog,WindowDialog);
|
||||
OBJ_TYPE(AcceptDialog, WindowDialog);
|
||||
|
||||
Control *child;
|
||||
HBoxContainer *hbc;
|
||||
Label *label;
|
||||
Button *ok;
|
||||
// Button *cancel; no more cancel (there is X on tht titlebar)
|
||||
// Button *cancel; no more cancel (there is X on tht titlebar)
|
||||
bool hide_on_ok;
|
||||
|
||||
|
||||
void _custom_action(const String& p_action);
|
||||
void _custom_action(const String &p_action);
|
||||
void _ok_pressed();
|
||||
void _close_pressed();
|
||||
void _builtin_text_entered(const String& p_text);
|
||||
void _builtin_text_entered(const String &p_text);
|
||||
void _update_child_rect();
|
||||
|
||||
static bool swap_ok_cancel;
|
||||
|
||||
|
||||
virtual void remove_child_notify(Node *p_child);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
virtual void _post_popup();
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
virtual void ok_pressed() {}
|
||||
virtual void cancel_pressed() {}
|
||||
virtual void custom_action(const String&) {}
|
||||
public:
|
||||
virtual void custom_action(const String &) {}
|
||||
|
||||
public:
|
||||
Size2 get_minimum_size() const;
|
||||
|
||||
Label *get_label() { return label; }
|
||||
static void set_swap_ok_cancel(bool p_swap);
|
||||
|
||||
|
||||
void register_text_enter(Node *p_line_edit);
|
||||
|
||||
Button *get_ok() { return ok; }
|
||||
Button* add_button(const String& p_text,bool p_right=false,const String& p_action="");
|
||||
Button* add_cancel(const String &p_cancel="");
|
||||
|
||||
Button *add_button(const String &p_text, bool p_right = false, const String &p_action = "");
|
||||
Button *add_cancel(const String &p_cancel = "");
|
||||
|
||||
void set_hide_on_ok(bool p_hide);
|
||||
bool get_hide_on_ok() const;
|
||||
|
|
@ -144,21 +135,19 @@ public:
|
|||
|
||||
AcceptDialog();
|
||||
~AcceptDialog();
|
||||
|
||||
};
|
||||
|
||||
|
||||
class ConfirmationDialog : public AcceptDialog {
|
||||
|
||||
OBJ_TYPE(ConfirmationDialog,AcceptDialog);
|
||||
OBJ_TYPE(ConfirmationDialog, AcceptDialog);
|
||||
Button *cancel;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
public:
|
||||
|
||||
public:
|
||||
Button *get_cancel();
|
||||
ConfirmationDialog();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -29,30 +29,28 @@
|
|||
#ifndef FILE_DIALOG_H
|
||||
#define FILE_DIALOG_H
|
||||
|
||||
#include "box_container.h"
|
||||
#include "os/dir_access.h"
|
||||
#include "scene/gui/dialogs.h"
|
||||
#include "scene/gui/dialogs.h"
|
||||
#include "scene/gui/tree.h"
|
||||
#include "scene/gui/line_edit.h"
|
||||
#include "scene/gui/option_button.h"
|
||||
#include "scene/gui/dialogs.h"
|
||||
#include "scene/gui/tool_button.h"
|
||||
#include "os/dir_access.h"
|
||||
#include "box_container.h"
|
||||
#include "scene/gui/tree.h"
|
||||
/**
|
||||
@author Juan Linietsky <reduzio@gmail.com>
|
||||
*/
|
||||
class FileDialog : public ConfirmationDialog {
|
||||
|
||||
OBJ_TYPE( FileDialog, ConfirmationDialog );
|
||||
OBJ_TYPE(FileDialog, ConfirmationDialog);
|
||||
|
||||
public:
|
||||
|
||||
enum Access {
|
||||
ACCESS_RESOURCES,
|
||||
ACCESS_USERDATA,
|
||||
ACCESS_FILESYSTEM
|
||||
};
|
||||
|
||||
|
||||
enum Mode {
|
||||
MODE_OPEN_FILE,
|
||||
MODE_OPEN_FILES,
|
||||
|
|
@ -61,8 +59,8 @@ public:
|
|||
MODE_SAVE_FILE
|
||||
};
|
||||
|
||||
typedef Ref<Texture> (*GetIconFunc)(const String&);
|
||||
typedef void (*RegisterFunc)(FileDialog*);
|
||||
typedef Ref<Texture> (*GetIconFunc)(const String &);
|
||||
typedef void (*RegisterFunc)(FileDialog *);
|
||||
|
||||
static GetIconFunc get_icon_func;
|
||||
static GetIconFunc get_large_icon_func;
|
||||
|
|
@ -70,7 +68,6 @@ public:
|
|||
static RegisterFunc unregister_func;
|
||||
|
||||
private:
|
||||
|
||||
ConfirmationDialog *makedialog;
|
||||
LineEdit *makedirname;
|
||||
|
||||
|
|
@ -93,7 +90,6 @@ private:
|
|||
|
||||
Vector<String> filters;
|
||||
|
||||
|
||||
static bool default_show_hidden_files;
|
||||
bool show_hidden_files;
|
||||
|
||||
|
|
@ -108,7 +104,7 @@ private:
|
|||
void _select_drive(int p_idx);
|
||||
void _tree_dc_selected();
|
||||
void _dir_entered(String p_dir);
|
||||
void _file_entered(const String& p_file);
|
||||
void _file_entered(const String &p_file);
|
||||
void _action_pressed();
|
||||
void _save_confirm_pressed();
|
||||
void _cancel_pressed();
|
||||
|
|
@ -118,20 +114,18 @@ private:
|
|||
|
||||
void _update_drives();
|
||||
|
||||
void _unhandled_input(const InputEvent& p_event);
|
||||
void _unhandled_input(const InputEvent &p_event);
|
||||
|
||||
virtual void _post_popup();
|
||||
|
||||
protected:
|
||||
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
//bind helpers
|
||||
public:
|
||||
|
||||
void clear_filters();
|
||||
void add_filter(const String& p_filter);
|
||||
void set_filters(const Vector<String>& p_filters);
|
||||
void add_filter(const String &p_filter);
|
||||
void set_filters(const Vector<String> &p_filters);
|
||||
Vector<String> get_filters() const;
|
||||
|
||||
void set_enable_multiple_selection(bool p_enable);
|
||||
|
|
@ -140,9 +134,9 @@ public:
|
|||
String get_current_dir() const;
|
||||
String get_current_file() const;
|
||||
String get_current_path() const;
|
||||
void set_current_dir(const String& p_dir);
|
||||
void set_current_file(const String& p_file);
|
||||
void set_current_path(const String& p_path);
|
||||
void set_current_dir(const String &p_dir);
|
||||
void set_current_file(const String &p_file);
|
||||
void set_current_path(const String &p_path);
|
||||
|
||||
void set_mode(Mode p_mode);
|
||||
Mode get_mode() const;
|
||||
|
|
@ -162,22 +156,22 @@ public:
|
|||
|
||||
FileDialog();
|
||||
~FileDialog();
|
||||
|
||||
};
|
||||
|
||||
class LineEditFileChooser : public HBoxContainer {
|
||||
|
||||
OBJ_TYPE( LineEditFileChooser, HBoxContainer );
|
||||
OBJ_TYPE(LineEditFileChooser, HBoxContainer);
|
||||
Button *button;
|
||||
LineEdit *line_edit;
|
||||
FileDialog *dialog;
|
||||
|
||||
void _chosen(const String& p_text);
|
||||
void _chosen(const String &p_text);
|
||||
void _browse();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
public:
|
||||
|
||||
public:
|
||||
Button *get_button() { return button; }
|
||||
LineEdit *get_line_edit() { return line_edit; }
|
||||
FileDialog *get_file_dialog() { return dialog; }
|
||||
|
|
@ -185,7 +179,7 @@ public:
|
|||
LineEditFileChooser();
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST( FileDialog::Mode );
|
||||
VARIANT_ENUM_CAST( FileDialog::Access );
|
||||
VARIANT_ENUM_CAST(FileDialog::Mode);
|
||||
VARIANT_ENUM_CAST(FileDialog::Access);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -39,33 +39,29 @@ class GraphEdit;
|
|||
|
||||
class GraphEditFilter : public Control {
|
||||
|
||||
OBJ_TYPE(GraphEditFilter,Control);
|
||||
OBJ_TYPE(GraphEditFilter, Control);
|
||||
|
||||
friend class GraphEdit;
|
||||
GraphEdit *ge;
|
||||
virtual bool has_point(const Point2& p_point) const;
|
||||
virtual bool has_point(const Point2 &p_point) const;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
GraphEditFilter(GraphEdit *p_edit);
|
||||
};
|
||||
|
||||
class GraphEdit : public Control {
|
||||
|
||||
OBJ_TYPE(GraphEdit,Control);
|
||||
public:
|
||||
OBJ_TYPE(GraphEdit, Control);
|
||||
|
||||
public:
|
||||
struct Connection {
|
||||
StringName from;
|
||||
StringName to;
|
||||
int from_port;
|
||||
int to_port;
|
||||
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
|
||||
ToolButton *zoom_minus;
|
||||
ToolButton *zoom_reset;
|
||||
ToolButton *zoom_plus;
|
||||
|
|
@ -74,9 +70,8 @@ private:
|
|||
void _zoom_reset();
|
||||
void _zoom_plus();
|
||||
|
||||
HScrollBar* h_scroll;
|
||||
VScrollBar* v_scroll;
|
||||
|
||||
HScrollBar *h_scroll;
|
||||
VScrollBar *v_scroll;
|
||||
|
||||
bool connecting;
|
||||
String connecting_from;
|
||||
|
|
@ -101,42 +96,42 @@ private:
|
|||
Point2 box_selecting_from;
|
||||
Point2 box_selecting_to;
|
||||
Rect2 box_selecting_rect;
|
||||
List<GraphNode*> previus_selected;
|
||||
List<GraphNode *> previus_selected;
|
||||
|
||||
bool right_disconnects;
|
||||
bool updating;
|
||||
List<Connection> connections;
|
||||
|
||||
void _draw_cos_line(const Vector2& p_from, const Vector2& p_to,const Color& p_color);
|
||||
void _draw_cos_line(const Vector2 &p_from, const Vector2 &p_to, const Color &p_color);
|
||||
|
||||
void _graph_node_raised(Node* p_gn);
|
||||
void _graph_node_raised(Node *p_gn);
|
||||
void _graph_node_moved(Node *p_gn);
|
||||
|
||||
void _update_scroll();
|
||||
void _scroll_moved(double);
|
||||
void _input_event(const InputEvent& p_ev);
|
||||
void _input_event(const InputEvent &p_ev);
|
||||
|
||||
GraphEditFilter *top_layer;
|
||||
void _top_layer_input(const InputEvent& p_ev);
|
||||
void _top_layer_input(const InputEvent &p_ev);
|
||||
void _top_layer_draw();
|
||||
void _update_scroll_offset();
|
||||
|
||||
Array _get_connection_list() const;
|
||||
|
||||
friend class GraphEditFilter;
|
||||
bool _filter_input(const Point2& p_point);
|
||||
protected:
|
||||
bool _filter_input(const Point2 &p_point);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
virtual void add_child_notify(Node *p_child);
|
||||
virtual void remove_child_notify(Node *p_child);
|
||||
void _notification(int p_what);
|
||||
virtual bool clips_input() const;
|
||||
public:
|
||||
|
||||
Error connect_node(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port);
|
||||
bool is_node_connected(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port);
|
||||
void disconnect_node(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port);
|
||||
public:
|
||||
Error connect_node(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port);
|
||||
bool is_node_connected(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port);
|
||||
void disconnect_node(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port);
|
||||
void clear_connections();
|
||||
|
||||
void set_zoom(float p_zoom);
|
||||
|
|
@ -150,7 +145,6 @@ public:
|
|||
|
||||
Vector2 get_scroll_ofs() const;
|
||||
|
||||
|
||||
GraphEdit();
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -29,356 +29,322 @@
|
|||
#include "graph_node.h"
|
||||
#include "method_bind_ext.inc"
|
||||
|
||||
|
||||
bool GraphNode::_set(const StringName& p_name, const Variant& p_value) {
|
||||
bool GraphNode::_set(const StringName &p_name, const Variant &p_value) {
|
||||
|
||||
if (!p_name.operator String().begins_with("slot/"))
|
||||
return false;
|
||||
|
||||
int idx=p_name.operator String().get_slice("/",1).to_int();
|
||||
String what = p_name.operator String().get_slice("/",2);
|
||||
|
||||
int idx = p_name.operator String().get_slice("/", 1).to_int();
|
||||
String what = p_name.operator String().get_slice("/", 2);
|
||||
|
||||
Slot si;
|
||||
if (slot_info.has(idx))
|
||||
si=slot_info[idx];
|
||||
si = slot_info[idx];
|
||||
|
||||
|
||||
if (what=="left_enabled")
|
||||
si.enable_left=p_value;
|
||||
else if (what=="left_type")
|
||||
si.type_left=p_value;
|
||||
else if (what=="left_color")
|
||||
si.color_left=p_value;
|
||||
else if (what=="right_enabled")
|
||||
si.enable_right=p_value;
|
||||
else if (what=="right_type")
|
||||
si.type_right=p_value;
|
||||
else if (what=="right_color")
|
||||
si.color_right=p_value;
|
||||
if (what == "left_enabled")
|
||||
si.enable_left = p_value;
|
||||
else if (what == "left_type")
|
||||
si.type_left = p_value;
|
||||
else if (what == "left_color")
|
||||
si.color_left = p_value;
|
||||
else if (what == "right_enabled")
|
||||
si.enable_right = p_value;
|
||||
else if (what == "right_type")
|
||||
si.type_right = p_value;
|
||||
else if (what == "right_color")
|
||||
si.color_right = p_value;
|
||||
else
|
||||
return false;
|
||||
|
||||
set_slot(idx,si.enable_left,si.type_left,si.color_left,si.enable_right,si.type_right,si.color_right);
|
||||
set_slot(idx, si.enable_left, si.type_left, si.color_left, si.enable_right, si.type_right, si.color_right);
|
||||
update();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GraphNode::_get(const StringName& p_name,Variant &r_ret) const{
|
||||
|
||||
|
||||
bool GraphNode::_get(const StringName &p_name, Variant &r_ret) const {
|
||||
|
||||
if (!p_name.operator String().begins_with("slot/")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int idx=p_name.operator String().get_slice("/",1).to_int();
|
||||
String what = p_name.operator String().get_slice("/",2);
|
||||
|
||||
|
||||
int idx = p_name.operator String().get_slice("/", 1).to_int();
|
||||
String what = p_name.operator String().get_slice("/", 2);
|
||||
|
||||
Slot si;
|
||||
if (slot_info.has(idx))
|
||||
si=slot_info[idx];
|
||||
si = slot_info[idx];
|
||||
|
||||
if (what=="left_enabled")
|
||||
r_ret=si.enable_left;
|
||||
else if (what=="left_type")
|
||||
r_ret=si.type_left;
|
||||
else if (what=="left_color")
|
||||
r_ret=si.color_left;
|
||||
else if (what=="right_enabled")
|
||||
r_ret=si.enable_right;
|
||||
else if (what=="right_type")
|
||||
r_ret=si.type_right;
|
||||
else if (what=="right_color")
|
||||
r_ret=si.color_right;
|
||||
if (what == "left_enabled")
|
||||
r_ret = si.enable_left;
|
||||
else if (what == "left_type")
|
||||
r_ret = si.type_left;
|
||||
else if (what == "left_color")
|
||||
r_ret = si.color_left;
|
||||
else if (what == "right_enabled")
|
||||
r_ret = si.enable_right;
|
||||
else if (what == "right_type")
|
||||
r_ret = si.type_right;
|
||||
else if (what == "right_color")
|
||||
r_ret = si.color_right;
|
||||
else
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
void GraphNode::_get_property_list( List<PropertyInfo> *p_list) const{
|
||||
void GraphNode::_get_property_list(List<PropertyInfo> *p_list) const {
|
||||
|
||||
int idx=0;
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
Control *c=get_child(i)->cast_to<Control>();
|
||||
if (!c || c->is_set_as_toplevel() )
|
||||
int idx = 0;
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c || c->is_set_as_toplevel())
|
||||
continue;
|
||||
|
||||
String base="slot/"+itos(idx)+"/";
|
||||
String base = "slot/" + itos(idx) + "/";
|
||||
|
||||
p_list->push_back(PropertyInfo(Variant::BOOL,base+"left_enabled"));
|
||||
p_list->push_back(PropertyInfo(Variant::INT,base+"left_type"));
|
||||
p_list->push_back(PropertyInfo(Variant::COLOR,base+"left_color"));
|
||||
p_list->push_back(PropertyInfo(Variant::BOOL,base+"right_enabled"));
|
||||
p_list->push_back(PropertyInfo(Variant::INT,base+"right_type"));
|
||||
p_list->push_back(PropertyInfo(Variant::COLOR,base+"right_color"));
|
||||
p_list->push_back(PropertyInfo(Variant::BOOL, base + "left_enabled"));
|
||||
p_list->push_back(PropertyInfo(Variant::INT, base + "left_type"));
|
||||
p_list->push_back(PropertyInfo(Variant::COLOR, base + "left_color"));
|
||||
p_list->push_back(PropertyInfo(Variant::BOOL, base + "right_enabled"));
|
||||
p_list->push_back(PropertyInfo(Variant::INT, base + "right_type"));
|
||||
p_list->push_back(PropertyInfo(Variant::COLOR, base + "right_color"));
|
||||
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GraphNode::_resort() {
|
||||
|
||||
|
||||
|
||||
int sep=get_constant("separation");
|
||||
Ref<StyleBox> sb=get_stylebox("frame");
|
||||
bool first=true;
|
||||
int sep = get_constant("separation");
|
||||
Ref<StyleBox> sb = get_stylebox("frame");
|
||||
bool first = true;
|
||||
|
||||
Size2 minsize;
|
||||
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
Control *c=get_child(i)->cast_to<Control>();
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c)
|
||||
continue;
|
||||
if (c->is_set_as_toplevel())
|
||||
continue;
|
||||
|
||||
Size2i size=c->get_combined_minimum_size();
|
||||
Size2i size = c->get_combined_minimum_size();
|
||||
|
||||
minsize.y+=size.y;
|
||||
minsize.x=MAX(minsize.x,size.x);
|
||||
minsize.y += size.y;
|
||||
minsize.x = MAX(minsize.x, size.x);
|
||||
|
||||
if (first)
|
||||
first=false;
|
||||
first = false;
|
||||
else
|
||||
minsize.y+=sep;
|
||||
|
||||
minsize.y += sep;
|
||||
}
|
||||
|
||||
|
||||
int vofs=0;
|
||||
int vofs = 0;
|
||||
int w = get_size().x - sb->get_minimum_size().x;
|
||||
|
||||
|
||||
cache_y.clear();
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
Control *c=get_child(i)->cast_to<Control>();
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c)
|
||||
continue;
|
||||
if (c->is_set_as_toplevel())
|
||||
continue;
|
||||
|
||||
Size2i size=c->get_combined_minimum_size();
|
||||
Size2i size = c->get_combined_minimum_size();
|
||||
|
||||
Rect2 r(sb->get_margin(MARGIN_LEFT),sb->get_margin(MARGIN_TOP)+vofs,w,size.y);
|
||||
|
||||
fit_child_in_rect(c,r);
|
||||
cache_y.push_back(vofs+size.y*0.5);
|
||||
|
||||
if (vofs>0)
|
||||
vofs+=sep;
|
||||
vofs+=size.y;
|
||||
Rect2 r(sb->get_margin(MARGIN_LEFT), sb->get_margin(MARGIN_TOP) + vofs, w, size.y);
|
||||
|
||||
fit_child_in_rect(c, r);
|
||||
cache_y.push_back(vofs + size.y * 0.5);
|
||||
|
||||
if (vofs > 0)
|
||||
vofs += sep;
|
||||
vofs += size.y;
|
||||
}
|
||||
|
||||
_change_notify();
|
||||
update();
|
||||
connpos_dirty=true;
|
||||
|
||||
|
||||
connpos_dirty = true;
|
||||
}
|
||||
|
||||
|
||||
void GraphNode::_notification(int p_what) {
|
||||
|
||||
if (p_what==NOTIFICATION_DRAW) {
|
||||
if (p_what == NOTIFICATION_DRAW) {
|
||||
|
||||
Ref<StyleBox> sb=get_stylebox(selected ? "selectedframe" : "frame");
|
||||
Ref<Texture> port =get_icon("port");
|
||||
Ref<Texture> close =get_icon("close");
|
||||
Ref<StyleBox> sb = get_stylebox(selected ? "selectedframe" : "frame");
|
||||
Ref<Texture> port = get_icon("port");
|
||||
Ref<Texture> close = get_icon("close");
|
||||
int close_offset = get_constant("close_offset");
|
||||
Ref<Font> title_font = get_font("title_font");
|
||||
int title_offset = get_constant("title_offset");
|
||||
Color title_color = get_color("title_color");
|
||||
Point2i icofs = -port->get_size()*0.5;
|
||||
int edgeofs=get_constant("port_offset");
|
||||
icofs.y+=sb->get_margin(MARGIN_TOP);
|
||||
draw_style_box(sb,Rect2(Point2(),get_size()));
|
||||
Point2i icofs = -port->get_size() * 0.5;
|
||||
int edgeofs = get_constant("port_offset");
|
||||
icofs.y += sb->get_margin(MARGIN_TOP);
|
||||
draw_style_box(sb, Rect2(Point2(), get_size()));
|
||||
|
||||
int w = get_size().width-sb->get_minimum_size().x;
|
||||
int w = get_size().width - sb->get_minimum_size().x;
|
||||
|
||||
if (show_close)
|
||||
w-=close->get_width();
|
||||
w -= close->get_width();
|
||||
|
||||
draw_string(title_font,Point2(sb->get_margin(MARGIN_LEFT),-title_font->get_height()+title_font->get_ascent()+title_offset),title,title_color,w);
|
||||
draw_string(title_font, Point2(sb->get_margin(MARGIN_LEFT), -title_font->get_height() + title_font->get_ascent() + title_offset), title, title_color, w);
|
||||
if (show_close) {
|
||||
Vector2 cpos = Point2(w+sb->get_margin(MARGIN_LEFT),-close->get_height()+close_offset);
|
||||
draw_texture(close,cpos);
|
||||
close_rect.pos=cpos;
|
||||
close_rect.size=close->get_size();
|
||||
Vector2 cpos = Point2(w + sb->get_margin(MARGIN_LEFT), -close->get_height() + close_offset);
|
||||
draw_texture(close, cpos);
|
||||
close_rect.pos = cpos;
|
||||
close_rect.size = close->get_size();
|
||||
} else {
|
||||
close_rect=Rect2();
|
||||
close_rect = Rect2();
|
||||
}
|
||||
|
||||
for (Map<int,Slot>::Element *E=slot_info.front();E;E=E->next()) {
|
||||
for (Map<int, Slot>::Element *E = slot_info.front(); E; E = E->next()) {
|
||||
|
||||
if (E->key() < 0 || E->key()>=cache_y.size())
|
||||
if (E->key() < 0 || E->key() >= cache_y.size())
|
||||
continue;
|
||||
if (!slot_info.has(E->key()))
|
||||
continue;
|
||||
const Slot &s=slot_info[E->key()];
|
||||
const Slot &s = slot_info[E->key()];
|
||||
//left
|
||||
if (s.enable_left)
|
||||
port->draw(get_canvas_item(),icofs+Point2(edgeofs,cache_y[E->key()]),s.color_left);
|
||||
port->draw(get_canvas_item(), icofs + Point2(edgeofs, cache_y[E->key()]), s.color_left);
|
||||
if (s.enable_right)
|
||||
port->draw(get_canvas_item(),icofs+Point2(get_size().x-edgeofs,cache_y[E->key()]),s.color_right);
|
||||
|
||||
port->draw(get_canvas_item(), icofs + Point2(get_size().x - edgeofs, cache_y[E->key()]), s.color_right);
|
||||
}
|
||||
}
|
||||
|
||||
if (p_what==NOTIFICATION_SORT_CHILDREN) {
|
||||
if (p_what == NOTIFICATION_SORT_CHILDREN) {
|
||||
|
||||
_resort();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void GraphNode::set_slot(int p_idx, bool p_enable_left, int p_type_left, const Color &p_color_left, bool p_enable_right, int p_type_right, const Color &p_color_right) {
|
||||
|
||||
void GraphNode::set_slot(int p_idx,bool p_enable_left,int p_type_left,const Color& p_color_left, bool p_enable_right,int p_type_right,const Color& p_color_right) {
|
||||
ERR_FAIL_COND(p_idx < 0);
|
||||
|
||||
ERR_FAIL_COND(p_idx<0);
|
||||
|
||||
if (!p_enable_left && p_type_left==0 && p_color_left==Color(1,1,1,1) && !p_enable_right && p_type_right==0 && p_color_right==Color(1,1,1,1)) {
|
||||
if (!p_enable_left && p_type_left == 0 && p_color_left == Color(1, 1, 1, 1) && !p_enable_right && p_type_right == 0 && p_color_right == Color(1, 1, 1, 1)) {
|
||||
slot_info.erase(p_idx);
|
||||
return;
|
||||
}
|
||||
|
||||
Slot s;
|
||||
s.enable_left=p_enable_left;
|
||||
s.type_left=p_type_left;
|
||||
s.color_left=p_color_left;
|
||||
s.enable_right=p_enable_right;
|
||||
s.type_right=p_type_right;
|
||||
s.color_right=p_color_right;
|
||||
slot_info[p_idx]=s;
|
||||
s.enable_left = p_enable_left;
|
||||
s.type_left = p_type_left;
|
||||
s.color_left = p_color_left;
|
||||
s.enable_right = p_enable_right;
|
||||
s.type_right = p_type_right;
|
||||
s.color_right = p_color_right;
|
||||
slot_info[p_idx] = s;
|
||||
update();
|
||||
connpos_dirty=true;
|
||||
|
||||
connpos_dirty = true;
|
||||
}
|
||||
|
||||
void GraphNode::clear_slot(int p_idx){
|
||||
void GraphNode::clear_slot(int p_idx) {
|
||||
|
||||
slot_info.erase(p_idx);
|
||||
update();
|
||||
connpos_dirty=true;
|
||||
|
||||
connpos_dirty = true;
|
||||
}
|
||||
void GraphNode::clear_all_slots(){
|
||||
void GraphNode::clear_all_slots() {
|
||||
|
||||
slot_info.clear();
|
||||
update();
|
||||
connpos_dirty=true;
|
||||
|
||||
connpos_dirty = true;
|
||||
}
|
||||
bool GraphNode::is_slot_enabled_left(int p_idx) const{
|
||||
bool GraphNode::is_slot_enabled_left(int p_idx) const {
|
||||
|
||||
if (!slot_info.has(p_idx))
|
||||
return false;
|
||||
return slot_info[p_idx].enable_left;
|
||||
|
||||
}
|
||||
|
||||
int GraphNode::get_slot_type_left(int p_idx) const{
|
||||
int GraphNode::get_slot_type_left(int p_idx) const {
|
||||
|
||||
if (!slot_info.has(p_idx))
|
||||
return 0;
|
||||
return slot_info[p_idx].type_left;
|
||||
|
||||
}
|
||||
|
||||
Color GraphNode::get_slot_color_left(int p_idx) const{
|
||||
Color GraphNode::get_slot_color_left(int p_idx) const {
|
||||
|
||||
if (!slot_info.has(p_idx))
|
||||
return Color(1,1,1,1);
|
||||
return Color(1, 1, 1, 1);
|
||||
return slot_info[p_idx].color_left;
|
||||
|
||||
}
|
||||
|
||||
bool GraphNode::is_slot_enabled_right(int p_idx) const{
|
||||
bool GraphNode::is_slot_enabled_right(int p_idx) const {
|
||||
|
||||
if (!slot_info.has(p_idx))
|
||||
return false;
|
||||
return slot_info[p_idx].enable_right;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int GraphNode::get_slot_type_right(int p_idx) const{
|
||||
int GraphNode::get_slot_type_right(int p_idx) const {
|
||||
|
||||
if (!slot_info.has(p_idx))
|
||||
return 0;
|
||||
return slot_info[p_idx].type_right;
|
||||
|
||||
}
|
||||
|
||||
Color GraphNode::get_slot_color_right(int p_idx) const{
|
||||
Color GraphNode::get_slot_color_right(int p_idx) const {
|
||||
|
||||
if (!slot_info.has(p_idx))
|
||||
return Color(1,1,1,1);
|
||||
return Color(1, 1, 1, 1);
|
||||
return slot_info[p_idx].color_right;
|
||||
|
||||
}
|
||||
|
||||
Size2 GraphNode::get_minimum_size() const {
|
||||
|
||||
Ref<Font> title_font = get_font("title_font");
|
||||
|
||||
int sep=get_constant("separation");
|
||||
Ref<StyleBox> sb=get_stylebox("frame");
|
||||
bool first=true;
|
||||
int sep = get_constant("separation");
|
||||
Ref<StyleBox> sb = get_stylebox("frame");
|
||||
bool first = true;
|
||||
|
||||
Size2 minsize;
|
||||
minsize.x=title_font->get_string_size(title).x;
|
||||
minsize.x = title_font->get_string_size(title).x;
|
||||
if (show_close) {
|
||||
Ref<Texture> close =get_icon("close");
|
||||
minsize.x+=sep+close->get_width();
|
||||
Ref<Texture> close = get_icon("close");
|
||||
minsize.x += sep + close->get_width();
|
||||
}
|
||||
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
|
||||
Control *c=get_child(i)->cast_to<Control>();
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c)
|
||||
continue;
|
||||
if (c->is_set_as_toplevel())
|
||||
continue;
|
||||
|
||||
Size2i size=c->get_combined_minimum_size();
|
||||
Size2i size = c->get_combined_minimum_size();
|
||||
|
||||
minsize.y+=size.y;
|
||||
minsize.x=MAX(minsize.x,size.x);
|
||||
minsize.y += size.y;
|
||||
minsize.x = MAX(minsize.x, size.x);
|
||||
|
||||
if (first)
|
||||
first=false;
|
||||
first = false;
|
||||
else
|
||||
minsize.y+=sep;
|
||||
minsize.y += sep;
|
||||
}
|
||||
|
||||
return minsize+sb->get_minimum_size();
|
||||
return minsize + sb->get_minimum_size();
|
||||
}
|
||||
|
||||
void GraphNode::set_title(const String& p_title) {
|
||||
void GraphNode::set_title(const String &p_title) {
|
||||
|
||||
title=p_title;
|
||||
title = p_title;
|
||||
minimum_size_changed();
|
||||
update();
|
||||
|
||||
}
|
||||
|
||||
String GraphNode::get_title() const{
|
||||
String GraphNode::get_title() const {
|
||||
|
||||
return title;
|
||||
}
|
||||
|
||||
void GraphNode::set_offset(const Vector2& p_offset) {
|
||||
void GraphNode::set_offset(const Vector2 &p_offset) {
|
||||
|
||||
offset=p_offset;
|
||||
offset = p_offset;
|
||||
emit_signal("offset_changed");
|
||||
update();
|
||||
}
|
||||
|
|
@ -388,103 +354,93 @@ Vector2 GraphNode::get_offset() const {
|
|||
return offset;
|
||||
}
|
||||
|
||||
void GraphNode::set_selected(bool p_selected)
|
||||
{
|
||||
void GraphNode::set_selected(bool p_selected) {
|
||||
selected = p_selected;
|
||||
update();
|
||||
}
|
||||
|
||||
bool GraphNode::is_selected()
|
||||
{
|
||||
bool GraphNode::is_selected() {
|
||||
return selected;
|
||||
}
|
||||
|
||||
void GraphNode::set_drag(bool p_drag)
|
||||
{
|
||||
void GraphNode::set_drag(bool p_drag) {
|
||||
if (p_drag)
|
||||
drag_from=get_offset();
|
||||
drag_from = get_offset();
|
||||
else
|
||||
emit_signal("dragged",drag_from,get_offset()); //useful for undo/redo
|
||||
emit_signal("dragged", drag_from, get_offset()); //useful for undo/redo
|
||||
}
|
||||
|
||||
Vector2 GraphNode::get_drag_from()
|
||||
{
|
||||
Vector2 GraphNode::get_drag_from() {
|
||||
return drag_from;
|
||||
}
|
||||
|
||||
void GraphNode::set_show_close_button(bool p_enable) {
|
||||
|
||||
void GraphNode::set_show_close_button(bool p_enable){
|
||||
|
||||
show_close=p_enable;
|
||||
show_close = p_enable;
|
||||
update();
|
||||
}
|
||||
bool GraphNode::is_close_button_visible() const{
|
||||
bool GraphNode::is_close_button_visible() const {
|
||||
|
||||
return show_close;
|
||||
}
|
||||
|
||||
void GraphNode::_connpos_update() {
|
||||
|
||||
int edgeofs = get_constant("port_offset");
|
||||
int sep = get_constant("separation");
|
||||
|
||||
int edgeofs=get_constant("port_offset");
|
||||
int sep=get_constant("separation");
|
||||
|
||||
Ref<StyleBox> sb=get_stylebox("frame");
|
||||
Ref<StyleBox> sb = get_stylebox("frame");
|
||||
conn_input_cache.clear();
|
||||
conn_output_cache.clear();
|
||||
int vofs=0;
|
||||
int vofs = 0;
|
||||
|
||||
int idx=0;
|
||||
int idx = 0;
|
||||
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
Control *c=get_child(i)->cast_to<Control>();
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c)
|
||||
continue;
|
||||
if (c->is_set_as_toplevel())
|
||||
continue;
|
||||
|
||||
Size2i size=c->get_combined_minimum_size();
|
||||
Size2i size = c->get_combined_minimum_size();
|
||||
|
||||
int y = sb->get_margin(MARGIN_TOP)+vofs;
|
||||
int y = sb->get_margin(MARGIN_TOP) + vofs;
|
||||
int h = size.y;
|
||||
|
||||
|
||||
if (slot_info.has(idx)) {
|
||||
|
||||
if (slot_info[idx].enable_left) {
|
||||
ConnCache cc;
|
||||
cc.pos=Point2i(edgeofs,y+h/2);
|
||||
cc.type=slot_info[idx].type_left;
|
||||
cc.color=slot_info[idx].color_left;
|
||||
cc.pos = Point2i(edgeofs, y + h / 2);
|
||||
cc.type = slot_info[idx].type_left;
|
||||
cc.color = slot_info[idx].color_left;
|
||||
conn_input_cache.push_back(cc);
|
||||
}
|
||||
if (slot_info[idx].enable_right) {
|
||||
ConnCache cc;
|
||||
cc.pos=Point2i(get_size().width-edgeofs,y+h/2);
|
||||
cc.type=slot_info[idx].type_right;
|
||||
cc.color=slot_info[idx].color_right;
|
||||
cc.pos = Point2i(get_size().width - edgeofs, y + h / 2);
|
||||
cc.type = slot_info[idx].type_right;
|
||||
cc.color = slot_info[idx].color_right;
|
||||
conn_output_cache.push_back(cc);
|
||||
}
|
||||
}
|
||||
|
||||
if (vofs>0)
|
||||
vofs+=sep;
|
||||
vofs+=size.y;
|
||||
if (vofs > 0)
|
||||
vofs += sep;
|
||||
vofs += size.y;
|
||||
idx++;
|
||||
|
||||
}
|
||||
|
||||
|
||||
connpos_dirty=false;
|
||||
connpos_dirty = false;
|
||||
}
|
||||
|
||||
int GraphNode::get_connection_input_count() {
|
||||
int GraphNode::get_connection_input_count() {
|
||||
|
||||
if (connpos_dirty)
|
||||
_connpos_update();
|
||||
|
||||
return conn_input_cache.size();
|
||||
|
||||
}
|
||||
int GraphNode::get_connection_output_count() {
|
||||
|
||||
|
|
@ -492,16 +448,14 @@ int GraphNode::get_connection_output_count() {
|
|||
_connpos_update();
|
||||
|
||||
return conn_output_cache.size();
|
||||
|
||||
}
|
||||
|
||||
|
||||
Vector2 GraphNode::get_connection_input_pos(int p_idx) {
|
||||
|
||||
if (connpos_dirty)
|
||||
_connpos_update();
|
||||
|
||||
ERR_FAIL_INDEX_V(p_idx,conn_input_cache.size(),Vector2());
|
||||
ERR_FAIL_INDEX_V(p_idx, conn_input_cache.size(), Vector2());
|
||||
Vector2 pos = conn_input_cache[p_idx].pos;
|
||||
pos.x *= get_scale().x;
|
||||
pos.y *= get_scale().y;
|
||||
|
|
@ -513,7 +467,7 @@ int GraphNode::get_connection_input_type(int p_idx) {
|
|||
if (connpos_dirty)
|
||||
_connpos_update();
|
||||
|
||||
ERR_FAIL_INDEX_V(p_idx,conn_input_cache.size(),0);
|
||||
ERR_FAIL_INDEX_V(p_idx, conn_input_cache.size(), 0);
|
||||
return conn_input_cache[p_idx].type;
|
||||
}
|
||||
|
||||
|
|
@ -522,16 +476,16 @@ Color GraphNode::get_connection_input_color(int p_idx) {
|
|||
if (connpos_dirty)
|
||||
_connpos_update();
|
||||
|
||||
ERR_FAIL_INDEX_V(p_idx,conn_input_cache.size(),Color());
|
||||
ERR_FAIL_INDEX_V(p_idx, conn_input_cache.size(), Color());
|
||||
return conn_input_cache[p_idx].color;
|
||||
}
|
||||
|
||||
Vector2 GraphNode::get_connection_output_pos(int p_idx){
|
||||
Vector2 GraphNode::get_connection_output_pos(int p_idx) {
|
||||
|
||||
if (connpos_dirty)
|
||||
_connpos_update();
|
||||
|
||||
ERR_FAIL_INDEX_V(p_idx,conn_output_cache.size(),Vector2());
|
||||
ERR_FAIL_INDEX_V(p_idx, conn_output_cache.size(), Vector2());
|
||||
Vector2 pos = conn_output_cache[p_idx].pos;
|
||||
pos.x *= get_scale().x;
|
||||
pos.y *= get_scale().y;
|
||||
|
|
@ -543,7 +497,7 @@ int GraphNode::get_connection_output_type(int p_idx) {
|
|||
if (connpos_dirty)
|
||||
_connpos_update();
|
||||
|
||||
ERR_FAIL_INDEX_V(p_idx,conn_output_cache.size(),0);
|
||||
ERR_FAIL_INDEX_V(p_idx, conn_output_cache.size(), 0);
|
||||
return conn_output_cache[p_idx].type;
|
||||
}
|
||||
|
||||
|
|
@ -552,77 +506,74 @@ Color GraphNode::get_connection_output_color(int p_idx) {
|
|||
if (connpos_dirty)
|
||||
_connpos_update();
|
||||
|
||||
ERR_FAIL_INDEX_V(p_idx,conn_output_cache.size(),Color());
|
||||
ERR_FAIL_INDEX_V(p_idx, conn_output_cache.size(), Color());
|
||||
return conn_output_cache[p_idx].color;
|
||||
}
|
||||
|
||||
void GraphNode::_input_event(const InputEvent& p_ev) {
|
||||
void GraphNode::_input_event(const InputEvent &p_ev) {
|
||||
|
||||
if (p_ev.type==InputEvent::MOUSE_BUTTON) {
|
||||
if (p_ev.type == InputEvent::MOUSE_BUTTON) {
|
||||
|
||||
ERR_EXPLAIN("GraphNode must be the child of a GraphEdit node.");
|
||||
ERR_FAIL_COND(get_parent_control() == NULL);
|
||||
|
||||
get_parent_control()->grab_focus();
|
||||
|
||||
if(p_ev.mouse_button.pressed && p_ev.mouse_button.button_index==BUTTON_LEFT) {
|
||||
if (p_ev.mouse_button.pressed && p_ev.mouse_button.button_index == BUTTON_LEFT) {
|
||||
|
||||
Vector2 mpos = Vector2(p_ev.mouse_button.x,p_ev.mouse_button.y);
|
||||
if (close_rect.size!=Size2() && close_rect.has_point(mpos)) {
|
||||
Vector2 mpos = Vector2(p_ev.mouse_button.x, p_ev.mouse_button.y);
|
||||
if (close_rect.size != Size2() && close_rect.has_point(mpos)) {
|
||||
emit_signal("close_request");
|
||||
return;
|
||||
}
|
||||
emit_signal("raise_request");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void GraphNode::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_title","title"),&GraphNode::set_title);
|
||||
ObjectTypeDB::bind_method(_MD("get_title"),&GraphNode::get_title);
|
||||
ObjectTypeDB::bind_method(_MD("_input_event"),&GraphNode::_input_event);
|
||||
ObjectTypeDB::bind_method(_MD("set_title", "title"), &GraphNode::set_title);
|
||||
ObjectTypeDB::bind_method(_MD("get_title"), &GraphNode::get_title);
|
||||
ObjectTypeDB::bind_method(_MD("_input_event"), &GraphNode::_input_event);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_slot","idx","enable_left","type_left","color_left","enable_right","type_right","color_right"),&GraphNode::set_slot);
|
||||
ObjectTypeDB::bind_method(_MD("clear_slot","idx"),&GraphNode::clear_slot);
|
||||
ObjectTypeDB::bind_method(_MD("clear_all_slots","idx"),&GraphNode::clear_all_slots);
|
||||
ObjectTypeDB::bind_method(_MD("is_slot_enabled_left","idx"),&GraphNode::is_slot_enabled_left);
|
||||
ObjectTypeDB::bind_method(_MD("get_slot_type_left","idx"),&GraphNode::get_slot_type_left);
|
||||
ObjectTypeDB::bind_method(_MD("get_slot_color_left","idx"),&GraphNode::get_slot_color_left);
|
||||
ObjectTypeDB::bind_method(_MD("is_slot_enabled_right","idx"),&GraphNode::is_slot_enabled_right);
|
||||
ObjectTypeDB::bind_method(_MD("get_slot_type_right","idx"),&GraphNode::get_slot_type_right);
|
||||
ObjectTypeDB::bind_method(_MD("get_slot_color_right","idx"),&GraphNode::get_slot_color_right);
|
||||
ObjectTypeDB::bind_method(_MD("set_slot", "idx", "enable_left", "type_left", "color_left", "enable_right", "type_right", "color_right"), &GraphNode::set_slot);
|
||||
ObjectTypeDB::bind_method(_MD("clear_slot", "idx"), &GraphNode::clear_slot);
|
||||
ObjectTypeDB::bind_method(_MD("clear_all_slots", "idx"), &GraphNode::clear_all_slots);
|
||||
ObjectTypeDB::bind_method(_MD("is_slot_enabled_left", "idx"), &GraphNode::is_slot_enabled_left);
|
||||
ObjectTypeDB::bind_method(_MD("get_slot_type_left", "idx"), &GraphNode::get_slot_type_left);
|
||||
ObjectTypeDB::bind_method(_MD("get_slot_color_left", "idx"), &GraphNode::get_slot_color_left);
|
||||
ObjectTypeDB::bind_method(_MD("is_slot_enabled_right", "idx"), &GraphNode::is_slot_enabled_right);
|
||||
ObjectTypeDB::bind_method(_MD("get_slot_type_right", "idx"), &GraphNode::get_slot_type_right);
|
||||
ObjectTypeDB::bind_method(_MD("get_slot_color_right", "idx"), &GraphNode::get_slot_color_right);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_offset","offset"),&GraphNode::set_offset);
|
||||
ObjectTypeDB::bind_method(_MD("get_offset"),&GraphNode::get_offset);
|
||||
ObjectTypeDB::bind_method(_MD("set_offset", "offset"), &GraphNode::set_offset);
|
||||
ObjectTypeDB::bind_method(_MD("get_offset"), &GraphNode::get_offset);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("get_connection_output_count"),&GraphNode::get_connection_output_count);
|
||||
ObjectTypeDB::bind_method(_MD("get_connection_input_count"),&GraphNode::get_connection_input_count);
|
||||
ObjectTypeDB::bind_method(_MD("get_connection_output_count"), &GraphNode::get_connection_output_count);
|
||||
ObjectTypeDB::bind_method(_MD("get_connection_input_count"), &GraphNode::get_connection_input_count);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("get_connection_output_pos","idx"),&GraphNode::get_connection_output_pos);
|
||||
ObjectTypeDB::bind_method(_MD("get_connection_output_type","idx"),&GraphNode::get_connection_output_type);
|
||||
ObjectTypeDB::bind_method(_MD("get_connection_output_color","idx"),&GraphNode::get_connection_output_color);
|
||||
ObjectTypeDB::bind_method(_MD("get_connection_input_pos","idx"),&GraphNode::get_connection_input_pos);
|
||||
ObjectTypeDB::bind_method(_MD("get_connection_input_type","idx"),&GraphNode::get_connection_input_type);
|
||||
ObjectTypeDB::bind_method(_MD("get_connection_input_color","idx"),&GraphNode::get_connection_input_color);
|
||||
ObjectTypeDB::bind_method(_MD("get_connection_output_pos", "idx"), &GraphNode::get_connection_output_pos);
|
||||
ObjectTypeDB::bind_method(_MD("get_connection_output_type", "idx"), &GraphNode::get_connection_output_type);
|
||||
ObjectTypeDB::bind_method(_MD("get_connection_output_color", "idx"), &GraphNode::get_connection_output_color);
|
||||
ObjectTypeDB::bind_method(_MD("get_connection_input_pos", "idx"), &GraphNode::get_connection_input_pos);
|
||||
ObjectTypeDB::bind_method(_MD("get_connection_input_type", "idx"), &GraphNode::get_connection_input_type);
|
||||
ObjectTypeDB::bind_method(_MD("get_connection_input_color", "idx"), &GraphNode::get_connection_input_color);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_show_close_button", "show"), &GraphNode::set_show_close_button);
|
||||
ObjectTypeDB::bind_method(_MD("is_close_button_visible"), &GraphNode::is_close_button_visible);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_show_close_button","show"),&GraphNode::set_show_close_button);
|
||||
ObjectTypeDB::bind_method(_MD("is_close_button_visible"),&GraphNode::is_close_button_visible);
|
||||
|
||||
ADD_PROPERTY( PropertyInfo(Variant::STRING,"title"),_SCS("set_title"),_SCS("get_title"));
|
||||
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"show_close"),_SCS("set_show_close_button"),_SCS("is_close_button_visible"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "title"), _SCS("set_title"), _SCS("get_title"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_close"), _SCS("set_show_close_button"), _SCS("is_close_button_visible"));
|
||||
|
||||
ADD_SIGNAL(MethodInfo("offset_changed"));
|
||||
ADD_SIGNAL(MethodInfo("dragged",PropertyInfo(Variant::VECTOR2,"from"),PropertyInfo(Variant::VECTOR2,"to")));
|
||||
ADD_SIGNAL(MethodInfo("dragged", PropertyInfo(Variant::VECTOR2, "from"), PropertyInfo(Variant::VECTOR2, "to")));
|
||||
ADD_SIGNAL(MethodInfo("raise_request"));
|
||||
ADD_SIGNAL(MethodInfo("close_request"));
|
||||
}
|
||||
|
||||
GraphNode::GraphNode() {
|
||||
show_close=false;
|
||||
connpos_dirty=true;
|
||||
show_close = false;
|
||||
connpos_dirty = true;
|
||||
set_stop_mouse(false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,9 +33,7 @@
|
|||
|
||||
class GraphNode : public Container {
|
||||
|
||||
OBJ_TYPE(GraphNode,Container);
|
||||
|
||||
|
||||
OBJ_TYPE(GraphNode, Container);
|
||||
|
||||
struct Slot {
|
||||
bool enable_left;
|
||||
|
|
@ -45,8 +43,14 @@ class GraphNode : public Container {
|
|||
int type_right;
|
||||
Color color_right;
|
||||
|
||||
|
||||
Slot() { enable_left=false; type_left=0; color_left=Color(1,1,1,1); enable_right=false; type_right=0; color_right=Color(1,1,1,1); }
|
||||
Slot() {
|
||||
enable_left = false;
|
||||
type_left = 0;
|
||||
color_left = Color(1, 1, 1, 1);
|
||||
enable_right = false;
|
||||
type_right = 0;
|
||||
color_right = Color(1, 1, 1, 1);
|
||||
}
|
||||
};
|
||||
|
||||
String title;
|
||||
|
|
@ -66,7 +70,7 @@ class GraphNode : public Container {
|
|||
Vector<ConnCache> conn_input_cache;
|
||||
Vector<ConnCache> conn_output_cache;
|
||||
|
||||
Map<int,Slot> slot_info;
|
||||
Map<int, Slot> slot_info;
|
||||
|
||||
bool connpos_dirty;
|
||||
|
||||
|
|
@ -75,23 +79,18 @@ class GraphNode : public Container {
|
|||
|
||||
Vector2 drag_from;
|
||||
bool selected;
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
void _input_event(const InputEvent& p_ev);
|
||||
void _input_event(const InputEvent &p_ev);
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
bool _set(const StringName& p_name, const Variant& p_value);
|
||||
bool _get(const StringName& p_name,Variant &r_ret) const;
|
||||
void _get_property_list( List<PropertyInfo> *p_list) const;
|
||||
bool _set(const StringName &p_name, const Variant &p_value);
|
||||
bool _get(const StringName &p_name, Variant &r_ret) const;
|
||||
void _get_property_list(List<PropertyInfo> *p_list) const;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
void set_slot(int p_idx,bool p_enable_left,int p_type_left,const Color& p_color_left, bool p_enable_right,int p_type_right,const Color& p_color_right);
|
||||
void set_slot(int p_idx, bool p_enable_left, int p_type_left, const Color &p_color_left, bool p_enable_right, int p_type_right, const Color &p_color_right);
|
||||
void clear_slot(int p_idx);
|
||||
void clear_all_slots();
|
||||
bool is_slot_enabled_left(int p_idx) const;
|
||||
|
|
@ -101,10 +100,10 @@ public:
|
|||
int get_slot_type_right(int p_idx) const;
|
||||
Color get_slot_color_right(int p_idx) const;
|
||||
|
||||
void set_title(const String& p_title);
|
||||
void set_title(const String &p_title);
|
||||
String get_title() const;
|
||||
|
||||
void set_offset(const Vector2& p_offset);
|
||||
void set_offset(const Vector2 &p_offset);
|
||||
Vector2 get_offset() const;
|
||||
|
||||
void set_selected(bool p_selected);
|
||||
|
|
@ -116,8 +115,8 @@ public:
|
|||
void set_show_close_button(bool p_enable);
|
||||
bool is_close_button_visible() const;
|
||||
|
||||
int get_connection_input_count() ;
|
||||
int get_connection_output_count() ;
|
||||
int get_connection_input_count();
|
||||
int get_connection_output_count();
|
||||
Vector2 get_connection_input_pos(int p_idx);
|
||||
int get_connection_input_type(int p_idx);
|
||||
Color get_connection_input_color(int p_idx);
|
||||
|
|
@ -125,11 +124,9 @@ public:
|
|||
int get_connection_output_type(int p_idx);
|
||||
Color get_connection_output_color(int p_idx);
|
||||
|
||||
|
||||
virtual Size2 get_minimum_size() const;
|
||||
|
||||
GraphNode();
|
||||
};
|
||||
|
||||
|
||||
#endif // GRAPH_NODE_H
|
||||
|
|
|
|||
|
|
@ -28,29 +28,27 @@
|
|||
/*************************************************************************/
|
||||
#include "grid_container.h"
|
||||
|
||||
|
||||
void GridContainer::_notification(int p_what) {
|
||||
|
||||
switch(p_what) {
|
||||
switch (p_what) {
|
||||
|
||||
case NOTIFICATION_SORT_CHILDREN: {
|
||||
|
||||
Map<int,int> col_minw;
|
||||
Map<int,int> row_minh;
|
||||
Map<int, int> col_minw;
|
||||
Map<int, int> row_minh;
|
||||
Set<int> col_expanded;
|
||||
Set<int> row_expanded;
|
||||
|
||||
int hsep=get_constant("hseparation");
|
||||
int vsep=get_constant("vseparation");
|
||||
int hsep = get_constant("hseparation");
|
||||
int vsep = get_constant("vseparation");
|
||||
|
||||
int idx=0;
|
||||
int max_row=0;
|
||||
int max_col=0;
|
||||
int idx = 0;
|
||||
int max_row = 0;
|
||||
int max_col = 0;
|
||||
|
||||
Size2 size = get_size();
|
||||
|
||||
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c || !c->is_visible())
|
||||
|
|
@ -61,55 +59,54 @@ void GridContainer::_notification(int p_what) {
|
|||
|
||||
Size2i ms = c->get_combined_minimum_size();
|
||||
if (col_minw.has(col))
|
||||
col_minw[col] = MAX(col_minw[col],ms.width);
|
||||
col_minw[col] = MAX(col_minw[col], ms.width);
|
||||
else
|
||||
col_minw[col]=ms.width;
|
||||
col_minw[col] = ms.width;
|
||||
|
||||
if (row_minh.has(row))
|
||||
row_minh[row] = MAX(row_minh[row],ms.height);
|
||||
row_minh[row] = MAX(row_minh[row], ms.height);
|
||||
else
|
||||
row_minh[row]=ms.height;
|
||||
row_minh[row] = ms.height;
|
||||
|
||||
// print_line("store row "+itos(row)+" mw "+itos(ms.height));
|
||||
// print_line("store row "+itos(row)+" mw "+itos(ms.height));
|
||||
|
||||
if (c->get_h_size_flags()&SIZE_EXPAND)
|
||||
if (c->get_h_size_flags() & SIZE_EXPAND)
|
||||
col_expanded.insert(col);
|
||||
if (c->get_v_size_flags()&SIZE_EXPAND)
|
||||
if (c->get_v_size_flags() & SIZE_EXPAND)
|
||||
row_expanded.insert(row);
|
||||
|
||||
max_col=MAX(col,max_col);
|
||||
max_row=MAX(row,max_row);
|
||||
max_col = MAX(col, max_col);
|
||||
max_row = MAX(row, max_row);
|
||||
idx++;
|
||||
}
|
||||
|
||||
Size2 ms;
|
||||
int expand_rows=0;
|
||||
int expand_cols=0;
|
||||
int expand_rows = 0;
|
||||
int expand_cols = 0;
|
||||
|
||||
for (Map<int,int>::Element *E=col_minw.front();E;E=E->next()) {
|
||||
ms.width+=E->get();
|
||||
for (Map<int, int>::Element *E = col_minw.front(); E; E = E->next()) {
|
||||
ms.width += E->get();
|
||||
if (col_expanded.has(E->key()))
|
||||
expand_cols++;
|
||||
}
|
||||
|
||||
for (Map<int,int>::Element *E=row_minh.front();E;E=E->next()) {
|
||||
ms.height+=E->get();
|
||||
for (Map<int, int>::Element *E = row_minh.front(); E; E = E->next()) {
|
||||
ms.height += E->get();
|
||||
if (row_expanded.has(E->key()))
|
||||
expand_rows++;
|
||||
}
|
||||
|
||||
ms.height+=vsep*max_row;
|
||||
ms.width+=hsep*max_col;
|
||||
ms.height += vsep * max_row;
|
||||
ms.width += hsep * max_col;
|
||||
|
||||
int row_expand = expand_rows?(size.y-ms.y)/expand_rows:0;
|
||||
int col_expand = expand_cols?(size.x-ms.x)/expand_cols:0;
|
||||
int row_expand = expand_rows ? (size.y - ms.y) / expand_rows : 0;
|
||||
int col_expand = expand_cols ? (size.x - ms.x) / expand_cols : 0;
|
||||
|
||||
int col_ofs = 0;
|
||||
int row_ofs = 0;
|
||||
idx = 0;
|
||||
|
||||
int col_ofs=0;
|
||||
int row_ofs=0;
|
||||
idx=0;
|
||||
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c || !c->is_visible())
|
||||
|
|
@ -117,78 +114,74 @@ void GridContainer::_notification(int p_what) {
|
|||
int row = idx / columns;
|
||||
int col = idx % columns;
|
||||
|
||||
if (col==0) {
|
||||
col_ofs=0;
|
||||
if (row>0 && row_minh.has(row-1))
|
||||
row_ofs+=row_minh[row-1]+vsep+(row_expanded.has(row-1)?row_expand:0);
|
||||
if (col == 0) {
|
||||
col_ofs = 0;
|
||||
if (row > 0 && row_minh.has(row - 1))
|
||||
row_ofs += row_minh[row - 1] + vsep + (row_expanded.has(row - 1) ? row_expand : 0);
|
||||
}
|
||||
|
||||
Size2 s;
|
||||
if (col_minw.has(col))
|
||||
s.width=col_minw[col];
|
||||
s.width = col_minw[col];
|
||||
if (row_minh.has(row))
|
||||
s.height=row_minh[row];
|
||||
s.height = row_minh[row];
|
||||
|
||||
if (row_expanded.has(row))
|
||||
s.height+=row_expand;
|
||||
s.height += row_expand;
|
||||
if (col_expanded.has(col))
|
||||
s.width+=col_expand;
|
||||
s.width += col_expand;
|
||||
|
||||
Point2 p(col_ofs,row_ofs);
|
||||
Point2 p(col_ofs, row_ofs);
|
||||
|
||||
// print_line("col: "+itos(col)+" row: "+itos(row)+" col_ofs: "+itos(col_ofs)+" row_ofs: "+itos(row_ofs));
|
||||
fit_child_in_rect(c,Rect2(p,s));
|
||||
// print_line("col: "+itos(col)+" row: "+itos(row)+" col_ofs: "+itos(col_ofs)+" row_ofs: "+itos(row_ofs));
|
||||
fit_child_in_rect(c, Rect2(p, s));
|
||||
//print_line("col: "+itos(col)+" row: "+itos(row)+" rect: "+Rect2(p,s));
|
||||
|
||||
if (col_minw.has(col)) {
|
||||
col_ofs+=col_minw[col]+hsep+(col_expanded.has(col)?col_expand:0);
|
||||
col_ofs += col_minw[col] + hsep + (col_expanded.has(col) ? col_expand : 0);
|
||||
}
|
||||
|
||||
idx++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void GridContainer::set_columns(int p_columns) {
|
||||
|
||||
ERR_FAIL_COND(p_columns<1);
|
||||
columns=p_columns;
|
||||
ERR_FAIL_COND(p_columns < 1);
|
||||
columns = p_columns;
|
||||
queue_sort();
|
||||
minimum_size_changed();
|
||||
|
||||
}
|
||||
|
||||
int GridContainer::get_columns() const{
|
||||
int GridContainer::get_columns() const {
|
||||
|
||||
return columns;
|
||||
}
|
||||
|
||||
void GridContainer::_bind_methods(){
|
||||
void GridContainer::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_columns","columns"),&GridContainer::set_columns);
|
||||
ObjectTypeDB::bind_method(_MD("get_columns"),&GridContainer::get_columns);
|
||||
ObjectTypeDB::bind_method(_MD("set_columns", "columns"), &GridContainer::set_columns);
|
||||
ObjectTypeDB::bind_method(_MD("get_columns"), &GridContainer::get_columns);
|
||||
|
||||
ADD_PROPERTY( PropertyInfo(Variant::INT,"columns",PROPERTY_HINT_RANGE,"1,1024,1"),_SCS("set_columns"),_SCS("get_columns"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "columns", PROPERTY_HINT_RANGE, "1,1024,1"), _SCS("set_columns"), _SCS("get_columns"));
|
||||
}
|
||||
|
||||
Size2 GridContainer::get_minimum_size() const {
|
||||
|
||||
Map<int,int> col_minw;
|
||||
Map<int,int> row_minh;
|
||||
Map<int, int> col_minw;
|
||||
Map<int, int> row_minh;
|
||||
|
||||
int hsep=get_constant("hseparation");
|
||||
int vsep=get_constant("vseparation");
|
||||
int hsep = get_constant("hseparation");
|
||||
int vsep = get_constant("vseparation");
|
||||
|
||||
int idx=0;
|
||||
int max_row=0;
|
||||
int max_col=0;
|
||||
int idx = 0;
|
||||
int max_row = 0;
|
||||
int max_col = 0;
|
||||
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c || !c->is_visible())
|
||||
|
|
@ -197,39 +190,37 @@ Size2 GridContainer::get_minimum_size() const {
|
|||
int col = idx % columns;
|
||||
Size2i ms = c->get_combined_minimum_size();
|
||||
if (col_minw.has(col))
|
||||
col_minw[col] = MAX(col_minw[col],ms.width);
|
||||
col_minw[col] = MAX(col_minw[col], ms.width);
|
||||
else
|
||||
col_minw[col]=ms.width;
|
||||
col_minw[col] = ms.width;
|
||||
|
||||
if (row_minh.has(row))
|
||||
row_minh[row] = MAX(row_minh[row],ms.height);
|
||||
row_minh[row] = MAX(row_minh[row], ms.height);
|
||||
else
|
||||
row_minh[row]=ms.height;
|
||||
max_col=MAX(col,max_col);
|
||||
max_row=MAX(row,max_row);
|
||||
row_minh[row] = ms.height;
|
||||
max_col = MAX(col, max_col);
|
||||
max_row = MAX(row, max_row);
|
||||
idx++;
|
||||
}
|
||||
|
||||
Size2 ms;
|
||||
|
||||
for (Map<int,int>::Element *E=col_minw.front();E;E=E->next()) {
|
||||
ms.width+=E->get();
|
||||
for (Map<int, int>::Element *E = col_minw.front(); E; E = E->next()) {
|
||||
ms.width += E->get();
|
||||
}
|
||||
|
||||
for (Map<int,int>::Element *E=row_minh.front();E;E=E->next()) {
|
||||
ms.height+=E->get();
|
||||
for (Map<int, int>::Element *E = row_minh.front(); E; E = E->next()) {
|
||||
ms.height += E->get();
|
||||
}
|
||||
|
||||
ms.height+=vsep*max_row;
|
||||
ms.width+=hsep*max_col;
|
||||
ms.height += vsep * max_row;
|
||||
ms.width += hsep * max_col;
|
||||
|
||||
return ms;
|
||||
|
||||
}
|
||||
|
||||
|
||||
GridContainer::GridContainer() {
|
||||
|
||||
set_stop_mouse(false);
|
||||
columns=1;
|
||||
columns = 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,15 +33,15 @@
|
|||
|
||||
class GridContainer : public Container {
|
||||
|
||||
OBJ_TYPE(GridContainer,Container);
|
||||
OBJ_TYPE(GridContainer, Container);
|
||||
|
||||
int columns;
|
||||
protected:
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
public:
|
||||
|
||||
public:
|
||||
void set_columns(int p_columns);
|
||||
int get_columns() const;
|
||||
virtual Size2 get_minimum_size() const;
|
||||
|
|
|
|||
|
|
@ -1,42 +1,41 @@
|
|||
#include "input_action.h"
|
||||
#include "os/keyboard.h"
|
||||
|
||||
void ShortCut::set_shortcut(const InputEvent& p_shortcut){
|
||||
void ShortCut::set_shortcut(const InputEvent &p_shortcut) {
|
||||
|
||||
shortcut=p_shortcut;
|
||||
shortcut = p_shortcut;
|
||||
emit_changed();
|
||||
}
|
||||
|
||||
InputEvent ShortCut::get_shortcut() const{
|
||||
InputEvent ShortCut::get_shortcut() const {
|
||||
|
||||
return shortcut;
|
||||
}
|
||||
|
||||
bool ShortCut::is_shortcut(const InputEvent& p_event) const {
|
||||
bool ShortCut::is_shortcut(const InputEvent &p_event) const {
|
||||
|
||||
bool same=false;
|
||||
bool same = false;
|
||||
|
||||
|
||||
switch(p_event.type) {
|
||||
switch (p_event.type) {
|
||||
|
||||
case InputEvent::KEY: {
|
||||
|
||||
same=(shortcut.key.scancode==p_event.key.scancode && shortcut.key.mod == p_event.key.mod);
|
||||
same = (shortcut.key.scancode == p_event.key.scancode && shortcut.key.mod == p_event.key.mod);
|
||||
|
||||
} break;
|
||||
case InputEvent::JOYSTICK_BUTTON: {
|
||||
|
||||
same=(shortcut.joy_button.button_index==p_event.joy_button.button_index);
|
||||
same = (shortcut.joy_button.button_index == p_event.joy_button.button_index);
|
||||
|
||||
} break;
|
||||
case InputEvent::MOUSE_BUTTON: {
|
||||
|
||||
same=(shortcut.mouse_button.button_index==p_event.mouse_button.button_index);
|
||||
same = (shortcut.mouse_button.button_index == p_event.mouse_button.button_index);
|
||||
|
||||
} break;
|
||||
case InputEvent::JOYSTICK_MOTION: {
|
||||
|
||||
same=(shortcut.joy_motion.axis==p_event.joy_motion.axis && (shortcut.joy_motion.axis_value < 0) == (p_event.joy_motion.axis_value < 0));
|
||||
same = (shortcut.joy_motion.axis == p_event.joy_motion.axis && (shortcut.joy_motion.axis_value < 0) == (p_event.joy_motion.axis_value < 0));
|
||||
|
||||
} break;
|
||||
default: {};
|
||||
|
|
@ -47,7 +46,7 @@ bool ShortCut::is_shortcut(const InputEvent& p_event) const {
|
|||
|
||||
String ShortCut::get_as_text() const {
|
||||
|
||||
switch(shortcut.type) {
|
||||
switch (shortcut.type) {
|
||||
|
||||
case InputEvent::NONE: {
|
||||
|
||||
|
|
@ -57,35 +56,35 @@ String ShortCut::get_as_text() const {
|
|||
|
||||
String str;
|
||||
if (shortcut.key.mod.shift)
|
||||
str+=RTR("Shift+");
|
||||
str += RTR("Shift+");
|
||||
if (shortcut.key.mod.alt)
|
||||
str+=RTR("Alt+");
|
||||
str += RTR("Alt+");
|
||||
if (shortcut.key.mod.control)
|
||||
str+=RTR("Ctrl+");
|
||||
str += RTR("Ctrl+");
|
||||
if (shortcut.key.mod.meta)
|
||||
str+=RTR("Meta+");
|
||||
str += RTR("Meta+");
|
||||
|
||||
str+=keycode_get_string(shortcut.key.scancode).capitalize();
|
||||
str += keycode_get_string(shortcut.key.scancode).capitalize();
|
||||
|
||||
return str;
|
||||
} break;
|
||||
case InputEvent::JOYSTICK_BUTTON: {
|
||||
|
||||
String str = RTR("Device")+" "+itos(shortcut.device)+", "+RTR("Button")+" "+itos(shortcut.joy_button.button_index);
|
||||
str+=".";
|
||||
String str = RTR("Device") + " " + itos(shortcut.device) + ", " + RTR("Button") + " " + itos(shortcut.joy_button.button_index);
|
||||
str += ".";
|
||||
|
||||
return str;
|
||||
} break;
|
||||
case InputEvent::MOUSE_BUTTON: {
|
||||
|
||||
String str = RTR("Device")+" "+itos(shortcut.device)+", ";
|
||||
String str = RTR("Device") + " " + itos(shortcut.device) + ", ";
|
||||
switch (shortcut.mouse_button.button_index) {
|
||||
case BUTTON_LEFT: str+=RTR("Left Button."); break;
|
||||
case BUTTON_RIGHT: str+=RTR("Right Button."); break;
|
||||
case BUTTON_MIDDLE: str+=RTR("Middle Button."); break;
|
||||
case BUTTON_WHEEL_UP: str+=RTR("Wheel Up."); break;
|
||||
case BUTTON_WHEEL_DOWN: str+=RTR("Wheel Down."); break;
|
||||
default: str+=RTR("Button")+" "+itos(shortcut.mouse_button.button_index)+".";
|
||||
case BUTTON_LEFT: str += RTR("Left Button."); break;
|
||||
case BUTTON_RIGHT: str += RTR("Right Button."); break;
|
||||
case BUTTON_MIDDLE: str += RTR("Middle Button."); break;
|
||||
case BUTTON_WHEEL_UP: str += RTR("Wheel Up."); break;
|
||||
case BUTTON_WHEEL_DOWN: str += RTR("Wheel Down."); break;
|
||||
default: str += RTR("Button") + " " + itos(shortcut.mouse_button.button_index) + ".";
|
||||
}
|
||||
|
||||
return str;
|
||||
|
|
@ -93,7 +92,7 @@ String ShortCut::get_as_text() const {
|
|||
case InputEvent::JOYSTICK_MOTION: {
|
||||
|
||||
int ax = shortcut.joy_motion.axis;
|
||||
String str = RTR("Device")+" "+itos(shortcut.device)+", "+RTR("Axis")+" "+itos(ax)+".";
|
||||
String str = RTR("Device") + " " + itos(shortcut.device) + ", " + RTR("Axis") + " " + itos(ax) + ".";
|
||||
|
||||
return str;
|
||||
} break;
|
||||
|
|
@ -104,22 +103,21 @@ String ShortCut::get_as_text() const {
|
|||
|
||||
bool ShortCut::is_valid() const {
|
||||
|
||||
return shortcut.type!=InputEvent::NONE;
|
||||
return shortcut.type != InputEvent::NONE;
|
||||
}
|
||||
|
||||
void ShortCut::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_shortcut","event"),&ShortCut::set_shortcut);
|
||||
ObjectTypeDB::bind_method(_MD("get_shortcut"),&ShortCut::get_shortcut);
|
||||
ObjectTypeDB::bind_method(_MD("set_shortcut", "event"), &ShortCut::set_shortcut);
|
||||
ObjectTypeDB::bind_method(_MD("get_shortcut"), &ShortCut::get_shortcut);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("is_valid"),&ShortCut::is_valid);
|
||||
ObjectTypeDB::bind_method(_MD("is_valid"), &ShortCut::is_valid);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("is_shortcut","event"),&ShortCut::is_shortcut);
|
||||
ObjectTypeDB::bind_method(_MD("get_as_text"),&ShortCut::get_as_text);
|
||||
ObjectTypeDB::bind_method(_MD("is_shortcut", "event"), &ShortCut::is_shortcut);
|
||||
ObjectTypeDB::bind_method(_MD("get_as_text"), &ShortCut::get_as_text);
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INPUT_EVENT,"shortcut"),_SCS("set_shortcut"),_SCS("get_shortcut"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INPUT_EVENT, "shortcut"), _SCS("set_shortcut"), _SCS("get_shortcut"));
|
||||
}
|
||||
|
||||
ShortCut::ShortCut(){
|
||||
|
||||
ShortCut::ShortCut() {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,17 +5,17 @@
|
|||
|
||||
class ShortCut : public Resource {
|
||||
|
||||
OBJ_TYPE(ShortCut,Resource);
|
||||
OBJ_TYPE(ShortCut, Resource);
|
||||
|
||||
InputEvent shortcut;
|
||||
|
||||
protected:
|
||||
|
||||
static void _bind_methods();
|
||||
public:
|
||||
|
||||
void set_shortcut(const InputEvent& p_shortcut);
|
||||
public:
|
||||
void set_shortcut(const InputEvent &p_shortcut);
|
||||
InputEvent get_shortcut() const;
|
||||
bool is_shortcut(const InputEvent& p_Event) const;
|
||||
bool is_shortcut(const InputEvent &p_Event) const;
|
||||
bool is_valid() const;
|
||||
|
||||
String get_as_text() const;
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -34,9 +34,9 @@
|
|||
|
||||
class ItemList : public Control {
|
||||
|
||||
OBJ_TYPE( ItemList, Control );
|
||||
public:
|
||||
OBJ_TYPE(ItemList, Control);
|
||||
|
||||
public:
|
||||
enum IconMode {
|
||||
ICON_MODE_TOP,
|
||||
ICON_MODE_LEFT
|
||||
|
|
@ -46,6 +46,7 @@ public:
|
|||
SELECT_SINGLE,
|
||||
SELECT_MULTI
|
||||
};
|
||||
|
||||
private:
|
||||
struct Item {
|
||||
|
||||
|
|
@ -66,7 +67,7 @@ private:
|
|||
|
||||
Size2 get_icon_size() const;
|
||||
|
||||
bool operator<(const Item& p_another) const { return text<p_another.text; }
|
||||
bool operator<(const Item &p_another) const { return text < p_another.text; }
|
||||
};
|
||||
|
||||
int current;
|
||||
|
|
@ -102,50 +103,47 @@ private:
|
|||
real_t icon_scale;
|
||||
|
||||
void _scroll_changed(double);
|
||||
void _input_event(const InputEvent& p_event);
|
||||
|
||||
void _input_event(const InputEvent &p_event);
|
||||
|
||||
protected:
|
||||
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
void add_item(const String &p_item, const Ref<Texture> &p_texture = Ref<Texture>(), bool p_selectable = true);
|
||||
void add_icon_item(const Ref<Texture> &p_item, bool p_selectable = true);
|
||||
|
||||
|
||||
void add_item(const String& p_item,const Ref<Texture>& p_texture=Ref<Texture>(),bool p_selectable=true);
|
||||
void add_icon_item(const Ref<Texture>& p_item,bool p_selectable=true);
|
||||
|
||||
void set_item_text(int p_idx,const String& p_text);
|
||||
void set_item_text(int p_idx, const String &p_text);
|
||||
String get_item_text(int p_idx) const;
|
||||
|
||||
void set_item_icon(int p_idx,const Ref<Texture>& p_icon);
|
||||
void set_item_icon(int p_idx, const Ref<Texture> &p_icon);
|
||||
Ref<Texture> get_item_icon(int p_idx) const;
|
||||
|
||||
void set_item_icon_region(int p_idx,const Rect2& p_region);
|
||||
void set_item_icon_region(int p_idx, const Rect2 &p_region);
|
||||
Rect2 get_item_icon_region(int p_idx) const;
|
||||
|
||||
void set_item_selectable(int p_idx,bool p_selectable);
|
||||
void set_item_selectable(int p_idx, bool p_selectable);
|
||||
bool is_item_selectable(int p_idx) const;
|
||||
|
||||
void set_item_disabled(int p_idx,bool p_disabled);
|
||||
void set_item_disabled(int p_idx, bool p_disabled);
|
||||
bool is_item_disabled(int p_idx) const;
|
||||
|
||||
void set_item_metadata(int p_idx,const Variant& p_metadata);
|
||||
void set_item_metadata(int p_idx, const Variant &p_metadata);
|
||||
Variant get_item_metadata(int p_idx) const;
|
||||
|
||||
void set_item_tag_icon(int p_idx,const Ref<Texture>& p_tag_icon);
|
||||
void set_item_tag_icon(int p_idx, const Ref<Texture> &p_tag_icon);
|
||||
Ref<Texture> get_item_tag_icon(int p_idx) const;
|
||||
|
||||
void set_item_tooltip_enabled(int p_idx, const bool p_enabled);
|
||||
bool is_item_tooltip_enabled(int p_idx) const;
|
||||
|
||||
void set_item_tooltip(int p_idx,const String& p_tooltip);
|
||||
void set_item_tooltip(int p_idx, const String &p_tooltip);
|
||||
String get_item_tooltip(int p_idx) const;
|
||||
|
||||
void set_item_custom_bg_color(int p_idx,const Color& p_custom_bg_color);
|
||||
void set_item_custom_bg_color(int p_idx, const Color &p_custom_bg_color);
|
||||
Color get_item_custom_bg_color(int p_idx) const;
|
||||
|
||||
void select(int p_idx,bool p_single=true);
|
||||
void select(int p_idx, bool p_single = true);
|
||||
void unselect(int p_idx);
|
||||
bool is_selected(int p_idx) const;
|
||||
Vector<int> get_selected_items();
|
||||
|
|
@ -153,7 +151,7 @@ public:
|
|||
void set_current(int p_current);
|
||||
int get_current() const;
|
||||
|
||||
void move_item(int p_item,int p_to_pos);
|
||||
void move_item(int p_item, int p_to_pos);
|
||||
|
||||
int get_item_count() const;
|
||||
void remove_item(int p_idx);
|
||||
|
|
@ -178,7 +176,7 @@ public:
|
|||
void set_icon_mode(IconMode p_mode);
|
||||
IconMode get_icon_mode() const;
|
||||
|
||||
void set_fixed_icon_size(const Size2& p_size);
|
||||
void set_fixed_icon_size(const Size2 &p_size);
|
||||
Size2 get_fixed_icon_size() const;
|
||||
|
||||
void set_allow_rmb_select(bool p_allow);
|
||||
|
|
@ -187,10 +185,10 @@ public:
|
|||
void ensure_current_is_visible();
|
||||
|
||||
void sort_items_by_text();
|
||||
int find_metadata(const Variant& p_metadata) const;
|
||||
int find_metadata(const Variant &p_metadata) const;
|
||||
|
||||
virtual String get_tooltip(const Point2& p_pos) const;
|
||||
int get_item_at_pos(const Point2& p_pos,bool p_exact=false) const;
|
||||
virtual String get_tooltip(const Point2 &p_pos) const;
|
||||
int get_item_at_pos(const Point2 &p_pos, bool p_exact = false) const;
|
||||
|
||||
void set_icon_scale(real_t p_scale);
|
||||
real_t get_icon_scale() const;
|
||||
|
|
@ -204,5 +202,4 @@ public:
|
|||
VARIANT_ENUM_CAST(ItemList::SelectMode);
|
||||
VARIANT_ENUM_CAST(ItemList::IconMode);
|
||||
|
||||
|
||||
#endif // ITEMLIST_H
|
||||
|
|
|
|||
|
|
@ -27,29 +27,26 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "label.h"
|
||||
#include "print_string.h"
|
||||
#include "globals.h"
|
||||
#include "print_string.h"
|
||||
#include "translation.h"
|
||||
|
||||
|
||||
void Label::set_autowrap(bool p_autowrap) {
|
||||
|
||||
autowrap=p_autowrap;
|
||||
word_cache_dirty=true;
|
||||
autowrap = p_autowrap;
|
||||
word_cache_dirty = true;
|
||||
minimum_size_changed();
|
||||
update();
|
||||
|
||||
}
|
||||
bool Label::has_autowrap() const {
|
||||
|
||||
return autowrap;
|
||||
}
|
||||
|
||||
|
||||
void Label::set_uppercase(bool p_uppercase) {
|
||||
|
||||
uppercase=p_uppercase;
|
||||
word_cache_dirty=true;
|
||||
uppercase = p_uppercase;
|
||||
word_cache_dirty = true;
|
||||
minimum_size_changed();
|
||||
update();
|
||||
}
|
||||
|
|
@ -58,256 +55,239 @@ bool Label::is_uppercase() const {
|
|||
return uppercase;
|
||||
}
|
||||
|
||||
|
||||
int Label::get_line_height() const {
|
||||
|
||||
return get_font("font")->get_height();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Label::_notification(int p_what) {
|
||||
|
||||
if (p_what==NOTIFICATION_DRAW) {
|
||||
if (p_what == NOTIFICATION_DRAW) {
|
||||
|
||||
if (clip || autowrap)
|
||||
VisualServer::get_singleton()->canvas_item_set_clip(get_canvas_item(),true);
|
||||
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();
|
||||
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_outline = get_constant("shadow_as_outline");
|
||||
Point2 shadow_ofs(get_constant("shadow_offset_x"),get_constant("shadow_offset_y"));
|
||||
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());
|
||||
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 font_h = font->get_height() + line_spacing;
|
||||
|
||||
int lines_visible = (size.y+line_spacing)/font_h;
|
||||
int lines_visible = (size.y + line_spacing) / font_h;
|
||||
|
||||
int space_w=font->get_char_size(' ').width;
|
||||
int chars_total=0;
|
||||
int space_w = font->get_char_size(' ').width;
|
||||
int chars_total = 0;
|
||||
|
||||
int vbegin=0,vsep=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) {
|
||||
switch (valign) {
|
||||
|
||||
case VALIGN_TOP: {
|
||||
//nothing
|
||||
} break;
|
||||
case VALIGN_CENTER: {
|
||||
vbegin=(size.y - (lines_visible * font_h - line_spacing)) / 2;
|
||||
vsep=0;
|
||||
vbegin = (size.y - (lines_visible * font_h - line_spacing)) / 2;
|
||||
vsep = 0;
|
||||
|
||||
} break;
|
||||
case VALIGN_BOTTOM: {
|
||||
vbegin=size.y - (lines_visible * font_h - line_spacing);
|
||||
vsep=0;
|
||||
vbegin = size.y - (lines_visible * font_h - line_spacing);
|
||||
vsep = 0;
|
||||
|
||||
} break;
|
||||
case VALIGN_FILL: {
|
||||
vbegin=0;
|
||||
if (lines_visible>1) {
|
||||
vsep=(size.y - (lines_visible * font_h - line_spacing)) / (lines_visible - 1);
|
||||
vbegin = 0;
|
||||
if (lines_visible > 1) {
|
||||
vsep = (size.y - (lines_visible * font_h - line_spacing)) / (lines_visible - 1);
|
||||
} else {
|
||||
vsep=0;
|
||||
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)
|
||||
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) {
|
||||
if (line < lines_skipped) {
|
||||
|
||||
while (wc && wc->char_pos>=0)
|
||||
wc=wc->next;
|
||||
while (wc && wc->char_pos >= 0)
|
||||
wc = wc->next;
|
||||
if (wc)
|
||||
wc=wc->next;
|
||||
wc = wc->next;
|
||||
line++;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* handle lines normally */
|
||||
/* handle lines normally */
|
||||
|
||||
if (wc->char_pos<0) {
|
||||
//empty line
|
||||
wc=wc->next;
|
||||
if (wc->char_pos < 0) {
|
||||
//empty line
|
||||
wc = wc->next;
|
||||
line++;
|
||||
continue;
|
||||
}
|
||||
|
||||
WordCache *from=wc;
|
||||
WordCache *to=wc;
|
||||
WordCache *from = wc;
|
||||
WordCache *to = wc;
|
||||
|
||||
int taken=0;
|
||||
int spaces=0;
|
||||
while(to && to->char_pos>=0) {
|
||||
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;
|
||||
taken += to->pixel_width;
|
||||
if (to != from && to->space_count) {
|
||||
spaces += to->space_count;
|
||||
}
|
||||
to=to->next;
|
||||
to = to->next;
|
||||
}
|
||||
|
||||
bool can_fill = to && to->char_pos==WordCache::CHAR_WRAPLINE;
|
||||
bool can_fill = to && to->char_pos == WordCache::CHAR_WRAPLINE;
|
||||
|
||||
float x_ofs=0;
|
||||
float x_ofs = 0;
|
||||
|
||||
switch (align) {
|
||||
|
||||
case ALIGN_FILL:
|
||||
case ALIGN_LEFT: {
|
||||
|
||||
x_ofs=0;
|
||||
x_ofs = 0;
|
||||
} break;
|
||||
case ALIGN_CENTER: {
|
||||
|
||||
x_ofs=int(size.width-(taken+spaces*space_w))/2;
|
||||
x_ofs = int(size.width - (taken + spaces * space_w)) / 2;
|
||||
|
||||
} break;
|
||||
case ALIGN_RIGHT: {
|
||||
|
||||
|
||||
x_ofs=int(size.width-(taken+spaces*space_w));
|
||||
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;
|
||||
int y_ofs = (line - lines_skipped) * font_h + font->get_ascent();
|
||||
y_ofs += vbegin + line * vsep;
|
||||
|
||||
while(from!=to) {
|
||||
while (from != to) {
|
||||
|
||||
// draw a word
|
||||
// draw a word
|
||||
int pos = from->char_pos;
|
||||
if (from->char_pos<0) {
|
||||
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) {
|
||||
/* 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);
|
||||
x_ofs += int((size.width - (taken + space_w * spaces)) / spaces);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (font_color_shadow.a>0) {
|
||||
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++) {
|
||||
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 (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);
|
||||
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 );
|
||||
float move = font->draw_char(ci, Point2(x_ofs_shadow, y_ofs) + shadow_ofs, c, n, font_color_shadow);
|
||||
if (use_outline) {
|
||||
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 );
|
||||
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;
|
||||
x_ofs_shadow += move;
|
||||
chars_total_shadow++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
for (int i=0;i<from->word_len;i++) {
|
||||
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 (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);
|
||||
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 );
|
||||
x_ofs += font->draw_char(ci, Point2(x_ofs, y_ofs), c, n, font_color);
|
||||
chars_total++;
|
||||
}
|
||||
|
||||
}
|
||||
from=from->next;
|
||||
from = from->next;
|
||||
}
|
||||
|
||||
wc=to?to->next:0;
|
||||
wc = to ? to->next : 0;
|
||||
line++;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (p_what==NOTIFICATION_THEME_CHANGED) {
|
||||
if (p_what == NOTIFICATION_THEME_CHANGED) {
|
||||
|
||||
word_cache_dirty=true;
|
||||
word_cache_dirty = true;
|
||||
update();
|
||||
}
|
||||
if (p_what==NOTIFICATION_RESIZED) {
|
||||
if (p_what == NOTIFICATION_RESIZED) {
|
||||
|
||||
word_cache_dirty=true;
|
||||
word_cache_dirty = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Size2 Label::get_minimum_size() const {
|
||||
|
||||
if (autowrap)
|
||||
return Size2(1,1);
|
||||
return Size2(1, 1);
|
||||
else {
|
||||
|
||||
// don't want to mutable everything
|
||||
if(word_cache_dirty)
|
||||
const_cast<Label*>(this)->regenerate_word_cache();
|
||||
if (word_cache_dirty)
|
||||
const_cast<Label *>(this)->regenerate_word_cache();
|
||||
|
||||
Size2 ms=minsize;
|
||||
Size2 ms = minsize;
|
||||
if (clip)
|
||||
ms.width=1;
|
||||
ms.width = 1;
|
||||
return ms;
|
||||
}
|
||||
}
|
||||
|
|
@ -315,33 +295,32 @@ Size2 Label::get_minimum_size() const {
|
|||
int Label::get_longest_line_width() const {
|
||||
|
||||
Ref<Font> font = get_font("font");
|
||||
int max_line_width=0;
|
||||
int line_width=0;
|
||||
int max_line_width = 0;
|
||||
int line_width = 0;
|
||||
|
||||
for (int i=0;i<text.size();i++) {
|
||||
for (int i = 0; i < text.size(); i++) {
|
||||
|
||||
CharType current=text[i];
|
||||
CharType current = text[i];
|
||||
if (uppercase)
|
||||
current=String::char_uppercase(current);
|
||||
current = String::char_uppercase(current);
|
||||
|
||||
if (current<32) {
|
||||
if (current < 32) {
|
||||
|
||||
if (current=='\n') {
|
||||
if (current == '\n') {
|
||||
|
||||
if (line_width>max_line_width)
|
||||
max_line_width=line_width;
|
||||
line_width=0;
|
||||
if (line_width > max_line_width)
|
||||
max_line_width = line_width;
|
||||
line_width = 0;
|
||||
}
|
||||
} else {
|
||||
|
||||
int char_width=font->get_char_size(current,text[i+1]).width;
|
||||
line_width+=char_width;
|
||||
int char_width = font->get_char_size(current, text[i + 1]).width;
|
||||
line_width += char_width;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (line_width>max_line_width)
|
||||
max_line_width=line_width;
|
||||
if (line_width > max_line_width)
|
||||
max_line_width = line_width;
|
||||
|
||||
return max_line_width;
|
||||
}
|
||||
|
|
@ -351,7 +330,7 @@ int Label::get_line_count() const {
|
|||
if (!is_inside_tree())
|
||||
return 1;
|
||||
if (word_cache_dirty)
|
||||
const_cast<Label*>(this)->regenerate_word_cache();
|
||||
const_cast<Label *>(this)->regenerate_word_cache();
|
||||
|
||||
return line_count;
|
||||
}
|
||||
|
|
@ -359,8 +338,8 @@ int Label::get_line_count() const {
|
|||
int Label::get_visible_line_count() const {
|
||||
|
||||
int line_spacing = get_constant("line_spacing");
|
||||
int font_h = get_font("font")->get_height()+line_spacing;
|
||||
int lines_visible = (get_size().y+line_spacing)/font_h;
|
||||
int font_h = get_font("font")->get_height() + line_spacing;
|
||||
int lines_visible = (get_size().y + line_spacing) / font_h;
|
||||
|
||||
if (lines_visible > line_count)
|
||||
lines_visible = line_count;
|
||||
|
|
@ -375,190 +354,181 @@ void Label::regenerate_word_cache() {
|
|||
|
||||
while (word_cache) {
|
||||
|
||||
WordCache *current=word_cache;
|
||||
word_cache=current->next;
|
||||
memdelete( current );
|
||||
WordCache *current = word_cache;
|
||||
word_cache = current->next;
|
||||
memdelete(current);
|
||||
}
|
||||
|
||||
|
||||
int width=autowrap?get_size().width:get_longest_line_width();
|
||||
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 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;
|
||||
line_count = 1;
|
||||
total_char_cache = 0;
|
||||
|
||||
WordCache *last=NULL;
|
||||
WordCache *last = NULL;
|
||||
|
||||
for (int i=0;i<text.size()+1;i++) {
|
||||
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
|
||||
CharType current = i < text.length() ? text[i] : ' '; //always a space at the end, so the algo works
|
||||
|
||||
if (uppercase)
|
||||
current=String::char_uppercase(current);
|
||||
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;
|
||||
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 < 33) {
|
||||
|
||||
if (current_word_size>0) {
|
||||
WordCache *wc = memnew( WordCache );
|
||||
if (current_word_size > 0) {
|
||||
WordCache *wc = memnew(WordCache);
|
||||
if (word_cache) {
|
||||
last->next=wc;
|
||||
last->next = wc;
|
||||
} else {
|
||||
word_cache=wc;
|
||||
word_cache = wc;
|
||||
}
|
||||
last=wc;
|
||||
last = wc;
|
||||
|
||||
wc->pixel_width=current_word_size;
|
||||
wc->char_pos=word_pos;
|
||||
wc->word_len=i-word_pos;
|
||||
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;
|
||||
|
||||
current_word_size = 0;
|
||||
space_count = 0;
|
||||
}
|
||||
|
||||
|
||||
if (current=='\n') {
|
||||
insert_newline=true;
|
||||
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) {
|
||||
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;
|
||||
line_width += space_width;
|
||||
} else {
|
||||
space_count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
// latin characters
|
||||
if (current_word_size==0) {
|
||||
word_pos=i;
|
||||
if (current_word_size == 0) {
|
||||
word_pos = i;
|
||||
}
|
||||
|
||||
char_width=font->get_char_size(current,text[i+1]).width;
|
||||
current_word_size+=char_width;
|
||||
line_width+=char_width;
|
||||
char_width = font->get_char_size(current, text[i + 1]).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 (current_word_size > 0) {
|
||||
WordCache *wc = memnew(WordCache);
|
||||
if (word_cache) {
|
||||
last->next=wc;
|
||||
last->next = wc;
|
||||
} else {
|
||||
word_cache=wc;
|
||||
word_cache = wc;
|
||||
}
|
||||
last=wc;
|
||||
last = wc;
|
||||
|
||||
wc->pixel_width=current_word_size-char_width;
|
||||
wc->char_pos=word_pos;
|
||||
wc->word_len=i-word_pos;
|
||||
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;
|
||||
current_word_size = char_width;
|
||||
space_count = 0;
|
||||
word_pos = i;
|
||||
}
|
||||
}
|
||||
|
||||
WordCache *wc = memnew( WordCache );
|
||||
WordCache *wc = memnew(WordCache);
|
||||
if (word_cache) {
|
||||
last->next=wc;
|
||||
last->next = wc;
|
||||
} else {
|
||||
word_cache=wc;
|
||||
word_cache = wc;
|
||||
}
|
||||
last=wc;
|
||||
last = wc;
|
||||
|
||||
wc->pixel_width=0;
|
||||
wc->char_pos=insert_newline?WordCache::CHAR_NEWLINE:WordCache::CHAR_WRAPLINE;
|
||||
wc->pixel_width = 0;
|
||||
wc->char_pos = insert_newline ? WordCache::CHAR_NEWLINE : WordCache::CHAR_WRAPLINE;
|
||||
|
||||
line_width=current_word_size;
|
||||
line_width = current_word_size;
|
||||
line_count++;
|
||||
space_count=0;
|
||||
|
||||
space_count = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!autowrap) {
|
||||
minsize.width=width;
|
||||
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));
|
||||
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));
|
||||
minsize.height = (font->get_height() * line_count) + (line_spacing * (line_count - 1));
|
||||
}
|
||||
}
|
||||
|
||||
word_cache_dirty=false;
|
||||
|
||||
word_cache_dirty = false;
|
||||
}
|
||||
|
||||
void Label::set_align(Align p_align) {
|
||||
|
||||
ERR_FAIL_INDEX(p_align,4);
|
||||
align=p_align;
|
||||
ERR_FAIL_INDEX(p_align, 4);
|
||||
align = p_align;
|
||||
update();
|
||||
}
|
||||
|
||||
Label::Align Label::get_align() const{
|
||||
Label::Align Label::get_align() const {
|
||||
|
||||
return align;
|
||||
}
|
||||
|
||||
void Label::set_valign(VAlign p_align) {
|
||||
|
||||
ERR_FAIL_INDEX(p_align,4);
|
||||
valign=p_align;
|
||||
ERR_FAIL_INDEX(p_align, 4);
|
||||
valign = p_align;
|
||||
update();
|
||||
}
|
||||
|
||||
Label::VAlign Label::get_valign() const{
|
||||
Label::VAlign Label::get_valign() const {
|
||||
|
||||
return valign;
|
||||
}
|
||||
|
||||
void Label::set_text(const String& p_string) {
|
||||
void Label::set_text(const String &p_string) {
|
||||
|
||||
String str = XL_MESSAGE(p_string);
|
||||
|
||||
if (text==str)
|
||||
if (text == str)
|
||||
return;
|
||||
|
||||
text=str;
|
||||
word_cache_dirty=true;
|
||||
if (percent_visible<1)
|
||||
visible_chars=get_total_character_count()*percent_visible;
|
||||
text = str;
|
||||
word_cache_dirty = true;
|
||||
if (percent_visible < 1)
|
||||
visible_chars = get_total_character_count() * percent_visible;
|
||||
update();
|
||||
if (!autowrap) {
|
||||
minimum_size_changed();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Label::set_clip_text(bool p_clip) {
|
||||
|
||||
clip=p_clip;
|
||||
clip = p_clip;
|
||||
update();
|
||||
minimum_size_changed();
|
||||
}
|
||||
|
|
@ -575,9 +545,9 @@ String Label::get_text() const {
|
|||
|
||||
void Label::set_visible_characters(int p_amount) {
|
||||
|
||||
visible_chars=p_amount;
|
||||
visible_chars = p_amount;
|
||||
if (get_total_character_count() > 0) {
|
||||
percent_visible=(float)p_amount/(float)total_char_cache;
|
||||
percent_visible = (float)p_amount / (float)total_char_cache;
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
|
@ -589,44 +559,42 @@ int Label::get_visible_characters() const {
|
|||
|
||||
void Label::set_percent_visible(float p_percent) {
|
||||
|
||||
if (p_percent<0 || p_percent>=1) {
|
||||
if (p_percent < 0 || p_percent >= 1) {
|
||||
|
||||
visible_chars=-1;
|
||||
percent_visible=1;
|
||||
visible_chars = -1;
|
||||
percent_visible = 1;
|
||||
|
||||
} else {
|
||||
|
||||
visible_chars=get_total_character_count()*p_percent;
|
||||
percent_visible=p_percent;
|
||||
|
||||
visible_chars = get_total_character_count() * p_percent;
|
||||
percent_visible = p_percent;
|
||||
}
|
||||
update();
|
||||
|
||||
}
|
||||
|
||||
float Label::get_percent_visible() const{
|
||||
float Label::get_percent_visible() const {
|
||||
|
||||
return percent_visible;
|
||||
}
|
||||
|
||||
void Label::set_lines_skipped(int p_lines) {
|
||||
|
||||
lines_skipped=p_lines;
|
||||
lines_skipped = p_lines;
|
||||
update();
|
||||
}
|
||||
|
||||
int Label::get_lines_skipped() const{
|
||||
int Label::get_lines_skipped() const {
|
||||
|
||||
return lines_skipped;
|
||||
}
|
||||
|
||||
void Label::set_max_lines_visible(int p_lines) {
|
||||
|
||||
max_lines_visible=p_lines;
|
||||
max_lines_visible = p_lines;
|
||||
update();
|
||||
}
|
||||
|
||||
int Label::get_max_lines_visible() const{
|
||||
int Label::get_max_lines_visible() const {
|
||||
|
||||
return max_lines_visible;
|
||||
}
|
||||
|
|
@ -634,90 +602,86 @@ int Label::get_max_lines_visible() const{
|
|||
int Label::get_total_character_count() const {
|
||||
|
||||
if (word_cache_dirty)
|
||||
const_cast<Label*>(this)->regenerate_word_cache();
|
||||
const_cast<Label *>(this)->regenerate_word_cache();
|
||||
|
||||
return total_char_cache;
|
||||
}
|
||||
|
||||
void Label::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_align","align"),&Label::set_align);
|
||||
ObjectTypeDB::bind_method(_MD("get_align"),&Label::get_align);
|
||||
ObjectTypeDB::bind_method(_MD("set_valign","valign"),&Label::set_valign);
|
||||
ObjectTypeDB::bind_method(_MD("get_valign"),&Label::get_valign);
|
||||
ObjectTypeDB::bind_method(_MD("set_text","text"),&Label::set_text);
|
||||
ObjectTypeDB::bind_method(_MD("get_text"),&Label::get_text);
|
||||
ObjectTypeDB::bind_method(_MD("set_autowrap","enable"),&Label::set_autowrap);
|
||||
ObjectTypeDB::bind_method(_MD("has_autowrap"),&Label::has_autowrap);
|
||||
ObjectTypeDB::bind_method(_MD("set_clip_text","enable"),&Label::set_clip_text);
|
||||
ObjectTypeDB::bind_method(_MD("is_clipping_text"),&Label::is_clipping_text);
|
||||
ObjectTypeDB::bind_method(_MD("set_uppercase","enable"),&Label::set_uppercase);
|
||||
ObjectTypeDB::bind_method(_MD("is_uppercase"),&Label::is_uppercase);
|
||||
ObjectTypeDB::bind_method(_MD("get_line_height"),&Label::get_line_height);
|
||||
ObjectTypeDB::bind_method(_MD("get_line_count"),&Label::get_line_count);
|
||||
ObjectTypeDB::bind_method(_MD("get_visible_line_count"),&Label::get_visible_line_count);
|
||||
ObjectTypeDB::bind_method(_MD("get_total_character_count"),&Label::get_total_character_count);
|
||||
ObjectTypeDB::bind_method(_MD("set_visible_characters","amount"),&Label::set_visible_characters);
|
||||
ObjectTypeDB::bind_method(_MD("get_visible_characters"),&Label::get_visible_characters);
|
||||
ObjectTypeDB::bind_method(_MD("set_percent_visible","percent_visible"),&Label::set_percent_visible);
|
||||
ObjectTypeDB::bind_method(_MD("get_percent_visible"),&Label::get_percent_visible);
|
||||
ObjectTypeDB::bind_method(_MD("set_lines_skipped","lines_skipped"),&Label::set_lines_skipped);
|
||||
ObjectTypeDB::bind_method(_MD("get_lines_skipped"),&Label::get_lines_skipped);
|
||||
ObjectTypeDB::bind_method(_MD("set_max_lines_visible","lines_visible"),&Label::set_max_lines_visible);
|
||||
ObjectTypeDB::bind_method(_MD("get_max_lines_visible"),&Label::get_max_lines_visible);
|
||||
ObjectTypeDB::bind_method(_MD("set_align", "align"), &Label::set_align);
|
||||
ObjectTypeDB::bind_method(_MD("get_align"), &Label::get_align);
|
||||
ObjectTypeDB::bind_method(_MD("set_valign", "valign"), &Label::set_valign);
|
||||
ObjectTypeDB::bind_method(_MD("get_valign"), &Label::get_valign);
|
||||
ObjectTypeDB::bind_method(_MD("set_text", "text"), &Label::set_text);
|
||||
ObjectTypeDB::bind_method(_MD("get_text"), &Label::get_text);
|
||||
ObjectTypeDB::bind_method(_MD("set_autowrap", "enable"), &Label::set_autowrap);
|
||||
ObjectTypeDB::bind_method(_MD("has_autowrap"), &Label::has_autowrap);
|
||||
ObjectTypeDB::bind_method(_MD("set_clip_text", "enable"), &Label::set_clip_text);
|
||||
ObjectTypeDB::bind_method(_MD("is_clipping_text"), &Label::is_clipping_text);
|
||||
ObjectTypeDB::bind_method(_MD("set_uppercase", "enable"), &Label::set_uppercase);
|
||||
ObjectTypeDB::bind_method(_MD("is_uppercase"), &Label::is_uppercase);
|
||||
ObjectTypeDB::bind_method(_MD("get_line_height"), &Label::get_line_height);
|
||||
ObjectTypeDB::bind_method(_MD("get_line_count"), &Label::get_line_count);
|
||||
ObjectTypeDB::bind_method(_MD("get_visible_line_count"), &Label::get_visible_line_count);
|
||||
ObjectTypeDB::bind_method(_MD("get_total_character_count"), &Label::get_total_character_count);
|
||||
ObjectTypeDB::bind_method(_MD("set_visible_characters", "amount"), &Label::set_visible_characters);
|
||||
ObjectTypeDB::bind_method(_MD("get_visible_characters"), &Label::get_visible_characters);
|
||||
ObjectTypeDB::bind_method(_MD("set_percent_visible", "percent_visible"), &Label::set_percent_visible);
|
||||
ObjectTypeDB::bind_method(_MD("get_percent_visible"), &Label::get_percent_visible);
|
||||
ObjectTypeDB::bind_method(_MD("set_lines_skipped", "lines_skipped"), &Label::set_lines_skipped);
|
||||
ObjectTypeDB::bind_method(_MD("get_lines_skipped"), &Label::get_lines_skipped);
|
||||
ObjectTypeDB::bind_method(_MD("set_max_lines_visible", "lines_visible"), &Label::set_max_lines_visible);
|
||||
ObjectTypeDB::bind_method(_MD("get_max_lines_visible"), &Label::get_max_lines_visible);
|
||||
|
||||
BIND_CONSTANT( ALIGN_LEFT );
|
||||
BIND_CONSTANT( ALIGN_CENTER );
|
||||
BIND_CONSTANT( ALIGN_RIGHT );
|
||||
BIND_CONSTANT( ALIGN_FILL );
|
||||
BIND_CONSTANT(ALIGN_LEFT);
|
||||
BIND_CONSTANT(ALIGN_CENTER);
|
||||
BIND_CONSTANT(ALIGN_RIGHT);
|
||||
BIND_CONSTANT(ALIGN_FILL);
|
||||
|
||||
BIND_CONSTANT( VALIGN_TOP );
|
||||
BIND_CONSTANT( VALIGN_CENTER );
|
||||
BIND_CONSTANT( VALIGN_BOTTOM );
|
||||
BIND_CONSTANT( VALIGN_FILL );
|
||||
|
||||
ADD_PROPERTYNZ( PropertyInfo( Variant::STRING, "text",PROPERTY_HINT_MULTILINE_TEXT,"",PROPERTY_USAGE_DEFAULT_INTL), _SCS("set_text"),_SCS("get_text") );
|
||||
ADD_PROPERTYNZ( PropertyInfo( Variant::INT, "align", PROPERTY_HINT_ENUM,"Left,Center,Right,Fill" ),_SCS("set_align"),_SCS("get_align") );
|
||||
ADD_PROPERTYNZ( PropertyInfo( Variant::INT, "valign", PROPERTY_HINT_ENUM,"Top,Center,Bottom,Fill" ),_SCS("set_valign"),_SCS("get_valign") );
|
||||
ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "autowrap"),_SCS("set_autowrap"),_SCS("has_autowrap") );
|
||||
ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "clip_text"),_SCS("set_clip_text"),_SCS("is_clipping_text") );
|
||||
ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "uppercase"),_SCS("set_uppercase"),_SCS("is_uppercase") );
|
||||
ADD_PROPERTY( PropertyInfo( Variant::REAL, "percent_visible", PROPERTY_HINT_RANGE,"0,1,0.001"),_SCS("set_percent_visible"),_SCS("get_percent_visible") );
|
||||
ADD_PROPERTY( PropertyInfo( Variant::INT, "lines_skipped", PROPERTY_HINT_RANGE,"0,999,1"),_SCS("set_lines_skipped"),_SCS("get_lines_skipped") );
|
||||
ADD_PROPERTY( PropertyInfo( Variant::INT, "max_lines_visible", PROPERTY_HINT_RANGE,"-1,999,1"),_SCS("set_max_lines_visible"),_SCS("get_max_lines_visible") );
|
||||
BIND_CONSTANT(VALIGN_TOP);
|
||||
BIND_CONSTANT(VALIGN_CENTER);
|
||||
BIND_CONSTANT(VALIGN_BOTTOM);
|
||||
BIND_CONSTANT(VALIGN_FILL);
|
||||
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::STRING, "text", PROPERTY_HINT_MULTILINE_TEXT, "", PROPERTY_USAGE_DEFAULT_INTL), _SCS("set_text"), _SCS("get_text"));
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "align", PROPERTY_HINT_ENUM, "Left,Center,Right,Fill"), _SCS("set_align"), _SCS("get_align"));
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "valign", PROPERTY_HINT_ENUM, "Top,Center,Bottom,Fill"), _SCS("set_valign"), _SCS("get_valign"));
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "autowrap"), _SCS("set_autowrap"), _SCS("has_autowrap"));
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "clip_text"), _SCS("set_clip_text"), _SCS("is_clipping_text"));
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "uppercase"), _SCS("set_uppercase"), _SCS("is_uppercase"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "percent_visible", PROPERTY_HINT_RANGE, "0,1,0.001"), _SCS("set_percent_visible"), _SCS("get_percent_visible"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "lines_skipped", PROPERTY_HINT_RANGE, "0,999,1"), _SCS("set_lines_skipped"), _SCS("get_lines_skipped"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "max_lines_visible", PROPERTY_HINT_RANGE, "-1,999,1"), _SCS("set_max_lines_visible"), _SCS("get_max_lines_visible"));
|
||||
}
|
||||
|
||||
Label::Label(const String &p_text) {
|
||||
|
||||
align=ALIGN_LEFT;
|
||||
valign=VALIGN_TOP;
|
||||
text="";
|
||||
word_cache=NULL;
|
||||
word_cache_dirty=true;
|
||||
autowrap=false;
|
||||
line_count=0;
|
||||
align = ALIGN_LEFT;
|
||||
valign = VALIGN_TOP;
|
||||
text = "";
|
||||
word_cache = NULL;
|
||||
word_cache_dirty = true;
|
||||
autowrap = false;
|
||||
line_count = 0;
|
||||
set_v_size_flags(0);
|
||||
clip=false;
|
||||
clip = false;
|
||||
set_ignore_mouse(true);
|
||||
total_char_cache=0;
|
||||
visible_chars=-1;
|
||||
percent_visible=1;
|
||||
lines_skipped=0;
|
||||
max_lines_visible=-1;
|
||||
total_char_cache = 0;
|
||||
visible_chars = -1;
|
||||
percent_visible = 1;
|
||||
lines_skipped = 0;
|
||||
max_lines_visible = -1;
|
||||
set_text(p_text);
|
||||
uppercase=false;
|
||||
uppercase = false;
|
||||
}
|
||||
|
||||
|
||||
Label::~Label() {
|
||||
|
||||
while (word_cache) {
|
||||
|
||||
WordCache *current=word_cache;
|
||||
word_cache=current->next;
|
||||
memdelete( current );
|
||||
WordCache *current = word_cache;
|
||||
word_cache = current->next;
|
||||
memdelete(current);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -35,9 +35,9 @@
|
|||
*/
|
||||
class Label : public Control {
|
||||
|
||||
OBJ_TYPE( Label, Control );
|
||||
public:
|
||||
OBJ_TYPE(Label, Control);
|
||||
|
||||
public:
|
||||
enum Align {
|
||||
|
||||
ALIGN_LEFT,
|
||||
|
|
@ -69,15 +69,21 @@ private:
|
|||
struct WordCache {
|
||||
|
||||
enum {
|
||||
CHAR_NEWLINE=-1,
|
||||
CHAR_WRAPLINE=-2
|
||||
CHAR_NEWLINE = -1,
|
||||
CHAR_WRAPLINE = -2
|
||||
};
|
||||
int char_pos; // if -1, then newline
|
||||
int word_len;
|
||||
int pixel_width;
|
||||
int space_count;
|
||||
WordCache *next;
|
||||
WordCache() { char_pos=0; word_len=0; pixel_width=0; next=0; space_count=0;}
|
||||
WordCache() {
|
||||
char_pos = 0;
|
||||
word_len = 0;
|
||||
pixel_width = 0;
|
||||
next = 0;
|
||||
space_count = 0;
|
||||
}
|
||||
};
|
||||
|
||||
bool word_cache_dirty;
|
||||
|
|
@ -90,13 +96,13 @@ private:
|
|||
int visible_chars;
|
||||
int lines_skipped;
|
||||
int max_lines_visible;
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
|
||||
static void _bind_methods();
|
||||
// bind helpers
|
||||
public:
|
||||
|
||||
virtual Size2 get_minimum_size() const;
|
||||
|
||||
void set_align(Align p_align);
|
||||
|
|
@ -105,7 +111,7 @@ public:
|
|||
void set_valign(VAlign p_align);
|
||||
VAlign get_valign() const;
|
||||
|
||||
void set_text(const String& p_string);
|
||||
void set_text(const String &p_string);
|
||||
String get_text() const;
|
||||
|
||||
void set_autowrap(bool p_autowrap);
|
||||
|
|
@ -134,13 +140,11 @@ public:
|
|||
int get_line_count() const;
|
||||
int get_visible_line_count() const;
|
||||
|
||||
Label(const String& p_text=String());
|
||||
Label(const String &p_text = String());
|
||||
~Label();
|
||||
|
||||
};
|
||||
|
||||
|
||||
VARIANT_ENUM_CAST( Label::Align );
|
||||
VARIANT_ENUM_CAST( Label::VAlign );
|
||||
VARIANT_ENUM_CAST(Label::Align);
|
||||
VARIANT_ENUM_CAST(Label::VAlign);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -37,7 +37,7 @@
|
|||
*/
|
||||
class LineEdit : public Control {
|
||||
|
||||
OBJ_TYPE( LineEdit, Control );
|
||||
OBJ_TYPE(LineEdit, Control);
|
||||
|
||||
public:
|
||||
enum Align {
|
||||
|
|
@ -117,16 +117,16 @@ private:
|
|||
void _input_event(InputEvent p_event);
|
||||
void _notification(int p_what);
|
||||
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
void set_align(Align p_align);
|
||||
Align get_align() const;
|
||||
|
||||
virtual Variant get_drag_data(const Point2& p_point);
|
||||
virtual bool can_drop_data(const Point2& p_point,const Variant& p_data) const;
|
||||
virtual void drop_data(const Point2& p_point,const Variant& p_data);
|
||||
virtual Variant get_drag_data(const Point2 &p_point);
|
||||
virtual bool can_drop_data(const Point2 &p_point, const Variant &p_data) const;
|
||||
virtual void drop_data(const Point2 &p_point, const Variant &p_data);
|
||||
|
||||
void menu_option(int p_option);
|
||||
PopupMenu *get_menu() const;
|
||||
|
|
@ -165,17 +165,15 @@ public:
|
|||
void set_secret(bool p_secret);
|
||||
bool is_secret() const;
|
||||
|
||||
void select(int p_from=0, int p_to=-1);
|
||||
void select(int p_from = 0, int p_to = -1);
|
||||
|
||||
virtual Size2 get_minimum_size() const;
|
||||
|
||||
virtual bool is_text_field() const;
|
||||
LineEdit();
|
||||
~LineEdit();
|
||||
|
||||
};
|
||||
|
||||
|
||||
VARIANT_ENUM_CAST(LineEdit::Align);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -28,10 +28,9 @@
|
|||
/*************************************************************************/
|
||||
#include "link_button.h"
|
||||
|
||||
void LinkButton::set_text(const String &p_text) {
|
||||
|
||||
void LinkButton::set_text(const String& p_text) {
|
||||
|
||||
text=p_text;
|
||||
text = p_text;
|
||||
update();
|
||||
minimum_size_changed();
|
||||
}
|
||||
|
|
@ -42,7 +41,7 @@ String LinkButton::get_text() const {
|
|||
|
||||
void LinkButton::set_underline_mode(UnderlineMode p_underline_mode) {
|
||||
|
||||
underline_mode=p_underline_mode;
|
||||
underline_mode = p_underline_mode;
|
||||
update();
|
||||
}
|
||||
|
||||
|
|
@ -51,55 +50,51 @@ LinkButton::UnderlineMode LinkButton::get_underline_mode() const {
|
|||
return underline_mode;
|
||||
}
|
||||
|
||||
|
||||
Size2 LinkButton::get_minimum_size() const {
|
||||
|
||||
return get_font("font")->get_string_size( text );
|
||||
return get_font("font")->get_string_size(text);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void LinkButton::_notification(int p_what) {
|
||||
|
||||
switch( p_what ) {
|
||||
switch (p_what) {
|
||||
|
||||
case NOTIFICATION_DRAW: {
|
||||
|
||||
|
||||
RID ci = get_canvas_item();
|
||||
Size2 size=get_size();
|
||||
Size2 size = get_size();
|
||||
Color color;
|
||||
bool do_underline=false;
|
||||
bool do_underline = false;
|
||||
|
||||
//print_line(get_text()+": "+itos(is_flat())+" hover "+itos(get_draw_mode()));
|
||||
|
||||
switch( get_draw_mode() ) {
|
||||
switch (get_draw_mode()) {
|
||||
|
||||
case DRAW_NORMAL: {
|
||||
|
||||
color=get_color("font_color");
|
||||
do_underline=underline_mode==UNDERLINE_MODE_ALWAYS;
|
||||
color = get_color("font_color");
|
||||
do_underline = underline_mode == UNDERLINE_MODE_ALWAYS;
|
||||
} break;
|
||||
case DRAW_PRESSED: {
|
||||
|
||||
if (has_color("font_color_pressed"))
|
||||
color=get_color("font_color_pressed");
|
||||
color = get_color("font_color_pressed");
|
||||
else
|
||||
color=get_color("font_color");
|
||||
color = get_color("font_color");
|
||||
|
||||
do_underline=underline_mode!=UNDERLINE_MODE_NEVER;
|
||||
do_underline = underline_mode != UNDERLINE_MODE_NEVER;
|
||||
|
||||
} break;
|
||||
case DRAW_HOVER: {
|
||||
|
||||
color=get_color("font_color_hover");
|
||||
do_underline=underline_mode!=UNDERLINE_MODE_NEVER;
|
||||
color = get_color("font_color_hover");
|
||||
do_underline = underline_mode != UNDERLINE_MODE_NEVER;
|
||||
|
||||
} break;
|
||||
case DRAW_DISABLED: {
|
||||
|
||||
color=get_color("font_color_disabled");
|
||||
do_underline=underline_mode==UNDERLINE_MODE_ALWAYS;
|
||||
color = get_color("font_color_disabled");
|
||||
do_underline = underline_mode == UNDERLINE_MODE_ALWAYS;
|
||||
|
||||
} break;
|
||||
}
|
||||
|
|
@ -107,21 +102,19 @@ void LinkButton::_notification(int p_what) {
|
|||
if (has_focus()) {
|
||||
|
||||
Ref<StyleBox> style = get_stylebox("focus");
|
||||
style->draw(ci,Rect2(Point2(),size));
|
||||
style->draw(ci, Rect2(Point2(), size));
|
||||
}
|
||||
|
||||
Ref<Font> font=get_font("font");
|
||||
|
||||
draw_string(font,Vector2(0,font->get_ascent()),text,color);
|
||||
|
||||
Ref<Font> font = get_font("font");
|
||||
|
||||
draw_string(font, Vector2(0, font->get_ascent()), text, color);
|
||||
|
||||
if (do_underline) {
|
||||
int underline_spacing = get_constant("underline_spacing");
|
||||
int width = font->get_string_size(text).width;
|
||||
int y = font->get_ascent()+underline_spacing;
|
||||
int y = font->get_ascent() + underline_spacing;
|
||||
|
||||
draw_line(Vector2(0,y),Vector2(width,y),color);
|
||||
draw_line(Vector2(0, y), Vector2(width, y), color);
|
||||
}
|
||||
|
||||
} break;
|
||||
|
|
@ -130,24 +123,22 @@ void LinkButton::_notification(int p_what) {
|
|||
|
||||
void LinkButton::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_text","text"),&LinkButton::set_text);
|
||||
ObjectTypeDB::bind_method(_MD("get_text"),&LinkButton::get_text);
|
||||
ObjectTypeDB::bind_method(_MD("set_text", "text"), &LinkButton::set_text);
|
||||
ObjectTypeDB::bind_method(_MD("get_text"), &LinkButton::get_text);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_underline_mode","underline_mode"),&LinkButton::set_underline_mode);
|
||||
ObjectTypeDB::bind_method(_MD("get_underline_mode"),&LinkButton::get_underline_mode);
|
||||
ObjectTypeDB::bind_method(_MD("set_underline_mode", "underline_mode"), &LinkButton::set_underline_mode);
|
||||
ObjectTypeDB::bind_method(_MD("get_underline_mode"), &LinkButton::get_underline_mode);
|
||||
|
||||
BIND_CONSTANT(UNDERLINE_MODE_ALWAYS);
|
||||
BIND_CONSTANT(UNDERLINE_MODE_ON_HOVER);
|
||||
BIND_CONSTANT(UNDERLINE_MODE_NEVER);
|
||||
|
||||
BIND_CONSTANT( UNDERLINE_MODE_ALWAYS );
|
||||
BIND_CONSTANT( UNDERLINE_MODE_ON_HOVER );
|
||||
BIND_CONSTANT( UNDERLINE_MODE_NEVER );
|
||||
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::STRING,"text"), _SCS("set_text"), _SCS("get_text"));
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::INT,"underline",PROPERTY_HINT_ENUM,"Always,On Hover,Never"), _SCS("set_underline_mode"), _SCS("get_underline_mode"));
|
||||
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::STRING, "text"), _SCS("set_text"), _SCS("get_text"));
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "underline", PROPERTY_HINT_ENUM, "Always,On Hover,Never"), _SCS("set_underline_mode"), _SCS("get_underline_mode"));
|
||||
}
|
||||
|
||||
LinkButton::LinkButton() {
|
||||
underline_mode=UNDERLINE_MODE_ALWAYS;
|
||||
underline_mode = UNDERLINE_MODE_ALWAYS;
|
||||
set_enabled_focus_mode(FOCUS_NONE);
|
||||
set_default_cursor_shape(CURSOR_POINTING_HAND);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,33 +29,31 @@
|
|||
#ifndef LINKBUTTON_H
|
||||
#define LINKBUTTON_H
|
||||
|
||||
|
||||
#include "scene/gui/base_button.h"
|
||||
#include "scene/resources/bit_mask.h"
|
||||
|
||||
class LinkButton : public BaseButton {
|
||||
|
||||
OBJ_TYPE( LinkButton, BaseButton );
|
||||
public:
|
||||
OBJ_TYPE(LinkButton, BaseButton);
|
||||
|
||||
public:
|
||||
enum UnderlineMode {
|
||||
UNDERLINE_MODE_ALWAYS,
|
||||
UNDERLINE_MODE_ON_HOVER,
|
||||
UNDERLINE_MODE_NEVER
|
||||
};
|
||||
|
||||
private:
|
||||
String text;
|
||||
UnderlineMode underline_mode;
|
||||
|
||||
protected:
|
||||
|
||||
virtual Size2 get_minimum_size() const;
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
|
||||
void set_text(const String& p_text);
|
||||
void set_text(const String &p_text);
|
||||
String get_text() const;
|
||||
|
||||
void set_underline_mode(UnderlineMode p_underline_mode);
|
||||
|
|
@ -64,6 +62,6 @@ public:
|
|||
LinkButton();
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST( LinkButton::UnderlineMode );
|
||||
VARIANT_ENUM_CAST(LinkButton::UnderlineMode);
|
||||
|
||||
#endif // LINKBUTTON_H
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@
|
|||
/*************************************************************************/
|
||||
#include "margin_container.h"
|
||||
|
||||
|
||||
Size2 MarginContainer::get_minimum_size() const {
|
||||
|
||||
int margin_left = get_constant("margin_left");
|
||||
|
|
@ -38,7 +37,7 @@ Size2 MarginContainer::get_minimum_size() const {
|
|||
|
||||
Size2 max;
|
||||
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c)
|
||||
|
|
@ -59,12 +58,11 @@ Size2 MarginContainer::get_minimum_size() const {
|
|||
max.height += (margin_top + margin_bottom);
|
||||
|
||||
return max;
|
||||
|
||||
}
|
||||
|
||||
void MarginContainer::_notification(int p_what) {
|
||||
|
||||
if (p_what==NOTIFICATION_SORT_CHILDREN) {
|
||||
if (p_what == NOTIFICATION_SORT_CHILDREN) {
|
||||
|
||||
int margin_left = get_constant("margin_left");
|
||||
int margin_top = get_constant("margin_top");
|
||||
|
|
@ -73,7 +71,7 @@ void MarginContainer::_notification(int p_what) {
|
|||
|
||||
Size2 s = get_size();
|
||||
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c)
|
||||
|
|
@ -81,14 +79,12 @@ void MarginContainer::_notification(int p_what) {
|
|||
if (c->is_set_as_toplevel())
|
||||
continue;
|
||||
|
||||
int w=s.width-margin_left-margin_right;
|
||||
int h=s.height-margin_top-margin_bottom;
|
||||
fit_child_in_rect(c,Rect2(margin_left,margin_top,w,h));
|
||||
int w = s.width - margin_left - margin_right;
|
||||
int h = s.height - margin_top - margin_bottom;
|
||||
fit_child_in_rect(c, Rect2(margin_left, margin_top, w, h));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
MarginContainer::MarginContainer()
|
||||
{
|
||||
MarginContainer::MarginContainer() {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,12 +32,12 @@
|
|||
#include "scene/gui/container.h"
|
||||
|
||||
class MarginContainer : public Container {
|
||||
OBJ_TYPE(MarginContainer,Container);
|
||||
OBJ_TYPE(MarginContainer, Container);
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
public:
|
||||
|
||||
public:
|
||||
virtual Size2 get_minimum_size() const;
|
||||
|
||||
MarginContainer();
|
||||
|
|
|
|||
|
|
@ -30,11 +30,9 @@
|
|||
#include "os/keyboard.h"
|
||||
#include "scene/main/viewport.h"
|
||||
|
||||
|
||||
void MenuButton::_unhandled_key_input(InputEvent p_event) {
|
||||
|
||||
|
||||
if (p_event.is_pressed() && !p_event.is_echo() && (p_event.type==InputEvent::KEY || p_event.type==InputEvent::ACTION || p_event.type==InputEvent::JOYSTICK_BUTTON)) {
|
||||
if (p_event.is_pressed() && !p_event.is_echo() && (p_event.type == InputEvent::KEY || p_event.type == InputEvent::ACTION || p_event.type == InputEvent::JOYSTICK_BUTTON)) {
|
||||
|
||||
if (!get_parent() || !is_visible() || is_disabled())
|
||||
return;
|
||||
|
|
@ -42,26 +40,23 @@ void MenuButton::_unhandled_key_input(InputEvent p_event) {
|
|||
if (get_viewport()->get_modal_stack_top() && !get_viewport()->get_modal_stack_top()->is_a_parent_of(this))
|
||||
return; //ignore because of modal window
|
||||
|
||||
|
||||
if (popup->activate_item_by_event(p_event))
|
||||
accept_event();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MenuButton::pressed() {
|
||||
|
||||
emit_signal("about_to_show");
|
||||
Size2 size=get_size();
|
||||
Size2 size = get_size();
|
||||
|
||||
Point2 gp = get_global_pos();
|
||||
popup->set_global_pos( gp + Size2( 0, size.height ) );
|
||||
popup->set_size( Size2( size.width, 0) );
|
||||
popup->set_parent_rect( Rect2(Point2(gp-popup->get_global_pos()),get_size()));
|
||||
popup->set_global_pos(gp + Size2(0, size.height));
|
||||
popup->set_size(Size2(size.width, 0));
|
||||
popup->set_parent_rect(Rect2(Point2(gp - popup->get_global_pos()), get_size()));
|
||||
popup->popup();
|
||||
popup->call_deferred("grab_click_focus");
|
||||
popup->set_invalidate_click_until_motion();
|
||||
|
||||
}
|
||||
|
||||
void MenuButton::_input_event(InputEvent p_event) {
|
||||
|
|
@ -93,28 +88,27 @@ Array MenuButton::_get_items() const {
|
|||
|
||||
return popup->get("items");
|
||||
}
|
||||
void MenuButton::_set_items(const Array& p_items) {
|
||||
void MenuButton::_set_items(const Array &p_items) {
|
||||
|
||||
popup->set("items",p_items);
|
||||
popup->set("items", p_items);
|
||||
}
|
||||
|
||||
void MenuButton::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("get_popup:PopupMenu"),&MenuButton::get_popup);
|
||||
ObjectTypeDB::bind_method(_MD("_unhandled_key_input"),&MenuButton::_unhandled_key_input);
|
||||
ObjectTypeDB::bind_method(_MD("_set_items"),&MenuButton::_set_items);
|
||||
ObjectTypeDB::bind_method(_MD("_get_items"),&MenuButton::_get_items);
|
||||
ObjectTypeDB::bind_method(_MD("get_popup:PopupMenu"), &MenuButton::get_popup);
|
||||
ObjectTypeDB::bind_method(_MD("_unhandled_key_input"), &MenuButton::_unhandled_key_input);
|
||||
ObjectTypeDB::bind_method(_MD("_set_items"), &MenuButton::_set_items);
|
||||
ObjectTypeDB::bind_method(_MD("_get_items"), &MenuButton::_get_items);
|
||||
|
||||
ADD_PROPERTY( PropertyInfo(Variant::ARRAY,"items",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR), _SCS("_set_items"),_SCS("_get_items") );
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "items", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), _SCS("_set_items"), _SCS("_get_items"));
|
||||
|
||||
ADD_SIGNAL( MethodInfo("about_to_show") );
|
||||
ADD_SIGNAL(MethodInfo("about_to_show"));
|
||||
}
|
||||
MenuButton::MenuButton() {
|
||||
|
||||
|
||||
set_flat(true);
|
||||
set_enabled_focus_mode(FOCUS_NONE);
|
||||
popup = memnew( PopupMenu );
|
||||
popup = memnew(PopupMenu);
|
||||
popup->hide();
|
||||
add_child(popup);
|
||||
popup->set_as_toplevel(true);
|
||||
|
|
@ -122,9 +116,5 @@ MenuButton::MenuButton() {
|
|||
set_click_on_press(true);
|
||||
}
|
||||
|
||||
|
||||
MenuButton::~MenuButton() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -29,14 +29,14 @@
|
|||
#ifndef MENU_BUTTON_H
|
||||
#define MENU_BUTTON_H
|
||||
|
||||
#include "scene/gui/popup_menu.h"
|
||||
#include "scene/gui/button.h"
|
||||
#include "scene/gui/popup_menu.h"
|
||||
/**
|
||||
@author Juan Linietsky <reduzio@gmail.com>
|
||||
*/
|
||||
class MenuButton : public Button {
|
||||
|
||||
OBJ_TYPE( MenuButton, Button );
|
||||
OBJ_TYPE(MenuButton, Button);
|
||||
|
||||
bool clicked;
|
||||
PopupMenu *popup;
|
||||
|
|
@ -44,15 +44,14 @@ class MenuButton : public Button {
|
|||
|
||||
void _unhandled_key_input(InputEvent p_event);
|
||||
Array _get_items() const;
|
||||
void _set_items(const Array& p_items);
|
||||
void _set_items(const Array &p_items);
|
||||
|
||||
void _input_event(InputEvent p_event);
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
static void _bind_methods();
|
||||
public:
|
||||
|
||||
public:
|
||||
PopupMenu *get_popup();
|
||||
MenuButton();
|
||||
~MenuButton();
|
||||
|
|
|
|||
|
|
@ -29,22 +29,19 @@
|
|||
#include "option_button.h"
|
||||
#include "print_string.h"
|
||||
|
||||
|
||||
Size2 OptionButton::get_minimum_size() const {
|
||||
|
||||
|
||||
Size2 minsize = Button::get_minimum_size();
|
||||
|
||||
if (has_icon("arrow"))
|
||||
minsize.width+=Control::get_icon("arrow")->get_width();
|
||||
minsize.width += Control::get_icon("arrow")->get_width();
|
||||
|
||||
return minsize;
|
||||
}
|
||||
|
||||
void OptionButton::_notification(int p_what) {
|
||||
|
||||
|
||||
switch(p_what) {
|
||||
switch (p_what) {
|
||||
|
||||
case NOTIFICATION_DRAW: {
|
||||
|
||||
|
|
@ -53,86 +50,82 @@ void OptionButton::_notification(int p_what) {
|
|||
|
||||
RID ci = get_canvas_item();
|
||||
Ref<Texture> arrow = Control::get_icon("arrow");
|
||||
Ref<StyleBox> normal = get_stylebox("normal" );
|
||||
Ref<StyleBox> normal = get_stylebox("normal");
|
||||
|
||||
Size2 size = get_size();
|
||||
|
||||
Point2 ofs( size.width - arrow->get_width() - get_constant("arrow_margin"), int(Math::abs((size.height-arrow->get_height())/2)));
|
||||
arrow->draw(ci,ofs);
|
||||
Point2 ofs(size.width - arrow->get_width() - get_constant("arrow_margin"), int(Math::abs((size.height - arrow->get_height()) / 2)));
|
||||
arrow->draw(ci, ofs);
|
||||
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OptionButton::_selected(int p_which) {
|
||||
|
||||
int selid = -1;
|
||||
for (int i=0;i<popup->get_item_count();i++) {
|
||||
for (int i = 0; i < popup->get_item_count(); i++) {
|
||||
|
||||
bool is_clicked = popup->get_item_ID(i)==p_which;
|
||||
bool is_clicked = popup->get_item_ID(i) == p_which;
|
||||
if (is_clicked) {
|
||||
selid=i;
|
||||
selid = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (selid==-1 && p_which>=0 && p_which<popup->get_item_count()) {
|
||||
_select(p_which,true);
|
||||
if (selid == -1 && p_which >= 0 && p_which < popup->get_item_count()) {
|
||||
_select(p_which, true);
|
||||
} else {
|
||||
|
||||
ERR_FAIL_COND(selid==-1);
|
||||
ERR_FAIL_COND(selid == -1);
|
||||
|
||||
_select(selid,true);
|
||||
_select(selid, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OptionButton::pressed() {
|
||||
|
||||
Size2 size=get_size();
|
||||
popup->set_global_pos( get_global_pos() + Size2( 0, size.height ) );
|
||||
popup->set_size( Size2( size.width, 0) );
|
||||
Size2 size = get_size();
|
||||
popup->set_global_pos(get_global_pos() + Size2(0, size.height));
|
||||
popup->set_size(Size2(size.width, 0));
|
||||
|
||||
popup->popup();
|
||||
}
|
||||
|
||||
void OptionButton::add_icon_item(const Ref<Texture>& p_icon,const String& p_label,int p_ID) {
|
||||
void OptionButton::add_icon_item(const Ref<Texture> &p_icon, const String &p_label, int p_ID) {
|
||||
|
||||
popup->add_icon_check_item( p_icon, p_label, p_ID );
|
||||
if (popup->get_item_count()==1)
|
||||
popup->add_icon_check_item(p_icon, p_label, p_ID);
|
||||
if (popup->get_item_count() == 1)
|
||||
select(0);
|
||||
}
|
||||
void OptionButton::add_item(const String& p_label,int p_ID) {
|
||||
void OptionButton::add_item(const String &p_label, int p_ID) {
|
||||
|
||||
popup->add_check_item( p_label, p_ID );
|
||||
if (popup->get_item_count()==1)
|
||||
popup->add_check_item(p_label, p_ID);
|
||||
if (popup->get_item_count() == 1)
|
||||
select(0);
|
||||
}
|
||||
|
||||
void OptionButton::set_item_text(int p_idx,const String& p_text) {
|
||||
|
||||
popup->set_item_text(p_idx,p_text);
|
||||
void OptionButton::set_item_text(int p_idx, const String &p_text) {
|
||||
|
||||
popup->set_item_text(p_idx, p_text);
|
||||
}
|
||||
void OptionButton::set_item_icon(int p_idx,const Ref<Texture>& p_icon) {
|
||||
|
||||
popup->set_item_icon(p_idx,p_icon);
|
||||
void OptionButton::set_item_icon(int p_idx, const Ref<Texture> &p_icon) {
|
||||
|
||||
popup->set_item_icon(p_idx, p_icon);
|
||||
}
|
||||
void OptionButton::set_item_ID(int p_idx,int p_ID) {
|
||||
void OptionButton::set_item_ID(int p_idx, int p_ID) {
|
||||
|
||||
popup->set_item_ID(p_idx,p_ID);
|
||||
popup->set_item_ID(p_idx, p_ID);
|
||||
}
|
||||
|
||||
void OptionButton::set_item_metadata(int p_idx,const Variant& p_metadata) {
|
||||
void OptionButton::set_item_metadata(int p_idx, const Variant &p_metadata) {
|
||||
|
||||
popup->set_item_metadata(p_idx,p_metadata);
|
||||
popup->set_item_metadata(p_idx, p_metadata);
|
||||
}
|
||||
|
||||
void OptionButton::set_item_disabled(int p_idx,bool p_disabled) {
|
||||
void OptionButton::set_item_disabled(int p_idx, bool p_disabled) {
|
||||
|
||||
popup->set_item_disabled(p_idx,p_disabled);
|
||||
popup->set_item_disabled(p_idx, p_disabled);
|
||||
}
|
||||
|
||||
String OptionButton::get_item_text(int p_idx) const {
|
||||
|
|
@ -159,8 +152,7 @@ bool OptionButton::is_item_disabled(int p_idx) const {
|
|||
return popup->is_item_disabled(p_idx);
|
||||
}
|
||||
|
||||
|
||||
int OptionButton::get_item_count() const {
|
||||
int OptionButton::get_item_count() const {
|
||||
|
||||
return popup->get_item_count();
|
||||
}
|
||||
|
|
@ -174,44 +166,41 @@ void OptionButton::clear() {
|
|||
|
||||
popup->clear();
|
||||
set_text("");
|
||||
current=-1;
|
||||
current = -1;
|
||||
}
|
||||
|
||||
void OptionButton::_select(int p_idx,bool p_emit) {
|
||||
void OptionButton::_select(int p_idx, bool p_emit) {
|
||||
|
||||
if (p_idx<0)
|
||||
if (p_idx < 0)
|
||||
return;
|
||||
if (p_idx==current)
|
||||
if (p_idx == current)
|
||||
return;
|
||||
|
||||
ERR_FAIL_INDEX( p_idx, popup->get_item_count() );
|
||||
ERR_FAIL_INDEX(p_idx, popup->get_item_count());
|
||||
|
||||
for (int i=0;i<popup->get_item_count();i++) {
|
||||
for (int i = 0; i < popup->get_item_count(); i++) {
|
||||
|
||||
popup->set_item_checked(i,i==p_idx);
|
||||
popup->set_item_checked(i, i == p_idx);
|
||||
}
|
||||
|
||||
|
||||
|
||||
current=p_idx;
|
||||
set_text( popup->get_item_text( current ) );
|
||||
set_icon( popup->get_item_icon( current ) );
|
||||
current = p_idx;
|
||||
set_text(popup->get_item_text(current));
|
||||
set_icon(popup->get_item_icon(current));
|
||||
|
||||
if (is_inside_tree() && p_emit)
|
||||
emit_signal("item_selected",current);
|
||||
emit_signal("item_selected", current);
|
||||
}
|
||||
|
||||
void OptionButton::_select_int(int p_which) {
|
||||
|
||||
if (p_which<0 || p_which>=popup->get_item_count())
|
||||
if (p_which < 0 || p_which >= popup->get_item_count())
|
||||
return;
|
||||
_select(p_which,false);
|
||||
|
||||
_select(p_which, false);
|
||||
}
|
||||
|
||||
void OptionButton::select(int p_idx) {
|
||||
|
||||
_select(p_idx,false);
|
||||
_select(p_idx, false);
|
||||
}
|
||||
|
||||
int OptionButton::get_selected() const {
|
||||
|
|
@ -222,17 +211,16 @@ int OptionButton::get_selected() const {
|
|||
int OptionButton::get_selected_ID() const {
|
||||
|
||||
int idx = get_selected();
|
||||
if (idx<0)
|
||||
if (idx < 0)
|
||||
return 0;
|
||||
return get_item_ID(current);
|
||||
}
|
||||
Variant OptionButton::get_selected_metadata() const {
|
||||
|
||||
int idx = get_selected();
|
||||
if (idx<0)
|
||||
if (idx < 0)
|
||||
return Variant();
|
||||
return get_item_metadata(current);
|
||||
|
||||
}
|
||||
|
||||
void OptionButton::remove_item(int p_idx) {
|
||||
|
|
@ -243,7 +231,7 @@ void OptionButton::remove_item(int p_idx) {
|
|||
Array OptionButton::_get_items() const {
|
||||
|
||||
Array items;
|
||||
for(int i=0;i<get_item_count();i++) {
|
||||
for (int i = 0; i < get_item_count(); i++) {
|
||||
|
||||
items.push_back(get_item_text(i));
|
||||
items.push_back(get_item_icon(i));
|
||||
|
|
@ -253,90 +241,78 @@ Array OptionButton::_get_items() const {
|
|||
}
|
||||
|
||||
return items;
|
||||
|
||||
}
|
||||
void OptionButton::_set_items(const Array& p_items){
|
||||
void OptionButton::_set_items(const Array &p_items) {
|
||||
|
||||
ERR_FAIL_COND(p_items.size() % 5);
|
||||
clear();
|
||||
|
||||
for(int i=0;i<p_items.size();i+=5) {
|
||||
for (int i = 0; i < p_items.size(); i += 5) {
|
||||
|
||||
String text=p_items[i+0];
|
||||
Ref<Texture> icon=p_items[i+1];
|
||||
bool disabled=p_items[i+2];
|
||||
int id=p_items[i+3];
|
||||
Variant meta = p_items[i+4];
|
||||
String text = p_items[i + 0];
|
||||
Ref<Texture> icon = p_items[i + 1];
|
||||
bool disabled = p_items[i + 2];
|
||||
int id = p_items[i + 3];
|
||||
Variant meta = p_items[i + 4];
|
||||
|
||||
int idx=get_item_count();
|
||||
add_item(text,id);
|
||||
set_item_icon(idx,icon);
|
||||
set_item_disabled(idx,disabled);
|
||||
set_item_metadata(idx,meta);
|
||||
int idx = get_item_count();
|
||||
add_item(text, id);
|
||||
set_item_icon(idx, icon);
|
||||
set_item_disabled(idx, disabled);
|
||||
set_item_metadata(idx, meta);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void OptionButton::get_translatable_strings(List<String> *p_strings) const {
|
||||
|
||||
return popup->get_translatable_strings(p_strings);
|
||||
}
|
||||
|
||||
|
||||
void OptionButton::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("_selected"),&OptionButton::_selected);
|
||||
ObjectTypeDB::bind_method(_MD("_selected"), &OptionButton::_selected);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("add_item","label","id"),&OptionButton::add_item,DEFVAL(-1));
|
||||
ObjectTypeDB::bind_method(_MD("add_icon_item","texture:Texture","label","id"),&OptionButton::add_icon_item);
|
||||
ObjectTypeDB::bind_method(_MD("set_item_text","idx","text"),&OptionButton::set_item_text);
|
||||
ObjectTypeDB::bind_method(_MD("set_item_icon","idx","texture:Texture"),&OptionButton::set_item_icon);
|
||||
ObjectTypeDB::bind_method(_MD("set_item_disabled","idx","disabled"),&OptionButton::set_item_disabled);
|
||||
ObjectTypeDB::bind_method(_MD("set_item_ID","idx","id"),&OptionButton::set_item_ID);
|
||||
ObjectTypeDB::bind_method(_MD("set_item_metadata","idx","metadata"),&OptionButton::set_item_metadata);
|
||||
ObjectTypeDB::bind_method(_MD("get_item_text","idx"),&OptionButton::get_item_text);
|
||||
ObjectTypeDB::bind_method(_MD("get_item_icon:Texture","idx"),&OptionButton::get_item_icon);
|
||||
ObjectTypeDB::bind_method(_MD("get_item_ID","idx"),&OptionButton::get_item_ID);
|
||||
ObjectTypeDB::bind_method(_MD("get_item_metadata","idx"),&OptionButton::get_item_metadata);
|
||||
ObjectTypeDB::bind_method(_MD("is_item_disabled","idx"),&OptionButton::is_item_disabled);
|
||||
ObjectTypeDB::bind_method(_MD("get_item_count"),&OptionButton::get_item_count);
|
||||
ObjectTypeDB::bind_method(_MD("add_separator"),&OptionButton::add_separator);
|
||||
ObjectTypeDB::bind_method(_MD("clear"),&OptionButton::clear);
|
||||
ObjectTypeDB::bind_method(_MD("select","idx"),&OptionButton::select);
|
||||
ObjectTypeDB::bind_method(_MD("get_selected"),&OptionButton::get_selected);
|
||||
ObjectTypeDB::bind_method(_MD("get_selected_ID"),&OptionButton::get_selected_ID);
|
||||
ObjectTypeDB::bind_method(_MD("get_selected_metadata"),&OptionButton::get_selected_metadata);
|
||||
ObjectTypeDB::bind_method(_MD("remove_item","idx"),&OptionButton::remove_item);
|
||||
ObjectTypeDB::bind_method(_MD("_select_int"),&OptionButton::_select_int);
|
||||
ObjectTypeDB::bind_method(_MD("add_item", "label", "id"), &OptionButton::add_item, DEFVAL(-1));
|
||||
ObjectTypeDB::bind_method(_MD("add_icon_item", "texture:Texture", "label", "id"), &OptionButton::add_icon_item);
|
||||
ObjectTypeDB::bind_method(_MD("set_item_text", "idx", "text"), &OptionButton::set_item_text);
|
||||
ObjectTypeDB::bind_method(_MD("set_item_icon", "idx", "texture:Texture"), &OptionButton::set_item_icon);
|
||||
ObjectTypeDB::bind_method(_MD("set_item_disabled", "idx", "disabled"), &OptionButton::set_item_disabled);
|
||||
ObjectTypeDB::bind_method(_MD("set_item_ID", "idx", "id"), &OptionButton::set_item_ID);
|
||||
ObjectTypeDB::bind_method(_MD("set_item_metadata", "idx", "metadata"), &OptionButton::set_item_metadata);
|
||||
ObjectTypeDB::bind_method(_MD("get_item_text", "idx"), &OptionButton::get_item_text);
|
||||
ObjectTypeDB::bind_method(_MD("get_item_icon:Texture", "idx"), &OptionButton::get_item_icon);
|
||||
ObjectTypeDB::bind_method(_MD("get_item_ID", "idx"), &OptionButton::get_item_ID);
|
||||
ObjectTypeDB::bind_method(_MD("get_item_metadata", "idx"), &OptionButton::get_item_metadata);
|
||||
ObjectTypeDB::bind_method(_MD("is_item_disabled", "idx"), &OptionButton::is_item_disabled);
|
||||
ObjectTypeDB::bind_method(_MD("get_item_count"), &OptionButton::get_item_count);
|
||||
ObjectTypeDB::bind_method(_MD("add_separator"), &OptionButton::add_separator);
|
||||
ObjectTypeDB::bind_method(_MD("clear"), &OptionButton::clear);
|
||||
ObjectTypeDB::bind_method(_MD("select", "idx"), &OptionButton::select);
|
||||
ObjectTypeDB::bind_method(_MD("get_selected"), &OptionButton::get_selected);
|
||||
ObjectTypeDB::bind_method(_MD("get_selected_ID"), &OptionButton::get_selected_ID);
|
||||
ObjectTypeDB::bind_method(_MD("get_selected_metadata"), &OptionButton::get_selected_metadata);
|
||||
ObjectTypeDB::bind_method(_MD("remove_item", "idx"), &OptionButton::remove_item);
|
||||
ObjectTypeDB::bind_method(_MD("_select_int"), &OptionButton::_select_int);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("_set_items"),&OptionButton::_set_items);
|
||||
ObjectTypeDB::bind_method(_MD("_get_items"),&OptionButton::_get_items);
|
||||
ObjectTypeDB::bind_method(_MD("_set_items"), &OptionButton::_set_items);
|
||||
ObjectTypeDB::bind_method(_MD("_get_items"), &OptionButton::_get_items);
|
||||
|
||||
ADD_PROPERTY( PropertyInfo(Variant::INT,"selected"), _SCS("_select_int"),_SCS("get_selected") );
|
||||
ADD_PROPERTY( PropertyInfo(Variant::ARRAY,"items",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR), _SCS("_set_items"),_SCS("_get_items") );
|
||||
ADD_SIGNAL( MethodInfo("item_selected", PropertyInfo( Variant::INT,"ID") ) );
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "selected"), _SCS("_select_int"), _SCS("get_selected"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "items", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), _SCS("_set_items"), _SCS("_get_items"));
|
||||
ADD_SIGNAL(MethodInfo("item_selected", PropertyInfo(Variant::INT, "ID")));
|
||||
}
|
||||
|
||||
OptionButton::OptionButton() {
|
||||
|
||||
|
||||
popup = memnew( PopupMenu );
|
||||
popup = memnew(PopupMenu);
|
||||
popup->hide();
|
||||
popup->set_as_toplevel(true);
|
||||
add_child(popup);
|
||||
popup->connect("item_pressed", this,"_selected");
|
||||
popup->connect("item_pressed", this, "_selected");
|
||||
|
||||
current=-1;
|
||||
current = -1;
|
||||
set_text_align(ALIGN_LEFT);
|
||||
}
|
||||
|
||||
|
||||
OptionButton::~OptionButton() {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -36,34 +36,34 @@
|
|||
*/
|
||||
class OptionButton : public Button {
|
||||
|
||||
OBJ_TYPE( OptionButton, Button );
|
||||
OBJ_TYPE(OptionButton, Button);
|
||||
|
||||
PopupMenu *popup;
|
||||
int current;
|
||||
|
||||
void _selected(int p_which);
|
||||
void _select(int p_which,bool p_emit=false);
|
||||
void _select(int p_which, bool p_emit = false);
|
||||
void _select_int(int p_which);
|
||||
|
||||
Array _get_items() const;
|
||||
void _set_items(const Array& p_items);
|
||||
void _set_items(const Array &p_items);
|
||||
|
||||
virtual void pressed();
|
||||
protected:
|
||||
|
||||
protected:
|
||||
Size2 get_minimum_size() const;
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
void add_icon_item(const Ref<Texture> &p_icon, const String &p_label, int p_ID = -1);
|
||||
void add_item(const String &p_label, int p_ID = -1);
|
||||
|
||||
void add_icon_item(const Ref<Texture>& p_icon,const String& p_label,int p_ID=-1);
|
||||
void add_item(const String& p_label,int p_ID=-1);
|
||||
|
||||
void set_item_text(int p_idx,const String& p_text);
|
||||
void set_item_icon(int p_idx,const Ref<Texture>& p_icon);
|
||||
void set_item_ID(int p_idx,int p_ID);
|
||||
void set_item_metadata(int p_idx,const Variant& p_metadata);
|
||||
void set_item_disabled(int p_idx,bool p_disabled);
|
||||
void set_item_text(int p_idx, const String &p_text);
|
||||
void set_item_icon(int p_idx, const Ref<Texture> &p_icon);
|
||||
void set_item_ID(int p_idx, int p_ID);
|
||||
void set_item_metadata(int p_idx, const Variant &p_metadata);
|
||||
void set_item_disabled(int p_idx, bool p_disabled);
|
||||
|
||||
String get_item_text(int p_idx) const;
|
||||
Ref<Texture> get_item_icon(int p_idx) const;
|
||||
|
|
@ -71,7 +71,6 @@ public:
|
|||
Variant get_item_metadata(int p_idx) const;
|
||||
bool is_item_disabled(int p_idx) const;
|
||||
|
||||
|
||||
int get_item_count() const;
|
||||
|
||||
void add_separator();
|
||||
|
|
@ -89,7 +88,6 @@ public:
|
|||
|
||||
OptionButton();
|
||||
~OptionButton();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -31,11 +31,11 @@
|
|||
|
||||
void Panel::_notification(int p_what) {
|
||||
|
||||
if (p_what==NOTIFICATION_DRAW) {
|
||||
if (p_what == NOTIFICATION_DRAW) {
|
||||
|
||||
RID ci = get_canvas_item();
|
||||
Ref<StyleBox> style = get_stylebox("panel");
|
||||
style->draw( ci, Rect2( Point2(), get_size() ) );
|
||||
style->draw(ci, Rect2(Point2(), get_size()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -44,9 +44,5 @@ Panel::Panel() {
|
|||
set_stop_mouse(true);
|
||||
}
|
||||
|
||||
|
||||
Panel::~Panel()
|
||||
{
|
||||
Panel::~Panel() {
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -33,16 +33,16 @@
|
|||
/**
|
||||
@author Juan Linietsky <reduzio@gmail.com>
|
||||
*/
|
||||
class Panel : public Control{
|
||||
class Panel : public Control {
|
||||
|
||||
OBJ_TYPE(Panel, Control);
|
||||
|
||||
OBJ_TYPE(Panel,Control);
|
||||
protected:
|
||||
|
||||
void _notification(int p_what);
|
||||
|
||||
public:
|
||||
Panel();
|
||||
~Panel();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -28,19 +28,17 @@
|
|||
/*************************************************************************/
|
||||
#include "panel_container.h"
|
||||
|
||||
|
||||
Size2 PanelContainer::get_minimum_size() const {
|
||||
|
||||
Ref<StyleBox> style;
|
||||
|
||||
if (has_stylebox("panel"))
|
||||
style=get_stylebox("panel");
|
||||
style = get_stylebox("panel");
|
||||
else
|
||||
style=get_stylebox("panel","PanelContainer");
|
||||
|
||||
style = get_stylebox("panel", "PanelContainer");
|
||||
|
||||
Size2 ms;
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c || !c->is_visible())
|
||||
|
|
@ -49,53 +47,47 @@ Size2 PanelContainer::get_minimum_size() const {
|
|||
continue;
|
||||
|
||||
Size2 minsize = c->get_combined_minimum_size();
|
||||
ms.width = MAX(ms.width , minsize.width);
|
||||
ms.height = MAX(ms.height , minsize.height);
|
||||
|
||||
|
||||
ms.width = MAX(ms.width, minsize.width);
|
||||
ms.height = MAX(ms.height, minsize.height);
|
||||
}
|
||||
|
||||
if (style.is_valid())
|
||||
ms+=style->get_minimum_size();
|
||||
ms += style->get_minimum_size();
|
||||
return ms;
|
||||
|
||||
}
|
||||
|
||||
void PanelContainer::_notification(int p_what) {
|
||||
|
||||
if (p_what==NOTIFICATION_DRAW) {
|
||||
if (p_what == NOTIFICATION_DRAW) {
|
||||
|
||||
RID ci = get_canvas_item();
|
||||
Ref<StyleBox> style;
|
||||
|
||||
if (has_stylebox("panel"))
|
||||
style=get_stylebox("panel");
|
||||
style = get_stylebox("panel");
|
||||
else
|
||||
style=get_stylebox("panel","PanelContainer");
|
||||
|
||||
style->draw( ci, Rect2( Point2(), get_size() ) );
|
||||
style = get_stylebox("panel", "PanelContainer");
|
||||
|
||||
style->draw(ci, Rect2(Point2(), get_size()));
|
||||
}
|
||||
|
||||
if (p_what==NOTIFICATION_SORT_CHILDREN) {
|
||||
if (p_what == NOTIFICATION_SORT_CHILDREN) {
|
||||
|
||||
Ref<StyleBox> style;
|
||||
|
||||
if (has_stylebox("panel"))
|
||||
style=get_stylebox("panel");
|
||||
style = get_stylebox("panel");
|
||||
else
|
||||
style=get_stylebox("panel","PanelContainer");
|
||||
style = get_stylebox("panel", "PanelContainer");
|
||||
|
||||
Size2 size = get_size();
|
||||
Point2 ofs;
|
||||
if (style.is_valid()) {
|
||||
size-=style->get_minimum_size();
|
||||
ofs+=style->get_offset();
|
||||
size -= style->get_minimum_size();
|
||||
ofs += style->get_offset();
|
||||
}
|
||||
|
||||
|
||||
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c || !c->is_visible())
|
||||
|
|
@ -103,12 +95,10 @@ void PanelContainer::_notification(int p_what) {
|
|||
if (c->is_set_as_toplevel())
|
||||
continue;
|
||||
|
||||
fit_child_in_rect(c,Rect2(ofs,size));
|
||||
|
||||
fit_child_in_rect(c, Rect2(ofs, size));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PanelContainer::PanelContainer()
|
||||
{
|
||||
PanelContainer::PanelContainer() {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,13 +33,12 @@
|
|||
|
||||
class PanelContainer : public Container {
|
||||
|
||||
OBJ_TYPE( PanelContainer, Container );
|
||||
OBJ_TYPE(PanelContainer, Container);
|
||||
|
||||
protected:
|
||||
|
||||
void _notification(int p_what);
|
||||
public:
|
||||
|
||||
public:
|
||||
virtual Size2 get_minimum_size() const;
|
||||
|
||||
PanelContainer();
|
||||
|
|
|
|||
|
|
@ -32,17 +32,17 @@
|
|||
|
||||
void Patch9Frame::_notification(int p_what) {
|
||||
|
||||
if (p_what==NOTIFICATION_DRAW) {
|
||||
if (p_what == NOTIFICATION_DRAW) {
|
||||
|
||||
if (texture.is_null())
|
||||
return;
|
||||
|
||||
Size2 s=get_size();
|
||||
Size2 s = get_size();
|
||||
RID ci = get_canvas_item();
|
||||
VS::get_singleton()->canvas_item_add_style_box(ci,Rect2(Point2(),s),region_rect,texture->get_rid(),Vector2(margin[MARGIN_LEFT],margin[MARGIN_TOP]),Vector2(margin[MARGIN_RIGHT],margin[MARGIN_BOTTOM]),draw_center,modulate);
|
||||
// draw_texture_rect(texture,Rect2(Point2(),s),false,modulate);
|
||||
VS::get_singleton()->canvas_item_add_style_box(ci, Rect2(Point2(), s), region_rect, texture->get_rid(), Vector2(margin[MARGIN_LEFT], margin[MARGIN_TOP]), Vector2(margin[MARGIN_RIGHT], margin[MARGIN_BOTTOM]), draw_center, modulate);
|
||||
// draw_texture_rect(texture,Rect2(Point2(),s),false,modulate);
|
||||
|
||||
/*
|
||||
/*
|
||||
Vector<Point2> points;
|
||||
points.resize(4);
|
||||
points[0]=Point2(0,0);
|
||||
|
|
@ -63,41 +63,38 @@ void Patch9Frame::_notification(int p_what) {
|
|||
|
||||
Size2 Patch9Frame::get_minimum_size() const {
|
||||
|
||||
return Size2(margin[MARGIN_LEFT]+margin[MARGIN_RIGHT],margin[MARGIN_TOP]+margin[MARGIN_BOTTOM]);
|
||||
return Size2(margin[MARGIN_LEFT] + margin[MARGIN_RIGHT], margin[MARGIN_TOP] + margin[MARGIN_BOTTOM]);
|
||||
}
|
||||
void Patch9Frame::_bind_methods() {
|
||||
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_texture","texture"), & Patch9Frame::set_texture );
|
||||
ObjectTypeDB::bind_method(_MD("get_texture"), & Patch9Frame::get_texture );
|
||||
ObjectTypeDB::bind_method(_MD("set_modulate","modulate"), & Patch9Frame::set_modulate );
|
||||
ObjectTypeDB::bind_method(_MD("get_modulate"), & Patch9Frame::get_modulate );
|
||||
ObjectTypeDB::bind_method(_MD("set_patch_margin","margin","value"), & Patch9Frame::set_patch_margin );
|
||||
ObjectTypeDB::bind_method(_MD("get_patch_margin","margin"), & Patch9Frame::get_patch_margin );
|
||||
ObjectTypeDB::bind_method(_MD("set_region_rect","rect"),&Patch9Frame::set_region_rect);
|
||||
ObjectTypeDB::bind_method(_MD("get_region_rect"),&Patch9Frame::get_region_rect);
|
||||
ObjectTypeDB::bind_method(_MD("set_draw_center","draw_center"), & Patch9Frame::set_draw_center );
|
||||
ObjectTypeDB::bind_method(_MD("get_draw_center"), & Patch9Frame::get_draw_center );
|
||||
ObjectTypeDB::bind_method(_MD("set_texture", "texture"), &Patch9Frame::set_texture);
|
||||
ObjectTypeDB::bind_method(_MD("get_texture"), &Patch9Frame::get_texture);
|
||||
ObjectTypeDB::bind_method(_MD("set_modulate", "modulate"), &Patch9Frame::set_modulate);
|
||||
ObjectTypeDB::bind_method(_MD("get_modulate"), &Patch9Frame::get_modulate);
|
||||
ObjectTypeDB::bind_method(_MD("set_patch_margin", "margin", "value"), &Patch9Frame::set_patch_margin);
|
||||
ObjectTypeDB::bind_method(_MD("get_patch_margin", "margin"), &Patch9Frame::get_patch_margin);
|
||||
ObjectTypeDB::bind_method(_MD("set_region_rect", "rect"), &Patch9Frame::set_region_rect);
|
||||
ObjectTypeDB::bind_method(_MD("get_region_rect"), &Patch9Frame::get_region_rect);
|
||||
ObjectTypeDB::bind_method(_MD("set_draw_center", "draw_center"), &Patch9Frame::set_draw_center);
|
||||
ObjectTypeDB::bind_method(_MD("get_draw_center"), &Patch9Frame::get_draw_center);
|
||||
|
||||
ADD_SIGNAL(MethodInfo("texture_changed"));
|
||||
|
||||
ADD_PROPERTYNZ( PropertyInfo( Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), _SCS("set_texture"),_SCS("get_texture") );
|
||||
ADD_PROPERTYNO( PropertyInfo( Variant::COLOR, "modulate"), _SCS("set_modulate"),_SCS("get_modulate") );
|
||||
ADD_PROPERTYNO( PropertyInfo( Variant::BOOL, "draw_center"), _SCS("set_draw_center"),_SCS("get_draw_center") );
|
||||
ADD_PROPERTYNZ( PropertyInfo( Variant::RECT2, "region_rect"), _SCS("set_region_rect"),_SCS("get_region_rect"));
|
||||
ADD_PROPERTYINZ( PropertyInfo( Variant::INT, "patch_margin/left",PROPERTY_HINT_RANGE,"0,16384,1"), _SCS("set_patch_margin"),_SCS("get_patch_margin"),MARGIN_LEFT );
|
||||
ADD_PROPERTYINZ( PropertyInfo( Variant::INT, "patch_margin/top",PROPERTY_HINT_RANGE,"0,16384,1"), _SCS("set_patch_margin"),_SCS("get_patch_margin"),MARGIN_TOP );
|
||||
ADD_PROPERTYINZ( PropertyInfo( Variant::INT, "patch_margin/right",PROPERTY_HINT_RANGE,"0,16384,1"), _SCS("set_patch_margin"),_SCS("get_patch_margin"),MARGIN_RIGHT );
|
||||
ADD_PROPERTYINZ( PropertyInfo( Variant::INT, "patch_margin/bottom",PROPERTY_HINT_RANGE,"0,16384,1"), _SCS("set_patch_margin"),_SCS("get_patch_margin"),MARGIN_BOTTOM );
|
||||
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), _SCS("set_texture"), _SCS("get_texture"));
|
||||
ADD_PROPERTYNO(PropertyInfo(Variant::COLOR, "modulate"), _SCS("set_modulate"), _SCS("get_modulate"));
|
||||
ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "draw_center"), _SCS("set_draw_center"), _SCS("get_draw_center"));
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::RECT2, "region_rect"), _SCS("set_region_rect"), _SCS("get_region_rect"));
|
||||
ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "patch_margin/left", PROPERTY_HINT_RANGE, "0,16384,1"), _SCS("set_patch_margin"), _SCS("get_patch_margin"), MARGIN_LEFT);
|
||||
ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "patch_margin/top", PROPERTY_HINT_RANGE, "0,16384,1"), _SCS("set_patch_margin"), _SCS("get_patch_margin"), MARGIN_TOP);
|
||||
ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "patch_margin/right", PROPERTY_HINT_RANGE, "0,16384,1"), _SCS("set_patch_margin"), _SCS("get_patch_margin"), MARGIN_RIGHT);
|
||||
ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "patch_margin/bottom", PROPERTY_HINT_RANGE, "0,16384,1"), _SCS("set_patch_margin"), _SCS("get_patch_margin"), MARGIN_BOTTOM);
|
||||
}
|
||||
|
||||
void Patch9Frame::set_texture(const Ref<Texture> &p_tex) {
|
||||
|
||||
void Patch9Frame::set_texture(const Ref<Texture>& p_tex) {
|
||||
|
||||
if (texture==p_tex)
|
||||
if (texture == p_tex)
|
||||
return;
|
||||
texture=p_tex;
|
||||
texture = p_tex;
|
||||
update();
|
||||
//if (texture.is_valid())
|
||||
// texture->set_flags(texture->get_flags()&(~Texture::FLAG_REPEAT)); //remove repeat from texture, it looks bad in sprites
|
||||
|
|
@ -110,22 +107,21 @@ Ref<Texture> Patch9Frame::get_texture() const {
|
|||
return texture;
|
||||
}
|
||||
|
||||
void Patch9Frame::set_modulate(const Color& p_tex) {
|
||||
void Patch9Frame::set_modulate(const Color &p_tex) {
|
||||
|
||||
modulate=p_tex;
|
||||
modulate = p_tex;
|
||||
update();
|
||||
}
|
||||
|
||||
Color Patch9Frame::get_modulate() const{
|
||||
Color Patch9Frame::get_modulate() const {
|
||||
|
||||
return modulate;
|
||||
}
|
||||
|
||||
void Patch9Frame::set_patch_margin(Margin p_margin, int p_size) {
|
||||
|
||||
void Patch9Frame::set_patch_margin(Margin p_margin,int p_size) {
|
||||
|
||||
ERR_FAIL_INDEX(p_margin,4);
|
||||
margin[p_margin]=p_size;
|
||||
ERR_FAIL_INDEX(p_margin, 4);
|
||||
margin[p_margin] = p_size;
|
||||
update();
|
||||
minimum_size_changed();
|
||||
switch (p_margin) {
|
||||
|
|
@ -144,18 +140,18 @@ void Patch9Frame::set_patch_margin(Margin p_margin,int p_size) {
|
|||
}
|
||||
}
|
||||
|
||||
int Patch9Frame::get_patch_margin(Margin p_margin) const{
|
||||
int Patch9Frame::get_patch_margin(Margin p_margin) const {
|
||||
|
||||
ERR_FAIL_INDEX_V(p_margin,4,0);
|
||||
ERR_FAIL_INDEX_V(p_margin, 4, 0);
|
||||
return margin[p_margin];
|
||||
}
|
||||
|
||||
void Patch9Frame::set_region_rect(const Rect2& p_region_rect) {
|
||||
void Patch9Frame::set_region_rect(const Rect2 &p_region_rect) {
|
||||
|
||||
if (region_rect==p_region_rect)
|
||||
if (region_rect == p_region_rect)
|
||||
return;
|
||||
|
||||
region_rect=p_region_rect;
|
||||
region_rect = p_region_rect;
|
||||
|
||||
item_rect_changed();
|
||||
_change_notify("region_rect");
|
||||
|
|
@ -168,28 +164,25 @@ Rect2 Patch9Frame::get_region_rect() const {
|
|||
|
||||
void Patch9Frame::set_draw_center(bool p_draw) {
|
||||
|
||||
draw_center=p_draw;
|
||||
draw_center = p_draw;
|
||||
update();
|
||||
}
|
||||
|
||||
bool Patch9Frame::get_draw_center() const{
|
||||
bool Patch9Frame::get_draw_center() const {
|
||||
|
||||
return draw_center;
|
||||
}
|
||||
|
||||
Patch9Frame::Patch9Frame() {
|
||||
|
||||
|
||||
margin[MARGIN_LEFT]=0;
|
||||
margin[MARGIN_RIGHT]=0;
|
||||
margin[MARGIN_BOTTOM]=0;
|
||||
margin[MARGIN_TOP]=0;
|
||||
modulate=Color(1,1,1,1);
|
||||
margin[MARGIN_LEFT] = 0;
|
||||
margin[MARGIN_RIGHT] = 0;
|
||||
margin[MARGIN_BOTTOM] = 0;
|
||||
margin[MARGIN_TOP] = 0;
|
||||
modulate = Color(1, 1, 1, 1);
|
||||
set_ignore_mouse(true);
|
||||
draw_center=true;
|
||||
draw_center = true;
|
||||
}
|
||||
|
||||
|
||||
Patch9Frame::~Patch9Frame()
|
||||
{
|
||||
Patch9Frame::~Patch9Frame() {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,31 +35,30 @@
|
|||
*/
|
||||
class Patch9Frame : public Control {
|
||||
|
||||
OBJ_TYPE(Patch9Frame,Control);
|
||||
OBJ_TYPE(Patch9Frame, Control);
|
||||
|
||||
bool draw_center;
|
||||
int margin[4];
|
||||
Rect2 region_rect;
|
||||
Color modulate;
|
||||
Ref<Texture> texture;
|
||||
protected:
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
virtual Size2 get_minimum_size() const;
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
|
||||
void set_texture(const Ref<Texture>& p_tex);
|
||||
void set_texture(const Ref<Texture> &p_tex);
|
||||
Ref<Texture> get_texture() const;
|
||||
|
||||
void set_modulate(const Color& p_tex);
|
||||
void set_modulate(const Color &p_tex);
|
||||
Color get_modulate() const;
|
||||
|
||||
void set_patch_margin(Margin p_margin,int p_size);
|
||||
void set_patch_margin(Margin p_margin, int p_size);
|
||||
int get_patch_margin(Margin p_margin) const;
|
||||
|
||||
void set_region_rect(const Rect2& p_region_rect);
|
||||
void set_region_rect(const Rect2 &p_region_rect);
|
||||
Rect2 get_region_rect() const;
|
||||
|
||||
void set_draw_center(bool p_enable);
|
||||
|
|
@ -67,6 +66,5 @@ public:
|
|||
|
||||
Patch9Frame();
|
||||
~Patch9Frame();
|
||||
|
||||
};
|
||||
#endif // PATCH_9_FRAME_H
|
||||
|
|
|
|||
|
|
@ -29,18 +29,14 @@
|
|||
#include "popup.h"
|
||||
#include "os/keyboard.h"
|
||||
|
||||
|
||||
|
||||
void Popup::_input_event(InputEvent p_event) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Popup::_notification(int p_what) {
|
||||
|
||||
if (p_what==NOTIFICATION_VISIBILITY_CHANGED) {
|
||||
if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
|
||||
if (popped_up && !is_visible()) {
|
||||
popped_up=false;
|
||||
popped_up = false;
|
||||
notification(NOTIFICATION_POPUP_HIDE);
|
||||
emit_signal("popup_hide");
|
||||
}
|
||||
|
|
@ -48,20 +44,18 @@ void Popup::_notification(int p_what) {
|
|||
update_configuration_warning();
|
||||
}
|
||||
|
||||
if (p_what==NOTIFICATION_ENTER_TREE) {
|
||||
//small helper to make editing of these easier in editor
|
||||
if (p_what == NOTIFICATION_ENTER_TREE) {
|
||||
//small helper to make editing of these easier in editor
|
||||
#ifdef TOOLS_ENABLED
|
||||
if (get_tree()->is_editor_hint() && get_tree()->get_edited_scene_root() && get_tree()->get_edited_scene_root()->is_a_parent_of(this)) {
|
||||
set_as_toplevel(false);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Popup::_fix_size() {
|
||||
|
||||
|
||||
#if 0
|
||||
Point2 pos = get_pos();
|
||||
Size2 size = get_size();
|
||||
|
|
@ -73,34 +67,32 @@ void Popup::_fix_size() {
|
|||
Point2 window_size = get_viewport_rect().size;
|
||||
|
||||
#endif
|
||||
if (pos.x+size.width > window_size.width)
|
||||
pos.x=window_size.width-size.width;
|
||||
if (pos.x<0)
|
||||
pos.x=0;
|
||||
if (pos.x + size.width > window_size.width)
|
||||
pos.x = window_size.width - size.width;
|
||||
if (pos.x < 0)
|
||||
pos.x = 0;
|
||||
|
||||
if (pos.y+size.height > window_size.height)
|
||||
pos.y=window_size.height-size.height;
|
||||
if (pos.y<0)
|
||||
pos.y=0;
|
||||
if (pos.y + size.height > window_size.height)
|
||||
pos.y = window_size.height - size.height;
|
||||
if (pos.y < 0)
|
||||
pos.y = 0;
|
||||
#if 0
|
||||
if (pos!=get_pos())
|
||||
set_pos(pos);
|
||||
#else
|
||||
if (pos!=get_pos())
|
||||
if (pos != get_pos())
|
||||
set_global_pos(pos);
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Popup::set_as_minsize() {
|
||||
|
||||
Size2 total_minsize;
|
||||
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
|
||||
Control *c=get_child(i)->cast_to<Control>();
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c)
|
||||
continue;
|
||||
if (c->is_hidden())
|
||||
|
|
@ -108,10 +100,10 @@ void Popup::set_as_minsize() {
|
|||
|
||||
Size2 minsize = c->get_combined_minimum_size();
|
||||
|
||||
for(int j=0;j<2;j++) {
|
||||
for (int j = 0; j < 2; j++) {
|
||||
|
||||
Margin m_beg = Margin(0+j);
|
||||
Margin m_end = Margin(2+j);
|
||||
Margin m_beg = Margin(0 + j);
|
||||
Margin m_end = Margin(2 + j);
|
||||
|
||||
float margin_begin = c->get_margin(m_beg);
|
||||
float margin_end = c->get_margin(m_end);
|
||||
|
|
@ -119,29 +111,25 @@ void Popup::set_as_minsize() {
|
|||
AnchorType anchor_end = c->get_anchor(m_end);
|
||||
|
||||
if (anchor_begin == ANCHOR_BEGIN)
|
||||
minsize[j]+=margin_begin;
|
||||
minsize[j] += margin_begin;
|
||||
if (anchor_end == ANCHOR_END)
|
||||
minsize[j]+=margin_end;
|
||||
|
||||
minsize[j] += margin_end;
|
||||
}
|
||||
|
||||
total_minsize.width = MAX( total_minsize.width, minsize.width );
|
||||
total_minsize.height = MAX( total_minsize.height, minsize.height );
|
||||
total_minsize.width = MAX(total_minsize.width, minsize.width);
|
||||
total_minsize.height = MAX(total_minsize.height, minsize.height);
|
||||
}
|
||||
|
||||
set_size(total_minsize);
|
||||
|
||||
}
|
||||
|
||||
void Popup::popup_centered_minsize(const Size2 &p_minsize) {
|
||||
|
||||
void Popup::popup_centered_minsize(const Size2& p_minsize) {
|
||||
Size2 total_minsize = p_minsize;
|
||||
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
|
||||
Size2 total_minsize=p_minsize;
|
||||
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
|
||||
Control *c=get_child(i)->cast_to<Control>();
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c)
|
||||
continue;
|
||||
if (c->is_hidden())
|
||||
|
|
@ -149,10 +137,10 @@ void Popup::popup_centered_minsize(const Size2& p_minsize) {
|
|||
|
||||
Size2 minsize = c->get_combined_minimum_size();
|
||||
|
||||
for(int j=0;j<2;j++) {
|
||||
for (int j = 0; j < 2; j++) {
|
||||
|
||||
Margin m_beg = Margin(0+j);
|
||||
Margin m_end = Margin(2+j);
|
||||
Margin m_beg = Margin(0 + j);
|
||||
Margin m_end = Margin(2 + j);
|
||||
|
||||
float margin_begin = c->get_margin(m_beg);
|
||||
float margin_end = c->get_margin(m_end);
|
||||
|
|
@ -160,33 +148,30 @@ void Popup::popup_centered_minsize(const Size2& p_minsize) {
|
|||
AnchorType anchor_end = c->get_anchor(m_end);
|
||||
|
||||
if (anchor_begin == ANCHOR_BEGIN)
|
||||
minsize[j]+=margin_begin;
|
||||
minsize[j] += margin_begin;
|
||||
if (anchor_end == ANCHOR_END)
|
||||
minsize[j]+=margin_end;
|
||||
|
||||
minsize[j] += margin_end;
|
||||
}
|
||||
|
||||
total_minsize.width = MAX( total_minsize.width, minsize.width );
|
||||
total_minsize.height = MAX( total_minsize.height, minsize.height );
|
||||
total_minsize.width = MAX(total_minsize.width, minsize.width);
|
||||
total_minsize.height = MAX(total_minsize.height, minsize.height);
|
||||
}
|
||||
|
||||
|
||||
popup_centered( total_minsize );
|
||||
popped_up=true;
|
||||
|
||||
popup_centered(total_minsize);
|
||||
popped_up = true;
|
||||
}
|
||||
|
||||
void Popup::popup_centered(const Size2& p_size) {
|
||||
void Popup::popup_centered(const Size2 &p_size) {
|
||||
|
||||
Point2 window_size = get_viewport_rect().size;
|
||||
|
||||
emit_signal("about_to_show");
|
||||
Rect2 rect;
|
||||
rect.size = p_size==Size2()?get_size():p_size;
|
||||
rect.size = p_size == Size2() ? get_size() : p_size;
|
||||
|
||||
rect.pos = ((window_size-rect.size)/2.0).floor();
|
||||
set_pos( rect.pos );
|
||||
set_size( rect.size );
|
||||
rect.pos = ((window_size - rect.size) / 2.0).floor();
|
||||
set_pos(rect.pos);
|
||||
set_size(rect.size);
|
||||
|
||||
show_modal(exclusive);
|
||||
_fix_size();
|
||||
|
|
@ -197,21 +182,19 @@ void Popup::popup_centered(const Size2& p_size) {
|
|||
|
||||
_post_popup();
|
||||
notification(NOTIFICATION_POST_POPUP);
|
||||
popped_up=true;
|
||||
popped_up = true;
|
||||
}
|
||||
|
||||
void Popup::popup_centered_ratio(float p_screen_ratio) {
|
||||
|
||||
|
||||
|
||||
emit_signal("about_to_show");
|
||||
|
||||
Rect2 rect;
|
||||
Point2 window_size = get_viewport_rect().size;
|
||||
rect.size = (window_size * p_screen_ratio).floor();
|
||||
rect.pos = ((window_size-rect.size)/2.0).floor();
|
||||
set_pos( rect.pos );
|
||||
set_size( rect.size );
|
||||
rect.pos = ((window_size - rect.size) / 2.0).floor();
|
||||
set_pos(rect.pos);
|
||||
set_size(rect.size);
|
||||
|
||||
show_modal(exclusive);
|
||||
_fix_size();
|
||||
|
|
@ -222,8 +205,7 @@ void Popup::popup_centered_ratio(float p_screen_ratio) {
|
|||
|
||||
_post_popup();
|
||||
notification(NOTIFICATION_POST_POPUP);
|
||||
popped_up=true;
|
||||
|
||||
popped_up = true;
|
||||
}
|
||||
|
||||
void Popup::popup() {
|
||||
|
|
@ -231,7 +213,6 @@ void Popup::popup() {
|
|||
emit_signal("about_to_show");
|
||||
show_modal(exclusive);
|
||||
|
||||
|
||||
_fix_size();
|
||||
|
||||
Control *focusable = find_next_valid_focus();
|
||||
|
|
@ -241,42 +222,39 @@ void Popup::popup() {
|
|||
|
||||
_post_popup();
|
||||
notification(NOTIFICATION_POST_POPUP);
|
||||
popped_up=true;
|
||||
popped_up = true;
|
||||
}
|
||||
|
||||
void Popup::set_exclusive(bool p_exclusive) {
|
||||
|
||||
exclusive=p_exclusive;
|
||||
exclusive = p_exclusive;
|
||||
}
|
||||
|
||||
bool Popup::is_exclusive() const {
|
||||
bool Popup::is_exclusive() const {
|
||||
|
||||
return exclusive;
|
||||
}
|
||||
|
||||
|
||||
void Popup::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("popup_centered","size"),&Popup::popup_centered,DEFVAL(Size2()));
|
||||
ObjectTypeDB::bind_method(_MD("popup_centered_ratio","ratio"),&Popup::popup_centered_ratio,DEFVAL(0.75));
|
||||
ObjectTypeDB::bind_method(_MD("popup_centered_minsize","minsize"),&Popup::popup_centered_minsize,DEFVAL(Size2()));
|
||||
ObjectTypeDB::bind_method(_MD("popup"),&Popup::popup);
|
||||
ObjectTypeDB::bind_method(_MD("set_exclusive","enable"),&Popup::set_exclusive);
|
||||
ObjectTypeDB::bind_method(_MD("is_exclusive"),&Popup::is_exclusive);
|
||||
ADD_SIGNAL( MethodInfo("about_to_show") );
|
||||
ADD_SIGNAL( MethodInfo("popup_hide") );
|
||||
ADD_PROPERTY( PropertyInfo( Variant::BOOL, "popup/exclusive"), _SCS("set_exclusive"),_SCS("is_exclusive") );
|
||||
ObjectTypeDB::bind_method(_MD("popup_centered", "size"), &Popup::popup_centered, DEFVAL(Size2()));
|
||||
ObjectTypeDB::bind_method(_MD("popup_centered_ratio", "ratio"), &Popup::popup_centered_ratio, DEFVAL(0.75));
|
||||
ObjectTypeDB::bind_method(_MD("popup_centered_minsize", "minsize"), &Popup::popup_centered_minsize, DEFVAL(Size2()));
|
||||
ObjectTypeDB::bind_method(_MD("popup"), &Popup::popup);
|
||||
ObjectTypeDB::bind_method(_MD("set_exclusive", "enable"), &Popup::set_exclusive);
|
||||
ObjectTypeDB::bind_method(_MD("is_exclusive"), &Popup::is_exclusive);
|
||||
ADD_SIGNAL(MethodInfo("about_to_show"));
|
||||
ADD_SIGNAL(MethodInfo("popup_hide"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "popup/exclusive"), _SCS("set_exclusive"), _SCS("is_exclusive"));
|
||||
BIND_CONSTANT(NOTIFICATION_POST_POPUP);
|
||||
BIND_CONSTANT(NOTIFICATION_POPUP_HIDE);
|
||||
|
||||
|
||||
}
|
||||
|
||||
Popup::Popup() {
|
||||
|
||||
set_as_toplevel(true);
|
||||
exclusive=false;
|
||||
popped_up=false;
|
||||
exclusive = false;
|
||||
popped_up = false;
|
||||
hide();
|
||||
}
|
||||
|
||||
|
|
@ -289,9 +267,7 @@ String Popup::get_configuration_warning() const {
|
|||
return String();
|
||||
}
|
||||
|
||||
Popup::~Popup()
|
||||
{
|
||||
|
||||
Popup::~Popup() {
|
||||
}
|
||||
|
||||
void PopupPanel::set_child_rect(Control *p_child) {
|
||||
|
|
@ -299,21 +275,18 @@ void PopupPanel::set_child_rect(Control *p_child) {
|
|||
|
||||
Ref<StyleBox> p = get_stylebox("panel");
|
||||
p_child->set_area_as_parent_rect();
|
||||
for(int i=0;i<4;i++) {
|
||||
p_child->set_margin(Margin(i),p->get_margin(Margin(i)));
|
||||
for (int i = 0; i < 4; i++) {
|
||||
p_child->set_margin(Margin(i), p->get_margin(Margin(i)));
|
||||
}
|
||||
}
|
||||
|
||||
void PopupPanel::_notification(int p_what) {
|
||||
|
||||
if (p_what == NOTIFICATION_DRAW) {
|
||||
|
||||
if (p_what==NOTIFICATION_DRAW) {
|
||||
|
||||
get_stylebox("panel")->draw(get_canvas_item(),Rect2(Point2(),get_size()));
|
||||
get_stylebox("panel")->draw(get_canvas_item(), Rect2(Point2(), get_size()));
|
||||
}
|
||||
}
|
||||
|
||||
PopupPanel::PopupPanel() {
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,32 +36,31 @@
|
|||
*/
|
||||
class Popup : public Control {
|
||||
|
||||
OBJ_TYPE( Popup, Control );
|
||||
OBJ_TYPE(Popup, Control);
|
||||
|
||||
bool exclusive;
|
||||
bool popped_up;
|
||||
|
||||
protected:
|
||||
|
||||
virtual void _post_popup() {}
|
||||
|
||||
void _input_event(InputEvent p_event);
|
||||
void _notification(int p_what);
|
||||
void _fix_size();
|
||||
static void _bind_methods();
|
||||
public:
|
||||
|
||||
public:
|
||||
enum {
|
||||
NOTIFICATION_POST_POPUP=80,
|
||||
NOTIFICATION_POPUP_HIDE=81
|
||||
NOTIFICATION_POST_POPUP = 80,
|
||||
NOTIFICATION_POPUP_HIDE = 81
|
||||
};
|
||||
|
||||
void set_exclusive(bool p_exclusive);
|
||||
bool is_exclusive() const;
|
||||
|
||||
void popup_centered_ratio(float p_screen_ratio=0.75);
|
||||
void popup_centered(const Size2& p_size=Size2());
|
||||
void popup_centered_minsize(const Size2& p_minsize=Size2());
|
||||
void popup_centered_ratio(float p_screen_ratio = 0.75);
|
||||
void popup_centered(const Size2 &p_size = Size2());
|
||||
void popup_centered_minsize(const Size2 &p_minsize = Size2());
|
||||
void set_as_minsize();
|
||||
virtual void popup();
|
||||
|
||||
|
|
@ -69,23 +68,18 @@ public:
|
|||
|
||||
Popup();
|
||||
~Popup();
|
||||
|
||||
};
|
||||
|
||||
class PopupPanel : public Popup {
|
||||
|
||||
OBJ_TYPE(PopupPanel,Popup);
|
||||
|
||||
OBJ_TYPE(PopupPanel, Popup);
|
||||
|
||||
protected:
|
||||
|
||||
void _notification(int p_what);
|
||||
public:
|
||||
|
||||
public:
|
||||
void set_child_rect(Control *p_child);
|
||||
PopupPanel();
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -35,11 +35,9 @@
|
|||
@author Juan Linietsky <reduzio@gmail.com>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
class PopupMenu : public Popup {
|
||||
|
||||
OBJ_TYPE(PopupMenu, Popup );
|
||||
OBJ_TYPE(PopupMenu, Popup);
|
||||
|
||||
struct Item {
|
||||
Ref<Texture> icon;
|
||||
|
|
@ -56,10 +54,16 @@ class PopupMenu : public Popup {
|
|||
int _ofs_cache;
|
||||
Ref<ShortCut> shortcut;
|
||||
|
||||
Item() { checked=false; checkable=false; separator=false; accel=0; disabled=false; _ofs_cache=0; }
|
||||
Item() {
|
||||
checked = false;
|
||||
checkable = false;
|
||||
separator = false;
|
||||
accel = 0;
|
||||
disabled = false;
|
||||
_ofs_cache = 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Timer *submenu_timer;
|
||||
List<Rect2> autohide_areas;
|
||||
Vector<Item> items;
|
||||
|
|
@ -67,7 +71,7 @@ class PopupMenu : public Popup {
|
|||
int submenu_over;
|
||||
Rect2 parent_rect;
|
||||
String _get_accel_text(int p_item) const;
|
||||
int _get_mouse_over(const Point2& p_over) const;
|
||||
int _get_mouse_over(const Point2 &p_over) const;
|
||||
virtual Size2 get_minimum_size() const;
|
||||
void _input_event(const InputEvent &p_event);
|
||||
void _activate_submenu(int over);
|
||||
|
|
@ -78,44 +82,44 @@ class PopupMenu : public Popup {
|
|||
Vector2 moved;
|
||||
|
||||
Array _get_items() const;
|
||||
void _set_items(const Array& p_items);
|
||||
void _set_items(const Array &p_items);
|
||||
|
||||
Map< Ref<ShortCut>, int> shortcut_refcount;
|
||||
Map<Ref<ShortCut>, int> shortcut_refcount;
|
||||
|
||||
void _ref_shortcut(Ref<ShortCut> p_sc);
|
||||
void _unref_shortcut( Ref<ShortCut> p_sc);
|
||||
void _unref_shortcut(Ref<ShortCut> p_sc);
|
||||
|
||||
protected:
|
||||
virtual bool has_point(const Point2 &p_point) const;
|
||||
|
||||
virtual bool has_point(const Point2& p_point) const;
|
||||
|
||||
friend class MenuButton;
|
||||
friend class MenuButton;
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
void add_icon_item(const Ref<Texture> &p_icon, const String &p_label, int p_ID = -1, uint32_t p_accel = 0);
|
||||
void add_item(const String &p_label, int p_ID = -1, uint32_t p_accel = 0);
|
||||
void add_icon_check_item(const Ref<Texture> &p_icon, const String &p_label, int p_ID = -1, uint32_t p_accel = 0);
|
||||
void add_check_item(const String &p_label, int p_ID = -1, uint32_t p_accel = 0);
|
||||
void add_submenu_item(const String &p_label, const String &p_submenu, int p_ID = -1);
|
||||
|
||||
void add_icon_item(const Ref<Texture>& p_icon,const String& p_label,int p_ID=-1,uint32_t p_accel=0);
|
||||
void add_item(const String& p_label,int p_ID=-1,uint32_t p_accel=0);
|
||||
void add_icon_check_item(const Ref<Texture>& p_icon,const String& p_label,int p_ID=-1,uint32_t p_accel=0);
|
||||
void add_check_item(const String& p_label,int p_ID=-1,uint32_t p_accel=0);
|
||||
void add_submenu_item(const String& p_label,const String& p_submenu, int p_ID=-1);
|
||||
void add_icon_shortcut(const Ref<Texture> &p_icon, const Ref<ShortCut> &p_shortcut, int p_ID = -1);
|
||||
void add_shortcut(const Ref<ShortCut> &p_shortcut, int p_ID = -1);
|
||||
void add_icon_check_shortcut(const Ref<Texture> &p_icon, const Ref<ShortCut> &p_shortcut, int p_ID = -1);
|
||||
void add_check_shortcut(const Ref<ShortCut> &p_shortcut, int p_ID = -1);
|
||||
|
||||
void add_icon_shortcut(const Ref<Texture>& p_icon,const Ref<ShortCut>& p_shortcut,int p_ID=-1);
|
||||
void add_shortcut(const Ref<ShortCut>& p_shortcut,int p_ID=-1);
|
||||
void add_icon_check_shortcut(const Ref<Texture>& p_icon,const Ref<ShortCut>& p_shortcut,int p_ID=-1);
|
||||
void add_check_shortcut(const Ref<ShortCut>& p_shortcut,int p_ID=-1);
|
||||
|
||||
void set_item_text(int p_idx,const String& p_text);
|
||||
void set_item_icon(int p_idx,const Ref<Texture>& p_icon);
|
||||
void set_item_checked(int p_idx,bool p_checked);
|
||||
void set_item_ID(int p_idx,int p_ID);
|
||||
void set_item_accelerator(int p_idx,uint32_t p_accel);
|
||||
void set_item_metadata(int p_idx,const Variant& p_meta);
|
||||
void set_item_disabled(int p_idx,bool p_disabled);
|
||||
void set_item_submenu(int p_idx, const String& p_submenu);
|
||||
void set_item_text(int p_idx, const String &p_text);
|
||||
void set_item_icon(int p_idx, const Ref<Texture> &p_icon);
|
||||
void set_item_checked(int p_idx, bool p_checked);
|
||||
void set_item_ID(int p_idx, int p_ID);
|
||||
void set_item_accelerator(int p_idx, uint32_t p_accel);
|
||||
void set_item_metadata(int p_idx, const Variant &p_meta);
|
||||
void set_item_disabled(int p_idx, bool p_disabled);
|
||||
void set_item_submenu(int p_idx, const String &p_submenu);
|
||||
void set_item_as_separator(int p_idx, bool p_separator);
|
||||
void set_item_as_checkable(int p_idx, bool p_checkable);
|
||||
void set_item_tooltip(int p_idx,const String& p_tooltip);
|
||||
void set_item_shortcut(int p_idx, const Ref<ShortCut>& p_shortcut);
|
||||
void set_item_tooltip(int p_idx, const String &p_tooltip);
|
||||
void set_item_shortcut(int p_idx, const Ref<ShortCut> &p_shortcut);
|
||||
|
||||
void toggle_item_checked(int p_idx);
|
||||
|
||||
|
|
@ -135,7 +139,7 @@ public:
|
|||
|
||||
int get_item_count() const;
|
||||
|
||||
bool activate_item_by_event(const InputEvent& p_event);
|
||||
bool activate_item_by_event(const InputEvent &p_event);
|
||||
void activate_item(int p_item);
|
||||
|
||||
void remove_item(int p_idx);
|
||||
|
|
@ -144,13 +148,13 @@ public:
|
|||
|
||||
void clear();
|
||||
|
||||
void set_parent_rect(const Rect2& p_rect);
|
||||
void set_parent_rect(const Rect2 &p_rect);
|
||||
|
||||
virtual String get_tooltip(const Point2& p_pos) const;
|
||||
virtual String get_tooltip(const Point2 &p_pos) const;
|
||||
|
||||
virtual void get_translatable_strings(List<String> *p_strings) const;
|
||||
|
||||
void add_autohide_area(const Rect2& p_area);
|
||||
void add_autohide_area(const Rect2 &p_area);
|
||||
void clear_autohide_areas();
|
||||
|
||||
void set_invalidate_click_until_motion();
|
||||
|
|
@ -159,7 +163,6 @@ public:
|
|||
|
||||
PopupMenu();
|
||||
~PopupMenu();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -28,67 +28,63 @@
|
|||
/*************************************************************************/
|
||||
#include "progress_bar.h"
|
||||
|
||||
|
||||
Size2 ProgressBar::get_minimum_size() const {
|
||||
|
||||
Ref<StyleBox> bg = get_stylebox("bg");
|
||||
Ref<Font> font = get_font("font");
|
||||
|
||||
Size2 ms=bg->get_minimum_size()+bg->get_center_size();
|
||||
Size2 ms = bg->get_minimum_size() + bg->get_center_size();
|
||||
if (percent_visible) {
|
||||
ms.height=MAX(ms.height,bg->get_minimum_size().height+font->get_height());
|
||||
ms.height = MAX(ms.height, bg->get_minimum_size().height + font->get_height());
|
||||
}
|
||||
return ms;
|
||||
}
|
||||
|
||||
|
||||
void ProgressBar::_notification(int p_what) {
|
||||
|
||||
|
||||
if (p_what==NOTIFICATION_DRAW) {
|
||||
if (p_what == NOTIFICATION_DRAW) {
|
||||
|
||||
Ref<StyleBox> bg = get_stylebox("bg");
|
||||
Ref<StyleBox> fg = get_stylebox("fg");
|
||||
Ref<Font> font = get_font("font");
|
||||
Color font_color=get_color("font_color");
|
||||
Color font_color = get_color("font_color");
|
||||
|
||||
draw_style_box(bg,Rect2(Point2(),get_size()));
|
||||
draw_style_box(bg, Rect2(Point2(), get_size()));
|
||||
float r = get_unit_value();
|
||||
int mp = fg->get_minimum_size().width;
|
||||
int p = r*get_size().width-mp;
|
||||
if (p>0) {
|
||||
int p = r * get_size().width - mp;
|
||||
if (p > 0) {
|
||||
|
||||
draw_style_box(fg,Rect2(Point2(),Size2(p+fg->get_minimum_size().width,get_size().height)));
|
||||
draw_style_box(fg, Rect2(Point2(), Size2(p + fg->get_minimum_size().width, get_size().height)));
|
||||
}
|
||||
|
||||
if (percent_visible) {
|
||||
String txt=itos(int(get_unit_value()*100))+"%";
|
||||
font->draw_halign(get_canvas_item(),Point2(0,font->get_ascent()+(get_size().height-font->get_height())/2),HALIGN_CENTER,get_size().width,txt,font_color);
|
||||
String txt = itos(int(get_unit_value() * 100)) + "%";
|
||||
font->draw_halign(get_canvas_item(), Point2(0, font->get_ascent() + (get_size().height - font->get_height()) / 2), HALIGN_CENTER, get_size().width, txt, font_color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ProgressBar::set_percent_visible(bool p_visible) {
|
||||
|
||||
percent_visible=p_visible;
|
||||
percent_visible = p_visible;
|
||||
update();
|
||||
}
|
||||
|
||||
bool ProgressBar::is_percent_visible() const{
|
||||
bool ProgressBar::is_percent_visible() const {
|
||||
|
||||
return percent_visible;
|
||||
}
|
||||
|
||||
void ProgressBar::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_percent_visible","visible"),&ProgressBar::set_percent_visible);
|
||||
ObjectTypeDB::bind_method(_MD("is_percent_visible"),&ProgressBar::is_percent_visible);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL,"percent/visible"),_SCS("set_percent_visible"),_SCS("is_percent_visible"));
|
||||
ObjectTypeDB::bind_method(_MD("set_percent_visible", "visible"), &ProgressBar::set_percent_visible);
|
||||
ObjectTypeDB::bind_method(_MD("is_percent_visible"), &ProgressBar::is_percent_visible);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "percent/visible"), _SCS("set_percent_visible"), _SCS("is_percent_visible"));
|
||||
}
|
||||
|
||||
ProgressBar::ProgressBar() {
|
||||
|
||||
set_v_size_flags(0);
|
||||
percent_visible=true;
|
||||
percent_visible = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,15 +33,15 @@
|
|||
|
||||
class ProgressBar : public Range {
|
||||
|
||||
OBJ_TYPE( ProgressBar, Range );
|
||||
OBJ_TYPE(ProgressBar, Range);
|
||||
|
||||
bool percent_visible;
|
||||
protected:
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
public:
|
||||
|
||||
public:
|
||||
void set_percent_visible(bool p_visible);
|
||||
bool is_percent_visible() const;
|
||||
|
||||
|
|
|
|||
|
|
@ -28,20 +28,18 @@
|
|||
/*************************************************************************/
|
||||
#include "range.h"
|
||||
|
||||
|
||||
|
||||
void Range::_value_changed_notify() {
|
||||
|
||||
_value_changed(shared->val);
|
||||
emit_signal("value_changed",shared->val);
|
||||
emit_signal("value_changed", shared->val);
|
||||
update();
|
||||
_change_notify("range/value");
|
||||
}
|
||||
|
||||
void Range::Shared::emit_value_changed() {
|
||||
|
||||
for (Set<Range*>::Element *E=owners.front();E;E=E->next()) {
|
||||
Range *r=E->get();
|
||||
for (Set<Range *>::Element *E = owners.front(); E; E = E->next()) {
|
||||
Range *r = E->get();
|
||||
if (!r->is_inside_tree())
|
||||
continue;
|
||||
r->_value_changed_notify();
|
||||
|
|
@ -50,65 +48,62 @@ void Range::Shared::emit_value_changed() {
|
|||
|
||||
void Range::_changed_notify(const char *p_what) {
|
||||
|
||||
emit_signal("changed",shared->val);
|
||||
emit_signal("changed", shared->val);
|
||||
update();
|
||||
_change_notify(p_what);
|
||||
}
|
||||
|
||||
void Range::Shared::emit_changed(const char *p_what) {
|
||||
|
||||
for (Set<Range*>::Element *E=owners.front();E;E=E->next()) {
|
||||
Range *r=E->get();
|
||||
for (Set<Range *>::Element *E = owners.front(); E; E = E->next()) {
|
||||
Range *r = E->get();
|
||||
if (!r->is_inside_tree())
|
||||
continue;
|
||||
r->_changed_notify(p_what);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Range::set_val(double p_val) {
|
||||
|
||||
if(_rounded_values){
|
||||
if (_rounded_values) {
|
||||
p_val = Math::round(p_val);
|
||||
}
|
||||
|
||||
if (p_val>shared->max-shared->page)
|
||||
p_val=shared->max-shared->page;
|
||||
if (p_val > shared->max - shared->page)
|
||||
p_val = shared->max - shared->page;
|
||||
|
||||
if (p_val<shared->min)
|
||||
p_val=shared->min;
|
||||
if (p_val < shared->min)
|
||||
p_val = shared->min;
|
||||
|
||||
if (shared->val==p_val)
|
||||
if (shared->val == p_val)
|
||||
return;
|
||||
|
||||
shared->val=p_val;
|
||||
shared->val = p_val;
|
||||
|
||||
shared->emit_value_changed();
|
||||
}
|
||||
void Range::set_min(double p_min) {
|
||||
|
||||
shared->min=p_min;
|
||||
shared->min = p_min;
|
||||
set_val(shared->val);
|
||||
|
||||
shared->emit_changed("range/min");
|
||||
}
|
||||
void Range::set_max(double p_max) {
|
||||
|
||||
shared->max=p_max;
|
||||
shared->max = p_max;
|
||||
set_val(shared->val);
|
||||
|
||||
shared->emit_changed("range/max");
|
||||
|
||||
}
|
||||
void Range::set_step(double p_step) {
|
||||
|
||||
shared->step=p_step;
|
||||
shared->step = p_step;
|
||||
shared->emit_changed("range/step");
|
||||
|
||||
}
|
||||
void Range::set_page(double p_page) {
|
||||
|
||||
shared->page=p_page;
|
||||
shared->page = p_page;
|
||||
set_val(shared->val);
|
||||
|
||||
shared->emit_changed("range/page");
|
||||
|
|
@ -139,11 +134,11 @@ void Range::set_unit_value(double p_value) {
|
|||
|
||||
double v;
|
||||
|
||||
if (shared->exp_unit_value && get_min()>0) {
|
||||
if (shared->exp_unit_value && get_min() > 0) {
|
||||
|
||||
double exp_min = Math::log(get_min())/Math::log(2);
|
||||
double exp_max = Math::log(get_max())/Math::log(2);
|
||||
v = Math::pow(2,exp_min+(exp_max-exp_min)*p_value);
|
||||
double exp_min = Math::log(get_min()) / Math::log(2);
|
||||
double exp_max = Math::log(get_max()) / Math::log(2);
|
||||
v = Math::pow(2, exp_min + (exp_max - exp_min) * p_value);
|
||||
} else {
|
||||
|
||||
double percent = (get_max() - get_min()) * p_value;
|
||||
|
|
@ -154,15 +149,15 @@ void Range::set_unit_value(double p_value) {
|
|||
v = percent + get_min();
|
||||
}
|
||||
}
|
||||
set_val( v );
|
||||
set_val(v);
|
||||
}
|
||||
double Range::get_unit_value() const {
|
||||
|
||||
if (shared->exp_unit_value && get_min()>0) {
|
||||
if (shared->exp_unit_value && get_min() > 0) {
|
||||
|
||||
double exp_min = Math::log(get_min())/Math::log(2);
|
||||
double exp_max = Math::log(get_max())/Math::log(2);
|
||||
double v = Math::log(get_val())/Math::log(2);
|
||||
double exp_min = Math::log(get_min()) / Math::log(2);
|
||||
double exp_max = Math::log(get_max()) / Math::log(2);
|
||||
double v = Math::log(get_val()) / Math::log(2);
|
||||
|
||||
return (v - exp_min) / (exp_max - exp_min);
|
||||
|
||||
|
|
@ -174,7 +169,7 @@ double Range::get_unit_value() const {
|
|||
|
||||
void Range::_share(Node *p_range) {
|
||||
|
||||
Range * r = p_range->cast_to<Range>();
|
||||
Range *r = p_range->cast_to<Range>();
|
||||
ERR_FAIL_COND(!r);
|
||||
share(r);
|
||||
}
|
||||
|
|
@ -190,71 +185,69 @@ void Range::share(Range *p_range) {
|
|||
|
||||
void Range::unshare() {
|
||||
|
||||
Shared * nshared = memnew(Shared);
|
||||
nshared->min=shared->min;
|
||||
nshared->max=shared->max;
|
||||
nshared->val=shared->val;
|
||||
nshared->step=shared->step;
|
||||
nshared->page=shared->page;
|
||||
Shared *nshared = memnew(Shared);
|
||||
nshared->min = shared->min;
|
||||
nshared->max = shared->max;
|
||||
nshared->val = shared->val;
|
||||
nshared->step = shared->step;
|
||||
nshared->page = shared->page;
|
||||
_unref_shared();
|
||||
_ref_shared(nshared);
|
||||
}
|
||||
|
||||
void Range::_ref_shared(Shared *p_shared) {
|
||||
|
||||
if (shared && p_shared==shared)
|
||||
if (shared && p_shared == shared)
|
||||
return;
|
||||
|
||||
_unref_shared();
|
||||
shared=p_shared;
|
||||
shared = p_shared;
|
||||
shared->owners.insert(this);
|
||||
}
|
||||
|
||||
|
||||
void Range::_unref_shared() {
|
||||
|
||||
shared->owners.erase(this);
|
||||
if (shared->owners.size()==0) {
|
||||
if (shared->owners.size() == 0) {
|
||||
memdelete(shared);
|
||||
shared=NULL;
|
||||
shared = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void Range::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("get_val"),&Range::get_val);
|
||||
ObjectTypeDB::bind_method(_MD("get_value"),&Range::get_val);
|
||||
ObjectTypeDB::bind_method(_MD("get_min"),&Range::get_min);
|
||||
ObjectTypeDB::bind_method(_MD("get_max"),&Range::get_max);
|
||||
ObjectTypeDB::bind_method(_MD("get_step"),&Range::get_step);
|
||||
ObjectTypeDB::bind_method(_MD("get_page"),&Range::get_page);
|
||||
ObjectTypeDB::bind_method(_MD("get_unit_value"),&Range::get_unit_value);
|
||||
ObjectTypeDB::bind_method(_MD("set_val","value"),&Range::set_val);
|
||||
ObjectTypeDB::bind_method(_MD("set_value","value"),&Range::set_val);
|
||||
ObjectTypeDB::bind_method(_MD("set_min","minimum"),&Range::set_min);
|
||||
ObjectTypeDB::bind_method(_MD("set_max","maximum"),&Range::set_max);
|
||||
ObjectTypeDB::bind_method(_MD("set_step","step"),&Range::set_step);
|
||||
ObjectTypeDB::bind_method(_MD("set_page","pagesize"),&Range::set_page);
|
||||
ObjectTypeDB::bind_method(_MD("set_unit_value","value"),&Range::set_unit_value);
|
||||
ObjectTypeDB::bind_method(_MD("set_rounded_values","enabled"),&Range::set_rounded_values);
|
||||
ObjectTypeDB::bind_method(_MD("is_rounded_values"),&Range::is_rounded_values);
|
||||
ObjectTypeDB::bind_method(_MD("set_exp_unit_value","enabled"),&Range::set_exp_unit_value);
|
||||
ObjectTypeDB::bind_method(_MD("is_unit_value_exp"),&Range::is_unit_value_exp);
|
||||
ObjectTypeDB::bind_method(_MD("get_val"), &Range::get_val);
|
||||
ObjectTypeDB::bind_method(_MD("get_value"), &Range::get_val);
|
||||
ObjectTypeDB::bind_method(_MD("get_min"), &Range::get_min);
|
||||
ObjectTypeDB::bind_method(_MD("get_max"), &Range::get_max);
|
||||
ObjectTypeDB::bind_method(_MD("get_step"), &Range::get_step);
|
||||
ObjectTypeDB::bind_method(_MD("get_page"), &Range::get_page);
|
||||
ObjectTypeDB::bind_method(_MD("get_unit_value"), &Range::get_unit_value);
|
||||
ObjectTypeDB::bind_method(_MD("set_val", "value"), &Range::set_val);
|
||||
ObjectTypeDB::bind_method(_MD("set_value", "value"), &Range::set_val);
|
||||
ObjectTypeDB::bind_method(_MD("set_min", "minimum"), &Range::set_min);
|
||||
ObjectTypeDB::bind_method(_MD("set_max", "maximum"), &Range::set_max);
|
||||
ObjectTypeDB::bind_method(_MD("set_step", "step"), &Range::set_step);
|
||||
ObjectTypeDB::bind_method(_MD("set_page", "pagesize"), &Range::set_page);
|
||||
ObjectTypeDB::bind_method(_MD("set_unit_value", "value"), &Range::set_unit_value);
|
||||
ObjectTypeDB::bind_method(_MD("set_rounded_values", "enabled"), &Range::set_rounded_values);
|
||||
ObjectTypeDB::bind_method(_MD("is_rounded_values"), &Range::is_rounded_values);
|
||||
ObjectTypeDB::bind_method(_MD("set_exp_unit_value", "enabled"), &Range::set_exp_unit_value);
|
||||
ObjectTypeDB::bind_method(_MD("is_unit_value_exp"), &Range::is_unit_value_exp);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("share","with"),&Range::_share);
|
||||
ObjectTypeDB::bind_method(_MD("unshare"),&Range::unshare);
|
||||
ObjectTypeDB::bind_method(_MD("share", "with"), &Range::_share);
|
||||
ObjectTypeDB::bind_method(_MD("unshare"), &Range::unshare);
|
||||
|
||||
ADD_SIGNAL( MethodInfo("value_changed", PropertyInfo(Variant::REAL,"value")));
|
||||
ADD_SIGNAL( MethodInfo("changed"));
|
||||
|
||||
ADD_PROPERTY( PropertyInfo( Variant::REAL, "range/min" ), _SCS("set_min"), _SCS("get_min") );
|
||||
ADD_PROPERTY( PropertyInfo( Variant::REAL, "range/max" ), _SCS("set_max"), _SCS("get_max") );
|
||||
ADD_PROPERTY( PropertyInfo( Variant::REAL, "range/step" ), _SCS("set_step"), _SCS("get_step") );
|
||||
ADD_PROPERTY( PropertyInfo( Variant::REAL, "range/page" ), _SCS("set_page"), _SCS("get_page") );
|
||||
ADD_PROPERTY( PropertyInfo( Variant::REAL, "range/value" ), _SCS("set_val"), _SCS("get_val") );
|
||||
ADD_PROPERTY( PropertyInfo( Variant::BOOL, "range/exp_edit" ), _SCS("set_exp_unit_value"), _SCS("is_unit_value_exp") );
|
||||
ADD_PROPERTY( PropertyInfo( Variant::BOOL, "range/rounded" ), _SCS("set_rounded_values"), _SCS("is_rounded_values") );
|
||||
ADD_SIGNAL(MethodInfo("value_changed", PropertyInfo(Variant::REAL, "value")));
|
||||
ADD_SIGNAL(MethodInfo("changed"));
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "range/min"), _SCS("set_min"), _SCS("get_min"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "range/max"), _SCS("set_max"), _SCS("get_max"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "range/step"), _SCS("set_step"), _SCS("get_step"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "range/page"), _SCS("set_page"), _SCS("get_page"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "range/value"), _SCS("set_val"), _SCS("get_val"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "range/exp_edit"), _SCS("set_exp_unit_value"), _SCS("is_unit_value_exp"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "range/rounded"), _SCS("set_rounded_values"), _SCS("is_rounded_values"));
|
||||
}
|
||||
|
||||
void Range::set_rounded_values(bool p_enable) {
|
||||
|
|
@ -269,7 +262,7 @@ bool Range::is_rounded_values() const {
|
|||
|
||||
void Range::set_exp_unit_value(bool p_enable) {
|
||||
|
||||
shared->exp_unit_value=p_enable;
|
||||
shared->exp_unit_value = p_enable;
|
||||
}
|
||||
|
||||
bool Range::is_unit_value_exp() const {
|
||||
|
|
@ -277,25 +270,20 @@ bool Range::is_unit_value_exp() const {
|
|||
return shared->exp_unit_value;
|
||||
}
|
||||
|
||||
|
||||
Range::Range()
|
||||
{
|
||||
Range::Range() {
|
||||
shared = memnew(Shared);
|
||||
shared->min=0;
|
||||
shared->max=100;
|
||||
shared->val=
|
||||
shared->step=1;
|
||||
shared->page=0;
|
||||
shared->min = 0;
|
||||
shared->max = 100;
|
||||
shared->val =
|
||||
shared->step = 1;
|
||||
shared->page = 0;
|
||||
shared->owners.insert(this);
|
||||
shared->exp_unit_value=false;
|
||||
shared->exp_unit_value = false;
|
||||
|
||||
_rounded_values = false;
|
||||
}
|
||||
|
||||
|
||||
Range::~Range() {
|
||||
|
||||
_unref_shared();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -35,16 +35,15 @@
|
|||
*/
|
||||
class Range : public Control {
|
||||
|
||||
OBJ_TYPE( Range, Control );
|
||||
|
||||
OBJ_TYPE(Range, Control);
|
||||
|
||||
struct Shared {
|
||||
double val,min,max;
|
||||
double step,page;
|
||||
double val, min, max;
|
||||
double step, page;
|
||||
bool exp_unit_value;
|
||||
Set<Range*> owners;
|
||||
Set<Range *> owners;
|
||||
void emit_value_changed();
|
||||
void emit_changed(const char *p_what="");
|
||||
void emit_changed(const char *p_what = "");
|
||||
};
|
||||
|
||||
Shared *shared;
|
||||
|
|
@ -55,17 +54,16 @@ class Range : public Control {
|
|||
void _share(Node *p_range);
|
||||
|
||||
void _value_changed_notify();
|
||||
void _changed_notify(const char *p_what="");
|
||||
void _changed_notify(const char *p_what = "");
|
||||
|
||||
protected:
|
||||
|
||||
virtual void _value_changed(double) {}
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
bool _rounded_values;
|
||||
public:
|
||||
|
||||
public:
|
||||
void set_val(double p_val);
|
||||
void set_min(double p_min);
|
||||
void set_max(double p_max);
|
||||
|
|
@ -91,7 +89,6 @@ public:
|
|||
|
||||
Range();
|
||||
~Range();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -30,15 +30,14 @@
|
|||
|
||||
void ReferenceFrame::_notification(int p_what) {
|
||||
|
||||
if (p_what==NOTIFICATION_DRAW) {
|
||||
if (p_what == NOTIFICATION_DRAW) {
|
||||
|
||||
if (!is_inside_tree())
|
||||
return;
|
||||
if (get_tree()->is_editor_hint())
|
||||
draw_style_box(get_stylebox("border"),Rect2(Point2(),get_size())) ;
|
||||
draw_style_box(get_stylebox("border"), Rect2(Point2(), get_size()));
|
||||
}
|
||||
}
|
||||
|
||||
ReferenceFrame::ReferenceFrame()
|
||||
{
|
||||
ReferenceFrame::ReferenceFrame() {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,11 +33,11 @@
|
|||
|
||||
class ReferenceFrame : public Control {
|
||||
|
||||
OBJ_TYPE( ReferenceFrame, Control);
|
||||
OBJ_TYPE(ReferenceFrame, Control);
|
||||
|
||||
protected:
|
||||
|
||||
void _notification(int p_what);
|
||||
|
||||
public:
|
||||
ReferenceFrame();
|
||||
};
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -29,14 +29,13 @@
|
|||
#ifndef RICH_TEXT_LABEL_H
|
||||
#define RICH_TEXT_LABEL_H
|
||||
|
||||
|
||||
#include "scene/gui/scroll_bar.h"
|
||||
|
||||
class RichTextLabel : public Control {
|
||||
|
||||
OBJ_TYPE( RichTextLabel, Control );
|
||||
public:
|
||||
OBJ_TYPE(RichTextLabel, Control);
|
||||
|
||||
public:
|
||||
enum Align {
|
||||
|
||||
ALIGN_LEFT,
|
||||
|
|
@ -69,10 +68,9 @@ public:
|
|||
};
|
||||
|
||||
protected:
|
||||
|
||||
static void _bind_methods();
|
||||
private:
|
||||
|
||||
private:
|
||||
struct Item;
|
||||
|
||||
struct Line {
|
||||
|
|
@ -86,27 +84,37 @@ private:
|
|||
int char_count;
|
||||
int minimum_width;
|
||||
|
||||
Line() { from=NULL; char_count=0; }
|
||||
Line() {
|
||||
from = NULL;
|
||||
char_count = 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct Item {
|
||||
|
||||
int index;
|
||||
Item *parent;
|
||||
ItemType type;
|
||||
List<Item*> subitems;
|
||||
List<Item*>::Element *E;
|
||||
List<Item *> subitems;
|
||||
List<Item *>::Element *E;
|
||||
int line;
|
||||
|
||||
void _clear_children() { while (subitems.size()) { memdelete(subitems.front()->get()); subitems.pop_front(); } }
|
||||
void _clear_children() {
|
||||
while (subitems.size()) {
|
||||
memdelete(subitems.front()->get());
|
||||
subitems.pop_front();
|
||||
}
|
||||
}
|
||||
|
||||
Item() { parent=NULL; E=NULL; line=0;}
|
||||
virtual ~Item() { _clear_children(); }
|
||||
Item() {
|
||||
parent = NULL;
|
||||
E = NULL;
|
||||
line = 0;
|
||||
}
|
||||
virtual ~Item() { _clear_children(); }
|
||||
};
|
||||
|
||||
struct ItemFrame : public Item{
|
||||
struct ItemFrame : public Item {
|
||||
|
||||
int parent_line;
|
||||
bool cell;
|
||||
|
|
@ -114,71 +122,74 @@ private:
|
|||
int first_invalid_line;
|
||||
ItemFrame *parent_frame;
|
||||
|
||||
ItemFrame() { type=ITEM_FRAME; parent_frame=NULL; cell=false; parent_line=0; }
|
||||
ItemFrame() {
|
||||
type = ITEM_FRAME;
|
||||
parent_frame = NULL;
|
||||
cell = false;
|
||||
parent_line = 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct ItemText : public Item {
|
||||
|
||||
String text;
|
||||
ItemText() { type=ITEM_TEXT; }
|
||||
ItemText() { type = ITEM_TEXT; }
|
||||
};
|
||||
|
||||
struct ItemImage : public Item {
|
||||
|
||||
Ref<Texture> image;
|
||||
ItemImage() { type=ITEM_IMAGE; }
|
||||
ItemImage() { type = ITEM_IMAGE; }
|
||||
};
|
||||
|
||||
struct ItemFont : public Item {
|
||||
|
||||
Ref<Font> font;
|
||||
ItemFont() { type=ITEM_FONT; }
|
||||
ItemFont() { type = ITEM_FONT; }
|
||||
};
|
||||
|
||||
struct ItemColor : public Item {
|
||||
|
||||
Color color;
|
||||
ItemColor() { type=ITEM_COLOR; }
|
||||
ItemColor() { type = ITEM_COLOR; }
|
||||
};
|
||||
|
||||
struct ItemUnderline : public Item {
|
||||
|
||||
ItemUnderline() { type=ITEM_UNDERLINE; }
|
||||
ItemUnderline() { type = ITEM_UNDERLINE; }
|
||||
};
|
||||
|
||||
struct ItemMeta : public Item {
|
||||
|
||||
Variant meta;
|
||||
ItemMeta() { type=ITEM_META; }
|
||||
ItemMeta() { type = ITEM_META; }
|
||||
};
|
||||
|
||||
struct ItemAlign : public Item {
|
||||
|
||||
Align align;
|
||||
ItemAlign() { type=ITEM_ALIGN; }
|
||||
ItemAlign() { type = ITEM_ALIGN; }
|
||||
};
|
||||
|
||||
struct ItemIndent : public Item {
|
||||
|
||||
int level;
|
||||
ItemIndent() { type=ITEM_INDENT; }
|
||||
ItemIndent() { type = ITEM_INDENT; }
|
||||
};
|
||||
|
||||
struct ItemList : public Item {
|
||||
|
||||
ListType list_type;
|
||||
ItemList() { type=ITEM_LIST; }
|
||||
ItemList() { type = ITEM_LIST; }
|
||||
};
|
||||
|
||||
struct ItemNewline : public Item {
|
||||
|
||||
int line;
|
||||
ItemNewline() { type=ITEM_NEWLINE; }
|
||||
ItemNewline() { type = ITEM_NEWLINE; }
|
||||
};
|
||||
|
||||
|
||||
struct ItemTable : public Item{
|
||||
struct ItemTable : public Item {
|
||||
|
||||
struct Column {
|
||||
bool expand;
|
||||
|
|
@ -189,7 +200,7 @@ private:
|
|||
|
||||
Vector<Column> columns;
|
||||
int total_width;
|
||||
ItemTable() { type=ITEM_TABLE; }
|
||||
ItemTable() { type = ITEM_TABLE; }
|
||||
};
|
||||
|
||||
ItemFrame *main;
|
||||
|
|
@ -198,7 +209,6 @@ private:
|
|||
|
||||
VScrollBar *vscroll;
|
||||
|
||||
|
||||
bool scroll_visible;
|
||||
bool scroll_follow;
|
||||
bool scroll_following;
|
||||
|
|
@ -207,7 +217,6 @@ private:
|
|||
bool updating_scroll;
|
||||
int current_idx;
|
||||
|
||||
|
||||
int tab_size;
|
||||
bool underline_meta;
|
||||
|
||||
|
|
@ -216,12 +225,9 @@ private:
|
|||
void _invalidate_current_line(ItemFrame *p_frame);
|
||||
void _validate_line_caches(ItemFrame *p_frame);
|
||||
|
||||
void _add_item(Item *p_item, bool p_enter=false,bool p_ensure_newline=false);
|
||||
void _add_item(Item *p_item, bool p_enter = false, bool p_ensure_newline = false);
|
||||
void _remove_item(Item *p_item, const int p_line, const int p_subitem_line);
|
||||
|
||||
|
||||
|
||||
|
||||
struct ProcessState {
|
||||
|
||||
int line_width;
|
||||
|
|
@ -250,26 +256,23 @@ private:
|
|||
|
||||
Selection selection;
|
||||
|
||||
|
||||
int visible_characters;
|
||||
|
||||
|
||||
void _process_line(ItemFrame *p_frame,const Vector2& p_ofs,int &y, int p_width, int p_line, ProcessMode p_mode,const Ref<Font> &p_base_font,const Color &p_base_color,const Point2i& p_click_pos=Point2i(),Item **r_click_item=NULL,int *r_click_char=NULL,bool *r_outside=NULL,int p_char_count=0);
|
||||
void _find_click(ItemFrame *p_frame, const Point2i& p_click,Item **r_click_item=NULL,int *r_click_char=NULL,bool *r_outside=NULL);
|
||||
|
||||
void _process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &y, int p_width, int p_line, ProcessMode p_mode, const Ref<Font> &p_base_font, const Color &p_base_color, const Point2i &p_click_pos = Point2i(), Item **r_click_item = NULL, int *r_click_char = NULL, bool *r_outside = NULL, int p_char_count = 0);
|
||||
void _find_click(ItemFrame *p_frame, const Point2i &p_click, Item **r_click_item = NULL, int *r_click_char = NULL, bool *r_outside = NULL);
|
||||
|
||||
Ref<Font> _find_font(Item *p_item);
|
||||
int _find_margin(Item *p_item,const Ref<Font>& p_base_font);
|
||||
int _find_margin(Item *p_item, const Ref<Font> &p_base_font);
|
||||
Align _find_align(Item *p_item);
|
||||
Color _find_color(Item *p_item,const Color& p_default_color);
|
||||
Color _find_color(Item *p_item, const Color &p_default_color);
|
||||
bool _find_underline(Item *p_item);
|
||||
bool _find_meta(Item *p_item,Variant *r_meta);
|
||||
bool _find_meta(Item *p_item, Variant *r_meta);
|
||||
|
||||
void _update_scroll();
|
||||
void _scroll_changed(double);
|
||||
|
||||
void _input_event(InputEvent p_event);
|
||||
Item *_get_next_item(Item* p_item, bool p_free=false);
|
||||
Item *_get_next_item(Item *p_item, bool p_free = false);
|
||||
|
||||
bool use_bbcode;
|
||||
String bbcode;
|
||||
|
|
@ -280,21 +283,20 @@ protected:
|
|||
void _notification(int p_what);
|
||||
|
||||
public:
|
||||
|
||||
String get_text();
|
||||
void add_text(const String& p_text);
|
||||
void add_image(const Ref<Texture>& p_image);
|
||||
void add_text(const String &p_text);
|
||||
void add_image(const Ref<Texture> &p_image);
|
||||
void add_newline();
|
||||
bool remove_line(const int p_line);
|
||||
void push_font(const Ref<Font>& p_font);
|
||||
void push_color(const Color& p_color);
|
||||
void push_font(const Ref<Font> &p_font);
|
||||
void push_color(const Color &p_color);
|
||||
void push_underline();
|
||||
void push_align(Align p_align);
|
||||
void push_indent(int p_level);
|
||||
void push_list(ListType p_list);
|
||||
void push_meta(const Variant& p_data);
|
||||
void push_meta(const Variant &p_data);
|
||||
void push_table(int p_columns);
|
||||
void set_table_column_expand(int p_column, bool p_expand, int p_ratio=1);
|
||||
void set_table_column_expand(int p_column, bool p_expand, int p_ratio = 1);
|
||||
int get_current_table_column() const;
|
||||
void push_cell();
|
||||
void pop();
|
||||
|
|
@ -315,29 +317,26 @@ public:
|
|||
void set_tab_size(int p_spaces);
|
||||
int get_tab_size() const;
|
||||
|
||||
|
||||
|
||||
bool search(const String& p_string,bool p_from_selection=false);
|
||||
bool search(const String &p_string, bool p_from_selection = false);
|
||||
|
||||
void scroll_to_line(int p_line);
|
||||
int get_line_count() const;
|
||||
|
||||
VScrollBar *get_v_scroll() { return vscroll; }
|
||||
|
||||
virtual CursorShape get_cursor_shape(const Point2& p_pos) const;
|
||||
virtual CursorShape get_cursor_shape(const Point2 &p_pos) const;
|
||||
|
||||
void set_selection_enabled(bool p_enabled);
|
||||
bool is_selection_enabled() const;
|
||||
void selection_copy();
|
||||
|
||||
|
||||
Error parse_bbcode(const String& p_bbcode);
|
||||
Error append_bbcode(const String& p_bbcode);
|
||||
Error parse_bbcode(const String &p_bbcode);
|
||||
Error append_bbcode(const String &p_bbcode);
|
||||
|
||||
void set_use_bbcode(bool p_enable);
|
||||
bool is_using_bbcode() const;
|
||||
|
||||
void set_bbcode(const String& p_bbcode);
|
||||
void set_bbcode(const String &p_bbcode);
|
||||
String get_bbcode() const;
|
||||
|
||||
void set_visible_characters(int p_visible);
|
||||
|
|
@ -348,8 +347,8 @@ public:
|
|||
~RichTextLabel();
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST( RichTextLabel::Align );
|
||||
VARIANT_ENUM_CAST( RichTextLabel::ListType );
|
||||
VARIANT_ENUM_CAST( RichTextLabel::ItemType );
|
||||
VARIANT_ENUM_CAST(RichTextLabel::Align);
|
||||
VARIANT_ENUM_CAST(RichTextLabel::ListType);
|
||||
VARIANT_ENUM_CAST(RichTextLabel::ItemType);
|
||||
|
||||
#endif // RICH_TEXT_LABEL_H
|
||||
|
|
|
|||
|
|
@ -28,162 +28,149 @@
|
|||
/*************************************************************************/
|
||||
#include "scroll_bar.h"
|
||||
#include "os/keyboard.h"
|
||||
#include "print_string.h"
|
||||
#include "os/os.h"
|
||||
bool ScrollBar::focus_by_default=false;
|
||||
|
||||
|
||||
#include "print_string.h"
|
||||
bool ScrollBar::focus_by_default = false;
|
||||
|
||||
void ScrollBar::set_can_focus_by_default(bool p_can_focus) {
|
||||
|
||||
focus_by_default=p_can_focus;
|
||||
focus_by_default = p_can_focus;
|
||||
}
|
||||
|
||||
void ScrollBar::_input_event(InputEvent p_event) {
|
||||
|
||||
|
||||
switch(p_event.type) {
|
||||
switch (p_event.type) {
|
||||
|
||||
case InputEvent::MOUSE_BUTTON: {
|
||||
|
||||
const InputEventMouseButton &b=p_event.mouse_button;
|
||||
const InputEventMouseButton &b = p_event.mouse_button;
|
||||
accept_event();
|
||||
|
||||
if (b.button_index==5 && b.pressed) {
|
||||
if (b.button_index == 5 && b.pressed) {
|
||||
|
||||
//if (orientation==VERTICAL)
|
||||
// set_val( get_val() + get_page() / 4.0 );
|
||||
//else
|
||||
set_val( get_val() + get_page() / 4.0 );
|
||||
set_val(get_val() + get_page() / 4.0);
|
||||
accept_event();
|
||||
|
||||
}
|
||||
|
||||
if (b.button_index==4 && b.pressed) {
|
||||
if (b.button_index == 4 && b.pressed) {
|
||||
|
||||
//if (orientation==HORIZONTAL)
|
||||
// set_val( get_val() - get_page() / 4.0 );
|
||||
//else
|
||||
set_val( get_val() - get_page() / 4.0 );
|
||||
set_val(get_val() - get_page() / 4.0);
|
||||
accept_event();
|
||||
}
|
||||
|
||||
if (b.button_index!=1)
|
||||
if (b.button_index != 1)
|
||||
return;
|
||||
|
||||
|
||||
if (b.pressed) {
|
||||
|
||||
|
||||
double ofs = orientation==VERTICAL ? b.y : b.x ;
|
||||
double ofs = orientation == VERTICAL ? b.y : b.x;
|
||||
Ref<Texture> decr = get_icon("decrement");
|
||||
Ref<Texture> incr = get_icon("increment");
|
||||
|
||||
double decr_size = orientation==VERTICAL ? decr->get_height() : decr->get_width();
|
||||
double incr_size = orientation==VERTICAL ? incr->get_height() : incr->get_width();
|
||||
double decr_size = orientation == VERTICAL ? decr->get_height() : decr->get_width();
|
||||
double incr_size = orientation == VERTICAL ? incr->get_height() : incr->get_width();
|
||||
double grabber_ofs = get_grabber_offset();
|
||||
double grabber_size = get_grabber_size();
|
||||
double total = orientation==VERTICAL ? get_size().height : get_size().width;
|
||||
double total = orientation == VERTICAL ? get_size().height : get_size().width;
|
||||
|
||||
if (ofs < decr_size ) {
|
||||
if (ofs < decr_size) {
|
||||
|
||||
set_val( get_val() - (custom_step>=0?custom_step:get_step()) );
|
||||
set_val(get_val() - (custom_step >= 0 ? custom_step : get_step()));
|
||||
break;
|
||||
}
|
||||
|
||||
if (ofs > total-incr_size ) {
|
||||
if (ofs > total - incr_size) {
|
||||
|
||||
set_val( get_val() + (custom_step>=0?custom_step:get_step()) );
|
||||
set_val(get_val() + (custom_step >= 0 ? custom_step : get_step()));
|
||||
break;
|
||||
}
|
||||
|
||||
ofs-=decr_size;
|
||||
ofs -= decr_size;
|
||||
|
||||
if ( ofs < grabber_ofs ) {
|
||||
if (ofs < grabber_ofs) {
|
||||
|
||||
set_val( get_val() - get_page() );
|
||||
set_val(get_val() - get_page());
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
ofs-=grabber_ofs;
|
||||
ofs -= grabber_ofs;
|
||||
|
||||
if (ofs < grabber_size ) {
|
||||
if (ofs < grabber_size) {
|
||||
|
||||
drag.active=true;
|
||||
drag.pos_at_click=grabber_ofs+ofs;
|
||||
drag.value_at_click=get_unit_value();
|
||||
drag.active = true;
|
||||
drag.pos_at_click = grabber_ofs + ofs;
|
||||
drag.value_at_click = get_unit_value();
|
||||
update();
|
||||
} else {
|
||||
|
||||
|
||||
set_val( get_val() + get_page() );
|
||||
set_val(get_val() + get_page());
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
drag.active=false;
|
||||
drag.active = false;
|
||||
update();
|
||||
}
|
||||
|
||||
} break;
|
||||
case InputEvent::MOUSE_MOTION: {
|
||||
|
||||
const InputEventMouseMotion &m=p_event.mouse_motion;
|
||||
const InputEventMouseMotion &m = p_event.mouse_motion;
|
||||
|
||||
accept_event();
|
||||
|
||||
|
||||
if (drag.active) {
|
||||
|
||||
double ofs = orientation==VERTICAL ? m.y : m.x ;
|
||||
double ofs = orientation == VERTICAL ? m.y : m.x;
|
||||
Ref<Texture> decr = get_icon("decrement");
|
||||
|
||||
double decr_size = orientation==VERTICAL ? decr->get_height() : decr->get_width();
|
||||
ofs-=decr_size;
|
||||
double decr_size = orientation == VERTICAL ? decr->get_height() : decr->get_width();
|
||||
ofs -= decr_size;
|
||||
|
||||
double diff = (ofs-drag.pos_at_click) / get_area_size();
|
||||
double diff = (ofs - drag.pos_at_click) / get_area_size();
|
||||
|
||||
set_unit_value( drag.value_at_click + diff );
|
||||
set_unit_value(drag.value_at_click + diff);
|
||||
} else {
|
||||
|
||||
|
||||
double ofs = orientation==VERTICAL ? m.y : m.x ;
|
||||
double ofs = orientation == VERTICAL ? m.y : m.x;
|
||||
Ref<Texture> decr = get_icon("decrement");
|
||||
Ref<Texture> incr = get_icon("increment");
|
||||
|
||||
double decr_size = orientation==VERTICAL ? decr->get_height() : decr->get_width();
|
||||
double incr_size = orientation==VERTICAL ? incr->get_height() : incr->get_width();
|
||||
double total = orientation==VERTICAL ? get_size().height : get_size().width;
|
||||
double decr_size = orientation == VERTICAL ? decr->get_height() : decr->get_width();
|
||||
double incr_size = orientation == VERTICAL ? incr->get_height() : incr->get_width();
|
||||
double total = orientation == VERTICAL ? get_size().height : get_size().width;
|
||||
|
||||
HiliteStatus new_hilite;
|
||||
|
||||
if (ofs < decr_size ) {
|
||||
if (ofs < decr_size) {
|
||||
|
||||
new_hilite=HILITE_DECR;
|
||||
new_hilite = HILITE_DECR;
|
||||
|
||||
} else if (ofs > total-incr_size ) {
|
||||
} else if (ofs > total - incr_size) {
|
||||
|
||||
new_hilite=HILITE_INCR;
|
||||
new_hilite = HILITE_INCR;
|
||||
|
||||
} else {
|
||||
|
||||
new_hilite=HILITE_RANGE;
|
||||
new_hilite = HILITE_RANGE;
|
||||
}
|
||||
|
||||
if (new_hilite!=hilite) {
|
||||
if (new_hilite != hilite) {
|
||||
|
||||
hilite=new_hilite;
|
||||
hilite = new_hilite;
|
||||
update();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
} break;
|
||||
case InputEvent::KEY: {
|
||||
|
||||
const InputEventKey &k=p_event.key;
|
||||
const InputEventKey &k = p_event.key;
|
||||
|
||||
if (!k.pressed)
|
||||
return;
|
||||
|
|
@ -192,317 +179,296 @@ void ScrollBar::_input_event(InputEvent p_event) {
|
|||
|
||||
case KEY_LEFT: {
|
||||
|
||||
if (orientation!=HORIZONTAL)
|
||||
if (orientation != HORIZONTAL)
|
||||
return;
|
||||
set_val( get_val() - (custom_step>=0?custom_step:get_step()) );
|
||||
set_val(get_val() - (custom_step >= 0 ? custom_step : get_step()));
|
||||
|
||||
} break;
|
||||
case KEY_RIGHT: {
|
||||
|
||||
if (orientation!=HORIZONTAL)
|
||||
if (orientation != HORIZONTAL)
|
||||
return;
|
||||
set_val( get_val() + (custom_step>=0?custom_step:get_step()) );
|
||||
set_val(get_val() + (custom_step >= 0 ? custom_step : get_step()));
|
||||
|
||||
} break;
|
||||
case KEY_UP: {
|
||||
|
||||
if (orientation!=VERTICAL)
|
||||
if (orientation != VERTICAL)
|
||||
return;
|
||||
|
||||
set_val( get_val() - (custom_step>=0?custom_step:get_step()) );
|
||||
|
||||
set_val(get_val() - (custom_step >= 0 ? custom_step : get_step()));
|
||||
|
||||
} break;
|
||||
case KEY_DOWN: {
|
||||
|
||||
if (orientation!=VERTICAL)
|
||||
if (orientation != VERTICAL)
|
||||
return;
|
||||
set_val( get_val() + (custom_step>=0?custom_step:get_step()) );
|
||||
set_val(get_val() + (custom_step >= 0 ? custom_step : get_step()));
|
||||
|
||||
} break;
|
||||
case KEY_HOME: {
|
||||
|
||||
set_val( get_min() );
|
||||
set_val(get_min());
|
||||
|
||||
} break;
|
||||
case KEY_END: {
|
||||
|
||||
set_val( get_max() );
|
||||
set_val(get_max());
|
||||
|
||||
} break;
|
||||
|
||||
} break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScrollBar::_notification(int p_what) {
|
||||
|
||||
if (p_what==NOTIFICATION_DRAW) {
|
||||
if (p_what == NOTIFICATION_DRAW) {
|
||||
|
||||
RID ci = get_canvas_item();
|
||||
|
||||
Ref<Texture> decr = hilite==HILITE_DECR ? get_icon("decrement_hilite") : get_icon("decrement");
|
||||
Ref<Texture> incr = hilite==HILITE_INCR ? get_icon("increment_hilite") : get_icon("increment");
|
||||
Ref<Texture> decr = hilite == HILITE_DECR ? get_icon("decrement_hilite") : get_icon("decrement");
|
||||
Ref<Texture> incr = hilite == HILITE_INCR ? get_icon("increment_hilite") : get_icon("increment");
|
||||
Ref<StyleBox> bg = has_focus() ? get_stylebox("scroll_focus") : get_stylebox("scroll");
|
||||
Ref<StyleBox> grabber = (drag.active || hilite==HILITE_RANGE) ? get_stylebox("grabber_hilite") : get_stylebox("grabber");
|
||||
Ref<StyleBox> grabber = (drag.active || hilite == HILITE_RANGE) ? get_stylebox("grabber_hilite") : get_stylebox("grabber");
|
||||
|
||||
Point2 ofs;
|
||||
|
||||
VisualServer *vs = VisualServer::get_singleton();
|
||||
|
||||
vs->canvas_item_add_texture_rect( ci, Rect2( Point2(), decr->get_size()),decr->get_rid() );
|
||||
vs->canvas_item_add_texture_rect(ci, Rect2(Point2(), decr->get_size()), decr->get_rid());
|
||||
|
||||
if (orientation==HORIZONTAL)
|
||||
ofs.x+=decr->get_width();
|
||||
if (orientation == HORIZONTAL)
|
||||
ofs.x += decr->get_width();
|
||||
else
|
||||
ofs.y+=decr->get_height();
|
||||
ofs.y += decr->get_height();
|
||||
|
||||
Size2 area=get_size();
|
||||
Size2 area = get_size();
|
||||
|
||||
if (orientation==HORIZONTAL)
|
||||
area.width-=incr->get_width()+decr->get_width();
|
||||
if (orientation == HORIZONTAL)
|
||||
area.width -= incr->get_width() + decr->get_width();
|
||||
else
|
||||
area.height-=incr->get_height()+decr->get_height();
|
||||
area.height -= incr->get_height() + decr->get_height();
|
||||
|
||||
bg->draw(ci,Rect2(ofs,area));
|
||||
bg->draw(ci, Rect2(ofs, area));
|
||||
|
||||
if (orientation==HORIZONTAL)
|
||||
ofs.width+=area.width;
|
||||
if (orientation == HORIZONTAL)
|
||||
ofs.width += area.width;
|
||||
else
|
||||
ofs.height+=area.height;
|
||||
ofs.height += area.height;
|
||||
|
||||
vs->canvas_item_add_texture_rect( ci, Rect2( ofs, decr->get_size()),incr->get_rid() );
|
||||
vs->canvas_item_add_texture_rect(ci, Rect2(ofs, decr->get_size()), incr->get_rid());
|
||||
Rect2 grabber_rect;
|
||||
|
||||
if (orientation==HORIZONTAL) {
|
||||
if (orientation == HORIZONTAL) {
|
||||
|
||||
grabber_rect.size.width=get_grabber_size();
|
||||
grabber_rect.size.height=get_size().height;
|
||||
grabber_rect.pos.y=0;
|
||||
grabber_rect.pos.x=get_grabber_offset()+decr->get_width()+bg->get_margin( MARGIN_LEFT );
|
||||
grabber_rect.size.width = get_grabber_size();
|
||||
grabber_rect.size.height = get_size().height;
|
||||
grabber_rect.pos.y = 0;
|
||||
grabber_rect.pos.x = get_grabber_offset() + decr->get_width() + bg->get_margin(MARGIN_LEFT);
|
||||
} else {
|
||||
|
||||
grabber_rect.size.width=get_size().width;
|
||||
grabber_rect.size.height=get_grabber_size();
|
||||
grabber_rect.pos.y=get_grabber_offset()+decr->get_height()+bg->get_margin( MARGIN_TOP );
|
||||
grabber_rect.pos.x=0;
|
||||
grabber_rect.size.width = get_size().width;
|
||||
grabber_rect.size.height = get_grabber_size();
|
||||
grabber_rect.pos.y = get_grabber_offset() + decr->get_height() + bg->get_margin(MARGIN_TOP);
|
||||
grabber_rect.pos.x = 0;
|
||||
}
|
||||
|
||||
grabber->draw(ci,grabber_rect);
|
||||
|
||||
grabber->draw(ci, grabber_rect);
|
||||
}
|
||||
|
||||
if (p_what==NOTIFICATION_ENTER_TREE) {
|
||||
|
||||
if (p_what == NOTIFICATION_ENTER_TREE) {
|
||||
|
||||
if (has_node(drag_slave_path)) {
|
||||
Node *n = get_node(drag_slave_path);
|
||||
drag_slave=n->cast_to<Control>();
|
||||
drag_slave = n->cast_to<Control>();
|
||||
}
|
||||
|
||||
if (drag_slave) {
|
||||
drag_slave->connect("input_event",this,"_drag_slave_input");
|
||||
drag_slave->connect("exit_tree",this,"_drag_slave_exit",varray(),CONNECT_ONESHOT);
|
||||
drag_slave->connect("input_event", this, "_drag_slave_input");
|
||||
drag_slave->connect("exit_tree", this, "_drag_slave_exit", varray(), CONNECT_ONESHOT);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
if (p_what==NOTIFICATION_EXIT_TREE) {
|
||||
if (p_what == NOTIFICATION_EXIT_TREE) {
|
||||
|
||||
if (drag_slave) {
|
||||
drag_slave->disconnect("input_event",this,"_drag_slave_input");
|
||||
drag_slave->disconnect("exit_tree",this,"_drag_slave_exit");
|
||||
drag_slave->disconnect("input_event", this, "_drag_slave_input");
|
||||
drag_slave->disconnect("exit_tree", this, "_drag_slave_exit");
|
||||
}
|
||||
|
||||
drag_slave=NULL;
|
||||
|
||||
drag_slave = NULL;
|
||||
}
|
||||
|
||||
if (p_what==NOTIFICATION_FIXED_PROCESS) {
|
||||
if (p_what == NOTIFICATION_FIXED_PROCESS) {
|
||||
|
||||
if (drag_slave_touching) {
|
||||
if (drag_slave_touching) {
|
||||
|
||||
if (drag_slave_touching_deaccel) {
|
||||
|
||||
Vector2 pos = Vector2(orientation==HORIZONTAL?get_val():0,orientation==VERTICAL?get_val():0);
|
||||
pos+=drag_slave_speed*get_fixed_process_delta_time();
|
||||
Vector2 pos = Vector2(orientation == HORIZONTAL ? get_val() : 0, orientation == VERTICAL ? get_val() : 0);
|
||||
pos += drag_slave_speed * get_fixed_process_delta_time();
|
||||
|
||||
bool turnoff=false;
|
||||
bool turnoff = false;
|
||||
|
||||
if (orientation==HORIZONTAL) {
|
||||
if (orientation == HORIZONTAL) {
|
||||
|
||||
if (pos.x<0) {
|
||||
pos.x=0;
|
||||
turnoff=true;
|
||||
if (pos.x < 0) {
|
||||
pos.x = 0;
|
||||
turnoff = true;
|
||||
}
|
||||
|
||||
if (pos.x > (get_max()-get_page())) {
|
||||
pos.x=get_max()-get_page();
|
||||
turnoff=true;
|
||||
if (pos.x > (get_max() - get_page())) {
|
||||
pos.x = get_max() - get_page();
|
||||
turnoff = true;
|
||||
}
|
||||
|
||||
set_val(pos.x);
|
||||
|
||||
float sgn_x = drag_slave_speed.x<0? -1 : 1;
|
||||
float sgn_x = drag_slave_speed.x < 0 ? -1 : 1;
|
||||
float val_x = Math::abs(drag_slave_speed.x);
|
||||
val_x-=1000*get_fixed_process_delta_time();
|
||||
val_x -= 1000 * get_fixed_process_delta_time();
|
||||
|
||||
if (val_x<0) {
|
||||
turnoff=true;
|
||||
if (val_x < 0) {
|
||||
turnoff = true;
|
||||
}
|
||||
|
||||
drag_slave_speed.x=sgn_x*val_x;
|
||||
drag_slave_speed.x = sgn_x * val_x;
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
if (pos.y<0) {
|
||||
pos.y=0;
|
||||
turnoff=true;
|
||||
if (pos.y < 0) {
|
||||
pos.y = 0;
|
||||
turnoff = true;
|
||||
}
|
||||
|
||||
if (pos.y > (get_max()-get_page())) {
|
||||
pos.y=get_max()-get_page();
|
||||
turnoff=true;
|
||||
if (pos.y > (get_max() - get_page())) {
|
||||
pos.y = get_max() - get_page();
|
||||
turnoff = true;
|
||||
}
|
||||
|
||||
set_val(pos.y);
|
||||
|
||||
float sgn_y = drag_slave_speed.y<0? -1 : 1;
|
||||
float sgn_y = drag_slave_speed.y < 0 ? -1 : 1;
|
||||
float val_y = Math::abs(drag_slave_speed.y);
|
||||
val_y-=1000*get_fixed_process_delta_time();
|
||||
val_y -= 1000 * get_fixed_process_delta_time();
|
||||
|
||||
if (val_y<0) {
|
||||
turnoff=true;
|
||||
if (val_y < 0) {
|
||||
turnoff = true;
|
||||
}
|
||||
drag_slave_speed.y=sgn_y*val_y;
|
||||
drag_slave_speed.y = sgn_y * val_y;
|
||||
}
|
||||
|
||||
|
||||
if (turnoff) {
|
||||
set_fixed_process(false);
|
||||
drag_slave_touching=false;
|
||||
drag_slave_touching_deaccel=false;
|
||||
drag_slave_touching = false;
|
||||
drag_slave_touching_deaccel = false;
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
if (time_since_motion==0 || time_since_motion>0.1) {
|
||||
if (time_since_motion == 0 || time_since_motion > 0.1) {
|
||||
|
||||
Vector2 diff = drag_slave_accum - last_drag_slave_accum;
|
||||
last_drag_slave_accum=drag_slave_accum;
|
||||
drag_slave_speed=diff/get_fixed_process_delta_time();
|
||||
last_drag_slave_accum = drag_slave_accum;
|
||||
drag_slave_speed = diff / get_fixed_process_delta_time();
|
||||
}
|
||||
|
||||
time_since_motion+=get_fixed_process_delta_time();
|
||||
time_since_motion += get_fixed_process_delta_time();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (p_what==NOTIFICATION_MOUSE_EXIT) {
|
||||
if (p_what == NOTIFICATION_MOUSE_EXIT) {
|
||||
|
||||
hilite=HILITE_NONE;
|
||||
hilite = HILITE_NONE;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
double ScrollBar::get_grabber_min_size() const {
|
||||
|
||||
Ref<StyleBox> grabber=get_stylebox("grabber");
|
||||
Size2 gminsize=grabber->get_minimum_size()+grabber->get_center_size();
|
||||
return (orientation==VERTICAL)?gminsize.height:gminsize.width;
|
||||
Ref<StyleBox> grabber = get_stylebox("grabber");
|
||||
Size2 gminsize = grabber->get_minimum_size() + grabber->get_center_size();
|
||||
return (orientation == VERTICAL) ? gminsize.height : gminsize.width;
|
||||
}
|
||||
|
||||
double ScrollBar::get_grabber_size() const {
|
||||
|
||||
float range = get_max()-get_min();
|
||||
if (range<=0)
|
||||
float range = get_max() - get_min();
|
||||
if (range <= 0)
|
||||
return 0;
|
||||
|
||||
float page = (get_page()>0)? get_page() : 0;
|
||||
// if (grabber_range < get_step())
|
||||
// grabber_range=get_step();
|
||||
float page = (get_page() > 0) ? get_page() : 0;
|
||||
// if (grabber_range < get_step())
|
||||
// grabber_range=get_step();
|
||||
|
||||
double area_size=get_area_size();
|
||||
double area_size = get_area_size();
|
||||
double grabber_size = page / range * area_size;
|
||||
return grabber_size+get_grabber_min_size();
|
||||
|
||||
return grabber_size + get_grabber_min_size();
|
||||
}
|
||||
|
||||
double ScrollBar::get_area_size() const {
|
||||
|
||||
if (orientation==VERTICAL) {
|
||||
if (orientation == VERTICAL) {
|
||||
|
||||
double area=get_size().height;
|
||||
area-=get_stylebox("scroll")->get_minimum_size().height;
|
||||
area-=get_icon("increment")->get_height();
|
||||
area-=get_icon("decrement")->get_height();
|
||||
area-=get_grabber_min_size();
|
||||
double area = get_size().height;
|
||||
area -= get_stylebox("scroll")->get_minimum_size().height;
|
||||
area -= get_icon("increment")->get_height();
|
||||
area -= get_icon("decrement")->get_height();
|
||||
area -= get_grabber_min_size();
|
||||
return area;
|
||||
|
||||
} else if (orientation==HORIZONTAL) {
|
||||
} else if (orientation == HORIZONTAL) {
|
||||
|
||||
double area=get_size().width;
|
||||
area-=get_stylebox("scroll")->get_minimum_size().width;
|
||||
area-=get_icon("increment")->get_width();
|
||||
area-=get_icon("decrement")->get_width();
|
||||
area-=get_grabber_min_size();
|
||||
double area = get_size().width;
|
||||
area -= get_stylebox("scroll")->get_minimum_size().width;
|
||||
area -= get_icon("increment")->get_width();
|
||||
area -= get_icon("decrement")->get_width();
|
||||
area -= get_grabber_min_size();
|
||||
return area;
|
||||
} else {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
double ScrollBar::get_area_offset() const {
|
||||
|
||||
double ofs=0;
|
||||
double ofs = 0;
|
||||
|
||||
if (orientation==VERTICAL) {
|
||||
|
||||
ofs+=get_stylebox("hscroll")->get_margin( MARGIN_TOP );
|
||||
ofs+=get_icon("decrement")->get_height();
|
||||
if (orientation == VERTICAL) {
|
||||
|
||||
ofs += get_stylebox("hscroll")->get_margin(MARGIN_TOP);
|
||||
ofs += get_icon("decrement")->get_height();
|
||||
}
|
||||
|
||||
if (orientation==HORIZONTAL) {
|
||||
if (orientation == HORIZONTAL) {
|
||||
|
||||
ofs+=get_stylebox("hscroll")->get_margin( MARGIN_LEFT );
|
||||
ofs+=get_icon("decrement")->get_width();
|
||||
ofs += get_stylebox("hscroll")->get_margin(MARGIN_LEFT);
|
||||
ofs += get_icon("decrement")->get_width();
|
||||
}
|
||||
|
||||
return ofs;
|
||||
}
|
||||
|
||||
double ScrollBar::get_click_pos(const Point2& p_pos) const {
|
||||
double ScrollBar::get_click_pos(const Point2 &p_pos) const {
|
||||
|
||||
float pos = (orientation == VERTICAL) ? p_pos.y : p_pos.x;
|
||||
pos -= get_area_offset();
|
||||
|
||||
float pos=(orientation==VERTICAL)?p_pos.y:p_pos.x;
|
||||
pos-=get_area_offset();
|
||||
|
||||
float area=get_area_size();
|
||||
if (area==0)
|
||||
float area = get_area_size();
|
||||
if (area == 0)
|
||||
return 0;
|
||||
else
|
||||
return pos/area;
|
||||
|
||||
return pos / area;
|
||||
}
|
||||
|
||||
double ScrollBar::get_grabber_offset() const {
|
||||
|
||||
|
||||
return (get_area_size()) * get_unit_value();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Size2 ScrollBar::get_minimum_size() const {
|
||||
|
||||
Ref<Texture> incr = get_icon("increment");
|
||||
|
|
@ -510,31 +476,30 @@ Size2 ScrollBar::get_minimum_size() const {
|
|||
Ref<StyleBox> bg = get_stylebox("scroll");
|
||||
Size2 minsize;
|
||||
|
||||
if (orientation==VERTICAL) {
|
||||
if (orientation == VERTICAL) {
|
||||
|
||||
minsize.width=MAX(incr->get_size().width,(bg->get_minimum_size()+bg->get_center_size()).width);
|
||||
minsize.height+=incr->get_size().height;
|
||||
minsize.height+=decr->get_size().height;
|
||||
minsize.height+=bg->get_minimum_size().height;
|
||||
minsize.height+=get_grabber_min_size();
|
||||
minsize.width = MAX(incr->get_size().width, (bg->get_minimum_size() + bg->get_center_size()).width);
|
||||
minsize.height += incr->get_size().height;
|
||||
minsize.height += decr->get_size().height;
|
||||
minsize.height += bg->get_minimum_size().height;
|
||||
minsize.height += get_grabber_min_size();
|
||||
}
|
||||
|
||||
if (orientation==HORIZONTAL) {
|
||||
if (orientation == HORIZONTAL) {
|
||||
|
||||
minsize.height=MAX(incr->get_size().height,(bg->get_center_size()+bg->get_minimum_size()).height);
|
||||
minsize.width+=incr->get_size().width;
|
||||
minsize.width+=decr->get_size().width;
|
||||
minsize.width+=bg->get_minimum_size().width;
|
||||
minsize.width+=get_grabber_min_size();
|
||||
minsize.height = MAX(incr->get_size().height, (bg->get_center_size() + bg->get_minimum_size()).height);
|
||||
minsize.width += incr->get_size().width;
|
||||
minsize.width += decr->get_size().width;
|
||||
minsize.width += bg->get_minimum_size().width;
|
||||
minsize.width += get_grabber_min_size();
|
||||
}
|
||||
|
||||
return minsize;
|
||||
|
||||
}
|
||||
|
||||
void ScrollBar::set_custom_step(float p_custom_step) {
|
||||
|
||||
custom_step=p_custom_step;
|
||||
custom_step = p_custom_step;
|
||||
}
|
||||
|
||||
float ScrollBar::get_custom_step() const {
|
||||
|
|
@ -542,53 +507,50 @@ float ScrollBar::get_custom_step() const {
|
|||
return custom_step;
|
||||
}
|
||||
|
||||
|
||||
void ScrollBar::_drag_slave_exit() {
|
||||
|
||||
if (drag_slave) {
|
||||
drag_slave->disconnect("input_event",this,"_drag_slave_input");
|
||||
drag_slave->disconnect("input_event", this, "_drag_slave_input");
|
||||
}
|
||||
drag_slave=NULL;
|
||||
drag_slave = NULL;
|
||||
}
|
||||
|
||||
void ScrollBar::_drag_slave_input(const InputEvent &p_input) {
|
||||
|
||||
void ScrollBar::_drag_slave_input(const InputEvent& p_input) {
|
||||
|
||||
switch(p_input.type) {
|
||||
switch (p_input.type) {
|
||||
|
||||
case InputEvent::MOUSE_BUTTON: {
|
||||
|
||||
const InputEventMouseButton &mb=p_input.mouse_button;
|
||||
const InputEventMouseButton &mb = p_input.mouse_button;
|
||||
|
||||
if (mb.button_index!=1)
|
||||
if (mb.button_index != 1)
|
||||
break;
|
||||
|
||||
if (mb.pressed) {
|
||||
|
||||
if (drag_slave_touching) {
|
||||
set_fixed_process(false);
|
||||
drag_slave_touching_deaccel=false;
|
||||
drag_slave_touching=false;
|
||||
drag_slave_speed=Vector2();
|
||||
drag_slave_accum=Vector2();
|
||||
last_drag_slave_accum=Vector2();
|
||||
drag_slave_from=Vector2();
|
||||
drag_slave_touching_deaccel = false;
|
||||
drag_slave_touching = false;
|
||||
drag_slave_speed = Vector2();
|
||||
drag_slave_accum = Vector2();
|
||||
last_drag_slave_accum = Vector2();
|
||||
drag_slave_from = Vector2();
|
||||
}
|
||||
|
||||
if (true) {
|
||||
drag_slave_speed=Vector2();
|
||||
drag_slave_accum=Vector2();
|
||||
last_drag_slave_accum=Vector2();
|
||||
drag_slave_speed = Vector2();
|
||||
drag_slave_accum = Vector2();
|
||||
last_drag_slave_accum = Vector2();
|
||||
//drag_slave_from=Vector2(h_scroll->get_val(),v_scroll->get_val());
|
||||
drag_slave_from= Vector2(orientation==HORIZONTAL?get_val():0,orientation==VERTICAL?get_val():0);
|
||||
drag_slave_from = Vector2(orientation == HORIZONTAL ? get_val() : 0, orientation == VERTICAL ? get_val() : 0);
|
||||
|
||||
drag_slave_touching=OS::get_singleton()->has_touchscreen_ui_hint();
|
||||
drag_slave_touching_deaccel=false;
|
||||
time_since_motion=0;
|
||||
drag_slave_touching = OS::get_singleton()->has_touchscreen_ui_hint();
|
||||
drag_slave_touching_deaccel = false;
|
||||
time_since_motion = 0;
|
||||
if (drag_slave_touching) {
|
||||
set_fixed_process(true);
|
||||
time_since_motion=0;
|
||||
|
||||
time_since_motion = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -596,78 +558,75 @@ void ScrollBar::_drag_slave_input(const InputEvent& p_input) {
|
|||
|
||||
if (drag_slave_touching) {
|
||||
|
||||
if (drag_slave_speed==Vector2()) {
|
||||
drag_slave_touching_deaccel=false;
|
||||
drag_slave_touching=false;
|
||||
if (drag_slave_speed == Vector2()) {
|
||||
drag_slave_touching_deaccel = false;
|
||||
drag_slave_touching = false;
|
||||
set_fixed_process(false);
|
||||
} else {
|
||||
|
||||
drag_slave_touching_deaccel=true;
|
||||
drag_slave_touching_deaccel = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case InputEvent::MOUSE_MOTION: {
|
||||
|
||||
const InputEventMouseMotion &mm=p_input.mouse_motion;
|
||||
const InputEventMouseMotion &mm = p_input.mouse_motion;
|
||||
|
||||
if (drag_slave_touching && ! drag_slave_touching_deaccel) {
|
||||
if (drag_slave_touching && !drag_slave_touching_deaccel) {
|
||||
|
||||
Vector2 motion = Vector2(mm.relative_x,mm.relative_y);
|
||||
Vector2 motion = Vector2(mm.relative_x, mm.relative_y);
|
||||
|
||||
drag_slave_accum-=motion;
|
||||
Vector2 diff = drag_slave_from+drag_slave_accum;
|
||||
drag_slave_accum -= motion;
|
||||
Vector2 diff = drag_slave_from + drag_slave_accum;
|
||||
|
||||
if (orientation==HORIZONTAL)
|
||||
if (orientation == HORIZONTAL)
|
||||
set_val(diff.x);
|
||||
//else
|
||||
// drag_slave_accum.x=0;
|
||||
if (orientation==VERTICAL)
|
||||
if (orientation == VERTICAL)
|
||||
set_val(diff.y);
|
||||
//else
|
||||
// drag_slave_accum.y=0;
|
||||
time_since_motion=0;
|
||||
time_since_motion = 0;
|
||||
}
|
||||
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void ScrollBar::set_drag_slave(const NodePath& p_path) {
|
||||
void ScrollBar::set_drag_slave(const NodePath &p_path) {
|
||||
|
||||
if (is_inside_tree()) {
|
||||
|
||||
if (drag_slave) {
|
||||
drag_slave->disconnect("input_event",this,"_drag_slave_input");
|
||||
drag_slave->disconnect("exit_tree",this,"_drag_slave_exit");
|
||||
drag_slave->disconnect("input_event", this, "_drag_slave_input");
|
||||
drag_slave->disconnect("exit_tree", this, "_drag_slave_exit");
|
||||
}
|
||||
}
|
||||
|
||||
drag_slave=NULL;
|
||||
drag_slave_path=p_path;
|
||||
drag_slave = NULL;
|
||||
drag_slave_path = p_path;
|
||||
|
||||
if (is_inside_tree()) {
|
||||
|
||||
if (has_node(p_path)) {
|
||||
Node *n = get_node(p_path);
|
||||
drag_slave=n->cast_to<Control>();
|
||||
drag_slave = n->cast_to<Control>();
|
||||
}
|
||||
|
||||
if (drag_slave) {
|
||||
drag_slave->connect("input_event",this,"_drag_slave_input");
|
||||
drag_slave->connect("exit_tree",this,"_drag_slave_exit",varray(),CONNECT_ONESHOT);
|
||||
drag_slave->connect("input_event", this, "_drag_slave_input");
|
||||
drag_slave->connect("exit_tree", this, "_drag_slave_exit", varray(), CONNECT_ONESHOT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NodePath ScrollBar::get_drag_slave() const{
|
||||
|
||||
NodePath ScrollBar::get_drag_slave() const {
|
||||
|
||||
return drag_slave_path;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if 0
|
||||
|
||||
void ScrollBar::mouse_button(const Point2& p_pos, int b.button_index,bool b.pressed,int p_modifier_mask) {
|
||||
|
|
@ -798,48 +757,36 @@ bool ScrollBar::key(unsigned long p_unicode, unsigned long p_scan_code,bool b.pr
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
void ScrollBar::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("_input_event"),&ScrollBar::_input_event);
|
||||
ObjectTypeDB::bind_method(_MD("set_custom_step","step"),&ScrollBar::set_custom_step);
|
||||
ObjectTypeDB::bind_method(_MD("get_custom_step"),&ScrollBar::get_custom_step);
|
||||
ObjectTypeDB::bind_method(_MD("_drag_slave_input"),&ScrollBar::_drag_slave_input);
|
||||
ObjectTypeDB::bind_method(_MD("_drag_slave_exit"),&ScrollBar::_drag_slave_exit);
|
||||
|
||||
ADD_PROPERTY( PropertyInfo(Variant::REAL,"custom_step",PROPERTY_HINT_RANGE,"-1,4096"), _SCS("set_custom_step"),_SCS("get_custom_step"));
|
||||
ObjectTypeDB::bind_method(_MD("_input_event"), &ScrollBar::_input_event);
|
||||
ObjectTypeDB::bind_method(_MD("set_custom_step", "step"), &ScrollBar::set_custom_step);
|
||||
ObjectTypeDB::bind_method(_MD("get_custom_step"), &ScrollBar::get_custom_step);
|
||||
ObjectTypeDB::bind_method(_MD("_drag_slave_input"), &ScrollBar::_drag_slave_input);
|
||||
ObjectTypeDB::bind_method(_MD("_drag_slave_exit"), &ScrollBar::_drag_slave_exit);
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "custom_step", PROPERTY_HINT_RANGE, "-1,4096"), _SCS("set_custom_step"), _SCS("get_custom_step"));
|
||||
}
|
||||
|
||||
ScrollBar::ScrollBar(Orientation p_orientation) {
|
||||
|
||||
ScrollBar::ScrollBar(Orientation p_orientation)
|
||||
{
|
||||
orientation = p_orientation;
|
||||
hilite = HILITE_NONE;
|
||||
custom_step = -1;
|
||||
drag_slave = NULL;
|
||||
|
||||
drag.active = false;
|
||||
|
||||
orientation=p_orientation;
|
||||
hilite=HILITE_NONE;
|
||||
custom_step=-1;
|
||||
drag_slave=NULL;
|
||||
|
||||
drag.active=false;
|
||||
|
||||
drag_slave_speed=Vector2();
|
||||
drag_slave_touching=false;
|
||||
drag_slave_touching_deaccel=false;
|
||||
drag_slave_speed = Vector2();
|
||||
drag_slave_touching = false;
|
||||
drag_slave_touching_deaccel = false;
|
||||
|
||||
if (focus_by_default)
|
||||
set_focus_mode( FOCUS_ALL );
|
||||
set_focus_mode(FOCUS_ALL);
|
||||
set_step(0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
ScrollBar::~ScrollBar()
|
||||
{
|
||||
ScrollBar::~ScrollBar() {
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -31,13 +31,12 @@
|
|||
|
||||
#include "scene/gui/range.h"
|
||||
|
||||
|
||||
/**
|
||||
@author Juan Linietsky <reduzio@gmail.com>
|
||||
*/
|
||||
class ScrollBar : public Range {
|
||||
|
||||
OBJ_TYPE( ScrollBar, Range );
|
||||
OBJ_TYPE(ScrollBar, Range);
|
||||
|
||||
enum HiliteStatus {
|
||||
HILITE_NONE,
|
||||
|
|
@ -61,17 +60,16 @@ class ScrollBar : public Range {
|
|||
float value_at_click;
|
||||
} drag;
|
||||
|
||||
|
||||
double get_grabber_size() const;
|
||||
double get_grabber_min_size() const;
|
||||
double get_area_size() const;
|
||||
double get_area_offset() const;
|
||||
double get_click_pos(const Point2& p_pos) const;
|
||||
double get_click_pos(const Point2 &p_pos) const;
|
||||
double get_grabber_offset() const;
|
||||
|
||||
static void set_can_focus_by_default(bool p_can_focus);
|
||||
|
||||
Node* drag_slave;
|
||||
Node *drag_slave;
|
||||
NodePath drag_slave_path;
|
||||
|
||||
Vector2 drag_slave_speed;
|
||||
|
|
@ -85,43 +83,43 @@ class ScrollBar : public Range {
|
|||
bool click_handled;
|
||||
|
||||
void _drag_slave_exit();
|
||||
void _drag_slave_input(const InputEvent& p_input);
|
||||
void _drag_slave_input(const InputEvent &p_input);
|
||||
|
||||
void _input_event(InputEvent p_event);
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
|
||||
void set_custom_step(float p_custom_step);
|
||||
float get_custom_step() const;
|
||||
|
||||
void set_drag_slave(const NodePath& p_path);
|
||||
void set_drag_slave(const NodePath &p_path);
|
||||
NodePath get_drag_slave() const;
|
||||
|
||||
virtual Size2 get_minimum_size() const;
|
||||
ScrollBar(Orientation p_orientation=VERTICAL);
|
||||
ScrollBar(Orientation p_orientation = VERTICAL);
|
||||
~ScrollBar();
|
||||
|
||||
};
|
||||
|
||||
class HScrollBar : public ScrollBar {
|
||||
|
||||
OBJ_TYPE( HScrollBar, ScrollBar );
|
||||
public:
|
||||
OBJ_TYPE(HScrollBar, ScrollBar);
|
||||
|
||||
HScrollBar() : ScrollBar(HORIZONTAL) { set_v_size_flags(0); }
|
||||
public:
|
||||
HScrollBar()
|
||||
: ScrollBar(HORIZONTAL) { set_v_size_flags(0); }
|
||||
};
|
||||
|
||||
class VScrollBar : public ScrollBar {
|
||||
|
||||
OBJ_TYPE( VScrollBar, ScrollBar );
|
||||
public:
|
||||
OBJ_TYPE(VScrollBar, ScrollBar);
|
||||
|
||||
VScrollBar() : ScrollBar(VERTICAL) { set_h_size_flags(0); }
|
||||
public:
|
||||
VScrollBar()
|
||||
: ScrollBar(VERTICAL) { set_h_size_flags(0); }
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -35,10 +35,9 @@ bool ScrollContainer::clips_input() const {
|
|||
|
||||
Size2 ScrollContainer::get_minimum_size() const {
|
||||
|
||||
|
||||
Size2 min_size;
|
||||
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c)
|
||||
|
|
@ -49,161 +48,150 @@ Size2 ScrollContainer::get_minimum_size() const {
|
|||
continue;
|
||||
Size2 minsize = c->get_combined_minimum_size();
|
||||
|
||||
|
||||
if (!scroll_h) {
|
||||
min_size.x = MAX(min_size.x, minsize.x);
|
||||
}
|
||||
if (!scroll_v) {
|
||||
min_size.y = MAX(min_size.y, minsize.y);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (h_scroll->is_visible()) {
|
||||
min_size.y+=h_scroll->get_minimum_size().y;
|
||||
min_size.y += h_scroll->get_minimum_size().y;
|
||||
}
|
||||
if (v_scroll->is_visible()) {
|
||||
min_size.x+=v_scroll->get_minimum_size().x;
|
||||
min_size.x += v_scroll->get_minimum_size().x;
|
||||
}
|
||||
return min_size;
|
||||
};
|
||||
|
||||
|
||||
void ScrollContainer::_cancel_drag() {
|
||||
set_fixed_process(false);
|
||||
drag_touching_deaccel=false;
|
||||
drag_touching=false;
|
||||
drag_speed=Vector2();
|
||||
drag_accum=Vector2();
|
||||
last_drag_accum=Vector2();
|
||||
drag_from=Vector2();
|
||||
drag_touching_deaccel = false;
|
||||
drag_touching = false;
|
||||
drag_speed = Vector2();
|
||||
drag_accum = Vector2();
|
||||
last_drag_accum = Vector2();
|
||||
drag_from = Vector2();
|
||||
}
|
||||
|
||||
void ScrollContainer::_input_event(const InputEvent& p_input_event) {
|
||||
void ScrollContainer::_input_event(const InputEvent &p_input_event) {
|
||||
|
||||
|
||||
switch(p_input_event.type) {
|
||||
switch (p_input_event.type) {
|
||||
|
||||
case InputEvent::MOUSE_BUTTON: {
|
||||
|
||||
const InputEventMouseButton &mb=p_input_event.mouse_button;
|
||||
const InputEventMouseButton &mb = p_input_event.mouse_button;
|
||||
|
||||
if (mb.button_index==BUTTON_WHEEL_UP && mb.pressed) {
|
||||
if (h_scroll->is_visible() && !v_scroll->is_visible()){
|
||||
if (mb.button_index == BUTTON_WHEEL_UP && mb.pressed) {
|
||||
if (h_scroll->is_visible() && !v_scroll->is_visible()) {
|
||||
// only horizontal is enabled, scroll horizontally
|
||||
h_scroll->set_val( h_scroll->get_val()-h_scroll->get_page()/8 );
|
||||
h_scroll->set_val(h_scroll->get_val() - h_scroll->get_page() / 8);
|
||||
} else if (v_scroll->is_visible()) {
|
||||
v_scroll->set_val( v_scroll->get_val()-v_scroll->get_page()/8 );
|
||||
v_scroll->set_val(v_scroll->get_val() - v_scroll->get_page() / 8);
|
||||
}
|
||||
}
|
||||
|
||||
if (mb.button_index==BUTTON_WHEEL_DOWN && mb.pressed) {
|
||||
if (h_scroll->is_visible() && !v_scroll->is_visible()){
|
||||
if (mb.button_index == BUTTON_WHEEL_DOWN && mb.pressed) {
|
||||
if (h_scroll->is_visible() && !v_scroll->is_visible()) {
|
||||
// only horizontal is enabled, scroll horizontally
|
||||
h_scroll->set_val( h_scroll->get_val()+h_scroll->get_page()/8 );
|
||||
h_scroll->set_val(h_scroll->get_val() + h_scroll->get_page() / 8);
|
||||
} else if (v_scroll->is_visible()) {
|
||||
v_scroll->set_val( v_scroll->get_val()+v_scroll->get_page()/8 );
|
||||
v_scroll->set_val(v_scroll->get_val() + v_scroll->get_page() / 8);
|
||||
}
|
||||
}
|
||||
|
||||
if(!OS::get_singleton()->has_touchscreen_ui_hint())
|
||||
if (!OS::get_singleton()->has_touchscreen_ui_hint())
|
||||
return;
|
||||
|
||||
if (mb.button_index!=BUTTON_LEFT)
|
||||
if (mb.button_index != BUTTON_LEFT)
|
||||
break;
|
||||
|
||||
if (mb.pressed) {
|
||||
|
||||
if (drag_touching) {
|
||||
set_fixed_process(false);
|
||||
drag_touching_deaccel=false;
|
||||
drag_touching=false;
|
||||
drag_speed=Vector2();
|
||||
drag_accum=Vector2();
|
||||
last_drag_accum=Vector2();
|
||||
drag_from=Vector2();
|
||||
drag_touching_deaccel = false;
|
||||
drag_touching = false;
|
||||
drag_speed = Vector2();
|
||||
drag_accum = Vector2();
|
||||
last_drag_accum = Vector2();
|
||||
drag_from = Vector2();
|
||||
}
|
||||
|
||||
if (true) {
|
||||
drag_speed=Vector2();
|
||||
drag_accum=Vector2();
|
||||
last_drag_accum=Vector2();
|
||||
drag_from=Vector2(h_scroll->get_val(),v_scroll->get_val());
|
||||
drag_touching=OS::get_singleton()->has_touchscreen_ui_hint();
|
||||
drag_touching_deaccel=false;
|
||||
time_since_motion=0;
|
||||
drag_speed = Vector2();
|
||||
drag_accum = Vector2();
|
||||
last_drag_accum = Vector2();
|
||||
drag_from = Vector2(h_scroll->get_val(), v_scroll->get_val());
|
||||
drag_touching = OS::get_singleton()->has_touchscreen_ui_hint();
|
||||
drag_touching_deaccel = false;
|
||||
time_since_motion = 0;
|
||||
if (drag_touching) {
|
||||
set_fixed_process(true);
|
||||
time_since_motion=0;
|
||||
|
||||
time_since_motion = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
if (drag_touching) {
|
||||
|
||||
if (drag_speed==Vector2()) {
|
||||
drag_touching_deaccel=false;
|
||||
drag_touching=false;
|
||||
if (drag_speed == Vector2()) {
|
||||
drag_touching_deaccel = false;
|
||||
drag_touching = false;
|
||||
set_fixed_process(false);
|
||||
} else {
|
||||
|
||||
drag_touching_deaccel=true;
|
||||
drag_touching_deaccel = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} break;
|
||||
case InputEvent::MOUSE_MOTION: {
|
||||
|
||||
const InputEventMouseMotion &mm=p_input_event.mouse_motion;
|
||||
const InputEventMouseMotion &mm = p_input_event.mouse_motion;
|
||||
|
||||
if (drag_touching && ! drag_touching_deaccel) {
|
||||
if (drag_touching && !drag_touching_deaccel) {
|
||||
|
||||
Vector2 motion = Vector2(mm.relative_x,mm.relative_y);
|
||||
drag_accum-=motion;
|
||||
Vector2 diff = drag_from+drag_accum;
|
||||
Vector2 motion = Vector2(mm.relative_x, mm.relative_y);
|
||||
drag_accum -= motion;
|
||||
Vector2 diff = drag_from + drag_accum;
|
||||
|
||||
if (scroll_h)
|
||||
h_scroll->set_val(diff.x);
|
||||
else
|
||||
drag_accum.x=0;
|
||||
drag_accum.x = 0;
|
||||
if (scroll_v)
|
||||
v_scroll->set_val(diff.y);
|
||||
else
|
||||
drag_accum.y=0;
|
||||
time_since_motion=0;
|
||||
drag_accum.y = 0;
|
||||
time_since_motion = 0;
|
||||
}
|
||||
|
||||
} break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ScrollContainer::_update_scrollbar_pos() {
|
||||
|
||||
Size2 hmin = h_scroll->get_combined_minimum_size();
|
||||
Size2 vmin = v_scroll->get_combined_minimum_size();
|
||||
|
||||
v_scroll->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_END,vmin.width);
|
||||
v_scroll->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,0);
|
||||
v_scroll->set_anchor_and_margin(MARGIN_TOP,ANCHOR_BEGIN,0);
|
||||
v_scroll->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,0);
|
||||
v_scroll->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_END, vmin.width);
|
||||
v_scroll->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 0);
|
||||
v_scroll->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, 0);
|
||||
v_scroll->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, 0);
|
||||
|
||||
h_scroll->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_BEGIN,0);
|
||||
h_scroll->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,0);
|
||||
h_scroll->set_anchor_and_margin(MARGIN_TOP,ANCHOR_END,hmin.height);
|
||||
h_scroll->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,0);
|
||||
h_scroll->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 0);
|
||||
h_scroll->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 0);
|
||||
h_scroll->set_anchor_and_margin(MARGIN_TOP, ANCHOR_END, hmin.height);
|
||||
h_scroll->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, 0);
|
||||
|
||||
h_scroll->raise();
|
||||
v_scroll->raise();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ScrollContainer::_notification(int p_what) {
|
||||
|
||||
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
|
||||
|
|
@ -211,18 +199,17 @@ void ScrollContainer::_notification(int p_what) {
|
|||
call_deferred("_update_scrollbar_pos");
|
||||
};
|
||||
|
||||
|
||||
if (p_what==NOTIFICATION_SORT_CHILDREN) {
|
||||
if (p_what == NOTIFICATION_SORT_CHILDREN) {
|
||||
|
||||
child_max_size = Size2(0, 0);
|
||||
Size2 size = get_size();
|
||||
if (h_scroll->is_visible())
|
||||
size.y-=h_scroll->get_minimum_size().y;
|
||||
size.y -= h_scroll->get_minimum_size().y;
|
||||
|
||||
if (v_scroll->is_visible())
|
||||
size.x-=h_scroll->get_minimum_size().x;
|
||||
size.x -= h_scroll->get_minimum_size().x;
|
||||
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c)
|
||||
|
|
@ -235,24 +222,23 @@ void ScrollContainer::_notification(int p_what) {
|
|||
child_max_size.x = MAX(child_max_size.x, minsize.x);
|
||||
child_max_size.y = MAX(child_max_size.y, minsize.y);
|
||||
|
||||
Rect2 r = Rect2(-scroll,minsize);
|
||||
if (!scroll_h || (!h_scroll->is_visible() && c->get_h_size_flags()&SIZE_EXPAND)) {
|
||||
r.pos.x=0;
|
||||
if (c->get_h_size_flags()&SIZE_EXPAND)
|
||||
r.size.width=MAX(size.width,minsize.width);
|
||||
Rect2 r = Rect2(-scroll, minsize);
|
||||
if (!scroll_h || (!h_scroll->is_visible() && c->get_h_size_flags() & SIZE_EXPAND)) {
|
||||
r.pos.x = 0;
|
||||
if (c->get_h_size_flags() & SIZE_EXPAND)
|
||||
r.size.width = MAX(size.width, minsize.width);
|
||||
else
|
||||
r.size.width=minsize.width;
|
||||
r.size.width = minsize.width;
|
||||
}
|
||||
if (!scroll_v || (!v_scroll->is_visible() && c->get_v_size_flags()&SIZE_EXPAND)) {
|
||||
r.pos.y=0;
|
||||
r.size.height=size.height;
|
||||
if (c->get_v_size_flags()&SIZE_EXPAND)
|
||||
r.size.height=MAX(size.height,minsize.height);
|
||||
if (!scroll_v || (!v_scroll->is_visible() && c->get_v_size_flags() & SIZE_EXPAND)) {
|
||||
r.pos.y = 0;
|
||||
r.size.height = size.height;
|
||||
if (c->get_v_size_flags() & SIZE_EXPAND)
|
||||
r.size.height = MAX(size.height, minsize.height);
|
||||
else
|
||||
r.size.height=minsize.height;
|
||||
|
||||
r.size.height = minsize.height;
|
||||
}
|
||||
fit_child_in_rect(c,r);
|
||||
fit_child_in_rect(c, r);
|
||||
}
|
||||
update();
|
||||
};
|
||||
|
|
@ -261,37 +247,37 @@ void ScrollContainer::_notification(int p_what) {
|
|||
|
||||
update_scrollbars();
|
||||
|
||||
VisualServer::get_singleton()->canvas_item_set_clip(get_canvas_item(),true);
|
||||
VisualServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), true);
|
||||
}
|
||||
|
||||
if (p_what==NOTIFICATION_FIXED_PROCESS) {
|
||||
if (p_what == NOTIFICATION_FIXED_PROCESS) {
|
||||
|
||||
if (drag_touching) {
|
||||
if (drag_touching) {
|
||||
|
||||
if (drag_touching_deaccel) {
|
||||
|
||||
Vector2 pos = Vector2(h_scroll->get_val(),v_scroll->get_val());
|
||||
pos+=drag_speed*get_fixed_process_delta_time();
|
||||
Vector2 pos = Vector2(h_scroll->get_val(), v_scroll->get_val());
|
||||
pos += drag_speed * get_fixed_process_delta_time();
|
||||
|
||||
bool turnoff_h=false;
|
||||
bool turnoff_v=false;
|
||||
bool turnoff_h = false;
|
||||
bool turnoff_v = false;
|
||||
|
||||
if (pos.x<0) {
|
||||
pos.x=0;
|
||||
turnoff_h=true;
|
||||
if (pos.x < 0) {
|
||||
pos.x = 0;
|
||||
turnoff_h = true;
|
||||
}
|
||||
if (pos.x > (h_scroll->get_max()-h_scroll->get_page())) {
|
||||
pos.x=h_scroll->get_max()-h_scroll->get_page();
|
||||
turnoff_h=true;
|
||||
if (pos.x > (h_scroll->get_max() - h_scroll->get_page())) {
|
||||
pos.x = h_scroll->get_max() - h_scroll->get_page();
|
||||
turnoff_h = true;
|
||||
}
|
||||
|
||||
if (pos.y<0) {
|
||||
pos.y=0;
|
||||
turnoff_v=true;
|
||||
if (pos.y < 0) {
|
||||
pos.y = 0;
|
||||
turnoff_v = true;
|
||||
}
|
||||
if (pos.y > (v_scroll->get_max()-v_scroll->get_page())) {
|
||||
pos.y=v_scroll->get_max()-v_scroll->get_page();
|
||||
turnoff_v=true;
|
||||
if (pos.y > (v_scroll->get_max() - v_scroll->get_page())) {
|
||||
pos.y = v_scroll->get_max() - v_scroll->get_page();
|
||||
turnoff_v = true;
|
||||
}
|
||||
|
||||
if (scroll_h)
|
||||
|
|
@ -299,48 +285,43 @@ void ScrollContainer::_notification(int p_what) {
|
|||
if (scroll_v)
|
||||
v_scroll->set_val(pos.y);
|
||||
|
||||
float sgn_x = drag_speed.x<0? -1 : 1;
|
||||
float sgn_x = drag_speed.x < 0 ? -1 : 1;
|
||||
float val_x = Math::abs(drag_speed.x);
|
||||
val_x-=1000*get_fixed_process_delta_time();
|
||||
val_x -= 1000 * get_fixed_process_delta_time();
|
||||
|
||||
if (val_x<0) {
|
||||
turnoff_h=true;
|
||||
if (val_x < 0) {
|
||||
turnoff_h = true;
|
||||
}
|
||||
|
||||
|
||||
float sgn_y = drag_speed.y<0? -1 : 1;
|
||||
float sgn_y = drag_speed.y < 0 ? -1 : 1;
|
||||
float val_y = Math::abs(drag_speed.y);
|
||||
val_y-=1000*get_fixed_process_delta_time();
|
||||
val_y -= 1000 * get_fixed_process_delta_time();
|
||||
|
||||
if (val_y<0) {
|
||||
turnoff_v=true;
|
||||
if (val_y < 0) {
|
||||
turnoff_v = true;
|
||||
}
|
||||
|
||||
|
||||
drag_speed=Vector2(sgn_x*val_x,sgn_y*val_y);
|
||||
drag_speed = Vector2(sgn_x * val_x, sgn_y * val_y);
|
||||
|
||||
if (turnoff_h && turnoff_v) {
|
||||
set_fixed_process(false);
|
||||
drag_touching=false;
|
||||
drag_touching_deaccel=false;
|
||||
drag_touching = false;
|
||||
drag_touching_deaccel = false;
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
if (time_since_motion==0 || time_since_motion>0.1) {
|
||||
if (time_since_motion == 0 || time_since_motion > 0.1) {
|
||||
|
||||
Vector2 diff = drag_accum - last_drag_accum;
|
||||
last_drag_accum=drag_accum;
|
||||
drag_speed=diff/get_fixed_process_delta_time();
|
||||
last_drag_accum = drag_accum;
|
||||
drag_speed = diff / get_fixed_process_delta_time();
|
||||
}
|
||||
|
||||
time_since_motion+=get_fixed_process_delta_time();
|
||||
time_since_motion += get_fixed_process_delta_time();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
void ScrollContainer::update_scrollbars() {
|
||||
|
|
@ -355,66 +336,62 @@ void ScrollContainer::update_scrollbars() {
|
|||
if (!scroll_v || min.height <= size.height - hmin.height) {
|
||||
|
||||
v_scroll->hide();
|
||||
scroll.y=0;
|
||||
scroll.y = 0;
|
||||
} else {
|
||||
|
||||
v_scroll->show();
|
||||
scroll.y=v_scroll->get_val();
|
||||
|
||||
scroll.y = v_scroll->get_val();
|
||||
}
|
||||
|
||||
v_scroll->set_max(min.height);
|
||||
v_scroll->set_page(size.height - hmin.height);
|
||||
|
||||
|
||||
if (!scroll_h || min.width <= size.width - vmin.width) {
|
||||
|
||||
h_scroll->hide();
|
||||
scroll.x=0;
|
||||
scroll.x = 0;
|
||||
} else {
|
||||
|
||||
h_scroll->show();
|
||||
h_scroll->set_max(min.width);
|
||||
h_scroll->set_page(size.width - vmin.width);
|
||||
scroll.x=h_scroll->get_val();
|
||||
scroll.x = h_scroll->get_val();
|
||||
}
|
||||
}
|
||||
|
||||
void ScrollContainer::_scroll_moved(float) {
|
||||
|
||||
scroll.x=h_scroll->get_val();
|
||||
scroll.y=v_scroll->get_val();
|
||||
scroll.x = h_scroll->get_val();
|
||||
scroll.y = v_scroll->get_val();
|
||||
queue_sort();
|
||||
|
||||
update();
|
||||
};
|
||||
|
||||
|
||||
void ScrollContainer::set_enable_h_scroll(bool p_enable) {
|
||||
|
||||
scroll_h=p_enable;
|
||||
scroll_h = p_enable;
|
||||
queue_sort();
|
||||
}
|
||||
|
||||
bool ScrollContainer::is_h_scroll_enabled() const{
|
||||
bool ScrollContainer::is_h_scroll_enabled() const {
|
||||
|
||||
return scroll_h;
|
||||
}
|
||||
|
||||
void ScrollContainer::set_enable_v_scroll(bool p_enable) {
|
||||
|
||||
scroll_v=p_enable;
|
||||
scroll_v = p_enable;
|
||||
queue_sort();
|
||||
}
|
||||
|
||||
bool ScrollContainer::is_v_scroll_enabled() const{
|
||||
bool ScrollContainer::is_v_scroll_enabled() const {
|
||||
|
||||
return scroll_v;
|
||||
}
|
||||
|
||||
int ScrollContainer::get_v_scroll() const {
|
||||
|
||||
|
||||
return v_scroll->get_val();
|
||||
}
|
||||
void ScrollContainer::set_v_scroll(int p_pos) {
|
||||
|
|
@ -431,27 +408,24 @@ void ScrollContainer::set_h_scroll(int p_pos) {
|
|||
|
||||
h_scroll->set_val(p_pos);
|
||||
_cancel_drag();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ScrollContainer::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("_scroll_moved"),&ScrollContainer::_scroll_moved);
|
||||
ObjectTypeDB::bind_method(_MD("_input_event"),&ScrollContainer::_input_event);
|
||||
ObjectTypeDB::bind_method(_MD("set_enable_h_scroll","enable"),&ScrollContainer::set_enable_h_scroll);
|
||||
ObjectTypeDB::bind_method(_MD("is_h_scroll_enabled"),&ScrollContainer::is_h_scroll_enabled);
|
||||
ObjectTypeDB::bind_method(_MD("set_enable_v_scroll","enable"),&ScrollContainer::set_enable_v_scroll);
|
||||
ObjectTypeDB::bind_method(_MD("is_v_scroll_enabled"),&ScrollContainer::is_v_scroll_enabled);
|
||||
ObjectTypeDB::bind_method(_MD("_update_scrollbar_pos"),&ScrollContainer::_update_scrollbar_pos);
|
||||
ObjectTypeDB::bind_method(_MD("set_h_scroll","val"),&ScrollContainer::set_h_scroll);
|
||||
ObjectTypeDB::bind_method(_MD("get_h_scroll"),&ScrollContainer::get_h_scroll);
|
||||
ObjectTypeDB::bind_method(_MD("set_v_scroll","val"),&ScrollContainer::set_v_scroll);
|
||||
ObjectTypeDB::bind_method(_MD("get_v_scroll"),&ScrollContainer::get_v_scroll);
|
||||
|
||||
ADD_PROPERTY( PropertyInfo( Variant::BOOL, "scroll/horizontal"), _SCS("set_enable_h_scroll"),_SCS("is_h_scroll_enabled"));
|
||||
ADD_PROPERTY( PropertyInfo( Variant::BOOL, "scroll/vertical"), _SCS("set_enable_v_scroll"),_SCS("is_v_scroll_enabled"));
|
||||
ObjectTypeDB::bind_method(_MD("_scroll_moved"), &ScrollContainer::_scroll_moved);
|
||||
ObjectTypeDB::bind_method(_MD("_input_event"), &ScrollContainer::_input_event);
|
||||
ObjectTypeDB::bind_method(_MD("set_enable_h_scroll", "enable"), &ScrollContainer::set_enable_h_scroll);
|
||||
ObjectTypeDB::bind_method(_MD("is_h_scroll_enabled"), &ScrollContainer::is_h_scroll_enabled);
|
||||
ObjectTypeDB::bind_method(_MD("set_enable_v_scroll", "enable"), &ScrollContainer::set_enable_v_scroll);
|
||||
ObjectTypeDB::bind_method(_MD("is_v_scroll_enabled"), &ScrollContainer::is_v_scroll_enabled);
|
||||
ObjectTypeDB::bind_method(_MD("_update_scrollbar_pos"), &ScrollContainer::_update_scrollbar_pos);
|
||||
ObjectTypeDB::bind_method(_MD("set_h_scroll", "val"), &ScrollContainer::set_h_scroll);
|
||||
ObjectTypeDB::bind_method(_MD("get_h_scroll"), &ScrollContainer::get_h_scroll);
|
||||
ObjectTypeDB::bind_method(_MD("set_v_scroll", "val"), &ScrollContainer::set_v_scroll);
|
||||
ObjectTypeDB::bind_method(_MD("get_v_scroll"), &ScrollContainer::get_v_scroll);
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "scroll/horizontal"), _SCS("set_enable_h_scroll"), _SCS("is_h_scroll_enabled"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "scroll/vertical"), _SCS("set_enable_v_scroll"), _SCS("is_v_scroll_enabled"));
|
||||
};
|
||||
|
||||
ScrollContainer::ScrollContainer() {
|
||||
|
|
@ -464,15 +438,12 @@ ScrollContainer::ScrollContainer() {
|
|||
v_scroll->set_name("_v_scroll");
|
||||
add_child(v_scroll);
|
||||
|
||||
h_scroll->connect("value_changed", this,"_scroll_moved");
|
||||
v_scroll->connect("value_changed", this,"_scroll_moved");
|
||||
|
||||
drag_speed=Vector2();
|
||||
drag_touching=false;
|
||||
drag_touching_deaccel=false;
|
||||
scroll_h=true;
|
||||
scroll_v=true;
|
||||
|
||||
h_scroll->connect("value_changed", this, "_scroll_moved");
|
||||
v_scroll->connect("value_changed", this, "_scroll_moved");
|
||||
|
||||
drag_speed = Vector2();
|
||||
drag_touching = false;
|
||||
drag_touching_deaccel = false;
|
||||
scroll_h = true;
|
||||
scroll_v = true;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -37,8 +37,8 @@ class ScrollContainer : public Container {
|
|||
|
||||
OBJ_TYPE(ScrollContainer, Container);
|
||||
|
||||
HScrollBar* h_scroll;
|
||||
VScrollBar* v_scroll;
|
||||
HScrollBar *h_scroll;
|
||||
VScrollBar *v_scroll;
|
||||
|
||||
Size2 child_max_size;
|
||||
Size2 scroll;
|
||||
|
|
@ -63,16 +63,15 @@ class ScrollContainer : public Container {
|
|||
protected:
|
||||
Size2 get_minimum_size() const;
|
||||
|
||||
|
||||
void _input_event(const InputEvent& p_input_event);
|
||||
void _input_event(const InputEvent &p_input_event);
|
||||
void _notification(int p_what);
|
||||
|
||||
void _scroll_moved(float);
|
||||
static void _bind_methods();
|
||||
|
||||
void _update_scrollbar_pos();
|
||||
public:
|
||||
|
||||
public:
|
||||
int get_v_scroll() const;
|
||||
void set_v_scroll(int p_pos);
|
||||
|
||||
|
|
|
|||
|
|
@ -28,54 +28,47 @@
|
|||
/*************************************************************************/
|
||||
#include "separator.h"
|
||||
|
||||
|
||||
Size2 Separator::get_minimum_size() const {
|
||||
|
||||
Size2 ms(3,3);
|
||||
ms[orientation]=get_constant("separation");
|
||||
Size2 ms(3, 3);
|
||||
ms[orientation] = get_constant("separation");
|
||||
return ms;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Separator::_notification(int p_what) {
|
||||
|
||||
|
||||
switch(p_what) {
|
||||
switch (p_what) {
|
||||
|
||||
case NOTIFICATION_DRAW: {
|
||||
|
||||
Size2i size = get_size();
|
||||
Ref<StyleBox> style = get_stylebox("separator");
|
||||
Size2i ssize=style->get_minimum_size()+style->get_center_size();
|
||||
Size2i ssize = style->get_minimum_size() + style->get_center_size();
|
||||
|
||||
if (orientation==VERTICAL) {
|
||||
if (orientation == VERTICAL) {
|
||||
|
||||
style->draw(get_canvas_item(),Rect2( (size.x-ssize.x)/2,0,ssize.x,size.y ));
|
||||
style->draw(get_canvas_item(), Rect2((size.x - ssize.x) / 2, 0, ssize.x, size.y));
|
||||
} else {
|
||||
|
||||
style->draw(get_canvas_item(),Rect2( 0,(size.y-ssize.y)/2,size.x,ssize.y ));
|
||||
style->draw(get_canvas_item(), Rect2(0, (size.y - ssize.y) / 2, size.x, ssize.y));
|
||||
}
|
||||
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
Separator::Separator()
|
||||
{
|
||||
Separator::Separator() {
|
||||
}
|
||||
|
||||
|
||||
Separator::~Separator()
|
||||
{
|
||||
Separator::~Separator() {
|
||||
}
|
||||
|
||||
HSeparator::HSeparator() {
|
||||
|
||||
orientation=HORIZONTAL;
|
||||
orientation = HORIZONTAL;
|
||||
}
|
||||
|
||||
VSeparator::VSeparator() {
|
||||
|
||||
orientation=VERTICAL;
|
||||
orientation = VERTICAL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,40 +36,33 @@
|
|||
#include "scene/gui/control.h"
|
||||
class Separator : public Control {
|
||||
|
||||
OBJ_TYPE( Separator, Control );
|
||||
|
||||
OBJ_TYPE(Separator, Control);
|
||||
|
||||
protected:
|
||||
|
||||
Orientation orientation;
|
||||
void _notification(int p_what);
|
||||
public:
|
||||
|
||||
public:
|
||||
virtual Size2 get_minimum_size() const;
|
||||
|
||||
Separator();
|
||||
~Separator();
|
||||
|
||||
};
|
||||
|
||||
class VSeparator : public Separator {
|
||||
|
||||
OBJ_TYPE( VSeparator, Separator );
|
||||
OBJ_TYPE(VSeparator, Separator);
|
||||
|
||||
public:
|
||||
|
||||
VSeparator();
|
||||
|
||||
};
|
||||
|
||||
class HSeparator : public Separator {
|
||||
|
||||
OBJ_TYPE( HSeparator, Separator );
|
||||
OBJ_TYPE(HSeparator, Separator);
|
||||
|
||||
public:
|
||||
|
||||
HSeparator();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -29,91 +29,88 @@
|
|||
#include "slider.h"
|
||||
#include "os/keyboard.h"
|
||||
|
||||
|
||||
Size2 Slider::get_minimum_size() const {
|
||||
|
||||
Ref<StyleBox> style = get_stylebox("slider");
|
||||
Size2i ms = style->get_minimum_size()+style->get_center_size();
|
||||
Size2i ms = style->get_minimum_size() + style->get_center_size();
|
||||
return ms;
|
||||
}
|
||||
|
||||
void Slider::_input_event(InputEvent p_event) {
|
||||
|
||||
|
||||
|
||||
if (p_event.type==InputEvent::MOUSE_BUTTON) {
|
||||
if (p_event.type == InputEvent::MOUSE_BUTTON) {
|
||||
|
||||
InputEventMouseButton &mb = p_event.mouse_button;
|
||||
if (mb.button_index==BUTTON_LEFT) {
|
||||
if (mb.button_index == BUTTON_LEFT) {
|
||||
|
||||
if (mb.pressed) {
|
||||
Ref<Texture> grabber = get_icon(mouse_inside||has_focus()?"grabber_hilite":"grabber");
|
||||
grab.pos=orientation==VERTICAL?mb.y:mb.x;
|
||||
if (mb.pressed) {
|
||||
Ref<Texture> grabber = get_icon(mouse_inside || has_focus() ? "grabber_hilite" : "grabber");
|
||||
grab.pos = orientation == VERTICAL ? mb.y : mb.x;
|
||||
double grab_width = (double)grabber->get_size().width;
|
||||
double grab_height = (double)grabber->get_size().height;
|
||||
double max = orientation==VERTICAL ? get_size().height - grab_height : get_size().width - grab_width;
|
||||
if (orientation==VERTICAL)
|
||||
set_unit_value( 1 - (((double)grab.pos - (grab_height / 2.0)) / max) );
|
||||
double max = orientation == VERTICAL ? get_size().height - grab_height : get_size().width - grab_width;
|
||||
if (orientation == VERTICAL)
|
||||
set_unit_value(1 - (((double)grab.pos - (grab_height / 2.0)) / max));
|
||||
else
|
||||
set_unit_value(((double)grab.pos - (grab_width/2.0)) / max);
|
||||
grab.active=true;
|
||||
grab.uvalue=get_unit_value();
|
||||
set_unit_value(((double)grab.pos - (grab_width / 2.0)) / max);
|
||||
grab.active = true;
|
||||
grab.uvalue = get_unit_value();
|
||||
} else {
|
||||
grab.active=false;
|
||||
grab.active = false;
|
||||
}
|
||||
} else if (mb.pressed && mb.button_index==BUTTON_WHEEL_UP) {
|
||||
} else if (mb.pressed && mb.button_index == BUTTON_WHEEL_UP) {
|
||||
|
||||
set_val( get_val() + get_step());
|
||||
} else if (mb.pressed && mb.button_index==BUTTON_WHEEL_DOWN) {
|
||||
set_val( get_val() - get_step());
|
||||
set_val(get_val() + get_step());
|
||||
} else if (mb.pressed && mb.button_index == BUTTON_WHEEL_DOWN) {
|
||||
set_val(get_val() - get_step());
|
||||
}
|
||||
|
||||
} else if (p_event.type==InputEvent::MOUSE_MOTION) {
|
||||
} else if (p_event.type == InputEvent::MOUSE_MOTION) {
|
||||
|
||||
if (grab.active) {
|
||||
|
||||
Size2i size = get_size();
|
||||
Ref<Texture> grabber = get_icon("grabber");
|
||||
float motion = (orientation==VERTICAL?p_event.mouse_motion.y:p_event.mouse_motion.x) - grab.pos;
|
||||
if (orientation==VERTICAL)
|
||||
motion=-motion;
|
||||
float areasize = orientation==VERTICAL?size.height - grabber->get_size().height:size.width - grabber->get_size().width;
|
||||
if (areasize<=0)
|
||||
float motion = (orientation == VERTICAL ? p_event.mouse_motion.y : p_event.mouse_motion.x) - grab.pos;
|
||||
if (orientation == VERTICAL)
|
||||
motion = -motion;
|
||||
float areasize = orientation == VERTICAL ? size.height - grabber->get_size().height : size.width - grabber->get_size().width;
|
||||
if (areasize <= 0)
|
||||
return;
|
||||
float umotion = motion / float(areasize);
|
||||
set_unit_value( grab.uvalue + umotion );
|
||||
set_unit_value(grab.uvalue + umotion);
|
||||
}
|
||||
} else {
|
||||
|
||||
if (p_event.is_action("ui_left") && p_event.is_pressed()) {
|
||||
|
||||
if (orientation!=HORIZONTAL)
|
||||
if (orientation != HORIZONTAL)
|
||||
return;
|
||||
set_val( get_val() - (custom_step>=0?custom_step:get_step()) );
|
||||
set_val(get_val() - (custom_step >= 0 ? custom_step : get_step()));
|
||||
accept_event();
|
||||
} else if (p_event.is_action("ui_right") && p_event.is_pressed()) {
|
||||
|
||||
if (orientation!=HORIZONTAL)
|
||||
if (orientation != HORIZONTAL)
|
||||
return;
|
||||
set_val( get_val() + (custom_step>=0?custom_step:get_step()) );
|
||||
set_val(get_val() + (custom_step >= 0 ? custom_step : get_step()));
|
||||
accept_event();
|
||||
} else if (p_event.is_action("ui_up") && p_event.is_pressed()) {
|
||||
|
||||
if (orientation!=VERTICAL)
|
||||
if (orientation != VERTICAL)
|
||||
return;
|
||||
|
||||
set_val( get_val() + (custom_step>=0?custom_step:get_step()) );
|
||||
set_val(get_val() + (custom_step >= 0 ? custom_step : get_step()));
|
||||
accept_event();
|
||||
} else if (p_event.is_action("ui_down") && p_event.is_pressed()) {
|
||||
|
||||
if (orientation!=VERTICAL)
|
||||
if (orientation != VERTICAL)
|
||||
return;
|
||||
set_val( get_val() - (custom_step>=0?custom_step:get_step()) );
|
||||
set_val(get_val() - (custom_step >= 0 ? custom_step : get_step()));
|
||||
accept_event();
|
||||
|
||||
} else if (p_event.type==InputEvent::KEY) {
|
||||
} else if (p_event.type == InputEvent::KEY) {
|
||||
|
||||
const InputEventKey &k=p_event.key;
|
||||
const InputEventKey &k = p_event.key;
|
||||
|
||||
if (!k.pressed)
|
||||
return;
|
||||
|
|
@ -122,35 +119,32 @@ void Slider::_input_event(InputEvent p_event) {
|
|||
|
||||
case KEY_HOME: {
|
||||
|
||||
set_val( get_min() );
|
||||
set_val(get_min());
|
||||
accept_event();
|
||||
} break;
|
||||
case KEY_END: {
|
||||
|
||||
set_val( get_max() );
|
||||
set_val(get_max());
|
||||
accept_event();
|
||||
|
||||
} break;
|
||||
|
||||
} ;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Slider::_notification(int p_what) {
|
||||
|
||||
|
||||
switch(p_what) {
|
||||
switch (p_what) {
|
||||
|
||||
case NOTIFICATION_MOUSE_ENTER: {
|
||||
|
||||
mouse_inside=true;
|
||||
mouse_inside = true;
|
||||
update();
|
||||
} break;
|
||||
case NOTIFICATION_MOUSE_EXIT: {
|
||||
|
||||
mouse_inside=false;
|
||||
mouse_inside = false;
|
||||
update();
|
||||
} break;
|
||||
case NOTIFICATION_DRAW: {
|
||||
|
|
@ -158,41 +152,39 @@ void Slider::_notification(int p_what) {
|
|||
Size2i size = get_size();
|
||||
Ref<StyleBox> style = get_stylebox("slider");
|
||||
Ref<StyleBox> focus = get_stylebox("focus");
|
||||
Ref<Texture> grabber = get_icon(mouse_inside||has_focus()?"grabber_hilite":"grabber");
|
||||
Ref<Texture> grabber = get_icon(mouse_inside || has_focus() ? "grabber_hilite" : "grabber");
|
||||
Ref<Texture> tick = get_icon("tick");
|
||||
|
||||
if (orientation==VERTICAL) {
|
||||
if (orientation == VERTICAL) {
|
||||
|
||||
style->draw(ci,Rect2i(Point2i(),Size2i(style->get_minimum_size().width+style->get_center_size().width,size.height)));
|
||||
style->draw(ci, Rect2i(Point2i(), Size2i(style->get_minimum_size().width + style->get_center_size().width, size.height)));
|
||||
//if (mouse_inside||has_focus())
|
||||
// focus->draw(ci,Rect2i(Point2i(),Size2i(style->get_minimum_size().width+style->get_center_size().width,size.height)));
|
||||
float areasize = size.height - grabber->get_size().height;
|
||||
if (ticks>1) {
|
||||
if (ticks > 1) {
|
||||
int tickarea = size.height - tick->get_height();
|
||||
for(int i=0;i<ticks;i++) {
|
||||
if( ! ticks_on_borders && (i == 0 || i + 1 == ticks) ) continue;
|
||||
int ofs = i*tickarea/(ticks-1);
|
||||
tick->draw(ci,Point2(0,ofs));
|
||||
for (int i = 0; i < ticks; i++) {
|
||||
if (!ticks_on_borders && (i == 0 || i + 1 == ticks)) continue;
|
||||
int ofs = i * tickarea / (ticks - 1);
|
||||
tick->draw(ci, Point2(0, ofs));
|
||||
}
|
||||
|
||||
}
|
||||
grabber->draw(ci,Point2i(size.width/2-grabber->get_size().width/2,size.height - get_unit_value()*areasize - grabber->get_size().height));
|
||||
grabber->draw(ci, Point2i(size.width / 2 - grabber->get_size().width / 2, size.height - get_unit_value() * areasize - grabber->get_size().height));
|
||||
} else {
|
||||
style->draw(ci,Rect2i(Point2i(),Size2i(size.width,style->get_minimum_size().height+style->get_center_size().height)));
|
||||
style->draw(ci, Rect2i(Point2i(), Size2i(size.width, style->get_minimum_size().height + style->get_center_size().height)));
|
||||
//if (mouse_inside||has_focus())
|
||||
// focus->draw(ci,Rect2i(Point2i(),Size2i(size.width,style->get_minimum_size().height+style->get_center_size().height)));
|
||||
|
||||
float areasize = size.width - grabber->get_size().width;
|
||||
if (ticks>1) {
|
||||
if (ticks > 1) {
|
||||
int tickarea = size.width - tick->get_width();
|
||||
for(int i=0;i<ticks;i++) {
|
||||
if( (! ticks_on_borders) && ( (i == 0) || ((i + 1) == ticks)) ) continue;
|
||||
int ofs = i*tickarea/(ticks-1);
|
||||
tick->draw(ci,Point2(ofs,0));
|
||||
for (int i = 0; i < ticks; i++) {
|
||||
if ((!ticks_on_borders) && ((i == 0) || ((i + 1) == ticks))) continue;
|
||||
int ofs = i * tickarea / (ticks - 1);
|
||||
tick->draw(ci, Point2(ofs, 0));
|
||||
}
|
||||
|
||||
}
|
||||
grabber->draw(ci,Point2i(get_unit_value()*areasize,size.height/2-grabber->get_size().height/2));
|
||||
grabber->draw(ci, Point2i(get_unit_value() * areasize, size.height / 2 - grabber->get_size().height / 2));
|
||||
}
|
||||
|
||||
} break;
|
||||
|
|
@ -201,7 +193,7 @@ void Slider::_notification(int p_what) {
|
|||
|
||||
void Slider::set_custom_step(float p_custom_step) {
|
||||
|
||||
custom_step=p_custom_step;
|
||||
custom_step = p_custom_step;
|
||||
}
|
||||
|
||||
float Slider::get_custom_step() const {
|
||||
|
|
@ -211,7 +203,7 @@ float Slider::get_custom_step() const {
|
|||
|
||||
void Slider::set_ticks(int p_count) {
|
||||
|
||||
ticks=p_count;
|
||||
ticks = p_count;
|
||||
update();
|
||||
}
|
||||
|
||||
|
|
@ -220,35 +212,34 @@ int Slider::get_ticks() const {
|
|||
return ticks;
|
||||
}
|
||||
|
||||
bool Slider::get_ticks_on_borders() const{
|
||||
bool Slider::get_ticks_on_borders() const {
|
||||
return ticks_on_borders;
|
||||
}
|
||||
|
||||
void Slider::set_ticks_on_borders(bool _tob){
|
||||
void Slider::set_ticks_on_borders(bool _tob) {
|
||||
ticks_on_borders = _tob;
|
||||
update();
|
||||
}
|
||||
|
||||
void Slider::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("_input_event"),&Slider::_input_event);
|
||||
ObjectTypeDB::bind_method(_MD("set_ticks","count"),&Slider::set_ticks);
|
||||
ObjectTypeDB::bind_method(_MD("get_ticks"),&Slider::get_ticks);
|
||||
ObjectTypeDB::bind_method(_MD("_input_event"), &Slider::_input_event);
|
||||
ObjectTypeDB::bind_method(_MD("set_ticks", "count"), &Slider::set_ticks);
|
||||
ObjectTypeDB::bind_method(_MD("get_ticks"), &Slider::get_ticks);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("get_ticks_on_borders"),&Slider::get_ticks_on_borders);
|
||||
ObjectTypeDB::bind_method(_MD("set_ticks_on_borders","ticks_on_border"),&Slider::set_ticks_on_borders);
|
||||
|
||||
ADD_PROPERTY( PropertyInfo( Variant::INT, "tick_count", PROPERTY_HINT_RANGE,"0,4096,1"), _SCS("set_ticks"), _SCS("get_ticks") );
|
||||
ADD_PROPERTY( PropertyInfo( Variant::BOOL, "ticks_on_borders" ), _SCS("set_ticks_on_borders"), _SCS("get_ticks_on_borders") );
|
||||
ADD_PROPERTY( PropertyInfo( Variant::INT,"focus_mode", PROPERTY_HINT_ENUM, "None,Click,All" ), _SCS("set_focus_mode"), _SCS("get_focus_mode") );
|
||||
ObjectTypeDB::bind_method(_MD("get_ticks_on_borders"), &Slider::get_ticks_on_borders);
|
||||
ObjectTypeDB::bind_method(_MD("set_ticks_on_borders", "ticks_on_border"), &Slider::set_ticks_on_borders);
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "tick_count", PROPERTY_HINT_RANGE, "0,4096,1"), _SCS("set_ticks"), _SCS("get_ticks"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ticks_on_borders"), _SCS("set_ticks_on_borders"), _SCS("get_ticks_on_borders"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "focus_mode", PROPERTY_HINT_ENUM, "None,Click,All"), _SCS("set_focus_mode"), _SCS("get_focus_mode"));
|
||||
}
|
||||
|
||||
Slider::Slider(Orientation p_orientation) {
|
||||
orientation=p_orientation;
|
||||
mouse_inside=false;
|
||||
grab.active=false;
|
||||
ticks=0;
|
||||
custom_step=-1;
|
||||
orientation = p_orientation;
|
||||
mouse_inside = false;
|
||||
grab.active = false;
|
||||
ticks = 0;
|
||||
custom_step = -1;
|
||||
set_focus_mode(FOCUS_ALL);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
class Slider : public Range {
|
||||
|
||||
OBJ_TYPE( Slider, Range );
|
||||
OBJ_TYPE(Slider, Range);
|
||||
|
||||
struct Grab {
|
||||
int pos;
|
||||
|
|
@ -46,16 +46,13 @@ class Slider : public Range {
|
|||
Orientation orientation;
|
||||
float custom_step;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
void _input_event(InputEvent p_event);
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
bool ticks_on_borders;
|
||||
|
||||
public:
|
||||
|
||||
virtual Size2 get_minimum_size() const;
|
||||
|
||||
void set_custom_step(float p_custom_step);
|
||||
|
|
@ -67,25 +64,25 @@ public:
|
|||
void set_ticks_on_borders(bool);
|
||||
bool get_ticks_on_borders() const;
|
||||
|
||||
Slider(Orientation p_orientation=VERTICAL);
|
||||
Slider(Orientation p_orientation = VERTICAL);
|
||||
};
|
||||
|
||||
|
||||
|
||||
class HSlider : public Slider {
|
||||
|
||||
OBJ_TYPE( HSlider, Slider );
|
||||
public:
|
||||
OBJ_TYPE(HSlider, Slider);
|
||||
|
||||
HSlider() : Slider(HORIZONTAL) { set_v_size_flags(0);}
|
||||
public:
|
||||
HSlider()
|
||||
: Slider(HORIZONTAL) { set_v_size_flags(0); }
|
||||
};
|
||||
|
||||
class VSlider : public Slider {
|
||||
|
||||
OBJ_TYPE( VSlider, Slider );
|
||||
public:
|
||||
OBJ_TYPE(VSlider, Slider);
|
||||
|
||||
VSlider() : Slider(VERTICAL) { set_h_size_flags(0);}
|
||||
public:
|
||||
VSlider()
|
||||
: Slider(VERTICAL) { set_h_size_flags(0); }
|
||||
};
|
||||
|
||||
#endif // SLIDER_H
|
||||
|
|
|
|||
|
|
@ -32,51 +32,45 @@
|
|||
Size2 SpinBox::get_minimum_size() const {
|
||||
|
||||
Size2 ms = line_edit->get_combined_minimum_size();
|
||||
ms.width+=last_w;
|
||||
ms.width += last_w;
|
||||
return ms;
|
||||
}
|
||||
|
||||
|
||||
void SpinBox::_value_changed(double) {
|
||||
|
||||
String value = String::num(get_val(),Math::step_decimals(get_step()));
|
||||
if (prefix!="")
|
||||
value=prefix+" "+value;
|
||||
if (suffix!="")
|
||||
value+=" "+suffix;
|
||||
String value = String::num(get_val(), Math::step_decimals(get_step()));
|
||||
if (prefix != "")
|
||||
value = prefix + " " + value;
|
||||
if (suffix != "")
|
||||
value += " " + suffix;
|
||||
line_edit->set_text(value);
|
||||
}
|
||||
|
||||
void SpinBox::_text_entered(const String& p_string) {
|
||||
void SpinBox::_text_entered(const String &p_string) {
|
||||
|
||||
//if (!p_string.is_numeric())
|
||||
// return;
|
||||
String value = p_string;
|
||||
if (prefix!="" && p_string.begins_with(prefix))
|
||||
value = p_string.substr(prefix.length(), p_string.length()-prefix.length());
|
||||
set_val( value.to_double() );
|
||||
if (prefix != "" && p_string.begins_with(prefix))
|
||||
value = p_string.substr(prefix.length(), p_string.length() - prefix.length());
|
||||
set_val(value.to_double());
|
||||
_value_changed(0);
|
||||
}
|
||||
|
||||
|
||||
LineEdit *SpinBox::get_line_edit() {
|
||||
|
||||
return line_edit;
|
||||
}
|
||||
|
||||
|
||||
void SpinBox::_line_edit_input(const InputEvent& p_event) {
|
||||
|
||||
|
||||
|
||||
void SpinBox::_line_edit_input(const InputEvent &p_event) {
|
||||
}
|
||||
|
||||
void SpinBox::_range_click_timeout() {
|
||||
|
||||
if (!drag.enabled && Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) {
|
||||
|
||||
bool up = get_local_mouse_pos().y < (get_size().height/2);
|
||||
set_val( get_val() + (up?get_step():-get_step()));
|
||||
bool up = get_local_mouse_pos().y < (get_size().height / 2);
|
||||
set_val(get_val() + (up ? get_step() : -get_step()));
|
||||
|
||||
if (range_click_timer->is_one_shot()) {
|
||||
range_click_timer->set_wait_time(0.075);
|
||||
|
|
@ -89,23 +83,21 @@ void SpinBox::_range_click_timeout() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void SpinBox::_input_event(const InputEvent& p_event) {
|
||||
void SpinBox::_input_event(const InputEvent &p_event) {
|
||||
|
||||
if (!is_editable()) {
|
||||
return;
|
||||
}
|
||||
if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.pressed) {
|
||||
const InputEventMouseButton &mb=p_event.mouse_button;
|
||||
if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.pressed) {
|
||||
const InputEventMouseButton &mb = p_event.mouse_button;
|
||||
|
||||
bool up = mb.y < (get_size().height / 2);
|
||||
|
||||
bool up = mb.y < (get_size().height/2);
|
||||
|
||||
switch(mb.button_index) {
|
||||
switch (mb.button_index) {
|
||||
|
||||
case BUTTON_LEFT: {
|
||||
|
||||
set_val( get_val() + (up?get_step():-get_step()));
|
||||
set_val(get_val() + (up ? get_step() : -get_step()));
|
||||
|
||||
range_click_timer->set_wait_time(0.6);
|
||||
range_click_timer->set_one_shot(true);
|
||||
|
|
@ -115,70 +107,68 @@ void SpinBox::_input_event(const InputEvent& p_event) {
|
|||
} break;
|
||||
case BUTTON_RIGHT: {
|
||||
|
||||
set_val( (up?get_max():get_min()) );
|
||||
set_val((up ? get_max() : get_min()));
|
||||
line_edit->grab_focus();
|
||||
} break;
|
||||
case BUTTON_WHEEL_UP: {
|
||||
if (line_edit->has_focus()) {
|
||||
set_val( get_val() + get_step() );
|
||||
set_val(get_val() + get_step());
|
||||
accept_event();
|
||||
}
|
||||
} break;
|
||||
case BUTTON_WHEEL_DOWN: {
|
||||
if (line_edit->has_focus()) {
|
||||
set_val( get_val() - get_step() );
|
||||
set_val(get_val() - get_step());
|
||||
accept_event();
|
||||
}
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.pressed && p_event.mouse_button.button_index==1) {
|
||||
if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.pressed && p_event.mouse_button.button_index == 1) {
|
||||
|
||||
//set_default_cursor_shape(CURSOR_VSIZE);
|
||||
Vector2 cpos = Vector2(p_event.mouse_button.x,p_event.mouse_button.y);
|
||||
drag.mouse_pos=cpos;
|
||||
Vector2 cpos = Vector2(p_event.mouse_button.x, p_event.mouse_button.y);
|
||||
drag.mouse_pos = cpos;
|
||||
}
|
||||
|
||||
if (p_event.type==InputEvent::MOUSE_BUTTON && !p_event.mouse_button.pressed && p_event.mouse_button.button_index==1) {
|
||||
if (p_event.type == InputEvent::MOUSE_BUTTON && !p_event.mouse_button.pressed && p_event.mouse_button.button_index == 1) {
|
||||
|
||||
//set_default_cursor_shape(CURSOR_ARROW);
|
||||
range_click_timer->stop();
|
||||
|
||||
if (drag.enabled) {
|
||||
drag.enabled=false;
|
||||
drag.enabled = false;
|
||||
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);
|
||||
warp_mouse(drag.capture_pos);
|
||||
}
|
||||
}
|
||||
|
||||
if (p_event.type==InputEvent::MOUSE_MOTION && p_event.mouse_button.button_mask&1) {
|
||||
if (p_event.type == InputEvent::MOUSE_MOTION && p_event.mouse_button.button_mask & 1) {
|
||||
|
||||
Vector2 cpos = Vector2(p_event.mouse_motion.x,p_event.mouse_motion.y);
|
||||
Vector2 cpos = Vector2(p_event.mouse_motion.x, p_event.mouse_motion.y);
|
||||
if (drag.enabled) {
|
||||
|
||||
float diff_y = drag.mouse_pos.y - cpos.y;
|
||||
diff_y=Math::pow(ABS(diff_y),1.8)*SGN(diff_y);
|
||||
diff_y*=0.1;
|
||||
diff_y = Math::pow(ABS(diff_y), 1.8) * SGN(diff_y);
|
||||
diff_y *= 0.1;
|
||||
|
||||
drag.mouse_pos=cpos;
|
||||
drag.base_val=CLAMP(drag.base_val + get_step() * diff_y, get_min(), get_max());
|
||||
drag.mouse_pos = cpos;
|
||||
drag.base_val = CLAMP(drag.base_val + get_step() * diff_y, get_min(), get_max());
|
||||
|
||||
set_val( drag.base_val);
|
||||
set_val(drag.base_val);
|
||||
|
||||
} else if (drag.mouse_pos.distance_to(cpos)>2) {
|
||||
} else if (drag.mouse_pos.distance_to(cpos) > 2) {
|
||||
|
||||
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED);
|
||||
drag.enabled=true;
|
||||
drag.base_val=get_val();
|
||||
drag.mouse_pos=cpos;
|
||||
drag.capture_pos=cpos;
|
||||
|
||||
drag.enabled = true;
|
||||
drag.base_val = get_val();
|
||||
drag.mouse_pos = cpos;
|
||||
drag.capture_pos = cpos;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SpinBox::_line_edit_focus_exit() {
|
||||
|
||||
_text_entered(line_edit->get_text());
|
||||
|
|
@ -186,54 +176,48 @@ void SpinBox::_line_edit_focus_exit() {
|
|||
|
||||
void SpinBox::_notification(int p_what) {
|
||||
|
||||
if (p_what==NOTIFICATION_DRAW) {
|
||||
if (p_what == NOTIFICATION_DRAW) {
|
||||
|
||||
Ref<Texture> updown = get_icon("updown");
|
||||
|
||||
int w = updown->get_width();
|
||||
if (w!=last_w) {
|
||||
line_edit->set_margin(MARGIN_RIGHT,w);
|
||||
last_w=w;
|
||||
if (w != last_w) {
|
||||
line_edit->set_margin(MARGIN_RIGHT, w);
|
||||
last_w = w;
|
||||
}
|
||||
|
||||
RID ci = get_canvas_item();
|
||||
Size2i size = get_size();
|
||||
|
||||
updown->draw(ci,Point2i(size.width-updown->get_width(),(size.height-updown->get_height())/2));
|
||||
|
||||
} else if (p_what==NOTIFICATION_FOCUS_EXIT) {
|
||||
updown->draw(ci, Point2i(size.width - updown->get_width(), (size.height - updown->get_height()) / 2));
|
||||
|
||||
} else if (p_what == NOTIFICATION_FOCUS_EXIT) {
|
||||
|
||||
//_value_changed(0);
|
||||
} else if (p_what==NOTIFICATION_ENTER_TREE) {
|
||||
} else if (p_what == NOTIFICATION_ENTER_TREE) {
|
||||
|
||||
_value_changed(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SpinBox::set_suffix(const String &p_suffix) {
|
||||
|
||||
void SpinBox::set_suffix(const String& p_suffix) {
|
||||
|
||||
suffix=p_suffix;
|
||||
suffix = p_suffix;
|
||||
_value_changed(0);
|
||||
|
||||
}
|
||||
|
||||
String SpinBox::get_suffix() const{
|
||||
String SpinBox::get_suffix() const {
|
||||
|
||||
return suffix;
|
||||
}
|
||||
|
||||
void SpinBox::set_prefix(const String &p_prefix) {
|
||||
|
||||
void SpinBox::set_prefix(const String& p_prefix) {
|
||||
|
||||
prefix=p_prefix;
|
||||
prefix = p_prefix;
|
||||
_value_changed(0);
|
||||
|
||||
}
|
||||
|
||||
String SpinBox::get_prefix() const{
|
||||
String SpinBox::get_prefix() const {
|
||||
|
||||
return prefix;
|
||||
}
|
||||
|
|
@ -250,41 +234,38 @@ bool SpinBox::is_editable() const {
|
|||
void SpinBox::_bind_methods() {
|
||||
|
||||
//ObjectTypeDB::bind_method(_MD("_value_changed"),&SpinBox::_value_changed);
|
||||
ObjectTypeDB::bind_method(_MD("_input_event"),&SpinBox::_input_event);
|
||||
ObjectTypeDB::bind_method(_MD("_text_entered"),&SpinBox::_text_entered);
|
||||
ObjectTypeDB::bind_method(_MD("set_suffix","suffix"),&SpinBox::set_suffix);
|
||||
ObjectTypeDB::bind_method(_MD("get_suffix"),&SpinBox::get_suffix);
|
||||
ObjectTypeDB::bind_method(_MD("set_prefix","prefix"),&SpinBox::set_prefix);
|
||||
ObjectTypeDB::bind_method(_MD("get_prefix"),&SpinBox::get_prefix);
|
||||
ObjectTypeDB::bind_method(_MD("set_editable","editable"),&SpinBox::set_editable);
|
||||
ObjectTypeDB::bind_method(_MD("is_editable"),&SpinBox::is_editable);
|
||||
ObjectTypeDB::bind_method(_MD("_line_edit_focus_exit"),&SpinBox::_line_edit_focus_exit);
|
||||
ObjectTypeDB::bind_method(_MD("get_line_edit"),&SpinBox::get_line_edit);
|
||||
ObjectTypeDB::bind_method(_MD("_line_edit_input"),&SpinBox::_line_edit_input);
|
||||
ObjectTypeDB::bind_method(_MD("_range_click_timeout"),&SpinBox::_range_click_timeout);
|
||||
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL,"editable"),_SCS("set_editable"),_SCS("is_editable"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING,"prefix"),_SCS("set_prefix"),_SCS("get_prefix"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING,"suffix"),_SCS("set_suffix"),_SCS("get_suffix"));
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("_input_event"), &SpinBox::_input_event);
|
||||
ObjectTypeDB::bind_method(_MD("_text_entered"), &SpinBox::_text_entered);
|
||||
ObjectTypeDB::bind_method(_MD("set_suffix", "suffix"), &SpinBox::set_suffix);
|
||||
ObjectTypeDB::bind_method(_MD("get_suffix"), &SpinBox::get_suffix);
|
||||
ObjectTypeDB::bind_method(_MD("set_prefix", "prefix"), &SpinBox::set_prefix);
|
||||
ObjectTypeDB::bind_method(_MD("get_prefix"), &SpinBox::get_prefix);
|
||||
ObjectTypeDB::bind_method(_MD("set_editable", "editable"), &SpinBox::set_editable);
|
||||
ObjectTypeDB::bind_method(_MD("is_editable"), &SpinBox::is_editable);
|
||||
ObjectTypeDB::bind_method(_MD("_line_edit_focus_exit"), &SpinBox::_line_edit_focus_exit);
|
||||
ObjectTypeDB::bind_method(_MD("get_line_edit"), &SpinBox::get_line_edit);
|
||||
ObjectTypeDB::bind_method(_MD("_line_edit_input"), &SpinBox::_line_edit_input);
|
||||
ObjectTypeDB::bind_method(_MD("_range_click_timeout"), &SpinBox::_range_click_timeout);
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editable"), _SCS("set_editable"), _SCS("is_editable"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "prefix"), _SCS("set_prefix"), _SCS("get_prefix"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "suffix"), _SCS("set_suffix"), _SCS("get_suffix"));
|
||||
}
|
||||
|
||||
SpinBox::SpinBox() {
|
||||
|
||||
last_w = 0;
|
||||
line_edit = memnew( LineEdit );
|
||||
line_edit = memnew(LineEdit);
|
||||
add_child(line_edit);
|
||||
|
||||
line_edit->set_area_as_parent_rect();
|
||||
//connect("value_changed",this,"_value_changed");
|
||||
line_edit->connect("text_entered",this,"_text_entered",Vector<Variant>(),CONNECT_DEFERRED);
|
||||
line_edit->connect("focus_exit",this,"_line_edit_focus_exit",Vector<Variant>(),CONNECT_DEFERRED);
|
||||
line_edit->connect("input_event",this,"_line_edit_input");
|
||||
drag.enabled=false;
|
||||
line_edit->connect("text_entered", this, "_text_entered", Vector<Variant>(), CONNECT_DEFERRED);
|
||||
line_edit->connect("focus_exit", this, "_line_edit_focus_exit", Vector<Variant>(), CONNECT_DEFERRED);
|
||||
line_edit->connect("input_event", this, "_line_edit_input");
|
||||
drag.enabled = false;
|
||||
|
||||
range_click_timer = memnew( Timer );
|
||||
range_click_timer->connect("timeout",this,"_range_click_timeout");
|
||||
range_click_timer = memnew(Timer);
|
||||
range_click_timer->connect("timeout", this, "_range_click_timeout");
|
||||
add_child(range_click_timer);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@
|
|||
|
||||
class SpinBox : public Range {
|
||||
|
||||
OBJ_TYPE( SpinBox, Range );
|
||||
OBJ_TYPE(SpinBox, Range);
|
||||
|
||||
LineEdit *line_edit;
|
||||
int last_w;
|
||||
|
|
@ -43,35 +43,31 @@ class SpinBox : public Range {
|
|||
Timer *range_click_timer;
|
||||
void _range_click_timeout();
|
||||
|
||||
void _text_entered(const String& p_string);
|
||||
void _text_entered(const String &p_string);
|
||||
virtual void _value_changed(double);
|
||||
String prefix;
|
||||
String suffix;
|
||||
|
||||
void _line_edit_input(const InputEvent& p_event);
|
||||
|
||||
void _line_edit_input(const InputEvent &p_event);
|
||||
|
||||
struct Drag {
|
||||
float base_val;
|
||||
bool enabled;
|
||||
Vector2 from;
|
||||
Vector2 mouse_pos;
|
||||
Vector2 mouse_pos;
|
||||
Vector2 capture_pos;
|
||||
} drag;
|
||||
|
||||
|
||||
void _line_edit_focus_exit();
|
||||
|
||||
protected:
|
||||
|
||||
void _input_event(const InputEvent& p_event);
|
||||
|
||||
void _input_event(const InputEvent &p_event);
|
||||
|
||||
void _notification(int p_what);
|
||||
|
||||
static void _bind_methods();
|
||||
public:
|
||||
|
||||
public:
|
||||
LineEdit *get_line_edit();
|
||||
|
||||
virtual Size2 get_minimum_size() const;
|
||||
|
|
@ -79,10 +75,10 @@ public:
|
|||
void set_editable(bool p_editable);
|
||||
bool is_editable() const;
|
||||
|
||||
void set_suffix(const String& p_suffix);
|
||||
void set_suffix(const String &p_suffix);
|
||||
String get_suffix() const;
|
||||
|
||||
void set_prefix(const String& p_prefix);
|
||||
void set_prefix(const String &p_prefix);
|
||||
String get_prefix() const;
|
||||
|
||||
SpinBox();
|
||||
|
|
|
|||
|
|
@ -28,10 +28,8 @@
|
|||
/*************************************************************************/
|
||||
#include "split_container.h"
|
||||
|
||||
#include "margin_container.h"
|
||||
#include "label.h"
|
||||
|
||||
|
||||
#include "margin_container.h"
|
||||
|
||||
struct _MinSizeCache {
|
||||
|
||||
|
|
@ -40,235 +38,208 @@ struct _MinSizeCache {
|
|||
int final_size;
|
||||
};
|
||||
|
||||
|
||||
Control *SplitContainer::_getch(int p_idx) const {
|
||||
|
||||
int idx=0;
|
||||
int idx = 0;
|
||||
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
Control *c=get_child(i)->cast_to<Control>();
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c || !c->is_visible())
|
||||
continue;
|
||||
if (c->is_set_as_toplevel())
|
||||
continue;
|
||||
|
||||
if (idx==p_idx)
|
||||
if (idx == p_idx)
|
||||
return c;
|
||||
|
||||
idx++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void SplitContainer::_resort() {
|
||||
|
||||
/** First pass, determine minimum size AND amount of stretchable elements */
|
||||
|
||||
int axis = vertical?1:0;
|
||||
int axis = vertical ? 1 : 0;
|
||||
|
||||
bool has_first=_getch(0);
|
||||
bool has_second=_getch(1);
|
||||
bool has_first = _getch(0);
|
||||
bool has_second = _getch(1);
|
||||
|
||||
if (!has_first && !has_second) {
|
||||
return;
|
||||
} else if (! (has_first && has_second)) {
|
||||
} else if (!(has_first && has_second)) {
|
||||
if (has_first)
|
||||
fit_child_in_rect(_getch(0),Rect2(Point2(),get_size()));
|
||||
fit_child_in_rect(_getch(0), Rect2(Point2(), get_size()));
|
||||
else
|
||||
fit_child_in_rect(_getch(1),Rect2(Point2(),get_size()));
|
||||
fit_child_in_rect(_getch(1), Rect2(Point2(), get_size()));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Control *first = _getch(0);
|
||||
Control *second = _getch(1);
|
||||
|
||||
|
||||
Control *first=_getch(0);
|
||||
Control *second=_getch(1);
|
||||
|
||||
|
||||
bool ratiomode=false;
|
||||
bool expand_first_mode=false;
|
||||
|
||||
|
||||
|
||||
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);
|
||||
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);
|
||||
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");
|
||||
int sep = get_constant("separation");
|
||||
Ref<Texture> g = get_icon("grabber");
|
||||
|
||||
if (dragger_visibility==DRAGGER_HIDDEN_COLLAPSED) {
|
||||
sep=0;
|
||||
if (dragger_visibility == DRAGGER_HIDDEN_COLLAPSED) {
|
||||
sep = 0;
|
||||
} else {
|
||||
sep=MAX(sep,vertical?g->get_height():g->get_width());
|
||||
sep = MAX(sep, vertical ? g->get_height() : g->get_width());
|
||||
}
|
||||
|
||||
int total = vertical?get_size().height:get_size().width;
|
||||
int total = vertical ? get_size().height : get_size().width;
|
||||
|
||||
total-=sep;
|
||||
total -= sep;
|
||||
|
||||
int minimum=0;
|
||||
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;
|
||||
minimum = ms_first.height + ms_second.height;
|
||||
} else {
|
||||
|
||||
minimum=ms_first.width+ms_second.width;
|
||||
minimum = ms_first.width + ms_second.width;
|
||||
}
|
||||
|
||||
int available=total-minimum;
|
||||
if (available<0)
|
||||
available=0;
|
||||
int available = total - minimum;
|
||||
if (available < 0)
|
||||
available = 0;
|
||||
|
||||
|
||||
middle_sep=0;
|
||||
middle_sep = 0;
|
||||
|
||||
if (collapsed) {
|
||||
|
||||
|
||||
if (ratiomode) {
|
||||
|
||||
middle_sep=ms_first[axis]+available/2;
|
||||
|
||||
middle_sep = ms_first[axis] + available / 2;
|
||||
|
||||
} else if (expand_first_mode) {
|
||||
|
||||
middle_sep=get_size()[axis]-ms_second[axis]-sep;
|
||||
middle_sep = get_size()[axis] - ms_second[axis] - sep;
|
||||
|
||||
} else {
|
||||
|
||||
middle_sep=ms_first[axis];
|
||||
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;
|
||||
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 > 0)
|
||||
expand_ofs = 0;
|
||||
|
||||
if (expand_ofs < -available)
|
||||
expand_ofs=-available;
|
||||
expand_ofs = -available;
|
||||
|
||||
middle_sep=get_size()[axis]-ms_second[axis]-sep+expand_ofs;
|
||||
middle_sep = get_size()[axis] - ms_second[axis] - sep + expand_ofs;
|
||||
|
||||
} else {
|
||||
|
||||
if (expand_ofs<0)
|
||||
expand_ofs=0;
|
||||
if (expand_ofs < 0)
|
||||
expand_ofs = 0;
|
||||
|
||||
if (expand_ofs > available)
|
||||
expand_ofs=available;
|
||||
|
||||
middle_sep=ms_first[axis]+expand_ofs;
|
||||
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)));
|
||||
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)));
|
||||
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");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Size2 SplitContainer::get_minimum_size() const {
|
||||
|
||||
|
||||
/* Calculate MINIMUM SIZE */
|
||||
|
||||
Size2i minimum;
|
||||
int sep=get_constant("separation");
|
||||
int sep = get_constant("separation");
|
||||
Ref<Texture> g = get_icon("grabber");
|
||||
sep=(dragger_visibility!=DRAGGER_HIDDEN_COLLAPSED)?MAX(sep,vertical?g->get_height():g->get_width()):0;
|
||||
sep = (dragger_visibility != DRAGGER_HIDDEN_COLLAPSED) ? MAX(sep, vertical ? g->get_height() : g->get_width()) : 0;
|
||||
|
||||
for(int i=0;i<2;i++) {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
|
||||
if (!_getch(i))
|
||||
break;
|
||||
|
||||
if (i==1) {
|
||||
if (i == 1) {
|
||||
|
||||
if (vertical)
|
||||
minimum.height+=sep;
|
||||
minimum.height += sep;
|
||||
else
|
||||
minimum.width+=sep;
|
||||
minimum.width += sep;
|
||||
}
|
||||
|
||||
Size2 ms = _getch(i)->get_combined_minimum_size();
|
||||
|
||||
if (vertical) {
|
||||
|
||||
minimum.height+=ms.height;
|
||||
minimum.width=MAX(minimum.width,ms.width);
|
||||
minimum.height += ms.height;
|
||||
minimum.width = MAX(minimum.width, ms.width);
|
||||
} else {
|
||||
|
||||
minimum.width+=ms.width;
|
||||
minimum.height=MAX(minimum.height,ms.height);
|
||||
minimum.width += ms.width;
|
||||
minimum.height = MAX(minimum.height, ms.height);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return minimum;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void SplitContainer::_notification(int p_what) {
|
||||
|
||||
switch(p_what) {
|
||||
switch (p_what) {
|
||||
|
||||
case NOTIFICATION_SORT_CHILDREN: {
|
||||
|
||||
_resort();
|
||||
} break;
|
||||
case NOTIFICATION_MOUSE_ENTER: {
|
||||
mouse_inside=true;
|
||||
mouse_inside = true;
|
||||
update();
|
||||
} break;
|
||||
case NOTIFICATION_MOUSE_EXIT: {
|
||||
mouse_inside=false;
|
||||
mouse_inside = false;
|
||||
update();
|
||||
} break;
|
||||
case NOTIFICATION_DRAW: {
|
||||
|
|
@ -278,111 +249,105 @@ void SplitContainer::_notification(int p_what) {
|
|||
|
||||
if (collapsed || (!mouse_inside && get_constant("autohide")))
|
||||
return;
|
||||
int sep=dragger_visibility!=DRAGGER_HIDDEN_COLLAPSED?get_constant("separation"):0;
|
||||
int sep = dragger_visibility != DRAGGER_HIDDEN_COLLAPSED ? get_constant("separation") : 0;
|
||||
Ref<Texture> tex = get_icon("grabber");
|
||||
Size2 size=get_size();
|
||||
Size2 size = get_size();
|
||||
if (vertical) {
|
||||
|
||||
//draw_style_box( get_stylebox("bg"), Rect2(0,middle_sep,get_size().width,sep));
|
||||
if (dragger_visibility==DRAGGER_VISIBLE)
|
||||
draw_texture(tex,Point2i((size.x-tex->get_width())/2,middle_sep+(sep-tex->get_height())/2));
|
||||
if (dragger_visibility == DRAGGER_VISIBLE)
|
||||
draw_texture(tex, Point2i((size.x - tex->get_width()) / 2, middle_sep + (sep - tex->get_height()) / 2));
|
||||
|
||||
} else {
|
||||
|
||||
//draw_style_box( get_stylebox("bg"), Rect2(middle_sep,0,sep,get_size().height));
|
||||
if (dragger_visibility==DRAGGER_VISIBLE)
|
||||
draw_texture(tex,Point2i(middle_sep+(sep-tex->get_width())/2,(size.y-tex->get_height())/2));
|
||||
|
||||
if (dragger_visibility == DRAGGER_VISIBLE)
|
||||
draw_texture(tex, Point2i(middle_sep + (sep - tex->get_width()) / 2, (size.y - tex->get_height()) / 2));
|
||||
}
|
||||
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void SplitContainer::_input_event(const InputEvent& p_event) {
|
||||
void SplitContainer::_input_event(const InputEvent &p_event) {
|
||||
|
||||
if (collapsed || !_getch(0) || !_getch(1) || dragger_visibility!=DRAGGER_VISIBLE)
|
||||
if (collapsed || !_getch(0) || !_getch(1) || dragger_visibility != DRAGGER_VISIBLE)
|
||||
return;
|
||||
|
||||
if (p_event.type==InputEvent::MOUSE_BUTTON) {
|
||||
if (p_event.type == InputEvent::MOUSE_BUTTON) {
|
||||
|
||||
const InputEventMouseButton &mb=p_event.mouse_button;
|
||||
const InputEventMouseButton &mb = p_event.mouse_button;
|
||||
|
||||
if (mb.button_index==BUTTON_LEFT) {
|
||||
if (mb.button_index == BUTTON_LEFT) {
|
||||
|
||||
if (mb.pressed) {
|
||||
int sep=get_constant("separation");
|
||||
int sep = get_constant("separation");
|
||||
|
||||
if (vertical) {
|
||||
|
||||
|
||||
if (mb.y > middle_sep && mb.y < middle_sep+sep) {
|
||||
dragging=true;
|
||||
drag_from=mb.y;
|
||||
drag_ofs=expand_ofs;
|
||||
if (mb.y > middle_sep && mb.y < middle_sep + sep) {
|
||||
dragging = true;
|
||||
drag_from = mb.y;
|
||||
drag_ofs = expand_ofs;
|
||||
}
|
||||
} else {
|
||||
|
||||
if (mb.x > middle_sep && mb.x < middle_sep+sep) {
|
||||
dragging=true;
|
||||
drag_from=mb.x;
|
||||
drag_ofs=expand_ofs;
|
||||
if (mb.x > middle_sep && mb.x < middle_sep + sep) {
|
||||
dragging = true;
|
||||
drag_from = mb.x;
|
||||
drag_ofs = expand_ofs;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
dragging=false;
|
||||
dragging = false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (p_event.type==InputEvent::MOUSE_MOTION) {
|
||||
if (p_event.type == InputEvent::MOUSE_MOTION) {
|
||||
|
||||
const InputEventMouseMotion &mm=p_event.mouse_motion;
|
||||
const InputEventMouseMotion &mm = p_event.mouse_motion;
|
||||
|
||||
if (dragging) {
|
||||
|
||||
expand_ofs=drag_ofs+((vertical?mm.y:mm.x)-drag_from);
|
||||
expand_ofs = drag_ofs + ((vertical ? mm.y : mm.x) - drag_from);
|
||||
queue_sort();
|
||||
emit_signal("dragged",get_split_offset());
|
||||
emit_signal("dragged", get_split_offset());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Control::CursorShape SplitContainer::get_cursor_shape(const Point2& p_pos) const {
|
||||
Control::CursorShape SplitContainer::get_cursor_shape(const Point2 &p_pos) const {
|
||||
|
||||
if (collapsed)
|
||||
return Control::get_cursor_shape(p_pos);
|
||||
|
||||
if (dragging)
|
||||
return (vertical?CURSOR_VSIZE:CURSOR_HSIZE);
|
||||
return (vertical ? CURSOR_VSIZE : CURSOR_HSIZE);
|
||||
|
||||
int sep=get_constant("separation");
|
||||
int sep = get_constant("separation");
|
||||
|
||||
if (vertical) {
|
||||
|
||||
|
||||
if (p_pos.y > middle_sep && p_pos.y < middle_sep+sep) {
|
||||
if (p_pos.y > middle_sep && p_pos.y < middle_sep + sep) {
|
||||
return CURSOR_VSIZE;
|
||||
}
|
||||
} else {
|
||||
|
||||
if (p_pos.x > middle_sep && p_pos.x < middle_sep+sep) {
|
||||
if (p_pos.x > middle_sep && p_pos.x < middle_sep + sep) {
|
||||
return CURSOR_HSIZE;
|
||||
}
|
||||
}
|
||||
|
||||
return Control::get_cursor_shape(p_pos);
|
||||
|
||||
}
|
||||
|
||||
void SplitContainer::set_split_offset(int p_offset) {
|
||||
|
||||
if (expand_ofs==p_offset)
|
||||
if (expand_ofs == p_offset)
|
||||
return;
|
||||
expand_ofs=p_offset;
|
||||
expand_ofs = p_offset;
|
||||
queue_sort();
|
||||
}
|
||||
|
||||
|
|
@ -393,16 +358,15 @@ int SplitContainer::get_split_offset() const {
|
|||
|
||||
void SplitContainer::set_collapsed(bool p_collapsed) {
|
||||
|
||||
if (collapsed==p_collapsed)
|
||||
if (collapsed == p_collapsed)
|
||||
return;
|
||||
collapsed=p_collapsed;
|
||||
collapsed = p_collapsed;
|
||||
queue_sort();
|
||||
|
||||
}
|
||||
|
||||
void SplitContainer::set_dragger_visibility(DraggerVisibility p_visibility) {
|
||||
|
||||
dragger_visibility=p_visibility;
|
||||
dragger_visibility = p_visibility;
|
||||
queue_sort();
|
||||
update();
|
||||
}
|
||||
|
|
@ -412,49 +376,41 @@ SplitContainer::DraggerVisibility SplitContainer::get_dragger_visibility() const
|
|||
return dragger_visibility;
|
||||
}
|
||||
|
||||
|
||||
bool SplitContainer::is_collapsed() const {
|
||||
|
||||
|
||||
return collapsed;
|
||||
}
|
||||
|
||||
|
||||
void SplitContainer::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("_input_event"),&SplitContainer::_input_event);
|
||||
ObjectTypeDB::bind_method(_MD("set_split_offset","offset"),&SplitContainer::set_split_offset);
|
||||
ObjectTypeDB::bind_method(_MD("get_split_offset"),&SplitContainer::get_split_offset);
|
||||
ObjectTypeDB::bind_method(_MD("_input_event"), &SplitContainer::_input_event);
|
||||
ObjectTypeDB::bind_method(_MD("set_split_offset", "offset"), &SplitContainer::set_split_offset);
|
||||
ObjectTypeDB::bind_method(_MD("get_split_offset"), &SplitContainer::get_split_offset);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_collapsed","collapsed"),&SplitContainer::set_collapsed);
|
||||
ObjectTypeDB::bind_method(_MD("is_collapsed"),&SplitContainer::is_collapsed);
|
||||
ObjectTypeDB::bind_method(_MD("set_collapsed", "collapsed"), &SplitContainer::set_collapsed);
|
||||
ObjectTypeDB::bind_method(_MD("is_collapsed"), &SplitContainer::is_collapsed);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_dragger_visibility","mode"),&SplitContainer::set_dragger_visibility);
|
||||
ObjectTypeDB::bind_method(_MD("get_dragger_visibility"),&SplitContainer::get_dragger_visibility);
|
||||
ObjectTypeDB::bind_method(_MD("set_dragger_visibility", "mode"), &SplitContainer::set_dragger_visibility);
|
||||
ObjectTypeDB::bind_method(_MD("get_dragger_visibility"), &SplitContainer::get_dragger_visibility);
|
||||
|
||||
ADD_SIGNAL( MethodInfo("dragged",PropertyInfo(Variant::INT,"offset")));
|
||||
ADD_SIGNAL(MethodInfo("dragged", PropertyInfo(Variant::INT, "offset")));
|
||||
|
||||
ADD_PROPERTY( PropertyInfo(Variant::INT,"split/offset"),_SCS("set_split_offset"),_SCS("get_split_offset"));
|
||||
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"split/collapsed"),_SCS("set_collapsed"),_SCS("is_collapsed"));
|
||||
ADD_PROPERTY( PropertyInfo(Variant::INT,"split/dragger_visibility",PROPERTY_HINT_ENUM,"Visible,Hidden,Hidden & Collapsed"),_SCS("set_dragger_visibility"),_SCS("get_dragger_visibility"));
|
||||
|
||||
BIND_CONSTANT( DRAGGER_VISIBLE );
|
||||
BIND_CONSTANT( DRAGGER_HIDDEN );
|
||||
BIND_CONSTANT( DRAGGER_HIDDEN_COLLAPSED );
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "split/offset"), _SCS("set_split_offset"), _SCS("get_split_offset"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "split/collapsed"), _SCS("set_collapsed"), _SCS("is_collapsed"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "split/dragger_visibility", PROPERTY_HINT_ENUM, "Visible,Hidden,Hidden & Collapsed"), _SCS("set_dragger_visibility"), _SCS("get_dragger_visibility"));
|
||||
|
||||
BIND_CONSTANT(DRAGGER_VISIBLE);
|
||||
BIND_CONSTANT(DRAGGER_HIDDEN);
|
||||
BIND_CONSTANT(DRAGGER_HIDDEN_COLLAPSED);
|
||||
}
|
||||
|
||||
SplitContainer::SplitContainer(bool p_vertical) {
|
||||
|
||||
|
||||
mouse_inside=false;
|
||||
expand_ofs=0;
|
||||
middle_sep=0;
|
||||
vertical=p_vertical;
|
||||
dragging=false;
|
||||
collapsed=false;
|
||||
dragger_visibility=DRAGGER_VISIBLE;
|
||||
|
||||
mouse_inside = false;
|
||||
expand_ofs = 0;
|
||||
middle_sep = 0;
|
||||
vertical = p_vertical;
|
||||
dragging = false;
|
||||
collapsed = false;
|
||||
dragger_visibility = DRAGGER_VISIBLE;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -31,16 +31,17 @@
|
|||
|
||||
#include "scene/gui/container.h"
|
||||
|
||||
|
||||
class SplitContainer : public Container {
|
||||
|
||||
OBJ_TYPE(SplitContainer,Container);
|
||||
OBJ_TYPE(SplitContainer, Container);
|
||||
|
||||
public:
|
||||
enum DraggerVisibility {
|
||||
DRAGGER_VISIBLE,
|
||||
DRAGGER_HIDDEN,
|
||||
DRAGGER_HIDDEN_COLLAPSED
|
||||
};
|
||||
|
||||
private:
|
||||
bool vertical;
|
||||
int expand_ofs;
|
||||
|
|
@ -52,20 +53,16 @@ private:
|
|||
DraggerVisibility dragger_visibility;
|
||||
bool mouse_inside;
|
||||
|
||||
|
||||
Control *_getch(int p_idx) const;
|
||||
|
||||
void _resort();
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
void _input_event(const InputEvent& p_event);
|
||||
void _input_event(const InputEvent &p_event);
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
void set_split_offset(int p_offset);
|
||||
int get_split_offset() const;
|
||||
|
||||
|
|
@ -75,32 +72,31 @@ public:
|
|||
void set_dragger_visibility(DraggerVisibility p_visibility);
|
||||
DraggerVisibility get_dragger_visibility() const;
|
||||
|
||||
virtual CursorShape get_cursor_shape(const Point2& p_pos=Point2i()) const;
|
||||
virtual CursorShape get_cursor_shape(const Point2 &p_pos = Point2i()) const;
|
||||
|
||||
virtual Size2 get_minimum_size() const;
|
||||
|
||||
SplitContainer(bool p_vertical=false);
|
||||
SplitContainer(bool p_vertical = false);
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST(SplitContainer::DraggerVisibility);
|
||||
|
||||
class HSplitContainer : public SplitContainer {
|
||||
|
||||
OBJ_TYPE(HSplitContainer,SplitContainer);
|
||||
OBJ_TYPE(HSplitContainer, SplitContainer);
|
||||
|
||||
public:
|
||||
|
||||
HSplitContainer() : SplitContainer(false) {set_default_cursor_shape(CURSOR_HSPLIT);}
|
||||
HSplitContainer()
|
||||
: SplitContainer(false) { set_default_cursor_shape(CURSOR_HSPLIT); }
|
||||
};
|
||||
|
||||
|
||||
class VSplitContainer : public SplitContainer {
|
||||
|
||||
OBJ_TYPE(VSplitContainer,SplitContainer);
|
||||
OBJ_TYPE(VSplitContainer, SplitContainer);
|
||||
|
||||
public:
|
||||
|
||||
VSplitContainer() : SplitContainer(true) {set_default_cursor_shape(CURSOR_VSPLIT);}
|
||||
VSplitContainer()
|
||||
: SplitContainer(true) { set_default_cursor_shape(CURSOR_VSPLIT); }
|
||||
};
|
||||
|
||||
#endif // SPLIT_CONTAINER_H
|
||||
|
|
|
|||
|
|
@ -30,18 +30,16 @@
|
|||
|
||||
#include "message_queue.h"
|
||||
|
||||
|
||||
|
||||
int TabContainer::_get_top_margin() const {
|
||||
|
||||
Ref<StyleBox> tab_bg = get_stylebox("tab_bg");
|
||||
Ref<StyleBox> tab_fg = get_stylebox("tab_fg");
|
||||
Ref<Font> font = get_font("font");
|
||||
|
||||
int h = MAX( tab_bg->get_minimum_size().height,tab_fg->get_minimum_size().height);
|
||||
int h = MAX(tab_bg->get_minimum_size().height, tab_fg->get_minimum_size().height);
|
||||
|
||||
int ch = font->get_height();
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c)
|
||||
|
|
@ -54,31 +52,28 @@ int TabContainer::_get_top_margin() const {
|
|||
Ref<Texture> tex = c->get_meta("_tab_icon");
|
||||
if (!tex.is_valid())
|
||||
continue;
|
||||
ch = MAX( ch, tex->get_size().height );
|
||||
ch = MAX(ch, tex->get_size().height);
|
||||
}
|
||||
|
||||
h+=ch;
|
||||
h += ch;
|
||||
|
||||
return h;
|
||||
|
||||
}
|
||||
|
||||
void TabContainer::_input_event(const InputEvent &p_event) {
|
||||
|
||||
|
||||
void TabContainer::_input_event(const InputEvent& p_event) {
|
||||
|
||||
if (p_event.type==InputEvent::MOUSE_BUTTON &&
|
||||
p_event.mouse_button.pressed &&
|
||||
p_event.mouse_button.button_index==BUTTON_LEFT) {
|
||||
if (p_event.type == InputEvent::MOUSE_BUTTON &&
|
||||
p_event.mouse_button.pressed &&
|
||||
p_event.mouse_button.button_index == BUTTON_LEFT) {
|
||||
|
||||
// clicks
|
||||
Point2 pos( p_event.mouse_button.x, p_event.mouse_button.y );
|
||||
Point2 pos(p_event.mouse_button.x, p_event.mouse_button.y);
|
||||
|
||||
int top_margin = _get_top_margin();
|
||||
if (pos.y>top_margin)
|
||||
if (pos.y > top_margin)
|
||||
return; // no click (too far down)
|
||||
|
||||
if (pos.x<tabs_ofs_cache)
|
||||
if (pos.x < tabs_ofs_cache)
|
||||
return; // no click (too far left)
|
||||
|
||||
Ref<StyleBox> tab_bg = get_stylebox("tab_bg");
|
||||
|
|
@ -89,26 +84,25 @@ void TabContainer::_input_event(const InputEvent& p_event) {
|
|||
Ref<Texture> menu = get_icon("menu");
|
||||
Ref<Texture> menu_hl = get_icon("menu_hl");
|
||||
|
||||
if (popup && pos.x>get_size().width-menu->get_width()) {
|
||||
|
||||
if (popup && pos.x > get_size().width - menu->get_width()) {
|
||||
|
||||
emit_signal("pre_popup_pressed");
|
||||
Vector2 pp_pos = get_global_pos();
|
||||
pp_pos.x+=get_size().width;
|
||||
pp_pos.x-=popup->get_size().width;
|
||||
pp_pos.y+=menu->get_height();
|
||||
pp_pos.x += get_size().width;
|
||||
pp_pos.x -= popup->get_size().width;
|
||||
pp_pos.y += menu->get_height();
|
||||
|
||||
popup->set_global_pos( pp_pos );
|
||||
popup->set_global_pos(pp_pos);
|
||||
popup->popup();
|
||||
return;
|
||||
}
|
||||
pos.x-=tabs_ofs_cache;
|
||||
pos.x -= tabs_ofs_cache;
|
||||
|
||||
int idx=0;
|
||||
int found=-1;
|
||||
bool rightroom=false;
|
||||
int idx = 0;
|
||||
int found = -1;
|
||||
bool rightroom = false;
|
||||
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c)
|
||||
|
|
@ -116,77 +110,71 @@ void TabContainer::_input_event(const InputEvent& p_event) {
|
|||
if (c->is_set_as_toplevel())
|
||||
continue;
|
||||
|
||||
if (idx<tab_display_ofs) {
|
||||
if (idx < tab_display_ofs) {
|
||||
idx++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (idx>last_tab_cache) {
|
||||
rightroom=true;
|
||||
if (idx > last_tab_cache) {
|
||||
rightroom = true;
|
||||
break;
|
||||
}
|
||||
|
||||
String s = c->has_meta("_tab_name")?String(XL_MESSAGE(String(c->get_meta("_tab_name")))):String(c->get_name());
|
||||
int tab_width=font->get_string_size(s).width;
|
||||
String s = c->has_meta("_tab_name") ? String(XL_MESSAGE(String(c->get_meta("_tab_name")))) : String(c->get_name());
|
||||
int tab_width = font->get_string_size(s).width;
|
||||
|
||||
if (c->has_meta("_tab_icon")) {
|
||||
Ref<Texture> icon = c->get_meta("_tab_icon");
|
||||
if (icon.is_valid()) {
|
||||
tab_width+=icon->get_width();
|
||||
if (s!="")
|
||||
tab_width+=get_constant("hseparation");
|
||||
|
||||
tab_width += icon->get_width();
|
||||
if (s != "")
|
||||
tab_width += get_constant("hseparation");
|
||||
}
|
||||
}
|
||||
|
||||
if (idx==current) {
|
||||
if (idx == current) {
|
||||
|
||||
tab_width+=tab_fg->get_minimum_size().width;
|
||||
tab_width += tab_fg->get_minimum_size().width;
|
||||
} else {
|
||||
tab_width+=tab_bg->get_minimum_size().width;
|
||||
tab_width += tab_bg->get_minimum_size().width;
|
||||
}
|
||||
|
||||
if (pos.x < tab_width) {
|
||||
|
||||
found=idx;
|
||||
found = idx;
|
||||
break;
|
||||
}
|
||||
|
||||
pos.x-=tab_width;
|
||||
pos.x -= tab_width;
|
||||
idx++;
|
||||
}
|
||||
|
||||
if (buttons_visible_cache) {
|
||||
|
||||
if (p_event.mouse_button.x>get_size().width-incr->get_width()) {
|
||||
if (p_event.mouse_button.x > get_size().width - incr->get_width()) {
|
||||
if (rightroom) {
|
||||
tab_display_ofs+=1;
|
||||
tab_display_ofs += 1;
|
||||
update();
|
||||
}
|
||||
} else if (p_event.mouse_button.x>get_size().width-incr->get_width()-decr->get_width()) {
|
||||
} else if (p_event.mouse_button.x > get_size().width - incr->get_width() - decr->get_width()) {
|
||||
|
||||
if (tab_display_ofs>0) {
|
||||
tab_display_ofs-=1;
|
||||
if (tab_display_ofs > 0) {
|
||||
tab_display_ofs -= 1;
|
||||
update();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (found!=-1) {
|
||||
if (found != -1) {
|
||||
|
||||
set_current_tab(found);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void TabContainer::_notification(int p_what) {
|
||||
|
||||
|
||||
switch(p_what) {
|
||||
|
||||
switch (p_what) {
|
||||
|
||||
case NOTIFICATION_DRAW: {
|
||||
|
||||
|
|
@ -196,12 +184,10 @@ void TabContainer::_notification(int p_what) {
|
|||
|
||||
if (!tabs_visible) {
|
||||
|
||||
panel->draw(ci, Rect2( 0, 0, size.width, size.height));
|
||||
panel->draw(ci, Rect2(0, 0, size.width, size.height));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Ref<StyleBox> tab_bg = get_stylebox("tab_bg");
|
||||
Ref<StyleBox> tab_fg = get_stylebox("tab_fg");
|
||||
Ref<Texture> incr = get_icon("increment");
|
||||
|
|
@ -215,179 +201,165 @@ void TabContainer::_notification(int p_what) {
|
|||
int side_margin = get_constant("side_margin");
|
||||
int top_margin = _get_top_margin();
|
||||
|
||||
Size2 top_size = Size2(size.width, top_margin);
|
||||
|
||||
Size2 top_size = Size2( size.width, top_margin );
|
||||
|
||||
|
||||
|
||||
int w=0;
|
||||
int idx=0;
|
||||
int w = 0;
|
||||
int idx = 0;
|
||||
Vector<int> offsets;
|
||||
Vector<Control*> controls;
|
||||
int from=0;
|
||||
int limit=get_size().width;
|
||||
Vector<Control *> controls;
|
||||
int from = 0;
|
||||
int limit = get_size().width;
|
||||
if (popup) {
|
||||
top_size.width-=menu->get_width();
|
||||
limit-=menu->get_width();
|
||||
top_size.width -= menu->get_width();
|
||||
limit -= menu->get_width();
|
||||
}
|
||||
|
||||
bool notdone=false;
|
||||
last_tab_cache=-1;
|
||||
bool notdone = false;
|
||||
last_tab_cache = -1;
|
||||
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c)
|
||||
continue;
|
||||
if (c->is_set_as_toplevel())
|
||||
continue;
|
||||
if (idx<tab_display_ofs) {
|
||||
if (idx < tab_display_ofs) {
|
||||
idx++;
|
||||
from=idx;
|
||||
from = idx;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (w>=get_size().width) {
|
||||
buttons_visible_cache=true;
|
||||
notdone=true;
|
||||
if (w >= get_size().width) {
|
||||
buttons_visible_cache = true;
|
||||
notdone = true;
|
||||
break;
|
||||
}
|
||||
|
||||
offsets.push_back(w);
|
||||
controls.push_back(c);
|
||||
|
||||
String s = c->has_meta("_tab_name")?String(XL_MESSAGE(String(c->get_meta("_tab_name")))):String(c->get_name());
|
||||
w+=font->get_string_size(s).width;
|
||||
String s = c->has_meta("_tab_name") ? String(XL_MESSAGE(String(c->get_meta("_tab_name")))) : String(c->get_name());
|
||||
w += font->get_string_size(s).width;
|
||||
if (c->has_meta("_tab_icon")) {
|
||||
Ref<Texture> icon = c->get_meta("_tab_icon");
|
||||
if (icon.is_valid()) {
|
||||
w+=icon->get_width();
|
||||
if (s!="")
|
||||
w+=get_constant("hseparation");
|
||||
|
||||
w += icon->get_width();
|
||||
if (s != "")
|
||||
w += get_constant("hseparation");
|
||||
}
|
||||
}
|
||||
|
||||
if (idx==current) {
|
||||
if (idx == current) {
|
||||
|
||||
w+=tab_fg->get_minimum_size().width;
|
||||
w += tab_fg->get_minimum_size().width;
|
||||
} else {
|
||||
w+=tab_bg->get_minimum_size().width;
|
||||
w += tab_bg->get_minimum_size().width;
|
||||
}
|
||||
|
||||
if (idx<tab_display_ofs) {
|
||||
|
||||
if (idx < tab_display_ofs) {
|
||||
}
|
||||
last_tab_cache=idx;
|
||||
last_tab_cache = idx;
|
||||
|
||||
idx++;
|
||||
}
|
||||
|
||||
|
||||
int ofs;
|
||||
|
||||
switch(align) {
|
||||
switch (align) {
|
||||
|
||||
case ALIGN_LEFT: ofs = side_margin; break;
|
||||
case ALIGN_CENTER: ofs = (int(limit) - w)/2; break;
|
||||
case ALIGN_CENTER: ofs = (int(limit) - w) / 2; break;
|
||||
case ALIGN_RIGHT: ofs = int(limit) - w - side_margin; break;
|
||||
};
|
||||
|
||||
tab_display_ofs=0;
|
||||
tab_display_ofs = 0;
|
||||
|
||||
tabs_ofs_cache = ofs;
|
||||
idx = 0;
|
||||
|
||||
tabs_ofs_cache=ofs;
|
||||
idx=0;
|
||||
for (int i = 0; i < controls.size(); i++) {
|
||||
|
||||
|
||||
|
||||
for(int i=0;i<controls.size();i++) {
|
||||
|
||||
idx=i+from;
|
||||
if (current>=from && current<from+controls.size()-1) {
|
||||
idx = i + from;
|
||||
if (current >= from && current < from + controls.size() - 1) {
|
||||
//current is visible! draw it last.
|
||||
if (i==controls.size()-1) {
|
||||
idx=current;
|
||||
} else if (idx>=current) {
|
||||
idx+=1;
|
||||
if (i == controls.size() - 1) {
|
||||
idx = current;
|
||||
} else if (idx >= current) {
|
||||
idx += 1;
|
||||
}
|
||||
}
|
||||
|
||||
Control *c = controls[idx-from];
|
||||
Control *c = controls[idx - from];
|
||||
|
||||
String s = c->has_meta("_tab_name")?String(c->get_meta("_tab_name")):String(c->get_name());
|
||||
int w=font->get_string_size(s).width;
|
||||
String s = c->has_meta("_tab_name") ? String(c->get_meta("_tab_name")) : String(c->get_name());
|
||||
int w = font->get_string_size(s).width;
|
||||
Ref<Texture> icon;
|
||||
if (c->has_meta("_tab_icon")) {
|
||||
icon = c->get_meta("_tab_icon");
|
||||
if (icon.is_valid()) {
|
||||
|
||||
w+=icon->get_width();
|
||||
if (s!="")
|
||||
w+=get_constant("hseparation");
|
||||
|
||||
w += icon->get_width();
|
||||
if (s != "")
|
||||
w += get_constant("hseparation");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Ref<StyleBox> sb;
|
||||
Color col;
|
||||
|
||||
if (idx==current) {
|
||||
if (idx == current) {
|
||||
|
||||
sb=tab_fg;
|
||||
col=color_fg;
|
||||
sb = tab_fg;
|
||||
col = color_fg;
|
||||
} else {
|
||||
sb=tab_bg;
|
||||
col=color_bg;
|
||||
sb = tab_bg;
|
||||
col = color_bg;
|
||||
}
|
||||
|
||||
int lofs = ofs + offsets[idx-from];
|
||||
int lofs = ofs + offsets[idx - from];
|
||||
|
||||
Size2i sb_ms = sb->get_minimum_size();
|
||||
Rect2 sb_rect = Rect2( lofs, 0, w+sb_ms.width, top_margin);
|
||||
Rect2 sb_rect = Rect2(lofs, 0, w + sb_ms.width, top_margin);
|
||||
|
||||
|
||||
sb->draw(ci, sb_rect );
|
||||
sb->draw(ci, sb_rect);
|
||||
|
||||
Point2i lpos = sb_rect.pos;
|
||||
lpos.x+=sb->get_margin(MARGIN_LEFT);
|
||||
lpos.x += sb->get_margin(MARGIN_LEFT);
|
||||
if (icon.is_valid()) {
|
||||
|
||||
icon->draw(ci, Point2i( lpos.x, sb->get_margin(MARGIN_TOP)+((sb_rect.size.y-sb_ms.y)-icon->get_height())/2 ) );
|
||||
if (s!="")
|
||||
lpos.x+=icon->get_width()+get_constant("hseparation");
|
||||
|
||||
icon->draw(ci, Point2i(lpos.x, sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - icon->get_height()) / 2));
|
||||
if (s != "")
|
||||
lpos.x += icon->get_width() + get_constant("hseparation");
|
||||
}
|
||||
|
||||
font->draw(ci, Point2i( lpos.x, sb->get_margin(MARGIN_TOP)+((sb_rect.size.y-sb_ms.y)-font->get_height())/2+font->get_ascent() ), s, col );
|
||||
font->draw(ci, Point2i(lpos.x, sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - font->get_height()) / 2 + font->get_ascent()), s, col);
|
||||
|
||||
idx++;
|
||||
}
|
||||
|
||||
|
||||
if (buttons_visible_cache) {
|
||||
|
||||
int vofs = (top_margin-incr->get_height())/2;
|
||||
decr->draw(ci,Point2(limit,vofs),Color(1,1,1,tab_display_ofs==0?0.5:1.0));
|
||||
incr->draw(ci,Point2(limit+incr->get_width(),vofs),Color(1,1,1,notdone?1.0:0.5));
|
||||
int vofs = (top_margin - incr->get_height()) / 2;
|
||||
decr->draw(ci, Point2(limit, vofs), Color(1, 1, 1, tab_display_ofs == 0 ? 0.5 : 1.0));
|
||||
incr->draw(ci, Point2(limit + incr->get_width(), vofs), Color(1, 1, 1, notdone ? 1.0 : 0.5));
|
||||
}
|
||||
|
||||
if (popup) {
|
||||
int from = get_size().width-menu->get_width();
|
||||
int from = get_size().width - menu->get_width();
|
||||
|
||||
if (mouse_x_cache > from)
|
||||
menu_hl->draw(get_canvas_item(),Size2(from,0));
|
||||
menu_hl->draw(get_canvas_item(), Size2(from, 0));
|
||||
else
|
||||
menu->draw(get_canvas_item(),Size2(from,0));
|
||||
menu->draw(get_canvas_item(), Size2(from, 0));
|
||||
}
|
||||
|
||||
panel->draw(ci, Rect2( 0, top_size.height, size.width, size.height-top_size.height));
|
||||
panel->draw(ci, Rect2(0, top_size.height, size.width, size.height - top_size.height));
|
||||
|
||||
} break;
|
||||
case NOTIFICATION_THEME_CHANGED: {
|
||||
if (get_tab_count() > 0) {
|
||||
call_deferred("set_current_tab",get_current_tab()); //wait until all changed theme
|
||||
call_deferred("set_current_tab", get_current_tab()); //wait until all changed theme
|
||||
}
|
||||
} break;
|
||||
}
|
||||
|
|
@ -400,16 +372,15 @@ void TabContainer::_child_renamed_callback() {
|
|||
|
||||
void TabContainer::add_child_notify(Node *p_child) {
|
||||
|
||||
|
||||
Control *c = p_child->cast_to<Control>();
|
||||
if (!c)
|
||||
return;
|
||||
if (c->is_set_as_toplevel())
|
||||
return;
|
||||
|
||||
bool first=false;
|
||||
bool first = false;
|
||||
|
||||
if (get_tab_count()!=1)
|
||||
if (get_tab_count() != 1)
|
||||
c->hide();
|
||||
else {
|
||||
c->show();
|
||||
|
|
@ -420,23 +391,22 @@ void TabContainer::add_child_notify(Node *p_child) {
|
|||
}
|
||||
c->set_area_as_parent_rect();
|
||||
if (tabs_visible)
|
||||
c->set_margin(MARGIN_TOP,_get_top_margin());
|
||||
c->set_margin(MARGIN_TOP, _get_top_margin());
|
||||
Ref<StyleBox> sb = get_stylebox("panel");
|
||||
for(int i=0;i<4;i++)
|
||||
c->set_margin(Margin(i),c->get_margin(Margin(i))+sb->get_margin(Margin(i)));
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
c->set_margin(Margin(i), c->get_margin(Margin(i)) + sb->get_margin(Margin(i)));
|
||||
|
||||
update();
|
||||
p_child->connect("renamed", this,"_child_renamed_callback");
|
||||
if(first)
|
||||
emit_signal("tab_changed",current);
|
||||
p_child->connect("renamed", this, "_child_renamed_callback");
|
||||
if (first)
|
||||
emit_signal("tab_changed", current);
|
||||
}
|
||||
|
||||
int TabContainer::get_tab_count() const {
|
||||
|
||||
int count=0;
|
||||
int count = 0;
|
||||
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c)
|
||||
|
|
@ -447,32 +417,30 @@ int TabContainer::get_tab_count() const {
|
|||
return count;
|
||||
}
|
||||
|
||||
|
||||
void TabContainer::set_current_tab(int p_current) {
|
||||
|
||||
ERR_FAIL_INDEX( p_current, get_tab_count() );
|
||||
ERR_FAIL_INDEX(p_current, get_tab_count());
|
||||
|
||||
int pending_previous = current;
|
||||
current = p_current;
|
||||
|
||||
int idx=0;
|
||||
int idx = 0;
|
||||
|
||||
Ref<StyleBox> sb=get_stylebox("panel");
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
Ref<StyleBox> sb = get_stylebox("panel");
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c)
|
||||
continue;
|
||||
if (c->is_set_as_toplevel())
|
||||
continue;
|
||||
if (idx==current) {
|
||||
if (idx == current) {
|
||||
c->show();
|
||||
c->set_area_as_parent_rect();
|
||||
if (tabs_visible)
|
||||
c->set_margin(MARGIN_TOP,_get_top_margin());
|
||||
for(int i=0;i<4;i++)
|
||||
c->set_margin(Margin(i),c->get_margin(Margin(i))+sb->get_margin(Margin(i)));
|
||||
|
||||
c->set_margin(MARGIN_TOP, _get_top_margin());
|
||||
for (int i = 0; i < 4; i++)
|
||||
c->set_margin(Margin(i), c->get_margin(Margin(i)) + sb->get_margin(Margin(i)));
|
||||
|
||||
} else
|
||||
c->hide();
|
||||
|
|
@ -480,7 +448,7 @@ void TabContainer::set_current_tab(int p_current) {
|
|||
}
|
||||
|
||||
_change_notify("current_tab");
|
||||
|
||||
|
||||
if (pending_previous != current)
|
||||
previous = pending_previous;
|
||||
|
||||
|
|
@ -496,25 +464,23 @@ int TabContainer::get_current_tab() const {
|
|||
}
|
||||
|
||||
int TabContainer::get_previous_tab() const {
|
||||
|
||||
return previous;
|
||||
|
||||
return previous;
|
||||
}
|
||||
|
||||
Control* TabContainer::get_tab_control(int p_idx) const {
|
||||
Control *TabContainer::get_tab_control(int p_idx) const {
|
||||
|
||||
int idx=0;
|
||||
int idx = 0;
|
||||
|
||||
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c)
|
||||
continue;
|
||||
if (c->is_set_as_toplevel())
|
||||
continue;
|
||||
if (idx==p_idx) {
|
||||
if (idx == p_idx) {
|
||||
return c;
|
||||
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
|
|
@ -522,21 +488,19 @@ Control* TabContainer::get_tab_control(int p_idx) const {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
Control* TabContainer::get_current_tab_control() const {
|
||||
Control *TabContainer::get_current_tab_control() const {
|
||||
|
||||
int idx=0;
|
||||
int idx = 0;
|
||||
|
||||
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c)
|
||||
continue;
|
||||
if (c->is_set_as_toplevel())
|
||||
continue;
|
||||
if (idx==current) {
|
||||
if (idx == current) {
|
||||
return c;
|
||||
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
|
|
@ -547,24 +511,24 @@ Control* TabContainer::get_current_tab_control() const {
|
|||
void TabContainer::remove_child_notify(Node *p_child) {
|
||||
|
||||
int tc = get_tab_count();
|
||||
if (current==tc-1) {
|
||||
if (current == tc - 1) {
|
||||
current--;
|
||||
if (current<0)
|
||||
current=0;
|
||||
if (current < 0)
|
||||
current = 0;
|
||||
else {
|
||||
call_deferred("set_current_tab",current);
|
||||
call_deferred("set_current_tab", current);
|
||||
}
|
||||
}
|
||||
|
||||
p_child->disconnect("renamed", this,"_child_renamed_callback");
|
||||
p_child->disconnect("renamed", this, "_child_renamed_callback");
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void TabContainer::set_tab_align(TabAlign p_align) {
|
||||
|
||||
ERR_FAIL_INDEX(p_align,3);
|
||||
align=p_align;
|
||||
ERR_FAIL_INDEX(p_align, 3);
|
||||
align = p_align;
|
||||
update();
|
||||
|
||||
_change_notify("tab_align");
|
||||
|
|
@ -577,21 +541,20 @@ TabContainer::TabAlign TabContainer::get_tab_align() const {
|
|||
|
||||
void TabContainer::set_tabs_visible(bool p_visibe) {
|
||||
|
||||
if (p_visibe==tabs_visible)
|
||||
if (p_visibe == tabs_visible)
|
||||
return;
|
||||
|
||||
tabs_visible=p_visibe;
|
||||
tabs_visible = p_visibe;
|
||||
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c)
|
||||
continue;
|
||||
if (p_visibe)
|
||||
c->set_margin(MARGIN_TOP,_get_top_margin());
|
||||
c->set_margin(MARGIN_TOP, _get_top_margin());
|
||||
else
|
||||
c->set_margin(MARGIN_TOP,0);
|
||||
|
||||
c->set_margin(MARGIN_TOP, 0);
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
|
@ -599,60 +562,53 @@ void TabContainer::set_tabs_visible(bool p_visibe) {
|
|||
bool TabContainer::are_tabs_visible() const {
|
||||
|
||||
return tabs_visible;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Control *TabContainer::_get_tab(int p_idx) const {
|
||||
|
||||
int idx=0;
|
||||
int idx = 0;
|
||||
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c)
|
||||
continue;
|
||||
if (c->is_set_as_toplevel())
|
||||
continue;
|
||||
if (idx==p_idx)
|
||||
if (idx == p_idx)
|
||||
return c;
|
||||
idx++;
|
||||
|
||||
}
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
void TabContainer::set_tab_title(int p_tab,const String& p_title) {
|
||||
void TabContainer::set_tab_title(int p_tab, const String &p_title) {
|
||||
|
||||
Control *child = _get_tab(p_tab);
|
||||
ERR_FAIL_COND(!child);
|
||||
child->set_meta("_tab_name",p_title);
|
||||
|
||||
child->set_meta("_tab_name", p_title);
|
||||
}
|
||||
|
||||
String TabContainer::get_tab_title(int p_tab) const{
|
||||
String TabContainer::get_tab_title(int p_tab) const {
|
||||
|
||||
Control *child = _get_tab(p_tab);
|
||||
ERR_FAIL_COND_V(!child,"");
|
||||
ERR_FAIL_COND_V(!child, "");
|
||||
if (child->has_meta("_tab_name"))
|
||||
return child->get_meta("_tab_name");
|
||||
else
|
||||
return child->get_name();
|
||||
|
||||
}
|
||||
|
||||
void TabContainer::set_tab_icon(int p_tab,const Ref<Texture>& p_icon){
|
||||
void TabContainer::set_tab_icon(int p_tab, const Ref<Texture> &p_icon) {
|
||||
|
||||
Control *child = _get_tab(p_tab);
|
||||
ERR_FAIL_COND(!child);
|
||||
child->set_meta("_tab_icon",p_icon);
|
||||
|
||||
child->set_meta("_tab_icon", p_icon);
|
||||
}
|
||||
Ref<Texture> TabContainer::get_tab_icon(int p_tab) const{
|
||||
Ref<Texture> TabContainer::get_tab_icon(int p_tab) const {
|
||||
|
||||
Control *child = _get_tab(p_tab);
|
||||
ERR_FAIL_COND_V(!child,Ref<Texture>());
|
||||
ERR_FAIL_COND_V(!child, Ref<Texture>());
|
||||
if (child->has_meta("_tab_icon"))
|
||||
return child->get_meta("_tab_icon");
|
||||
else
|
||||
|
|
@ -661,7 +617,7 @@ Ref<Texture> TabContainer::get_tab_icon(int p_tab) const{
|
|||
|
||||
void TabContainer::get_translatable_strings(List<String> *p_strings) const {
|
||||
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c)
|
||||
|
|
@ -674,17 +630,16 @@ void TabContainer::get_translatable_strings(List<String> *p_strings) const {
|
|||
|
||||
String name = c->get_meta("_tab_name");
|
||||
|
||||
if (name!="")
|
||||
if (name != "")
|
||||
p_strings->push_back(name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Size2 TabContainer::get_minimum_size() const {
|
||||
|
||||
Size2 ms;
|
||||
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
|
||||
Control *c = get_child(i)->cast_to<Control>();
|
||||
if (!c)
|
||||
|
|
@ -696,52 +651,51 @@ Size2 TabContainer::get_minimum_size() const {
|
|||
continue;
|
||||
|
||||
Size2 cms = c->get_combined_minimum_size();
|
||||
ms.x=MAX(ms.x,cms.x);
|
||||
ms.y=MAX(ms.y,cms.y);
|
||||
ms.x = MAX(ms.x, cms.x);
|
||||
ms.y = MAX(ms.y, cms.y);
|
||||
}
|
||||
|
||||
Ref<StyleBox> tab_bg = get_stylebox("tab_bg");
|
||||
Ref<StyleBox> tab_fg = get_stylebox("tab_fg");
|
||||
Ref<Font> font = get_font("font");
|
||||
|
||||
ms.y+=MAX(tab_bg->get_minimum_size().y,tab_fg->get_minimum_size().y);
|
||||
ms.y+=font->get_height();
|
||||
ms.y += MAX(tab_bg->get_minimum_size().y, tab_fg->get_minimum_size().y);
|
||||
ms.y += font->get_height();
|
||||
|
||||
Ref<StyleBox> sb = get_stylebox("panel");
|
||||
ms+=sb->get_minimum_size();
|
||||
ms += sb->get_minimum_size();
|
||||
|
||||
return ms;
|
||||
}
|
||||
|
||||
void TabContainer::set_popup(Node *p_popup) {
|
||||
ERR_FAIL_NULL(p_popup);
|
||||
popup=p_popup->cast_to<Popup>();
|
||||
popup = p_popup->cast_to<Popup>();
|
||||
update();
|
||||
}
|
||||
|
||||
Popup* TabContainer::get_popup() const {
|
||||
Popup *TabContainer::get_popup() const {
|
||||
return popup;
|
||||
}
|
||||
|
||||
|
||||
void TabContainer::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("_input_event"), &TabContainer::_input_event);
|
||||
ObjectTypeDB::bind_method(_MD("get_tab_count"), &TabContainer::get_tab_count);
|
||||
ObjectTypeDB::bind_method(_MD("set_current_tab","tab_idx"), &TabContainer::set_current_tab);
|
||||
ObjectTypeDB::bind_method(_MD("set_current_tab", "tab_idx"), &TabContainer::set_current_tab);
|
||||
ObjectTypeDB::bind_method(_MD("get_current_tab"), &TabContainer::get_current_tab);
|
||||
ObjectTypeDB::bind_method(_MD("get_previous_tab"), &TabContainer::get_previous_tab);
|
||||
ObjectTypeDB::bind_method(_MD("get_current_tab_control:Control"), &TabContainer::get_current_tab_control);
|
||||
ObjectTypeDB::bind_method(_MD("get_tab_control:Control","idx"), &TabContainer::get_tab_control);
|
||||
ObjectTypeDB::bind_method(_MD("set_tab_align","align"), &TabContainer::set_tab_align);
|
||||
ObjectTypeDB::bind_method(_MD("get_tab_control:Control", "idx"), &TabContainer::get_tab_control);
|
||||
ObjectTypeDB::bind_method(_MD("set_tab_align", "align"), &TabContainer::set_tab_align);
|
||||
ObjectTypeDB::bind_method(_MD("get_tab_align"), &TabContainer::get_tab_align);
|
||||
ObjectTypeDB::bind_method(_MD("set_tabs_visible","visible"), &TabContainer::set_tabs_visible);
|
||||
ObjectTypeDB::bind_method(_MD("set_tabs_visible", "visible"), &TabContainer::set_tabs_visible);
|
||||
ObjectTypeDB::bind_method(_MD("are_tabs_visible"), &TabContainer::are_tabs_visible);
|
||||
ObjectTypeDB::bind_method(_MD("set_tab_title","tab_idx","title"), &TabContainer::set_tab_title);
|
||||
ObjectTypeDB::bind_method(_MD("get_tab_title","tab_idx"), &TabContainer::get_tab_title);
|
||||
ObjectTypeDB::bind_method(_MD("set_tab_icon","tab_idx","icon:Texture"), &TabContainer::set_tab_icon);
|
||||
ObjectTypeDB::bind_method(_MD("get_tab_icon:Texture","tab_idx"), &TabContainer::get_tab_icon);
|
||||
ObjectTypeDB::bind_method(_MD("set_popup","popup:Popup"), &TabContainer::set_popup);
|
||||
ObjectTypeDB::bind_method(_MD("set_tab_title", "tab_idx", "title"), &TabContainer::set_tab_title);
|
||||
ObjectTypeDB::bind_method(_MD("get_tab_title", "tab_idx"), &TabContainer::get_tab_title);
|
||||
ObjectTypeDB::bind_method(_MD("set_tab_icon", "tab_idx", "icon:Texture"), &TabContainer::set_tab_icon);
|
||||
ObjectTypeDB::bind_method(_MD("get_tab_icon:Texture", "tab_idx"), &TabContainer::get_tab_icon);
|
||||
ObjectTypeDB::bind_method(_MD("set_popup", "popup:Popup"), &TabContainer::set_popup);
|
||||
ObjectTypeDB::bind_method(_MD("get_popup:Popup"), &TabContainer::get_popup);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("_child_renamed_callback"), &TabContainer::_child_renamed_callback);
|
||||
|
|
@ -750,10 +704,9 @@ void TabContainer::_bind_methods() {
|
|||
ADD_SIGNAL(MethodInfo("tab_selected", PropertyInfo(Variant::INT, "tab")));
|
||||
ADD_SIGNAL(MethodInfo("pre_popup_pressed"));
|
||||
|
||||
ADD_PROPERTY( PropertyInfo(Variant::INT, "tab_align", PROPERTY_HINT_ENUM,"Left,Center,Right"), _SCS("set_tab_align"), _SCS("get_tab_align") );
|
||||
ADD_PROPERTY( PropertyInfo(Variant::INT, "current_tab", PROPERTY_HINT_RANGE,"-1,4096,1",PROPERTY_USAGE_EDITOR), _SCS("set_current_tab"), _SCS("get_current_tab") );
|
||||
ADD_PROPERTY( PropertyInfo(Variant::BOOL, "tabs_visible"), _SCS("set_tabs_visible"), _SCS("are_tabs_visible") );
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "tab_align", PROPERTY_HINT_ENUM, "Left,Center,Right"), _SCS("set_tab_align"), _SCS("get_tab_align"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "current_tab", PROPERTY_HINT_RANGE, "-1,4096,1", PROPERTY_USAGE_EDITOR), _SCS("set_current_tab"), _SCS("get_current_tab"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "tabs_visible"), _SCS("set_tabs_visible"), _SCS("are_tabs_visible"));
|
||||
}
|
||||
|
||||
TabContainer::TabContainer() {
|
||||
|
|
@ -767,5 +720,4 @@ TabContainer::TabContainer() {
|
|||
align = ALIGN_CENTER;
|
||||
tabs_visible = true;
|
||||
popup = NULL;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,22 +29,21 @@
|
|||
#ifndef TAB_CONTAINER_H
|
||||
#define TAB_CONTAINER_H
|
||||
|
||||
|
||||
#include "scene/gui/control.h"
|
||||
#include "scene/gui/popup.h"
|
||||
class TabContainer : public Control {
|
||||
|
||||
OBJ_TYPE( TabContainer, Control );
|
||||
public:
|
||||
OBJ_TYPE(TabContainer, Control);
|
||||
|
||||
public:
|
||||
enum TabAlign {
|
||||
|
||||
ALIGN_LEFT,
|
||||
ALIGN_CENTER,
|
||||
ALIGN_RIGHT
|
||||
};
|
||||
private:
|
||||
|
||||
private:
|
||||
int mouse_x_cache;
|
||||
int tab_display_ofs;
|
||||
int tabs_ofs_cache;
|
||||
|
|
@ -58,11 +57,9 @@ private:
|
|||
int _get_top_margin() const;
|
||||
Popup *popup;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
void _child_renamed_callback();
|
||||
void _input_event(const InputEvent& p_event);
|
||||
void _input_event(const InputEvent &p_event);
|
||||
void _notification(int p_what);
|
||||
virtual void add_child_notify(Node *p_child);
|
||||
virtual void remove_child_notify(Node *p_child);
|
||||
|
|
@ -70,40 +67,36 @@ protected:
|
|||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
|
||||
|
||||
void set_tab_align(TabAlign p_align);
|
||||
TabAlign get_tab_align() const;
|
||||
|
||||
void set_tabs_visible(bool p_visibe);
|
||||
bool are_tabs_visible() const;
|
||||
|
||||
void set_tab_title(int p_tab,const String& p_title);
|
||||
void set_tab_title(int p_tab, const String &p_title);
|
||||
String get_tab_title(int p_tab) const;
|
||||
|
||||
void set_tab_icon(int p_tab,const Ref<Texture>& p_icon);
|
||||
void set_tab_icon(int p_tab, const Ref<Texture> &p_icon);
|
||||
Ref<Texture> get_tab_icon(int p_tab) const;
|
||||
|
||||
int get_tab_count() const;
|
||||
void set_current_tab(int p_current);
|
||||
int get_current_tab() const;
|
||||
int get_previous_tab() const;
|
||||
|
||||
Control* get_tab_control(int p_idx) const;
|
||||
Control* get_current_tab_control() const;
|
||||
|
||||
Control *get_tab_control(int p_idx) const;
|
||||
Control *get_current_tab_control() const;
|
||||
|
||||
virtual Size2 get_minimum_size() const;
|
||||
|
||||
virtual void get_translatable_strings(List<String> *p_strings) const;
|
||||
|
||||
void set_popup(Node *p_popup);
|
||||
Popup* get_popup() const;
|
||||
|
||||
Popup *get_popup() const;
|
||||
|
||||
TabContainer();
|
||||
};
|
||||
|
||||
|
||||
VARIANT_ENUM_CAST( TabContainer::TabAlign );
|
||||
VARIANT_ENUM_CAST(TabContainer::TabAlign);
|
||||
|
||||
#endif // TAB_CONTAINER_H
|
||||
|
|
|
|||
|
|
@ -36,150 +36,144 @@ Size2 Tabs::get_minimum_size() const {
|
|||
Ref<StyleBox> tab_fg = get_stylebox("tab_fg");
|
||||
Ref<Font> font = get_font("font");
|
||||
|
||||
Size2 ms(0, MAX(tab_bg->get_minimum_size().height, tab_fg->get_minimum_size().height)+font->get_height());
|
||||
Size2 ms(0, MAX(tab_bg->get_minimum_size().height, tab_fg->get_minimum_size().height) + font->get_height());
|
||||
|
||||
for(int i=0;i<tabs.size();i++) {
|
||||
for (int i = 0; i < tabs.size(); i++) {
|
||||
|
||||
Ref<Texture> tex = tabs[i].icon;
|
||||
if (tex.is_valid()) {
|
||||
ms.height = MAX(ms.height, tex->get_size().height);
|
||||
if (tabs[i].text!="")
|
||||
ms.width+=get_constant("hseparation");
|
||||
if (tabs[i].text != "")
|
||||
ms.width += get_constant("hseparation");
|
||||
}
|
||||
|
||||
ms.width+=font->get_string_size(tabs[i].text).width;
|
||||
ms.width += font->get_string_size(tabs[i].text).width;
|
||||
|
||||
if (current==i)
|
||||
ms.width+=tab_fg->get_minimum_size().width;
|
||||
if (current == i)
|
||||
ms.width += tab_fg->get_minimum_size().width;
|
||||
else
|
||||
ms.width+=tab_bg->get_minimum_size().width;
|
||||
ms.width += tab_bg->get_minimum_size().width;
|
||||
|
||||
if (tabs[i].right_button.is_valid()) {
|
||||
Ref<Texture> rb=tabs[i].right_button;
|
||||
Ref<Texture> rb = tabs[i].right_button;
|
||||
Size2 bms = rb->get_size();
|
||||
bms.width+=get_constant("hseparation");
|
||||
ms.width+=bms.width;
|
||||
ms.height=MAX(bms.height+tab_bg->get_minimum_size().height,ms.height);
|
||||
bms.width += get_constant("hseparation");
|
||||
ms.width += bms.width;
|
||||
ms.height = MAX(bms.height + tab_bg->get_minimum_size().height, ms.height);
|
||||
}
|
||||
|
||||
if (cb_displaypolicy==CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy==CLOSE_BUTTON_SHOW_ACTIVE_ONLY && i==current)) {
|
||||
Ref<Texture> cb=get_icon("close");
|
||||
if (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && i == current)) {
|
||||
Ref<Texture> cb = get_icon("close");
|
||||
Size2 bms = cb->get_size();
|
||||
bms.width+=get_constant("hseparation");
|
||||
ms.width+=bms.width;
|
||||
ms.height=MAX(bms.height+tab_bg->get_minimum_size().height,ms.height);
|
||||
bms.width += get_constant("hseparation");
|
||||
ms.width += bms.width;
|
||||
ms.height = MAX(bms.height + tab_bg->get_minimum_size().height, ms.height);
|
||||
}
|
||||
}
|
||||
|
||||
ms.width=0; //TODO: should make this optional
|
||||
ms.width = 0; //TODO: should make this optional
|
||||
return ms;
|
||||
}
|
||||
|
||||
void Tabs::_input_event(const InputEvent &p_event) {
|
||||
|
||||
void Tabs::_input_event(const InputEvent& p_event) {
|
||||
if (p_event.type == InputEvent::MOUSE_MOTION) {
|
||||
|
||||
if (p_event.type==InputEvent::MOUSE_MOTION) {
|
||||
Point2 pos(p_event.mouse_motion.x, p_event.mouse_motion.y);
|
||||
|
||||
Point2 pos( p_event.mouse_motion.x, p_event.mouse_motion.y );
|
||||
|
||||
hilite_arrow=-1;
|
||||
hilite_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();
|
||||
int limit = get_size().width - incr->get_width() - decr->get_width();
|
||||
|
||||
if (pos.x>limit+decr->get_width()) {
|
||||
hilite_arrow=1;
|
||||
} else if (pos.x>limit) {
|
||||
hilite_arrow=0;
|
||||
if (pos.x > limit + decr->get_width()) {
|
||||
hilite_arrow = 1;
|
||||
} else if (pos.x > limit) {
|
||||
hilite_arrow = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// test hovering to display right or close button
|
||||
int hover_buttons=-1;
|
||||
hover=-1;
|
||||
for(int i=0;i<tabs.size();i++) {
|
||||
int hover_buttons = -1;
|
||||
hover = -1;
|
||||
for (int i = 0; i < tabs.size(); i++) {
|
||||
|
||||
if (i<offset)
|
||||
if (i < offset)
|
||||
continue;
|
||||
|
||||
if (tabs[i].rb_rect.has_point(pos)) {
|
||||
rb_hover=i;
|
||||
cb_hover=-1;
|
||||
rb_hover = i;
|
||||
cb_hover = -1;
|
||||
hover_buttons = i;
|
||||
break;
|
||||
} else if (tabs[i].cb_rect.has_point(pos)) {
|
||||
cb_hover = i;
|
||||
rb_hover = -1;
|
||||
hover_buttons = i;
|
||||
break;
|
||||
}
|
||||
else if (tabs[i].cb_rect.has_point(pos)) {
|
||||
cb_hover=i;
|
||||
rb_hover=-1;
|
||||
hover_buttons = i;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (hover_buttons == -1) { // no hover
|
||||
rb_hover= hover_buttons;
|
||||
cb_hover= hover_buttons;
|
||||
rb_hover = hover_buttons;
|
||||
cb_hover = hover_buttons;
|
||||
}
|
||||
update();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (rb_pressing && p_event.type == InputEvent::MOUSE_BUTTON &&
|
||||
!p_event.mouse_button.pressed &&
|
||||
p_event.mouse_button.button_index == BUTTON_LEFT) {
|
||||
|
||||
if (rb_pressing && p_event.type==InputEvent::MOUSE_BUTTON &&
|
||||
!p_event.mouse_button.pressed &&
|
||||
p_event.mouse_button.button_index==BUTTON_LEFT) {
|
||||
|
||||
if (rb_hover!=-1) {
|
||||
if (rb_hover != -1) {
|
||||
//pressed
|
||||
emit_signal("right_button_pressed",rb_hover);
|
||||
emit_signal("right_button_pressed", rb_hover);
|
||||
}
|
||||
|
||||
rb_pressing=false;
|
||||
rb_pressing = false;
|
||||
update();
|
||||
}
|
||||
|
||||
if (cb_pressing && p_event.type == InputEvent::MOUSE_BUTTON &&
|
||||
!p_event.mouse_button.pressed &&
|
||||
p_event.mouse_button.button_index == BUTTON_LEFT) {
|
||||
|
||||
if (cb_pressing && p_event.type==InputEvent::MOUSE_BUTTON &&
|
||||
!p_event.mouse_button.pressed &&
|
||||
p_event.mouse_button.button_index==BUTTON_LEFT) {
|
||||
|
||||
if (cb_hover!=-1) {
|
||||
if (cb_hover != -1) {
|
||||
//pressed
|
||||
emit_signal("tab_close",cb_hover);
|
||||
emit_signal("tab_close", cb_hover);
|
||||
}
|
||||
|
||||
cb_pressing=false;
|
||||
cb_pressing = false;
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
if (p_event.type==InputEvent::MOUSE_BUTTON &&
|
||||
p_event.mouse_button.pressed &&
|
||||
p_event.mouse_button.button_index==BUTTON_LEFT) {
|
||||
if (p_event.type == InputEvent::MOUSE_BUTTON &&
|
||||
p_event.mouse_button.pressed &&
|
||||
p_event.mouse_button.button_index == BUTTON_LEFT) {
|
||||
|
||||
// clicks
|
||||
Point2 pos( p_event.mouse_button.x, p_event.mouse_button.y );
|
||||
Point2 pos(p_event.mouse_button.x, p_event.mouse_button.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();
|
||||
int limit = get_size().width - incr->get_width() - decr->get_width();
|
||||
|
||||
if (pos.x>limit+decr->get_width()) {
|
||||
if (pos.x > limit + decr->get_width()) {
|
||||
if (missing_right) {
|
||||
offset++;
|
||||
update();
|
||||
}
|
||||
return;
|
||||
} else if (pos.x>limit) {
|
||||
if (offset>0) {
|
||||
} else if (pos.x > limit) {
|
||||
if (offset > 0) {
|
||||
offset--;
|
||||
update();
|
||||
}
|
||||
|
|
@ -187,49 +181,46 @@ void Tabs::_input_event(const InputEvent& p_event) {
|
|||
}
|
||||
}
|
||||
|
||||
int found=-1;
|
||||
for(int i=0;i<tabs.size();i++) {
|
||||
int found = -1;
|
||||
for (int i = 0; i < tabs.size(); i++) {
|
||||
|
||||
if (i<offset)
|
||||
if (i < offset)
|
||||
continue;
|
||||
|
||||
if (tabs[i].rb_rect.has_point(pos)) {
|
||||
rb_pressing=true;
|
||||
rb_pressing = true;
|
||||
update();
|
||||
return;
|
||||
}
|
||||
|
||||
if (tabs[i].cb_rect.has_point(pos)) {
|
||||
cb_pressing=true;
|
||||
cb_pressing = true;
|
||||
update();
|
||||
return;
|
||||
}
|
||||
|
||||
if (pos.x >=tabs[i].ofs_cache && pos.x<tabs[i].ofs_cache+tabs[i].size_cache) {
|
||||
found=i;
|
||||
if (pos.x >= tabs[i].ofs_cache && pos.x < tabs[i].ofs_cache + tabs[i].size_cache) {
|
||||
found = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (found!=-1) {
|
||||
if (found != -1) {
|
||||
|
||||
set_current_tab(found);
|
||||
emit_signal("tab_changed",found);
|
||||
emit_signal("tab_changed", found);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Tabs::_notification(int p_what) {
|
||||
|
||||
switch(p_what) {
|
||||
switch (p_what) {
|
||||
|
||||
case NOTIFICATION_MOUSE_EXIT: {
|
||||
rb_hover=-1;
|
||||
cb_hover=-1;
|
||||
hover=-1;
|
||||
rb_hover = -1;
|
||||
cb_hover = -1;
|
||||
hover = -1;
|
||||
update();
|
||||
} break;
|
||||
case NOTIFICATION_RESIZED: {
|
||||
|
|
@ -245,27 +236,26 @@ void Tabs::_notification(int p_what) {
|
|||
Ref<Font> font = get_font("font");
|
||||
Color color_fg = get_color("font_color_fg");
|
||||
Color color_bg = get_color("font_color_bg");
|
||||
Ref<Texture> close=get_icon("close");
|
||||
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++) {
|
||||
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 (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;
|
||||
if (w < 0) {
|
||||
w = 0;
|
||||
}
|
||||
|
||||
Ref<Texture> incr = get_icon("increment");
|
||||
|
|
@ -273,134 +263,129 @@ void Tabs::_notification(int p_what) {
|
|||
Ref<Texture> incr_hl = get_icon("increment_hilite");
|
||||
Ref<Texture> decr_hl = get_icon("decrement_hilite");
|
||||
|
||||
int limit=get_size().width - incr->get_size().width - decr->get_size().width;
|
||||
int limit = get_size().width - incr->get_size().width - decr->get_size().width;
|
||||
|
||||
missing_right=false;
|
||||
missing_right = false;
|
||||
|
||||
for(int i=0;i<tabs.size();i++) {
|
||||
for (int i = 0; i < tabs.size(); i++) {
|
||||
|
||||
if (i<offset)
|
||||
if (i < offset)
|
||||
continue;
|
||||
|
||||
tabs[i].ofs_cache=w;
|
||||
tabs[i].ofs_cache = w;
|
||||
|
||||
int lsize = get_tab_width(i);
|
||||
|
||||
String text = tabs[i].text;
|
||||
int slen = font->get_string_size(text).width;
|
||||
|
||||
if (w+lsize > limit) {
|
||||
max_drawn_tab=i-1;
|
||||
missing_right=true;
|
||||
if (w + lsize > limit) {
|
||||
max_drawn_tab = i - 1;
|
||||
missing_right = true;
|
||||
break;
|
||||
} else {
|
||||
max_drawn_tab=i;
|
||||
max_drawn_tab = i;
|
||||
}
|
||||
|
||||
|
||||
Ref<StyleBox> sb;
|
||||
Color col;
|
||||
|
||||
if (i==current) {
|
||||
sb=tab_fg;
|
||||
col=color_fg;
|
||||
if (i == current) {
|
||||
sb = tab_fg;
|
||||
col = color_fg;
|
||||
} else {
|
||||
sb=tab_bg;
|
||||
col=color_bg;
|
||||
sb = tab_bg;
|
||||
col = color_bg;
|
||||
}
|
||||
|
||||
|
||||
Rect2 sb_rect = Rect2(w, 0, lsize, h);
|
||||
sb->draw(ci, sb_rect);
|
||||
|
||||
w+=sb->get_margin(MARGIN_LEFT);
|
||||
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 (text!="")
|
||||
w+=icon->get_width()+get_constant("hseparation");
|
||||
|
||||
icon->draw(ci, Point2i(w, sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - icon->get_height()) / 2));
|
||||
if (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() ), text, col );
|
||||
font->draw(ci, Point2i(w, sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - font->get_height()) / 2 + font->get_ascent()), text, col);
|
||||
|
||||
w+=slen;
|
||||
w += slen;
|
||||
|
||||
if (tabs[i].right_button.is_valid()) {
|
||||
|
||||
Ref<StyleBox> style = get_stylebox("button");
|
||||
Ref<Texture> rb=tabs[i].right_button;
|
||||
Ref<Texture> rb = tabs[i].right_button;
|
||||
|
||||
w+=get_constant("hseparation");
|
||||
w += get_constant("hseparation");
|
||||
|
||||
Rect2 rb_rect;
|
||||
rb_rect.size=style->get_minimum_size()+rb->get_size();
|
||||
rb_rect.pos.x=w;
|
||||
rb_rect.pos.y=sb->get_margin(MARGIN_TOP)+((sb_rect.size.y-sb_ms.y)-(rb_rect.size.y))/2;
|
||||
rb_rect.size = style->get_minimum_size() + rb->get_size();
|
||||
rb_rect.pos.x = w;
|
||||
rb_rect.pos.y = sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - (rb_rect.size.y)) / 2;
|
||||
|
||||
if (rb_hover==i) {
|
||||
if (rb_hover == i) {
|
||||
if (rb_pressing)
|
||||
get_stylebox("button_pressed")->draw(ci,rb_rect);
|
||||
get_stylebox("button_pressed")->draw(ci, rb_rect);
|
||||
else
|
||||
style->draw(ci,rb_rect);
|
||||
style->draw(ci, rb_rect);
|
||||
}
|
||||
|
||||
rb->draw(ci,Point2i( w+style->get_margin(MARGIN_LEFT), rb_rect.pos.y+style->get_margin(MARGIN_TOP) ));
|
||||
w+=rb->get_width();
|
||||
tabs[i].rb_rect=rb_rect;
|
||||
|
||||
rb->draw(ci, Point2i(w + style->get_margin(MARGIN_LEFT), rb_rect.pos.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)) {
|
||||
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;
|
||||
Ref<Texture> cb = close;
|
||||
|
||||
w+=get_constant("hseparation");
|
||||
w += get_constant("hseparation");
|
||||
|
||||
Rect2 cb_rect;
|
||||
cb_rect.size=style->get_minimum_size()+cb->get_size();
|
||||
cb_rect.pos.x=w;
|
||||
cb_rect.pos.y=sb->get_margin(MARGIN_TOP)+((sb_rect.size.y-sb_ms.y)-(cb_rect.size.y))/2;
|
||||
cb_rect.size = style->get_minimum_size() + cb->get_size();
|
||||
cb_rect.pos.x = w;
|
||||
cb_rect.pos.y = sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - (cb_rect.size.y)) / 2;
|
||||
|
||||
if (cb_hover==i) {
|
||||
if (cb_hover == i) {
|
||||
if (cb_pressing)
|
||||
get_stylebox("button_pressed")->draw(ci,cb_rect);
|
||||
get_stylebox("button_pressed")->draw(ci, cb_rect);
|
||||
else
|
||||
style->draw(ci,cb_rect);
|
||||
style->draw(ci, cb_rect);
|
||||
}
|
||||
|
||||
cb->draw(ci,Point2i( w+style->get_margin(MARGIN_LEFT), cb_rect.pos.y+style->get_margin(MARGIN_TOP) ));
|
||||
w+=cb->get_width();
|
||||
tabs[i].cb_rect=cb_rect;
|
||||
cb->draw(ci, Point2i(w + style->get_margin(MARGIN_LEFT), cb_rect.pos.y + style->get_margin(MARGIN_TOP)));
|
||||
w += cb->get_width();
|
||||
tabs[i].cb_rect = cb_rect;
|
||||
}
|
||||
|
||||
w+=sb->get_margin(MARGIN_RIGHT);
|
||||
|
||||
tabs[i].size_cache=w-tabs[i].ofs_cache;
|
||||
w += sb->get_margin(MARGIN_RIGHT);
|
||||
|
||||
tabs[i].size_cache = w - tabs[i].ofs_cache;
|
||||
}
|
||||
|
||||
if (offset>0 || missing_right) {
|
||||
if (offset > 0 || missing_right) {
|
||||
|
||||
int vofs = (get_size().height-incr->get_size().height)/2;
|
||||
int vofs = (get_size().height - incr->get_size().height) / 2;
|
||||
|
||||
if (offset>0)
|
||||
draw_texture(hilite_arrow==0 ? decr_hl : decr, Point2(limit,vofs));
|
||||
if (offset > 0)
|
||||
draw_texture(hilite_arrow == 0 ? decr_hl : decr, Point2(limit, vofs));
|
||||
else
|
||||
draw_texture(decr,Point2(limit,vofs), Color(1,1,1,0.5));
|
||||
draw_texture(decr, Point2(limit, vofs), Color(1, 1, 1, 0.5));
|
||||
|
||||
if (missing_right)
|
||||
draw_texture(hilite_arrow==1 ? incr_hl : incr, Point2(limit+decr->get_size().width,vofs));
|
||||
draw_texture(hilite_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));
|
||||
draw_texture(incr, Point2(limit + decr->get_size().width, vofs), Color(1, 1, 1, 0.5));
|
||||
|
||||
buttons_visible=true;
|
||||
buttons_visible = true;
|
||||
} else {
|
||||
buttons_visible=false;
|
||||
buttons_visible = false;
|
||||
}
|
||||
|
||||
} break;
|
||||
|
|
@ -412,12 +397,11 @@ int Tabs::get_tab_count() const {
|
|||
return tabs.size();
|
||||
}
|
||||
|
||||
|
||||
void Tabs::set_current_tab(int p_current) {
|
||||
|
||||
ERR_FAIL_INDEX( p_current, get_tab_count() );
|
||||
ERR_FAIL_INDEX(p_current, get_tab_count());
|
||||
|
||||
current=p_current;
|
||||
current = p_current;
|
||||
|
||||
_change_notify("current_tab");
|
||||
update();
|
||||
|
|
@ -428,98 +412,85 @@ int Tabs::get_current_tab() const {
|
|||
return current;
|
||||
}
|
||||
|
||||
void Tabs::set_tab_title(int p_tab, const String &p_title) {
|
||||
|
||||
void Tabs::set_tab_title(int p_tab,const String& p_title) {
|
||||
|
||||
ERR_FAIL_INDEX(p_tab,tabs.size());
|
||||
tabs[p_tab].text=p_title;
|
||||
ERR_FAIL_INDEX(p_tab, tabs.size());
|
||||
tabs[p_tab].text = p_title;
|
||||
update();
|
||||
minimum_size_changed();
|
||||
|
||||
}
|
||||
|
||||
String Tabs::get_tab_title(int p_tab) const{
|
||||
String Tabs::get_tab_title(int p_tab) const {
|
||||
|
||||
ERR_FAIL_INDEX_V(p_tab,tabs.size(),"");
|
||||
ERR_FAIL_INDEX_V(p_tab, tabs.size(), "");
|
||||
return tabs[p_tab].text;
|
||||
|
||||
}
|
||||
|
||||
void Tabs::set_tab_icon(int p_tab, const Ref<Texture> &p_icon) {
|
||||
|
||||
void Tabs::set_tab_icon(int p_tab,const Ref<Texture>& p_icon){
|
||||
|
||||
ERR_FAIL_INDEX(p_tab,tabs.size());
|
||||
tabs[p_tab].icon=p_icon;
|
||||
ERR_FAIL_INDEX(p_tab, tabs.size());
|
||||
tabs[p_tab].icon = p_icon;
|
||||
update();
|
||||
minimum_size_changed();
|
||||
|
||||
}
|
||||
|
||||
Ref<Texture> Tabs::get_tab_icon(int p_tab) const{
|
||||
Ref<Texture> Tabs::get_tab_icon(int p_tab) const {
|
||||
|
||||
ERR_FAIL_INDEX_V(p_tab,tabs.size(),Ref<Texture>());
|
||||
ERR_FAIL_INDEX_V(p_tab, tabs.size(), Ref<Texture>());
|
||||
return tabs[p_tab].icon;
|
||||
|
||||
}
|
||||
|
||||
void Tabs::set_tab_right_button(int p_tab, const Ref<Texture> &p_right_button) {
|
||||
|
||||
void Tabs::set_tab_right_button(int p_tab,const Ref<Texture>& p_right_button){
|
||||
|
||||
ERR_FAIL_INDEX(p_tab,tabs.size());
|
||||
tabs[p_tab].right_button=p_right_button;
|
||||
ERR_FAIL_INDEX(p_tab, tabs.size());
|
||||
tabs[p_tab].right_button = p_right_button;
|
||||
update();
|
||||
minimum_size_changed();
|
||||
|
||||
}
|
||||
Ref<Texture> Tabs::get_tab_right_button(int p_tab) const{
|
||||
Ref<Texture> Tabs::get_tab_right_button(int p_tab) const {
|
||||
|
||||
ERR_FAIL_INDEX_V(p_tab,tabs.size(),Ref<Texture>());
|
||||
ERR_FAIL_INDEX_V(p_tab, tabs.size(), Ref<Texture>());
|
||||
return tabs[p_tab].right_button;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Tabs::add_tab(const String& p_str,const Ref<Texture>& p_icon) {
|
||||
void Tabs::add_tab(const String &p_str, const Ref<Texture> &p_icon) {
|
||||
|
||||
Tab t;
|
||||
t.text=p_str;
|
||||
t.icon=p_icon;
|
||||
t.text = p_str;
|
||||
t.icon = p_icon;
|
||||
|
||||
tabs.push_back(t);
|
||||
|
||||
update();
|
||||
minimum_size_changed();
|
||||
|
||||
}
|
||||
|
||||
void Tabs::clear_tabs() {
|
||||
tabs.clear();
|
||||
current=0;
|
||||
current = 0;
|
||||
update();
|
||||
}
|
||||
|
||||
void Tabs::remove_tab(int p_idx) {
|
||||
|
||||
ERR_FAIL_INDEX(p_idx,tabs.size());
|
||||
ERR_FAIL_INDEX(p_idx, tabs.size());
|
||||
tabs.remove(p_idx);
|
||||
if (current>=p_idx)
|
||||
if (current >= p_idx)
|
||||
current--;
|
||||
update();
|
||||
minimum_size_changed();
|
||||
|
||||
if (current<0)
|
||||
current=0;
|
||||
if (current>=tabs.size())
|
||||
current=tabs.size()-1;
|
||||
if (current < 0)
|
||||
current = 0;
|
||||
if (current >= tabs.size())
|
||||
current = tabs.size() - 1;
|
||||
|
||||
_ensure_no_over_offset();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Tabs::set_tab_align(TabAlign p_align) {
|
||||
|
||||
tab_align=p_align;
|
||||
tab_align = p_align;
|
||||
update();
|
||||
}
|
||||
|
||||
|
|
@ -530,46 +501,43 @@ Tabs::TabAlign Tabs::get_tab_align() const {
|
|||
|
||||
int Tabs::get_tab_width(int p_idx) const {
|
||||
|
||||
ERR_FAIL_INDEX_V(p_idx,tabs.size(),0);
|
||||
ERR_FAIL_INDEX_V(p_idx, tabs.size(), 0);
|
||||
|
||||
Ref<StyleBox> tab_bg = get_stylebox("tab_bg");
|
||||
Ref<StyleBox> tab_fg = get_stylebox("tab_fg");
|
||||
Ref<Font> font = get_font("font");
|
||||
|
||||
|
||||
int x=0;
|
||||
int x = 0;
|
||||
|
||||
Ref<Texture> tex = tabs[p_idx].icon;
|
||||
if (tex.is_valid()) {
|
||||
x+=tex->get_width();
|
||||
if (tabs[p_idx].text!="")
|
||||
x+=get_constant("hseparation");
|
||||
|
||||
x += tex->get_width();
|
||||
if (tabs[p_idx].text != "")
|
||||
x += get_constant("hseparation");
|
||||
}
|
||||
|
||||
x+=font->get_string_size(tabs[p_idx].text).width;
|
||||
x += font->get_string_size(tabs[p_idx].text).width;
|
||||
|
||||
if (current==p_idx)
|
||||
x+=tab_fg->get_minimum_size().width;
|
||||
if (current == p_idx)
|
||||
x += tab_fg->get_minimum_size().width;
|
||||
else
|
||||
x+=tab_bg->get_minimum_size().width;
|
||||
x += tab_bg->get_minimum_size().width;
|
||||
|
||||
if (tabs[p_idx].right_button.is_valid()) {
|
||||
Ref<Texture> rb=tabs[p_idx].right_button;
|
||||
x+=rb->get_width();
|
||||
x+=get_constant("hseparation");
|
||||
Ref<Texture> rb = tabs[p_idx].right_button;
|
||||
x += rb->get_width();
|
||||
x += get_constant("hseparation");
|
||||
}
|
||||
|
||||
if (cb_displaypolicy==CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy==CLOSE_BUTTON_SHOW_ACTIVE_ONLY && p_idx==current)) {
|
||||
Ref<Texture> cb=get_icon("close");
|
||||
x+=cb->get_width();
|
||||
x+=get_constant("hseparation");
|
||||
if (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && p_idx == current)) {
|
||||
Ref<Texture> cb = get_icon("close");
|
||||
x += cb->get_width();
|
||||
x += get_constant("hseparation");
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
void Tabs::_ensure_no_over_offset() {
|
||||
|
||||
if (!is_inside_tree())
|
||||
|
|
@ -578,17 +546,17 @@ void Tabs::_ensure_no_over_offset() {
|
|||
Ref<Texture> incr = get_icon("increment");
|
||||
Ref<Texture> decr = get_icon("decrement");
|
||||
|
||||
int limit=get_size().width-incr->get_width()-decr->get_width();
|
||||
int limit = get_size().width - incr->get_width() - decr->get_width();
|
||||
|
||||
while(offset>0) {
|
||||
while (offset > 0) {
|
||||
|
||||
int total_w=0;
|
||||
for(int i=0;i<tabs.size();i++) {
|
||||
int total_w = 0;
|
||||
for (int i = 0; i < tabs.size(); i++) {
|
||||
|
||||
if (i<offset-1)
|
||||
if (i < offset - 1)
|
||||
continue;
|
||||
|
||||
total_w+=get_tab_width(i);
|
||||
total_w += get_tab_width(i);
|
||||
}
|
||||
|
||||
if (total_w < limit) {
|
||||
|
|
@ -598,44 +566,40 @@ void Tabs::_ensure_no_over_offset() {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Tabs::ensure_tab_visible(int p_idx) {
|
||||
|
||||
if (!is_inside_tree())
|
||||
return;
|
||||
|
||||
ERR_FAIL_INDEX(p_idx,tabs.size());
|
||||
ERR_FAIL_INDEX(p_idx, tabs.size());
|
||||
|
||||
_ensure_no_over_offset();
|
||||
|
||||
if (p_idx<=offset) {
|
||||
offset=p_idx;
|
||||
if (p_idx <= offset) {
|
||||
offset = p_idx;
|
||||
update();
|
||||
return;
|
||||
}
|
||||
|
||||
Ref<Texture> incr = get_icon("increment");
|
||||
Ref<Texture> decr = get_icon("decrement");
|
||||
int limit=get_size().width-incr->get_width()-decr->get_width();
|
||||
int limit = get_size().width - incr->get_width() - decr->get_width();
|
||||
|
||||
int x = 0;
|
||||
for (int i = 0; i < tabs.size(); i++) {
|
||||
|
||||
int x=0;
|
||||
for(int i=0;i<tabs.size();i++) {
|
||||
|
||||
if (i<offset)
|
||||
if (i < offset)
|
||||
continue;
|
||||
|
||||
int sz = get_tab_width(i);
|
||||
tabs[i].x_cache=x;
|
||||
tabs[i].x_size_cache=sz;
|
||||
x+=sz;
|
||||
|
||||
tabs[i].x_cache = x;
|
||||
tabs[i].x_size_cache = sz;
|
||||
x += sz;
|
||||
}
|
||||
|
||||
while(offset<tabs.size() && ( (tabs[p_idx].x_cache + tabs[p_idx].x_size_cache) - tabs[offset].x_cache) > limit) {
|
||||
while (offset < tabs.size() && ((tabs[p_idx].x_cache + tabs[p_idx].x_size_cache) - tabs[offset].x_cache) > limit) {
|
||||
offset++;
|
||||
}
|
||||
|
||||
|
|
@ -643,55 +607,52 @@ void Tabs::ensure_tab_visible(int p_idx) {
|
|||
}
|
||||
|
||||
void Tabs::set_tab_close_display_policy(CloseButtonDisplayPolicy p_policy) {
|
||||
cb_displaypolicy=p_policy;
|
||||
cb_displaypolicy = p_policy;
|
||||
update();
|
||||
}
|
||||
|
||||
void Tabs::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("_input_event"),&Tabs::_input_event);
|
||||
ObjectTypeDB::bind_method(_MD("get_tab_count"),&Tabs::get_tab_count);
|
||||
ObjectTypeDB::bind_method(_MD("set_current_tab","tab_idx"),&Tabs::set_current_tab);
|
||||
ObjectTypeDB::bind_method(_MD("get_current_tab"),&Tabs::get_current_tab);
|
||||
ObjectTypeDB::bind_method(_MD("set_tab_title","tab_idx","title"),&Tabs::set_tab_title);
|
||||
ObjectTypeDB::bind_method(_MD("get_tab_title","tab_idx"),&Tabs::get_tab_title);
|
||||
ObjectTypeDB::bind_method(_MD("set_tab_icon","tab_idx","icon:Texture"),&Tabs::set_tab_icon);
|
||||
ObjectTypeDB::bind_method(_MD("get_tab_icon:Texture","tab_idx"),&Tabs::get_tab_icon);
|
||||
ObjectTypeDB::bind_method(_MD("remove_tab","tab_idx"),&Tabs::remove_tab);
|
||||
ObjectTypeDB::bind_method(_MD("add_tab","title","icon:Texture"),&Tabs::add_tab);
|
||||
ObjectTypeDB::bind_method(_MD("set_tab_align","align"),&Tabs::set_tab_align);
|
||||
ObjectTypeDB::bind_method(_MD("get_tab_align"),&Tabs::get_tab_align);
|
||||
ObjectTypeDB::bind_method(_MD("ensure_tab_visible","idx"),&Tabs::ensure_tab_visible);
|
||||
ObjectTypeDB::bind_method(_MD("_input_event"), &Tabs::_input_event);
|
||||
ObjectTypeDB::bind_method(_MD("get_tab_count"), &Tabs::get_tab_count);
|
||||
ObjectTypeDB::bind_method(_MD("set_current_tab", "tab_idx"), &Tabs::set_current_tab);
|
||||
ObjectTypeDB::bind_method(_MD("get_current_tab"), &Tabs::get_current_tab);
|
||||
ObjectTypeDB::bind_method(_MD("set_tab_title", "tab_idx", "title"), &Tabs::set_tab_title);
|
||||
ObjectTypeDB::bind_method(_MD("get_tab_title", "tab_idx"), &Tabs::get_tab_title);
|
||||
ObjectTypeDB::bind_method(_MD("set_tab_icon", "tab_idx", "icon:Texture"), &Tabs::set_tab_icon);
|
||||
ObjectTypeDB::bind_method(_MD("get_tab_icon:Texture", "tab_idx"), &Tabs::get_tab_icon);
|
||||
ObjectTypeDB::bind_method(_MD("remove_tab", "tab_idx"), &Tabs::remove_tab);
|
||||
ObjectTypeDB::bind_method(_MD("add_tab", "title", "icon:Texture"), &Tabs::add_tab);
|
||||
ObjectTypeDB::bind_method(_MD("set_tab_align", "align"), &Tabs::set_tab_align);
|
||||
ObjectTypeDB::bind_method(_MD("get_tab_align"), &Tabs::get_tab_align);
|
||||
ObjectTypeDB::bind_method(_MD("ensure_tab_visible", "idx"), &Tabs::ensure_tab_visible);
|
||||
|
||||
ADD_SIGNAL(MethodInfo("tab_changed",PropertyInfo(Variant::INT,"tab")));
|
||||
ADD_SIGNAL(MethodInfo("right_button_pressed",PropertyInfo(Variant::INT,"tab")));
|
||||
ADD_SIGNAL(MethodInfo("tab_close",PropertyInfo(Variant::INT,"tab")));
|
||||
ADD_SIGNAL(MethodInfo("tab_changed", PropertyInfo(Variant::INT, "tab")));
|
||||
ADD_SIGNAL(MethodInfo("right_button_pressed", PropertyInfo(Variant::INT, "tab")));
|
||||
ADD_SIGNAL(MethodInfo("tab_close", PropertyInfo(Variant::INT, "tab")));
|
||||
|
||||
ADD_PROPERTY( PropertyInfo(Variant::INT, "current_tab", PROPERTY_HINT_RANGE,"-1,4096,1",PROPERTY_USAGE_EDITOR), _SCS("set_current_tab"), _SCS("get_current_tab") );
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "current_tab", PROPERTY_HINT_RANGE, "-1,4096,1", PROPERTY_USAGE_EDITOR), _SCS("set_current_tab"), _SCS("get_current_tab"));
|
||||
|
||||
BIND_CONSTANT( ALIGN_LEFT );
|
||||
BIND_CONSTANT( ALIGN_CENTER );
|
||||
BIND_CONSTANT( ALIGN_RIGHT );
|
||||
|
||||
BIND_CONSTANT( CLOSE_BUTTON_SHOW_ACTIVE_ONLY );
|
||||
BIND_CONSTANT( CLOSE_BUTTON_SHOW_ALWAYS );
|
||||
BIND_CONSTANT( CLOSE_BUTTON_SHOW_NEVER );
|
||||
BIND_CONSTANT(ALIGN_LEFT);
|
||||
BIND_CONSTANT(ALIGN_CENTER);
|
||||
BIND_CONSTANT(ALIGN_RIGHT);
|
||||
|
||||
BIND_CONSTANT(CLOSE_BUTTON_SHOW_ACTIVE_ONLY);
|
||||
BIND_CONSTANT(CLOSE_BUTTON_SHOW_ALWAYS);
|
||||
BIND_CONSTANT(CLOSE_BUTTON_SHOW_NEVER);
|
||||
}
|
||||
|
||||
|
||||
Tabs::Tabs() {
|
||||
|
||||
current=0;
|
||||
tab_align=ALIGN_CENTER;
|
||||
rb_hover=-1;
|
||||
rb_pressing=false;
|
||||
hilite_arrow=-1;
|
||||
current = 0;
|
||||
tab_align = ALIGN_CENTER;
|
||||
rb_hover = -1;
|
||||
rb_pressing = false;
|
||||
hilite_arrow = -1;
|
||||
|
||||
cb_hover=-1;
|
||||
cb_pressing=false;
|
||||
cb_hover = -1;
|
||||
cb_pressing = false;
|
||||
cb_displaypolicy = CLOSE_BUTTON_SHOW_NEVER;
|
||||
offset=0;
|
||||
max_drawn_tab=0;
|
||||
|
||||
offset = 0;
|
||||
max_drawn_tab = 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,9 +33,9 @@
|
|||
|
||||
class Tabs : public Control {
|
||||
|
||||
OBJ_TYPE( Tabs, Control );
|
||||
public:
|
||||
OBJ_TYPE(Tabs, Control);
|
||||
|
||||
public:
|
||||
enum TabAlign {
|
||||
|
||||
ALIGN_LEFT,
|
||||
|
|
@ -49,9 +49,8 @@ public:
|
|||
CLOSE_BUTTON_SHOW_ACTIVE_ONLY,
|
||||
CLOSE_BUTTON_SHOW_ALWAYS,
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
|
||||
struct Tab {
|
||||
|
||||
String text;
|
||||
|
|
@ -64,10 +63,8 @@ private:
|
|||
Ref<Texture> right_button;
|
||||
Rect2 rb_rect;
|
||||
Rect2 cb_rect;
|
||||
|
||||
};
|
||||
|
||||
|
||||
int offset;
|
||||
int max_drawn_tab;
|
||||
int hilite_arrow;
|
||||
|
|
@ -85,28 +82,26 @@ private:
|
|||
bool cb_pressing;
|
||||
CloseButtonDisplayPolicy cb_displaypolicy;
|
||||
|
||||
int hover; // hovered tab
|
||||
int hover; // hovered tab
|
||||
|
||||
int get_tab_width(int p_idx) const;
|
||||
void _ensure_no_over_offset();
|
||||
|
||||
protected:
|
||||
|
||||
void _input_event(const InputEvent& p_event);
|
||||
void _input_event(const InputEvent &p_event);
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
void add_tab(const String &p_str = "", const Ref<Texture> &p_icon = Ref<Texture>());
|
||||
|
||||
void add_tab(const String& p_str="",const Ref<Texture>& p_icon=Ref<Texture>());
|
||||
|
||||
void set_tab_title(int p_tab,const String& p_title);
|
||||
void set_tab_title(int p_tab, const String &p_title);
|
||||
String get_tab_title(int p_tab) const;
|
||||
|
||||
void set_tab_icon(int p_tab,const Ref<Texture>& p_icon);
|
||||
void set_tab_icon(int p_tab, const Ref<Texture> &p_icon);
|
||||
Ref<Texture> get_tab_icon(int p_tab) const;
|
||||
|
||||
void set_tab_right_button(int p_tab,const Ref<Texture>& p_right_button);
|
||||
void set_tab_right_button(int p_tab, const Ref<Texture> &p_right_button);
|
||||
Ref<Texture> get_tab_right_button(int p_tab) const;
|
||||
|
||||
void set_tab_align(TabAlign p_align);
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -30,19 +30,18 @@
|
|||
#define TEXT_EDIT_H
|
||||
|
||||
#include "scene/gui/control.h"
|
||||
#include "scene/gui/scroll_bar.h"
|
||||
#include "scene/gui/popup_menu.h"
|
||||
#include "scene/gui/scroll_bar.h"
|
||||
#include "scene/main/timer.h"
|
||||
|
||||
class TextEdit : public Control {
|
||||
|
||||
class TextEdit : public Control {
|
||||
|
||||
OBJ_TYPE( TextEdit, Control );
|
||||
OBJ_TYPE(TextEdit, Control);
|
||||
|
||||
struct Cursor {
|
||||
int last_fit_x;
|
||||
int line,column; ///< cursor
|
||||
int x_ofs,line_ofs;
|
||||
int line, column; ///< cursor
|
||||
int x_ofs, line_ofs;
|
||||
} cursor;
|
||||
|
||||
struct Selection {
|
||||
|
|
@ -55,14 +54,13 @@ class TextEdit : public Control {
|
|||
};
|
||||
|
||||
Mode selecting_mode;
|
||||
int selecting_line,selecting_column;
|
||||
int selecting_line, selecting_column;
|
||||
bool selecting_text;
|
||||
|
||||
|
||||
bool active;
|
||||
|
||||
int from_line,from_column;
|
||||
int to_line,to_column;
|
||||
int from_line, from_column;
|
||||
int to_line, to_column;
|
||||
|
||||
bool shiftclick_left;
|
||||
|
||||
|
|
@ -111,7 +109,13 @@ class TextEdit : public Control {
|
|||
String end_key;
|
||||
bool line_only;
|
||||
bool eq;
|
||||
ColorRegion(const String& p_begin_key="",const String& p_end_key="",const Color &p_color=Color(),bool p_line_only=false) { begin_key=p_begin_key; end_key=p_end_key; color=p_color; line_only=p_line_only || p_end_key==""; eq=begin_key==end_key; }
|
||||
ColorRegion(const String &p_begin_key = "", const String &p_end_key = "", const Color &p_color = Color(), bool p_line_only = false) {
|
||||
begin_key = p_begin_key;
|
||||
end_key = p_end_key;
|
||||
color = p_color;
|
||||
line_only = p_line_only || p_end_key == "";
|
||||
eq = begin_key == end_key;
|
||||
}
|
||||
};
|
||||
|
||||
class Text {
|
||||
|
|
@ -122,43 +126,42 @@ class TextEdit : public Control {
|
|||
bool end;
|
||||
};
|
||||
|
||||
struct Line {
|
||||
int width_cache : 24;
|
||||
bool marked : 1;
|
||||
bool breakpoint : 1;
|
||||
Map<int,ColorRegionInfo> region_info;
|
||||
String data;
|
||||
};
|
||||
private:
|
||||
const Vector<ColorRegion> *color_regions;
|
||||
mutable Vector<Line> text;
|
||||
Ref<Font> font;
|
||||
int tab_size;
|
||||
struct Line {
|
||||
int width_cache : 24;
|
||||
bool marked : 1;
|
||||
bool breakpoint : 1;
|
||||
Map<int, ColorRegionInfo> region_info;
|
||||
String data;
|
||||
};
|
||||
|
||||
void _update_line_cache(int p_line) const;
|
||||
private:
|
||||
const Vector<ColorRegion> *color_regions;
|
||||
mutable Vector<Line> text;
|
||||
Ref<Font> font;
|
||||
int tab_size;
|
||||
|
||||
void _update_line_cache(int p_line) const;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
void set_tab_size(int p_tab_size);
|
||||
void set_font(const Ref<Font>& p_font);
|
||||
void set_color_regions(const Vector<ColorRegion>*p_regions) { color_regions=p_regions; }
|
||||
void set_font(const Ref<Font> &p_font);
|
||||
void set_color_regions(const Vector<ColorRegion> *p_regions) { color_regions = p_regions; }
|
||||
int get_line_width(int p_line) const;
|
||||
int get_max_width() const;
|
||||
const Map<int,ColorRegionInfo>& get_color_region_info(int p_line);
|
||||
void set(int p_line,const String& p_string);
|
||||
void set_marked(int p_line,bool p_marked) { text[p_line].marked=p_marked; }
|
||||
const Map<int, ColorRegionInfo> &get_color_region_info(int p_line);
|
||||
void set(int p_line, const String &p_string);
|
||||
void set_marked(int p_line, bool p_marked) { text[p_line].marked = p_marked; }
|
||||
bool is_marked(int p_line) const { return text[p_line].marked; }
|
||||
void set_breakpoint(int p_line,bool p_breakpoint) { text[p_line].breakpoint=p_breakpoint; }
|
||||
void set_breakpoint(int p_line, bool p_breakpoint) { text[p_line].breakpoint = p_breakpoint; }
|
||||
bool is_breakpoint(int p_line) const { return text[p_line].breakpoint; }
|
||||
void insert(int p_at,const String& p_text);
|
||||
void insert(int p_at, const String &p_text);
|
||||
void remove(int p_at);
|
||||
int size() const { return text.size(); }
|
||||
void clear();
|
||||
void clear_caches();
|
||||
_FORCE_INLINE_ const String& operator[](int p_line) const { return text[p_line].data; }
|
||||
Text() { tab_size=4; }
|
||||
};
|
||||
_FORCE_INLINE_ const String &operator[](int p_line) const { return text[p_line].data; }
|
||||
Text() { tab_size = 4; }
|
||||
};
|
||||
|
||||
struct TextOperation {
|
||||
|
||||
|
|
@ -169,7 +172,7 @@ class TextEdit : public Control {
|
|||
};
|
||||
|
||||
Type type;
|
||||
int from_line,from_column;
|
||||
int from_line, from_column;
|
||||
int to_line, to_column;
|
||||
String text;
|
||||
uint32_t prev_version;
|
||||
|
|
@ -181,15 +184,14 @@ class TextEdit : public Control {
|
|||
TextOperation current_op;
|
||||
|
||||
List<TextOperation> undo_stack;
|
||||
List<TextOperation>::Element *undo_stack_pos;
|
||||
List<TextOperation>::Element *undo_stack_pos;
|
||||
|
||||
void _clear_redo();
|
||||
void _do_text_op(const TextOperation& p_op, bool p_reverse);
|
||||
|
||||
void _do_text_op(const TextOperation &p_op, bool p_reverse);
|
||||
|
||||
//syntax coloring
|
||||
Color symbol_color;
|
||||
HashMap<String,Color> keywords;
|
||||
HashMap<String, Color> keywords;
|
||||
Color custom_bg_color;
|
||||
|
||||
Vector<ColorRegion> color_regions;
|
||||
|
|
@ -257,7 +259,6 @@ class TextEdit : public Control {
|
|||
VScrollBar *v_scroll;
|
||||
bool updating_scrolls;
|
||||
|
||||
|
||||
Object *tooltip_obj;
|
||||
StringName tooltip_func;
|
||||
Variant tooltip_ud;
|
||||
|
|
@ -276,8 +277,8 @@ class TextEdit : public Control {
|
|||
|
||||
int get_char_count();
|
||||
|
||||
int get_char_pos_for(int p_px,String p_pos) const;
|
||||
int get_column_x_offset(int p_column,String p_pos);
|
||||
int get_char_pos_for(int p_px, String p_pos) const;
|
||||
int get_column_x_offset(int p_column, String p_pos);
|
||||
|
||||
void adjust_viewport_to_cursor();
|
||||
void _scroll_moved(double);
|
||||
|
|
@ -290,7 +291,7 @@ class TextEdit : public Control {
|
|||
void _scroll_lines_up();
|
||||
void _scroll_lines_down();
|
||||
|
||||
// void mouse_motion(const Point& p_pos, const Point& p_rel, int p_button_mask);
|
||||
// void mouse_motion(const Point& p_pos, const Point& p_rel, int p_button_mask);
|
||||
Size2 get_minimum_size() const;
|
||||
|
||||
int get_row_height() const;
|
||||
|
|
@ -306,13 +307,13 @@ class TextEdit : public Control {
|
|||
|
||||
/* super internal api, undo/redo builds on it */
|
||||
|
||||
void _base_insert_text(int p_line, int p_column,const String& p_text,int &r_end_line,int &r_end_column);
|
||||
String _base_get_text(int p_from_line, int p_from_column,int p_to_line,int p_to_column) const;
|
||||
void _base_remove_text(int p_from_line, int p_from_column,int p_to_line,int p_to_column);
|
||||
void _base_insert_text(int p_line, int p_column, const String &p_text, int &r_end_line, int &r_end_column);
|
||||
String _base_get_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column) const;
|
||||
void _base_remove_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column);
|
||||
|
||||
int _get_column_pos_of_word(const String &p_key, const String &p_search, uint32_t p_search_flags, int p_from_column);
|
||||
|
||||
DVector<int> _search_bind(const String &p_key,uint32_t p_search_flags, int p_from_line,int p_from_column) const;
|
||||
DVector<int> _search_bind(const String &p_key, uint32_t p_search_flags, int p_from_line, int p_from_column) const;
|
||||
|
||||
PopupMenu *menu;
|
||||
|
||||
|
|
@ -322,16 +323,15 @@ class TextEdit : public Control {
|
|||
void _confirm_completion();
|
||||
void _update_completion_candidates();
|
||||
|
||||
void _get_mouse_pos(const Point2i& p_mouse, int &r_row, int &r_col) const;
|
||||
void _get_mouse_pos(const Point2i &p_mouse, int &r_row, int &r_col) const;
|
||||
|
||||
protected:
|
||||
virtual String get_tooltip(const Point2 &p_pos) const;
|
||||
|
||||
virtual String get_tooltip(const Point2& p_pos) const;
|
||||
|
||||
void _insert_text(int p_line, int p_column,const String& p_text,int *r_end_line=NULL,int *r_end_char=NULL);
|
||||
void _remove_text(int p_from_line, int p_from_column,int p_to_line,int p_to_column);
|
||||
void _insert_text_at_cursor(const String& p_text);
|
||||
void _input_event(const InputEvent& p_input);
|
||||
void _insert_text(int p_line, int p_column, const String &p_text, int *r_end_line = NULL, int *r_end_char = NULL);
|
||||
void _remove_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column);
|
||||
void _insert_text_at_cursor(const String &p_text);
|
||||
void _input_event(const InputEvent &p_input);
|
||||
void _notification(int p_what);
|
||||
|
||||
void _consume_pair_symbol(CharType ch);
|
||||
|
|
@ -339,10 +339,7 @@ protected:
|
|||
|
||||
static void _bind_methods();
|
||||
|
||||
|
||||
|
||||
public:
|
||||
|
||||
enum MenuItems {
|
||||
MENU_CUT,
|
||||
MENU_COPY,
|
||||
|
|
@ -356,12 +353,12 @@ public:
|
|||
|
||||
enum SearchFlags {
|
||||
|
||||
SEARCH_MATCH_CASE=1,
|
||||
SEARCH_WHOLE_WORDS=2,
|
||||
SEARCH_BACKWARDS=4
|
||||
SEARCH_MATCH_CASE = 1,
|
||||
SEARCH_WHOLE_WORDS = 2,
|
||||
SEARCH_BACKWARDS = 4
|
||||
};
|
||||
|
||||
virtual CursorShape get_cursor_shape(const Point2& p_pos=Point2i()) const;
|
||||
virtual CursorShape get_cursor_shape(const Point2 &p_pos = Point2i()) const;
|
||||
|
||||
//void delete_char();
|
||||
//void delete_line();
|
||||
|
|
@ -370,16 +367,16 @@ public:
|
|||
void end_complex_operation();
|
||||
|
||||
void set_text(String p_text);
|
||||
void insert_text_at_cursor(const String& p_text);
|
||||
void insert_at(const String& p_text, int at);
|
||||
void insert_text_at_cursor(const String &p_text);
|
||||
void insert_at(const String &p_text, int at);
|
||||
int get_line_count() const;
|
||||
void set_line_as_marked(int p_line,bool p_marked);
|
||||
void set_line_as_breakpoint(int p_line,bool p_breakpoint);
|
||||
void set_line_as_marked(int p_line, bool p_marked);
|
||||
void set_line_as_breakpoint(int p_line, bool p_breakpoint);
|
||||
bool is_line_set_as_breakpoint(int p_line) const;
|
||||
void get_breakpoints(List<int> *p_breakpoints) const;
|
||||
String get_text();
|
||||
String get_line(int line) const;
|
||||
void set_line(int line, String new_text);
|
||||
void set_line(int line, String new_text);
|
||||
void backspace_at_cursor();
|
||||
|
||||
void indent_selection_left();
|
||||
|
|
@ -393,7 +390,7 @@ public:
|
|||
auto_brace_completion_enabled = p_enabled;
|
||||
}
|
||||
inline void set_brace_matching(bool p_enabled) {
|
||||
brace_matching_enabled=p_enabled;
|
||||
brace_matching_enabled = p_enabled;
|
||||
update();
|
||||
}
|
||||
inline void set_callhint_settings(bool below, Vector2 offset) {
|
||||
|
|
@ -404,8 +401,8 @@ public:
|
|||
|
||||
void center_viewport_to_cursor();
|
||||
|
||||
void cursor_set_column(int p_col, bool p_adjust_viewport=true);
|
||||
void cursor_set_line(int p_row, bool p_adjust_viewport=true);
|
||||
void cursor_set_column(int p_col, bool p_adjust_viewport = true);
|
||||
void cursor_set_line(int p_row, bool p_adjust_viewport = true);
|
||||
|
||||
int cursor_get_column() const;
|
||||
int cursor_get_line() const;
|
||||
|
|
@ -433,10 +430,10 @@ public:
|
|||
void copy();
|
||||
void paste();
|
||||
void select_all();
|
||||
void select(int p_from_line,int p_from_column,int p_to_line,int p_to_column);
|
||||
void select(int p_from_line, int p_from_column, int p_to_line, int p_to_column);
|
||||
void deselect();
|
||||
|
||||
void set_search_text(const String& p_search_text);
|
||||
void set_search_text(const String &p_search_text);
|
||||
void set_search_flags(uint32_t p_flags);
|
||||
void set_current_search_result(int line, int col);
|
||||
|
||||
|
|
@ -444,14 +441,14 @@ public:
|
|||
bool is_highlight_all_occurrences_enabled() const;
|
||||
bool is_selection_active() const;
|
||||
int get_selection_from_line() const;
|
||||
int get_selection_from_column() const;
|
||||
int get_selection_from_column() const;
|
||||
int get_selection_to_line() const;
|
||||
int get_selection_to_column() const;
|
||||
String get_selection_text() const;
|
||||
|
||||
String get_word_under_cursor() const;
|
||||
|
||||
bool search(const String &p_key,uint32_t p_search_flags, int p_from_line, int p_from_column,int &r_line,int &r_column) const;
|
||||
bool search(const String &p_key, uint32_t p_search_flags, int p_from_line, int p_from_column, int &r_line, int &r_column) const;
|
||||
|
||||
void undo();
|
||||
void redo();
|
||||
|
|
@ -464,10 +461,10 @@ public:
|
|||
void set_insert_mode(bool p_enabled);
|
||||
bool is_insert_mode() const;
|
||||
|
||||
void add_keyword_color(const String& p_keyword,const Color& p_color);
|
||||
void add_color_region(const String& p_begin_key=String(),const String& p_end_key=String(),const Color &p_color=Color(),bool p_line_only=false);
|
||||
void set_symbol_color(const Color& p_color);
|
||||
void set_custom_bg_color(const Color& p_color);
|
||||
void add_keyword_color(const String &p_keyword, const Color &p_color);
|
||||
void add_color_region(const String &p_begin_key = String(), const String &p_end_key = String(), const Color &p_color = Color(), bool p_line_only = false);
|
||||
void set_symbol_color(const Color &p_color);
|
||||
void set_custom_bg_color(const Color &p_color);
|
||||
void clear_colors();
|
||||
|
||||
int get_v_scroll() const;
|
||||
|
|
@ -496,21 +493,20 @@ public:
|
|||
void set_breakpoint_gutter_width(int p_gutter_width);
|
||||
int get_breakpoint_gutter_width() const;
|
||||
|
||||
void set_tooltip_request_func(Object *p_obj, const StringName& p_function, const Variant& p_udata);
|
||||
void set_tooltip_request_func(Object *p_obj, const StringName &p_function, const Variant &p_udata);
|
||||
|
||||
void set_completion(bool p_enabled,const Vector<String>& p_prefixes);
|
||||
void set_completion(bool p_enabled, const Vector<String> &p_prefixes);
|
||||
void code_complete(const Vector<String> &p_strings);
|
||||
void set_code_hint(const String& p_hint);
|
||||
void set_code_hint(const String &p_hint);
|
||||
void query_code_comple();
|
||||
|
||||
PopupMenu *get_menu() const;
|
||||
|
||||
String get_text_for_completion();
|
||||
|
||||
virtual bool is_text_field() const;
|
||||
virtual bool is_text_field() const;
|
||||
TextEdit();
|
||||
~TextEdit();
|
||||
};
|
||||
|
||||
|
||||
#endif // TEXT_EDIT_H
|
||||
|
|
|
|||
|
|
@ -31,34 +31,34 @@
|
|||
Size2 TextureButton::get_minimum_size() const {
|
||||
|
||||
Size2 size = Control::get_minimum_size();
|
||||
if(resize_mode == RESIZE_SCALE) {
|
||||
if (resize_mode == RESIZE_SCALE) {
|
||||
if (normal.is_null()) {
|
||||
if (pressed.is_null()) {
|
||||
if (hover.is_null())
|
||||
if (click_mask.is_null())
|
||||
size=Size2();
|
||||
size = Size2();
|
||||
else
|
||||
size=click_mask->get_size();
|
||||
size = click_mask->get_size();
|
||||
else
|
||||
size=hover->get_size();
|
||||
size = hover->get_size();
|
||||
} else
|
||||
size=pressed->get_size();
|
||||
size = pressed->get_size();
|
||||
} else
|
||||
size=normal->get_size();
|
||||
size=size*scale.abs();
|
||||
size = normal->get_size();
|
||||
size = size * scale.abs();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
bool TextureButton::has_point(const Point2& p_point) const {
|
||||
if ( resize_mode == RESIZE_SCALE && (scale[0] == 0 || scale[1] == 0)) {
|
||||
bool TextureButton::has_point(const Point2 &p_point) const {
|
||||
if (resize_mode == RESIZE_SCALE && (scale[0] == 0 || scale[1] == 0)) {
|
||||
return false;
|
||||
}
|
||||
Point2 ppos = (resize_mode == RESIZE_SCALE) ? (p_point/scale.abs()) : p_point;
|
||||
Point2 ppos = (resize_mode == RESIZE_SCALE) ? (p_point / scale.abs()) : p_point;
|
||||
if (click_mask.is_valid()) {
|
||||
|
||||
Point2i p = ppos;
|
||||
if (p.x<0 || p.x>=click_mask->get_size().width || p.y<0 || p.y>=click_mask->get_size().height)
|
||||
if (p.x < 0 || p.x >= click_mask->get_size().width || p.y < 0 || p.y >= click_mask->get_size().height)
|
||||
return false;
|
||||
|
||||
return click_mask->get_bit(p);
|
||||
|
|
@ -67,10 +67,9 @@ bool TextureButton::has_point(const Point2& p_point) const {
|
|||
return Control::has_point(p_point);
|
||||
}
|
||||
|
||||
|
||||
void TextureButton::_notification(int p_what) {
|
||||
|
||||
switch( p_what ) {
|
||||
switch (p_what) {
|
||||
|
||||
case NOTIFICATION_DRAW: {
|
||||
DrawMode draw_mode = get_draw_mode();
|
||||
|
|
@ -81,37 +80,37 @@ void TextureButton::_notification(int p_what) {
|
|||
case DRAW_NORMAL: {
|
||||
|
||||
if (normal.is_valid())
|
||||
texdraw=normal;
|
||||
texdraw = normal;
|
||||
} break;
|
||||
case DRAW_PRESSED: {
|
||||
|
||||
if (pressed.is_null()) {
|
||||
if (hover.is_null()) {
|
||||
if (normal.is_valid())
|
||||
texdraw=normal;
|
||||
texdraw = normal;
|
||||
} else
|
||||
texdraw=hover;
|
||||
texdraw = hover;
|
||||
|
||||
} else
|
||||
texdraw=pressed;
|
||||
texdraw = pressed;
|
||||
} break;
|
||||
case DRAW_HOVER: {
|
||||
|
||||
if (hover.is_null()) {
|
||||
if (pressed.is_valid() && is_pressed())
|
||||
texdraw=pressed;
|
||||
texdraw = pressed;
|
||||
else if (normal.is_valid())
|
||||
texdraw=normal;
|
||||
texdraw = normal;
|
||||
} else
|
||||
texdraw=hover;
|
||||
texdraw = hover;
|
||||
} break;
|
||||
case DRAW_DISABLED: {
|
||||
|
||||
if (disabled.is_null()) {
|
||||
if (normal.is_valid())
|
||||
texdraw=normal;
|
||||
texdraw = normal;
|
||||
} else
|
||||
texdraw=disabled;
|
||||
texdraw = disabled;
|
||||
} break;
|
||||
}
|
||||
|
||||
|
|
@ -120,7 +119,7 @@ void TextureButton::_notification(int p_what) {
|
|||
Size2 size = texdraw->get_size();
|
||||
Rect2 tex_regin = Rect2(Point2(), texdraw->get_size());
|
||||
bool tile = false;
|
||||
if(resize_mode == RESIZE_STRETCH) {
|
||||
if (resize_mode == RESIZE_STRETCH) {
|
||||
switch (stretch_mode) {
|
||||
case STRETCH_KEEP:
|
||||
size = texdraw->get_size();
|
||||
|
|
@ -134,12 +133,12 @@ void TextureButton::_notification(int p_what) {
|
|||
tile = true;
|
||||
break;
|
||||
case STRETCH_KEEP_CENTERED:
|
||||
ofs = (get_size() - texdraw->get_size())/2;
|
||||
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();
|
||||
Size2 _size = get_size();
|
||||
float tex_width = texdraw->get_width() * _size.height / texdraw->get_height();
|
||||
float tex_height = _size.height;
|
||||
|
||||
|
|
@ -148,37 +147,35 @@ void TextureButton::_notification(int p_what) {
|
|||
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;
|
||||
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:{
|
||||
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 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);
|
||||
tex_regin = Rect2(ofs, size / scale);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
size = texdraw->get_size()*scale;
|
||||
} else {
|
||||
size = texdraw->get_size() * scale;
|
||||
}
|
||||
if (tile)
|
||||
draw_texture_rect(texdraw,Rect2(ofs,size),tile,modulate);
|
||||
draw_texture_rect(texdraw, Rect2(ofs, size), tile, modulate);
|
||||
else
|
||||
draw_texture_rect_region(texdraw, Rect2(ofs, size), tex_regin, modulate);
|
||||
}
|
||||
if (has_focus() && focused.is_valid()) {
|
||||
|
||||
Rect2 drect(Point2(), get_size());
|
||||
draw_texture_rect(focused,drect,false,modulate);
|
||||
|
||||
draw_texture_rect(focused, drect, false, modulate);
|
||||
};
|
||||
} break;
|
||||
}
|
||||
|
|
@ -186,38 +183,38 @@ void TextureButton::_notification(int p_what) {
|
|||
|
||||
void TextureButton::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_normal_texture","texture:Texture"),&TextureButton::set_normal_texture);
|
||||
ObjectTypeDB::bind_method(_MD("set_pressed_texture","texture:Texture"),&TextureButton::set_pressed_texture);
|
||||
ObjectTypeDB::bind_method(_MD("set_hover_texture","texture:Texture"),&TextureButton::set_hover_texture);
|
||||
ObjectTypeDB::bind_method(_MD("set_disabled_texture","texture:Texture"),&TextureButton::set_disabled_texture);
|
||||
ObjectTypeDB::bind_method(_MD("set_focused_texture","texture:Texture"),&TextureButton::set_focused_texture);
|
||||
ObjectTypeDB::bind_method(_MD("set_click_mask","mask:BitMap"),&TextureButton::set_click_mask);
|
||||
ObjectTypeDB::bind_method(_MD("set_texture_scale","scale"),&TextureButton::set_texture_scale);
|
||||
ObjectTypeDB::bind_method(_MD("set_modulate","color"),&TextureButton::set_modulate);
|
||||
ObjectTypeDB::bind_method(_MD("set_resize_mode","p_mode"), &TextureButton::set_resize_mode);
|
||||
ObjectTypeDB::bind_method(_MD("set_stretch_mode","p_mode"), & TextureButton::set_stretch_mode );
|
||||
ObjectTypeDB::bind_method(_MD("set_normal_texture", "texture:Texture"), &TextureButton::set_normal_texture);
|
||||
ObjectTypeDB::bind_method(_MD("set_pressed_texture", "texture:Texture"), &TextureButton::set_pressed_texture);
|
||||
ObjectTypeDB::bind_method(_MD("set_hover_texture", "texture:Texture"), &TextureButton::set_hover_texture);
|
||||
ObjectTypeDB::bind_method(_MD("set_disabled_texture", "texture:Texture"), &TextureButton::set_disabled_texture);
|
||||
ObjectTypeDB::bind_method(_MD("set_focused_texture", "texture:Texture"), &TextureButton::set_focused_texture);
|
||||
ObjectTypeDB::bind_method(_MD("set_click_mask", "mask:BitMap"), &TextureButton::set_click_mask);
|
||||
ObjectTypeDB::bind_method(_MD("set_texture_scale", "scale"), &TextureButton::set_texture_scale);
|
||||
ObjectTypeDB::bind_method(_MD("set_modulate", "color"), &TextureButton::set_modulate);
|
||||
ObjectTypeDB::bind_method(_MD("set_resize_mode", "p_mode"), &TextureButton::set_resize_mode);
|
||||
ObjectTypeDB::bind_method(_MD("set_stretch_mode", "p_mode"), &TextureButton::set_stretch_mode);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("get_normal_texture:Texture"),&TextureButton::get_normal_texture);
|
||||
ObjectTypeDB::bind_method(_MD("get_pressed_texture:Texture"),&TextureButton::get_pressed_texture);
|
||||
ObjectTypeDB::bind_method(_MD("get_hover_texture:Texture"),&TextureButton::get_hover_texture);
|
||||
ObjectTypeDB::bind_method(_MD("get_disabled_texture:Texture"),&TextureButton::get_disabled_texture);
|
||||
ObjectTypeDB::bind_method(_MD("get_focused_texture:Texture"),&TextureButton::get_focused_texture);
|
||||
ObjectTypeDB::bind_method(_MD("get_click_mask:BitMap"),&TextureButton::get_click_mask);
|
||||
ObjectTypeDB::bind_method(_MD("get_texture_scale"),&TextureButton::get_texture_scale);
|
||||
ObjectTypeDB::bind_method(_MD("get_modulate"),&TextureButton::get_modulate);
|
||||
ObjectTypeDB::bind_method(_MD("get_resize_mode"), & TextureButton::get_resize_mode);
|
||||
ObjectTypeDB::bind_method(_MD("get_normal_texture:Texture"), &TextureButton::get_normal_texture);
|
||||
ObjectTypeDB::bind_method(_MD("get_pressed_texture:Texture"), &TextureButton::get_pressed_texture);
|
||||
ObjectTypeDB::bind_method(_MD("get_hover_texture:Texture"), &TextureButton::get_hover_texture);
|
||||
ObjectTypeDB::bind_method(_MD("get_disabled_texture:Texture"), &TextureButton::get_disabled_texture);
|
||||
ObjectTypeDB::bind_method(_MD("get_focused_texture:Texture"), &TextureButton::get_focused_texture);
|
||||
ObjectTypeDB::bind_method(_MD("get_click_mask:BitMap"), &TextureButton::get_click_mask);
|
||||
ObjectTypeDB::bind_method(_MD("get_texture_scale"), &TextureButton::get_texture_scale);
|
||||
ObjectTypeDB::bind_method(_MD("get_modulate"), &TextureButton::get_modulate);
|
||||
ObjectTypeDB::bind_method(_MD("get_resize_mode"), &TextureButton::get_resize_mode);
|
||||
ObjectTypeDB::bind_method(_MD("get_stretch_mode"), &TextureButton::get_stretch_mode);
|
||||
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT,"textures/normal",PROPERTY_HINT_RESOURCE_TYPE,"Texture"), _SCS("set_normal_texture"), _SCS("get_normal_texture"));
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT,"textures/pressed",PROPERTY_HINT_RESOURCE_TYPE,"Texture"), _SCS("set_pressed_texture"), _SCS("get_pressed_texture"));
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT,"textures/hover",PROPERTY_HINT_RESOURCE_TYPE,"Texture"), _SCS("set_hover_texture"), _SCS("get_hover_texture"));
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT,"textures/disabled",PROPERTY_HINT_RESOURCE_TYPE,"Texture"), _SCS("set_disabled_texture"), _SCS("get_disabled_texture"));
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT,"textures/focused",PROPERTY_HINT_RESOURCE_TYPE,"Texture"), _SCS("set_focused_texture"), _SCS("get_focused_texture"));
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT,"textures/click_mask",PROPERTY_HINT_RESOURCE_TYPE,"BitMap"), _SCS("set_click_mask"), _SCS("get_click_mask")) ;
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "params/resize_mode",PROPERTY_HINT_ENUM,"Scale (Compat),Stretch"), _SCS("set_resize_mode"), _SCS("get_resize_mode"));
|
||||
ADD_PROPERTYNO(PropertyInfo(Variant::VECTOR2,"params/scale",PROPERTY_HINT_RANGE,"0.01,1024,0.01"), _SCS("set_texture_scale"), _SCS("get_texture_scale"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "params/stretch_mode",PROPERTY_HINT_ENUM,"Scale On Expand (Compat),Scale,Tile,Keep,Keep Centered,Keep Aspect,Keep Aspect Centered,Keep Aspect Covered"), _SCS("set_stretch_mode"),_SCS("get_stretch_mode"));
|
||||
ADD_PROPERTYNO(PropertyInfo(Variant::COLOR,"params/modulate"), _SCS("set_modulate"), _SCS("get_modulate"));
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "textures/normal", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), _SCS("set_normal_texture"), _SCS("get_normal_texture"));
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "textures/pressed", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), _SCS("set_pressed_texture"), _SCS("get_pressed_texture"));
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "textures/hover", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), _SCS("set_hover_texture"), _SCS("get_hover_texture"));
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "textures/disabled", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), _SCS("set_disabled_texture"), _SCS("get_disabled_texture"));
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "textures/focused", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), _SCS("set_focused_texture"), _SCS("get_focused_texture"));
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "textures/click_mask", PROPERTY_HINT_RESOURCE_TYPE, "BitMap"), _SCS("set_click_mask"), _SCS("get_click_mask"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "params/resize_mode", PROPERTY_HINT_ENUM, "Scale (Compat),Stretch"), _SCS("set_resize_mode"), _SCS("get_resize_mode"));
|
||||
ADD_PROPERTYNO(PropertyInfo(Variant::VECTOR2, "params/scale", PROPERTY_HINT_RANGE, "0.01,1024,0.01"), _SCS("set_texture_scale"), _SCS("get_texture_scale"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "params/stretch_mode", PROPERTY_HINT_ENUM, "Scale On Expand (Compat),Scale,Tile,Keep,Keep Centered,Keep Aspect,Keep Aspect Centered,Keep Aspect Covered"), _SCS("set_stretch_mode"), _SCS("get_stretch_mode"));
|
||||
ADD_PROPERTYNO(PropertyInfo(Variant::COLOR, "params/modulate"), _SCS("set_modulate"), _SCS("get_modulate"));
|
||||
|
||||
BIND_CONSTANT(STRETCH_SCALE_ON_EXPAND);
|
||||
BIND_CONSTANT(STRETCH_SCALE);
|
||||
|
|
@ -229,36 +226,31 @@ void TextureButton::_bind_methods() {
|
|||
BIND_CONSTANT(STRETCH_KEEP_ASPECT_COVERED);
|
||||
}
|
||||
|
||||
void TextureButton::set_normal_texture(const Ref<Texture> &p_normal) {
|
||||
|
||||
void TextureButton::set_normal_texture(const Ref<Texture>& p_normal) {
|
||||
|
||||
normal=p_normal;
|
||||
normal = p_normal;
|
||||
update();
|
||||
minimum_size_changed();
|
||||
|
||||
}
|
||||
|
||||
void TextureButton::set_pressed_texture(const Ref<Texture>& p_pressed) {
|
||||
void TextureButton::set_pressed_texture(const Ref<Texture> &p_pressed) {
|
||||
|
||||
pressed=p_pressed;
|
||||
pressed = p_pressed;
|
||||
update();
|
||||
|
||||
}
|
||||
void TextureButton::set_hover_texture(const Ref<Texture>& p_hover) {
|
||||
void TextureButton::set_hover_texture(const Ref<Texture> &p_hover) {
|
||||
|
||||
hover=p_hover;
|
||||
hover = p_hover;
|
||||
update();
|
||||
|
||||
}
|
||||
void TextureButton::set_disabled_texture(const Ref<Texture>& p_disabled) {
|
||||
void TextureButton::set_disabled_texture(const Ref<Texture> &p_disabled) {
|
||||
|
||||
disabled=p_disabled;
|
||||
disabled = p_disabled;
|
||||
update();
|
||||
|
||||
}
|
||||
void TextureButton::set_click_mask(const Ref<BitMap>& p_click_mask) {
|
||||
void TextureButton::set_click_mask(const Ref<BitMap> &p_click_mask) {
|
||||
|
||||
click_mask=p_click_mask;
|
||||
click_mask = p_click_mask;
|
||||
update();
|
||||
}
|
||||
|
||||
|
|
@ -288,13 +280,13 @@ Ref<Texture> TextureButton::get_focused_texture() const {
|
|||
return focused;
|
||||
};
|
||||
|
||||
void TextureButton::set_focused_texture(const Ref<Texture>& p_focused) {
|
||||
void TextureButton::set_focused_texture(const Ref<Texture> &p_focused) {
|
||||
|
||||
focused = p_focused;
|
||||
};
|
||||
|
||||
void TextureButton::set_modulate(const Color& p_modulate) {
|
||||
modulate=p_modulate;
|
||||
void TextureButton::set_modulate(const Color &p_modulate) {
|
||||
modulate = p_modulate;
|
||||
update();
|
||||
}
|
||||
|
||||
|
|
@ -331,10 +323,9 @@ TextureButton::StretchMode TextureButton::get_stretch_mode() const {
|
|||
return stretch_mode;
|
||||
}
|
||||
|
||||
|
||||
TextureButton::TextureButton() {
|
||||
modulate=Color(1,1,1);
|
||||
resize_mode=RESIZE_SCALE;
|
||||
scale=Size2(1.0, 1.0);
|
||||
stretch_mode=STRETCH_SCALE_ON_EXPAND;
|
||||
modulate = Color(1, 1, 1);
|
||||
resize_mode = RESIZE_SCALE;
|
||||
scale = Size2(1.0, 1.0);
|
||||
stretch_mode = STRETCH_SCALE_ON_EXPAND;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,8 @@
|
|||
|
||||
class TextureButton : public BaseButton {
|
||||
|
||||
OBJ_TYPE( TextureButton, BaseButton );
|
||||
OBJ_TYPE(TextureButton, BaseButton);
|
||||
|
||||
public:
|
||||
enum ResizeMode {
|
||||
RESIZE_SCALE, // for backwards compatibility
|
||||
|
|
@ -65,20 +66,18 @@ private:
|
|||
StretchMode stretch_mode;
|
||||
|
||||
protected:
|
||||
|
||||
virtual bool has_point(const Point2& p_point) const;
|
||||
virtual bool has_point(const Point2 &p_point) const;
|
||||
virtual Size2 get_minimum_size() const;
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
|
||||
void set_normal_texture(const Ref<Texture>& p_normal);
|
||||
void set_pressed_texture(const Ref<Texture>& p_pressed);
|
||||
void set_hover_texture(const Ref<Texture>& p_hover);
|
||||
void set_disabled_texture(const Ref<Texture>& p_disabled);
|
||||
void set_focused_texture(const Ref<Texture>& p_focused);
|
||||
void set_click_mask(const Ref<BitMap>& p_image);
|
||||
void set_normal_texture(const Ref<Texture> &p_normal);
|
||||
void set_pressed_texture(const Ref<Texture> &p_pressed);
|
||||
void set_hover_texture(const Ref<Texture> &p_hover);
|
||||
void set_disabled_texture(const Ref<Texture> &p_disabled);
|
||||
void set_focused_texture(const Ref<Texture> &p_focused);
|
||||
void set_click_mask(const Ref<BitMap> &p_image);
|
||||
|
||||
Ref<Texture> get_normal_texture() const;
|
||||
Ref<Texture> get_pressed_texture() const;
|
||||
|
|
@ -87,7 +86,7 @@ public:
|
|||
Ref<Texture> get_focused_texture() const;
|
||||
Ref<BitMap> get_click_mask() const;
|
||||
|
||||
void set_modulate(const Color& p_modulate);
|
||||
void set_modulate(const Color &p_modulate);
|
||||
Color get_modulate() const;
|
||||
|
||||
ResizeMode get_resize_mode() const;
|
||||
|
|
@ -102,6 +101,6 @@ public:
|
|||
TextureButton();
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST( TextureButton::ResizeMode );
|
||||
VARIANT_ENUM_CAST( TextureButton::StretchMode );
|
||||
VARIANT_ENUM_CAST(TextureButton::ResizeMode);
|
||||
VARIANT_ENUM_CAST(TextureButton::StretchMode);
|
||||
#endif // TEXTURE_BUTTON_H
|
||||
|
|
|
|||
|
|
@ -31,67 +31,65 @@
|
|||
|
||||
void TextureFrame::_notification(int p_what) {
|
||||
|
||||
if (p_what==NOTIFICATION_DRAW) {
|
||||
if (p_what == NOTIFICATION_DRAW) {
|
||||
|
||||
if (texture.is_null())
|
||||
return;
|
||||
|
||||
|
||||
switch(stretch_mode) {
|
||||
switch (stretch_mode) {
|
||||
case STRETCH_SCALE_ON_EXPAND: {
|
||||
Size2 s=expand?get_size():texture->get_size();
|
||||
draw_texture_rect(texture,Rect2(Point2(),s),false,modulate);
|
||||
Size2 s = expand ? get_size() : texture->get_size();
|
||||
draw_texture_rect(texture, Rect2(Point2(), s), false, modulate);
|
||||
} break;
|
||||
case STRETCH_SCALE: {
|
||||
draw_texture_rect(texture,Rect2(Point2(),get_size()),false,modulate);
|
||||
draw_texture_rect(texture, Rect2(Point2(), get_size()), false, modulate);
|
||||
} break;
|
||||
case STRETCH_TILE: {
|
||||
draw_texture_rect(texture,Rect2(Point2(),get_size()),true,modulate);
|
||||
draw_texture_rect(texture, Rect2(Point2(), get_size()), true, modulate);
|
||||
} break;
|
||||
case STRETCH_KEEP: {
|
||||
draw_texture_rect(texture,Rect2(Point2(),texture->get_size()),false,modulate);
|
||||
draw_texture_rect(texture, Rect2(Point2(), texture->get_size()), false, modulate);
|
||||
|
||||
} break;
|
||||
case STRETCH_KEEP_CENTERED: {
|
||||
|
||||
Vector2 ofs = (get_size() - texture->get_size())/2;
|
||||
draw_texture_rect(texture,Rect2(ofs,texture->get_size()),false,modulate);
|
||||
Vector2 ofs = (get_size() - texture->get_size()) / 2;
|
||||
draw_texture_rect(texture, Rect2(ofs, texture->get_size()), false, modulate);
|
||||
} break;
|
||||
case STRETCH_KEEP_ASPECT_CENTERED:
|
||||
case STRETCH_KEEP_ASPECT: {
|
||||
|
||||
Size2 size=get_size();
|
||||
int tex_width = texture->get_width() * size.height / texture ->get_height();
|
||||
Size2 size = get_size();
|
||||
int tex_width = texture->get_width() * size.height / texture->get_height();
|
||||
int tex_height = size.height;
|
||||
|
||||
if (tex_width>size.width) {
|
||||
tex_width=size.width;
|
||||
tex_height=texture->get_height() * tex_width / texture->get_width();
|
||||
if (tex_width > size.width) {
|
||||
tex_width = size.width;
|
||||
tex_height = texture->get_height() * tex_width / texture->get_width();
|
||||
}
|
||||
|
||||
int ofs_x = 0;
|
||||
int ofs_y = 0;
|
||||
|
||||
if (stretch_mode==STRETCH_KEEP_ASPECT_CENTERED) {
|
||||
ofs_x+=(size.width - tex_width)/2;
|
||||
ofs_y+=(size.height - tex_height)/2;
|
||||
if (stretch_mode == STRETCH_KEEP_ASPECT_CENTERED) {
|
||||
ofs_x += (size.width - tex_width) / 2;
|
||||
ofs_y += (size.height - tex_height) / 2;
|
||||
}
|
||||
|
||||
draw_texture_rect(texture,Rect2(ofs_x,ofs_y,tex_width,tex_height),false,modulate);
|
||||
draw_texture_rect(texture, Rect2(ofs_x, ofs_y, tex_width, tex_height), false, modulate);
|
||||
} break;
|
||||
case STRETCH_KEEP_ASPECT_COVERED: {
|
||||
|
||||
Size2 size = get_size();
|
||||
Size2 tex_size = texture->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 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;
|
||||
|
||||
draw_texture_rect_region(texture, Rect2(Point2(), size), Rect2(ofs, size/scale), modulate);
|
||||
draw_texture_rect_region(texture, Rect2(Point2(), size), Rect2(ofs, size / scale), modulate);
|
||||
} break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -104,35 +102,33 @@ Size2 TextureFrame::get_minimum_size() const {
|
|||
}
|
||||
void TextureFrame::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_texture", "texture"), &TextureFrame::set_texture);
|
||||
ObjectTypeDB::bind_method(_MD("get_texture"), &TextureFrame::get_texture);
|
||||
ObjectTypeDB::bind_method(_MD("set_modulate", "modulate"), &TextureFrame::set_modulate);
|
||||
ObjectTypeDB::bind_method(_MD("get_modulate"), &TextureFrame::get_modulate);
|
||||
ObjectTypeDB::bind_method(_MD("set_expand", "enable"), &TextureFrame::set_expand);
|
||||
ObjectTypeDB::bind_method(_MD("has_expand"), &TextureFrame::has_expand);
|
||||
ObjectTypeDB::bind_method(_MD("set_stretch_mode", "stretch_mode"), &TextureFrame::set_stretch_mode);
|
||||
ObjectTypeDB::bind_method(_MD("get_stretch_mode"), &TextureFrame::get_stretch_mode);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_texture","texture"), & TextureFrame::set_texture );
|
||||
ObjectTypeDB::bind_method(_MD("get_texture"), & TextureFrame::get_texture );
|
||||
ObjectTypeDB::bind_method(_MD("set_modulate","modulate"), & TextureFrame::set_modulate );
|
||||
ObjectTypeDB::bind_method(_MD("get_modulate"), & TextureFrame::get_modulate );
|
||||
ObjectTypeDB::bind_method(_MD("set_expand","enable"), & TextureFrame::set_expand );
|
||||
ObjectTypeDB::bind_method(_MD("has_expand"), & TextureFrame::has_expand );
|
||||
ObjectTypeDB::bind_method(_MD("set_stretch_mode","stretch_mode"), & TextureFrame::set_stretch_mode );
|
||||
ObjectTypeDB::bind_method(_MD("get_stretch_mode"), & TextureFrame::get_stretch_mode );
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), _SCS("set_texture"), _SCS("get_texture"));
|
||||
ADD_PROPERTYNO(PropertyInfo(Variant::COLOR, "modulate"), _SCS("set_modulate"), _SCS("get_modulate"));
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "expand"), _SCS("set_expand"), _SCS("has_expand"));
|
||||
ADD_PROPERTYNO(PropertyInfo(Variant::INT, "stretch_mode", PROPERTY_HINT_ENUM, "Scale On Expand (Compat),Scale,Tile,Keep,Keep Centered,Keep Aspect,Keep Aspect Centered,Keep Aspect Covered"), _SCS("set_stretch_mode"), _SCS("get_stretch_mode"));
|
||||
|
||||
ADD_PROPERTYNZ( PropertyInfo( Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), _SCS("set_texture"),_SCS("get_texture") );
|
||||
ADD_PROPERTYNO( PropertyInfo( Variant::COLOR, "modulate"), _SCS("set_modulate"),_SCS("get_modulate") );
|
||||
ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "expand" ), _SCS("set_expand"),_SCS("has_expand") );
|
||||
ADD_PROPERTYNO( PropertyInfo( Variant::INT, "stretch_mode",PROPERTY_HINT_ENUM,"Scale On Expand (Compat),Scale,Tile,Keep,Keep Centered,Keep Aspect,Keep Aspect Centered,Keep Aspect Covered"), _SCS("set_stretch_mode"),_SCS("get_stretch_mode") );
|
||||
|
||||
BIND_CONSTANT( STRETCH_SCALE_ON_EXPAND );
|
||||
BIND_CONSTANT( STRETCH_SCALE );
|
||||
BIND_CONSTANT( STRETCH_TILE );
|
||||
BIND_CONSTANT( STRETCH_KEEP );
|
||||
BIND_CONSTANT( STRETCH_KEEP_CENTERED );
|
||||
BIND_CONSTANT( STRETCH_KEEP_ASPECT );
|
||||
BIND_CONSTANT( STRETCH_KEEP_ASPECT_CENTERED );
|
||||
BIND_CONSTANT( STRETCH_KEEP_ASPECT_COVERED );
|
||||
BIND_CONSTANT(STRETCH_SCALE_ON_EXPAND);
|
||||
BIND_CONSTANT(STRETCH_SCALE);
|
||||
BIND_CONSTANT(STRETCH_TILE);
|
||||
BIND_CONSTANT(STRETCH_KEEP);
|
||||
BIND_CONSTANT(STRETCH_KEEP_CENTERED);
|
||||
BIND_CONSTANT(STRETCH_KEEP_ASPECT);
|
||||
BIND_CONSTANT(STRETCH_KEEP_ASPECT_CENTERED);
|
||||
BIND_CONSTANT(STRETCH_KEEP_ASPECT_COVERED);
|
||||
}
|
||||
|
||||
void TextureFrame::set_texture(const Ref<Texture> &p_tex) {
|
||||
|
||||
void TextureFrame::set_texture(const Ref<Texture>& p_tex) {
|
||||
|
||||
texture=p_tex;
|
||||
texture = p_tex;
|
||||
update();
|
||||
//if (texture.is_valid())
|
||||
// texture->set_flags(texture->get_flags()&(~Texture::FLAG_REPEAT)); //remove repeat from texture, it looks bad in sprites
|
||||
|
|
@ -144,21 +140,20 @@ Ref<Texture> TextureFrame::get_texture() const {
|
|||
return texture;
|
||||
}
|
||||
|
||||
void TextureFrame::set_modulate(const Color& p_tex) {
|
||||
void TextureFrame::set_modulate(const Color &p_tex) {
|
||||
|
||||
modulate=p_tex;
|
||||
modulate = p_tex;
|
||||
update();
|
||||
}
|
||||
|
||||
Color TextureFrame::get_modulate() const{
|
||||
Color TextureFrame::get_modulate() const {
|
||||
|
||||
return modulate;
|
||||
}
|
||||
|
||||
|
||||
void TextureFrame::set_expand(bool p_expand) {
|
||||
|
||||
expand=p_expand;
|
||||
expand = p_expand;
|
||||
update();
|
||||
minimum_size_changed();
|
||||
}
|
||||
|
|
@ -169,7 +164,7 @@ bool TextureFrame::has_expand() const {
|
|||
|
||||
void TextureFrame::set_stretch_mode(StretchMode p_mode) {
|
||||
|
||||
stretch_mode=p_mode;
|
||||
stretch_mode = p_mode;
|
||||
update();
|
||||
}
|
||||
|
||||
|
|
@ -180,14 +175,11 @@ TextureFrame::StretchMode TextureFrame::get_stretch_mode() const {
|
|||
|
||||
TextureFrame::TextureFrame() {
|
||||
|
||||
|
||||
expand=false;
|
||||
modulate=Color(1,1,1,1);
|
||||
expand = false;
|
||||
modulate = Color(1, 1, 1, 1);
|
||||
set_ignore_mouse(true);
|
||||
stretch_mode=STRETCH_SCALE_ON_EXPAND;
|
||||
stretch_mode = STRETCH_SCALE_ON_EXPAND;
|
||||
}
|
||||
|
||||
|
||||
TextureFrame::~TextureFrame()
|
||||
{
|
||||
TextureFrame::~TextureFrame() {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,8 @@
|
|||
*/
|
||||
class TextureFrame : public Control {
|
||||
|
||||
OBJ_TYPE(TextureFrame,Control);
|
||||
OBJ_TYPE(TextureFrame, Control);
|
||||
|
||||
public:
|
||||
enum StretchMode {
|
||||
STRETCH_SCALE_ON_EXPAND, //default, for backwards compatibility
|
||||
|
|
@ -47,23 +48,23 @@ public:
|
|||
STRETCH_KEEP_ASPECT_CENTERED,
|
||||
STRETCH_KEEP_ASPECT_COVERED,
|
||||
};
|
||||
|
||||
private:
|
||||
bool expand;
|
||||
Color modulate;
|
||||
Ref<Texture> texture;
|
||||
StretchMode stretch_mode;
|
||||
protected:
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
virtual Size2 get_minimum_size() const;
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
|
||||
void set_texture(const Ref<Texture>& p_tex);
|
||||
void set_texture(const Ref<Texture> &p_tex);
|
||||
Ref<Texture> get_texture() const;
|
||||
|
||||
void set_modulate(const Color& p_tex);
|
||||
void set_modulate(const Color &p_tex);
|
||||
Color get_modulate() const;
|
||||
|
||||
void set_expand(bool p_expand);
|
||||
|
|
@ -74,8 +75,7 @@ public:
|
|||
|
||||
TextureFrame();
|
||||
~TextureFrame();
|
||||
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST( TextureFrame::StretchMode );
|
||||
VARIANT_ENUM_CAST(TextureFrame::StretchMode);
|
||||
#endif // TEXTURE_FRAME_H
|
||||
|
|
|
|||
|
|
@ -28,31 +28,28 @@
|
|||
/*************************************************************************/
|
||||
#include "texture_progress.h"
|
||||
|
||||
void TextureProgress::set_under_texture(const Ref<Texture> &p_texture) {
|
||||
|
||||
void TextureProgress::set_under_texture(const Ref<Texture>& p_texture) {
|
||||
|
||||
under=p_texture;
|
||||
under = p_texture;
|
||||
update();
|
||||
minimum_size_changed();
|
||||
}
|
||||
|
||||
Ref<Texture> TextureProgress::get_under_texture() const{
|
||||
Ref<Texture> TextureProgress::get_under_texture() const {
|
||||
|
||||
return under;
|
||||
|
||||
}
|
||||
|
||||
void TextureProgress::set_over_texture(const Ref<Texture>& p_texture) {
|
||||
void TextureProgress::set_over_texture(const Ref<Texture> &p_texture) {
|
||||
|
||||
over=p_texture;
|
||||
over = p_texture;
|
||||
update();
|
||||
minimum_size_changed();
|
||||
}
|
||||
|
||||
Ref<Texture> TextureProgress::get_over_texture() const{
|
||||
Ref<Texture> TextureProgress::get_over_texture() const {
|
||||
|
||||
return over;
|
||||
|
||||
}
|
||||
|
||||
Size2 TextureProgress::get_minimum_size() const {
|
||||
|
|
@ -64,240 +61,224 @@ Size2 TextureProgress::get_minimum_size() const {
|
|||
else if (progress.is_valid())
|
||||
return progress->get_size();
|
||||
|
||||
return Size2(1,1);
|
||||
return Size2(1, 1);
|
||||
}
|
||||
|
||||
void TextureProgress::set_progress_texture(const Ref<Texture>& p_texture) {
|
||||
void TextureProgress::set_progress_texture(const Ref<Texture> &p_texture) {
|
||||
|
||||
progress=p_texture;
|
||||
progress = p_texture;
|
||||
update();
|
||||
minimum_size_changed();
|
||||
}
|
||||
|
||||
Ref<Texture> TextureProgress::get_progress_texture() const{
|
||||
Ref<Texture> TextureProgress::get_progress_texture() const {
|
||||
|
||||
return progress;
|
||||
|
||||
}
|
||||
|
||||
Point2 TextureProgress::unit_val_to_uv(float val) {
|
||||
if (progress.is_null())
|
||||
return Point2();
|
||||
|
||||
if (val<0)
|
||||
val+=1;
|
||||
if (val>1)
|
||||
val-=1;
|
||||
if (val < 0)
|
||||
val += 1;
|
||||
if (val > 1)
|
||||
val -= 1;
|
||||
|
||||
Point2 p=get_relative_center();
|
||||
Point2 p = get_relative_center();
|
||||
|
||||
if (val<0.125)
|
||||
return Point2(p.x+(1-p.x)*val*8,0);
|
||||
if (val<0.25)
|
||||
return Point2(1,p.y*(val-0.125)*8);
|
||||
if (val<0.375)
|
||||
return Point2(1,p.y+(1-p.y)*(val-0.25)*8);
|
||||
if (val<0.5)
|
||||
return Point2(1-(1-p.x)*(val-0.375)*8,1);
|
||||
if (val<0.625)
|
||||
return Point2(p.x*(1-(val-0.5)*8),1);
|
||||
if (val<0.75)
|
||||
return Point2(0,1-((1-p.y)*(val-0.625)*8));
|
||||
if (val<0.875)
|
||||
return Point2(0,p.y-p.y*(val-0.75)*8);
|
||||
if (val < 0.125)
|
||||
return Point2(p.x + (1 - p.x) * val * 8, 0);
|
||||
if (val < 0.25)
|
||||
return Point2(1, p.y * (val - 0.125) * 8);
|
||||
if (val < 0.375)
|
||||
return Point2(1, p.y + (1 - p.y) * (val - 0.25) * 8);
|
||||
if (val < 0.5)
|
||||
return Point2(1 - (1 - p.x) * (val - 0.375) * 8, 1);
|
||||
if (val < 0.625)
|
||||
return Point2(p.x * (1 - (val - 0.5) * 8), 1);
|
||||
if (val < 0.75)
|
||||
return Point2(0, 1 - ((1 - p.y) * (val - 0.625) * 8));
|
||||
if (val < 0.875)
|
||||
return Point2(0, p.y - p.y * (val - 0.75) * 8);
|
||||
else
|
||||
return Point2(p.x*(val-0.875)*8,0);
|
||||
return Point2(p.x * (val - 0.875) * 8, 0);
|
||||
}
|
||||
|
||||
Point2 TextureProgress::get_relative_center()
|
||||
{
|
||||
Point2 TextureProgress::get_relative_center() {
|
||||
if (progress.is_null())
|
||||
return Point2();
|
||||
Point2 p = progress->get_size()/2;
|
||||
p+=rad_center_off;
|
||||
p.x/=progress->get_width();
|
||||
p.y/=progress->get_height();
|
||||
p.x=CLAMP(p.x,0,1);
|
||||
p.y=CLAMP(p.y,0,1);
|
||||
Point2 p = progress->get_size() / 2;
|
||||
p += rad_center_off;
|
||||
p.x /= progress->get_width();
|
||||
p.y /= progress->get_height();
|
||||
p.x = CLAMP(p.x, 0, 1);
|
||||
p.y = CLAMP(p.y, 0, 1);
|
||||
return p;
|
||||
}
|
||||
|
||||
void TextureProgress::_notification(int p_what){
|
||||
const float corners[12]={-0.125,-0.375,-0.625,-0.875,0.125,0.375,0.625,0.875,1.125,1.375,1.625,1.875};
|
||||
switch(p_what) {
|
||||
void TextureProgress::_notification(int p_what) {
|
||||
const float corners[12] = { -0.125, -0.375, -0.625, -0.875, 0.125, 0.375, 0.625, 0.875, 1.125, 1.375, 1.625, 1.875 };
|
||||
switch (p_what) {
|
||||
|
||||
case NOTIFICATION_DRAW: {
|
||||
|
||||
|
||||
if (under.is_valid())
|
||||
draw_texture(under,Point2());
|
||||
draw_texture(under, Point2());
|
||||
if (progress.is_valid()) {
|
||||
Size2 s = progress->get_size();
|
||||
switch (mode) {
|
||||
case FILL_LEFT_TO_RIGHT: {
|
||||
Rect2 region=Rect2(Point2(),Size2(s.x*get_unit_value(),s.y));
|
||||
draw_texture_rect_region(progress,region,region);
|
||||
} break;
|
||||
case FILL_RIGHT_TO_LEFT: {
|
||||
Rect2 region=Rect2(Point2(s.x-s.x*get_unit_value(),0),Size2(s.x*get_unit_value(),s.y));
|
||||
draw_texture_rect_region(progress,region,region);
|
||||
} break;
|
||||
case FILL_TOP_TO_BOTTOM: {
|
||||
Rect2 region=Rect2(Point2(),Size2(s.x,s.y*get_unit_value()));
|
||||
draw_texture_rect_region(progress,region,region);
|
||||
} break;
|
||||
case FILL_BOTTOM_TO_TOP: {
|
||||
Rect2 region=Rect2(Point2(0,s.y-s.y*get_unit_value()),Size2(s.x,s.y*get_unit_value()));
|
||||
draw_texture_rect_region(progress,region,region);
|
||||
} break;
|
||||
case FILL_CLOCKWISE:
|
||||
case FILL_COUNTER_CLOCKWISE: {
|
||||
float val=get_unit_value()*rad_max_degrees/360;
|
||||
if (val==1) {
|
||||
Rect2 region=Rect2(Point2(),s);
|
||||
draw_texture_rect_region(progress,region,region);
|
||||
} else if (val!=0) {
|
||||
Array pts;
|
||||
float direction=mode==FILL_CLOCKWISE?1:-1;
|
||||
float start=rad_init_angle/360;
|
||||
float end=start+direction*val;
|
||||
pts.append(start);
|
||||
pts.append(end);
|
||||
float from=MIN(start,end);
|
||||
float to=MAX(start,end);
|
||||
for (int i=0;i<12;i++)
|
||||
if (corners[i]>from&&corners[i]<to)
|
||||
pts.append(corners[i]);
|
||||
pts.sort();
|
||||
Vector<Point2> uvs;
|
||||
Vector<Point2> points;
|
||||
uvs.push_back(get_relative_center());
|
||||
points.push_back(Point2(s.x*get_relative_center().x,s.y*get_relative_center().y));
|
||||
for (int i=0;i<pts.size();i++) {
|
||||
Point2 uv=unit_val_to_uv(pts[i]);
|
||||
if (uvs.find(uv)>=0)
|
||||
continue;
|
||||
uvs.push_back(uv);
|
||||
points.push_back(Point2(uv.x*s.x,uv.y*s.y));
|
||||
case FILL_LEFT_TO_RIGHT: {
|
||||
Rect2 region = Rect2(Point2(), Size2(s.x * get_unit_value(), s.y));
|
||||
draw_texture_rect_region(progress, region, region);
|
||||
} break;
|
||||
case FILL_RIGHT_TO_LEFT: {
|
||||
Rect2 region = Rect2(Point2(s.x - s.x * get_unit_value(), 0), Size2(s.x * get_unit_value(), s.y));
|
||||
draw_texture_rect_region(progress, region, region);
|
||||
} break;
|
||||
case FILL_TOP_TO_BOTTOM: {
|
||||
Rect2 region = Rect2(Point2(), Size2(s.x, s.y * get_unit_value()));
|
||||
draw_texture_rect_region(progress, region, region);
|
||||
} break;
|
||||
case FILL_BOTTOM_TO_TOP: {
|
||||
Rect2 region = Rect2(Point2(0, s.y - s.y * get_unit_value()), Size2(s.x, s.y * get_unit_value()));
|
||||
draw_texture_rect_region(progress, region, region);
|
||||
} break;
|
||||
case FILL_CLOCKWISE:
|
||||
case FILL_COUNTER_CLOCKWISE: {
|
||||
float val = get_unit_value() * rad_max_degrees / 360;
|
||||
if (val == 1) {
|
||||
Rect2 region = Rect2(Point2(), s);
|
||||
draw_texture_rect_region(progress, region, region);
|
||||
} else if (val != 0) {
|
||||
Array pts;
|
||||
float direction = mode == FILL_CLOCKWISE ? 1 : -1;
|
||||
float start = rad_init_angle / 360;
|
||||
float end = start + direction * val;
|
||||
pts.append(start);
|
||||
pts.append(end);
|
||||
float from = MIN(start, end);
|
||||
float to = MAX(start, end);
|
||||
for (int i = 0; i < 12; i++)
|
||||
if (corners[i] > from && corners[i] < to)
|
||||
pts.append(corners[i]);
|
||||
pts.sort();
|
||||
Vector<Point2> uvs;
|
||||
Vector<Point2> points;
|
||||
uvs.push_back(get_relative_center());
|
||||
points.push_back(Point2(s.x * get_relative_center().x, s.y * get_relative_center().y));
|
||||
for (int i = 0; i < pts.size(); i++) {
|
||||
Point2 uv = unit_val_to_uv(pts[i]);
|
||||
if (uvs.find(uv) >= 0)
|
||||
continue;
|
||||
uvs.push_back(uv);
|
||||
points.push_back(Point2(uv.x * s.x, uv.y * s.y));
|
||||
}
|
||||
draw_polygon(points, Vector<Color>(), uvs, progress);
|
||||
}
|
||||
draw_polygon(points,Vector<Color>(),uvs,progress);
|
||||
}
|
||||
if (get_tree()->is_editor_hint()) {
|
||||
Point2 p=progress->get_size();
|
||||
p.x*=get_relative_center().x;
|
||||
p.y*=get_relative_center().y;
|
||||
p=p.floor();
|
||||
draw_line(p-Point2(8,0),p+Point2(8,0),Color(0.9,0.5,0.5),2);
|
||||
draw_line(p-Point2(0,8),p+Point2(0,8),Color(0.9,0.5,0.5),2);
|
||||
}
|
||||
} break;
|
||||
default:
|
||||
draw_texture_rect_region(progress,Rect2(Point2(),Size2(s.x*get_unit_value(),s.y)),Rect2(Point2(),Size2(s.x*get_unit_value(),s.y)));
|
||||
if (get_tree()->is_editor_hint()) {
|
||||
Point2 p = progress->get_size();
|
||||
p.x *= get_relative_center().x;
|
||||
p.y *= get_relative_center().y;
|
||||
p = p.floor();
|
||||
draw_line(p - Point2(8, 0), p + Point2(8, 0), Color(0.9, 0.5, 0.5), 2);
|
||||
draw_line(p - Point2(0, 8), p + Point2(0, 8), Color(0.9, 0.5, 0.5), 2);
|
||||
}
|
||||
} break;
|
||||
default:
|
||||
draw_texture_rect_region(progress, Rect2(Point2(), Size2(s.x * get_unit_value(), s.y)), Rect2(Point2(), Size2(s.x * get_unit_value(), s.y)));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
if (over.is_valid())
|
||||
draw_texture(over,Point2());
|
||||
draw_texture(over, Point2());
|
||||
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void TextureProgress::set_fill_mode(int p_fill)
|
||||
{
|
||||
ERR_FAIL_INDEX(p_fill,6);
|
||||
mode=(FillMode)p_fill;
|
||||
void TextureProgress::set_fill_mode(int p_fill) {
|
||||
ERR_FAIL_INDEX(p_fill, 6);
|
||||
mode = (FillMode)p_fill;
|
||||
update();
|
||||
}
|
||||
|
||||
int TextureProgress::get_fill_mode()
|
||||
{
|
||||
int TextureProgress::get_fill_mode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
void TextureProgress::set_radial_initial_angle(float p_angle)
|
||||
{
|
||||
while(p_angle>360)
|
||||
p_angle-=360;
|
||||
while (p_angle<0)
|
||||
p_angle+=360;
|
||||
rad_init_angle=p_angle;
|
||||
void TextureProgress::set_radial_initial_angle(float p_angle) {
|
||||
while (p_angle > 360)
|
||||
p_angle -= 360;
|
||||
while (p_angle < 0)
|
||||
p_angle += 360;
|
||||
rad_init_angle = p_angle;
|
||||
update();
|
||||
}
|
||||
|
||||
float TextureProgress::get_radial_initial_angle()
|
||||
{
|
||||
float TextureProgress::get_radial_initial_angle() {
|
||||
return rad_init_angle;
|
||||
}
|
||||
|
||||
void TextureProgress::set_fill_degrees(float p_angle)
|
||||
{
|
||||
rad_max_degrees=CLAMP(p_angle,0,360);
|
||||
void TextureProgress::set_fill_degrees(float p_angle) {
|
||||
rad_max_degrees = CLAMP(p_angle, 0, 360);
|
||||
update();
|
||||
}
|
||||
|
||||
float TextureProgress::get_fill_degrees()
|
||||
{
|
||||
float TextureProgress::get_fill_degrees() {
|
||||
return rad_max_degrees;
|
||||
}
|
||||
|
||||
void TextureProgress::set_radial_center_offset(const Point2 &p_off)
|
||||
{
|
||||
rad_center_off=p_off;
|
||||
void TextureProgress::set_radial_center_offset(const Point2 &p_off) {
|
||||
rad_center_off = p_off;
|
||||
update();
|
||||
}
|
||||
|
||||
Point2 TextureProgress::get_radial_center_offset()
|
||||
{
|
||||
Point2 TextureProgress::get_radial_center_offset() {
|
||||
return rad_center_off;
|
||||
}
|
||||
|
||||
void TextureProgress::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_under_texture","tex"),&TextureProgress::set_under_texture);
|
||||
ObjectTypeDB::bind_method(_MD("get_under_texture"),&TextureProgress::get_under_texture);
|
||||
ObjectTypeDB::bind_method(_MD("set_under_texture", "tex"), &TextureProgress::set_under_texture);
|
||||
ObjectTypeDB::bind_method(_MD("get_under_texture"), &TextureProgress::get_under_texture);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_progress_texture","tex"),&TextureProgress::set_progress_texture);
|
||||
ObjectTypeDB::bind_method(_MD("get_progress_texture"),&TextureProgress::get_progress_texture);
|
||||
ObjectTypeDB::bind_method(_MD("set_progress_texture", "tex"), &TextureProgress::set_progress_texture);
|
||||
ObjectTypeDB::bind_method(_MD("get_progress_texture"), &TextureProgress::get_progress_texture);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_over_texture","tex"),&TextureProgress::set_over_texture);
|
||||
ObjectTypeDB::bind_method(_MD("get_over_texture"),&TextureProgress::get_over_texture);
|
||||
ObjectTypeDB::bind_method(_MD("set_over_texture", "tex"), &TextureProgress::set_over_texture);
|
||||
ObjectTypeDB::bind_method(_MD("get_over_texture"), &TextureProgress::get_over_texture);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_fill_mode","mode"),&TextureProgress::set_fill_mode);
|
||||
ObjectTypeDB::bind_method(_MD("set_fill_mode", "mode"), &TextureProgress::set_fill_mode);
|
||||
ObjectTypeDB::bind_method(_MD("get_fill_mode"), &TextureProgress::get_fill_mode);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_radial_initial_angle","mode"),&TextureProgress::set_radial_initial_angle);
|
||||
ObjectTypeDB::bind_method(_MD("set_radial_initial_angle", "mode"), &TextureProgress::set_radial_initial_angle);
|
||||
ObjectTypeDB::bind_method(_MD("get_radial_initial_angle"), &TextureProgress::get_radial_initial_angle);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_radial_center_offset","mode"),&TextureProgress::set_radial_center_offset);
|
||||
ObjectTypeDB::bind_method(_MD("set_radial_center_offset", "mode"), &TextureProgress::set_radial_center_offset);
|
||||
ObjectTypeDB::bind_method(_MD("get_radial_center_offset"), &TextureProgress::get_radial_center_offset);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_fill_degrees","mode"),&TextureProgress::set_fill_degrees);
|
||||
ObjectTypeDB::bind_method(_MD("set_fill_degrees", "mode"), &TextureProgress::set_fill_degrees);
|
||||
ObjectTypeDB::bind_method(_MD("get_fill_degrees"), &TextureProgress::get_fill_degrees);
|
||||
|
||||
ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"texture/under",PROPERTY_HINT_RESOURCE_TYPE,"Texture"),_SCS("set_under_texture"),_SCS("get_under_texture"));
|
||||
ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"texture/over",PROPERTY_HINT_RESOURCE_TYPE,"Texture"),_SCS("set_over_texture"),_SCS("get_over_texture"));
|
||||
ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"texture/progress",PROPERTY_HINT_RESOURCE_TYPE,"Texture"),_SCS("set_progress_texture"),_SCS("get_progress_texture"));
|
||||
ADD_PROPERTYNZ( PropertyInfo(Variant::INT,"mode",PROPERTY_HINT_ENUM,"Left to Right,Right to Left,Top to Bottom,Bottom to Top,Clockwise,Counter Clockwise"),_SCS("set_fill_mode"),_SCS("get_fill_mode"));
|
||||
ADD_PROPERTYNZ( PropertyInfo(Variant::REAL,"radial_fill/initial_angle",PROPERTY_HINT_RANGE,"0.0,360.0,0.1,slider"),_SCS("set_radial_initial_angle"),_SCS("get_radial_initial_angle"));
|
||||
ADD_PROPERTYNZ( PropertyInfo(Variant::REAL,"radial_fill/fill_degrees",PROPERTY_HINT_RANGE,"0.0,360.0,0.1,slider"),_SCS("set_fill_degrees"),_SCS("get_fill_degrees"));
|
||||
ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"radial_fill/center_offset"),_SCS("set_radial_center_offset"),_SCS("get_radial_center_offset"));
|
||||
|
||||
BIND_CONSTANT( FILL_LEFT_TO_RIGHT );
|
||||
BIND_CONSTANT( FILL_RIGHT_TO_LEFT );
|
||||
BIND_CONSTANT( FILL_TOP_TO_BOTTOM );
|
||||
BIND_CONSTANT( FILL_BOTTOM_TO_TOP );
|
||||
BIND_CONSTANT( FILL_CLOCKWISE );
|
||||
BIND_CONSTANT( FILL_COUNTER_CLOCKWISE );
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture/under", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), _SCS("set_under_texture"), _SCS("get_under_texture"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture/over", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), _SCS("set_over_texture"), _SCS("get_over_texture"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture/progress", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), _SCS("set_progress_texture"), _SCS("get_progress_texture"));
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Left to Right,Right to Left,Top to Bottom,Bottom to Top,Clockwise,Counter Clockwise"), _SCS("set_fill_mode"), _SCS("get_fill_mode"));
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "radial_fill/initial_angle", PROPERTY_HINT_RANGE, "0.0,360.0,0.1,slider"), _SCS("set_radial_initial_angle"), _SCS("get_radial_initial_angle"));
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "radial_fill/fill_degrees", PROPERTY_HINT_RANGE, "0.0,360.0,0.1,slider"), _SCS("set_fill_degrees"), _SCS("get_fill_degrees"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "radial_fill/center_offset"), _SCS("set_radial_center_offset"), _SCS("get_radial_center_offset"));
|
||||
|
||||
BIND_CONSTANT(FILL_LEFT_TO_RIGHT);
|
||||
BIND_CONSTANT(FILL_RIGHT_TO_LEFT);
|
||||
BIND_CONSTANT(FILL_TOP_TO_BOTTOM);
|
||||
BIND_CONSTANT(FILL_BOTTOM_TO_TOP);
|
||||
BIND_CONSTANT(FILL_CLOCKWISE);
|
||||
BIND_CONSTANT(FILL_COUNTER_CLOCKWISE);
|
||||
}
|
||||
|
||||
|
||||
TextureProgress::TextureProgress()
|
||||
{
|
||||
mode=FILL_LEFT_TO_RIGHT;
|
||||
rad_init_angle=0;
|
||||
rad_center_off=Point2();
|
||||
rad_max_degrees=360;
|
||||
TextureProgress::TextureProgress() {
|
||||
mode = FILL_LEFT_TO_RIGHT;
|
||||
rad_init_angle = 0;
|
||||
rad_center_off = Point2();
|
||||
rad_max_degrees = 360;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,20 +33,19 @@
|
|||
|
||||
class TextureProgress : public Range {
|
||||
|
||||
OBJ_TYPE( TextureProgress, Range );
|
||||
OBJ_TYPE(TextureProgress, Range);
|
||||
|
||||
Ref<Texture> under;
|
||||
Ref<Texture> progress;
|
||||
Ref<Texture> over;
|
||||
|
||||
protected:
|
||||
|
||||
static void _bind_methods();
|
||||
void _notification(int p_what);
|
||||
public:
|
||||
|
||||
public:
|
||||
enum FillMode {
|
||||
FILL_LEFT_TO_RIGHT=0,
|
||||
FILL_LEFT_TO_RIGHT = 0,
|
||||
FILL_RIGHT_TO_LEFT,
|
||||
FILL_TOP_TO_BOTTOM,
|
||||
FILL_BOTTOM_TO_TOP,
|
||||
|
|
@ -66,13 +65,13 @@ public:
|
|||
void set_radial_center_offset(const Point2 &p_off);
|
||||
Point2 get_radial_center_offset();
|
||||
|
||||
void set_under_texture(const Ref<Texture>& p_texture);
|
||||
void set_under_texture(const Ref<Texture> &p_texture);
|
||||
Ref<Texture> get_under_texture() const;
|
||||
|
||||
void set_progress_texture(const Ref<Texture>& p_texture);
|
||||
void set_progress_texture(const Ref<Texture> &p_texture);
|
||||
Ref<Texture> get_progress_texture() const;
|
||||
|
||||
void set_over_texture(const Ref<Texture>& p_texture);
|
||||
void set_over_texture(const Ref<Texture> &p_texture);
|
||||
Ref<Texture> get_over_texture() const;
|
||||
|
||||
Size2 get_minimum_size() const;
|
||||
|
|
@ -80,7 +79,6 @@ public:
|
|||
TextureProgress();
|
||||
|
||||
private:
|
||||
|
||||
FillMode mode;
|
||||
float rad_init_angle;
|
||||
float rad_max_degrees;
|
||||
|
|
|
|||
|
|
@ -32,7 +32,8 @@
|
|||
#include "scene/gui/button.h"
|
||||
|
||||
class ToolButton : public Button {
|
||||
OBJ_TYPE(ToolButton,Button);
|
||||
OBJ_TYPE(ToolButton, Button);
|
||||
|
||||
public:
|
||||
ToolButton();
|
||||
};
|
||||
|
|
|
|||
2678
scene/gui/tree.cpp
2678
scene/gui/tree.cpp
File diff suppressed because it is too large
Load diff
222
scene/gui/tree.h
222
scene/gui/tree.h
|
|
@ -29,25 +29,24 @@
|
|||
#ifndef TREE_H
|
||||
#define TREE_H
|
||||
|
||||
#include "core/helper/value_evaluator.h"
|
||||
#include "scene/gui/control.h"
|
||||
#include "scene/gui/popup_menu.h"
|
||||
#include "scene/gui/line_edit.h"
|
||||
#include "scene/gui/popup_menu.h"
|
||||
#include "scene/gui/scroll_bar.h"
|
||||
#include "scene/gui/slider.h"
|
||||
#include "core/helper/value_evaluator.h"
|
||||
|
||||
/**
|
||||
@author Juan Linietsky <reduzio@gmail.com>
|
||||
*/
|
||||
|
||||
|
||||
class Tree;
|
||||
|
||||
class TreeItem : public Object {
|
||||
|
||||
OBJ_TYPE(TreeItem,Object);
|
||||
public:
|
||||
OBJ_TYPE(TreeItem, Object);
|
||||
|
||||
public:
|
||||
enum TreeCellMode {
|
||||
|
||||
CELL_MODE_STRING, ///< just a string
|
||||
|
|
@ -59,8 +58,7 @@ public:
|
|||
};
|
||||
|
||||
private:
|
||||
friend class Tree;
|
||||
|
||||
friend class Tree;
|
||||
|
||||
struct Cell {
|
||||
|
||||
|
|
@ -69,7 +67,7 @@ friend class Tree;
|
|||
Ref<Texture> icon;
|
||||
Rect2i icon_region;
|
||||
String text;
|
||||
double min,max,step,val;
|
||||
double min, max, step, val;
|
||||
int icon_max_w;
|
||||
bool expr;
|
||||
bool checked;
|
||||
|
|
@ -93,33 +91,35 @@ friend class Tree;
|
|||
bool disabled;
|
||||
Ref<Texture> texture;
|
||||
Color color;
|
||||
Button() { id=0; disabled=false; color=Color(1,1,1,1); }
|
||||
Button() {
|
||||
id = 0;
|
||||
disabled = false;
|
||||
color = Color(1, 1, 1, 1);
|
||||
}
|
||||
};
|
||||
|
||||
Vector< Button > buttons;
|
||||
Vector<Button> buttons;
|
||||
|
||||
Cell() {
|
||||
|
||||
custom_draw_obj=0;
|
||||
mode=TreeItem::CELL_MODE_STRING;
|
||||
min=0;
|
||||
max=100;
|
||||
step=1;
|
||||
val=0;
|
||||
checked=false;
|
||||
editable=false;
|
||||
selected=false;
|
||||
selectable=true;
|
||||
custom_color=false;
|
||||
custom_bg_color=false;
|
||||
expr=false;
|
||||
icon_max_w=0;
|
||||
custom_draw_obj = 0;
|
||||
mode = TreeItem::CELL_MODE_STRING;
|
||||
min = 0;
|
||||
max = 100;
|
||||
step = 1;
|
||||
val = 0;
|
||||
checked = false;
|
||||
editable = false;
|
||||
selected = false;
|
||||
selectable = true;
|
||||
custom_color = false;
|
||||
custom_bg_color = false;
|
||||
expr = false;
|
||||
icon_max_w = 0;
|
||||
}
|
||||
|
||||
|
||||
Size2 get_icon_size() const;
|
||||
void draw_icon(const RID& p_where, const Point2& p_pos, const Size2& p_size=Size2()) const;
|
||||
|
||||
void draw_icon(const RID &p_where, const Point2 &p_pos, const Size2 &p_size = Size2()) const;
|
||||
};
|
||||
|
||||
Vector<Cell> cells;
|
||||
|
|
@ -131,76 +131,73 @@ friend class Tree;
|
|||
TreeItem *childs; //child items
|
||||
Tree *tree; //tree (for reference)
|
||||
|
||||
|
||||
|
||||
TreeItem(Tree *p_tree);
|
||||
|
||||
|
||||
void _changed_notify(int p_cell);
|
||||
void _changed_notify();
|
||||
void _cell_selected(int p_cell);
|
||||
void _cell_deselected(int p_cell);
|
||||
protected:
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
//bind helpers
|
||||
Dictionary _get_range_config( int p_column ) {
|
||||
Dictionary _get_range_config(int p_column) {
|
||||
Dictionary d;
|
||||
double min,max,step;
|
||||
get_range_config(p_column,min,max,step);
|
||||
d["min"]=min;
|
||||
d["max"]=max;
|
||||
d["step"]=step;
|
||||
d["expr"]=false;
|
||||
double min, max, step;
|
||||
get_range_config(p_column, min, max, step);
|
||||
d["min"] = min;
|
||||
d["max"] = max;
|
||||
d["step"] = step;
|
||||
d["expr"] = false;
|
||||
|
||||
return d;
|
||||
}
|
||||
void _remove_child(Object *p_child) { remove_child( p_child->cast_to<TreeItem>() ); }
|
||||
public:
|
||||
void _remove_child(Object *p_child) { remove_child(p_child->cast_to<TreeItem>()); }
|
||||
|
||||
public:
|
||||
/* cell mode */
|
||||
void set_cell_mode( int p_column, TreeCellMode p_mode );
|
||||
TreeCellMode get_cell_mode( int p_column ) const;
|
||||
void set_cell_mode(int p_column, TreeCellMode p_mode);
|
||||
TreeCellMode get_cell_mode(int p_column) const;
|
||||
|
||||
/* check mode */
|
||||
void set_checked(int p_column,bool p_checked);
|
||||
void set_checked(int p_column, bool p_checked);
|
||||
bool is_checked(int p_column) const;
|
||||
|
||||
void set_text(int p_column,String p_text);
|
||||
void set_text(int p_column, String p_text);
|
||||
String get_text(int p_column) const;
|
||||
|
||||
void set_icon(int p_column,const Ref<Texture>& p_icon);
|
||||
void set_icon(int p_column, const Ref<Texture> &p_icon);
|
||||
Ref<Texture> get_icon(int p_column) const;
|
||||
|
||||
void set_icon_region(int p_column,const Rect2& p_icon_region);
|
||||
void set_icon_region(int p_column, const Rect2 &p_icon_region);
|
||||
Rect2 get_icon_region(int p_column) const;
|
||||
|
||||
void set_icon_max_width(int p_column,int p_max);
|
||||
void set_icon_max_width(int p_column, int p_max);
|
||||
int get_icon_max_width(int p_column) const;
|
||||
|
||||
void add_button(int p_column,const Ref<Texture>& p_button,int p_id=-1,bool p_disabled=false);
|
||||
void add_button(int p_column, const Ref<Texture> &p_button, int p_id = -1, bool p_disabled = false);
|
||||
int get_button_count(int p_column) const;
|
||||
Ref<Texture> get_button(int p_column,int p_idx) const;
|
||||
int get_button_id(int p_column,int p_idx) const;
|
||||
void erase_button(int p_column,int p_idx);
|
||||
int get_button_by_id(int p_column,int p_id) const;
|
||||
bool is_button_disabled(int p_column,int p_idx) const;
|
||||
void set_button(int p_column,int p_idx,const Ref<Texture>& p_button);
|
||||
void set_button_color(int p_column,int p_idx,const Color& p_color);
|
||||
Ref<Texture> get_button(int p_column, int p_idx) const;
|
||||
int get_button_id(int p_column, int p_idx) const;
|
||||
void erase_button(int p_column, int p_idx);
|
||||
int get_button_by_id(int p_column, int p_id) const;
|
||||
bool is_button_disabled(int p_column, int p_idx) const;
|
||||
void set_button(int p_column, int p_idx, const Ref<Texture> &p_button);
|
||||
void set_button_color(int p_column, int p_idx, const Color &p_color);
|
||||
|
||||
/* range works for mode number or mode combo */
|
||||
|
||||
void set_range(int p_column,double p_value);
|
||||
void set_range(int p_column, double p_value);
|
||||
double get_range(int p_column) const;
|
||||
|
||||
void set_range_config(int p_column,double p_min,double p_max,double p_step,bool p_exp=false);
|
||||
void get_range_config(int p_column,double& r_min,double& r_max,double &r_step) const;
|
||||
void set_range_config(int p_column, double p_min, double p_max, double p_step, bool p_exp = false);
|
||||
void get_range_config(int p_column, double &r_min, double &r_max, double &r_step) const;
|
||||
bool is_range_exponential(int p_column) const;
|
||||
|
||||
void set_metadata(int p_column,const Variant& p_meta);
|
||||
void set_metadata(int p_column, const Variant &p_meta);
|
||||
Variant get_metadata(int p_column) const;
|
||||
|
||||
void set_custom_draw(int p_column,Object *p_object,const StringName& p_callback);
|
||||
void set_custom_draw(int p_column, Object *p_object, const StringName &p_callback);
|
||||
|
||||
void set_collapsed(bool p_collapsed);
|
||||
bool is_collapsed();
|
||||
|
|
@ -215,7 +212,7 @@ public:
|
|||
|
||||
void remove_child(TreeItem *p_item);
|
||||
|
||||
void set_selectable(int p_column,bool p_selectable);
|
||||
void set_selectable(int p_column, bool p_selectable);
|
||||
bool is_selectable(int p_column) const;
|
||||
|
||||
bool is_selected(int p_column);
|
||||
|
|
@ -223,52 +220,49 @@ public:
|
|||
void deselect(int p_column);
|
||||
void set_as_cursor(int p_column);
|
||||
|
||||
void set_editable(int p_column,bool p_editable);
|
||||
void set_editable(int p_column, bool p_editable);
|
||||
bool is_editable(int p_column);
|
||||
|
||||
void set_custom_color(int p_column,const Color& p_color);
|
||||
void set_custom_color(int p_column, const Color &p_color);
|
||||
Color get_custom_color(int p_column) const;
|
||||
void clear_custom_color(int p_column);
|
||||
|
||||
void set_custom_bg_color(int p_column, const Color& p_color, bool p_bg_outline=false);
|
||||
void set_custom_bg_color(int p_column, const Color &p_color, bool p_bg_outline = false);
|
||||
void clear_custom_bg_color(int p_column);
|
||||
Color get_custom_bg_color(int p_column) const;
|
||||
|
||||
void set_tooltip(int p_column, const String& p_tooltip);
|
||||
void set_tooltip(int p_column, const String &p_tooltip);
|
||||
String get_tooltip(int p_column) const;
|
||||
|
||||
|
||||
void clear_children();
|
||||
|
||||
void move_to_top();
|
||||
void move_to_bottom();
|
||||
|
||||
~TreeItem();
|
||||
|
||||
};
|
||||
|
||||
|
||||
VARIANT_ENUM_CAST( TreeItem::TreeCellMode );
|
||||
|
||||
VARIANT_ENUM_CAST(TreeItem::TreeCellMode);
|
||||
|
||||
class Tree : public Control {
|
||||
|
||||
OBJ_TYPE( Tree, Control );
|
||||
OBJ_TYPE(Tree, Control);
|
||||
|
||||
public:
|
||||
enum SelectMode {
|
||||
SELECT_SINGLE,
|
||||
SELECT_ROW,
|
||||
SELECT_MULTI
|
||||
SELECT_SINGLE,
|
||||
SELECT_ROW,
|
||||
SELECT_MULTI
|
||||
};
|
||||
|
||||
enum DropModeFlags {
|
||||
DROP_MODE_DISABLED=0,
|
||||
DROP_MODE_ON_ITEM=1,
|
||||
DROP_MODE_INBETWEEN=2
|
||||
DROP_MODE_DISABLED = 0,
|
||||
DROP_MODE_ON_ITEM = 1,
|
||||
DROP_MODE_INBETWEEN = 2
|
||||
};
|
||||
|
||||
private:
|
||||
friend class TreeItem;
|
||||
friend class TreeItem;
|
||||
|
||||
TreeItem *root;
|
||||
TreeItem *popup_edited_item;
|
||||
|
|
@ -291,7 +285,6 @@ friend class TreeItem;
|
|||
bool range_drag_enabled;
|
||||
Vector2 range_drag_capture_pos;
|
||||
|
||||
|
||||
//TreeItem *cursor_item;
|
||||
//int cursor_column;
|
||||
|
||||
|
|
@ -311,7 +304,10 @@ friend class TreeItem;
|
|||
int min_width;
|
||||
bool expand;
|
||||
String title;
|
||||
ColumnInfo() { min_width=1; expand=true; }
|
||||
ColumnInfo() {
|
||||
min_width = 1;
|
||||
expand = true;
|
||||
}
|
||||
};
|
||||
|
||||
bool show_column_titles;
|
||||
|
|
@ -330,11 +326,11 @@ friend class TreeItem;
|
|||
|
||||
int compute_item_height(TreeItem *p_item) const;
|
||||
int get_item_height(TreeItem *p_item) const;
|
||||
// void draw_item_text(String p_text,const Ref<Texture>& p_icon,int p_icon_max_w,bool p_tool,Rect2i p_rect,const Color& p_color);
|
||||
void draw_item_rect(const TreeItem::Cell& p_cell,const Rect2i& p_rect,const Color& p_color);
|
||||
int draw_item(const Point2i& p_pos,const Point2& p_draw_ofs, const Size2& p_draw_size,TreeItem *p_item);
|
||||
void select_single_item(TreeItem *p_selected,TreeItem *p_current,int p_col,TreeItem *p_prev=NULL,bool *r_in_range=NULL,bool p_force_deselect=false);
|
||||
int propagate_mouse_event(const Point2i &p_pos,int x_ofs,int y_ofs,bool p_doubleclick,TreeItem *p_item,int p_button,const InputModifierState& p_mod);
|
||||
// void draw_item_text(String p_text,const Ref<Texture>& p_icon,int p_icon_max_w,bool p_tool,Rect2i p_rect,const Color& p_color);
|
||||
void draw_item_rect(const TreeItem::Cell &p_cell, const Rect2i &p_rect, const Color &p_color);
|
||||
int draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 &p_draw_size, TreeItem *p_item);
|
||||
void select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_col, TreeItem *p_prev = NULL, bool *r_in_range = NULL, bool p_force_deselect = false);
|
||||
int propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool p_doubleclick, TreeItem *p_item, int p_button, const InputModifierState &p_mod);
|
||||
void text_editor_enter(String p_text);
|
||||
void _text_editor_modal_close();
|
||||
void value_editor_changed(double p_value);
|
||||
|
|
@ -346,10 +342,10 @@ friend class TreeItem;
|
|||
|
||||
Size2 get_minimum_size() const;
|
||||
|
||||
void item_edited(int p_column,TreeItem *p_item);
|
||||
void item_changed(int p_column,TreeItem *p_item);
|
||||
void item_selected(int p_column,TreeItem *p_item);
|
||||
void item_deselected(int p_column,TreeItem *p_item);
|
||||
void item_edited(int p_column, TreeItem *p_item);
|
||||
void item_changed(int p_column, TreeItem *p_item);
|
||||
void item_selected(int p_column, TreeItem *p_item);
|
||||
void item_deselected(int p_column, TreeItem *p_item);
|
||||
|
||||
void propagate_set_columns(TreeItem *p_item);
|
||||
|
||||
|
|
@ -409,7 +405,6 @@ friend class TreeItem;
|
|||
|
||||
} cache;
|
||||
|
||||
|
||||
int _get_title_button_height() const;
|
||||
|
||||
void _scroll_moved(float p_value);
|
||||
|
|
@ -425,13 +420,13 @@ friend class TreeItem;
|
|||
uint64_t last_keypress;
|
||||
String incr_search;
|
||||
bool cursor_can_exit_tree;
|
||||
void _do_incr_search(const String& p_add);
|
||||
void _do_incr_search(const String &p_add);
|
||||
|
||||
TreeItem* _search_item_text(TreeItem *p_at, const String& p_find,int *r_col,bool p_selectable,bool p_backwards=false);
|
||||
TreeItem *_search_item_text(TreeItem *p_at, const String &p_find, int *r_col, bool p_selectable, bool p_backwards = false);
|
||||
|
||||
TreeItem* _find_item_at_pos(TreeItem *p_current, const Point2& p_pos, int& r_column, int &h, int §ion) const;
|
||||
TreeItem *_find_item_at_pos(TreeItem *p_current, const Point2 &p_pos, int &r_column, int &h, int §ion) const;
|
||||
|
||||
/* float drag_speed;
|
||||
/* float drag_speed;
|
||||
float drag_accum;
|
||||
|
||||
float last_drag_accum;
|
||||
|
|
@ -454,37 +449,35 @@ friend class TreeItem;
|
|||
|
||||
ValueEvaluator *evaluator;
|
||||
|
||||
int _count_selected_items(TreeItem* p_from) const;
|
||||
int _count_selected_items(TreeItem *p_from) const;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
//bind helpers
|
||||
Object* _create_item(Object *p_parent) { return create_item(p_parent->cast_to<TreeItem>() ); }
|
||||
TreeItem *_get_next_selected(Object *p_item) { return get_next_selected(p_item->cast_to<TreeItem>() ); }
|
||||
Rect2 _get_item_rect(Object *p_item,int p_column) const { return get_item_rect(p_item->cast_to<TreeItem>(),p_column ); }
|
||||
|
||||
Object *_create_item(Object *p_parent) { return create_item(p_parent->cast_to<TreeItem>()); }
|
||||
TreeItem *_get_next_selected(Object *p_item) { return get_next_selected(p_item->cast_to<TreeItem>()); }
|
||||
Rect2 _get_item_rect(Object *p_item, int p_column) const { return get_item_rect(p_item->cast_to<TreeItem>(), p_column); }
|
||||
|
||||
public:
|
||||
virtual String get_tooltip(const Point2 &p_pos) const;
|
||||
|
||||
virtual String get_tooltip(const Point2& p_pos) const;
|
||||
|
||||
TreeItem* get_item_at_pos(const Point2& p_pos) const;
|
||||
int get_column_at_pos(const Point2& p_pos) const;
|
||||
int get_drop_section_at_pos(const Point2& p_pos) const;
|
||||
TreeItem *get_item_at_pos(const Point2 &p_pos) const;
|
||||
int get_column_at_pos(const Point2 &p_pos) const;
|
||||
int get_drop_section_at_pos(const Point2 &p_pos) const;
|
||||
|
||||
void clear();
|
||||
|
||||
TreeItem* create_item(TreeItem *p_parent=0);
|
||||
TreeItem* get_root();
|
||||
TreeItem* get_last_item();
|
||||
TreeItem *create_item(TreeItem *p_parent = 0);
|
||||
TreeItem *get_root();
|
||||
TreeItem *get_last_item();
|
||||
|
||||
void set_column_min_width(int p_column,int p_min_width);
|
||||
void set_column_expand(int p_column,bool p_expand);
|
||||
void set_column_min_width(int p_column, int p_min_width);
|
||||
void set_column_expand(int p_column, bool p_expand);
|
||||
int get_column_width(int p_column) const;
|
||||
|
||||
void set_hide_root(bool p_eanbled);
|
||||
TreeItem *get_next_selected( TreeItem* p_item);
|
||||
TreeItem *get_next_selected(TreeItem *p_item);
|
||||
TreeItem *get_selected() const;
|
||||
int get_selected_column() const;
|
||||
int get_pressed_button() const;
|
||||
|
|
@ -493,7 +486,7 @@ public:
|
|||
void set_columns(int p_columns);
|
||||
int get_columns() const;
|
||||
|
||||
void set_column_title(int p_column,const String& p_title);
|
||||
void set_column_title(int p_column, const String &p_title);
|
||||
String get_column_title(int p_column) const;
|
||||
|
||||
void set_column_titles_visible(bool p_show);
|
||||
|
|
@ -507,10 +500,10 @@ public:
|
|||
Rect2 get_custom_popup_rect() const;
|
||||
|
||||
int get_item_offset(TreeItem *p_item) const;
|
||||
Rect2 get_item_rect(TreeItem *p_item,int p_column=-1) const;
|
||||
Rect2 get_item_rect(TreeItem *p_item, int p_column = -1) const;
|
||||
bool edit_selected();
|
||||
|
||||
TreeItem* search_item_text(const String& p_find,int *r_col=NULL,bool p_selectable=false);
|
||||
TreeItem *search_item_text(const String &p_find, int *r_col = NULL, bool p_selectable = false);
|
||||
|
||||
Point2 get_scroll() const;
|
||||
|
||||
|
|
@ -535,8 +528,7 @@ public:
|
|||
|
||||
Tree();
|
||||
~Tree();
|
||||
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST( Tree::SelectMode );
|
||||
VARIANT_ENUM_CAST(Tree::SelectMode);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -29,39 +29,37 @@
|
|||
#include "video_player.h"
|
||||
#include "os/os.h"
|
||||
|
||||
|
||||
int VideoPlayer::InternalStream::get_channel_count() const {
|
||||
|
||||
return player->sp_get_channel_count();
|
||||
}
|
||||
void VideoPlayer::InternalStream::set_mix_rate(int p_rate){
|
||||
void VideoPlayer::InternalStream::set_mix_rate(int p_rate) {
|
||||
|
||||
return player->sp_set_mix_rate(p_rate);
|
||||
}
|
||||
bool VideoPlayer::InternalStream::mix(int32_t *p_buffer,int p_frames){
|
||||
bool VideoPlayer::InternalStream::mix(int32_t *p_buffer, int p_frames) {
|
||||
|
||||
return player->sp_mix(p_buffer,p_frames);
|
||||
return player->sp_mix(p_buffer, p_frames);
|
||||
}
|
||||
void VideoPlayer::InternalStream::update(){
|
||||
void VideoPlayer::InternalStream::update() {
|
||||
|
||||
player->sp_update();
|
||||
}
|
||||
|
||||
|
||||
int VideoPlayer::sp_get_channel_count() const {
|
||||
|
||||
return playback->get_channels();
|
||||
}
|
||||
|
||||
void VideoPlayer::sp_set_mix_rate(int p_rate){
|
||||
void VideoPlayer::sp_set_mix_rate(int p_rate) {
|
||||
|
||||
server_mix_rate=p_rate;
|
||||
server_mix_rate = p_rate;
|
||||
}
|
||||
|
||||
bool VideoPlayer::sp_mix(int32_t *p_buffer,int p_frames) {
|
||||
bool VideoPlayer::sp_mix(int32_t *p_buffer, int p_frames) {
|
||||
|
||||
if (resampler.is_ready()) {
|
||||
return resampler.mix(p_buffer,p_frames);
|
||||
return resampler.mix(p_buffer, p_frames);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
@ -92,24 +90,22 @@ void VideoPlayer::sp_update() {
|
|||
#endif
|
||||
}
|
||||
|
||||
int VideoPlayer::_audio_mix_callback(void* p_udata,const int16_t *p_data,int p_frames) {
|
||||
int VideoPlayer::_audio_mix_callback(void *p_udata, const int16_t *p_data, int p_frames) {
|
||||
|
||||
VideoPlayer *vp=(VideoPlayer*)p_udata;
|
||||
VideoPlayer *vp = (VideoPlayer *)p_udata;
|
||||
|
||||
int todo=MIN(vp->resampler.get_todo(),p_frames);
|
||||
int todo = MIN(vp->resampler.get_todo(), p_frames);
|
||||
|
||||
int16_t *wb = vp->resampler.get_write_buffer();
|
||||
int c = vp->resampler.get_channel_count();
|
||||
|
||||
for(int i=0;i<todo*c;i++) {
|
||||
wb[i]=p_data[i];
|
||||
for (int i = 0; i < todo * c; i++) {
|
||||
wb[i] = p_data[i];
|
||||
}
|
||||
vp->resampler.write(todo);
|
||||
return todo;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void VideoPlayer::_notification(int p_notification) {
|
||||
|
||||
switch (p_notification) {
|
||||
|
|
@ -132,12 +128,11 @@ void VideoPlayer::_notification(int p_notification) {
|
|||
|
||||
double audio_time = USEC_TO_SEC(OS::get_singleton()->get_ticks_usec()); //AudioServer::get_singleton()->get_mix_time();
|
||||
|
||||
double delta = last_audio_time==0?0:audio_time-last_audio_time;
|
||||
last_audio_time=audio_time;
|
||||
if (delta==0)
|
||||
double delta = last_audio_time == 0 ? 0 : audio_time - last_audio_time;
|
||||
last_audio_time = audio_time;
|
||||
if (delta == 0)
|
||||
return;
|
||||
|
||||
|
||||
playback->update(delta);
|
||||
|
||||
} break;
|
||||
|
|
@ -149,17 +144,13 @@ void VideoPlayer::_notification(int p_notification) {
|
|||
if (texture->get_width() == 0)
|
||||
return;
|
||||
|
||||
Size2 s=expand?get_size():texture->get_size();
|
||||
draw_texture_rect(texture,Rect2(Point2(),s),false);
|
||||
Size2 s = expand ? get_size() : texture->get_size();
|
||||
draw_texture_rect(texture, Rect2(Point2(), s), false);
|
||||
|
||||
} break;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
Size2 VideoPlayer::get_minimum_size() const {
|
||||
|
||||
if (!expand && !texture.is_null())
|
||||
|
|
@ -170,7 +161,7 @@ Size2 VideoPlayer::get_minimum_size() const {
|
|||
|
||||
void VideoPlayer::set_expand(bool p_expand) {
|
||||
|
||||
expand=p_expand;
|
||||
expand = p_expand;
|
||||
update();
|
||||
minimum_size_changed();
|
||||
}
|
||||
|
|
@ -180,35 +171,34 @@ bool VideoPlayer::has_expand() const {
|
|||
return expand;
|
||||
}
|
||||
|
||||
|
||||
void VideoPlayer::set_stream(const Ref<VideoStream> &p_stream) {
|
||||
|
||||
stop();
|
||||
|
||||
stream=p_stream;
|
||||
if (stream.is_valid()) {
|
||||
stream->set_audio_track(audio_track);
|
||||
playback=stream->instance_playback();
|
||||
} else {
|
||||
playback=Ref<VideoStreamPlayback>();
|
||||
}
|
||||
stream = p_stream;
|
||||
if (stream.is_valid()) {
|
||||
stream->set_audio_track(audio_track);
|
||||
playback = stream->instance_playback();
|
||||
} else {
|
||||
playback = Ref<VideoStreamPlayback>();
|
||||
}
|
||||
|
||||
if (!playback.is_null()) {
|
||||
playback->set_loop(loops);
|
||||
playback->set_paused(paused);
|
||||
texture=playback->get_texture();
|
||||
texture = playback->get_texture();
|
||||
|
||||
const int channels = playback->get_channels();
|
||||
|
||||
AudioServer::get_singleton()->lock();
|
||||
if (channels > 0)
|
||||
resampler.setup(channels,playback->get_mix_rate(),server_mix_rate,buffering_ms,0);
|
||||
resampler.setup(channels, playback->get_mix_rate(), server_mix_rate, buffering_ms, 0);
|
||||
else
|
||||
resampler.clear();
|
||||
AudioServer::get_singleton()->unlock();
|
||||
|
||||
if (channels > 0)
|
||||
playback->set_mix_callback(_audio_mix_callback,this);
|
||||
playback->set_mix_callback(_audio_mix_callback, this);
|
||||
|
||||
} else {
|
||||
texture.unref();
|
||||
|
|
@ -218,7 +208,6 @@ void VideoPlayer::set_stream(const Ref<VideoStream> &p_stream) {
|
|||
}
|
||||
|
||||
update();
|
||||
|
||||
};
|
||||
|
||||
Ref<VideoStream> VideoPlayer::get_stream() const {
|
||||
|
|
@ -234,9 +223,9 @@ void VideoPlayer::play() {
|
|||
playback->stop();
|
||||
playback->play();
|
||||
set_process(true);
|
||||
AudioServer::get_singleton()->stream_set_active(stream_rid,true);
|
||||
AudioServer::get_singleton()->stream_set_volume_scale(stream_rid,volume);
|
||||
last_audio_time=0;
|
||||
AudioServer::get_singleton()->stream_set_active(stream_rid, true);
|
||||
AudioServer::get_singleton()->stream_set_volume_scale(stream_rid, volume);
|
||||
last_audio_time = 0;
|
||||
};
|
||||
|
||||
void VideoPlayer::stop() {
|
||||
|
|
@ -247,10 +236,10 @@ void VideoPlayer::stop() {
|
|||
return;
|
||||
|
||||
playback->stop();
|
||||
AudioServer::get_singleton()->stream_set_active(stream_rid,false);
|
||||
AudioServer::get_singleton()->stream_set_active(stream_rid, false);
|
||||
resampler.flush();
|
||||
set_process(false);
|
||||
last_audio_time=0;
|
||||
last_audio_time = 0;
|
||||
};
|
||||
|
||||
bool VideoPlayer::is_playing() const {
|
||||
|
|
@ -263,7 +252,7 @@ bool VideoPlayer::is_playing() const {
|
|||
|
||||
void VideoPlayer::set_paused(bool p_paused) {
|
||||
|
||||
paused=p_paused;
|
||||
paused = p_paused;
|
||||
if (playback.is_valid()) {
|
||||
playback->set_paused(p_paused);
|
||||
set_process(!p_paused);
|
||||
|
|
@ -278,27 +267,26 @@ bool VideoPlayer::is_paused() const {
|
|||
|
||||
void VideoPlayer::set_buffering_msec(int p_msec) {
|
||||
|
||||
buffering_ms=p_msec;
|
||||
buffering_ms = p_msec;
|
||||
}
|
||||
|
||||
int VideoPlayer::get_buffering_msec() const{
|
||||
int VideoPlayer::get_buffering_msec() const {
|
||||
|
||||
return buffering_ms;
|
||||
}
|
||||
|
||||
void VideoPlayer::set_audio_track(int p_track) {
|
||||
audio_track=p_track;
|
||||
audio_track = p_track;
|
||||
}
|
||||
|
||||
int VideoPlayer::get_audio_track() const {
|
||||
|
||||
return audio_track;
|
||||
return audio_track;
|
||||
}
|
||||
|
||||
|
||||
void VideoPlayer::set_volume(float p_vol) {
|
||||
|
||||
volume=p_vol;
|
||||
volume = p_vol;
|
||||
};
|
||||
|
||||
float VideoPlayer::get_volume() const {
|
||||
|
|
@ -308,7 +296,7 @@ float VideoPlayer::get_volume() const {
|
|||
|
||||
void VideoPlayer::set_volume_db(float p_db) {
|
||||
|
||||
if (p_db<-79)
|
||||
if (p_db < -79)
|
||||
set_volume(0);
|
||||
else
|
||||
set_volume(Math::db2linear(p_db));
|
||||
|
|
@ -316,13 +304,12 @@ void VideoPlayer::set_volume_db(float p_db) {
|
|||
|
||||
float VideoPlayer::get_volume_db() const {
|
||||
|
||||
if (volume==0)
|
||||
if (volume == 0)
|
||||
return -80;
|
||||
else
|
||||
return Math::linear2db(volume);
|
||||
};
|
||||
|
||||
|
||||
String VideoPlayer::get_stream_name() const {
|
||||
|
||||
if (stream.is_null())
|
||||
|
|
@ -342,12 +329,12 @@ Ref<Texture> VideoPlayer::get_video_texture() {
|
|||
if (playback.is_valid())
|
||||
return playback->get_texture();
|
||||
|
||||
return Ref<Texture> ();
|
||||
return Ref<Texture>();
|
||||
}
|
||||
|
||||
void VideoPlayer::set_autoplay(bool p_enable) {
|
||||
|
||||
autoplay=p_enable;
|
||||
autoplay = p_enable;
|
||||
};
|
||||
|
||||
bool VideoPlayer::has_autoplay() const {
|
||||
|
|
@ -357,69 +344,67 @@ bool VideoPlayer::has_autoplay() const {
|
|||
|
||||
void VideoPlayer::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_stream","stream:VideoStream"),&VideoPlayer::set_stream);
|
||||
ObjectTypeDB::bind_method(_MD("get_stream:VideoStream"),&VideoPlayer::get_stream);
|
||||
ObjectTypeDB::bind_method(_MD("set_stream", "stream:VideoStream"), &VideoPlayer::set_stream);
|
||||
ObjectTypeDB::bind_method(_MD("get_stream:VideoStream"), &VideoPlayer::get_stream);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("play"),&VideoPlayer::play);
|
||||
ObjectTypeDB::bind_method(_MD("stop"),&VideoPlayer::stop);
|
||||
ObjectTypeDB::bind_method(_MD("play"), &VideoPlayer::play);
|
||||
ObjectTypeDB::bind_method(_MD("stop"), &VideoPlayer::stop);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("is_playing"),&VideoPlayer::is_playing);
|
||||
ObjectTypeDB::bind_method(_MD("is_playing"), &VideoPlayer::is_playing);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_paused","paused"),&VideoPlayer::set_paused);
|
||||
ObjectTypeDB::bind_method(_MD("is_paused"),&VideoPlayer::is_paused);
|
||||
ObjectTypeDB::bind_method(_MD("set_paused", "paused"), &VideoPlayer::set_paused);
|
||||
ObjectTypeDB::bind_method(_MD("is_paused"), &VideoPlayer::is_paused);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_volume","volume"),&VideoPlayer::set_volume);
|
||||
ObjectTypeDB::bind_method(_MD("get_volume"),&VideoPlayer::get_volume);
|
||||
ObjectTypeDB::bind_method(_MD("set_volume", "volume"), &VideoPlayer::set_volume);
|
||||
ObjectTypeDB::bind_method(_MD("get_volume"), &VideoPlayer::get_volume);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_volume_db","db"),&VideoPlayer::set_volume_db);
|
||||
ObjectTypeDB::bind_method(_MD("get_volume_db"),&VideoPlayer::get_volume_db);
|
||||
ObjectTypeDB::bind_method(_MD("set_volume_db", "db"), &VideoPlayer::set_volume_db);
|
||||
ObjectTypeDB::bind_method(_MD("get_volume_db"), &VideoPlayer::get_volume_db);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_audio_track","track"),&VideoPlayer::set_audio_track);
|
||||
ObjectTypeDB::bind_method(_MD("get_audio_track"),&VideoPlayer::get_audio_track);
|
||||
ObjectTypeDB::bind_method(_MD("set_audio_track", "track"), &VideoPlayer::set_audio_track);
|
||||
ObjectTypeDB::bind_method(_MD("get_audio_track"), &VideoPlayer::get_audio_track);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("get_stream_name"),&VideoPlayer::get_stream_name);
|
||||
ObjectTypeDB::bind_method(_MD("get_stream_name"), &VideoPlayer::get_stream_name);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("get_stream_pos"),&VideoPlayer::get_stream_pos);
|
||||
ObjectTypeDB::bind_method(_MD("get_stream_pos"), &VideoPlayer::get_stream_pos);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_autoplay","enabled"),&VideoPlayer::set_autoplay);
|
||||
ObjectTypeDB::bind_method(_MD("has_autoplay"),&VideoPlayer::has_autoplay);
|
||||
ObjectTypeDB::bind_method(_MD("set_autoplay", "enabled"), &VideoPlayer::set_autoplay);
|
||||
ObjectTypeDB::bind_method(_MD("has_autoplay"), &VideoPlayer::has_autoplay);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_expand","enable"), &VideoPlayer::set_expand );
|
||||
ObjectTypeDB::bind_method(_MD("has_expand"), &VideoPlayer::has_expand );
|
||||
ObjectTypeDB::bind_method(_MD("set_expand", "enable"), &VideoPlayer::set_expand);
|
||||
ObjectTypeDB::bind_method(_MD("has_expand"), &VideoPlayer::has_expand);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_buffering_msec","msec"),&VideoPlayer::set_buffering_msec);
|
||||
ObjectTypeDB::bind_method(_MD("get_buffering_msec"),&VideoPlayer::get_buffering_msec);
|
||||
ObjectTypeDB::bind_method(_MD("set_buffering_msec", "msec"), &VideoPlayer::set_buffering_msec);
|
||||
ObjectTypeDB::bind_method(_MD("get_buffering_msec"), &VideoPlayer::get_buffering_msec);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("get_video_texture:Texture"), &VideoPlayer::get_video_texture );
|
||||
ObjectTypeDB::bind_method(_MD("get_video_texture:Texture"), &VideoPlayer::get_video_texture);
|
||||
|
||||
ADD_PROPERTY( PropertyInfo(Variant::INT, "stream/audio_track",PROPERTY_HINT_RANGE,"0,128,1"), _SCS("set_audio_track"), _SCS("get_audio_track") );
|
||||
ADD_PROPERTY( PropertyInfo(Variant::OBJECT, "stream/stream", PROPERTY_HINT_RESOURCE_TYPE,"VideoStream"), _SCS("set_stream"), _SCS("get_stream") );
|
||||
// ADD_PROPERTY( PropertyInfo(Variant::BOOL, "stream/loop"), _SCS("set_loop"), _SCS("has_loop") );
|
||||
ADD_PROPERTY( PropertyInfo(Variant::REAL, "stream/volume_db", PROPERTY_HINT_RANGE,"-80,24,0.01"), _SCS("set_volume_db"), _SCS("get_volume_db") );
|
||||
ADD_PROPERTY( PropertyInfo(Variant::BOOL, "stream/autoplay"), _SCS("set_autoplay"), _SCS("has_autoplay") );
|
||||
ADD_PROPERTY( PropertyInfo(Variant::BOOL, "stream/paused"), _SCS("set_paused"), _SCS("is_paused") );
|
||||
ADD_PROPERTY( PropertyInfo( Variant::BOOL, "expand" ), _SCS("set_expand"),_SCS("has_expand") );
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "stream/audio_track", PROPERTY_HINT_RANGE, "0,128,1"), _SCS("set_audio_track"), _SCS("get_audio_track"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "stream/stream", PROPERTY_HINT_RESOURCE_TYPE, "VideoStream"), _SCS("set_stream"), _SCS("get_stream"));
|
||||
// ADD_PROPERTY( PropertyInfo(Variant::BOOL, "stream/loop"), _SCS("set_loop"), _SCS("has_loop") );
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "stream/volume_db", PROPERTY_HINT_RANGE, "-80,24,0.01"), _SCS("set_volume_db"), _SCS("get_volume_db"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "stream/autoplay"), _SCS("set_autoplay"), _SCS("has_autoplay"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "stream/paused"), _SCS("set_paused"), _SCS("is_paused"));
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "expand"), _SCS("set_expand"), _SCS("has_expand"));
|
||||
}
|
||||
|
||||
|
||||
VideoPlayer::VideoPlayer() {
|
||||
|
||||
volume=1;
|
||||
volume = 1;
|
||||
loops = false;
|
||||
paused = false;
|
||||
autoplay = false;
|
||||
expand = true;
|
||||
loops = false;
|
||||
|
||||
audio_track=0;
|
||||
audio_track = 0;
|
||||
|
||||
buffering_ms=500;
|
||||
server_mix_rate=44100;
|
||||
|
||||
internal_stream.player=this;
|
||||
stream_rid=AudioServer::get_singleton()->audio_stream_create(&internal_stream);
|
||||
last_audio_time=0;
|
||||
buffering_ms = 500;
|
||||
server_mix_rate = 44100;
|
||||
|
||||
internal_stream.player = this;
|
||||
stream_rid = AudioServer::get_singleton()->audio_stream_create(&internal_stream);
|
||||
last_audio_time = 0;
|
||||
};
|
||||
|
||||
VideoPlayer::~VideoPlayer() {
|
||||
|
|
@ -428,4 +413,3 @@ VideoPlayer::~VideoPlayer() {
|
|||
AudioServer::get_singleton()->free(stream_rid);
|
||||
resampler.clear(); //Not necessary here, but make in consistent with other "stream_player" classes
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -29,33 +29,31 @@
|
|||
#ifndef VIDEO_PLAYER_H
|
||||
#define VIDEO_PLAYER_H
|
||||
|
||||
#include "scene/resources/video_stream.h"
|
||||
#include "scene/gui/control.h"
|
||||
#include "scene/resources/video_stream.h"
|
||||
#include "servers/audio/audio_rb_resampler.h"
|
||||
|
||||
class VideoPlayer : public Control {
|
||||
|
||||
OBJ_TYPE(VideoPlayer,Control);
|
||||
OBJ_TYPE(VideoPlayer, Control);
|
||||
|
||||
struct InternalStream : public AudioServer::AudioStream {
|
||||
VideoPlayer *player;
|
||||
virtual int get_channel_count() const;
|
||||
virtual void set_mix_rate(int p_rate); //notify the stream of the mix rate
|
||||
virtual bool mix(int32_t *p_buffer,int p_frames);
|
||||
virtual bool mix(int32_t *p_buffer, int p_frames);
|
||||
virtual void update();
|
||||
};
|
||||
|
||||
|
||||
InternalStream internal_stream;
|
||||
Ref<VideoStreamPlayback> playback;
|
||||
Ref<VideoStream> stream;
|
||||
|
||||
int sp_get_channel_count() const;
|
||||
void sp_set_mix_rate(int p_rate); //notify the stream of the mix rate
|
||||
bool sp_mix(int32_t *p_buffer,int p_frames);
|
||||
bool sp_mix(int32_t *p_buffer, int p_frames);
|
||||
void sp_update();
|
||||
|
||||
|
||||
RID stream_rid;
|
||||
|
||||
Ref<ImageTexture> texture;
|
||||
|
|
@ -70,24 +68,20 @@ class VideoPlayer : public Control {
|
|||
bool expand;
|
||||
bool loops;
|
||||
int buffering_ms;
|
||||
int server_mix_rate;
|
||||
int audio_track;
|
||||
|
||||
static int _audio_mix_callback(void* p_udata,const int16_t *p_data,int p_frames);
|
||||
int server_mix_rate;
|
||||
int audio_track;
|
||||
|
||||
static int _audio_mix_callback(void *p_udata, const int16_t *p_data, int p_frames);
|
||||
|
||||
protected:
|
||||
|
||||
static void _bind_methods();
|
||||
void _notification(int p_notification);
|
||||
|
||||
public:
|
||||
|
||||
Size2 get_minimum_size() const;
|
||||
void set_expand(bool p_expand);
|
||||
bool has_expand() const;
|
||||
|
||||
|
||||
Ref<Texture> get_video_texture();
|
||||
|
||||
void set_stream(const Ref<VideoStream> &p_stream);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue