AndyObtiva / glimmer-dsl-libui

Glimmer DSL for LibUI - Prerequisite-Free Ruby Desktop Development Cross-Platform Native GUI Library - The Quickest Way From Zero To GUI - If You Liked Shoes, You'll Love Glimmer! - No need to pre-install any prerequisites. Just install the gem and have platform-independent GUI that just works on Mac, Windows, and Linux.
MIT License
458 stars 15 forks source link

shape_coloring.rb - I believe there is a very, very small(ish) bug, not sure if worthy to fix it, but at the least it should be reported #25

Open rubyFeedback opened 2 years ago

rubyFeedback commented 2 years ago

Hey there Andy,

I just tested shape_coloring.rb.

It works and is quite neat. glimmer-dsl-libui is like going the way for kids-drawing sketches! :D

Would be fun if the whole glimmer-suite becomes like a kids-platform (aka to use it to create stuff, even without being a programmer), but I digress.

The basic functionality of shape_coloring.rb works fine, but I noticed one small problem with the ... bezier ellipsoid thingy. The shape on the bottom right.

I believe it is best to show an image here, I will link in from imgur (not sure whether you can embed directly in github issue requests but I hope this link in is no big bother, on my linux machine I can mouse middle-click and it opens in a new tab):

https://i.imgur.com/ReXOxwa.png

I am not sure if you can instantly spot the problem, so let me also describe it.

On that image you can see that I have selected the most bototm right shape. It's a bit like a half-circle thingy, not sure how it is called ... other than a half-circle. :P (But it reminds me a bit of these bezier curves too, my memory is probably contaminated with GIMP tutorials from years ago...)

The curved area is correctly selected via red. But the upper area is not selected red at all, so I assume the code currently does not include these parts. But I think the code works fine in general, because the full circle, when I click on it, correctly has ALL of its border red, thus indicating the selection. The other objects all work fine, so only that half-circle thingy for some reason does not correctly highlight everything; the full circle does, though, which is peculiar.

Not sure if it is worth to report this tiny bug but either way I think reporting is bettter at the least just so that you know. And perhaps you get a weekend with beer to fix things in the future! \o/

PS: One reason I mentioned kids is not solely due to glimmer, but I remember _why used to have his comics kind of relate to a younger audience too, and before he quit, things such as the original shoes KIND of tap into that. And the turtle drawing program if you know that, e. g. where kids can tell the turtle to move, or rather to input commands that is then drawn into bars and circles and stuff. So that's why it reminded me ... glimmer reminds me a bit of the original shoes in some ways. I wonder if _why ever contacted you. I know baweaver did, the original badger. :P

rubyFeedback commented 2 years ago

Oh yes, I forgot, just for quick copy/paste, or if anyone else wants to test, here is the code as-is, I got it from the official webpage for glimmer libui:

require 'glimmer-dsl-libui'

class ShapeColoring
  include Glimmer::LibUI::Application

  COLOR_SELECTION = Glimmer::LibUI.interpret_color(:red)

  before_body {
    @shapes = []
  }

  body {
    window('Shape Coloring', 200, 200) {
      margined false

      grid {
        label("Click a shape to select and\nchange color via color button") {
          left 0
          top 0
          hexpand true
          halign :center
          vexpand false
        }

        color_button { |cb|
          left 0
          top 1
          hexpand true
          vexpand false

          on_changed do
            @selected_shape&.fill = cb.color
          end
        }

        area {
          left 0
          top 2
          hexpand true
          vexpand true

          rectangle(0, 0, 600, 400) { # background shape
            fill :white
          }

          @shapes << colorable(:rectangle, 20, 20, 40, 20) {
            fill :lime
          }

          @shapes << colorable(:square, 80, 20, 20) {
            fill :blue
          }

          @shapes << colorable(:circle, 75, 70, 20) {
            fill :green
          }

          @shapes << colorable(:arc, 120, 70, 40, 0, 145) {
            fill :orange
          }

          @shapes << colorable(:polygon, 120, 10, 120, 50, 150, 10, 150, 50) {
            fill :cyan
          }

          @shapes << colorable(:polybezier, 20, 40,
                     30, 100, 50, 80, 80, 110,
                     40, 120, 20, 120, 30, 91) {
            fill :pink
          }
        }
      }
    }
  }

  def colorable(shape_symbol, *args, &content)
    send(shape_symbol, *args) do |shape|
      on_mouse_up do |area_mouse_event|
        old_stroke = Glimmer::LibUI.interpret_color(shape.stroke).slice(:r, :g, :b)
        @shapes.each {|sh| sh.stroke = nil}
        @selected_shape = nil
        unless old_stroke == COLOR_SELECTION
          shape.stroke = COLOR_SELECTION.merge(thickness: 2)
          @selected_shape = shape
        end
      end

      content.call(shape)
    end
  end
end

ShapeColoring.launch
AndyObtiva commented 2 years ago

Hi @rubyFeedback,

Thank you for your feedback.

The good news is what you ask for in the case of "Glimmer for Kids" and turtle graphics already exists in the DCR Programming Language (written using Glimmer DSL for SWT), which is short for Draw Color Repeat.

DCR Sample

I'd be happy to port it into Glimmer DSL for LibUI.

The shape you mentioned is in fact an arc, which is a part of a circle, so you were almost right about calling it half circle, though the arc angle is less than half of a circle (145 degrees only, not 180 degress as required by half circles).

SWT supports drawing an arc with a stroked border around its inner area. C libui does not currently support that, which is why when you stroke it, you do not see a red border on the inside of the arc.

You are welcome to open this as an issue in C libui.