forked from AnyOldName3/modorganizer-preview_dds
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add transparency toggle #9
Open
Jampi0n
wants to merge
4
commits into
ModOrganizer2:master
Choose a base branch
from
Jampi0n:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,9 +151,11 @@ | |
glVersionProfile.setVersion(2, 1) | ||
|
||
class DDSWidget(QOpenGLWidget): | ||
def __init__(self, ddsFile, debugContext = False, parent = None, f = Qt.WindowFlags()): | ||
def __init__(self, ddsPreview, ddsFile, debugContext = False, parent = None, f = Qt.WindowFlags()): | ||
super(DDSWidget, self).__init__(parent, f) | ||
|
||
|
||
self.ddsPreview = ddsPreview | ||
|
||
self.ddsFile = ddsFile | ||
|
||
self.clean = True | ||
|
@@ -166,8 +168,6 @@ def __init__(self, ddsFile, debugContext = False, parent = None, f = Qt.WindowFl | |
self.vbo = None | ||
self.vao = None | ||
|
||
self.backgroundColour = None | ||
|
||
if debugContext: | ||
format = QSurfaceFormat() | ||
format.setOption(QSurfaceFormat.DebugContext) | ||
|
@@ -252,9 +252,10 @@ def paintGL(self): | |
|
||
# Draw checkerboard so transparency is obvious | ||
self.transparecyProgram.bind() | ||
|
||
if self.backgroundColour and self.backgroundColour.isValid(): | ||
self.transparecyProgram.setUniformValue("backgroundColour", self.backgroundColour) | ||
|
||
backgroundColour = self.ddsPreview.getBackgroundColour() | ||
if backgroundColour and backgroundColour.isValid(): | ||
self.transparecyProgram.setUniformValue("backgroundColour", backgroundColour) | ||
|
||
gl.glDrawArrays(gl.GL_TRIANGLES, 0, 6) | ||
|
||
|
@@ -264,9 +265,12 @@ def paintGL(self): | |
|
||
if self.texture: | ||
self.texture.bind() | ||
|
||
gl.glEnable(gl.GL_BLEND) | ||
gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) | ||
|
||
if self.ddsPreview.getTransparency(): | ||
gl.glEnable(gl.GL_BLEND) | ||
gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) | ||
else: | ||
gl.glDisable(gl.GL_BLEND) | ||
|
||
gl.glDrawArrays(gl.GL_TRIANGLES, 0, 6) | ||
|
||
|
@@ -291,12 +295,6 @@ def cleanup(self): | |
self.doneCurrent() | ||
self.clean = True | ||
|
||
def setBackgroundColour(self, colour): | ||
self.backgroundColour = colour | ||
|
||
def getBackgroundColour(self): | ||
return self.backgroundColour | ||
|
||
def __tr(self, str): | ||
return QCoreApplication.translate("DDSWidget", str) | ||
|
||
|
@@ -311,6 +309,12 @@ def init(self, organizer): | |
self.__organizer = organizer | ||
return True | ||
|
||
def pluginSetting(self, name): | ||
return self.__organizer.pluginSetting(self.name(), name) | ||
|
||
def setPluginSetting(self, name, value): | ||
self.__organizer.setPluginSetting(self.name(), name, value) | ||
|
||
def name(self): | ||
return "DDS Preview Plugin" | ||
|
||
|
@@ -328,7 +332,8 @@ def settings(self): | |
mobase.PluginSetting("background r", self.__tr("Red channel of background colour"), 0), | ||
mobase.PluginSetting("background g", self.__tr("Green channel of background colour"), 0), | ||
mobase.PluginSetting("background b", self.__tr("Blue channel of background colour"), 0), | ||
mobase.PluginSetting("background a", self.__tr("Alpha channel of background colour"), 0)] | ||
mobase.PluginSetting("background a", self.__tr("Alpha channel of background colour"), 0), | ||
mobase.PluginSetting("transparency", self.__tr("If enabled, transparency will be displayed."), True)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'd be more technically accurate to refer to it as alpha rather than transparency or translucency. The whole reason this PR is necessary is that it's not always transparency data. |
||
|
||
def supportedExtensions(self): | ||
return ["dds"] | ||
|
@@ -342,12 +347,13 @@ def genFilePreview(self, fileName, maxSize): | |
# Label grows before button | ||
layout.setColumnStretch(0, 1) | ||
layout.addWidget(self.__makeLabel(ddsFile), 1, 0, 1, 1) | ||
|
||
ddsWidget = DDSWidget(ddsFile, self.__organizer.pluginSetting(self.name(), "log gl errors")) | ||
layout.addWidget(ddsWidget, 0, 0, 1, 2) | ||
|
||
layout.addWidget(self.__makeColourButton(ddsWidget), 1, 1, 1, 1) | ||
|
||
|
||
ddsWidget = DDSWidget(self, ddsFile, self.__organizer.pluginSetting(self.name(), "log gl errors")) | ||
layout.addWidget(ddsWidget, 0, 0, 1, 3) | ||
|
||
layout.addWidget(self.__makeColourButton(ddsWidget), 1, 2, 1, 1) | ||
layout.addWidget(self.__makeToggleTransparencyButton(ddsWidget), 1, 1, 1, 1) | ||
|
||
widget = QWidget() | ||
widget.setLayout(layout) | ||
return widget | ||
|
@@ -363,20 +369,44 @@ def __makeLabel(self, ddsFile): | |
|
||
def __makeColourButton(self, ddsWidget): | ||
button = QPushButton(self.__tr("Pick background colour")) | ||
savedColour = QColor(self.__organizer.pluginSetting(self.name(), "background r"), self.__organizer.pluginSetting(self.name(), "background g"), self.__organizer.pluginSetting(self.name(), "background b"), self.__organizer.pluginSetting(self.name(), "background a")) | ||
ddsWidget.setBackgroundColour(savedColour) | ||
|
||
|
||
def pickColour(unused): | ||
newColour = QColorDialog.getColor(ddsWidget.getBackgroundColour(), button, "Background colour", QColorDialog.ShowAlphaChannel) | ||
newColour = QColorDialog.getColor(self.getBackgroundColour(), button, "Background colour", QColorDialog.ShowAlphaChannel) | ||
if newColour.isValid(): | ||
ddsWidget.setBackgroundColour(newColour) | ||
self.__organizer.setPluginSetting(self.name(), "background r", newColour.red()) | ||
self.__organizer.setPluginSetting(self.name(), "background g", newColour.green()) | ||
self.__organizer.setPluginSetting(self.name(), "background b", newColour.blue()) | ||
self.__organizer.setPluginSetting(self.name(), "background a", newColour.alpha()) | ||
self.setPluginSetting("background r", newColour.red()) | ||
self.setPluginSetting("background g", newColour.green()) | ||
self.setPluginSetting("background b", newColour.blue()) | ||
self.setPluginSetting("background a", newColour.alpha()) | ||
ddsWidget.update() | ||
|
||
button.clicked.connect(pickColour) | ||
return button | ||
|
||
def __makeToggleTransparencyButton(self, ddsWidget): | ||
def getButtonText(): | ||
if self.getTransparency(): | ||
return self.__tr("Disable Transparency") | ||
else: | ||
return self.__tr("Enable Transparency") | ||
|
||
button = QPushButton(getButtonText()) | ||
# Since every conflicting mod gets its own button, the text needs to be updated when the page is changed. | ||
button.showEvent = lambda _: button.setText(getButtonText()) | ||
|
||
def toggleTransparency(unused): | ||
transparency = not self.getTransparency() | ||
self.setPluginSetting("transparency", transparency) | ||
ddsWidget.update() | ||
button.setText(getButtonText()) | ||
|
||
button.clicked.connect(toggleTransparency) | ||
return button | ||
|
||
def getBackgroundColour(self): | ||
return QColor(self.pluginSetting("background r"), self.pluginSetting("background g"), self.pluginSetting("background b"), self.pluginSetting("background a")) | ||
|
||
def getTransparency(self): | ||
return self.pluginSetting("transparency") | ||
|
||
def createPlugin(): | ||
return DDSPreview() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not keen on creating a cyclic dependency between
DDSWidget
andDDSPreview
. Technically, it's possible to find uses for a DDS widget other than the preview, so we might want to move it out of this plugin into a library and make the plugin depend on that library. You can break the cycle by creating a class that holds the current options which both the widget and preview plugin have a reference to an instance of.