Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mandelbrot-explorer
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ильин Владимир Александрович
mandelbrot-explorer
Commits
918d2bd6
Commit
918d2bd6
authored
Jun 26, 2025
by
Ильин Владимир Александрович
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more info in ui and print view info on exit
parent
6cc918c0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
15 deletions
+53
-15
mandelbrot.c
src/mandelbrot.c
+16
-9
ui.c
src/ui.c
+30
-4
ui.h
src/ui.h
+7
-2
No files found.
src/mandelbrot.c
View file @
918d2bd6
...
...
@@ -241,16 +241,16 @@ parse_opt (int key, char *arg, struct argp_state *state)
break
;
case
'a'
:
arguments
->
x_max
=
ato
i
(
arg
);
arguments
->
x_max
=
ato
f
(
arg
);
break
;
case
'b'
:
arguments
->
x_min
=
ato
i
(
arg
);
arguments
->
x_min
=
ato
f
(
arg
);
break
;
case
'c'
:
arguments
->
y_max
=
ato
i
(
arg
);
arguments
->
y_max
=
ato
f
(
arg
);
break
;
case
'd'
:
arguments
->
y_min
=
ato
i
(
arg
);
arguments
->
y_min
=
ato
f
(
arg
);
break
;
case
'z'
:
arguments
->
zoom
=
atof
(
arg
);
...
...
@@ -358,10 +358,10 @@ main(int argc, char **argv)
ViewInfo
view
=
{
.
x_min
=
args
.
x_min
*
args
.
zoom
,
.
x_max
=
args
.
x_max
*
args
.
zoom
,
.
y_min
=
args
.
y_min
*
args
.
zoom
,
.
y_max
=
args
.
y_max
*
args
.
zoom
,
.
x_min
=
args
.
x_min
,
.
x_max
=
args
.
x_max
,
.
y_min
=
args
.
y_min
,
.
y_max
=
args
.
y_max
,
.
zoom
=
args
.
zoom
};
...
...
@@ -520,7 +520,7 @@ main(int argc, char **argv)
fps
=
1000
.
0
/
(
double
)
msec
;
if
(
app
.
draw_ui
)
render_ui
(
&
ui
,
app
.
renderer
,
view
,
fps
);
render_ui
(
&
ui
,
app
.
renderer
,
view
,
fps
,
app
.
win_width
,
app
.
win_height
,
screen
.
size
);
SDL_RenderPresent
(
app
.
renderer
);
}
...
...
@@ -530,4 +530,11 @@ main(int argc, char **argv)
SDL_DestroyRenderer
(
app
.
renderer
);
SDL_DestroyWindow
(
app
.
window
);
SDL_Quit
();
printf
(
"To recreate last image add those arguments to program next time:
\n
"
"--x_min %lf --x_max %lf --y_min %lf --y_max %lf --zoom %lf "
"--width %u --height %u --iterations %u
\n
"
,
view
.
x_min
,
view
.
x_max
,
view
.
y_min
,
view
.
y_max
,
view
.
zoom
,
app
.
win_width
,
app
.
win_height
,
args
.
max_iterations
);
}
src/ui.c
View file @
918d2bd6
#include "ui.h"
#include <SDL2/SDL_render.h>
void
render_text
(
SDL_Renderer
*
renderer
,
TTF_Font
*
font
,
const
char
*
text
,
SDL_Rect
*
rect
)
{
...
...
@@ -26,34 +27,59 @@ init_ui(UI* ui)
ui
->
fps_display
=
(
SDL_Rect
){
UI_PADDING
,
UI_PADDING
*
2
+
BUTTON_HEIGHT
,
BUTTON_WIDTH
,
BUTTON_HEIGHT
};
ui
->
window_size
=
(
SDL_Rect
){
UI_PADDING
,
UI_PADDING
*
3
+
2
*
BUTTON_HEIGHT
,
BUTTON_WIDTH
,
BUTTON_HEIGHT
};
ui
->
x_cords
=
(
SDL_Rect
){
UI_PADDING
,
UI_PADDING
*
4
+
3
*
BUTTON_HEIGHT
,
BUTTON_WIDTH
,
BUTTON_HEIGHT
};
ui
->
y_cords
=
(
SDL_Rect
){
UI_PADDING
,
UI_PADDING
*
5
+
4
*
BUTTON_HEIGHT
,
BUTTON_WIDTH
,
BUTTON_HEIGHT
};
TTF_Init
();
//ui->font = TTF_OpenFont("/System/Library/Fonts/Monaco.ttf", FONT_SIZE);
//ui->font = TTF_OpenFont("C:/Windows/Fonts/arial.ttf", FONT_SIZE);
ui
->
font
=
TTF_OpenFont
(
"/usr/share/fonts/nerdfonts/TerminessNerdFont-Regular.ttf"
,
FONT_SIZE
);
if
(
!
ui
->
font
)
{
printf
(
"Font
yüklenemedi
: %s
\n
"
,
TTF_GetError
());
printf
(
"Font
not found!
: %s
\n
"
,
TTF_GetError
());
}
}
void
render_ui
(
UI
*
ui
,
SDL_Renderer
*
renderer
,
ViewInfo
view
,
float
fps
)
render_ui
(
UI
*
ui
,
SDL_Renderer
*
renderer
,
ViewInfo
view
,
float
fps
,
unsigned
short
win_width
,
unsigned
short
win_height
,
int
arr_size
)
{
SDL_SetRenderDrawColor
(
renderer
,
60
,
60
,
60
,
UI_ALPHA
);
SDL_RenderFillRect
(
renderer
,
&
ui
->
zoom_display
);
SDL_RenderFillRect
(
renderer
,
&
ui
->
fps_display
);
SDL_RenderFillRect
(
renderer
,
&
ui
->
window_size
);
SDL_RenderFillRect
(
renderer
,
&
ui
->
x_cords
);
SDL_RenderFillRect
(
renderer
,
&
ui
->
y_cords
);
SDL_SetRenderDrawColor
(
renderer
,
255
,
255
,
255
,
UI_ALPHA
);
SDL_RenderDrawRect
(
renderer
,
&
ui
->
zoom_display
);
SDL_RenderDrawRect
(
renderer
,
&
ui
->
fps_display
);
SDL_RenderDrawRect
(
renderer
,
&
ui
->
window_size
);
SDL_RenderDrawRect
(
renderer
,
&
ui
->
x_cords
);
SDL_RenderDrawRect
(
renderer
,
&
ui
->
y_cords
);
if
(
ui
->
font
)
{
char
buf
[
16
];
char
buf
[
24
];
snprintf
(
buf
,
sizeof
(
buf
),
"Zoom %.3gx"
,
view
.
zoom
);
render_text
(
renderer
,
ui
->
font
,
buf
,
&
ui
->
zoom_display
);
snprintf
(
buf
,
sizeof
(
buf
),
"Fps %.2f"
,
fps
);
render_text
(
renderer
,
ui
->
font
,
buf
,
&
ui
->
fps_display
);
snprintf
(
buf
,
sizeof
(
buf
),
"%ux%u; arr:%d"
,
win_width
,
win_height
,
arr_size
);
render_text
(
renderer
,
ui
->
font
,
buf
,
&
ui
->
window_size
);
snprintf
(
buf
,
sizeof
(
buf
),
"x:(%lf %lf)"
,
view
.
x_min
,
view
.
x_max
);
render_text
(
renderer
,
ui
->
font
,
buf
,
&
ui
->
x_cords
);
snprintf
(
buf
,
sizeof
(
buf
),
"y:(%lf %lf)"
,
view
.
y_min
,
view
.
y_max
);
render_text
(
renderer
,
ui
->
font
,
buf
,
&
ui
->
y_cords
);
}
}
...
...
src/ui.h
View file @
918d2bd6
...
...
@@ -6,7 +6,7 @@
#include "mouse.h"
#include "mandelbrot.h"
#define BUTTON_WIDTH 1
2
0
#define BUTTON_WIDTH 1
9
0
#define BUTTON_HEIGHT 30
#define PREVIEW_SIZE 200
#define UI_PADDING 10
...
...
@@ -17,11 +17,16 @@
typedef
struct
{
SDL_Rect
zoom_display
;
SDL_Rect
fps_display
;
SDL_Rect
window_size
;
SDL_Rect
x_cords
;
SDL_Rect
y_cords
;
TTF_Font
*
font
;
}
UI
;
void
init_ui
(
UI
*
ui
);
void
render_ui
(
UI
*
ui
,
SDL_Renderer
*
renderer
,
ViewInfo
view
,
float
fps
);
void
render_ui
(
UI
*
ui
,
SDL_Renderer
*
renderer
,
ViewInfo
view
,
float
fps
,
unsigned
short
win_width
,
unsigned
short
win_height
,
int
arr_size
);
int
handle_ui_event
(
UI
*
ui
,
SDL_Event
event
,
ViewInfo
*
view
);
void
cleanup_ui
(
UI
*
ui
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment