[Y-devel] State of the Widgets

Fred P. fprog26 at hotmail.com
Sat Feb 28 08:43:42 GMT 2004


>On Fri, Feb 27, 2004 at 05:46:31PM -0800, Carl Jantzen wrote:
>>I agree with Fred. Java implements a very similar method, where anything 
>>can implement a MouseListener. The MouseListener recieves MouseEvents 
>>whenever the mouse is moved, clicked, or released.
>> >
>> >
>> >You guys are making WAY TOO complicated, when it could be much simpler 
>> >than that...

>I don't think I was understood. You guys are very much saying,
>"No, no, doing it with method XYZ is much to complicated, you should
>do it like Java does," and then you're describing method XYZ.

I was not talking about Java at all, but how most SVG GUI toolkit are 
built...
Like CGUI or mine JGUI.

https://homepage.usask.ca/~ctl271/cgui/index.shtml
https://resource-solutions.de/svgeditor/
https://j2k.sourceforge.net/svg/august11/btn_def78.svg

One of the problems in SVG, is that the "viewer"
doesn't support native XUL/XFORM widgets
and that every "theme" needs to reimplement
all event handling from scratch each time and that sucks...
[provides only: keypress, keydown, keyup, mousemove, mouseup, mousedown, 
mouseclick]
Therefore if you need to drag'n'drop, or have a combo box, list box, 
scrollbar, menu,
toolbar, button or similar... you must reinvent the wheel every time...

Following what I wrote on the Widget Wiki:
https://y-win-wiki.jciteassist.org/y-win-wiki/Widget

>theme-module contains the code that actually draws to the screen.
>'DrawButton' in theme module is analagous to shape->draw here.

True and untrue.

You don't ask the theme to draw a button, but part of it...
You don't want the theme to deal with mouseover thingy

Basically, the theme has many draw "button" parts...

Button background, button border, button text, over and non-over and 
clicked.

When you draw the "background", the background drawing method return a 
Widget*
and that is what you use to know if it's in  "button area" or not.

For complicated shapes, Widget* could be a link list of Widget*
For instance a circle+rectangle+circle... (_______)

The server when he receives an event have a linklist of 
circle1->next=rectangle->next=circle2
and do something like

bool b = inscope( circle1 );

bool Container::inArea(Widget* head, Event* event)
{
  bool b = false;
  while( !b && head )
  {
    b = head->within( event->x, event->y );
    head = head->next;
  }

  return b;
}

>I am saying -exactly- that we need to ask the module that does the drawing 
>whether points are inside or outside of the drawing, because
>that's, in my opinion and apparently everyone else's, the only sane
>way to do it.

No it's not, ask the server.

The theme draws widget, the server knows what widget are drawn and in which 
context
(button, slider, menu, combobox), why do the theme needs to know?

The theme need to know how to draw widget of different size,
the *magic* happens on the server side (common widget code).

In fact, the theme could be "evaluated code" or parametrized.
but for that you need a simple Interpreter pattern with maybe some 
Reflection.
A simpler way is as is currently, compiled theme C modules
or use XUL/SVG or similar.


Toolbar button 22x22 Win98 style example:

<svg width='1024' height='700' enableZoomAndPanControls='false'
   xmlns='https://www.w3.org/2000/svg'
   xmlns:xlink='https://www.w3.org/1999/xlink'
>
<defs style="shape-rendering: optimizeSpeed; ">
    <pattern id='BtnBackground' patternUnits='userSpaceOnUse'
             x='0' y='0' width='2' height='2'
             viewBox="0 0 2 2" >
      <rect style='fill:#c0c0c0' width='2' height='2' x='0' y='0'/>
    </pattern>
    <g id='btn_blank_flat22'>
      <rect style='fill:url(#BtnBackground)'  width='22' height='22' x='0' 
y='0'/>
    </g>
    <g id='btn_blank_over22'>
      <rect style='fill:#FFFFFF' width='22' height='21' x='0' y=' 0'/>
      <rect style='fill:#808080' width='21' height='21' x='1' y=' 1'/>
      <rect style='fill:#808080' width=' 1' height=' 1' x='0' y='21'/>
      <rect style='fill:url(#BtnBackground)'  width='20' height='20' x='1' 
y='1'/>
    </g>
    <g id='btn_blank_down22'>
      <rect style='fill:#808080' width='22' height='21' x='0' y=' 0'/>
      <rect style='fill:#FFFFFF' width='21' height='21' x='1' y=' 1'/>
      <rect style='fill:#FFFFFF' width=' 1' height=' 1' x='0' y='21'/>
      <rect style='fill:url(#BtnBackground)'  width='20' height='20' x='1' 
y='1'/>
    </g>
    <g id='btn_blank_push22'>
      <use xlink:href='#btn_blank_down22'  x='0' y='0'/>
      <rect style='fill:url(#ShadePatternD0)' width='20' height='20' x='1' 
y='1'/>
    </g>
</defs>

<!-- Then all you do is cycle through them: -->


    <g id='toolbar_all_view' drag='true' clone='false'
       onmouseover="TranslateMouseOver(evt)"
        onmouseout="TranslateMouseOut(evt)"
       onmousemove="TranslateMouseMove(evt)"
      onmousedown="TranslateMouseDown(evt)"
         onmouseup="TranslateMouseUp(evt)">

        <g id='btn_incfontsize'   button='toolbar' drag='false' 
clone='false' state='flat'
          onclick="updateLayoutPlus(evt)"
        >
          <use xlink:href='#btn_blank_flat22'   x='394' y='3'/>
          <!-- use xlink:href='#growfont'           x='397' y='10'/ -->
        </g>
</g>

<script><![CDATA[
var xlink_ns = 'https://www.w3.org/1999/xlink';
var dragger           = null;
var origTransform = "";
var origStyle     = "";
var origX;
var origY;
var oldTranslateX;
var oldTranslateY;
// Perl-like regexp in JavaScript
var translateRegExp=/translate\(([-+]?\d+)(\s*[\s,]\s*)([-+]?\d+)\)\s*/
var status = "";
function TranslateMouseOver(evt)
{
  if ( !evt ) return true;
  var target = getEventTarget(evt);
  if ( target && target.getAttribute('state') )
  {
    var state = target.getAttribute('state');
    var use0  = target.getElementsByTagName("use").item(0);
    //alert( 'over' );
    if ( target.getAttribute('pstate') && target.getAttribute('pstate') == 
'push' )
    {
      target.setAttribute( 'state', 'push' );
      use0.setAttributeNS( xlink_ns,'xlink:href', '#btn_blank_push22' );
    }
    else
    //if ( state != 'push' )
    {
      target.setAttribute( 'state', 'over' );
      use0.setAttributeNS( xlink_ns,'xlink:href', '#btn_blank_over22' );
    }
  }
}
function TranslateMouseMove(evt)
{
  if ( !evt ) return true;
  if( dragger != null )
  {
    var target = getEventTarget(evt);
    PerformTranslation(evt, target);
  }
  // Propagate the event to other handlers.
  return true;
}
function TranslateMouseDown(evt)
{
  if ( !evt ) return true;
  var target = getEventTarget(evt);
  if ( target && target.getAttribute('state') )
  {
    var state = target.getAttribute('state');
    var use0  = target.getElementsByTagName("use").item(0);
    //if ( state != 'push' )
    {
      target.setAttribute( 'state', 'down' );
      use0.setAttributeNS( xlink_ns,'xlink:href', '#btn_blank_down22' );
    }
  }
  if ( target && target.getAttribute("drag") != "false" )
  {
    if ( target.getAttribute("clone") == "true" )
    {
      target = CloneContent( evt );
    }
    dragger = target;

    origTransform = dragger.getAttribute("transform");
    origStyle     = dragger.getAttribute("style");
    if (origTransform == null)
    {
      origTransform = "";
    }
    else
    {
      origTransform = new String(origTransform);
    }
    origX = evt.getClientX();
    origY = evt.getClientY();
    oldTranslateX = 0;
    oldTranslateY = 0;
    if (origTransform.length != 0)
    {
      var result = origTransform.match(translateRegExp);
      if (result == null || result.index == -1)
      {
        alert("The regular expression had a problem finding the translate at 
the end of \"" + origTransform + "\"");
        oldTranslateX = 0;
        oldTranslateY = 0;
      }
      else
      {
        oldTranslateX = parseFloat(result[1]);
        oldTranslateY = parseFloat(result[3]);
        origTransform = origTransform.substr(0, result.index);
      }
    }
    PerformTranslation(evt, target);
  }
  // Propagate the event to other handlers.
  return true;
}
function TranslateMouseOut(evt)
{
  if ( !evt ) return true;
  var target = getEventTarget(evt);
  if ( target && target.getAttribute('state') )
  {
    var state = target.getAttribute('state');
    var use0  = target.getElementsByTagName("use").item(0);
    if ( target.getAttribute('pstate') && target.getAttribute('pstate') == 
'push' )
    {
      target.setAttribute( 'state', 'push' );
      use0.setAttributeNS( xlink_ns,'xlink:href', '#btn_blank_push22' );
    }
    else
    //if ( state != 'push' )
    {
      target.setAttribute( 'state', 'flat' );
      use0.setAttributeNS( xlink_ns,'xlink:href', '#btn_blank_flat22' );
    }
  }
}
function TranslateMouseUp(evt)
{
  if ( !evt ) return true;
  var target = getEventTarget(evt);
  if( dragger != null )
  {
    if (dragger.getAttribute("id") != "shapeBar")
    {
      dragger.setAttribute("style", origStyle);
      if (dragger.getAttribute("clone") == "false")  // i.e. This must be an 
icon on the map.
      {
        // Update the (x,y) status
      }
    }
    origTransform = "";
    origX = 0;
    origY = 0;
    oldTranslateX = 0;
    oldTranslateY = 0;
    //dragger = null;
    ToolbarDrop(evt);
  }
  // Propagate the event to other handlers.
  return true;
}
]]>
</script>
</svg>

etc.

In other words, the theme have a list of drawing <defs>
draw such rectangle here and there with such offset.
and the widget server draw those widget parts as needed
and deals with all the interaction (behavior), since it knows how to deal 
with widget.
It as a list of all the drawing, so there's no need to ask the theme,
just ask the list if it's in scope or not.


Fred.

_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*.  
https://join.msn.com/?page=features/photos&pgmarket=en-ca&RU=http%3a%2f%2fjoin.msn.com%2f%3fpage%3dmisc%2fspecialoffers%26pgmarket%3den-ca




More information about the Y-devel mailing list









2026 © www.Y-Windows.Org - All Rights Reserved