// File: /workspace/github_c_makefile_star2_O3/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 *0x42e4d(%rip)          # 0x603e0
movl %eax, %ebp
cmpb $0x1, %al
jne 0x1d746
cmpb $0x7, %r14b
jne 0x1d5c0
leaq 0x223a6(%rip), %rsi     # 0x3f950
movq %r15, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6c02
movq %rbx, %rdi
callq 0x6af7
movq %rax, %rbp
movq %rbx, %rdi
callq 0x566d
movl %eax, %r13d
movq %rbx, %rdi
callq 0x5697
movl %eax, %r12d
cmpb $0x9, %r14b
je 0x1d604
movzbl %r14b, %eax
cmpl $0x8, %eax
jne 0x1d662
movq %rbx, %rdi
callq 0x1e0ae
movw %ax, 0x20(%rbp)
movb $0x1, %bpl
jmp 0x1d746
leaq 0xc(%rsp), %rsi
movq %r15, %rdi
callq 0x3838
movswl %r13w, %ecx
movswl %r12w, %esi
cmpw %r12w, %r13w
jle 0x1d6cf
movzwl %r12w, %eax
shrl $0xf, %eax
addl %r12d, %eax
cwtl
shrl %eax
addw 0x20(%rbx), %ax
movzwl 0xc(%rsp), %edx
subl %eax, %edx
movw %dx, 0xc(%rsp)
movswl %dx, %edx
movswl 0x4(%rbp), %r8d
movswl 0x2(%rbp), %edi
movl %r8d, %eax
subl %edi, %eax
incl %eax
imull %edx, %eax
subl %esi, %ecx
cltd
idivl %ecx
addl %edi, %eax
jmp 0x1d70e
andb $-0x2, %r14b
cmpb $0xa, %r14b
jne 0x1d757
movzwl 0x20(%rbp), %eax
cmpl $0x8000, %eax           # imm = 0x8000
je 0x1d688
movswl %ax, %esi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x920b
movw $0x8000, 0x20(%rbp)     # imm = 0x8000
movq %rbx, %rdi
callq 0x4ed1
movq %rax, %rbx
movq %rax, %rdi
callq 0x2b0b
movl %eax, %ebp
callq 0x378a
movq %rax, %rdi
callq 0x3792
cmpb $0x4, %al
sete %al
andb %bpl, %al
movb $0x1, %bpl
cmpb $0x1, %al
jne 0x1d746
movq %rbx, %rdi
xorl %esi, %esi
callq 0x27a6
jmp 0x1d746
movzwl %r13w, %eax
shrl $0xf, %eax
addl %r13d, %eax
cwtl
shrl %eax
movzwl 0xe(%rsp), %edx
addw 0x22(%rbx), %ax
subl %eax, %edx
movw %dx, 0xe(%rsp)
movswl %dx, %edx
movswl 0x4(%rbp), %r8d
movswl 0x2(%rbp), %edi
movl %r8d, %eax
subl %edi, %eax
incl %eax
imull %edx, %eax
subl %ecx, %esi
cltd
idivl %esi
movl %eax, %ecx
movl %r8d, %eax
subl %ecx, %eax
movq %rbp, %rcx
cmpw %r8w, %ax
cmovll %eax, %r8d
cmpw %di, %ax
cmovgel %r8d, %edi
movb $0x1, %bpl
cmpw 0x20(%rcx), %di
je 0x1d746
movw %di, 0x20(%rcx)
movq %rbx, %rdi
callq 0x4c4d
movq %rbx, %rdi
movl $0xe, %esi
xorl %edx, %edx
callq 0x5018
movl %eax, %ebp
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbp, %r14
movb $0x1, %bpl
cmpl $0x11, %eax
jg 0x1d7d9
cmpl $0x2, %eax
je 0x1d7f0
cmpl $0x6, %eax
jne 0x1d746
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1e148
movq %rax, 0x10(%rsp)
movq %rbx, %rdi
movl $0x2, %esi
callq 0x1e148
movzwl 0x12(%rax), %eax
testb $0x1, 0x22(%r14)
jne 0x1d858
movzwl %r13w, %ecx
shrl $0xf, %ecx
addl %r13d, %ecx
movswl %cx, %ecx
shrl %ecx
movzwl %r12w, %edx
shrl $0xf, %edx
addl %r12d, %edx
movswl %dx, %edx
shrl %edx
cmpw %dx, %cx
cmovll %ecx, %edx
addl %edx, %eax
incl %eax
cmpw %ax, 0x5c(%rbx)
jge 0x1d746
movw %ax, 0x5c(%rbx)
jmp 0x1d746
cmpl $0x12, %eax
je 0x1d837
cmpl $0x13, %eax
jne 0x1d746
movb $0x1, (%r15)
jmp 0x1d746
movq %rbx, %rdi
callq 0x566d
movzwl 0x4(%r15), %ecx
subw (%r15), %cx
incl %ecx
cmpw %cx, %ax
jne 0x1d825
movq %rbx, %rdi
callq 0x5697
movzwl 0x6(%r15), %ecx
subw 0x2(%r15), %cx
incl %ecx
cmpw %cx, %ax
je 0x1d746
movq %rbx, %rdi
movl $0x6, %esi
xorl %edx, %edx
callq *0x30(%rbx)
jmp 0x1d746
movzbl (%r15), %eax
movw $0x8000, 0x20(%r14)     # imm = 0x8000
movl %eax, %ecx
andb $-0x3, %cl
cmpb $0x11, %cl
jne 0x1d8b4
movq %rbx, %rdi
callq 0x1e0ae
incl %eax
jmp 0x1d8cc
movq 0x10(%rsp), %rcx
movq 0x16(%rcx), %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, %ecx
testw %cx, %cx
cmovsl %ecx, %r15d
negl %r15d
movl 0x5c(%rbx), %ecx
cmpw %r15w, %cx
cmovgl %ecx, %r15d
setl %cl
cmpw %ax, %r15w
setl %dl
orb %cl, %dl
je 0x1d746
cmpw %ax, %r15w
cmovgl %r15d, %eax
movw %ax, 0x5c(%rbx)
jmp 0x1d746
cmpl $0x14, %eax
je 0x1d8c2
cmpl $0x12, %eax
jne 0x1d746
movq %rbx, %rdi
callq 0x1e0ae
decl %eax
movswl %ax, %esi
movq %rbx, %rdi
movl $0x1, %edx
callq 0x920b
jmp 0x1d735