// File: /workspace/github_c_makefile_star2_O2/OnionIoT[P]lv_example/lvgl/src/lv_objx/lv_slider.c
// Function: lv_slider_signal
static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * param)
{
    lv_res_t res;

    /* Include the ancient signal function */
    res = ancestor_signal(slider, sign, param);
    if(res != LV_RES_OK) return res;
    if(sign == LV_SIGNAL_GET_TYPE) return lv_obj_handle_get_type_signal(param, LV_OBJX_NAME);

    lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider);
    lv_point_t p;
    lv_coord_t w = lv_obj_get_width(slider);
    lv_coord_t h = lv_obj_get_height(slider);

    if(sign == LV_SIGNAL_PRESSED) {
        ext->drag_value = lv_slider_get_value(slider);
    } else if(sign == LV_SIGNAL_PRESSING) {
        lv_indev_get_point(param, &p);
        int16_t tmp = 0;
        if(w > h) {
            lv_coord_t knob_w = h;
            p.x -=
                slider->coords.x1 + h / 2; /*Modify the point to shift with half knob (important on the start and end)*/
            tmp = (int32_t)((int32_t)p.x * (ext->bar.max_value - ext->bar.min_value + 1)) / (w - knob_w);
            tmp += ext->bar.min_value;
        } else {
            lv_coord_t knob_h = w;
            p.y -=
                slider->coords.y1 + w / 2; /*Modify the point to shift with half knob (important on the start and end)*/
            tmp = (int32_t)((int32_t)p.y * (ext->bar.max_value - ext->bar.min_value + 1)) / (h - knob_h);
            tmp = ext->bar.max_value - tmp; /*Invert the value: smaller value means higher y*/
        }

        if(tmp < ext->bar.min_value)
            tmp = ext->bar.min_value;
        else if(tmp > ext->bar.max_value)
            tmp = ext->bar.max_value;

        if(tmp != ext->drag_value) {
            ext->drag_value = tmp;
            lv_obj_invalidate(slider);
            res = lv_event_send(slider, LV_EVENT_VALUE_CHANGED, NULL);
            if(res != LV_RES_OK) return res;
        }
    } else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST) {
        if(ext->drag_value != LV_SLIDER_NOT_PRESSED) lv_slider_set_value(slider, ext->drag_value, false);
        ext->drag_value = LV_SLIDER_NOT_PRESSED;

#if LV_USE_GROUP
        /*Leave edit mode if released. (No need to wait for LONG_PRESS) */
        lv_group_t * g             = lv_obj_get_group(slider);
        bool editing               = lv_group_get_editing(g);
        lv_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act());
        if(indev_type == LV_INDEV_TYPE_ENCODER) {
            if(editing) lv_group_set_editing(g, false);
        }
#endif

    } else if(sign == LV_SIGNAL_CORD_CHG) {
        /* The knob size depends on slider size.
         * During the drawing method the ext. size is used by the knob so refresh the ext. size.*/
        if(lv_obj_get_width(slider) != lv_area_get_width(param) ||
           lv_obj_get_height(slider) != lv_area_get_height(param)) {
            slider->signal_cb(slider, LV_SIGNAL_REFR_EXT_DRAW_PAD, NULL);
        }
    } else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) {
        const lv_style_t * style      = lv_slider_get_style(slider, LV_SLIDER_STYLE_BG);
        const lv_style_t * knob_style = lv_slider_get_style(slider, LV_SLIDER_STYLE_KNOB);

        lv_coord_t shadow_w = knob_style->body.shadow.width;
        if(ext->knob_in == 0) {
            /* The smaller size is the knob diameter*/
            lv_coord_t x = LV_MATH_MIN(w / 2 + 1 + shadow_w, h / 2 + 1 + shadow_w);
            if(slider->ext_draw_pad < x) slider->ext_draw_pad = x;
        } else {
            lv_coord_t pad = 0;
            pad            = LV_MATH_MIN(pad, style->body.padding.top);
            pad            = LV_MATH_MIN(pad, style->body.padding.bottom);
            pad            = LV_MATH_MIN(pad, style->body.padding.left);
            pad            = LV_MATH_MIN(pad, style->body.padding.right);
            if(pad < 0) pad = -pad;
            if(slider->ext_draw_pad < pad) slider->ext_draw_pad = pad;

            if(slider->ext_draw_pad < shadow_w) slider->ext_draw_pad = shadow_w;
        }
    } else if(sign == LV_SIGNAL_CONTROL) {
        char c = *((char *)param);

        ext->drag_value = LV_SLIDER_NOT_PRESSED;

        if(c == LV_KEY_RIGHT || c == LV_KEY_UP) {
            lv_slider_set_value(slider, lv_slider_get_value(slider) + 1, true);
            res = lv_event_send(slider, LV_EVENT_VALUE_CHANGED, NULL);
            if(res != LV_RES_OK) return res;
        } else if(c == LV_KEY_LEFT || c == LV_KEY_DOWN) {
            lv_slider_set_value(slider, lv_slider_get_value(slider) - 1, true);
            res = lv_event_send(slider, LV_EVENT_VALUE_CHANGED, NULL);
            if(res != LV_RES_OK) return res;
        }
    } else if(sign == LV_SIGNAL_GET_EDITABLE) {
        bool * editable = (bool *)param;
        *editable       = true;
    }

    return res;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r15
movl %esi, %r14d
movq %rdi, %rbx
callq *0x42c7e(%rip)          # 0x5e3e0
movl %eax, %ebp
cmpb $0x1, %al
jne 0x1b900
cmpb $0x7, %r14b
jne 0x1b78f
leaq 0x200d7(%rip), %rsi     # 0x3b850
movq %r15, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x684b
movq %rbx, %rdi
callq 0x6747
movq %rax, %rbp
movq %rbx, %rdi
callq 0x5308
movl %eax, %r12d
movq %rbx, %rdi
callq 0x5332
movl %eax, %r13d
cmpb $0x9, %r14b
je 0x1b7d3
movzbl %r14b, %eax
cmpl $0x8, %eax
jne 0x1b82d
movq %rbx, %rdi
callq 0x1c203
movw %ax, 0x20(%rbp)
movb $0x1, %bpl
jmp 0x1b900
leaq 0xc(%rsp), %rsi
movq %r15, %rdi
callq 0x3661
movswl %r12w, %ecx
movswl %r13w, %r8d
movw $0xfffe, %si            # imm = 0xFFFE
cmpw %r13w, %r12w
jle 0x1b896
movl %r13d, %eax
cwtd
idivw %si
subw 0x20(%rbx), %ax
addw 0xc(%rsp), %ax
movw %ax, 0xc(%rsp)
movswl %ax, %edx
movswl 0x4(%rbp), %edi
movswl 0x2(%rbp), %esi
movl %edi, %eax
subl %esi, %eax
incl %eax
imull %edx, %eax
subl %r8d, %ecx
cltd
idivl %ecx
addl %esi, %eax
jmp 0x1b8cd
movl %r14d, %ecx
andb $-0x2, %cl
cmpb $0xa, %cl
jne 0x1b911
movzwl 0x20(%rbp), %eax
cmpw $0x8000, %ax            # imm = 0x8000
je 0x1b853
movswl %ax, %esi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x8a31
movw $0x8000, 0x20(%rbp)     # imm = 0x8000
movq %rbx, %rdi
callq 0x4b8e
movq %rax, %rbx
movq %rax, %rdi
callq 0x2aaa
movl %eax, %ebp
callq 0x35b3
movq %rax, %rdi
callq 0x35bb
cmpb $0x4, %al
sete %al
andb %bpl, %al
movb $0x1, %bpl
cmpb $0x1, %al
jne 0x1b900
movq %rbx, %rdi
xorl %esi, %esi
callq 0x275c
jmp 0x1b900
movl %r12d, %eax
cwtd
idivw %si
subw 0x22(%rbx), %ax
addw 0xe(%rsp), %ax
movw %ax, 0xe(%rsp)
movswl %ax, %edx
movswl 0x4(%rbp), %edi
movswl 0x2(%rbp), %esi
movl %edi, %eax
subl %esi, %eax
incl %eax
imull %edx, %eax
subl %ecx, %r8d
cltd
idivl %r8d
movl %eax, %ecx
movl %edi, %eax
subl %ecx, %eax
movq %rbp, %rcx
cmpw %di, %ax
cmovll %eax, %edi
cmpw %si, %ax
cmovgel %edi, %esi
movb $0x1, %bpl
cmpw 0x20(%rcx), %si
je 0x1b900
movw %si, 0x20(%rcx)
movq %rbx, %rdi
callq 0x493a
pushq $0xe
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x4caf
movl %eax, %ebp
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbp, 0x10(%rsp)
movb $0x1, %bpl
cmpb $0x13, %r14b
je 0x1b9f6
cmpl $0x6, %eax
je 0x1b974
cmpl $0x12, %eax
je 0x1b9d1
cmpl $0x2, %eax
jne 0x1b900
movq %rbx, %rdi
callq 0x5308
movzwl 0x4(%r15), %ecx
subw (%r15), %cx
incl %ecx
cmpw %cx, %ax
jne 0x1b967
movq %rbx, %rdi
callq 0x5332
movzwl 0x6(%r15), %ecx
subw 0x2(%r15), %cx
incl %ecx
cmpw %cx, %ax
je 0x1b900
pushq $0x6
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq *0x30(%rbx)
jmp 0x1b900
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1c29c
movq %rax, %r14
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x1c29c
movzwl 0x12(%rax), %esi
movq 0x10(%rsp), %rax
testb $0x1, 0x22(%rax)
jne 0x1b9ff
movw $0x2, %di
movl %r12d, %eax
cwtd
idivw %di
movl %eax, %ecx
movl %r13d, %eax
cwtd
idivw %di
cmpw %ax, %cx
cmovll %ecx, %eax
addl %esi, %eax
incl %eax
cmpw %ax, 0x5c(%rbx)
jge 0x1b900
movw %ax, 0x5c(%rbx)
jmp 0x1b900
movzbl (%r15), %eax
movq 0x10(%rsp), %rcx
movw $0x8000, 0x20(%rcx)     # imm = 0x8000
movl %eax, %ecx
andb $-0x3, %cl
cmpb $0x11, %cl
jne 0x1ba57
movq %rbx, %rdi
callq 0x1c203
incl %eax
jmp 0x1ba6f
movb $0x1, (%r15)
jmp 0x1b900
movq 0x16(%r14), %xmm0
pshufd $0x55, %xmm0, %xmm1     # xmm1 = xmm0[1,1,1,1]
pminsw %xmm0, %xmm1
movdqa %xmm1, %xmm0
psrld $0x10, %xmm0
pminsw %xmm1, %xmm0
movd %xmm0, %eax
testw %ax, %ax
cmovsl %eax, %r15d
negl %r15d
movl 0x5c(%rbx), %eax
cmpw %r15w, %ax
cmovgl %eax, %r15d
setl %al
cmpw %si, %r15w
setl %cl
orb %al, %cl
je 0x1b900
cmpw %si, %r15w
cmovgl %r15d, %esi
movw %si, 0x5c(%rbx)
jmp 0x1b900
cmpl $0x14, %eax
je 0x1ba65
cmpl $0x12, %eax
jne 0x1b900
movq %rbx, %rdi
callq 0x1c203
decl %eax
movswl %ax, %esi
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x8a31
jmp 0x1b8f1