/******************************************************************************* * * Picking functions * ******************************************************************************/ enum edit_error edit_create_picking (struct app* app, struct edit_imgui* imgui, struct edit_model_instance_selection* instance_selection, struct mem_allocator* allocator, struct edit_picking** out_picking) { struct edit_picking* picking = NULL; enum edit_error edit_err = EDIT_NO_ERROR; enum sl_error sl_err = SL_NO_ERROR; if(UNLIKELY(!app || !instance_selection || !allocator || !out_picking)) { edit_err = EDIT_INVALID_ARGUMENT; goto error; } picking = MEM_CALLOC(allocator, 1, sizeof(struct edit_picking)); if(!picking) { edit_err = EDIT_MEMORY_ERROR; goto error; } ref_init(&picking->ref); APP(ref_get(app)); picking->app = app; EDIT(imgui_ref_get(imgui)); picking->imgui = imgui; EDIT(model_instance_selection_ref_get(instance_selection)); picking->instance_selection = instance_selection; picking->allocator = allocator; sl_err = sl_create_hash_table (sizeof(uint32_t), ALIGNOF(uint32_t), sizeof(uint32_t), ALIGNOF(uint32_t), hash_uint32, eq_uint32, allocator, &picking->picked_instances_htbl); if(sl_err != SL_NO_ERROR) { edit_err = sl_to_edit_error(sl_err); goto error; } exit: if(out_picking) *out_picking = picking; return edit_err; error: if(picking) { EDIT(picking_ref_put(picking)); picking = NULL; } goto exit; }
static void release_picking(struct ref* ref) { struct edit_picking* picking = NULL; assert(ref); picking = CONTAINER_OF(ref, struct edit_picking, ref); EDIT(imgui_ref_put(picking->imgui)); EDIT(model_instance_selection_ref_put(picking->instance_selection)); APP(ref_put(picking->app)); SL(free_hash_table(picking->picked_instances_htbl)); MEM_FREE(picking->allocator, picking); }
/******************************************************************************* * * Builtin cvars registration. * ******************************************************************************/ enum edit_error edit_setup_cvars(struct app* app, struct edit_cvars* cvars) { enum app_error app_err = APP_NO_ERROR; enum edit_error edit_err = EDIT_NO_ERROR; if(UNLIKELY(!app || !cvars)) { edit_err = EDIT_INVALID_ARGUMENT; goto error; } #define EDIT_CVAR(name, desc) \ app_err = app_add_cvar(app, STR(CONCAT(edit_, name)), desc); \ if(app_err != APP_NO_ERROR) { \ edit_err = app_to_edit_error(app_err);\ goto error;\ } \ app_err = app_get_cvar(app, STR(CONCAT(edit_, name)), &cvars->name); \ if(app_err != APP_NO_ERROR) { \ edit_err = app_to_edit_error(app_err); \ goto error; \ } #include "app/editor/regular/edit_cvars_decl.h" #undef EDIT_CVAR exit: return edit_err; error: if(app && cvars) EDIT(release_cvars(app, cvars)); goto exit; }
static enum edit_error pick_imdraw(struct edit_picking* picking, uint32_t pick_id) { if(!picking) return EDIT_INVALID_ARGUMENT; EDIT(imgui_enable_item(picking->imgui, pick_id)); return EDIT_NO_ERROR; }
void CPgRect::OnFoundered() { UpdateData( TRUE ); LPFX pfx = EDIT().GetEditFx(); if ( pfx == NULL ) return; // Toggle bit if ( m_bFoundered ) pfx->f1 |= FXF1_FOUNDERED; else pfx->f1 &= ~FXF1_FOUNDERED; APP()->ReGen(); }
void CPgRect::OnColor() { LPFX pfx = EDIT().GetEditFx(); if ( pfx == NULL ) return; // Choose a new color CWinFile::ChooseColor( &pfx->bck, GetSafeHwnd() ); m_colorbox.SetColor( pfx->bck ); APP()->ReGen(); }
/* ARGSUSED */ int Xedit(cmd_t *cmd, disk_t *disk, mbr_t *mbr, mbr_t *tt, int offset) { const char *errstr; int pn, num, ret; prt_t *pp; pn = (int)strtonum(cmd->args, 0, 3, &errstr); if (errstr) { printf("partition number is %s: %s\n", errstr, cmd->args); return (CMD_CONT); } pp = &mbr->part[pn]; /* Edit partition type */ ret = Xsetpid(cmd, disk, mbr, tt, offset); #define EDIT(p, v, n, m) \ if ((num = ask_num(p, v, n, m)) != v) \ ret = CMD_DIRTY; \ v = num; /* Unused, so just zero out */ if (pp->id == DOSPTYP_UNUSED) { memset(pp, 0, sizeof(*pp)); printf("Partition %d is disabled.\n", pn); return (ret); } /* Change table entry */ if (ask_yn("Do you wish to edit in CHS mode?")) { int maxcyl, maxhead, maxsect; /* Shorter */ maxcyl = disk->real->cylinders - 1; maxhead = disk->real->heads - 1; maxsect = disk->real->sectors; /* Get data */ EDIT("BIOS Starting cylinder", pp->scyl, 0, maxcyl); EDIT("BIOS Starting head", pp->shead, 0, maxhead); EDIT("BIOS Starting sector", pp->ssect, 1, maxsect); EDIT("BIOS Ending cylinder", pp->ecyl, 0, maxcyl); EDIT("BIOS Ending head", pp->ehead, 0, maxhead); EDIT("BIOS Ending sector", pp->esect, 1, maxsect); /* Fix up off/size values */ PRT_fix_BN(disk, pp, pn); /* Fix up CHS values for LBA */ PRT_fix_CHS(disk, pp); } else { pp->bs = getuint(disk, "Partition offset", pp->bs, disk->real->size); pp->ns = getuint(disk, "Partition size", pp->ns, disk->real->size - pp->bs); /* Fix up CHS values */ PRT_fix_CHS(disk, pp); } #undef EDIT return (ret); }
LRESULT CPgRect::OnRefresh(WPARAM wParam, LPARAM lParam) { LPFX pfx = EDIT().GetEditFx(); if ( pfx == NULL ) return -1; CWnd *pBck = GetDlgItem( IDC_BCK ); if ( pBck != NULL ) { if ( pfx->type == FXTYPE_RECT ) { pBck->EnableWindow( FALSE ); pBck->ShowWindow( SW_HIDE ); } // end if else { pBck->EnableWindow( TRUE ); m_bBck = ( pfx->f1 & FXF1_BCK ) != 0; } // end else } // end if CWnd *pTrans = GetDlgItem( IDC_TRANSLUCENCY ); CWnd *pTText = GetDlgItem( IDC_TTEXT ); { if ( pfx->type == FXTYPE_TEXT || pfx->type == FXTYPE_TIME || pfx->type == FXTYPE_DATE || pfx->type == FXTYPE_SCREENSHOT || pfx->type == FXTYPE_VIDEO || pfx->type == FXTYPE_URL ) { pTrans->EnableWindow( TRUE ); pTText->EnableWindow( TRUE ); char num[ 64 ]; sprintf( num, "%.2f", ( (double)pfx->translucency ) / ( (double)100 ) ); m_sTranslucency = num; } // end else else { pTrans->EnableWindow( FALSE ); pTrans->ShowWindow( SW_HIDE ); pTText->EnableWindow( FALSE ); pTText->ShowWindow( SW_HIDE ); } // end if } // end if m_colorbox.SetColor( pfx->bck ); m_bBorder = ( pfx->f1 & FXF1_BORDER ) != 0; m_bFoundered = ( pfx->f1 & FXF1_FOUNDERED ) != 0; UpdateData( FALSE ); DoEnable(); return 0; }
void CPgRect::OnBorder() { UpdateData( TRUE ); LPFX pfx = EDIT().GetEditFx(); if ( pfx == NULL ) return; // Toggle bit if ( m_bBorder ) pfx->f1 |= FXF1_BORDER; else pfx->f1 &= ~FXF1_BORDER; APP()->ReGen(); DoEnable(); }
void CPgRect::OnChangeTranslucency() { UpdateData( TRUE ); LPFX pfx = EDIT().GetEditFx(); if ( pfx == NULL ) return; pfx->translucency = (DWORD)( strtod( m_sTranslucency, NULL ) * 100 ); if ( pfx->translucency > 10000 ) { pfx->translucency = 10000; m_sTranslucency = "100.00"; UpdateData( FALSE ); } // end if APP()->ReGen(); }
void CPgImageProp::OnChangeWidth() { UpdateData( TRUE ); // Get the current image LPPUBIMGINFO ppii = IMGLIST().GetSelImage(); if ( ppii == NULL ) return; long w = strtoul( m_sWidth, NULL, 10 ); if ( w <= 8 || w > 2600 ) w = 320; ppii->rect.right = ppii->rect.left + w; EDIT().Size( NULL ); // Regen everything FRAME()->SetUpdateTimer(); }
void CPgImageProp::OnChangeHeight() { UpdateData( TRUE ); // Get the current image LPPUBIMGINFO ppii = IMGLIST().GetSelImage(); if ( ppii == NULL ) return; long h = strtoul( m_sHeight, NULL, 10 ); if ( h <= 8 || h > 2600 ) h = 320; ppii->rect.bottom = ppii->rect.top + h; EDIT().Size( NULL ); // Regen everything FRAME()->SetUpdateTimer(); }
void CPgImageProp::OnCustomsize() { DoEnable(); // Get the current image LPPUBIMGINFO ppii = IMGLIST().GetSelImage(); if ( ppii == NULL ) return; // Toggle custom size mode if ( m_bCustomSize ) ppii->f1 |= PIIF1_CUSTOMSIZE; else ppii->f1 &= ~PIIF1_CUSTOMSIZE; APP()->ReGen(); EDIT().Size( NULL ); OnRefresh( 0, 0L ); }
/******************************************************************************* * * Edit tool functions * ******************************************************************************/ enum edit_error edit_scale_tool (struct edit_imgui* imgui, struct edit_model_instance_selection* selection, const float sensitivity) { const float size = 0.2f; float pivot_pos[3] = {0.f, 0.f, 0.f}; float val[3] = { 1.f, 1.f, 1.f }; if(UNLIKELY(!imgui || !selection)) return EDIT_INVALID_ARGUMENT; EDIT(get_model_instance_selection_pivot(selection, pivot_pos)); EDIT(imgui_scale_tool (imgui, EDIT_IMGUI_ID, sensitivity, pivot_pos, size, (float[]) { 1.f, 0.f, 0.f },
void main() { EDIT(); }
static enum edit_error pick_world (struct edit_picking* picking, struct app_world* world, const uint32_t pick_id, const enum edit_selection_mode selection_mode) { struct app_model_instance* inst = NULL; enum app_error app_err = APP_NO_ERROR; enum edit_error edit_err = EDIT_NO_ERROR; assert(picking && world); if(selection_mode == EDIT_SELECTION_MODE_NONE) goto exit; app_err = app_world_picked_model_instance(world, pick_id, &inst); if(app_err != APP_NO_ERROR) { edit_err = app_to_edit_error(app_err); goto error; } if(selection_mode == EDIT_SELECTION_MODE_XOR) { bool is_selected = false; edit_err = edit_is_model_instance_selected (picking->instance_selection, inst, &is_selected); if(edit_err != EDIT_NO_ERROR) goto error; if(is_selected == true) { void* data = NULL; /* If the instance was already selected and is not registered into the * picked_instance_htbl then this instance was previously selected and * thus we unselect it. */ SL(hash_table_find(picking->picked_instances_htbl, &pick_id, &data)); if(data == NULL) { edit_err = edit_unselect_model_instance (picking->instance_selection, inst); if(edit_err != EDIT_NO_ERROR) goto error; } } else { /* If the instance was not already selected add it to the selection */ const enum sl_error sl_err = sl_hash_table_insert (picking->picked_instances_htbl, &pick_id, &pick_id); if(sl_err != SL_NO_ERROR) { edit_err = sl_to_edit_error(sl_err); goto error; } edit_err = edit_select_model_instance (picking->instance_selection, inst); if(edit_err != EDIT_NO_ERROR) goto error; } } if(selection_mode == EDIT_SELECTION_MODE_NEW) { EDIT(clear_model_instance_selection(picking->instance_selection)); edit_err = edit_select_model_instance(picking->instance_selection, inst); if(edit_err != EDIT_NO_ERROR) goto error; } exit: return edit_err; error: goto exit; }