private void calc_selected_CHR(int _X, int _Y) { m_selected_CHR = -1; // run through all sprite's CHRs and find the hit CHR_data_attr chr_attr; int size = m_spr_data.get_CHR_attr().Count; float chr_pos_x; float chr_pos_y; for (int i = 0; i < size; i++) { chr_attr = m_spr_data.get_CHR_attr()[i]; chr_pos_x = transform_to_scr_pos(chr_attr.x + m_offset_x + m_spr_data.offset_x, m_scr_half_width); chr_pos_y = transform_to_scr_pos(chr_attr.y + m_offset_y + m_spr_data.offset_y, m_scr_half_height); if (_X > chr_pos_x && _X < chr_pos_x + m_CHR_size && _Y > chr_pos_y && _Y < chr_pos_y + get_CHR_height()) { m_selected_CHR = i; #if DEF_FIXED_LEN_PALETTE16_ARR if (SetCHRPalette != null) { SetCHRPalette(this, null); } #endif #if DEF_NES // highlight the palette if (m_palette_group.active_palette != chr_attr.palette_ind) { int color_slot = (m_palette_group.active_palette >= 0) ? m_palette_group.get_palettes_arr()[m_palette_group.active_palette].color_slot:-1; m_palette_group.active_palette = chr_attr.palette_ind; if (m_palette_group.active_palette >= 0) { // set the same color slot that was in the last palette m_palette_group.get_palettes_arr()[m_palette_group.active_palette].color_slot = color_slot; } } #endif break; } } dispatch_event_set_selected_CHR(); /* reset palette when clicked outside of CHRs * if( m_mode == EMode.m_build && m_selected_CHR < 0 ) * { * m_palette_group.active_palette = -1; * } */ }
public bool CHR_fill_with_color() { palette_group plt = palette_group.Instance; if (plt.active_palette >= 0) { if (m_selected_ind >= 0 && get_data() != null) { #if DEF_NES byte color_ind = ( byte )plt.get_palettes_arr()[plt.active_palette].color_slot; #elif DEF_SMS || DEF_PCE byte color_ind = ( byte )(plt.active_palette * utils.CONST_NUM_SMALL_PALETTES + plt.get_palettes_arr()[plt.active_palette].color_slot); #endif get_data()[m_selected_ind].fill(color_ind); if (m_mode8x16 && m_selected_ind + 1 < get_data().Count) { get_data()[m_selected_ind + 1].fill(color_ind); } update(); if (UpdatePixel != null) { UpdatePixel(this, null); } return(true); } } return(false); }
private Color get_color(int _ind) { palette_group plt_grp = palette_group.Instance; palette_small[] sm_plts_arr = plt_grp.get_palettes_arr(); return(Color.FromArgb(plt_grp.main_palette[sm_plts_arr[_ind >> 2].get_color_inds()[_ind & 0x03]])); }
public void subscribe_event(palette_group _plt) { _plt.UpdateColor += new EventHandler(update_color); m_palette_group = _plt; palette_small[] plt_arr = _plt.get_palettes_arr(); plt_arr[0].ActivePalette += new EventHandler(update_color); plt_arr[1].ActivePalette += new EventHandler(update_color); plt_arr[2].ActivePalette += new EventHandler(update_color); plt_arr[3].ActivePalette += new EventHandler(update_color); }
private void update() { if (m_sprites_arr != null) { int clr; palette_group plt_grp = palette_group.Instance; palette_small[] sm_plts_arr = plt_grp.get_palettes_arr(); for (int i = 0; i < utils.CONST_NUM_SMALL_PALETTES * utils.CONST_PALETTE_SMALL_NUM_COLORS; i++) { clr = palette_group.Instance.main_palette[sm_plts_arr[i >> 2].get_color_inds()[i & 0x03]]; utils.brush.Color = Color.FromArgb((clr & 0xff0000) >> 16, (clr & 0xff00) >> 8, clr & 0xff); m_main_gfx.FillRectangle(utils.brush, (i << 4) + 1, 1, 16, 16); } if (CheckBoxColorA.Checked || CheckBoxColorB.Checked) { m_pen.Color = CONST_COLOR_PALETTE_SWAP_COLOR_ACTIVE_BORDER; m_pen.Width = 2; m_main_gfx.DrawRectangle(m_pen, 1, 1, PixBoxPalette.Width - 2, PixBoxPalette.Height - 2); } else { m_pen.Color = CONST_COLOR_PALETTE_SWAP_COLOR_INACTIVE_BORDER; m_pen.Width = 1; m_main_gfx.DrawRectangle(m_pen, 0, 0, PixBoxPalette.Width - 1, PixBoxPalette.Height - 1); } } if (m_color_A >= 0) { draw_sel_border(m_color_A); } if (m_color_B >= 0) { draw_sel_border(m_color_B); } PixBoxPalette.Invalidate(); }
public bool update() { bool res = false; clear_background(CONST_BACKGROUND_COLOR); if (m_data_list != null) { disable(false); CHR_data chr_data; Bitmap bmp; m_pen.Color = Color.White; bool draw_colored = m_palette_group != null && m_palette_group.active_palette >= 0; int size = m_data_list.Count; for (int i = 0; i < size; i++) { chr_data = m_data_list[i]; if (draw_colored == true) { bmp = utils.create_CHR_bitmap(chr_data, null, false, m_palette_group.active_palette, m_palette_group.get_palettes_arr()); } else { bmp = utils.create_CHR_bitmap(chr_data, null, false, -1); } m_gfx.DrawImage(bmp, (i * utils.CONST_CHR_IMG_SIZE) % m_pix_box.Width, (i / utils.CONST_CHR_BANK_SIDE_SPRITES_CNT) * utils.CONST_CHR_IMG_SIZE, utils.CONST_CHR_IMG_SIZE, utils.CONST_CHR_IMG_SIZE); bmp.Dispose(); } if (m_selected_ind >= 0) { draw_selection_border(m_selected_ind); if (m_mode8x16) { draw_selection_border(m_selected_ind + 1); } } res = true; } if (m_data_list == null || (m_data_list != null && m_data_list.Count == 0)) { disable(true); utils.brush.Color = Color.White; m_gfx.DrawString("BUILD Mode:\n\n1) Select a CHR and drag and drop it\nto the LAYOUT window using a RIGHT\nmouse button", utils.fnt10_Arial, utils.brush, 0, 0); } else { // draw grid m_pen.Color = Color.FromArgb(0x78808080); int n_lines = m_pix_box.Width / utils.CONST_CHR_IMG_SIZE; int pos; for (int i = 0; i < n_lines; i++) { pos = i * utils.CONST_CHR_IMG_SIZE; m_gfx.DrawLine(m_pen, pos, 0, pos, m_pix_box.Width); m_gfx.DrawLine(m_pen, 0, pos, m_pix_box.Height, pos); } } invalidate(); return(res); }
void BtnOkClick_Event(object sender, EventArgs e) { if (m_color_A >= 0 && m_color_B >= 0) { uint chr_key; CHR_data chr_data; #if DEF_FIXED_LEN_PALETTE16_ARR palettes_array plts_arr = palettes_array.Instance; #endif SortedSet <uint> used_CHR_data = new SortedSet <uint>(); foreach (sprite_data spr in m_sprites_arr) { foreach (CHR_data_attr attr in spr.get_CHR_attr()) { #if DEF_FIXED_LEN_PALETTE16_ARR if (attr.palette_ind == plts_arr.palette_index) { #endif chr_key = ( uint )(((spr.get_CHR_data().id & 0x0000ffff) << 16) | (attr.CHR_ind & 0x0000ffff)); if (!used_CHR_data.Contains(chr_key)) { chr_data = spr.get_CHR_data().get_data()[attr.CHR_ind]; for (int pix_n = 0; pix_n < utils.CONST_CHR_TOTAL_PIXELS_CNT; pix_n++) { if (chr_data.get_data()[pix_n] == m_color_A) { chr_data.get_data()[pix_n] = ( byte )m_color_B; } else if (chr_data.get_data()[pix_n] == m_color_B) { chr_data.get_data()[pix_n] = ( byte )m_color_A; } } used_CHR_data.Add(chr_key); } #if DEF_FIXED_LEN_PALETTE16_ARR } #endif } } #if DEF_FIXED_LEN_PALETTE16_ARR plts_arr.swap_colors(m_color_A, m_color_B); plts_arr.update_palette(); #else palette_group plt_grp = palette_group.Instance; palette_small[] sm_plts_arr = plt_grp.get_palettes_arr(); int ind_A = sm_plts_arr[m_color_A >> 2].get_color_inds()[m_color_A & 0x03]; int ind_B = sm_plts_arr[m_color_B >> 2].get_color_inds()[m_color_B & 0x03]; sm_plts_arr[m_color_A >> 2].get_color_inds()[m_color_A & 0x03] = ind_B; sm_plts_arr[m_color_B >> 2].get_color_inds()[m_color_B & 0x03] = ind_A; for (int j = 0; j < utils.CONST_NUM_SMALL_PALETTES; j++) { sm_plts_arr[j].update(); } #endif } else { MainForm.message_box("Please, select both Color A and Color B!", "Colors Swapping Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }