Iván Briano (Sachiel) wrote:
>>
>> The source of showcase.edc is attached, too, to just have a glimpse at
>> Lua inside of EDC
>>
>>     
>
> No, it's not. Make sure it gets attached as text/plain or the list
> will strip it out.
>   
Sorry, second try then ...
-- 
  Hanspeter Portner
  vento...@airpost.net

-- 
http://www.fastmail.fm - Access all of your messages and folders
                          wherever you are

images {
   image: "gauge_base.png" COMP;
   image: "gauge_light.png" COMP;
}

fonts { 
   font: "Vera.ttf" "default";
   font: "VeraBd.ttf" "bold";
}

collections {
   group {
      name: "gauge";
      lua_script {
         function _get_pos(ed)
            local x, y, w, h, pos
            x, y = unpack (ed.mouse)
            _, _, w, h = unpack (ed.geometry)
            pos = 1+math.atan2 (y-h, x-w/2) / math.pi
            if pos > 1 and x < w/2 then pos = 0 end
            if pos > 1 and x > w/2 then pos = 1 end
            return pos
         end

         function _update(ed)
            if ed.range and ed.format and ed.value then
               ed.label.text = string.format (ed.format, ed.value)
               if ed.is_int then
                  ed:message_send (MESSAGE_INT, 1, ed.value)
               else
                 ed:message_send (MESSAGE_FLOAT, 1, ed.value)
               end

               local custom, pos, phi, x, y
               custom = ed.arrow:custom_state ("default", 0.0)
               pos = (ed.value - ed.range[1]) / (ed.range[2] - ed.range[1])
               ed:message_send (MESSAGE_FLOAT, 2, pos)
               phi = pos * math.pi
               x = 0.5 - 0.5*math.cos (phi)*0.7
               y = 1 - math.sin (phi)*0.7
               custom.rel1 = {x - 0.07, y - 0.17}
               custom.rel2 = {x + 0.07, y + 0.17}
               custom.color = {255, pos*255, pos*255, 255}
               ed.arrow.state = {'custom', 0.0}
            end
         end

         function message(ed, typ, id, ...)
            if id == 0 then
               if typ == MESSAGE_FLOAT_SET then
                  ed.is_int = false
                  ed.range = ...
               elseif typ == MESSAGE_INT_SET then
                  ed.is_int = true
                  ed.range = ...
               elseif typ == MESSAGE_FLOAT then
                  ed.is_int = false
                  ed.value = ...
               elseif typ == MESSAGE_INT then
                  ed.is_int = true
                  ed.value = ...
               elseif typ == MESSAGE_STRING then
                  ed.format = ...
               end
               _update(ed)
            end
            if id == 1 and (typ == MESSAGE_INT or typ == MESSAGE_FLOAT) then
               -- here we listen for changes of the value
            end
         end
      }
      parts {
         part {
            name: "base";
            type: IMAGE;
            description {
               state: "default" 0.0;
               rel1.relative: 0 0;
               rel2.relative: 1 1;
               image.normal: "gauge_base.png";
            }
         }
         part {
            name: "arrow";
            type: GROUP;
            source: "arrow";
            description {
               state: "default" 0.0;
               rel1.relative: 0.05 0.75;
               rel2.relative: 0.15 0.95;
            }
         }
         part {
            name: "label";
            type: TEXT;
            effect: SOFT_SHADOW;
            description {
               state: "default" 0.0;
               rel1.relative: 0.0 0.5;
               rel2.relative: 1.0 1.0;
               color: 255 255 255 255;
               color3: 255 0 0 128;
               text {
                  text: "label";
                  font: "default";
                  size: 16;
                  align: 0.5 0.5;
               }
            }
         }
         part {
            name: "light";
            type: IMAGE;
            description {
               state: "default" 0.0;
               rel1.relative: 0 0;
               rel2.relative: 1 1;
               image.normal: "gauge_light.png";
            }
         }
         part {
            name: "event";
            type: RECT;
            mouse_events: 1;
            description {
               state: "default" 0.0;
               rel1.relative: 0 0;
               rel2.relative: 1 1;
               color: 255 255 255 0;
            }
         }
      }
      programs {
         program {
            signal: "show";
            source: "*";
            lua_script {
               ed:message_send (MESSAGE_STRING, 0, '%.1f%%') -- format
               ed:message_send (MESSAGE_FLOAT_SET, 0, {0, 100}) -- range
               ed:message_send (MESSAGE_FLOAT, 0, math.random (100)) -- value
            }
         }
         program {
            signal: "mouse,down,1";
            source: "event";
            lua_script {
               if ed.anim then ed.anim:del () end
               local pos = _get_pos (ed)
               ed:message_send (MESSAGE_FLOAT, 0, pos*100)
               grab = true
            }
         }
         program {
            signal: "mouse,up,1";
            source: "event";
            lua_script {
               if ed.anim then ed.anim:del () end
               grab = false
            }
         }
         program {
            signal: "mouse,up,3";
            source: "event";
            lua_script {
               if ed.anim then ed.anim:del () end
               ed.anim = ed:animator(coroutine.wrap(function(self)
                  for itr = ed.value, 0, -100*ed.frametime do
                     ed:message_send (MESSAGE_FLOAT, 0, itr)
                     coroutine.yield (CALLBACK_RENEW)
                  end
                  return CALLBACK_CANCEL
               end))
            }
         }
         program {
            signal: "mouse,move";
            source: "event";
            lua_script {
               if grab then
                  local pos = _get_pos (ed)
                  ed:message_send (MESSAGE_FLOAT, 0, pos*100)
               end
            }
         }
      }
   }
   group {
      name: "arrow";
      lua_script_only: 1;
      lua_script {
         function init (ed)
            poly = ed:polygon {
               anti_alias = true,
               pos = 0,
               recalc = function(self)
                  local X, Y = {0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 
0}
                  local x, y, w, h = unpack (ed.geometry)
                  local pi, cos, sin = math.pi, math.cos, math.sin
                  local pos = self.pos
                  local phi = pi*(pos-1)
                  local dphi = pi / 1.3
                  self.color = {255, pos*255, pos*255, 255}
                  X[1], Y[1] = x+w*(0.5+0.5*cos(phi)), y+h*(0.5+0.5*sin(phi))
                  X[2], Y[2] = x+w*(0.5+0.5*cos(phi+dphi)), 
y+h*(0.5+0.5*sin(phi+dphi))
                  X[3], Y[3] = x+w*(0.5+0.5*cos(phi+dphi*1.4)), 
y+h*(0.5+0.5*sin(phi+dphi*1.4))
                  X[4], Y[4] = x+w*(0.5+0.3*cos(phi+dphi*1.4)), 
y+h*(0.5+0.3*sin(phi+dphi*1.4))
                  X[5], Y[5] = x+w*(0.5+0.3*cos(phi+dphi)), 
y+h*(0.5+0.3*sin(phi+dphi))
                  X[6], Y[6] = x+w*(0.5+0.2*cos(phi)), y+h*(0.5+0.2*sin(phi))
                  X[7], Y[7] = x+w*(0.5+0.2*cos(phi-dphi)), 
y+h*(0.5+0.2*sin(phi-dphi))
                  X[8], Y[8] = x+w*(0.5+0.5*cos(phi-dphi)), 
y+h*(0.5+0.5*sin(phi-dphi))
                  self:points_clear ()
                  for i, _ in ipairs (X) do
                    self:point_add (X[i], Y[i])
                  end
               end
            }
            poly:recalc ()
         end

         function shutdown (ed)
            poly:del ()
         end

         function show (ed)
            poly:show ()
         end

         function hide (ed)
            poly:hide ()
         end

         function move (ed, x, y)
            poly:recalc ()
         end

         function resize (ed, w, h)
            poly:recalc ()
         end

         function message (ed, typ, id, ...)
            if (typ == MESSAGE_FLOAT or typ == MESSAGE_INT) and id == 2 then
               poly.pos = ...
               poly:recalc ()
            end
         end
      }
   }
   group {
      name: "main";
      min: 400 200;
      max: 500 250;
      parts {
         part {
            name: "gauge1";
            type: GROUP;
            source: "gauge";
            description {
               state: "default" 0.0;
               rel1.relative: 0.0 0.0;
               rel2.relative: 0.5 0.5;
            }
         }
         part {
            name: "gauge2";
            type: GROUP;
            source: "gauge";
            description {
               state: "default" 0.0;
               rel1.relative: 0.0 0.5;
               rel2.relative: 0.5 1.0;
            }
         }
         part {
            name: "gauge3";
            type: GROUP;
            source: "gauge";
            description {
               state: "default" 0.0;
               rel1.relative: 0.5 0.0;
               rel2.relative: 1.0 0.5;
            }
         }
         part {
            name: "gauge4";
            type: GROUP;
            source: "gauge";
            description {
               state: "default" 0.0;
               rel1.relative: 0.5 0.5;
               rel2.relative: 1.0 1.0;
            }
         }
      }
   }
}

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to