// File: /workspace/github_c_makefile_star2_O1/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, %r12
movl %esi, %r15d
movq %rdi, %r14
callq *0x43651(%rip)          # 0x603e0
movl %eax, %ebx
cmpb $0x1, %al
jne 0x1cf5a
cmpb $0x7, %r15b
jne 0x1cdbc
leaq 0x22a41(%rip), %rsi     # 0x3f7e7
movq %r12, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6bf5
movq %r14, %rdi
callq 0x6ad8
movq %rax, 0x10(%rsp)
movq %r14, %rdi
callq 0x5651
movl %eax, %r13d
movq %r14, %rdi
callq 0x567b
movl %eax, %ebp
cmpb $0x9, %r15b
je 0x1ce03
movzbl %r15b, %eax
cmpl $0x8, %eax
jne 0x1ce64
movq %r14, %rdi
callq 0x1d8aa
movq 0x10(%rsp), %rcx
movw %ax, 0x20(%rcx)
jmp 0x1cf5a
leaq 0xc(%rsp), %rsi
movq %r12, %rdi
callq 0x3832
movswl %r13w, %esi
movswl %bp, %edi
cmpw %bp, %r13w
jle 0x1ced8
movl %edi, %eax
shrl $0x1f, %eax
addl %edi, %eax
shrl %eax
movzwl 0xc(%rsp), %ecx
addw 0x20(%r14), %ax
subl %eax, %ecx
movw %cx, 0xc(%rsp)
movswl %cx, %ecx
movq 0x10(%rsp), %r9
movswl 0x4(%r9), %eax
movswl 0x2(%r9), %r8d
subl %r8d, %eax
incl %eax
imull %ecx, %eax
subl %edi, %esi
cltd
idivl %esi
movl %eax, %ecx
addl %r8d, %ecx
jmp 0x1cf14
andb $-0x2, %r15b
cmpb $0xa, %r15b
jne 0x1cf6b
movq 0x10(%rsp), %r15
movzwl 0x20(%r15), %eax
cmpl $0x8000, %eax           # imm = 0x8000
je 0x1ce90
movswl %ax, %esi
movq %r14, %rdi
xorl %edx, %edx
callq 0x928d
movw $0x8000, 0x20(%r15)     # imm = 0x8000
movq %r14, %rdi
callq 0x4ea3
movq %rax, %r14
movq %rax, %rdi
callq 0x2b2b
movl %eax, %ebp
callq 0x3784
movq %rax, %rdi
callq 0x378c
cmpb $0x4, %al
sete %al
andb %bpl, %al
cmpb $0x1, %al
jne 0x1cf5a
movq %r14, %rdi
xorl %esi, %esi
callq 0x27ad
jmp 0x1cf5a
movl %esi, %eax
shrl $0x1f, %eax
addl %esi, %eax
shrl %eax
movzwl 0xe(%rsp), %ecx
addw 0x22(%r14), %ax
subl %eax, %ecx
movw %cx, 0xe(%rsp)
movswl %cx, %edx
movq 0x10(%rsp), %r9
movswl 0x4(%r9), %ecx
movswl 0x2(%r9), %eax
negl %eax
addl %ecx, %eax
incl %eax
imull %edx, %eax
subl %esi, %edi
cltd
idivl %edi
subl %eax, %ecx
movzwl 0x2(%r9), %eax
cmpw %ax, %cx
jl 0x1cf2a
movl 0x4(%r9), %eax
cmpw %ax, %cx
cmovgel %eax, %ecx
movl %ecx, %eax
cmpw 0x20(%r9), %ax
jne 0x1cf35
movb $0x1, %al
jmp 0x1cf58
movw %ax, 0x20(%r9)
movq %r14, %rdi
callq 0x4c36
movq %r14, %rdi
movl $0xe, %esi
xorl %edx, %edx
callq 0x4fea
movl %eax, %ebx
cmpb $0x1, %al
sete %al
testb %al, %al
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x11, %eax
jg 0x1cfe9
cmpl $0x2, %eax
je 0x1d001
cmpl $0x6, %eax
jne 0x1cf5a
xorl %r12d, %r12d
movq %r14, %rdi
xorl %esi, %esi
callq 0x1d944
movq %rax, %r15
movq %r14, %rdi
movl $0x2, %esi
callq 0x1d944
movzwl 0x12(%rax), %eax
movq 0x10(%rsp), %rcx
testb $0x1, 0x22(%rcx)
jne 0x1d073
movzwl %r13w, %ecx
shrl $0xf, %ecx
addl %r13d, %ecx
movswl %cx, %ecx
shrl %ecx
movzwl %bp, %edx
shrl $0xf, %edx
addl %ebp, %edx
movswl %dx, %edx
shrl %edx
cmpw %dx, %cx
cmovll %ecx, %edx
addl %edx, %eax
incl %eax
cmpw %ax, 0x5c(%r14)
jge 0x1cf5a
movw %ax, 0x5c(%r14)
jmp 0x1cf5a
cmpl $0x12, %eax
je 0x1d04d
cmpl $0x13, %eax
jne 0x1cf5a
movb $0x1, (%r12)
jmp 0x1cf5a
movq %r14, %rdi
callq 0x5651
movzwl 0x4(%r12), %ecx
subw (%r12), %cx
incl %ecx
cmpw %cx, %ax
jne 0x1d03a
movq %r14, %rdi
callq 0x567b
movzwl 0x6(%r12), %ecx
subw 0x2(%r12), %cx
incl %ecx
cmpw %cx, %ax
je 0x1cf5a
movq %r14, %rdi
movl $0x6, %esi
xorl %edx, %edx
callq *0x30(%r14)
jmp 0x1cf5a
movzbl (%r12), %eax
movq 0x10(%rsp), %rcx
movw $0x8000, 0x20(%rcx)     # imm = 0x8000
movl %eax, %ecx
andb $-0x3, %cl
cmpb $0x11, %cl
jne 0x1d0cc
movq %r14, %rdi
callq 0x1d8aa
incl %eax
jmp 0x1d0e0
movzwl 0x16(%r15), %ecx
movzwl 0x18(%r15), %edx
cmpw %dx, %cx
cmovll %ecx, %edx
movzwl 0x1a(%r15), %ecx
cmpw %cx, %dx
cmovgel %ecx, %edx
movzwl 0x1c(%r15), %ecx
cmpw %cx, %dx
cmovgel %ecx, %edx
testw %dx, %dx
cmovsl %edx, %r12d
movl %r12d, %ecx
negw %cx
cmovsw %r12w, %cx
cmpw %cx, 0x5c(%r14)
jge 0x1d0b7
movw %cx, 0x5c(%r14)
cmpw %ax, 0x5c(%r14)
jge 0x1cf5a
movw %ax, 0x5c(%r14)
jmp 0x1cf5a
cmpl $0x14, %eax
je 0x1d0d6
cmpl $0x12, %eax
jne 0x1d108
movq %r14, %rdi
callq 0x1d8aa
decl %eax
movswl %ax, %esi
movq %r14, %rdi
movl $0x1, %edx
callq 0x928d
xorl %r15d, %r15d
movq %r14, %rdi
movl $0xe, %esi
xorl %edx, %edx
callq 0x4fea
movl %eax, %ebx
cmpb $0x1, %al
jne 0x1d10b
movb $0x1, %r15b
testb %r15b, %r15b
jmp 0x1cf5a