Skip to content

Commit

Permalink
help text
Browse files Browse the repository at this point in the history
  • Loading branch information
hannorein committed Nov 9, 2023
1 parent e4d12d4 commit 3aae860
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 14 deletions.
38 changes: 31 additions & 7 deletions src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,20 @@ EM_JS(void, reb_overlay_update, (const char* text, int status), {
overlay.style.backgroundColor = "rgba(0, 0, 0, 0.5)";
}
}

});
EM_JS(void, reb_overlay_help_set_text, (const char* text), {
var overlaytext = document.getElementById("overlaytext-help");
if (overlaytext){
overlaytext.innerHTML = UTF8ToString(text);
}
});
EM_JS(void, reb_overlay_help_hide, (int hide), {
var overlay = document.getElementById("overlay-help");
if (hide){
overlay.style.display = "none";
}else{
overlay.style.display = "block";
}
});
EM_JS(void, reb_overlay_hide, (int hide), {
var overlay = document.getElementById("overlay");
Expand All @@ -102,7 +115,7 @@ void reb_render_frame(void* p);
static void reb_display_set_default_scale(struct reb_simulation* const r);

static const char* onscreenhelp[] = {
"REBOUND OPENGL mouse and keyboard commands",
"REBOUND mouse and keyboard commands",
"----------------------------------------------------",
" To rotate the view, simply drag the simulation",
" with the mouse. To zoom in, press the shift key ",
Expand All @@ -124,7 +137,7 @@ static const char* onscreenhelp[] = {
" c | Toggle clear screen after each time-step",
" m | Toggle multisampling",
" w | Draw orbits as wires",
" t | Show/hide logo, time, timestep and number ",
" t | Show/hide logo, time, timestep and number",
" | of particles.",
"----------------------------------------------------"
};
Expand Down Expand Up @@ -378,7 +391,8 @@ void reb_display_keyboard(GLFWwindow* window, int key, int scancode, int action,
if (data->r->status == REB_STATUS_PAUSED){
printf("Resume.\n");
data->r->status = REB_STATUS_RUNNING;
}else{
}
if (data->r->status == REB_STATUS_RUNNING || data->r->status == REB_STATUS_LAST_STEP){
printf("Pause.\n");
data->r->status = REB_STATUS_PAUSED;
}
Expand Down Expand Up @@ -701,7 +715,6 @@ void reb_render_frame(void* p){
glBindVertexArray(0);
glBindTexture(GL_TEXTURE_2D,0);
}
#endif // __EMSCRIPTEN__
if (data->onscreenhelp){ // On screen help
glUseProgram(data->simplefont_shader_program);
glBindVertexArray(data->simplefont_shader_vao);
Expand All @@ -720,6 +733,7 @@ void reb_render_frame(void* p){
reb_glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, j);
}
}
#endif // __EMSCRIPTEN__

glfwSwapBuffers(data->window);
glfwPollEvents();
Expand All @@ -746,7 +760,7 @@ EM_BOOL reb_render_frame_emscripten(double time, void* p){
}else if (data->r_copy->status == REB_STATUS_PAUSED){
sprintf(line, "Simulation is paused<br />");
}else if (data->r_copy->status == REB_STATUS_SUCCESS){
sprintf(line, "Simulation finished<br />");
sprintf(line, "Simulation ready<br />");
}else if (data->r_copy->status > 0){
sprintf(line, "Simulation error occured<br />");
}
Expand All @@ -757,13 +771,23 @@ EM_BOOL reb_render_frame_emscripten(double time, void* p){
strlcat(str, line, 10240);
sprintf(line, "steps/s = %g<br />",1./data->r_copy->walltime_last_steps);
strlcat(str, line, 10240);
strlcat(str, "Press h for help.<br />", 10240);
reb_overlay_update(str, data->r_copy->status);
}else{
sprintf(line, "Unable to connect to server. Server might have shut down.");
sprintf(line, "Unable to connect. Server might have shut down.");
strlcat(str, line, 10240);
reb_overlay_update(str, 10);
}
}
reb_overlay_help_hide(!data->onscreenhelp);
if (data->onscreenhelp){
char str[10240] = "\0";
for (int i=0;i<sizeof(onscreenhelp)/sizeof(onscreenhelp[0]);i++){
strlcat(str, onscreenhelp[i], 10240);
strlcat(str, "<br />", 10240);
reb_overlay_help_set_text(str);
}
}
}
return EM_TRUE;
}
Expand Down
2 changes: 1 addition & 1 deletion src/rebound.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ void reb_simulation_init(struct reb_simulation* r){
r->exit_max_distance = 0;
r->max_radius0 = 0.;
r->max_radius1 = 0.;
r->status = REB_STATUS_RUNNING;
r->status = REB_STATUS_SUCCESS;
r->exact_finish_time = 1;
r->force_is_velocity_dependent = 0;
r->gravity_ignore_terms = 0;
Expand Down
33 changes: 27 additions & 6 deletions web_client/shell_rebound.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,42 @@
overflow: hidden;
display: block;
}
#overlay {
#overlay, #overlay-help {
container-type: inline-size;
width: 2em;
position: absolute;
padding: 5px;
color: #fff;
top: 5px;
left: 5px;
z-index: 10;
border-radius: 5px;
border: solid 1px;
resize: horizontal;
overflow: hidden;
font-size: 7cqw;
font-family: 'Lucida Console', Monaco, monospace;
}
#overlay {
top: 5px;
width: 2em;
left: 5px;
z-index: 10;
font-size: 7cqw;
}
#overlay-help {
top: 50%;
width: 10em;
left: 50%;
transform:translate(-50%, -50%);
z-index: 20;
font-size: 3.2cqw;
display: none;
}

#overlaytext {
font-size: 7cqw;
}
#overlaytext-help {
white-space: pre-wrap;
font-size: 3.2cqw;
background-color: rgba(0, 0, 0, 0.5);
}


</style>
Expand All @@ -94,6 +111,10 @@
REBOUND
</div>
</div>
<div id="overlay-help">
<div id="overlaytext-help">
</div>
</div>
</div>
<textarea id="output" rows="8"></textarea>

Expand Down

0 comments on commit 3aae860

Please sign in to comment.