-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfv_code_area_scroll.c
More file actions
94 lines (77 loc) · 2.86 KB
/
Copy pathfv_code_area_scroll.c
File metadata and controls
94 lines (77 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* FVCode - Fast and easy code editor
* Copyright (C) 2023-2024 FVCode Developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <fv/fv.h>
#include <config/config.h>
#include <fv/fv_component_code_area.h>
#include <fv/fv_component_lable.h>
#include <fv/fv_component_manager.h>
#include <fv/fv_component.h>
#include <fv/fv_collisions.h>
#include <fv/fv_string.h>
#include <fv/fv_drawing.h>
#include <fv/fv_font_manager.h>
#include <fv/fv_font_draw.h>
void
FV_ComponentCodeAreaHandleMouseWheel(fv_component_t* component, SDL_Event event)
{
GET_CODE_AREA(component);
const int change_view_line = abs(event.wheel.y);
if (event.wheel.y < 0)
{
for (i32 i = 0; i < change_view_line; i++)
FV_ComponentCodeAreaIncrementViewLine(component);
}
else if (event.wheel.y > 0)
{
for (i32 i = 0; i < change_view_line; i++)
FV_ComponentCodeAreaDecrementViewLine(component);
}
}
void
FV_ComponentCodeAreaIncrementViewLine(fv_component_t* component)
{
GET_CODE_AREA(component);
if (code_area->view_line != (code_area->splited_code->length - 1))
code_area->view_line++;
}
void
FV_ComponentCodeAreaDecrementViewLine(fv_component_t* component)
{
GET_CODE_AREA(component);
if (code_area->view_line != 0)
code_area->view_line--;
}
void
FV_ComponentCodeAreaRenderScrollBar(fv_component_t* component, fv_app_t* app)
{
GET_CODE_AREA(component);
i32 max_scroll_value = code_area->splited_code->length;
i32 scroll_bar_height = code_area->size.y;
i32 track_height = (scroll_bar_height / max_scroll_value) * 3;
f32 track_position = ((f32)code_area->view_line / (f32)max_scroll_value) * (f32)scroll_bar_height;
if (track_height < 4)
track_height = 4;
FV_DrawFillRect(app, FV_NewVector(code_area->pos.x + code_area->size.x - 5,
code_area->pos.y),
FV_NewVector(5, code_area->size.y),
code_area->border_color);
FV_DrawFillRect(app, FV_NewVector(code_area->pos.x + code_area->size.x - 5,
code_area->pos.y + (i32)track_position),
FV_NewVector(5, track_height),
code_area->scroll_bar_color);
}