<commit_before>//
//  button.m
//  GameEngine
//
//  Created by <NAME> on 2010-04-30.
//  Copyright 2010 Sharkable. All rights reserved.
//

#include "gameengine/entities/button.h"

#include "gameengine/resource_loader.h"
#include "gameengine/touch.h"
#include "soundengine/sound_player.h"

using std::vector;

Button::Button(Sprite normal_sprite, Sprite pressed_sprite, GamePoint position)
    : Animatable(position),
      normal_sprite_(normal_sprite),
      pressed_sprite_(pressed_sprite),
      state_(kButtonStateNormal),
      delegate_(NULL) {
}

Button::~Button() {
  if (normal_sprite_.texture().loaded()) {
    ResourceLoader::Instance().ReleaseResource(normal_sprite_.texture());
  }
  if (pressed_sprite_.texture().loaded()) {
    ResourceLoader::Instance().ReleaseResource(pressed_sprite_.texture());
  }
}

bool Button::ContainsPoint(GamePoint p) {
  // TODO: THIS IS A HACK
  // For this big release, I zoom one button: the story stuff.
  if (zoom() > 1) {
    return true;
  }
  return p.x >= position().x &&
      p.y >= position().y &&
      p.x < position().x + pressed_sprite_.content_size().width &&
      p.y < position().y + pressed_sprite_.content_size().height;
}


// ViewEntity

void Button::Render() {
  switch (state_) {
    case kButtonStateNormal: {
      normal_sprite_.Draw(position(), angle(), alpha(), zoom());
      break;
    }
    case kButtonStatePressed: {
      pressed_sprite_.Draw(position(), angle(), alpha(), zoom());
      break;
    }
  }
}

void Button::TouchesBegan(vector<Touch> touches) {
  if (state_ == kButtonStateNormal) {
    for (int i = 0; i < touches.size(); i++) {
      if (ContainsPoint(touches[i].location())) {
        state_ = kButtonStatePressed;
        SoundPlayer::instance()->playSound(kSoundButton);
        start_touch_ = touches[i].identifier();
        break;
      }<commit_msg>Remove zoom hack from Button. zoom just not supported.<commit_after>//
//  button.m
//  GameEngine
//
//  Created by <NAME> on 2010-04-30.
//  Copyright 2010 Sharkable. All rights reserved.
//

#include "gameengine/entities/button.h"

#include "gameengine/resource_loader.h"
#include "gameengine/touch.h"
#include "soundengine/sound_player.h"

using std::vector;

Button::Button(Sprite normal_sprite, Sprite pressed_sprite, GamePoint position)
    : Animatable(position),
      normal_sprite_(normal_sprite),
      pressed_sprite_(pressed_sprite),
      state_(kButtonStateNormal),
      delegate_(NULL) {
}

Button::~Button() {
  if (normal_sprite_.texture().loaded()) {
    ResourceLoader::Instance().ReleaseResource(normal_sprite_.texture());
  }
  if (pressed_sprite_.texture().loaded()) {
    ResourceLoader::Instance().ReleaseResource(pressed_sprite_.texture());
  }
}

bool Button::ContainsPoint(GamePoint p) {
  return p.x >= position().x &&
      p.y >= position().y &&
      p.x < position().x + pressed_sprite_.content_size().width &&
      p.y < position().y + pressed_sprite_.content_size().height;
}


// ViewEntity

void Button::Render() {
  switch (state_) {
    case kButtonStateNormal: {
      normal_sprite_.Draw(position(), angle(), alpha(), zoom());
      break;
    }
    case kButtonStatePressed: {
      pressed_sprite_.Draw(position(), angle(), alpha(), zoom());
      break;
    }
  }
}

void Button::TouchesBegan(vector<Touch> touches) {
  if (state_ == kButtonStateNormal) {
    for (int i = 0; i < touches.size(); i++) {
      if (ContainsPoint(touches[i].location())) {
        state_ = kButtonStatePressed;
        SoundPlayer::instance()->playSound(kSoundButton);
        start_touch_ = touches[i].identifier();
        break;
      }
{'fraction_non_alphanumeric': 0.15410107705053852, 'fraction_numerical': 0.007456503728251864, 'mean_word_length': 3.573232323232323, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5608808', 'n_tokens_mistral': 1164, 'n_tokens_neox': 1143, 'n_words': 221}