Textbox improvement, camera blend mode

This commit is contained in:
Tanasart 2024-01-24 14:38:57 +07:00
parent d33137233d
commit 77271b7de2
7 changed files with 233 additions and 129 deletions

View file

@ -75,6 +75,9 @@ function Node_3D_Camera(_x, _y, _group = noone) : Node_3D_Object(_x, _y, _group)
inputs[| in_d3d + 21] = nodeValue("Round Normal", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0 )
.setWindows();
inputs[| in_d3d + 22] = nodeValue("Blend mode", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0 )
.setDisplay(VALUE_DISPLAY.enum_button, [ "Normal", "Additive" ]);
in_cam = ds_list_size(inputs);
outputs[| 0] = nodeValue("Rendered", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone );
@ -89,7 +92,7 @@ function Node_3D_Camera(_x, _y, _group = noone) : Node_3D_Object(_x, _y, _group)
["Output", false], in_d3d + 2,
["Transform", false], in_d3d + 9, 0, 1, in_d3d + 10, in_d3d + 11, in_d3d + 12, in_d3d + 13, in_d3d + 14,
["Camera", true], in_d3d + 3, in_d3d + 0, in_d3d + 1, in_d3d + 8,
["Render", true], in_d3d + 5, in_d3d + 16, in_d3d + 6, in_d3d + 7, in_d3d + 15,
["Render", true], in_d3d + 5, in_d3d + 16, in_d3d + 6, in_d3d + 7, in_d3d + 15, in_d3d + 22,
["Ambient Occlusion", true], in_d3d + 17, in_d3d + 20, in_d3d + 18, in_d3d + 19,
["Effects", true], in_d3d + 21,
];
@ -227,6 +230,7 @@ function Node_3D_Camera(_x, _y, _group = noone) : Node_3D_Object(_x, _y, _group)
var _aoSr = _data[in_d3d + 20];
var _nrmSmt = _data[in_d3d + 21];
var _blend = _data[in_d3d + 22];
var _qi1 = new BBMOD_Quaternion().FromAxisAngle(new BBMOD_Vec3(0, 1, 0), 90);
var _qi2 = new BBMOD_Quaternion().FromAxisAngle(new BBMOD_Vec3(1, 0, 0), -90);
@ -327,6 +331,11 @@ function Node_3D_Camera(_x, _y, _group = noone) : Node_3D_Object(_x, _y, _group)
gpu_set_ztestenable(true);
gpu_set_cullmode(_back);
if(_blend == 1) {
BLEND_ADD
gpu_set_ztestenable(false);
}
camera.applyCamera();
scene.reset();
scene.submitShader(_sobj);
@ -335,6 +344,7 @@ function Node_3D_Camera(_x, _y, _group = noone) : Node_3D_Object(_x, _y, _group)
scene.apply(deferData);
scene.submit(_sobj);
BLEND_NORMAL
surface_reset_target();
camera.resetCamera();

View file

@ -100,7 +100,8 @@ function Node_Scatter(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
inputs[| 31] = nodeValue("Auto amount", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false);
inputs[| 32] = nodeValue("Alternate rotation", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false);
inputs[| 32] = nodeValue("Twisting", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0)
.setDisplay(VALUE_DISPLAY.rotation);
inputs[| 33] = nodeValue("Random position", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, [ 0, 0, 0, 0 ])
.setDisplay(VALUE_DISPLAY.vector_range);
@ -371,7 +372,7 @@ function Node_Scatter(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
} else {
var _ang = _acol * 360 / uniAmo[0];
var _rad = uniAmo[1] == 1? 0.5 : _arow / (uniAmo[1] - 1);
if(uniRot) _ang += (_arow % 2) * 180 / uniAmo[0];
_ang += _arow * uniRot;
_x += _axc + lengthdir_x(_rad * _aw, _ang);
_y += _ayc + lengthdir_y(_rad * _ah, _ang);

View file

@ -1613,7 +1613,7 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
cache_value[1] = _time;
}
cache_value[2] = val;
cache_value[2] = variable_clone(val, 1);
cache_value[3] = applyUnit;
updateColor(val);

View file

@ -17,7 +17,7 @@ function Panel_Text_Editor(_textArea, _inputFunc, _context) : PanelContent() con
self.inputFunc = method(self, _inputFunc);
self.context = _context;
shift_new_line = true;
shift_new_line = false;
function drawContent(panel) {
draw_clear_alpha(COLORS.panel_bg_clear, 0);
@ -57,6 +57,7 @@ function Panel_Text_Editor(_textArea, _inputFunc, _context) : PanelContent() con
var th = h - ui(4 + 36 + 8);
var _text = inputFunc();
_textArea.setMaxHieght(th);
_textArea.register();
_textArea.setFocusHover(pFOCUS, pHOVER);
_textArea.shift_new_line = shift_new_line;

View file

@ -122,11 +122,6 @@ function scrollPane(_w, _h, ondraw) : widget() constructor {
draw_sprite_stretched_ext(THEME.ui_scrollbar, 0, scr_x, scr_y, scr_w, scr_h, bg_col, 1);
draw_sprite_stretched_ext(THEME.ui_scrollbar, 0, bx0, by0, ww, hh, bar_col, 1);
//draw_set_color(c_white);
//draw_rectangle(scr_x - 2, scr_y - 2, scr_x + scr_w + 2, scr_y + scr_h + 2, 0);
//draw_set_color(c_red);
//draw_circle(mx, my, 2, false);
if(active && point_in_rectangle(mx, my, scr_x - 2, scr_y - 2, scr_x + scr_w + 2, scr_y + scr_h + 2) || is_scrolling) {
draw_sprite_stretched_ext(THEME.ui_scrollbar, 0, bar_x, bar_y, bar_w, bar_h, bar_hcol, 1);
if(mouse_press(mb_left, active)) {

View file

@ -26,6 +26,7 @@ function textArea(_input, _onModify) : textInput(_input, _onModify) constructor
min_lines = 0;
line_width = 1000;
max_height = -1;
cursor = 0;
cursor_tx = 0;
@ -65,8 +66,22 @@ function textArea(_input, _onModify) : textInput(_input, _onModify) constructor
undo_stack = ds_stack_create();
redo_stack = ds_stack_create();
text_surface = noone;
text_y = 0;
text_y_to = 0;
text_y_max = 0;
text_scrolling = false;
text_scroll_sy = 0;
text_scroll_my = 0;
_cl = -1;
static setMaxHieght = function(height) { #region
max_height = height;
return self;
} #endregion
static activate = function() { #region
WIDGET_CURRENT = self;
WIDGET_CURRENT_SCROLL = parent;
@ -412,6 +427,7 @@ function textArea(_input, _onModify) : textInput(_input, _onModify) constructor
} else if(keyboard_check_pressed(vk_tab)) {
} else if(keyboardEnter() == 2) {
var ch = "\n";
if(cursor_select == -1) {
var str_before = string_copy(_input_text, 1, cursor);
var str_after = string_copy(_input_text, cursor + 1, string_length(_input_text) - cursor);
@ -611,6 +627,8 @@ function textArea(_input, _onModify) : textInput(_input, _onModify) constructor
var ch_y = _y;
var _str;
text_y_max = 0;
if(_input_text != _text) {
_input_text = _text;
cut_line();
@ -640,6 +658,7 @@ function textArea(_input, _onModify) : textInput(_input, _onModify) constructor
}
ch_y += line_get_height();
text_y_max += line_get_height();
}
draw_set_alpha(1);
@ -703,8 +722,12 @@ function textArea(_input, _onModify) : textInput(_input, _onModify) constructor
}
}
if(mouse_release(mb_left, active))
if(mouse_release(mb_left)) {
click_block = false;
if(cursor_select == cursor)
cursor_select = -1;
}
} #endregion
static drawParam = function(params) { #region
@ -715,6 +738,8 @@ function textArea(_input, _onModify) : textInput(_input, _onModify) constructor
} #endregion
static draw = function(_x, _y, _w, _h, _text, _m) { #region
_h = max_height == -1? _h : min(_h, max_height);
x = _x;
y = _y;
w = _w;
@ -726,10 +751,9 @@ function textArea(_input, _onModify) : textInput(_input, _onModify) constructor
_current_text = _text;
draw_set_font(font);
if(_stretch_width) {
_w = string_width(self == WIDGET_CURRENT? _input_text : _text) + ui(16);
if(_stretch_width) _w = string_width(self == WIDGET_CURRENT? _input_text : _text) + ui(16);
w = _w;
}
if(side_button && instanceof(side_button) == "buttonClass") {
side_button.setFocusHover(active, hover);
@ -737,7 +761,7 @@ function textArea(_input, _onModify) : textInput(_input, _onModify) constructor
_w -= ui(40);
}
var tx = _x + ui(8);
var tx = ui(8);
var hh = _h;
var pl = line_width;
@ -749,41 +773,59 @@ function textArea(_input, _onModify) : textInput(_input, _onModify) constructor
}
if(_stretch_width) line_width = 9999999;
cursor_tx = tx;
cursor_tx = _x + tx;
var c_h = line_get_height();
var line_count = max(min_lines, array_length(_input_text_line));
hh = max(_h, ui(14) + c_h * line_count);
if(max_height) hh = min(hh, max_height);
var _hw = _w;
if(max_height && text_y_max) {
_hw -= 16;
line_width -= 16;
}
var hoverRect = point_in_rectangle(_m[0], _m[1], _x, _y, _x + _hw, _y + hh);
var tsw = _w;
var tsh = hh;
text_surface = surface_verify(text_surface, tsw, tsh);
draw_sprite_stretched_ext(THEME.textbox, 3, _x, _y, _w, hh, boxColor, 1);
surface_set_shader(text_surface, noone, true, BLEND.add);
if(isCodeFormat() && show_line_number) {
draw_sprite_stretched_ext(THEME.textbox_code, 0, _x, _y, ui(code_line_width), hh, boxColor, 1);
draw_sprite_stretched_ext(THEME.textbox_code, 0, 0, 0, ui(code_line_width), hh, boxColor, 1);
draw_set_text(f_code, fa_right, fa_top, COLORS._main_text_sub);
var lx = _x + ui(code_line_width - 8);
var lx = ui(code_line_width - 8);
for( var i = 0; i < array_length(_input_text_line_index); i++ ) {
var ly = _y + ui(7) + i * c_h;
var ly = text_y + ui(7) + i * c_h;
draw_text_add(lx, ly, _input_text_line_index[i]);
}
}
var hoverRect = point_in_rectangle(_m[0], _m[1], _x, _y, _x + _w, _y + hh);
surface_reset_shader();
if(selecting) {
WIDGET_TAB_BLOCK = true;
draw_set_text(font, fa_left, fa_top, COLORS._main_text);
draw_sprite_stretched_ext(THEME.textbox, 2, _x, _y, _w, hh, COLORS._main_accent, 1);
editText();
#region draw
var msx = _m[0] - _x;
var msy = _m[1] - _y;
surface_set_shader(text_surface, noone, false, BLEND.add);
draw_set_text(font, fa_left, fa_top, COLORS._main_text);
#region draw cursor highlight
var _l, _str;
var ch_x = tx;
var ch_y = _y + ui(7);
var ch_y = text_y + ui(7);
var ch_sel_min = -1;
var ch_sel_max = -1;
var char_line = 0;
@ -859,7 +901,7 @@ function textArea(_input, _onModify) : textInput(_input, _onModify) constructor
cursor_pos_y = cursor_pos_y == 0? cursor_pos_y_to : lerp_float(cursor_pos_y, cursor_pos_y_to, 2);
#endregion
display_text(tx, _y + ui(7), _input_text, _m[0], _m[1], hover && hoverRect);
display_text(tx, text_y + ui(7), _input_text, msx, msy, hover && hoverRect);
if(cursor_pos_y != 0 && cursor_pos_x != 0) {
draw_set_color(COLORS._main_text_accent);
@ -867,13 +909,20 @@ function textArea(_input, _onModify) : textInput(_input, _onModify) constructor
draw_line_width(cursor_pos_x, cursor_pos_y, cursor_pos_x, cursor_pos_y + c_h, 2);
draw_set_alpha(1);
}
surface_reset_shader();
if(o_dialog_textbox_autocomplete.textbox == self) {
o_dialog_textbox_autocomplete.dialog_x = rx + cursor_pos_x + 1;
o_dialog_textbox_autocomplete.dialog_y = ry + cursor_pos_y + line_get_height() + 1;
}
BLEND_ALPHA
draw_surface(text_surface, _x, _y);
BLEND_NORMAL
if(typing) typing--;
draw_sprite_stretched_ext(THEME.textbox, 2, _x, _y, _w, hh, COLORS._main_accent, 1);
if(o_dialog_textbox_autocomplete.textbox == self) {
o_dialog_textbox_autocomplete.dialog_x = rx + _x + cursor_pos_x + 1;
o_dialog_textbox_autocomplete.dialog_y = ry + _y + cursor_pos_y + line_get_height() + 1;
}
#endregion
if(autocomplete_modi && PREFERENCES.widget_autocomplete_delay >= 0 && autocomplete_delay >= PREFERENCES.widget_autocomplete_delay) {
@ -881,10 +930,18 @@ function textArea(_input, _onModify) : textInput(_input, _onModify) constructor
autocomplete_modi = false;
}
if(!point_in_rectangle(_m[0], _m[1], _x, _y, _x + _w, _y + hh) && mouse_press(mb_left) && HOVER != o_dialog_textbox_autocomplete.id) {
if(!point_in_rectangle(_m[0], _m[1], _x, _y, _x + _w, _y + hh) && mouse_press(mb_left) && HOVER != o_dialog_textbox_autocomplete.id)
deactivate();
}
} else {
surface_set_shader(text_surface, noone, false, BLEND.add);
display_text(tx, text_y + ui(7), _text);
surface_reset_shader();
BLEND_ALPHA
draw_surface(text_surface, _x, _y);
BLEND_NORMAL
if(hover && hoverRect) {
if(hide)
draw_sprite_stretched_ext(THEME.textbox, 1, _x, _y, _w, hh, boxColor, 0.5);
@ -895,11 +952,51 @@ function textArea(_input, _onModify) : textInput(_input, _onModify) constructor
} else if(!hide)
draw_sprite_stretched_ext(THEME.textbox, 0, _x, _y, _w, hh, boxColor, 0.5 + 0.5 * interactable);
display_text(tx, _y + ui(7), _text);
o_dialog_textbox_autocomplete.deactivate(self);
}
#region scroll height
if(max_height) {
var total_h = text_y_max;
text_y_max = max(0, total_h - hh + 16);
text_y = lerp_float(text_y, text_y_to, 5);
if(hover) {
if(mouse_wheel_down()) text_y_to = clamp(text_y_to - ui(64) * SCROLL_SPEED, -text_y_max, 0);
if(mouse_wheel_up()) text_y_to = clamp(text_y_to + ui(64) * SCROLL_SPEED, -text_y_max, 0);
}
var scr_w = ui(sprite_get_width(THEME.ui_scrollbar));
var scr_h = hh - (ui(12) - scr_w) * 2;
var scr_x = _x + _w - ui(12);
var scr_y = _y + ui(12) - scr_w;
var bar_h = hh / total_h * scr_h;
var bar_y = scr_y + (scr_h - bar_h) * abs(text_y / text_y_max);
if(text_scrolling) {
text_y_to = text_scroll_sy - (_m[1] - text_scroll_my) / bar_h * scr_h;
text_y_to = clamp(text_y_to, -text_y_max, 0);
if(mouse_release(mb_left))
text_scrolling = false;
}
if(text_y_max) {
var hov = hover && point_in_rectangle(_m[0], _m[1], scr_x - 3, _y, _x + _w, _y + _h);
draw_sprite_stretched_ext(THEME.ui_scrollbar, 0, scr_x, scr_y, scr_w, scr_h, COLORS.scrollbar_bg, 1);
draw_sprite_stretched_ext(THEME.ui_scrollbar, 0, scr_x, bar_y, scr_w, bar_h, hov || text_scrolling? COLORS.scrollbar_hover : COLORS.scrollbar_idle, 1);
if(mouse_press(mb_left, hov && active)) {
text_scrolling = true;
text_scroll_sy = text_y;
text_scroll_my = _m[1];
}
}
}
#endregion
if(DRAGGING && (DRAGGING.type == "Text" || DRAGGING.type == "Number") && hover && hoverRect) {
draw_sprite_stretched_ext(THEME.ui_panel_active, 0, _x, _y, _w, hh, COLORS._main_value_positive, 1);
if(mouse_release(mb_left))
@ -907,8 +1004,8 @@ function textArea(_input, _onModify) : textInput(_input, _onModify) constructor
}
selecting = self == WIDGET_CURRENT;
resetFocus();
shift_new_line = true;
resetFocus();
return hh;
} #endregion