Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File colors #282

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ sources = \
src/core/vectors.cpp \
src/dirnode.cpp \
src/file.cpp \
src/file_colours.cpp \
src/formats/apache.cpp \
src/formats/bzr.cpp \
src/formats/commitlog.cpp \
Expand Down
2 changes: 2 additions & 0 deletions gource.pro
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ SOURCES += \
caption.cpp \
dirnode.cpp \
file.cpp \
file_colours.cpp \
gource.cpp \
gource_settings.cpp \
gource_shell.cpp \
Expand Down Expand Up @@ -92,6 +93,7 @@ HEADERS += \
caption.h \
dirnode.h \
file.h \
file_colours.h \
gource.h \
gource_settings.h \
gource_shell.h \
Expand Down
3 changes: 2 additions & 1 deletion src/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include "file.h"
#include "file_colours.h"

float gGourceFileDiameter = 8.0;

Expand Down Expand Up @@ -134,7 +135,7 @@ void RFile::setFilename(const std::string& abs_file_path) {
}

void RFile::colourize() {
file_colour = ext.size() ? colourHash(ext) : vec3(1.0f, 1.0f, 1.0f);
file_colour = gRFileColours.find(ext);
}

const vec3& RFile::getNameColour() const{
Expand Down
1,284 changes: 1,284 additions & 0 deletions src/file_colours.cpp

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions src/file_colours.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Copyright (C) 2009 Andrew Caudwell ([email protected])

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 <http://www.gnu.org/licenses/>.
*/

#ifndef FILE_COLOURS_H_
#define FILE_COLOURS_H_

#include "core/vectors.h"
#include <map>
#include <string>

class RFileColours {
public:
std::map<std::string, vec3> colours;

void init();
vec3 find(std::string);
};

extern RFileColours gRFileColours;

#endif
9 changes: 4 additions & 5 deletions src/formats/commitlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "commitlog.h"
#include "../gource_settings.h"
#include "../file_colours.h"
#include "../core/sdlapp.h"

#include "../core/utf8/utf8.h"
Expand Down Expand Up @@ -310,12 +311,10 @@ vec3 RCommit::fileColour(const std::string& filename) {
size_t dot = filename.rfind('.');

if(dot != std::string::npos && dot+1<filename.size() && (slash == std::string::npos || slash < dot)) {
std::string file_ext = filename.substr(dot+1);

return colourHash(file_ext);
} else {
return vec3(1.0, 1.0, 1.0);
return gRFileColours.find(filename.substr(dot+1));
}

return vec3(1.0, 1.0, 1.0);
}

void RCommit::addFile(const std::string& filename, const std::string& action) {
Expand Down
1 change: 1 addition & 0 deletions src/gource.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "action.h"
#include "caption.h"
#include "file.h"
#include "file_colours.h"
#include "user.h"
#include "dirnode.h"
#include "zoomcamera.h"
Expand Down
2 changes: 2 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

int main(int argc, char *argv[]) {

gRFileColours.init();

std::string exepath;
#ifndef _WIN32
if(argc > 0) {
Expand Down