Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
Signed-off-by: Thxios <[email protected]>
  • Loading branch information
Thxios committed Mar 27, 2020
1 parent d7759d0 commit d1b3af7
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 11 deletions.
30 changes: 30 additions & 0 deletions src/Interaction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from src.lib import *
from src.Section.Section import *


class Interaction:

canvasSection = None
brushSection = None
colorSection = None
frameSection = None
layerSection = None
paletteSection = None

def Initialize(self, **kwargs):
if 'canvas' in kwargs:
self.canvasSection = kwargs['canvas']
if 'brush' in kwargs:
self.brushSection = kwargs['brush']
if 'color' in kwargs:
self.colorSection = kwargs['color']
if 'frame' in kwargs:
self.frameSection = kwargs['frame']
if 'layer' in kwargs:
self.layerSection = kwargs['layer']
if 'palette' in kwargs:
self.paletteSection = kwargs['palette']


Interaction = Interaction()

21 changes: 15 additions & 6 deletions src/Section/_ColorSection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from src.Color import Color
from src.Command import Command
from src.Text import Text
from src.Interaction import Interaction
from src import utility
from math import sin, cos, atan2, degrees, radians, sqrt

Expand Down Expand Up @@ -53,7 +54,6 @@ class ColorSection(Section):
def Setup(self, x, y, w, h):
super().Setup(x, y, w, h)

self.SetColor()
self.valueBarRect = pg.Rect((self.w - self.barWidth) // 2,
self.wheelCenterY + self.radius + self.radiusTerm + 13 + 1,
self.barWidth,
Expand All @@ -63,6 +63,13 @@ def Setup(self, x, y, w, h):
self.barWidth,
self.barHeight)

if self.color.hsv[V] > 50:
self.dotImage = self.dotDarkImage
else:
self.dotImage = self.dotBrightImage
Brush.SetCurrentColor(self.color.rgba)
self.Changed()

def Update(self):
# print(self.w - self.barWidth)
# print(self.wheelCenterY + self.radius + self.radiusTerm + 15 + 1)
Expand All @@ -72,23 +79,25 @@ def Update(self):
self.DrawPreview()
self.DrawText()

def SetColor(self):
def SetColor(self, outer=False):
if self.color.hsv[V] > 50:
self.dotImage = self.dotDarkImage
else:
self.dotImage = self.dotBrightImage
Brush.SetCurrentColor(self.color.rgba)
if not outer:
Interaction.paletteSection.SetColorIndex(-1)
self.Changed()

def SetColorRGB(self, r, g, b, a=255):
def SetColorRGB(self, r, g, b, a=255, outer=False):
self.color.rgba = (r, g, b, a)
self.SetColor()
self.SetColor(outer)

def SetColorHSV(self, h, s, v):
def SetColorHSV(self, h, s, v, outer=False):
# self.colorHSV = color
# self.colorRGB = utility.HSV2RGB(color)
self.color.hsv = (h, s, v)
self.SetColor()
self.SetColor(outer)

def SetAlpha(self, alpha):
self.color.alpha = utility.Clamp(alpha, 255, 0)
Expand Down
7 changes: 6 additions & 1 deletion src/Section/_PaletteSection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from src.lib import *
from src.Section._Section import Section
from src.Interaction import Interaction
from src.Brush import Brush


Expand Down Expand Up @@ -56,8 +57,12 @@ def MakeColorRect(self):
))

def SetColorIndex(self, idx):
if idx == self.selectedIndex:
return
self.selectedIndex = idx
Brush.SetCurrentColor(self.color[idx])
if idx != -1:
Interaction.colorSection.SetColorRGB(*self.color[idx], outer=True)
Brush.SetCurrentColor(self.color[idx])
self.Changed()

def OnMouseDown(self, button, x, y):
Expand Down
15 changes: 11 additions & 4 deletions src/Window.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from src.lib import *
from .Section.Section import *
from src.Section.Section import *
from src.Command import Command
from src.Brush import Brush
from src.Interaction import Interaction


class MainWindow:
Expand All @@ -20,7 +21,7 @@ class MainWindow:

_topTerm = 30
_left = 250
_middle = 50
_middle = 52
_l1 = 250
_l2 = 400 - _topTerm
_l3 = 250
Expand All @@ -30,14 +31,20 @@ class MainWindow:

# CanvasSection.Setup(_left, _topTerm, w - _left, _r1)
CanvasSection.Setup(_left + _middle, _topTerm, w - _left - _middle, _r1)
PaletteSection.Setup(0, _topTerm, _left - _bs, _l1)
BrushSection.Setup(_left - _bs, _topTerm, _bs, _l1)
# PaletteSection.Setup(0, _topTerm, _left - _bs, _l1)
PaletteSection.Setup(0, _topTerm, _left, _l1)
# BrushSection.Setup(_left - _bs, _topTerm, _bs, _l1)
BrushSection.Setup(_left, _topTerm, _middle, _l1 + _l2 + _l3)
# FrameSection.Setup(_left, _r1 + _topTerm, w - _left, _r2)
FrameSection.Setup(_left + _middle, _r1 + _topTerm, w - _left - _middle, _r2)
ColorSection.Setup(0, _l1 + _topTerm, _left, _l2)
LayerSection.Setup(0, _l1 + _l2 + _topTerm, _left, _l3)

# ----- for test -----
Interaction.Initialize(
palette=PaletteSection,
color=ColorSection
)
# sprite = Canvas.Empty(20, 15, (0, 0, 0, 255))

mouseButton = [0, 0, 0, 0]
Expand Down
24 changes: 24 additions & 0 deletions src/palette/0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,27 @@
255 0 255
0 255 255
0 0 0
255 255 255
255 0 0
0 255 0
0 0 255
255 255 0
255 0 255
0 255 255
0 0 0
255 255 255
255 0 0
0 255 0
0 0 255
255 255 0
255 0 255
0 255 255
0 0 0
255 255 255
255 0 0
0 255 0
0 0 255
255 255 0
255 0 255
0 255 255
0 0 0

0 comments on commit d1b3af7

Please sign in to comment.