示例#1
0
void AbstractButton::SetDown (bool down)
{
  if (is_checkable()) {
    if (is_checked() != down) RequestRedraw();

    set_checked(down);

    if (group_) {
      group_->Toggle(this, is_checked());
    } else {
      toggled_.Invoke(is_checked());
    }

  } else {

    if (is_down() != down) RequestRedraw();

    set_down(down);
    if (group_) {
      group_->Click(this);
    } else {
      clicked_.Invoke();
    }
  }
}
示例#2
0
Response AbstractButton::PerformMouseRelease (AbstractWindow* context)
{
  if (context->GetMouseButton() == MouseButtonLeft) {
    int fire_event = 0;	// 0: no event, 1: click event, 2: toggled event

    if (is_checkable()) {
      if (is_pressed()) {
        fire_event = 2;
      }
    } else {
      if (is_pressed() && is_down()) {
        fire_event = 1;
      }
    }

    RequestRedraw();

    switch (fire_event) {

      case 0:
        break;

      case 1: {
        if (group_) {
          group_->Click(this);
        } else {
          clicked_.Invoke();
        }
        break;
      }

      case 2: {
        if (is_checked() != is_last_checked()) {

          if (group_) {
            group_->Toggle(this, is_checked());
          } else {
            toggled_.Invoke(is_checked());
          }
        }
        break;
      }

      default:
        break;
    }

    set_pressed(false);
    set_down(false);

    released_.Invoke();

    return Finish;
  }

  return Ignore;
}
示例#3
0
LRESULT CALLBACK hook( int nCode, WPARAM wParam, LPARAM lParam )
{
    PKBDLLHOOKSTRUCT key_info = 0;
    /* char msg[256]; */

    if ( nCode < 0 )
    {
        return CallNextHookEx( hook_handle, nCode, wParam, lParam );
    }

    key_info = (PKBDLLHOOKSTRUCT)lParam;
    /* sprintf( msg, "key: %d\n", key_info->vkCode ); */
    /* OutputDebugString( msg ); */

    if ( is_ignore_key( key_info ) )
    {
        pop_ignore_key();
        return CallNextHookEx( hook_handle, nCode, wParam, lParam );
    }

    if ( key_info->vkCode == VK_SPACE )
    {
        if ( is_down( key_info ) )
        {
            process_space_down( key_info );
        }
        else
        {
            process_space_up( key_info );
        }
        return PREVENT_KEY_PRESS;
    }
    else if ( is_down( key_info ) && is_space_down )
    {
        if ( process_not_space_down( key_info ) )
        {
            return PREVENT_KEY_PRESS;
        }
    }

    return CallNextHookEx( hook_handle, nCode, wParam, lParam );
}
示例#4
0
void resolve_delays_keys_as_combo()
{
    int i = 0;
    for ( i = 0; i < delayed_keys_count; i += 1 )
    {
        if ( is_down( &delayed_keys[ i ] ) )
        {
            resolve_as_combo( &delayed_keys[ i ] );
        }
    }
    reset_delayed_keys();
}
示例#5
0
BOOL is_ignore_key( PKBDLLHOOKSTRUCT key )
{
    BOOL result = FALSE;
    int idx_to_read = inc_ring_idx( read_ring_idx );
    if ( idx_to_read != write_ring_idx )
    {
        Key *current = &ignore_keys_ring[ idx_to_read ];
        if ( current->vk_code == key->vkCode && current->down == is_down( key ) )
        {
            result = TRUE;
        }
    }
    return result;
}
示例#6
0
void
WndButton::OnPaint(Canvas &canvas)
{
  PixelRect rc = {
    PixelScalar(0), PixelScalar(0), PixelScalar(canvas.get_width()),
    PixelScalar(canvas.get_height())
  };

  const bool focused = HasFocus();
  const bool pressed = is_down();

  renderer.DrawButton(canvas, rc, focused, pressed);

  // If button has text on it
  tstring caption = get_text();
  if (caption.empty())
    return;

  rc = renderer.GetDrawingRect(rc, pressed);

  canvas.SetBackgroundTransparent();
  if (!IsEnabled())
    canvas.SetTextColor(look.button.disabled.color);
  else if (focused)
    canvas.SetTextColor(look.button.focused.foreground_color);
  else
    canvas.SetTextColor(look.button.standard.foreground_color);

#ifndef USE_GDI
  canvas.formatted_text(&rc, caption.c_str(), GetTextStyle());
#else
  unsigned style = DT_CENTER | DT_NOCLIP | DT_WORDBREAK;
  canvas.Select(*(look.button.font));

  PixelRect text_rc = rc;
  canvas.formatted_text(&text_rc, caption.c_str(), style | DT_CALCRECT);
  text_rc.right = rc.right;

  PixelScalar offset = rc.bottom - text_rc.bottom;
  if (offset > 0) {
    offset /= 2;
    text_rc.top += offset;
    text_rc.bottom += offset;
  }

  canvas.formatted_text(&text_rc, caption.c_str(), style);
#endif
}
示例#7
0
Response RadioButton::Draw (AbstractWindow* context)
{
  AbstractWindow::shaders()->widget_inner_program()->use();

  glUniform1i(
      AbstractWindow::shaders()->location(Shaders::WIDGET_INNER_GAMMA), 0);
  glUniform1i(
      AbstractWindow::shaders()->location(Shaders::WIDGET_INNER_SHADED),
      context->theme()->radio_button().shaded);
  if (is_checked()) {
    glUniform4fv(AbstractWindow::shaders()->location(Shaders::WIDGET_INNER_COLOR), 1,
                 AbstractWindow::theme()->radio_button().inner_sel.data());
  } else {
    glUniform4fv(AbstractWindow::shaders()->location(Shaders::WIDGET_INNER_COLOR), 1,
                 AbstractWindow::theme()->radio_button().inner.data());
  }

  glBindVertexArray(vao_[0]);
  glDrawArrays(GL_TRIANGLE_FAN, 0, outline_vertex_count(round_type()) + 2);

  AbstractWindow::shaders()->widget_outer_program()->use();

  glUniform2f(AbstractWindow::shaders()->location(Shaders::WIDGET_OUTER_OFFSET), 0.f, 0.f);
  glUniform4fv(AbstractWindow::shaders()->location(Shaders::WIDGET_OUTER_COLOR), 1,
               AbstractWindow::theme()->radio_button().outline.data());

  glBindVertexArray(vao_[1]);
  glDrawArrays(GL_TRIANGLE_STRIP, 0,
               outline_vertex_count(round_type()) * 2 + 2);

  if (emboss()) {
    glUniform4f(AbstractWindow::shaders()->location(Shaders::WIDGET_OUTER_COLOR), 1.0f,
                1.0f, 1.0f, 0.16f);
    glUniform2f(AbstractWindow::shaders()->location(Shaders::WIDGET_OUTER_OFFSET),
                0.f, 0.f - 1.f);
    glDrawArrays(GL_TRIANGLE_STRIP, 0,
                 emboss_vertex_count(round_type()) * 2);
  }

  if (is_down()) {
    DrawIconText(context->theme()->radio_button().text_sel.data(), 0);
  } else {
    DrawIconText(context->theme()->radio_button().text.data(), 0);
  }

  return Finish;
}
示例#8
0
/**
 * Reset event state.
 *
 * Input state (like pressed keys) is reset, by sending events if
 * necessary (and if dettached is false).
 */
void console_input::reset( bool dettached )
{
    // Reset keyboard state
    if ( !dettached && pressed_ )
        for ( unsigned sc = 0; sc < sizeof(kstate_); ++sc )
            if ( is_down(sc) )
                send_scan_( sc | 0x80 );  // Release key
    memset( kstate_, 0, sizeof(kstate_) );
    pressed_ = 0;

    // Reset mouse state (only needed if buttons pressed)
    if ( !dettached && last_mouse_.abs_x != unsigned(-1) && last_mouse_.btns )
    {
        // Release mouse buttons
        last_mouse_.btns = 0;
        send_mouse_event( last_mouse_ );
    }
    last_mouse_.abs_x = unsigned(-1);   // Invalidate last mouse data
}
示例#9
0
BOOL process_not_space_down( PKBDLLHOOKSTRUCT key_info )
{
    BOOL need_prevent = FALSE;
    is_something_was_pressed = TRUE;
    if ( is_need_delay( key_info->time ) )
    {
        add_to_delayed_keys( key_info );
        need_prevent = TRUE;
    }
    else
    {
        if ( is_down( key_info ) )
        {
            resolve_as_combo( key_info );
        }
        need_prevent = TRUE;
    }
    return need_prevent;
}
示例#10
0
void
MenuBar::Button::on_paint(Canvas &canvas)
{
  Brush brush(menu_button_bk_color(is_enabled(), is_down()));
  canvas.fill_rectangle(0, 0, canvas.get_width(), canvas.get_height(), brush);

  canvas.set_text_color(is_enabled() ? Color::BLACK : Color::GRAY);
  canvas.background_transparent();

#ifndef ENABLE_SDL
  HFONT font = (HFONT)::SendMessage(hWnd, WM_GETFONT, 0, 0);
  if (font != NULL)
    ::SelectObject(canvas, font);
#endif

  RECT rc = get_client_rect();
  canvas.formatted_text(&rc, get_text().c_str(),
                        DT_NOPREFIX | DT_CENTER |
                        DT_NOCLIP | DT_WORDBREAK);
}
示例#11
0
void
WndCustomButton::OnPaint(Canvas &canvas)
{
#ifdef HAVE_CLIPPING
  /* background and selector */
  canvas.Clear(look.background_brush);
#endif

  PixelRect rc = GetClientRect();

  // Draw focus rectangle
  if (HasFocus()) {
    canvas.DrawFilledRectangle(rc, look.focused.background_color);
    canvas.SetTextColor(IsEnabled()
                        ? look.focused.text_color : look.button.disabled.color);
  } else {
    canvas.DrawFilledRectangle(rc, look.background_color);
    canvas.SetTextColor(IsEnabled() ? look.text_color : look.button.disabled.color);
  }

  // If button has text on it
  tstring caption = get_text();
  if (caption.empty())
    return;

  // If button is pressed, offset the text for 3D effect
  if (is_down())
    OffsetRect(&rc, 1, 1);

  canvas.SelectNullPen();
  canvas.SetBackgroundTransparent();
#ifndef USE_GDI
  canvas.formatted_text(&rc, caption.c_str(), GetTextStyle());
#else
  unsigned s = DT_CENTER | DT_NOCLIP | DT_WORDBREAK;
  canvas.Select(*(look.button.font));
  canvas.formatted_text(&rc, caption.c_str(), s);
#endif
}
示例#12
0
void
WndSymbolButton::OnPaint(Canvas &canvas)
{
  PixelRect rc = {
    PixelScalar(0), PixelScalar(0), PixelScalar(canvas.get_width()),
    PixelScalar(canvas.get_height())
  };

  bool pressed = is_down();

  renderer.DrawButton(canvas, rc, HasFocus(), pressed);
  // If button has text on it
  tstring caption = get_text();
  if (caption.empty())
    return;

  rc = renderer.GetDrawingRect(rc, pressed);

  canvas.SelectNullPen();
  if (!IsEnabled())
    canvas.Select(look.button.disabled.brush);
  else if (HasFocus())
    canvas.Select(look.button.focused.foreground_brush);
  else
    canvas.Select(look.button.standard.foreground_brush);

  const char ch = (char)caption[0];

  // Draw arrow symbols instead of < and >
  if (ch == '<' || ch == '>') {
    int size = min(rc.right - rc.left, rc.bottom - rc.top) / 5;

    RasterPoint Arrow[3];
    Arrow[0].x = (rc.left + rc.right) / 2 + (ch == '<' ? size : -size);
    Arrow[0].y = (rc.top + rc.bottom) / 2 + size;
    Arrow[1].x = (rc.left + rc.right) / 2 + (ch == '<' ? -size : size);
    Arrow[1].y = (rc.top + rc.bottom) / 2;
    Arrow[2].x = (rc.left + rc.right) / 2 + (ch == '<' ? size : -size);
    Arrow[2].y = (rc.top + rc.bottom) / 2 - size;

    canvas.DrawTriangleFan(Arrow, 3);
  }

  // Draw arrow symbols instead of v and ^
  else if (ch == '^' || ch == 'v') {
    int size = min(rc.right - rc.left, rc.bottom - rc.top) / 5;

    RasterPoint Arrow[3];
    Arrow[0].x = (rc.left + rc.right) / 2 +
                 size;
    Arrow[0].y = (rc.top + rc.bottom) / 2 +
                 (ch == '^' ? size : -size);
    Arrow[1].x = (rc.left + rc.right) / 2;
    Arrow[1].y = (rc.top + rc.bottom) / 2 +
                 (ch == '^' ? -size : size);
    Arrow[2].x = (rc.left + rc.right) / 2 - size;
    Arrow[2].y = (rc.top + rc.bottom) / 2 +
                 (ch == '^' ? size : -size);

    canvas.DrawTriangleFan(Arrow, 3);
  }

  // Draw symbols instead of + and -
  else if (ch == '+' || ch == '-') {
    int size = min(rc.right - rc.left, rc.bottom - rc.top) / 5;

    canvas.Rectangle((rc.left + rc.right) / 2 - size,
                     (rc.top + rc.bottom) / 2 - size / 3,
                     (rc.left + rc.right) / 2 + size,
                     (rc.top + rc.bottom) / 2 + size / 3);

    if (ch == '+')
      canvas.Rectangle((rc.left + rc.right) / 2 - size / 3,
                       (rc.top + rc.bottom) / 2 - size,
                       (rc.left + rc.right) / 2 + size / 3,
                       (rc.top + rc.bottom) / 2 + size);
  }

  // Draw Fly bitmap
  else if (caption == _T("Fly")) {
    Bitmap launcher1_bitmap(IDB_LAUNCHER1);
    canvas.ClearWhite();
    if (is_down())
      canvas.invert_stretch_transparent(launcher1_bitmap, COLOR_YELLOW);
    else
      canvas.stretch_transparent(launcher1_bitmap, COLOR_BLUE);
  }

  // Draw Simulator bitmap
  else if (caption == _T("Simulator")) {
    Bitmap launcher2_bitmap(IDB_LAUNCHER2);
    canvas.ClearWhite();
    if (is_down())
      canvas.invert_stretch_transparent(launcher2_bitmap, COLOR_YELLOW);
    else
      canvas.stretch_transparent(launcher2_bitmap, COLOR_BLUE);
  }

  else if (caption == _T("Green")) {
    InflateRect(&rc, -3, -3);
    canvas.DrawFilledRectangle(rc, Color(0x74, 0xFF, 0));
  } else if (caption == _T("Blue")) {
    InflateRect(&rc, -3, -3);
    canvas.DrawFilledRectangle(rc, Color(0, 0x90, 0xFF));
  } else if (caption == _T("Magenta")) {
    InflateRect(&rc, -3, -3);
    canvas.DrawFilledRectangle(rc, Color(0xFF, 0, 0xCB));
  } else if (caption == _T("Yellow")) {
    InflateRect(&rc, -3, -3);
    canvas.DrawFilledRectangle(rc, Color(0xFF, 0xE8, 0));
  }
}
示例#13
0
bool InputManager::is_down(SDL_Keycode k) const {
	return is_down(sdl_key(k).cc);
}
示例#14
0
bool InputManager::is_down(event_class ec, code_t code) const {
	return is_down(ClassCode(ec, code));
}
示例#15
0
void
WndSymbolButton::on_paint(Canvas &canvas)
{
  /* background and selector */
  canvas.clear(background_brush);

  // Get button RECT and shrink it to make room for the selector/focus
  RECT rc = get_client_rect();

  // Draw button to the background
  canvas.draw_button(rc, is_down());

  // Draw focus rectangle
  if (has_focus()) {
    RECT focus_rc = rc;
    InflateRect(&focus_rc, -3, -3);
    canvas.draw_focus(focus_rc);
  }

  // If button has text on it
  tstring caption = get_text();
  if (caption.empty())
    return;

  // If button is pressed, offset the text for 3D effect
  if (is_down())
    OffsetRect(&rc, 1, 1);

  canvas.null_pen();
  canvas.black_brush();

  const char ch = (char)caption[0];

  // Draw arrow symbols instead of < and >
  if (ch == '<' || ch == '>') {
    int size = min(rc.right - rc.left, rc.bottom - rc.top) / 5;

    static RasterPoint Arrow[4];
    Arrow[0].x = (rc.left + rc.right) / 2 + (ch == '<' ? size : -size);
    Arrow[0].y = (rc.top + rc.bottom) / 2 + size;
    Arrow[1].x = (rc.left + rc.right) / 2 + (ch == '<' ? -size : size);
    Arrow[1].y = (rc.top + rc.bottom) / 2;
    Arrow[2].x = (rc.left + rc.right) / 2 + (ch == '<' ? size : -size);
    Arrow[2].y = (rc.top + rc.bottom) / 2 - size;
    Arrow[3].x = Arrow[0].x;
    Arrow[3].y = Arrow[0].y;

    canvas.polygon(Arrow, 4);
  }

  // Draw arrow symbols instead of v and ^
  if (ch == '^' || ch == 'v') {
    int size = min(rc.right - rc.left, rc.bottom - rc.top) / 5;

    RasterPoint Arrow[3];
    Arrow[0].x = (rc.left + rc.right) / 2 +
                 size;
    Arrow[0].y = (rc.top + rc.bottom) / 2 +
                 (ch == '^' ? size : -size);
    Arrow[1].x = (rc.left + rc.right) / 2;
    Arrow[1].y = (rc.top + rc.bottom) / 2 +
                 (ch == '^' ? -size : size);
    Arrow[2].x = (rc.left + rc.right) / 2 - size;
    Arrow[2].y = (rc.top + rc.bottom) / 2 +
                 (ch == '^' ? size : -size);

    canvas.polygon(Arrow, 3);
  }

  // Draw symbols instead of + and -
  if (ch == '+' || ch == '-') {
    int size = min(rc.right - rc.left, rc.bottom - rc.top) / 5;

    canvas.rectangle((rc.left + rc.right) / 2 - size,
                     (rc.top + rc.bottom) / 2 - size / 3,
                     (rc.left + rc.right) / 2 + size,
                     (rc.top + rc.bottom) / 2 + size / 3);

    if (ch == '+')
      canvas.rectangle((rc.left + rc.right) / 2 - size / 3,
                       (rc.top + rc.bottom) / 2 - size,
                       (rc.left + rc.right) / 2 + size / 3,
                       (rc.top + rc.bottom) / 2 + size);
  }

  // Draw Fly bitmap
  if (caption == _T("Fly")) {
    Bitmap launcher1_bitmap(IDB_LAUNCHER1);
    if (is_down())
      canvas.stretch(launcher1_bitmap);
    else {
      canvas.clear_white();
      canvas.stretch_transparent(launcher1_bitmap, Color::BLUE);
    }
  }

  // Draw Simulator bitmap
  if (caption == _T("Simulator")) {
    Bitmap launcher2_bitmap(IDB_LAUNCHER2);
    if (is_down())
      canvas.stretch(launcher2_bitmap);
    else {
      canvas.clear_white();
      canvas.stretch_transparent(launcher2_bitmap, Color::BLUE);
    }
  }

}
示例#16
0
/**
 * Helper function to send the scancode to the attached monitor.
 *
 * Bit 7 signals it is a key release(1) or a key press(0).
 * Bit 8 signals it is an extended key(1) (having a 0xE0 prefix).
 * Bit 9 signals it is a very special key (only Pause for now)
 *
 * If the "compose key" is pressed, until is released we enter a special
 * mode where all keys are sticky.
 */
void console_input::send_scancode( unsigned code )
{
    const unsigned compose_key = 0x57;  // F11

    assert( !is_paused() );

    if ( !pressed_ && code == compose_key )
    {
        // Start "Compose" Mode. Only signal key is pressed, but don't send
        // any scancode.
        press_key( compose_key );
        return;
    }
    else if ( code == (compose_key | 0x80) )
    {
        // Leave "Compose" Mode. If no keys pressed, send the compose key.
        release_key( compose_key );
        if ( pressed_ == 1 )
        {   // No other keys pressed, send the compose key
            send_scan_( compose_key );
            send_scan_( compose_key | 0x80 );
            return;
        }
        // Release all other keys pressed.
        for ( unsigned sc=0; sc < 0x200; ++sc )
            if ( is_down(sc) )
                send_scan_( sc | 0x80 );
        memset( kstate_, 0, sizeof(kstate_) );
        pressed_ = 0;
        return;
    }

    // Ignore key release codes if in "compose" mode
    if ( is_down(compose_key) && (code & 0x80) )
        return;

    // Check if special key (only Pause, for now)
    if ( code & 0x200 )
    {
        if ( code != 0x245 )
            return;   // We don't know any other special key
        // Send the Pause sequence: E1 1D 45, E1 9D C5
        send_scan_( 0xE1 ); send_scan_( 0x1D ); send_scan_( 0x45 );
        send_scan_( 0xE1 ); send_scan_( 0x9D ); send_scan_( 0xC5 );
        // No state is changed by this key
        return;
    }

    // Check if key already released
    // FIXME: X sends repeats as released keys instead of pressed.
    if ( (code & 0x80) && !is_down(code & 0x17F) )
        return;   // Don't send two releases for the same key

    // Send e0 first if extended key
    if ( code & 0x100 )
        send_scan_( 0xE0 );
    send_scan_( code );

    // Update key state
    if ( code & 0x80 )
        release_key( code & 0x17F );
    else
        press_key( code );
}
示例#17
0
文件: gong.c 项目: DSkywalk/RetroArch
static void game_update_and_render(Game_Input *input, Game_Offscreen_Buffer *draw_buffer)
{
   const float initial_ball_speed = 80.f;
   float playing_field_x = 85.f;
   float playing_field_y = 48.f;
   float player_size_x = 2.5f;
   float player_size_y = 10.f;
   int i;

   if (!g_state->is_initialized)
   {
      g_state->is_initialized = 1;
      g_state->ball_px.f = 0;
      g_state->ball_py.f = 0;
      g_state->ball_dpx.f = initial_ball_speed;
      g_state->ball_dpy.f = 0;
      g_state->current_play_points.f = 10.f;
      g_state->player2_speed.f = 80.f;
   }

   for (i = 0; i < MAX_PLAYERS; i++)
   {
      float speed = 80.f;

      if (i == 1 && !g_state->player2_human)
        break;

      g_state->player[i].dpy.f = 0.f;

      if (is_down(input[i].buttons[B_SPEED_UP]))
         speed = 150.f;

      if (is_down(input[i].buttons[B_MOVE_UP]))
      {
         if (g_state->player[i].py.f < playing_field_y - player_size_y)
         {
            g_state->player[i].dpy.f = speed;
         }

         if (g_state->player[i].py.f < -playing_field_y + player_size_y)
         {
            g_state->player[i].py.f = -playing_field_y + player_size_y;
            g_state->player[i].dpy.f = 0.f;
         }
      }
      if (is_down(input[i].buttons[B_MOVE_DOWN]))
      {
         if (g_state->player[i].py.f > -playing_field_y + player_size_y)
         {
            g_state->player[i].dpy.f = -speed;
         }

         if (g_state->player[i].py.f < -playing_field_y + player_size_y)
         {
            g_state->player[i].py.f = -playing_field_y + player_size_y;
            g_state->player[i].dpy.f = 0.f;
         }
      }

      g_state->player[i].py.f += g_state->player[i].dpy.f * input->last_dt;
   }

   if (!g_state->player2_human)
   {
      g_state->player[1].dpy.f = (g_state->ball_py.f - g_state->player[1].py.f) * 100.f;
      g_state->player[1].dpy.f = MIN(g_state->player[1].dpy.f, g_state->player2_speed.f);
      g_state->player[1].dpy.f = MAX(g_state->player[1].dpy.f, -g_state->player2_speed.f);
      g_state->player[1].py.f += g_state->player[1].dpy.f * input->last_dt;

      if (g_state->player[1].py.f < -playing_field_y + player_size_y)
      {
         g_state->player[1].py.f = -playing_field_y + player_size_y;
         g_state->player[1].dpy.f = 0.f;
      }

      if (g_state->player[1].py.f > playing_field_y - player_size_y)
      {
         g_state->player[1].py.f = playing_field_y - player_size_y;
         g_state->player[1].dpy.f = 0.f;
      }
   }

   g_state->ball_px.f += g_state->ball_dpx.f * input->last_dt;

   if (g_state->ball_dpx.f > 0)
   {
      g_state->ball_dpx.f += 10.f * input->last_dt;
   }
   else
   {
      g_state->ball_dpx.f -= 10.f * input->last_dt;
   }

   g_state->ball_py.f += g_state->ball_dpy.f * input->last_dt;

   if (g_state->ball_py.f > playing_field_y - 1.f)
   {
      g_state->ball_py.f = playing_field_y - 1.f;
      g_state->ball_dpy.f *= -1.f;
   }
   else if (g_state->ball_py.f < -playing_field_y + 1)
   {
      g_state->ball_py.f = -playing_field_y + 1.f;
      g_state->ball_dpy.f *= -1;
   }

   if (g_state->ball_px.f > 80.f - 2.5f - 1.f) /* @Hardcoded */
   {
      if ((g_state->ball_py.f >= (g_state->player[1].py.f - 10.f)) && (g_state->ball_py.f <= (g_state->player[1].py.f + 10.f)))
      {
         g_state->ball_dpx.f *= -1.f;
         g_state->ball_px.f = 80.f - 2.5f - 1.f; /* @Hardcoded */
         g_state->ball_dpy.f = (g_state->ball_py.f - g_state->player[1].py.f) + g_state->player[1].dpy.f;
         ++g_state->current_play_points.f;
      }
      else if (g_state->ball_px.f >= playing_field_x - 1)
      {
         g_state->ball_px.f = 0;
         g_state->ball_py.f = 0;
         g_state->ball_dpy.f = 0;
         g_state->ball_dpx.f = -initial_ball_speed;
         g_state->player2_score += (unsigned)g_state->current_play_points.f;
         g_state->current_play_points.f = 10.f;
      }
   }
   else if (g_state->ball_px.f < -80 + 2.5f + 1.f) /* @Hardcoded */
   {
      if ((g_state->ball_py.f >= (g_state->player[0].py.f - 10.f)) && (g_state->ball_py.f <= (g_state->player[0].py.f + 10.f)))
      {
         g_state->ball_dpx.f *= -1.f;
         g_state->ball_px.f = -80 + 2.5f + 1.f; /* @Hardcoded */
         g_state->ball_dpy.f = (g_state->ball_py.f - g_state->player[0].py.f) + g_state->player[0].dpy.f;
         ++g_state->current_play_points.f;
      }
      else if (g_state->ball_px.f <= -playing_field_x + 1)
      {
         g_state->ball_px.f = 0;
         g_state->ball_py.f = 0;
         g_state->ball_dpy.f = 0;
         g_state->ball_dpx.f = initial_ball_speed;
         g_state->player1_score += (unsigned)g_state->current_play_points.f;
         g_state->current_play_points.f = 10.f;

         if (!g_state->player2_human)
            g_state->player2_speed.f += g_state->current_play_points.f * 0.01f;
      }
   }

   clear(draw_buffer, 0x021077);
   draw_rect(draw_buffer, 0x000530, 0.f, 0.f, playing_field_x, playing_field_y);

   draw_rect(draw_buffer, 0x00ffff, -80.f, g_state->player[0].py.f, player_size_x, player_size_y);
   draw_rect(draw_buffer, 0x00ffff, 80.f, g_state->player[1].py.f, player_size_x, player_size_y);

   draw_rect(draw_buffer, 0xffff00, g_state->ball_px.f, g_state->ball_py.f, 1.f, 1.f);

   draw_number(draw_buffer, (unsigned)g_state->current_play_points.f, 0xaaaaaa, 0.f, 38.f);
   draw_number(draw_buffer, g_state->player1_score, 0xff6611, 20.f, 38.f);
   draw_number(draw_buffer, g_state->player2_score, 0xff6611, -20.f, 38.f);
}
示例#18
0
int main(int argc, char **argv)
{
    int pos, i, tmp;
    struct input_event ev;
    __u8 kc_val[8];
    __u8 key_code;

    if(argc < 3) return 1;

    int ifd = open(argv[1], O_RDONLY);
    int ofd = open(argv[2], O_WRONLY);
    if(ifd < 0 || ofd < 0) return 1;


    memset(kc_val, 0, 8);
    while(read(ifd, &ev, sizeof(ev)) == sizeof(ev)){
        printf("input event -- type: %u, code: %u, value: %d\n", ev.type, ev.code, ev.value);
        if(ev.type == EV_KEY && ev.code < 246){
            if(ev.value == 1){ // a press-down
                if(ev.code == KEY_LEFTCTRL){
                    kc_val[0] |= 1 << 4;
                }else if(ev.code == KEY_LEFTSHIFT){
                    kc_val[0] |= 1 << 5;
                }else if(ev.code == KEY_LEFTALT){
                    kc_val[0] |= 1 << 6;
                }else if(ev.code == KEY_LEFTMETA){
                    kc_val[0] |= 1 << 7;
                }else if(ev.code == KEY_RIGHTCTRL){
                    kc_val[0] |= 1;
                }else if(ev.code == KEY_RIGHTSHIFT){
                    kc_val[0] |= 1 << 1;
                }else if(ev.code == KEY_RIGHTALT){
                    kc_val[0] |= 1 << 2;
                }else if(ev.code == KEY_RIGHTMETA){
                    kc_val[0] |= 1 << 3;
                }else{
                    /* other keys, check the array */
                    key_code = key_map[ev.code];
                    if(!is_down(kc_val, key_code)){
                        for(pos = 2; kc_val[pos] && pos < 6; pos++);
                        if(pos < 6) kc_val[pos] = key_code;
                    }
                }
                if((tmp = write(ofd, kc_val, 8)) != 8){
                    fprintf(stderr, "write error, len=%d, abort.\n", tmp);
                    break;
                }
            }else if(ev.value == 0){ // a release
                if(ev.code == KEY_LEFTCTRL){
                    kc_val[0] &= ~((__u8)(1<<4));
                }else if(ev.code == KEY_LEFTSHIFT){
                    kc_val[0] &= ~((__u8)(1<<5));
                }else if(ev.code == KEY_LEFTALT){
                    kc_val[0] &= ~((__u8)(1<<6));
                }else if(ev.code == KEY_LEFTMETA){
                    kc_val[0] &= ~((__u8)(1<<7));
                }else if(ev.code == KEY_RIGHTCTRL){
                    kc_val[0] &= ~((__u8)1);
                }else if(ev.code == KEY_RIGHTSHIFT){
                    kc_val[0] &= ~((__u8)(1<<1));
                }else if(ev.code == KEY_RIGHTALT){
                    kc_val[0] &= ~((__u8)(1<<2));
                }else if(ev.code == KEY_RIGHTMETA){
                    kc_val[0] &= ~((__u8)(1<<3));
                }else{
                    /* other keys, check the array */
                    key_code = key_map[ev.code];
                    if(is_down(kc_val, key_code)){
                        for(pos = 2; kc_val[pos] != key_code && pos < 6; pos++);
                        if(pos < 6){
                            for(i = pos; i < 5; i++)
                                kc_val[i] = kc_val[i+1];
                            kc_val[i] = 0;
                        }
                    }
                }
                if((tmp = write(ofd, kc_val, 8)) != 8){
                    fprintf(stderr, "write error, len=%d, abort.\n", tmp);
                    break;
                }
            }else continue;
        }
    }

    return 1;
}
示例#19
0
void
WndSymbolButton::on_paint(Canvas &canvas)
{
#ifdef HAVE_CLIPPING
    /* background and selector */
    canvas.clear(look.background_brush);
#endif

    // Get button PixelRect and shrink it to make room for the selector/focus
    PixelRect rc = get_client_rect();

    // Draw button to the background
    canvas.draw_button(rc, is_down());

    // Draw focus rectangle
    if (has_focus()) {
        PixelRect focus_rc = rc;
        InflateRect(&focus_rc, -3, -3);
        canvas.draw_focus(focus_rc);
    }

    // If button has text on it
    tstring caption = get_text();
    if (caption.empty())
        return;

    // If button is pressed, offset the text for 3D effect
    if (is_down())
        OffsetRect(&rc, 1, 1);

    canvas.null_pen();
    if (is_enabled())
        canvas.black_brush();
    else
        canvas.select(disabled_brush);

    const char ch = (char)caption[0];

    // Draw arrow symbols instead of < and >
    if (ch == '<' || ch == '>') {
        int size = min(rc.right - rc.left, rc.bottom - rc.top) / 5;

        RasterPoint Arrow[3];
        Arrow[0].x = (rc.left + rc.right) / 2 + (ch == '<' ? size : -size);
        Arrow[0].y = (rc.top + rc.bottom) / 2 + size;
        Arrow[1].x = (rc.left + rc.right) / 2 + (ch == '<' ? -size : size);
        Arrow[1].y = (rc.top + rc.bottom) / 2;
        Arrow[2].x = (rc.left + rc.right) / 2 + (ch == '<' ? size : -size);
        Arrow[2].y = (rc.top + rc.bottom) / 2 - size;

        canvas.TriangleFan(Arrow, 3);
    }

    // Draw arrow symbols instead of v and ^
    else if (ch == '^' || ch == 'v') {
        int size = min(rc.right - rc.left, rc.bottom - rc.top) / 5;

        RasterPoint Arrow[3];
        Arrow[0].x = (rc.left + rc.right) / 2 +
                     size;
        Arrow[0].y = (rc.top + rc.bottom) / 2 +
                     (ch == '^' ? size : -size);
        Arrow[1].x = (rc.left + rc.right) / 2;
        Arrow[1].y = (rc.top + rc.bottom) / 2 +
                     (ch == '^' ? -size : size);
        Arrow[2].x = (rc.left + rc.right) / 2 - size;
        Arrow[2].y = (rc.top + rc.bottom) / 2 +
                     (ch == '^' ? size : -size);

        canvas.TriangleFan(Arrow, 3);
    }

    // Draw symbols instead of + and -
    else if (ch == '+' || ch == '-') {
        int size = min(rc.right - rc.left, rc.bottom - rc.top) / 5;

        canvas.rectangle((rc.left + rc.right) / 2 - size,
                         (rc.top + rc.bottom) / 2 - size / 3,
                         (rc.left + rc.right) / 2 + size,
                         (rc.top + rc.bottom) / 2 + size / 3);

        if (ch == '+')
            canvas.rectangle((rc.left + rc.right) / 2 - size / 3,
                             (rc.top + rc.bottom) / 2 - size,
                             (rc.left + rc.right) / 2 + size / 3,
                             (rc.top + rc.bottom) / 2 + size);
    }

    // Draw Fly bitmap
    else if (caption == _T("Fly")) {
        Bitmap launcher1_bitmap(IDB_LAUNCHER1);
        canvas.clear_white();
        if (is_down())
            canvas.invert_stretch_transparent(launcher1_bitmap, COLOR_YELLOW);
        else
            canvas.stretch_transparent(launcher1_bitmap, COLOR_BLUE);
    }

    // Draw Simulator bitmap
    else if (caption == _T("Simulator")) {
        Bitmap launcher2_bitmap(IDB_LAUNCHER2);
        canvas.clear_white();
        if (is_down())
            canvas.invert_stretch_transparent(launcher2_bitmap, COLOR_YELLOW);
        else
            canvas.stretch_transparent(launcher2_bitmap, COLOR_BLUE);
    }

    else if (caption == _T("Green")) {
        InflateRect(&rc, -3, -3);
        canvas.fill_rectangle(rc, Color(0x74, 0xFF, 0));
    } else if (caption == _T("Blue")) {
        InflateRect(&rc, -3, -3);
        canvas.fill_rectangle(rc, Color(0, 0x90, 0xFF));
    } else if (caption == _T("Magenta")) {
        InflateRect(&rc, -3, -3);
        canvas.fill_rectangle(rc, Color(0xFF, 0, 0xCB));
    } else if (caption == _T("Yellow")) {
        InflateRect(&rc, -3, -3);
        canvas.fill_rectangle(rc, Color(0xFF, 0xE8, 0));
    }
}
示例#20
0
/**
 * Called to handle FLTK key events.
 *
 * Returns non-zero if event was handled, zero if not.
 */
int console_input::handle_key_event( )
{
    if ( is_paused() )
        return 0;

    // Get WIN32 event
    MSG msg = fl_msg;
    // MSDN says to only use the low word. Lets play safe...
    msg.message &= 0xFFFF;

    // Make sure it's a keyboard message
    if ( msg.message < WM_KEYFIRST || msg.message > WM_KEYLAST )
        return 0;

    WORD     flags  = msg.lParam >> 16;     // ignore the repeat count
    bool     is_up  = flags & KF_UP;        // key released
    unsigned code   = flags & 0x1FF;        // scancode & bit 16 set if extended

    // Special key processing
    switch ( code )
    {
    case 0x138: // Right Alt
        // If Control pressed, it's AltGr (received as Control+RightAlt)
        if ( !is_up && is_down(0x01D) )
        {
            // Release the Control key (linux knows that AltGr is RightAlt)
            send_scancode( 0x09D );
        }
        break;
    case 0x145: // NumLock
        // Windows says it's an extended key, but in effect is a single byte
        code = 0x45;
        break;
    case 0x45:  // Pause (1st code)
        // Ignore and wait for the second code (0xC5)
        return 1;
    case 0xC5:  // Pause (2nd code)
        // Send special scan code - 0x245 - so handler nows what it is
        send_scancode( 0x245 );
        return 1;
    case 0x54:  // SysRq
        // Windows only sends the released SysRq. Fake it.
        send_scancode( 0x54 );  // Down
        send_scancode( 0xD4 );  // Up
        return 1;
    case 0x137: // PrintScreen
        // Windows only sends the key up event. Fake it.
        send_scancode( 0x12A ); send_scancode( 0x137 ); // E0 2A E0 37
        send_scancode( 0x1AA ); send_scancode( 0x1B7 ); // E0 AA E0 B7
        return 1;
    }

    // Normal key processing
    if ( is_up )
        code |= 0x80;   // setup scan code for key release

    // Send key scancode
    send_scancode( code );

    // Let colinux handle all our keys
    return 1;
}