void NexusGroup::WriteGroup (NXhandle file_handle, long int compression_scheme) { NexusGroup *current_group; NexusField *current_field; try { MakeGroup (name, type, file_handle); OpenGroup (name, type, file_handle); current_field = field_list; while (current_field != NULL) { current_field->WriteField (file_handle, compression_scheme); current_field = current_field->NextField (); } current_group = subgroup_list; while (current_group != NULL) { current_group->WriteGroup (file_handle, compression_scheme); current_group = current_group->NextGroup (); } CloseGroup (file_handle); } catch (...) { throw; } }
const std::string LZ77::Compress() { std::string result = ""; // While there is characters left to handle while(!m_lookahead.empty()) { CodeGroup code_group; code_group.next_char = m_lookahead.front(); // Looking for the start of a match for(unsigned i = 0; i < m_history.size(); i++) { // If we find a beginning of a match if(m_lookahead.front() == m_history.at(i)) { // Find the length of the match unsigned current = GetMatchLength(i); // If the match is the longest for the current lookahead if(current > code_group.length) { // Create the group MakeGroup(code_group, current, i); } } } // Save the longest group to result result.append(code_group.ToString()); // Move the lookahead and sliding-history buffer MoveBuffers(code_group.length); } return result; }
HaloExample(void) : make_shape() , shape_indices(make_shape.Indices()) , shape_instr(make_shape.Instructions()) , vs_shape(ObjectDesc("Shape VS")) , vs_plane(ObjectDesc("Plane VS")) , fs_shape(ObjectDesc("Shape FS")) , fs_plane(ObjectDesc("Plane FS")) , vs_halo(ObjectDesc("Halo VS")) , gs_halo(ObjectDesc("Halo GS")) , fs_halo(ObjectDesc("Halo FS")) , shape_projection_matrix(shape_prog, "ProjectionMatrix") , shape_camera_matrix(shape_prog, "CameraMatrix") , shape_model_matrix(shape_prog, "ModelMatrix") , plane_projection_matrix(plane_prog, "ProjectionMatrix") , plane_camera_matrix(plane_prog, "CameraMatrix") , halo_projection_matrix(halo_prog, "ProjectionMatrix") , halo_camera_matrix(halo_prog, "CameraMatrix") , halo_model_matrix(halo_prog, "ModelMatrix") { vs_shape.Source( "#version 140\n" "in vec4 Position;" "in vec3 Normal;" "uniform mat4 ProjectionMatrix, CameraMatrix, ModelMatrix;" "uniform vec3 LightPos;" "out vec3 vertNormal;" "out vec3 vertViewNormal;" "out vec3 vertLight;" "void main(void)" "{" " gl_Position = ModelMatrix * Position;" " vertNormal = mat3(ModelMatrix)*Normal;" " vertViewNormal = mat3(CameraMatrix)*vertNormal;" " vertLight = LightPos - gl_Position.xyz;" " gl_Position = ProjectionMatrix * CameraMatrix * gl_Position;" "}" ); vs_shape.Compile(); fs_shape.Source( "#version 140\n" "in vec3 vertNormal;" "in vec3 vertViewNormal;" "in vec3 vertLight;" "uniform mat4 CameraMatrix;" "out vec4 fragColor;" "void main(void)" "{" " float ltlen = sqrt(length(vertLight));" " float ltexp = dot(" " normalize(vertNormal)," " normalize(vertLight)" " );" " float lview = dot(" " normalize(vertLight)," " normalize(vec3(" " CameraMatrix[0][2]," " CameraMatrix[1][2]," " CameraMatrix[2][2] " " ))" " );" " float depth = normalize(vertViewNormal).z;" " vec3 ftrefl = vec3(0.9, 0.8, 0.7);" " vec3 scatter = vec3(0.9, 0.6, 0.1);" " vec3 bklt = vec3(0.8, 0.6, 0.4);" " vec3 ambient = vec3(0.5, 0.4, 0.3);" " fragColor = vec4(" " pow(max(ltexp, 0.0), 8.0)*ftrefl+" " ( ltexp+1.0)/ltlen*pow(depth,2.0)*scatter+" " (-ltexp+1.0)/ltlen*(1.0-depth)*scatter+" " (-lview+1.0)*0.6*(1.0-abs(depth))*bklt+" " 0.2*ambient," " 1.0" " );" "}" ); fs_shape.Compile(); shape_prog.AttachShader(vs_shape); shape_prog.AttachShader(fs_shape); shape_prog.Link(); vs_plane.Source( "#version 140\n" "in vec4 Position;" "in vec3 Normal;" "uniform mat4 ProjectionMatrix, CameraMatrix;" "uniform vec3 LightPos;" "out vec3 vertNormal;" "out vec3 vertLight;" "void main(void)" "{" " gl_Position = " " ProjectionMatrix *" " CameraMatrix *" " Position;" " vertNormal = Normal;" " vertLight = LightPos-Position.xyz;" "}" ); vs_plane.Compile(); fs_plane.Source( "#version 140\n" "in vec3 vertNormal;" "in vec3 vertLight;" "out vec4 fragColor;" "void main(void)" "{" " float l = sqrt(length(vertLight));" " float e = dot(" " vertNormal," " normalize(vertLight)" " );" " float d = l > 0.0 ? e / l : 0.0;" " float i = 0.2 + 2.5 * d;" " fragColor = vec4(0.8*i, 0.7*i, 0.4*i, 1.0);" "}" ); fs_plane.Compile(); plane_prog.AttachShader(vs_plane); plane_prog.AttachShader(fs_plane); plane_prog.Link(); vs_halo.Source( "#version 150\n" "in vec4 Position;" "in vec3 Normal;" "uniform mat4 ModelMatrix, CameraMatrix;" "out vec3 vertNormal;" "out float vd;" "void main(void)" "{" " gl_Position = " " CameraMatrix *" " ModelMatrix *" " Position;" " vertNormal = (" " CameraMatrix *" " ModelMatrix *" " vec4(Normal, 0.0)" " ).xyz;" " vd = vertNormal.z;" "}" ); vs_halo.Compile(); gs_halo.Source( "#version 150\n" "layout(triangles) in;" "layout(triangle_strip, max_vertices = 12) out;" "in vec3 vertNormal[];" "in float vd[];" "uniform mat4 CameraMatrix, ProjectionMatrix;" "uniform vec3 LightPos;" "out float geomAlpha;" "void main(void)" "{" " for(int v=0; v!=3; ++v)" " {" " int a = v, b = (v+1)%3, c = (v+2)%3;" " vec4 pa = gl_in[a].gl_Position;" " vec4 pb = gl_in[b].gl_Position;" " vec4 pc = gl_in[c].gl_Position;" " vec4 px, py;" " vec3 na = vertNormal[a];" " vec3 nb = vertNormal[b];" " vec3 nc = vertNormal[c];" " vec3 nx, ny;" " if(vd[a] == 0.0 && vd[b] == 0.0)" " {" " px = pa;" " nx = na;" " py = pb;" " ny = nb;" " }" " else if(vd[a] > 0.0 && vd[b] < 0.0)" " {" " float x = vd[a]/(vd[a]-vd[b]);" " float y;" " px = mix(pa, pb, x);" " nx = mix(na, nb, x);" " if(vd[c] < 0.0)" " {" " y = vd[a]/(vd[a]-vd[c]);" " py = mix(pa, pc, y);" " ny = mix(na, nc, y);" " }" " else" " {" " y = vd[c]/(vd[c]-vd[b]);" " py = mix(pc, pb, y);" " ny = mix(nc, nb, y);" " }" " }" " else continue;" " vec4 gx1 = vec4(px.xyz, 1.0);" " vec4 gy1 = vec4(py.xyz, 1.0);" " vec4 gx2 = vec4(px.xyz + nx*0.3, 1.0);" " vec4 gy2 = vec4(py.xyz + ny*0.3, 1.0);" " gl_Position = ProjectionMatrix * gy1;" " geomAlpha = 1.0;" " EmitVertex();" " gl_Position = ProjectionMatrix * gx1;" " geomAlpha = 1.0;" " EmitVertex();" " gl_Position = ProjectionMatrix * gy2;" " geomAlpha = 0.0;" " EmitVertex();" " gl_Position = ProjectionMatrix * gx2;" " geomAlpha = 0.0;" " EmitVertex();" " EndPrimitive();" " break;" " }" "}" ); gs_halo.Compile(); fs_halo.Source( "#version 150\n" "in float geomAlpha;" "out vec4 fragColor;" "void main(void)" "{" " fragColor = vec4(" " 0.5, 0.4, 0.3," " pow(geomAlpha, 2.0)" " );" "}" ); fs_halo.Compile(); halo_prog.AttachShader(vs_halo); halo_prog.AttachShader(gs_halo); halo_prog.AttachShader(fs_halo); halo_prog.Link(); // bind the VAO for the shape shape.Bind(); // bind the VBO for the shape vertices shape_verts.Bind(Buffer::Target::Array); { std::vector<GLfloat> data; GLuint n_per_vertex = make_shape.Positions(data); Buffer::Data(Buffer::Target::Array, data); VertexAttribSlot location; if(VertexArrayAttrib::QueryCommonLocation( MakeGroup(shape_prog, halo_prog), "Position", location )) { VertexArrayAttrib attr(location); attr.Setup<GLfloat>(n_per_vertex); attr.Enable(); } else OGLPLUS_ABORT("Inconsistent 'Position' location"); } // bind the VBO for the shape normals shape_normals.Bind(Buffer::Target::Array); { std::vector<GLfloat> data; GLuint n_per_vertex = make_shape.Normals(data); Buffer::Data(Buffer::Target::Array, data); shape_prog.Use(); VertexArrayAttrib attr(shape_prog, "Normal"); attr.Setup<GLfloat>(n_per_vertex); attr.Enable(); } // bind the VAO for the plane plane.Bind(); // bind the VBO for the plane vertices plane_verts.Bind(Buffer::Target::Array); { GLfloat data[4*3] = { -9.0f, 0.0f, 9.0f, -9.0f, 0.0f, -9.0f, 9.0f, 0.0f, 9.0f, 9.0f, 0.0f, -9.0f }; Buffer::Data(Buffer::Target::Array, 4*3, data); plane_prog.Use(); VertexArrayAttrib attr(plane_prog, "Position"); attr.Setup<Vec3f>(); attr.Enable(); } // bind the VBO for the plane normals plane_normals.Bind(Buffer::Target::Array); { GLfloat data[4*3] = { -0.1f, 1.0f, 0.1f, -0.1f, 1.0f, -0.1f, 0.1f, 1.0f, 0.1f, 0.1f, 1.0f, -0.1f }; Buffer::Data(Buffer::Target::Array, 4*3, data); plane_prog.Use(); VertexArrayAttrib attr(plane_prog, "Normal"); attr.Setup<Vec3f>(); attr.Enable(); } Vec3f lightPos(2.0f, 2.5f, 9.0f); ProgramUniform<Vec3f>(shape_prog, "LightPos").Set(lightPos); ProgramUniform<Vec3f>(plane_prog, "LightPos").Set(lightPos); gl.ClearColor(0.2f, 0.2f, 0.2f, 0.0f); gl.ClearDepth(1.0f); gl.ClearStencil(0); gl.Enable(Capability::DepthTest); gl.BlendFunc(BlendFn::SrcAlpha, BlendFn::One); }
ShadowExample() : make_torus(1.0, 0.7, 72, 48) , torus_indices(make_torus.Indices()) , torus_instr(make_torus.Instructions()) , object_projection_matrix(object_prog) , object_camera_matrix(object_prog) , object_model_matrix(object_prog) , shadow_projection_matrix(shadow_prog) , shadow_camera_matrix(shadow_prog) , shadow_model_matrix(shadow_prog) , object_color(object_prog) , object_light_mult(object_prog) { vs_object.Source( "#version 140\n" "in vec4 Position;" "in vec3 Normal;" "uniform mat4 ProjectionMatrix, CameraMatrix, ModelMatrix;" "uniform vec3 LightPos;" "out vec3 vertNormal;" "out vec3 vertLight;" "void main()" "{" " gl_Position = ModelMatrix * Position;" " vertNormal = mat3(ModelMatrix)*Normal;" " vertLight = LightPos - gl_Position.xyz;" " gl_Position = ProjectionMatrix * CameraMatrix * gl_Position;" "}"); vs_object.Compile(); fs_object.Source( "#version 140\n" "in vec3 vertNormal;" "in vec3 vertLight;" "uniform vec3 Color;" "uniform float LightMult;" "out vec4 fragColor;" "void main()" "{" " float l = sqrt(length(vertLight));" " float d = l > 0.0 ?" " dot(" " vertNormal," " normalize(vertLight)" " ) / l : 0.0;" " float i = 0.3 + max(d, 0.0) * LightMult;" " fragColor = vec4(Color*i, 1.0);" "}"); fs_object.Compile(); object_prog.AttachShader(vs_object); object_prog.AttachShader(fs_object); object_prog.Link().Use(); object_projection_matrix.BindTo("ProjectionMatrix"); object_camera_matrix.BindTo("CameraMatrix"); object_model_matrix.BindTo("ModelMatrix"); object_color.BindTo("Color"); object_light_mult.BindTo("LightMult"); vs_shadow.Source( "#version 150\n" "in vec4 Position;" "in vec3 Normal;" "uniform mat4 ModelMatrix;" "uniform vec3 LightPos;" "out float ld;" "void main()" "{" " gl_Position = ModelMatrix * Position;" " vec3 geomNormal = mat3(ModelMatrix)*Normal;" " vec3 lightDir = LightPos - gl_Position.xyz;" " ld = dot(geomNormal, normalize(lightDir));" "}"); vs_shadow.Compile(); gs_shadow.Source( "#version 150\n" "layout(triangles) in;" "layout(triangle_strip, max_vertices = 12) out;" "in float ld[];" "uniform mat4 CameraMatrix, ProjectionMatrix;" "uniform vec3 LightPos;" "void main()" "{" " for(int v=0; v!=3; ++v)" " {" " int a = v, b = (v+1)%3, c = (v+2)%3;" " vec4 pa = gl_in[a].gl_Position;" " vec4 pb = gl_in[b].gl_Position;" " vec4 pc = gl_in[c].gl_Position;" " vec4 px, py;" " if(ld[a] == 0.0 && ld[b] == 0.0)" " {" " px = pa;" " py = pb;" " }" " else if(ld[a] > 0.0 && ld[b] < 0.0)" " {" " float x = ld[a]/(ld[a]-ld[b]);" " float y;" " px = mix(pa, pb, x);" " if(ld[c] < 0.0)" " {" " y = ld[a]/(ld[a]-ld[c]);" " py = mix(pa, pc, y);" " }" " else" " {" " y = ld[c]/(ld[c]-ld[b]);" " py = mix(pc, pb, y);" " }" " }" " else continue;" " vec3 vx = px.xyz - LightPos;" " vec3 vy = py.xyz - LightPos;" " vec4 sx = vec4(px.xyz + vx*10.0, 1.0);" " vec4 sy = vec4(py.xyz + vy*10.0, 1.0);" " vec4 cpx = CameraMatrix * px;" " vec4 cpy = CameraMatrix * py;" " vec4 csx = CameraMatrix * sx;" " vec4 csy = CameraMatrix * sy;" " gl_Position = ProjectionMatrix * cpy;" " EmitVertex();" " gl_Position = ProjectionMatrix * cpx;" " EmitVertex();" " gl_Position = ProjectionMatrix * csy;" " EmitVertex();" " gl_Position = ProjectionMatrix * csx;" " EmitVertex();" " EndPrimitive();" " break;" " }" "}"); gs_shadow.Compile(); fs_shadow.Source( "#version 150\n" "out vec4 fragColor;" "void main()" "{" " fragColor = vec4(0.0, 0.0, 0.0, 1.0);" "}"); fs_shadow.Compile(); shadow_prog.AttachShader(vs_shadow); shadow_prog.AttachShader(gs_shadow); shadow_prog.AttachShader(fs_shadow); shadow_prog.Link().Use(); shadow_projection_matrix.BindTo("ProjectionMatrix"); shadow_camera_matrix.BindTo("CameraMatrix"); shadow_model_matrix.BindTo("ModelMatrix"); // bind the VAO for the torus torus.Bind(); // bind the VBO for the torus vertices torus_verts.Bind(Buffer::Target::Array); { std::vector<GLfloat> data; GLuint n_per_vertex = make_torus.Positions(data); Buffer::Data(Buffer::Target::Array, data); VertexArrayAttrib attr(VertexArrayAttrib::GetCommonLocation( MakeGroup(object_prog, shadow_prog), "Position")); attr.Setup<GLfloat>(n_per_vertex); attr.Enable(); } // bind the VBO for the torus normals torus_normals.Bind(Buffer::Target::Array); { std::vector<GLfloat> data; GLuint n_per_vertex = make_torus.Normals(data); Buffer::Data(Buffer::Target::Array, data); object_prog.Use(); VertexArrayAttrib attr(object_prog, "Normal"); attr.Setup<GLfloat>(n_per_vertex); attr.Enable(); } // bind the VAO for the plane plane.Bind(); // bind the VBO for the plane vertices plane_verts.Bind(Buffer::Target::Array); { GLfloat data[4 * 3] = {-9.0f, 0.0f, -9.0f, -9.0f, 0.0f, 9.0f, 9.0f, 0.0f, -9.0f, 9.0f, 0.0f, 9.0f}; Buffer::Data(Buffer::Target::Array, 4 * 3, data); object_prog.Use(); VertexArrayAttrib attr(object_prog, "Position"); attr.Setup<GLfloat>(3); attr.Enable(); } // bind the VBO for the torus normals plane_normals.Bind(Buffer::Target::Array); { GLfloat data[4 * 3] = {-0.1f, 1.0f, 0.1f, -0.1f, 1.0f, -0.1f, 0.1f, 1.0f, 0.1f, 0.1f, 1.0f, -0.1f}; Buffer::Data(Buffer::Target::Array, 4 * 3, data); object_prog.Use(); VertexArrayAttrib attr(object_prog, "Normal"); attr.Setup<GLfloat>(3); attr.Enable(); } Vec3f lightPos(2.0f, 9.0f, 3.0f); ProgramUniform<Vec3f>(object_prog, "LightPos").Set(lightPos); ProgramUniform<Vec3f>(shadow_prog, "LightPos").Set(lightPos); gl.ClearColor(0.2f, 0.2f, 0.2f, 0.0f); gl.ClearDepth(1.0f); gl.ClearStencil(0); gl.Enable(Capability::DepthTest); gl.Enable(Capability::CullFace); gl.FrontFace(make_torus.FaceWinding()); }
void ProjectWindow::MessageReceived(BMessage *msg) { status_t status; if ( (msg->WasDropped() && msg->what == B_SIMPLE_DATA) || msg->what == M_ADD_FILES) { fAddFileStruct.refmsg = *msg; fAddFileStruct.parent = this; uint32 buttons; fProjectList->GetMouse(&fAddFileStruct.droppt,&buttons); thread_id addThread = spawn_thread(AddFileThread,"file adding thread", B_NORMAL_PRIORITY, &fAddFileStruct); if (addThread >= 0) resume_thread(addThread); } switch (msg->what) { case M_IMPORT_REFS: { fImportStruct.refmsg = *msg; fImportStruct.parent = this; thread_id importThread = spawn_thread(ImportFileThread,"file import thread", B_NORMAL_PRIORITY, &fImportStruct); if (importThread >= 0) resume_thread(importThread); break; } case M_BACKUP_PROJECT: { thread_id backupThread = spawn_thread(BackupThread,"project backup thread", B_NORMAL_PRIORITY, this); if (backupThread >= 0) { fStatusBar->SetText(TR("Backing up project")); UpdateIfNeeded(); SetMenuLock(true); resume_thread(backupThread); } break; } case M_GET_CHECK_IN_MSG: { if (!fSourceControl) { printf("NULL source control\n"); break; } BString out; fSourceControl->GetCheckinHeader(out); bool select = false; if (out.CountChars() > 1) out.Prepend("\n\n"); else { out = TR("Enter the description for the changes in this revision."); select = true; } GetTextWindow *gtw = new GetTextWindow("Paladin", out.String(), BMessage(M_CHECK_IN_PROJECT), BMessenger(this)); if (!select) gtw->GetTextView()->Select(0,0); gtw->Show(); break; } case M_CHECK_IN_PROJECT: { BString commitstr; if (msg->FindString("text", &commitstr) == B_OK && fSourceControl) { SCMOutputWindow *win = new SCMOutputWindow(TR("Commit")); win->Show(); fSourceControl->Commit(commitstr.String()); } break; } case M_REVERT_PROJECT: { if (!fSourceControl) break; int32 result = ShowAlert(TR("This will undo all changes since the last commit. " "Continue?"), "Don't Revert", "Revert"); if (result == 1) { SCMOutputWindow *win = new SCMOutputWindow(TR("Revert")); win->Show(); fSourceControl->Revert(NULL); } break; } case M_REBUILD_FILE: case M_ADD_SELECTION_TO_REPO: case M_REMOVE_SELECTION_FROM_REPO: case M_REVERT_SELECTION: case M_DIFF_SELECTION: { ActOnSelectedFiles(msg->what); break; } case M_DIFF_PROJECT: { if (fSourceControl) { SCMOutputWindow *win = new SCMOutputWindow(TR("Differences")); win->Show(); fSourceControl->Diff(NULL); } break; } case M_PROJECT_SCM_STATUS: { if (fSourceControl) { SCMOutputWindow *win = new SCMOutputWindow(TR("Project Status")); BString strstatus; fSourceControl->GetChangeStatus(strstatus); win->GetTextView()->SetText(strstatus.String()); win->Show(); } break; } case M_PUSH_PROJECT: { if (fSourceControl) { SCMOutputWindow *win = new SCMOutputWindow(TR("Push")); win->Show(); fSourceControl->Push(NULL); } break; } case M_PULL_PROJECT: { if (fSourceControl) { SCMOutputWindow *win = new SCMOutputWindow(TR("Pull")); win->Show(); status = fSourceControl->Pull(NULL); if (!status) ShowAlert("Unable to pull from the remote repository. If it " "uses a secure connection, please set up the appropriate " "SSH keys on the remote server.", "OK"); } break; } case M_CULL_EMPTY_GROUPS: { CullEmptyGroups(); break; } case M_RUN_FILE_TYPES: { int32 selection = fProjectList->FullListCurrentSelection(); if (selection < 0) break; SourceFileItem *item = dynamic_cast<SourceFileItem*>(fProjectList->FullListItemAt(selection)); if (!item) break; SpawnFileTypes(item->GetData()->GetPath()); break; } case M_OPEN_PARENT_FOLDER: { BMessage openmsg(B_REFS_RECEIVED); int32 selindex = 0; int32 selection = fProjectList->FullListCurrentSelection(); selindex++; if (selection >= 0) { while (selection >= 0) { SourceFileItem *item = dynamic_cast<SourceFileItem*>(fProjectList->FullListItemAt(selection)); if (!item) break; SourceFile *file = item->GetData(); BString abspath = file->GetPath().GetFullPath(); if (abspath[0] != '/') { abspath.Prepend("/"); abspath.Prepend(fProject->GetPath().GetFolder()); } DPath filepath(abspath); entry_ref ref; BEntry(filepath.GetFolder()).GetRef(&ref); openmsg.AddRef("refs",&ref); selection = fProjectList->FullListCurrentSelection(selindex++); } BMessenger msgr("application/x-vnd.Be-TRAK"); msgr.SendMessage(&openmsg); } break; } case M_SHOW_PROJECT_FOLDER: { entry_ref ref; BEntry(fProject->GetPath().GetFolder()).GetRef(&ref); BMessenger msgr("application/x-vnd.Be-TRAK"); BMessage openmsg(B_REFS_RECEIVED); openmsg.AddRef("refs",&ref); msgr.SendMessage(&openmsg); break; } case M_SHOW_ASCII_TABLE: { AsciiWindow *ascwin = new AsciiWindow(); ascwin->Show(); break; } case M_SHOW_VREGEX: { VRegWindow *vregwin = new VRegWindow(); vregwin->Show(); break; } case M_SHOW_LICENSES: { LicenseManager *man = new LicenseManager(fProject->GetPath().GetFolder()); man->Show(); break; } case M_RUN_TOOL: { BString sig; if (msg->FindString("signature", &sig) == B_OK) { LaunchHelper launcher(sig.String()); launcher.Launch(); } break; } case M_MAKE_MAKE: { DPath out(fProject->GetPath().GetFolder()); out.Append("Makefile"); if (MakeMake(fProject,out) == B_OK); { BEntry entry(out.GetFullPath()); entry_ref ref; if (entry.InitCheck() == B_OK) { entry.GetRef(&ref); BMessage refmsg(B_REFS_RECEIVED); refmsg.AddRef("refs",&ref); be_app->PostMessage(&refmsg); } } break; } case M_SHOW_CODE_LIBRARY: { #ifdef BUILD_CODE_LIBRARY CodeLibWindow *libwin = CodeLibWindow::GetInstance(BRect(100,100,500,350)); libwin->Show(); #endif break; } case M_OPEN_PARTNER: { int32 selection = fProjectList->FullListCurrentSelection(); if (selection < 0) break; SourceFileItem *item = dynamic_cast<SourceFileItem*>( fProjectList->FullListItemAt(selection)); if (!item) break; entry_ref ref; BEntry(fProject->GetPathForFile(item->GetData()).GetFullPath()).GetRef(&ref); BMessage refmsg(M_OPEN_PARTNER); refmsg.AddRef("refs",&ref); be_app->PostMessage(&refmsg); break; } case M_NEW_GROUP: { MakeGroup(fProjectList->FullListCurrentSelection()); PostMessage(M_SHOW_RENAME_GROUP); break; } case M_SHOW_RENAME_GROUP: { int32 selection = fProjectList->FullListCurrentSelection(); SourceGroupItem *groupItem = NULL; if (selection < 0) { // Don't need a selection if there is only one group in the project if (fProject->CountGroups() == 1) groupItem = fProjectList->ItemForGroup(fProject->GroupAt(0)); } else { BStringItem *strItem = (BStringItem*)fProjectList->FullListItemAt(selection); groupItem = fProjectList->GroupForItem(strItem); } if (!groupItem) break; GroupRenameWindow *grwin = new GroupRenameWindow(groupItem->GetData(), BMessage(M_RENAME_GROUP), BMessenger(this)); grwin->Show(); break; } case M_RENAME_GROUP: { SourceGroup *group; BString newname; if (msg->FindPointer("group",(void**)&group) != B_OK || msg->FindString("newname",&newname) != B_OK) break; group->name = newname; SourceGroupItem *groupItem = fProjectList->ItemForGroup(group); if (!groupItem) break; groupItem->SetText(newname.String()); fProjectList->InvalidateItem(fProjectList->IndexOf(groupItem)); fProject->Save(); break; } case M_SORT_GROUP: { int32 selection = fProjectList->FullListCurrentSelection(); SourceGroupItem *groupItem = NULL; if (selection < 0) { // Don't need a selection if there is only one group in the project if (fProject->CountGroups() == 1) groupItem = fProjectList->ItemForGroup(fProject->GroupAt(0)); } else { BStringItem *strItem = (BStringItem*)fProjectList->FullListItemAt(selection); groupItem = fProjectList->GroupForItem(strItem); } if (!groupItem) break; fProjectList->SortItemsUnder(groupItem,true,compare_source_file_items); groupItem->GetData()->Sort(); fProject->Save(); break; } case M_TOGGLE_ERROR_WINDOW: { ToggleErrorWindow(fProject->GetErrorList()); break; } case M_SHOW_ERROR_WINDOW: { ShowErrorWindow(fProject->GetErrorList()); break; } case M_SHOW_PROJECT_SETTINGS: { BRect r(0,0,350,300); BRect screen(BScreen().Frame()); r.OffsetTo((screen.Width() - r.Width()) / 2.0, (screen.Height() - r.Height()) / 2.0); ProjectSettingsWindow *win = new ProjectSettingsWindow(r,fProject); win->Show(); break; } case M_SHOW_RUN_ARGS: { RunArgsWindow *argwin = new RunArgsWindow(fProject); argwin->Show(); break; } case M_JUMP_TO_MSG: { entry_ref ref; if (msg->FindRef("refs",&ref) == B_OK) { msg->what = B_REFS_RECEIVED; be_app->PostMessage(msg); } break; } case B_ABOUT_REQUESTED: { be_app->PostMessage(B_ABOUT_REQUESTED); break; } case M_SHOW_OPEN_PROJECT: { be_app->PostMessage(msg); break; } case M_NEW_WINDOW: { be_app->PostMessage(M_NEW_PROJECT); break; } case M_SHOW_PROGRAM_SETTINGS: { PrefsWindow *prefwin = new PrefsWindow(BRect(0,0,500,400)); prefwin->Show(); break; } case M_SHOW_FIND_AND_OPEN_PANEL: { BString text; msg->FindString("name",&text); // Passing a NULL string to this is OK FindOpenFileWindow *findwin = new FindOpenFileWindow(text.String()); findwin->Show(); break; } case M_FILE_NEEDS_BUILD: { SourceFile *file; if (msg->FindPointer("file",(void**)&file) == B_OK) { SourceFileItem *item = fProjectList->ItemForFile(file); if (item) { item->SetDisplayState(SFITEM_NEEDS_BUILD); fProjectList->InvalidateItem(fProjectList->IndexOf(item)); } } break; } case M_EDIT_FILE: { int32 i = 0; int32 selection = fProjectList->FullListCurrentSelection(i); i++; BMessage refmsg(B_REFS_RECEIVED); while (selection >= 0) { SourceFileItem *item = dynamic_cast<SourceFileItem*> (fProjectList->FullListItemAt(selection)); if (item && item->GetData()) { BString abspath = item->GetData()->GetPath().GetFullPath(); if (abspath[0] != '/') { abspath.Prepend("/"); abspath.Prepend(fProject->GetPath().GetFolder()); } BEntry entry(abspath.String()); if (entry.InitCheck() == B_OK) { entry_ref ref; entry.GetRef(&ref); refmsg.AddRef("refs",&ref); } else { if (!entry.Exists()) { BString errmsg = TR("Couldn't find XXXXX. It may have been moved or renamed."); errmsg.ReplaceFirst("XXXXX",abspath.String()); ShowAlert(errmsg.String()); } } } else { SourceGroupItem *groupItem = dynamic_cast<SourceGroupItem*> (fProjectList->FullListItemAt(selection)); if (groupItem) { if (groupItem->IsExpanded()) fProjectList->Collapse(groupItem); else fProjectList->Expand(groupItem); groupItem->GetData()->expanded = groupItem->IsExpanded(); } } selection = fProjectList->CurrentSelection(i); i++; } be_app->PostMessage(&refmsg); break; } case M_LIBWIN_CLOSED: { fShowingLibs = false; break; } case M_SHOW_LIBRARIES: { fShowingLibs = true; LibraryWindow *libwin = new LibraryWindow(Frame().OffsetByCopy(15,15), BMessenger(this), fProject); libwin->Show(); break; } case M_SHOW_ADD_NEW_PANEL: { AddNewFileWindow *anfwin = new AddNewFileWindow(BMessage(M_ADD_NEW_FILE), BMessenger(this)); anfwin->Show(); break; } case M_SHOW_FIND_IN_PROJECT_FILES: { if (!gLuaAvailable) { ShowAlert("Paladin's multi-file Find window depends on Lua. It will " "need to be installed if you wish to use this feature.", "OK", NULL, NULL, B_STOP_ALERT); break; } FindWindow *findwin = new FindWindow(); findwin->Show(); break; } case M_ADD_NEW_FILE: { BString name; bool makepair; if (msg->FindString("name",&name) == B_OK && msg->FindBool("makepair",&makepair) == B_OK) AddNewFile(name,makepair); break; } case M_SHOW_ADD_PANEL: { if (!fFilePanel) { BMessenger msgr(this); BEntry entry(fProject->GetPath().GetFolder()); entry_ref ref; entry.GetRef(&ref); fFilePanel = new BFilePanel(B_OPEN_PANEL,&msgr,&ref,B_FILE_NODE,true, new BMessage(M_ADD_FILES)); } fFilePanel->Show(); break; } case M_REMOVE_FILES: { bool save = false; for (int32 i = 0; i < fProjectList->CountItems(); i++) { SourceFileItem *item = dynamic_cast<SourceFileItem*>(fProjectList->ItemAt(i)); if (item && item->IsSelected()) { fProjectList->RemoveItem(item); fProject->RemoveFile(item->GetData()); delete item; save = true; i--; } } CullEmptyGroups(); if (save) fProject->Save(); break; } case M_EMPTY_CCACHE: { // We don't do this when forcing a rebuild of the sources because sometimes it // can take quite a while if (gUseCCache && gCCacheAvailable) { fStatusBar->SetText(TR("Emptying build cache")); UpdateIfNeeded(); system("ccache -c > /dev/null"); fStatusBar->SetText(""); UpdateIfNeeded(); } break; } case M_FORCE_REBUILD: { fProject->ForceRebuild(); for (int32 i = 0; i < fProjectList->FullListCountItems(); i++) { SourceFileItem *item = dynamic_cast<SourceFileItem*>(fProjectList->FullListItemAt(i)); if (!item) continue; SourceFile *file = item->GetData(); if (file->UsesBuild()) { item->SetDisplayState(SFITEM_NEEDS_BUILD); fProjectList->InvalidateItem(i); } } // This is necessary because InvalidateItem() uses indices from ItemAt(), // not FullListItemAt fProjectList->Invalidate(); break; } case M_UPDATE_DEPENDENCIES: { UpdateDependencies(); break; } case M_MAKE_PROJECT: case M_BUILD_PROJECT: { fBuildingFile = 0; DoBuild(POSTBUILD_NOTHING); break; } case M_RUN_PROJECT: { DoBuild(POSTBUILD_RUN); break; } case M_RUN_IN_TERMINAL: { DoBuild(POSTBUILD_RUN_IN_TERMINAL); break; } case M_DEBUG_PROJECT: { if (!fProject->Debug()) { BString errmsg = TR("Your project does not have debugging information compiled "); errmsg << TR("in and will need to be rebuilt to debug. Do you wish to rebuild and ") << TR("run the debugger?"); int32 result = ShowAlert("Debugging information needs to compiled into " "your project. This may take some time for large " "projects. Do you wish to rebuild and run " "the debugger?", "Rebuild","Cancel"); if (result == 1) break; fProject->SetDebug(true); fProject->Save(); fProject->ForceRebuild(); } DoBuild(POSTBUILD_DEBUG); break; } case M_EXAMINING_FILE: { SourceFile *file; if (msg->FindPointer("file",(void**)&file) == B_OK) { BString out; out << TR("Examining ") << file->GetPath().GetFileName(); fStatusBar->SetText(out.String()); } break; } case M_BUILDING_FILE: { SourceFile *file; if (msg->FindPointer("sourcefile",(void**)&file) == B_OK) { SourceFileItem *item = fProjectList->ItemForFile(file); if (item) { item->SetDisplayState(SFITEM_BUILDING); fProjectList->InvalidateItem(fProjectList->IndexOf(item)); BString out; int32 count,total; if (msg->FindInt32("count",&count) == B_OK && msg->FindInt32("total",&total) == B_OK) { fBuildingFile = MAX(fBuildingFile, count); out << "(" << fBuildingFile << "/" << total << ") "; } out << TR("Building ") << item->Text(); fStatusBar->SetText(out.String()); } } break; } case M_BUILDING_DONE: { SourceFile *file; if (msg->FindPointer("sourcefile",(void**)&file) == B_OK) { SourceFileItem *item = fProjectList->ItemForFile(file); if (item) { item->SetDisplayState(SFITEM_NORMAL); fProjectList->InvalidateItem(fProjectList->IndexOf(item)); } } break; } case M_LINKING_PROJECT: { fStatusBar->SetText(TR("Linking")); break; } case M_UPDATING_RESOURCES: { fStatusBar->SetText(TR("Updating Resources")); break; } case M_DOING_POSTBUILD: { fStatusBar->SetText(TR("Performing Post-build tasks")); break; } case M_BUILD_FAILURE: { SetMenuLock(false); // fall through } case M_BUILD_MESSAGES: case M_BUILD_WARNINGS: { if (!fErrorWindow) { BRect screen(BScreen().Frame()); BRect r(screen); r.left = r.right / 4.0; r.right *= .75; r.top = r.bottom - 200; BDeskbar deskbar; if (deskbar.Location() == B_DESKBAR_BOTTOM) r.OffsetBy(0,-deskbar.Frame().Height()); fErrorWindow = new ErrorWindow(r,this); fErrorWindow->Show(); } else { if (!fErrorWindow->IsFront()) fErrorWindow->Activate(); } fStatusBar->SetText(""); // Should this be an Unflatten or an Append? ErrorList *errorList = fProject->GetErrorList(); errorList->Unflatten(*msg); fErrorWindow->PostMessage(msg); break; } case M_BUILD_SUCCESS: { SetMenuLock(false); fStatusBar->SetText(""); break; } case M_ERRORWIN_CLOSED: { fErrorWindow = NULL; break; } case M_SYNC_MODULES: { #ifdef BUILD_CODE_LIBRARY thread_id syncID = spawn_thread(SyncThread,"module update thread", B_NORMAL_PRIORITY, this); if (syncID >= 0) resume_thread(syncID); #endif break; } case M_TOGGLE_DEBUG_MENU: { ToggleDebugMenu(); break; } case M_DEBUG_DUMP_DEPENDENCIES: { DumpDependencies(fProject); break; } case M_DEBUG_DUMP_INCLUDES: { DumpIncludes(fProject); break; } default: { DWindow::MessageReceived(msg); break; } } }