Пример #1
0
void Layer::setValue(const string& key, const Variant& v, bool animated)
{
  bool setWithoutAnimation = false;
  if(animated)
  {
    auto pos = key2action.find(key);
    if(pos != key2action.end())
    {
      addAnimation(key, pos->second(key, v));
    }
    else
    {
      WOUT("no animation found for key: "<<key);
      setWithoutAnimation = true;
    }
  }
  
  if(!animated or setWithoutAnimation)
  {
    auto pos = key2setter.find(key);
    if(pos != key2setter.end())
    {
      pos->second(v);
    }
    else
    {
      WOUT("couldn't find setter for key '"<<key<<"'");
    }
  }
}
Пример #2
0
void Layer::addSublayer(const LayerPtr& layer)
{
  if(!isSublayer(layer))
  {
    if(layer->superlayer)
    {
      WOUT("added layer that already had superlayer: "<<layer->description());
    }
    layer->superlayer = this;
    sublayers.push_back(layer);
  }
  else
  {
    WOUT("tried to add layer that was already sublayer: "<<layer->description());
  }
}
Пример #3
0
void Layer::removeFromSuperlayer()
{
  if(superlayer)
  {
    superlayer->removeSublayer(shared_from_this());
  }
  else
  {
    WOUT("called removeFromSuperlayer() on layer without superlayer: "<<description());
  }
}
Пример #4
0
void View::addSubview(const ViewPtr& view)
{
  if(!containsSubview(view))
  {
    if(!view->superview)
    {
      subviews.push_back(view);
      layer->addSublayer(view->layer);
      view->superview = this;
    }
    else
    {
      WOUT("tried to insert subview that already had superview");
    }
  }
  else
  {
    WOUT("tried to insert subview that is already contained in this view, ignoring");
  }
}
Пример #5
0
void View::removeSubview(const ViewPtr& view)
{
  if(containsSubview(view))
  {
    if(view->superview == this)
    {
      subviews.remove(view);
      layer->removeSublayer(view->layer);
      view->superview = NULL;
      needsRedraw();
    }
    else
    {
      WOUT("tried to remove subview that was part of this view, but didn't have the correct superview, ignoring");
    }
  }
  else
  {
    WOUT("tried to remove subview that wasn't part of this view, ignoring");
  }
}
Пример #6
0
void Layer::removeSublayer(const LayerPtr& layer)
{
  auto pos = std::find(sublayers.begin(), sublayers.end(), layer);
  if(pos != sublayers.end())
  {
    LayerPtr sublayer = *pos;
    sublayer->superlayer = NULL;
    sublayers.erase(pos);
  }
  else
  {
    WOUT("tried to remove layer that wasn't sublayer: "<<layer->description());
  }
}
Пример #7
0
void DrawContext::drawImage(const ImagePtr& image, const Rect& rect, const Color& col)
{
  switch(image->resizeMode)
  {
    case ImageResizeModeStretch:drawImageStretched(image, rect, col);break;
    case ImageResizeModeNinePatch:drawImageNinepatched(image, rect, col);break;
    case ImageResizeModeTile:drawImageTiled(image, rect, col);break;
    default:
    {
      WOUT("dont' know what to do with ImageResizeMode"<<image->resizeMode);
      break;
    }
  }
}
Пример #8
0
void EventSystem::propagateUpDownEvent(Event* event)
{
  EventType et = event->base.type;
  if(et == ET_MouseDown)
  {
    if(currentViewStack.size() == 0)
    {
      WOUT("currentViewStack was empty!");
      return;
    }
  
    event->base.target = currentViewStack.back();
    propagateEvent(currentViewStack, event, (s32)currentViewStack.size()-1);
    previousMouseClickStack = currentViewStack;
  }
  else if(et == ET_MouseUp)
  {
    s32 oldIndex = previousMouseClickStack.size() > 0 ? (s32)previousMouseClickStack.size()-1 : -1;
    s32 newIndex = currentViewStack.size() > 0 ? (s32)currentViewStack.size()-1 : -1;
    View* oldView = oldIndex > 0 ? previousMouseClickStack[oldIndex] : NULL;
    View* newView = newIndex > 0 ? currentViewStack[newIndex] : NULL;
    if(oldView && (oldView != newView))
    {
      event->base.target = oldView;
      event->base.type = ET_MouseUpOutside;
      event->base.bubbles = true;
      propagateEvent(previousMouseClickStack, event, oldIndex);
      event->base.bubbles = true;
      event->base.type = ET_MouseUp;
      propagateEvent(previousMouseClickStack, event, oldIndex);
    }
    if(newView)
    {
      event->base.target = newView;
      event->base.type = ET_MouseUpInside;
      event->base.bubbles = true;
      propagateEvent(currentViewStack, event, newIndex);
      event->base.type = ET_MouseUp;
      event->base.bubbles = true;
      propagateEvent(currentViewStack, event, newIndex);
    }
    previousMouseClickStack = currentViewStack;
  }
}
Пример #9
0
Rect Layer::calculateDrawRectFor(const Rect& originalRect, const ImagePtr& img, LayerContentMode mode)
{
  Rect result = originalRect;
  
  switch(img->resizeMode)
  {
    case ImageResizeModeNinePatch:break; // do nothing since ninepatch will always span all of the original rect
    case ImageResizeModeTile:break; // do nothing, because image will be tiled acros all of the original rect
    case ImageResizeModeStretch: // adjust to content mode
    {
      switch(mode)
      {
        case LayerContentModeScaleToFill:break; // do nothing, results in original rect
        case LayerContentModeScaleAspectFit: // squeeze image into available space, preserving aspect ratio
        {
          f32 scale = 1;
          if(img->size.height > img->size.width)
          {
            scale = originalRect.height / img->size.height;
          }
          else
          {
            scale = originalRect.width / img->size.width;
          }
          result.width = floorf(img->size.width * scale);
          result.height = floorf(img->size.height * scale);
          result.centerWithin(originalRect);
          break;
        }
        case LayerContentModeScaleAspectFill: // scale image to fill available space, preserving aspect ratio
        {
          f32 scale = 1;
          if(img->size.height > img->size.width)
          {
            scale = originalRect.width / img->size.width;
          }
          else
          {
            scale = originalRect.height / img->size.height;
          }
          result.width = floorf(img->size.width * scale);
          result.height = floorf(img->size.height * scale);
          result.centerWithin(originalRect);
          break;
        }
        case LayerContentModeCenter:
        {
          result.size(img->size);
          result.centerWithin(originalRect);
          break;
        }
        default:
        {
          WOUT("don't know what to do with LayerContentMode: "<<mode);
          break;
        }
      }
      break;
    }
    default:
    {
      WOUT("don't know what to do with ImageResizeMode: "<<img->resizeMode);
      break;
    }
  }
  result.floor();
  return result;
}
Пример #10
0
void DrawContext::drawImageTiled(const ImagePtr& image, const Rect& rect, const Color& col)
{
  WOUT("not implemented yet");
}
Пример #11
0
int lpc_watcher( DEV* dev, u8* buf )
{
	u32 cport, wtcport;
	u8  *s, *d;
	s16 count, i;
	u8  xcvr, cmd, tmp;
	int t;

    dbg1("%s(): dev=%08X", __FUNCTION__, (uint)dev);
    
	cport   = dev->cport;
	wtcport = dev->wtcport;

	s = d = buf;
#if 01
	__get_user(count, s++);					// Get the length
	__get_user(tmp, s++);
	count = (count << 8) + tmp;
	__get_user(cmd, s++);
	cmd &= 0x7F;
#else
	count = *s++;					// Get the length
	count = (count << 8) + *s++;
	cmd = *s++ & 0x7F;
#endif

	if( cmd ) 
    {				// Normal case: request watcher firmware
		if(!dev->wtc_exist) return -ENODEV;
		t = jiffies + HZ/2;
		WTCHS;
		WOUT((u8)(count >> 8));		// Send the length
		WTCHS;
		WOUT((u8)(count & 0xFF));
		WTCHS;
		WOUT(cmd);
		count--;
		while( count > 0 ) {
			WTCHS;
#if 01
            __get_user(tmp, s++);
			WOUT(tmp);					// Send the data bytes
#else
			WOUT(*s++);					// Send the data bytes
#endif
			count--;
		}
		WTCHS;
		WOUT(0);						   // EOM

		WTCHS;
		count = WIN;					// Receive the length
#if 01
        __put_user(count & 0xFF, d++);
		WTCHS;
		count = (count << 8) + WIN;
        __put_user(count & 0xFF, d++);
#else
		*d++ = count & 0xFF;
		WTCHS;
		count = (count << 8) + WIN;
		*d++ = count & 0xFF;
#endif

		i = count;
		while( i > 0 ) {
			WTCHS;
#if 01
			tmp = WIN;
            __put_user(tmp, d++);
#else
			*d++ = WIN;
#endif
			i--;
		}

	} else {				// Special case: firmware download