Explorar o código

background fix

Ethosa %!s(int64=3) %!d(string=hai) anos
pai
achega
a654fa6b34

+ 0 - 7
src/nodesnim/nodescontrol/box.nim

@@ -60,13 +60,6 @@ method addChild*(self: BoxRef, child: NodeRef) =
 
 method draw*(self: BoxRef, w, h: GLfloat) =
   ## this method uses in the `window.nim`.
-  let
-    x = -w/2 + self.global_position.x
-    y = h/2 - self.global_position.y
-
-  glColor4f(self.background_color.r, self.background_color.g, self.background_color.b, self.background_color.a)
-  glRectf(x, y, x+self.rect_size.x, y-self.rect_size.y)
-
   for child in self.children:
     child.CanvasRef.position.x = self.rect_size.x*self.child_anchor.x1 - child.CanvasRef.rect_size.x*self.child_anchor.x2
     child.CanvasRef.position.y = self.rect_size.y*self.child_anchor.y1 - child.CanvasRef.rect_size.y*self.child_anchor.y2

+ 14 - 15
src/nodesnim/nodescontrol/button.nim

@@ -12,6 +12,7 @@ import
   ../core/color,
 
   ../nodes/node,
+  ../graphics/drawable,
   control,
   label
 
@@ -21,9 +22,9 @@ type
     button_mask*: cint  ## Mask for handle clicks
     action_mask*: cint  ## BUTTON_RELEASE or BUTTON_CLICK.
 
-    normal_background_color*: ColorRef  ## color, when button is not pressed and not hovered.
-    hover_background_color*: ColorRef   ## color, when button hovered.
-    press_background_color*: ColorRef   ## color, when button pressed.
+    normal_background*: DrawableRef  ## color, when button is not pressed and not hovered.
+    hover_background*: DrawableRef   ## color, when button hovered.
+    press_background*: DrawableRef   ## color, when button pressed.
 
     normal_color*: ColorRef  ## text color, whenwhen button is not pressed and not hovered.
     hover_color*: ColorRef   ## text color, when button hovered.
@@ -55,25 +56,25 @@ proc Button*(name: string = "Button"): ButtonRef =
   result.press_color = Color(1f, 1f, 1f)
   result.button_mask = BUTTON_LEFT
   result.action_mask = BUTTON_RELEASE
-  result.normal_background_color = Color(0x444444ff)
-  result.hover_background_color = Color(0x505050ff)
-  result.press_background_color = Color(0x595959ff)
+  result.normal_background = Drawable()
+  result.hover_background = Drawable()
+  result.press_background = Drawable()
+  result.normal_background.setColor(Color(0x444444ff))
+  result.hover_background.setColor(Color(0x505050ff))
+  result.press_background.setColor(Color(0x595959ff))
   result.on_touch = proc(self: ButtonRef, x, y: float) = discard
   result.kind = BUTTON_NODE
 
 
 method draw*(self: ButtonRef, w, h: GLfloat) =
   ## this method uses in the `window.nim`.
-  let
-    x = -w/2 + self.global_position.x
-    y = h/2 - self.global_position.y
-    color =
+  self.background =
       if self.pressed and self.focused:
-        self.press_background_color
+        self.press_background
       elif self.hovered and not mouse_pressed:
-        self.hover_background_color
+        self.hover_background
       else:
-        self.normal_background_color
+        self.normal_background
   self.color =
     if self.pressed and self.focused:
       self.press_color
@@ -81,8 +82,6 @@ method draw*(self: ButtonRef, w, h: GLfloat) =
       self.hover_color
     else:
       self.normal_color
-  glColor4f(color.r, color.g, color.b, color.a)
-  glRectf(x, y, x + self.rect_size.x, y - self.rect_size.y)
   procCall self.LabelRef.draw(w, h)
 
 method duplicate*(self: ButtonRef, obj: var ButtonObj): ButtonRef {.base.} =

+ 6 - 2
src/nodesnim/nodescontrol/color_rect.nim

@@ -11,6 +11,7 @@ import
   ../core/enums,
 
   ../nodes/node,
+  ../graphics/drawable,
   control
 
 
@@ -41,8 +42,11 @@ method draw*(self: ColorRectRef, w, h: GLfloat) =
     x = -w/2 + self.global_position.x
     y = h/2 - self.global_position.y
 
-  glColor4f(self.color.r, self.color.g, self.color.b, self.color.a)
-  glRectf(x, y, x + self.rect_size.x, y - self.rect_size.y)
+  if self.background.getColor().a == 0.0:
+    glColor4f(self.color.r, self.color.g, self.color.b, self.color.a)
+    glRectf(x, y, x + self.rect_size.x, y - self.rect_size.y)
+  else:
+    self.background.draw(x, y, self.rect_size.x, self.rect_size.y)
 
   # Press
   if self.pressed:

+ 1 - 6
src/nodesnim/nodescontrol/control.nim

@@ -25,7 +25,6 @@ type
     focused*: bool
 
     mousemode*: MouseMode
-    background_color*: ColorRef
     background*: DrawableRef
 
     on_mouse_enter*: proc(self: ControlRef, x, y: float): void  ## This called when the mouse enters the Control node.
@@ -44,7 +43,6 @@ template controlpattern*: untyped =
   result.pressed = false
 
   result.mousemode = MOUSEMODE_SEE
-  result.background_color = Color()
   result.background = Drawable()
   result.rect_size = Vector2()
   result.position = Vector2()
@@ -90,9 +88,6 @@ method draw*(self: ControlRef, w, h: GLfloat) =
     x = -w/2 + self.global_position.x
     y = h/2 - self.global_position.y
 
-  # glColor4f(self.background_color.r, self.background_color.g, self.background_color.b, self.background_color.a)
-  # glRectf(x, y, x+self.rect_size.x, y-self.rect_size.y)
-
   self.background.draw(x, y, self.rect_size.x, self.rect_size.y)
 
   # Press
@@ -143,7 +138,7 @@ method handle*(self: ControlRef, event: InputEvent, mouse_on: var NodeRef) =
 
 method setBackgroundColor*(self: ControlRef, color: ColorRef) {.base.} =
   ## Changes Control background color.
-  self.background_color = color
+  self.background.setColor(color)
 
 method setStyle*(self: ControlRef, style: StyleSheetRef) {.base.} =
   self.background.setStyle(style)

+ 3 - 3
src/nodesnim/nodescontrol/counter.nim

@@ -12,6 +12,7 @@ import
 
   ../nodes/node,
   ../nodes/canvas,
+  ../graphics/drawable,
   control,
   label
 
@@ -42,7 +43,7 @@ proc Counter*(name: string = "Counter"): CounterRef =
   result.label = Label()
   result.label.mousemode = MOUSEMODE_IGNORE
   result.label.parent = result
-  result.background_color = Color(0x212121ff)
+  result.background.setColor(Color(0x212121ff))
   result.kind = COUNTER_NODE
 
 
@@ -62,8 +63,7 @@ method draw*(self: CounterRef, w, h: GLfloat) =
     x = -w/2 + self.global_position.x
     y = h/2 - self.global_position.y
 
-  glColor4f(self.background_color.r, self.background_color.g, self.background_color.b, self.background_color.a)
-  glRectf(x, y, x+self.rect_size.x, y-self.rect_size.y)
+  self.background.draw(x, y, self.rect_size.x, self.rect_size.y)
 
   self.label.calcGlobalPosition()
   self.label.resize(self.rect_size.x - 40, self.rect_size.y)

+ 2 - 2
src/nodesnim/nodescontrol/edittext.nim

@@ -13,6 +13,7 @@ import
   ../core/color,
 
   ../nodes/node,
+  ../graphics/drawable,
   control
 
 
@@ -187,8 +188,7 @@ method draw*(self: EditTextRef, w, h: GLfloat) =
       else:
         self.hint_color
 
-  glColor4f(self.background_color.r, self.background_color.g, self.background_color.b, self.background_color.a)
-  glRectf(x, y, x+self.rect_size.x, y-self.rect_size.y)
+  self.background.draw(x, y, self.rect_size.x, self.rect_size.y)
   var
     th = 0f
     char_num = 0

+ 0 - 7
src/nodesnim/nodescontrol/grid_box.nim

@@ -79,13 +79,6 @@ method addChild*(self: GridBoxRef, child: NodeRef) =
 
 method draw*(self: GridBoxRef, w, h: GLfloat) =
   ## This method uses in the `window.nim`.
-  let
-    x1 = -w/2 + self.global_position.x
-    y1 = h/2 - self.global_position.y
-
-  glColor4f(self.background_color.r, self.background_color.g, self.background_color.b, self.background_color.a)
-  glRectf(x1, y1, x1+self.rect_size.x, y1-self.rect_size.y)
-
   var
     row = 0
     fakesize = self.getChildSize()

+ 0 - 7
src/nodesnim/nodescontrol/hbox.nim

@@ -61,13 +61,6 @@ method addChild*(self: HBoxRef, child: NodeRef) =
 
 method draw*(self: HBoxRef, w, h: GLfloat) =
   ## This uses in the `window.nim`.
-  let
-    x1 = -w/2 + self.global_position.x
-    y = h/2 - self.global_position.y
-
-  glColor4f(self.background_color.r, self.background_color.g, self.background_color.b, self.background_color.a)
-  glRectf(x1, y, x1+self.rect_size.x, y-self.rect_size.y)
-
   var
     fakesize = self.getChildSize()
     x = self.rect_size.x*self.child_anchor.x1 - fakesize.x*self.child_anchor.x2

+ 3 - 4
src/nodesnim/nodescontrol/lineedit.nim

@@ -12,6 +12,7 @@ import
   ../core/color,
 
   ../nodes/node,
+  ../graphics/drawable,
   control
 
 
@@ -51,7 +52,7 @@ proc LineEdit*(name: string = "LineEdit"): LineEditRef =
   result.spacing = 2
   result.text_align = Anchor(0.5, 0.5, 0.5, 0.5)
   result.color = Color(1f, 1f, 1f)
-  result.background_color = Color(0x454545ff)
+  result.background.setColor(Color(0x454545ff))
   result.hint_color = Color(0.8, 0.8, 0.8)
   result.hint_text = "Edit text ..."
   result.caret_position = 0
@@ -113,9 +114,7 @@ method draw*(self: LineEditRef, w, h: GLfloat) =
         self.hint_color
     tw = self.font.glutBitmapLength(text).float
 
-  glColor4f(self.background_color.r, self.background_color.g, self.background_color.b, self.background_color.a)
-  glRectf(x, y, x+self.rect_size.x, y-self.rect_size.y)
-
+  self.background.draw(x, y, self.rect_size.x, self.rect_size.y)
 
   var
     char_num = 0

+ 2 - 14
src/nodesnim/nodescontrol/popup.nim

@@ -11,6 +11,7 @@ import
   ../core/color,
 
   ../nodes/node,
+  ../graphics/drawable,
   control
 
 
@@ -28,7 +29,7 @@ proc Popup*(name: string = "Popup"): PopupRef =
     var p = Popup("Popup")
   nodepattern(PopupRef)
   controlpattern()
-  result.background_color = Color(0x212121ff)
+  result.background.setColor(Color(0x212121ff))
   result.rect_size.x = 160
   result.rect_size.y = 160
   result.visible = false
@@ -61,19 +62,6 @@ method calcPositionAnchor*(self: PopupRef) =
   procCall self.ControlRef.calcPositionAnchor()
   recalc()
 
-method draw*(self: PopupRef, w, h: GLfloat) =
-  ## This uses in the `window.nim`.
-  let
-    x = -w/2 + self.global_position.x
-    y = h/2 - self.global_position.y
-
-  glColor4f(self.background_color.r, self.background_color.g, self.background_color.b, self.background_color.a)
-  glRectf(x, y, x + self.rect_size.x, y - self.rect_size.y)
-
-  # Press
-  if self.pressed:
-    self.on_press(self, last_event.x, last_event.y)
-
 method duplicate*(self: PopupRef): PopupRef {.base.} =
   ## Duplicates Popup object and create a new Popup.
   self.deepCopy()

+ 2 - 2
src/nodesnim/nodescontrol/progress_bar.nim

@@ -12,6 +12,7 @@ import
 
   ../nodes/node,
   ../nodes/canvas,
+  ../graphics/drawable,
   control,
   math
 
@@ -42,7 +43,6 @@ proc ProgressBar*(name: string = "ProgressBar"): ProgressBarRef =
   controlpattern()
   result.value = 0
   result.max_value = 100
-  result.background_color = Color(1f, 1f, 1f)
   result.progress_color = Color(0.6, 0.6, 0.6)
   result.rect_size.x = 120
   result.rect_size.y = 20
@@ -101,7 +101,7 @@ method draw*(self: ProgressBarRef, w, h: GLfloat) =
       orad = min(self.rect_size.x, self.rect_size.y) / 2
       irad = (min(self.rect_size.x, self.rect_size.y) / 2) - 5f
     # background:
-    glColor4f(self.background_color.r, self.background_color.g, self.background_color.b, self.background_color.a)
+    glColor4f(self.background.getColor().r, self.background.getColor().g, self.background.getColor().b, self.background.getColor().a)
     glBegin(GL_TRIANGLE_STRIP)
     for i in 0..90:
       let angle = TAU * (i/90)

+ 2 - 2
src/nodesnim/nodescontrol/rich_edit_text.nim

@@ -13,6 +13,7 @@ import
   ../core/color_text,
 
   ../nodes/node,
+  ../graphics/drawable,
   control
 
 
@@ -177,8 +178,7 @@ method draw*(self: RichEditTextRef, w, h: GLfloat) =
       else:
         self.hint_text
 
-  glColor4f(self.background_color.r, self.background_color.g, self.background_color.b, self.background_color.a)
-  glRectf(x, y, x+self.rect_size.x, y-self.rect_size.y)
+  self.background.draw(x, y, self.rect_size.x, self.rect_size.y)
   var
     th = 0f
     char_num = 0

+ 2 - 3
src/nodesnim/nodescontrol/rich_label.nim

@@ -13,6 +13,7 @@ import
   ../core/color_text,
 
   ../nodes/node,
+  ../graphics/drawable,
   control
 
 
@@ -51,9 +52,7 @@ method draw*(self: RichLabelRef, w, h: GLfloat) =
     x = -w/2 + self.global_position.x
     y = h/2 - self.global_position.y
 
-  glColor4f(self.background_color.r, self.background_color.g, self.background_color.b, self.background_color.a)
-  glRectf(x, y, x+self.rect_size.x, y-self.rect_size.y)
-
+  self.background.draw(x, y, self.rect_size.x, self.rect_size.y)
 
   var th = 0f
 

+ 2 - 2
src/nodesnim/nodescontrol/scroll.nim

@@ -12,6 +12,7 @@ import
 
   ../nodes/node,
   ../nodes/canvas,
+  ../graphics/drawable,
   control
 
 
@@ -82,8 +83,7 @@ method draw*(self: ScrollRef, w, h: GLfloat) =
     x = -w/2 + self.global_position.x
     y = h/2 - self.global_position.y
 
-  glColor4f(self.background_color.r, self.background_color.g, self.background_color.b, self.background_color.a)
-  glRectf(x, y, x+self.viewport_w, y-self.viewport_h)
+  self.background.draw(x, y, self.rect_size.x, self.rect_size.y)
 
   # Press
   if self.pressed:

+ 3 - 3
src/nodesnim/nodescontrol/slider.nim

@@ -11,6 +11,7 @@ import
   ../core/enums,
 
   ../nodes/node,
+  ../graphics/drawable,
   control
 
 
@@ -33,7 +34,7 @@ proc Slider*(name: string = "Slider"): SliderRef =
     var sc = Slider("Slider")
   nodepattern(SliderRef)
   controlpattern()
-  result.background_color = Color(1f, 1f, 1f)
+  result.background.setColor(Color(1f, 1f, 1f))
   result.rect_size.x = 120
   result.rect_size.y = 40
   result.progress_color = Color(0.5, 0.5, 0.5)
@@ -51,8 +52,7 @@ method draw*(self: SliderRef, w, h: GLfloat) =
     y = h/2 - self.global_position.y
 
   # Background
-  glColor4f(self.background_color.r, self.background_color.g, self.background_color.b, self.background_color.a)
-  glRectf(x, y, x + self.rect_size.x, y - self.rect_size.y)
+  self.background.draw(x, y, self.rect_size.x, self.rect_size.y)
 
   # Progress
   let progress = self.rect_size.x * (self.value.float / self.max_value.float)

+ 10 - 32
src/nodesnim/nodescontrol/subwindow.nim

@@ -14,6 +14,7 @@ import
 
   ../nodes/node,
   ../nodes/canvas,
+  ../graphics/drawable,
   control,
   popup,
   label
@@ -24,8 +25,7 @@ type
     left_taked*, right_taked*, top_taked*, bottom_taked*: bool
     title_taked*: bool
     icon*: GlTextureObj
-    title_bar_color*: ColorRef
-    border_color*: ColorRef
+    title_bar*: DrawableRef
     title_taked_pos*: Vector2Ref
     title*: LabelRef
   SubWindowRef* = ref SubWindowObj
@@ -40,9 +40,10 @@ proc SubWindow*(name: string = "SubWindow"): SubWindowRef =
     var window = SubWindow("SubWindow")
   nodepattern(SubWindowRef)
   controlpattern()
-  result.background_color = Color(0x454545ff)
-  result.title_bar_color = Color(0x303030ff)
-  result.border_color = Color(0x212121ff)
+  result.background.setColor(Color(0x454545ff))
+  result.title_bar.setColor(Color(0x303030ff))
+  result.background.setBorderColor(Color(0x212121ff))
+  result.background.setBorderWidth(1)
   result.rect_size.x = 320
   result.rect_size.y = 220
   result.visible = false
@@ -75,8 +76,7 @@ method draw*(self: SubWindowRef, w, h: GLfloat) =
     x = -w/2 + self.global_position.x
     y = h/2 - self.global_position.y
 
-  glColor4f(self.background_color.r, self.background_color.g, self.background_color.b, self.background_color.a)
-  glRectf(x, y, x + self.rect_size.x, y - self.rect_size.y)
+  self.background.draw(x, y, self.rect_size.x, self.rect_size.y)
 
   for child in self.getChildIter():
     child.CanvasRef.calcGlobalPosition()
@@ -91,29 +91,7 @@ method draw*(self: SubWindowRef, w, h: GLfloat) =
     else:
       child.visible = true
 
-  glColor4f(self.border_color.r, self.border_color.g, self.border_color.b, self.border_color.a)
-  glBegin(GL_LINE_LOOP)
-  glVertex2f(x, y)
-  glVertex2f(x+self.rect_size.x, y)
-  glVertex2f(x+self.rect_size.x, y-self.rect_size.y)
-  glVertex2f(x, y-self.rect_size.y)
-  glEnd()
-
-  glBegin(GL_QUADS)
-
-  glColor4f(self.background_color.r, self.background_color.g, self.background_color.b, self.background_color.a)
-  glVertex2f(x+1, y-32)
-  glVertex2f(x + self.rect_size.x - 1, y-32)
-  glVertex2f(x + self.rect_size.x - 1, y - self.rect_size.y + 32)
-  glVertex2f(x+1, y - self.rect_size.y + 32)
-
-  glColor4f(self.title_bar_color.r, self.title_bar_color.g, self.title_bar_color.b, self.title_bar_color.a)
-  glVertex2f(x+1, y-1)
-  glVertex2f(x + self.rect_size.x - 1, y-1)
-  glVertex2f(x + self.rect_size.x - 1, y-31)
-  glVertex2f(x+1, y-31)
-
-  glEnd()
+  self.title_bar.draw(x, y, self.rect_size.x, 32)
 
   let size = self.title.getTextSize()
   self.title.position.x = self.rect_size.x / 2 - size.x / 2
@@ -256,7 +234,7 @@ method setBorderColor*(self: SubWindowRef, color: ColorRef) {.base.} =
   ##
   ## Arguments:
   ## - `color` is a new border color.
-  self.border_color = color
+  self.background.setBorderColor(color)
 
 
 method setIcon*(self: SubWindowRef, gltexture: GlTextureObj) {.base.} =
@@ -280,7 +258,7 @@ method setTitleBarColor*(self: SubWindowRef, color: ColorRef) {.base.} =
   ##
   ## Arguments:
   ## - `color` is a new title bar color.
-  self.title_bar_color = color
+  self.title_bar.setColor(color)
 
 
 method setTitle*(self: SubWindowRef, title: string) {.base.} =

+ 2 - 2
src/nodesnim/nodescontrol/texture_progress_bar.nim

@@ -11,6 +11,7 @@ import
   ../core/enums,
 
   ../nodes/node,
+  ../graphics/drawable,
   control
 
 
@@ -46,8 +47,7 @@ method draw*(self: TextureProgressBarRef, w, h: GLfloat) =
     y = h/2 - self.global_position.y
 
   # Background
-  glColor4f(self.background_color.r, self.background_color.g, self.background_color.b, self.background_color.a)
-  glRectf(x, y, x + self.rect_size.x, y - self.rect_size.y)
+  self.background.draw(x, y, self.rect_size.x, self.rect_size.y)
 
   # Progress
   let

+ 2 - 3
src/nodesnim/nodescontrol/texture_rect.nim

@@ -12,6 +12,7 @@ import
   ../core/color,
 
   ../nodes/node,
+  ../graphics/drawable,
   control
 
 
@@ -51,11 +52,9 @@ method draw*(self: TextureRectRef, w, h: GLfloat) =
     x = -w/2 + self.global_position.x
     y = h/2 - self.global_position.y
 
-  glColor4f(self.background_color.r, self.background_color.g, self.background_color.b, self.background_color.a)
-  glRectf(x, y, x+self.rect_size.x, y-self.rect_size.y)
+  self.background.draw(x, y, self.rect_size.x, self.rect_size.y)
   glColor4f(self.texture_filter.r, self.texture_filter.g, self.texture_filter.b, self.texture_filter.a)
 
-
   if self.texture > 0'u32:
     glEnable(GL_TEXTURE_2D)
     glBindTexture(GL_TEXTURE_2D, self.texture)

+ 0 - 7
src/nodesnim/nodescontrol/vbox.nim

@@ -61,13 +61,6 @@ method addChild*(self: VBoxRef, child: NodeRef) =
 
 method draw*(self: VBoxRef, w, h: GLfloat) =
   ## This uses in the `window.nim`.
-  let
-    x = -w/2 + self.global_position.x
-    y1 = h/2 - self.global_position.y
-
-  glColor4f(self.background_color.r, self.background_color.g, self.background_color.b, self.background_color.a)
-  glRectf(x, y1, x+self.rect_size.x, y1-self.rect_size.y)
-
   var
     fakesize = self.getChildSize()
     y = self.rect_size.y*self.child_anchor.y1 - fakesize.y*self.child_anchor.y2

+ 3 - 3
src/nodesnim/nodescontrol/vslider.nim

@@ -11,6 +11,7 @@ import
   ../core/enums,
 
   ../nodes/node,
+  ../graphics/drawable,
   control
 
 
@@ -33,7 +34,7 @@ proc VSlider*(name: string = "VSlider"): VSliderRef =
     var slider = VSlider("VSlider")
   nodepattern(VSliderRef)
   controlpattern()
-  result.background_color = Color(1f, 1f, 1f)
+  result.background.setColor(Color(1f, 1f, 1f))
   result.rect_size.x = 40
   result.rect_size.y = 120
   result.progress_color = Color(0.5, 0.5, 0.5)
@@ -51,8 +52,7 @@ method draw*(self: VSliderRef, w, h: GLfloat) =
     y = h/2 - self.global_position.y
 
   # Background
-  glColor4f(self.background_color.r, self.background_color.g, self.background_color.b, self.background_color.a)
-  glRectf(x, y, x + self.rect_size.x, y - self.rect_size.y)
+  self.background.draw(x, y, self.rect_size.x, self.rect_size.y)
 
   # Progress
   let progress = self.rect_size.y * (self.value.float / self.max_value.float)