Exemple #1
0
void
RoundRect(Canvas &canvas, int left, int top,
          int right, int bottom, unsigned radius)
{
  unsigned npoly = 0;
  BulkPixelPoint pt[66*4];

  segment_poly(pt, PixelPoint(left + radius, top + radius), radius,
               INT_ANGLE_RANGE * 3 / 4,
               INT_ANGLE_RANGE - 1,
               npoly);
  segment_poly(pt, PixelPoint(right - radius, top + radius), radius,
               0, INT_ANGLE_RANGE / 4 - 1,
               npoly);
  segment_poly(pt, PixelPoint(right - radius, bottom - radius), radius,
               INT_ANGLE_RANGE / 4,
               INT_ANGLE_RANGE / 2 - 1,
               npoly);
  segment_poly(pt, PixelPoint(left + radius, bottom - radius), radius,
               INT_ANGLE_RANGE / 2,
               INT_ANGLE_RANGE * 3 / 4 - 1,
               npoly);

  assert(npoly <= ARRAY_SIZE(pt));
  if (npoly)
    canvas.DrawTriangleFan(pt, npoly);
}
Exemple #2
0
Event
MergeMouse::Generate()
{
  if (moved) {
    moved = false;
    return Event(Event::MOUSE_MOTION, PixelPoint(x, y));
  }

  if (pressed) {
    pressed = false;
    return Event(Event::MOUSE_DOWN, PixelPoint(x, y));
  }

  if (released) {
    released = false;
    return Event(Event::MOUSE_UP, PixelPoint(x, y));
  }

  if (wheel != 0) {
    Event event(Event::MOUSE_WHEEL, PixelPoint(x, y));
    event.param = unsigned(wheel);
    wheel = 0;
    return event;
  }

  return Event(Event::Type::NOP);
}
PerPixelMesh::PerPixelMesh(int width, int height) : width(width), height(height), size (width * height),
		p(width * height, PixelPoint(0,0)),
		p_original(width * height, PixelPoint(0,0)),
		identity(width * height, PerPixelContext(0,0,0,0,0,0))
		{
		for (int j=0;j<height;j++)
			for(int i=0;i<width;i++)
			{
				int index = j * width + i;

						float xval=i/(float)(width-1);
						float yval=-((j/(float)(height-1))-1);

						p[index].x = xval;
						p[index].y = yval;

						p_original[index].x = xval;
						p_original[index].y = yval;

						identity[index].x= xval;
						identity[index].y= yval;

						//identity[index].x= (xval-.5)*2;
						//identity[index].y= (yval-.5)*2;

						identity[index].i= i;
						identity[index].j= j;

						identity[index].rad=hypot ( ( xval-.5 ) *2, ( yval-.5 ) *2 ) * .7071067;
						identity[index].theta=atan2 ( ( yval-.5 ) *2 ,  ( xval-.5 ) *2  );
			}
		}
void
GlueMapWindow::DrawFlightMode(Canvas &canvas, const PixelRect &rc) const
{
  int offset = 0;

  // draw flight mode
  const MaskedIcon *bmp;

  if (Calculated().common_stats.task_type == TaskType::ABORT)
    bmp = &look.abort_mode_icon;
  else if (GetDisplayMode() == DisplayMode::CIRCLING)
    bmp = &look.climb_mode_icon;
  else if (GetDisplayMode() == DisplayMode::FINAL_GLIDE)
    bmp = &look.final_glide_mode_icon;
  else
    bmp = &look.cruise_mode_icon;

  offset += bmp->GetSize().cx + Layout::Scale(6);

  bmp->Draw(canvas,
            PixelPoint(rc.right - offset,
                       rc.bottom - bmp->GetSize().cy - Layout::Scale(4)));

  // draw flarm status
  if (!GetMapSettings().show_flarm_alarm_level)
    // Don't show indicator when the gauge is indicating the traffic anyway
    return;

  const FlarmStatus &flarm = Basic().flarm.status;
  if (!flarm.available)
    return;

  switch (flarm.alarm_level) {
  case FlarmTraffic::AlarmType::NONE:
    bmp = &look.traffic_safe_icon;
    break;
  case FlarmTraffic::AlarmType::LOW:
  case FlarmTraffic::AlarmType::INFO_ALERT:
    bmp = &look.traffic_warning_icon;
    break;
  case FlarmTraffic::AlarmType::IMPORTANT:
  case FlarmTraffic::AlarmType::URGENT:
    bmp = &look.traffic_alarm_icon;
    break;
  };

  offset += bmp->GetSize().cx + Layout::Scale(6);

  bmp->Draw(canvas,
            PixelPoint(rc.right - offset,
                       rc.bottom - bmp->GetSize().cy - Layout::Scale(2)));
}
Exemple #5
0
  PixelPoint GetMousePosition() const {
#ifdef USE_LIBINPUT
    return PixelPoint(libinput_handler.GetX(), libinput_handler.GetY());
#else
    return merge_mouse.GetPosition();
#endif
  }
Exemple #6
0
gcc_const
static PixelPoint
CirclePoint(int radius, unsigned angle)
{
  assert(angle < ARRAY_SIZE(ISINETABLE));

  return PixelPoint(ISINETABLE[angle] * radius / 1024,
                    -ISINETABLE[(angle + INT_QUARTER_CIRCLE) & INT_ANGLE_MASK] * radius / 1024);
}
Exemple #7
0
gcc_visibility_default
JNIEXPORT void JNICALL
Java_org_xcsoar_NativeView_resizedNative(JNIEnv *env, jobject obj,
                                         jint width, jint height)
{
  if (event_queue == nullptr)
    return;

  if (CommonInterface::main_window != nullptr)
    CommonInterface::main_window->AnnounceResize({width, height});

  event_queue->Purge(Event::RESIZE);

  Event event(Event::RESIZE, PixelPoint(width, height));
  event_queue->Push(event);
}
Exemple #8
0
void
MergeMouse::MoveAbsolute(int new_x, int new_y,
                         int min_x, int max_x, int min_y, int max_y)
{
  /* scale touschreen coordinates to screen size */

  if (new_x < min_x)
    new_x = 0;
  else if (max_x > min_x)
    new_x = new_x * int(rotate.GetWidth()) / (max_x - min_x);

  if (new_y < min_y)
    new_y = 0;
  else if (max_y > min_y)
    new_y = new_y * int(rotate.GetHeight()) / (max_y - min_y);

  /* now call the "real" MoveAbsolute() */
  MoveAbsolute(PixelPoint(new_x, new_y));
}
Exemple #9
0
inline void
LinuxInputDevice::Read()
{
  struct input_event buffer[64];
  boost::system::error_code ec;
  const size_t nbytes = fd.read_some(boost::asio::buffer(buffer,
                                                         sizeof(buffer)),
                                     ec);
  if (ec) {
    /* device has failed or was unplugged - bail out */
    if (errno != boost::asio::error::try_again &&
        errno != boost::asio::error::interrupted)
      Close();
    return;
  }

  unsigned n = size_t(nbytes) / sizeof(buffer[0]);

  for (unsigned i = 0; i < n; ++i) {
    const struct input_event &e = buffer[i];

    switch (e.type) {
    case EV_SYN:
      if (e.code == SYN_REPORT) {
        /* commit the finger movement */

        const bool pressed = pressing;
        const bool released = releasing;
        pressing = releasing = false;

        if (pressed)
          merge.SetDown(true);

        if (released)
          merge.SetDown(false);

        if (IsKobo() && released) {
          /* workaround: on the Kobo Touch N905B, releasing the touch
             screen reliably produces a finger position that is way
             off; in that case, ignore finger movement */
          moving = false;
          edit_position = public_position;
        }

        if (moving) {
          moving = false;
          public_position = edit_position;
          merge.MoveAbsolute(public_position.x, public_position.y,
                             min_x, max_x, min_y, max_y);
        } else if (rel_x != 0 || rel_y != 0) {
          merge.MoveRelative(PixelPoint(rel_x, rel_y));
          rel_x = rel_y = 0;
        }

        if (rel_wheel != 0) {
          merge.MoveWheel(rel_wheel);
          rel_wheel = 0;
        }
      }

      break;

    case EV_KEY:
      if (e.code == BTN_TOUCH || e.code == BTN_MOUSE) {
        bool new_down = e.value;
        if (new_down != down) {
          down = new_down;
          if (new_down)
            pressing = true;
          else
            releasing = true;
        }
      } else {
        /* Discard all data on stdin to avoid that keyboard input data is read
         * on the executing shell. This fixes #3403. */
        tcflush(STDIN_FILENO, TCIFLUSH);

        bool is_char;
        Event ev(e.value ? Event::KEY_DOWN : Event::KEY_UP,
                 TranslateKeyCode(e.code, is_char));
        ev.is_char = is_char;
        queue.Push(ev);
      }

      break;

    case EV_ABS:
      moving = true;

      switch (e.code) {
      case ABS_X:
        edit_position.x = e.value;
        break;

      case ABS_Y:
        edit_position.y = e.value;
        break;

      case ABS_MT_POSITION_X:
        edit_position.x = e.value;
        break;

      case ABS_MT_POSITION_Y:
        edit_position.y = e.value;
        break;
      }

      break;

    case EV_REL:
      switch (e.code) {
      case REL_X:
        rel_x += e.value;
        break;

      case REL_Y:
        rel_y += e.value;
        break;

      case REL_WHEEL:
        rel_wheel += e.value;
        break;
      }

      break;
    }
  }
}
Exemple #10
0
void
BufferCanvas::Commit(Canvas &other)
{
  assert(IsDefined());
  assert(active);
  assert(GetWidth() == other.GetWidth());
  assert(GetHeight() == other.GetHeight());

  if (frame_buffer != nullptr) {
    assert(OpenGL::translate.x == 0);
    assert(OpenGL::translate.y == 0);

    frame_buffer->Unbind();

    /* restore the old viewport */

    assert(OpenGL::translate == PixelPoint(0, 0));

#ifdef HAVE_GLES
    /* there's no glPopAttrib() on GL/ES; emulate it */
    glViewport(old_viewport[0], old_viewport[1],
               old_viewport[2], old_viewport[3]);
#else
    glPopAttrib();
#endif

#ifdef USE_GLSL
    OpenGL::projection_matrix = old_projection_matrix;
    OpenGL::UpdateShaderProjectionMatrix();
#else
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();
#endif

    OpenGL::translate = old_translate;
    OpenGL::viewport_size = old_size;

#ifdef USE_GLSL
    glVertexAttrib4f(OpenGL::Attribute::TRANSLATE,
                     OpenGL::translate.x, OpenGL::translate.y, 0, 0);
#endif

#ifdef SOFTWARE_ROTATE_DISPLAY
    OpenGL::display_orientation = old_orientation;
#endif

    /* copy frame buffer to screen */
    CopyTo(other);
  } else {
    assert(offset == other.offset);

    /* copy screen to texture */
    CopyToTexture(*texture, GetRect());
  }

#ifndef NDEBUG
  active = false;
#endif
}