Beispiel #1
0
bool MainWindow::trySave()
{
    if (mSavePath.isEmpty())
    {
        QString path = QFileDialog::getSaveFileName(this,tr("Save shaderprogram"),"",tr("OpenCraft shaderprogram (*.ocsp)"));
        if (path.isEmpty())
        {
            return false;
        }

        return saveShader(path);
    }
    return saveShader(mSavePath);
}
Beispiel #2
0
void MainWindow::actionSaveAs()
{
    QString path = QFileDialog::getSaveFileName(this,tr("Save shaderprogram"),"",tr("OpenCraft shaderprogram (*.ocsp)"));
    if (!path.isEmpty())
    {
        saveShader(path);
    }
}
Beispiel #3
0
void App::gui() {
	ImGuiIO& io = ImGui::GetIO();

	if (ImGui::BeginMainMenuBar()) {
		if (ImGui::BeginMenu("File")) {
			if (ImGui::MenuItem("New", io.OSXBehaviors ? "Cmd+N" : "Ctrl+N")) {
				newShader();
			}
			ImGui::Separator();
			if (ImGui::MenuItem("Open...", io.OSXBehaviors ? "Cmd+O" : "Ctrl+O")) {
				openShaderDialog();
			}
			if (ImGui::BeginMenu("Open Recent", !!recently_used_filepaths[most_recently_used_index])) {
				for (int i = 0; i < (int)ARRAY_COUNT(recently_used_filepaths); i++) {
					int index = (most_recently_used_index+i) % ARRAY_COUNT(recently_used_filepaths);
					if (recently_used_filepaths[index]) {
						char *menuitem_label = recently_used_filepaths[index];
						// we might include libgen.h and use basename(3) but there is no windows support...
						// TODO: test this on windows
						char *basename = strrchr(menuitem_label, '/');
						if (basename) menuitem_label = basename+1;
						if (ImGui::MenuItem(menuitem_label)) {
							loadShader(recently_used_filepaths[index]);
						}
						if (basename && ImGui::IsItemHovered()) {
							ImGui::SetTooltip("%s", recently_used_filepaths[index]);
						}
					} else break;
				}
				ImGui::Separator();
				if (ImGui::MenuItem("Clear Items")) {
					clearRecentlyUsedFilepaths();
				}
				ImGui::EndMenu();
			}
			// TODO: move this to settings pane eventually
			if (ImGui::MenuItem("Autoreload", nullptr, shader_file_autoreload)) {
				shader_file_autoreload = !shader_file_autoreload;
				writePreferences();
			}
			if (ImGui::MenuItem("Save", io.OSXBehaviors ? "Cmd+S" : "Ctrl+S", false, !!shader_filepath)) {
				saveShader();
			}
			if (ImGui::IsItemHovered() && shader_filepath) {
				ImGui::SetTooltip("%s", shader_filepath);
			}
			if (ImGui::MenuItem("Save As...", io.OSXBehaviors ? "Cmd+Shift+S" : "Ctrl+Shift+S", false, !!src_edit_buffer[0])) {
				saveShaderDialog();
			}
			ImGui::Separator();
			if (ImGui::MenuItem("Quit", io.OSXBehaviors ? "Cmd+Q" : "Ctrl+Q")) {
				quit = true;
			}
 			ImGui::EndMenu();
		}
		if (ImGui::BeginMenu("View")) {
			if (ImGui::MenuItem("Fullscreen", io.OSXBehaviors ? "Cmd+F" : "Ctrl+F", windowIsFullscreen())) {
				windowToggleFullscreen();
			}
			if (ImGui::MenuItem("Hide Controls", io.OSXBehaviors ? "Cmd+Shift+H" : "Ctrl+H", hide_gui)) {
				hide_gui = !hide_gui;
			}
			ImGui::Separator();
			if (ImGui::MenuItem(anim_play ? "Pause Animation" : "Play Animation", "Space")) {
				toggleAnimation();
			}
			if (ImGui::MenuItem("Reset Animation")) {
				frame_count = 0;
			}
			if (ImGui::MenuItem("Reset Camera")) {
				resetCamera();
			}
			ImGui::EndMenu();
		}
if (ImGui::BeginMenu("Tools")) {
	if (ImGui::MenuItem("Recompile Shader", io.OSXBehaviors ? "Cmd+B" : "Ctrl+B", false, !!src_edit_buffer[0])) {
		recompileShader();
	}
	ImGui::EndMenu();
}
if (ImGui::BeginMenu("Window")) {
	if (ImGui::MenuItem("Uniforms", io.OSXBehaviors ? "Cmd+1" : "Ctrl+1", show_uniforms_window)) {
		show_uniforms_window = !show_uniforms_window;
	}
	if (ImGui::MenuItem("Textures", io.OSXBehaviors ? "Cmd+2" : "Ctrl+2", show_textures_window)) {
		show_textures_window = !show_textures_window;
	}
	ImGui::Separator();
	if (ImGui::MenuItem("Camera", io.OSXBehaviors ? "Cmd+3" : "Ctrl+3", show_textures_window)) {
		show_camera_window = !show_camera_window;
	}
	ImGui::Separator();
	if (ImGui::MenuItem("Source editor", io.OSXBehaviors ? "Cmd+4" : "Ctrl+4", show_src_edit_window)) {
		show_src_edit_window = !show_src_edit_window;
	}
	ImGui::EndMenu();
}
ImGui::EndMainMenuBar();
	}

	if (show_uniforms_window) {
		if (ImGui::Begin("Uniforms", &show_uniforms_window)) {
			if (ImGui::CollapsingHeader("Built-in uniform names")) {
				ImGui::InputText("Time", u_time_name, sizeof(u_time_name));
				ImGui::InputText("Resolution", u_resolution_name, sizeof(u_resolution_name));
				ImGui::InputText("View to World Matrix", u_view_to_world_name, sizeof(u_view_to_world_name));
				ImGui::InputText("World to View Matrix", u_world_to_view_name, sizeof(u_world_to_view_name));
			}
			ImGui::Separator();

			if (!compile_error_log) {
				ImGui::AlignFirstTextHeightToWidgets();
				ImGui::Text("Data"); ImGui::SameLine();
				if (ImGui::Button("Clear")) {
					if (uniform_data) {
						memset(uniform_data, 0, uniform_data_size);
					}
				} ImGui::SameLine();
				if (ImGui::Button("Save")) {
					writeUniformData();
				} ImGui::SameLine();
				if (ImGui::Button("Load")) {
					readUniformData();
				}
				for (int i = 0; i < uniform_count; i++) {
					// skip builtin uniforms
					if (!strcmp(u_time_name, uniforms[i].name)) continue;
					if (!strcmp(u_resolution_name, uniforms[i].name)) continue;
					if (!strcmp(u_view_to_world_name, uniforms[i].name)) continue;
					if (!strcmp(u_world_to_view_name, uniforms[i].name)) continue;
					uniforms[i].gui();
				}
			}
		}
		ImGui::End();
	}

	if (show_textures_window) {
		if (ImGui::Begin("Textures", &show_textures_window)) {
			ImGui::Columns(2);
			for (int tsi = 0; tsi < (int)ARRAY_COUNT(texture_slots); tsi++) {
				TextureSlot *texture_slot = texture_slots + tsi;

				ImGui::BeginGroup();
				ImGui::PushID(tsi);
				ImGui::Text("%d:", tsi);
				ImGui::SameLine();
				ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor::HSV(0.0f, 0.6f, 0.6f));
				ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::HSV(0.0f, 0.7f, 0.7f));
				ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::HSV(0.0f, 0.8f, 0.8f));
				if (ImGui::SmallButton("x")) texture_slot->clear();
				ImGui::PopStyleColor(3);
				if (ImGui::Button(" 2D ")) openImageDialog(texture_slot);
				if (ImGui::Button("Cube")) openImageDialog(texture_slot, /*load_cube_cross*/true);
				ImGui::PopID();
				ImGui::EndGroup();

				ImGui::SameLine();
				//ImTextureID im_tex_id = (ImTextureID)(intptr_t)texture_slot->texture;
				ImGui::Image((void*)texture_slot, ImVec2(64, 64));
				if (ImGui::IsItemHovered() && texture_slot->image_filepath) {
					ImGui::SetTooltip("%s\n%dx%d", texture_slot->image_filepath,
						texture_slot->image_width, texture_slot->image_height);
				}

				if ((tsi & 1) && tsi + 1 != ARRAY_COUNT(texture_slots)) {
					ImGui::Separator();
				}
				else {
					ImGui::SameLine(); ImGui::Spacing();
				}
				ImGui::NextColumn();
			}
			ImGui::Columns(1);
		}
		ImGui::End();
	}

	if (show_camera_window) {
		if (ImGui::Begin("Camera", &show_camera_window)) {
			ImGui::DragFloat3("Location", camera_location.e);
			ImGui::SliderAngle("Pitch", &camera_euler_angles.x);
			ImGui::SliderAngle("Yaw", &camera_euler_angles.y);
			ImGui::SliderAngle("Roll", &camera_euler_angles.z);
			if (ImGui::Button("Reset")) resetCamera();
			ImGui::End();
		}
	}

	if (show_src_edit_window) {
		if (ImGui::Begin("Source editor", &show_src_edit_window)) {
			// TODO: add horizontal scrollbar
			ImGui::InputTextMultiline("##Text buffer", src_edit_buffer, sizeof(src_edit_buffer)-1,
				/*fullwidth, fullheight*/ImVec2(-1.0f, -1.0f), ImGuiInputTextFlags_AllowTabInput);
		}
		ImGui::End();
	}

	// overlay messages
	int overlay_flags = ImGuiWindowFlags_NoTitleBar
		| ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize
		| ImGuiWindowFlags_NoBringToFrontOnFocus
		| ImGuiWindowFlags_NoMove
		| ImGuiWindowFlags_NoSavedSettings;
	if (!shader_filepath && !src_edit_buffer[0]) {
		ImGui::SetNextWindowPosCenter();
		ImGui::Begin("Overlay", nullptr, ImVec2(0, 0), 0.3f, overlay_flags);
		ImGui::AlignFirstTextHeightToWidgets(); // valign text to button
		ImGui::Text("No fragment shader");
		ImGui::SameLine();
		if (ImGui::Button("Open")) openShaderDialog();
		ImGui::SameLine();
		if (ImGui::Button("New")) newShader();
		ImGui::End();
	} else if (compile_error_log) {
		ImGui::SetNextWindowPosCenter();
		ImGui::Begin("Overlay", nullptr, ImVec2(0, 0), 0.3f, overlay_flags);
		ImGui::TextUnformatted(compile_error_log);
		ImGui::End();
	}
}