Пример #1
0
PaletteView::PaletteView(bool editable)
  : Widget(palette_view_type())
  , m_currentEntry(-1)
  , m_rangeAnchor(-1)
  , m_selectedEntries(Palette::MaxColors, false)
{
  m_editable = editable;
  m_columns = 16;
  m_boxsize = 6;

  this->setFocusStop(true);

  this->border_width.l = this->border_width.r = 1 * jguiscale();
  this->border_width.t = this->border_width.b = 1 * jguiscale();
  this->child_spacing = 1 * jguiscale();
}
Пример #2
0
bool ColorButton::onProcessMessage(Message* msg)
{
  switch (msg->type) {

    case JM_CLOSE:
      if (m_frame && m_frame->isVisible())
	m_frame->closeWindow(NULL);
      break;

    case JM_MOUSEENTER:
      app_get_statusbar()->showColor(0, "", m_color, 255);
      break;

    case JM_MOUSELEAVE:
      app_get_statusbar()->clearText();
      break;

    case JM_SIGNAL:
      if (msg->signal.num == JI_SIGNAL_BUTTON_SELECT) {
	// If the popup window was not created or shown yet..
	if (m_frame == NULL || !m_frame->isVisible()) {
	  // Open it
	  openSelectorDialog();
	}
	else if (!m_frame->is_moveable()) {
	  // If it is visible, close it
	  closeSelectorDialog();
	}
	return true;
      }
      break;

    case JM_MOTION:
      if (hasCapture()) {
	Widget* picked = ji_get_default_manager()->pick(msg->mouse.x, msg->mouse.y);
	Color color = m_color;

	if (picked && picked != this) {
	  // Pick a color from another color-button
	  if (ColorButton* pickedColBut = dynamic_cast<ColorButton*>(picked)) {
	    color = pickedColBut->getColor();
	  }
	  // Pick a color from the color-bar
	  else if (picked->type == palette_view_type()) {
	    color = ((PaletteView*)picked)->getColorByPosition(msg->mouse.x, msg->mouse.y);
	  }
	  // Pick a color from a editor
	  else if (picked->type == editor_type()) {
	    Editor* editor = static_cast<Editor*>(picked);
	    Sprite* sprite = editor->getSprite();
	    int x, y, imgcolor;

	    if (sprite) {
	      x = msg->mouse.x;
	      y = msg->mouse.y;
	      editor->screenToEditor(x, y, &x, &y);
	      imgcolor = sprite->getPixel(x, y);
	      color = Color::fromImage(sprite->getImgType(), imgcolor);
	    }
	  }
	}

	// Did the color change?
	if (color != m_color) {
	  setColor(color);
	}
      }
      break;

    case JM_SETCURSOR:
      if (hasCapture()) {
	jmouse_set_cursor(JI_CURSOR_EYEDROPPER);
	return true;
      }
      break;

  }

  return ButtonBase::onProcessMessage(msg);
}