using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Globalization;

namespace Engineer.Librarys.Offset_Calculator
{
    public partial class Calculator : Form
    {
        public Calculator()
        {
            InitializeComponent();
        }

        private void btnTrans_Click(object sender, EventArgs e)
        {
            if (rbtnDecimal.Checked)
            {
                txtTrans.Text = Translate(long.Parse(txtBase.Text), long.Parse(txtAddrs.Text), rbtnTTROffset.Checked).ToString();
            }
            else
            {
                txtTrans.Text = Translate(long.Parse(txtBase.Text, NumberStyles.HexNumber), long.Parse(txtAddrs.Text, NumberStyles.HexNumber), rbtnTTROffset.Checked).ToString("X");
            }
        }

        private long Translate(long baseAdrss, long addrs, bool realOff)
        {
            if (realOff)
                return addrs - baseAdrss;
            else
                return addrs + baseAdrss;

            return 0;
        }
    }
}
