Something dictionaryLookup(EmojicodeDictionary *dict, Object *keyString){ size_t index = findSlot(dict, keyString); if(slots(dict)[index].key){ return slots(dict)[index].value; } return NOTHINGNESS; }
StringValue *StringTable::insert(const char *s, size_t length) { const hash_t hash = calcHash(s, length); size_t i = findSlot(hash, s, length); if (table[i].vptr) return NULL; // already in table if (++count > tabledim * loadFactor) { grow(); i = findSlot(hash, s, length); } table[i].hash = hash; table[i].vptr = allocValue(s, length); // printf("insert %.*s %p\n", (int)length, s, table[i].value ?: NULL); return getValue(table[i].vptr); }
StringValue *StringTable::lookup(const char *s, size_t length) { const hash_t hash = calcHash(s, length); const size_t i = findSlot(hash, s, length); // printf("lookup %.*s %p\n", (int)length, s, table[i].value ?: NULL); return getValue(table[i].vptr); }
template <class T> T& Set<T>::addNoAssign(const T& value) { FW_ASSERT(!contains(value)); // Empty => allocate. if (!m_capacity) setCapacity(0); // Exceeds MaxUsagePct => rehash. else if ((S64)m_numNonEmpty * 100 >= (S64)m_capacity * MaxUsagePct) { int cap = m_capacity; if ((S64)m_numItems * 100 >= (S64)cap * ThrUsagePct) cap <<= 1; rehash(cap); } // Find slot. S32 hashValue = hash<T>(value) >> 1; int slot = findSlot(value, hashValue, true); FW_ASSERT(m_hashes[slot] < 0); // Add item. m_numItems++; if (m_hashes[slot] == Empty) m_numNonEmpty++; m_hashes[slot] = hashValue; return m_values[slot]; }
template <class T> void Set<T>::rehash(int capacity) { FW_ASSERT(capacity >= BlockSize); FW_ASSERT(capacity >= m_numItems); int oldCapacity = m_capacity; S32* oldHashes = m_hashes; T* oldValues = m_values; m_capacity = capacity; m_numNonEmpty = m_numItems; m_hashes = new S32[capacity]; m_values = new T[capacity]; memset(m_hashes, Empty, capacity * sizeof(S32)); for (int i = 0; i < oldCapacity; i++) { S32 oldHash = oldHashes[i]; if (oldHash < 0) continue; const T& oldValue = oldValues[i]; int slot = findSlot(oldValue, oldHash, true); FW_ASSERT(m_hashes[slot] == Empty); m_hashes[slot] = oldHash; m_values[slot] = oldValue; } delete[] oldHashes; delete[] oldValues; }
void dictionarySet(Object *dicto, Object *keyString, Something value, Thread *thread){ EmojicodeDictionary *dict = dicto->value; size_t index = findSlot(dict, keyString); slots(dict)[index].key = keyString; slots(dict)[index].value = value; if(++dict->count > 2 * (dict->capacity/3)){ size_t oldCapacity = dict->capacity; EmojicodeDictionaryKVP *oldSlots = slots(dict); stackPush(dicto, 0, 0, thread); Object *slotso = newArray(dict->capacity * 2 * sizeof(EmojicodeDictionaryKVP)); EmojicodeDictionary *dict = stackGetThis(thread)->value; stackPop(thread); dict->slots = slotso; dict->capacity *= 2; dict->count = 0; for (size_t i = 0; i < oldCapacity; i++) { if(oldSlots[i].key){ dictionarySet(dicto, oldSlots[i].key, oldSlots[i].value, thread); } } } }
StringValue *StringTable::update(const char *s, size_t length) { const hash_t hash = calcHash(s, length); size_t i = findSlot(hash, s, length); if (!table[i].vptr) { if (++count > tabledim * loadFactor) { grow(); i = findSlot(hash, s, length); } table[i].hash = hash; table[i].vptr = allocValue(s, length); } // printf("update %.*s %p\n", (int)length, s, table[i].value ?: NULL); return getValue(table[i].vptr); }
/* C_Sign signs data in a single part, where the signature is an appendix to the data. */ CK_DECLARE_FUNCTION(CK_RV, C_Sign)( CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, CK_ULONG ulDataLen, CK_BYTE_PTR pSignature, CK_ULONG_PTR pulSignatureLen ) { int rv; struct p11Object_t *pObject; struct p11Slot_t *pSlot; struct p11Session_t *pSession; FUNC_CALLED(); if (context == NULL) { FUNC_FAILS(CKR_CRYPTOKI_NOT_INITIALIZED, "C_Initialize not called"); } rv = findSessionByHandle(&context->sessionPool, hSession, &pSession); if (rv != CKR_OK) { FUNC_RETURNS(rv); } if (pSession->activeObjectHandle == CK_INVALID_HANDLE) { FUNC_FAILS(CKR_OPERATION_NOT_INITIALIZED, "Operation not initialized"); } rv = findSlot(&context->slotPool, pSession->slotID, &pSlot); if (rv != CKR_OK) { FUNC_RETURNS(rv); } rv = findSlotKey(pSlot, pSession->activeObjectHandle, &pObject); if (rv != CKR_OK) { FUNC_RETURNS(rv); } if (pObject->C_Sign != NULL) { rv = pObject->C_Sign(pObject, pSession->activeMechanism, pData, ulDataLen, pSignature, pulSignatureLen); if ((pSignature != NULL) && (rv != CKR_BUFFER_TOO_SMALL)) { pSession->activeObjectHandle = CK_INVALID_HANDLE; } if (rv == CKR_DEVICE_ERROR) { rv = handleDeviceError(hSession); FUNC_FAILS(rv, "Device error reported"); } } else { FUNC_FAILS(CKR_FUNCTION_NOT_SUPPORTED, "Operation not supported by token"); } FUNC_RETURNS(rv); }
/* C_SignInit initializes a signature operation, here the signature is an appendix to the data. */ CK_DECLARE_FUNCTION(CK_RV, C_SignInit)( CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, CK_OBJECT_HANDLE hKey ) { int rv; struct p11Object_t *pObject; struct p11Slot_t *pSlot; struct p11Session_t *pSession; FUNC_CALLED(); if (context == NULL) { FUNC_FAILS(CKR_CRYPTOKI_NOT_INITIALIZED, "C_Initialize not called"); } rv = findSessionByHandle(&context->sessionPool, hSession, &pSession); if (rv != CKR_OK) { FUNC_RETURNS(rv); } if (pSession->activeObjectHandle != CK_INVALID_HANDLE) { FUNC_FAILS(CKR_OPERATION_ACTIVE, "Operation is already active"); } rv = findSlot(&context->slotPool, pSession->slotID, &pSlot); if (rv != CKR_OK) { FUNC_RETURNS(rv); } rv = findSlotKey(pSlot, hKey, &pObject); if (rv != CKR_OK) { FUNC_RETURNS(rv); } if (pObject->C_SignInit != NULL) { rv = pObject->C_SignInit(pObject, pMechanism); if (rv == CKR_DEVICE_ERROR) { rv = handleDeviceError(hSession); FUNC_FAILS(rv, "Device error reported"); } } else { FUNC_FAILS(CKR_FUNCTION_NOT_SUPPORTED, "Operation not supported by token"); } if (!rv) { pSession->activeObjectHandle = pObject->handle; pSession->activeMechanism = pMechanism->mechanism; rv = CKR_OK; } FUNC_RETURNS(rv); }
template <class T> T Set<T>::replace(const T& value) { int slot = findSlot(value, hash<T>(value) >> 1, false); FW_ASSERT(m_hashes[slot] >= 0); T old = m_values[slot]; m_values[slot] = value; return old; }
template <class T> T& Set<T>::remove(const T& value) { int slot = findSlot(value, hash<T>(value) >> 1, false); FW_ASSERT(m_hashes[slot] >= 0); m_numItems--; m_hashes[slot] = Removed; return m_values[slot]; }
/* C_EncryptFinal finishes a multiple-part encryption operation. */ CK_DECLARE_FUNCTION(CK_RV, C_EncryptFinal)( CK_SESSION_HANDLE hSession, CK_BYTE_PTR pLastEncryptedPart, CK_ULONG_PTR pulLastEncryptedPartLen ) { int rv; struct p11Object_t *pObject; struct p11Slot_t *pSlot; struct p11Session_t *pSession; FUNC_CALLED(); if (context == NULL) { FUNC_FAILS(CKR_CRYPTOKI_NOT_INITIALIZED, "C_Initialize not called"); } rv = findSessionByHandle(&context->sessionPool, hSession, &pSession); if (rv != CKR_OK) { FUNC_RETURNS(rv); } if (pSession->activeObjectHandle == CK_INVALID_HANDLE) { FUNC_FAILS(CKR_OPERATION_NOT_INITIALIZED, "Operation not initialized"); } rv = findSlot(&context->slotPool, pSession->slotID, &pSlot); if (rv != CKR_OK) { FUNC_RETURNS(rv); } rv = findSlotKey(pSlot, pSession->activeObjectHandle, &pObject); if (rv != CKR_OK) { FUNC_RETURNS(rv); } if (pObject->C_EncryptFinal != NULL) { rv = pObject->C_EncryptFinal(pObject, pSession->activeMechanism, pLastEncryptedPart, pulLastEncryptedPartLen); if (rv == CKR_DEVICE_ERROR) { rv = handleDeviceError(hSession); FUNC_FAILS(rv, "Device error reported"); } } else { FUNC_FAILS(CKR_FUNCTION_NOT_SUPPORTED, "Operation not supported by token"); } if (!rv) { pSession->activeObjectHandle = CK_INVALID_HANDLE; rv = CKR_OK; } FUNC_RETURNS(rv); }
int getFreeSlot(int set, int base) { TSlotSet::iterator at = findSlot(set, base); if (at == slots[set].end()) return reserveSlot(set, base); // look in locksteps, if they not match, then there is a free slot for (; at != slots[set].end(); ++at, ++base) if (*at != base) break; return reserveSlot(set, base); }
/* C_SignUpdate continues a multiple-part signature operation, processing another data part. */ CK_DECLARE_FUNCTION(CK_RV, C_SignUpdate)( CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart, CK_ULONG ulPartLen ) { CK_RV rv; struct p11Object_t *pObject; struct p11Slot_t *pSlot; struct p11Session_t *pSession; FUNC_CALLED(); if (context == NULL) { FUNC_FAILS(CKR_CRYPTOKI_NOT_INITIALIZED, "C_Initialize not called"); } rv = findSessionByHandle(&context->sessionPool, hSession, &pSession); if (rv != CKR_OK) { FUNC_RETURNS(rv); } if (pSession->activeObjectHandle == CK_INVALID_HANDLE) { FUNC_FAILS(CKR_OPERATION_NOT_INITIALIZED, "Operation not initialized"); } rv = findSlot(&context->slotPool, pSession->slotID, &pSlot); if (rv != CKR_OK) { FUNC_RETURNS(rv); } rv = findSlotKey(pSlot, pSession->activeObjectHandle, &pObject); if (rv != CKR_OK) { FUNC_RETURNS(rv); } if (pObject->C_SignUpdate != NULL) { rv = pObject->C_SignUpdate(pObject, pSession->activeMechanism, pPart, ulPartLen); if (rv == CKR_DEVICE_ERROR) { rv = handleDeviceError(hSession); FUNC_FAILS(rv, "Device error reported"); } } else { rv = appendToCryptoBuffer(pSession, pPart, ulPartLen); } FUNC_RETURNS(rv); }
void ICACHE_FLASH_ATTR saveData(char *location, char *device, char *sensor, char *type, char *value) { int slot; if ((slot = findEntry(location, device, sensor, type)) >= 0) { strcpy(valueEntries[slot].type, type); // Update Value strcpy(valueEntries[slot].val, value); } else if ((slot = findSlot()) >= 0) { //os_printf("Slot %d\n", slot); storeEntry(slot, location, device, sensor, type, value); sortData(); } else { // Loose it } }
int getFreeSlot(int set, int base, int size = 1) { TSlotSet::iterator at = findSlot(set, base); if (at == slots[set].end()) return reserveSlot(set, base, size); // look for a big enough gap for (; at != slots[set].end(); ++at) { if (*at - base >= size) break; base = *at + 1; } return reserveSlot(set, base, size); }
/** * Remove a session from the session-pool * * @param pool Pointer to session-pool structure * @param handle The handle of the session * * @return CKR_OK, CKR_SESSION_HANDLE_INVALID, CKR_GENERAL_ERROR */ int removeSession(struct p11SessionPool_t *pool, CK_SESSION_HANDLE handle) { int rc; struct p11Session_t *session; struct p11Session_t **pSession; struct p11Slot_t *slot; pSession = &pool->list; while (*pSession && (*pSession)->handle != handle) { pSession = &((*pSession)->next); } session = *pSession; if (!session) { return CKR_SESSION_HANDLE_INVALID; } *pSession = session->next; rc = findSlot(&context->slotPool, session->slotID, &slot); if (rc == CKR_OK) { if (slot->token && !(session->flags & CKF_RW_SESSION)) { slot->token->rosessions--; } } clearSearchList(session); while(session->sessionObjList) { if (removeSessionObject(session, session->sessionObjList->handle) != CKR_OK) return CKR_GENERAL_ERROR; } if (session->cryptoBuffer) { free(session->cryptoBuffer); session->cryptoBuffer = NULL; session->cryptoBufferMax = 0; session->cryptoBufferSize = 0; } free(session); pool->numberOfSessions--; return CKR_OK; }
void StringTable::grow() { const size_t odim = tabledim; StringEntry *otab = table; tabledim *= 2; table = (StringEntry *)mem.xcalloc(tabledim, sizeof(table[0])); for (size_t i = 0; i < odim; ++i) { StringEntry *se = &otab[i]; if (!se->vptr) continue; StringValue *sv = getValue(se->vptr); table[findSlot(se->hash, sv->lstring(), sv->length)] = *se; } mem.xfree(otab); }
/** * If a crypto operation returns CKR_DEVICE_ERROR, then check if the token * is still present. * */ int handleDeviceError(CK_SESSION_HANDLE hSession) { int rv; struct p11Session_t *session; struct p11Slot_t *slot; struct p11Token_t *token; FUNC_CALLED(); if (context == NULL) { FUNC_FAILS(CKR_CRYPTOKI_NOT_INITIALIZED, "C_Initialize not called"); } // Even if SCardTransmit report a communication error with the card, the card present // switch and the card present status in the resource manager will still report a present card // // Wait 100ms to make sure the card status detection reports accurate results #ifndef _WIN32 usleep(100000); #endif rv = findSessionByHandle(&context->sessionPool, hSession, &session); if (rv == CKR_SESSION_HANDLE_INVALID) { FUNC_RETURNS(CKR_DEVICE_REMOVED); } if (rv != CKR_OK) { FUNC_RETURNS(rv); } rv = findSlot(&context->slotPool, session->slotID, &slot); if (rv != CKR_OK) { FUNC_RETURNS(rv); } rv = getValidatedToken(slot, &token); if (rv != CKR_OK) { FUNC_RETURNS(rv); } FUNC_RETURNS(CKR_DEVICE_ERROR); }
int updateTable(char* address, char* haddr, int index, int hops,int routediscovery) { int i; i = findInTable(address); if(i == -1) //If it's not in the table, it's new. Find a new slot { i = findSlot(); if(i != -1) { routing_table[i] = newRoute(address, haddr, index, hops); return 0; } return -1; } if(i != -1) //if it's in the table, update it { if(routediscovery == 1) { printf("Force update\n"); memcpy((void*)routing_table[i].nexthop, (void*)haddr, 6); routing_table[i].index = index; routing_table[i].hops = hops; routing_table[i].timestamp = time(NULL); } else if(routing_table[i].hops > hops) { memcpy((void*)routing_table[i].nexthop, (void*)haddr, 6); routing_table[i].index = index; routing_table[i].hops = hops; routing_table[i].timestamp = time(NULL); } else printf("This route is inferior - %d hops < %d hops\n", routing_table[i].hops, hops); } }
int MainWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QMainWindow::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: openFileSlot(); break; case 1: saveFileSlot(); break; case 2: newFileSlot(); break; case 3: saveAsFileSlot(); break; case 4: changeFont(); break; case 5: aboutMe(); break; case 6: isModified(); break; case 7: updateTitle(); break; case 8: findSlot(); break; default: ; } _id -= 9; } return _id; }
void MainWindow::initMenus() { /*Create Actions*/ newFileAction=new QAction(tr("&New"), this); newFileAction->setToolTip("Create a new file"); newFileAction->setStatusTip("wtf?"); newFileAction->setIcon(QIcon(":/images/filenew.png")); newFileAction->setShortcut(QKeySequence("Ctrl+N")); newFileAction->showStatusText(this->statusBar()); // newFileAction->setShortcutContext(Qt::ShortcutContext); openFileAction=new QAction(tr("O&pen"), this); openFileAction->setToolTip("Open an existing file"); openFileAction->setIcon(QIcon(":/images/fileopen.png")); openFileAction->setShortcut(QKeySequence("Ctrl+O")); saveFileAction=new QAction(tr("&Save"), this); saveFileAction->setToolTip("Save current file"); saveFileAction->setIcon(QIcon(":/images/filesave.png")); saveAsFileAction=new QAction(tr("Save &As"), this); saveAsFileAction->setIcon(QIcon(":/images/filesaveas.png")); exitFileAction=new QAction(tr("E&xit"),this); exitFileAction->setToolTip("Exit the Application"); exitFileAction->setIcon(QIcon(":/images/fileexit.png")); copyEditAction=new QAction(tr("&Copy"), this); copyEditAction->setToolTip("Copy"); copyEditAction->setIcon(QIcon(":/images/editcopy.png")); pasteEditAction=new QAction(tr("P&aste"), this); pasteEditAction->setToolTip("Paste"); pasteEditAction->setIcon(QIcon(":/images/editpaste.png")); fontEditAction=new QAction(tr("F&ont"), this); fontEditAction->setToolTip("Change Font"); fontEditAction->setIcon(QIcon(":/images/editfont.png")); cutEditAction=new QAction(tr("C&ut"), this); cutEditAction->setToolTip("Cut"); cutEditAction->setIcon(QIcon(":/images/editcut.png")); findEditAction=new QAction(tr("&Find"), this); findEditAction->setToolTip("Find text and/or replace"); findEditAction->setIcon(QIcon(":/images/editfind.png")); toolEditAction=new QAction(tr("Tool &Bar"),this); toolEditAction->setIcon(QIcon(":/images/edittool.png")); colorEditAction=new QAction(tr("Color"),this); colorEditAction->setIcon(QIcon(":/images/editcolor.png")); selectEditAction=new QAction(tr("Select All"),this); selectEditAction->setIcon(QIcon(":/images/editselect.png")); undoEditAction=new QAction(tr("Undo"),this); undoEditAction->setIcon(QIcon(":/images/editundo.png")); undoEditAction->setEnabled(false); redoEditAction=new QAction(tr("Redo"),this); redoEditAction->setIcon(QIcon(":/images/editredo.png")); redoEditAction->setEnabled(false); aboutHelpAction=new QAction(tr("&About"), this); aboutHelpAction->setToolTip("About this application"); aboutHelpAction->setIcon(QIcon(":/images/helpabout.png")); /*Connections*/ connect(fontEditAction,SIGNAL(triggered()),this,SLOT(changeFont())); connect(exitFileAction,SIGNAL(triggered()),this,SLOT(close())); connect(aboutHelpAction,SIGNAL(triggered()),this,SLOT(aboutMe())); connect(findEditAction,SIGNAL(triggered()),this,SLOT(findSlot())); connect(copyEditAction,SIGNAL(triggered()),textArea,SLOT(copy())); connect(cutEditAction,SIGNAL(triggered()),textArea,SLOT(cut())); connect(pasteEditAction,SIGNAL(triggered()),textArea,SLOT(paste())); connect(selectEditAction,SIGNAL(triggered()),textArea,SLOT(selectAll())); connect(openFileAction,SIGNAL(triggered()),this,SLOT(openFileSlot())); connect(saveFileAction,SIGNAL(triggered()),this,SLOT(saveFileSlot())); connect(newFileAction,SIGNAL(triggered()),this,SLOT(newFileSlot())); connect(saveAsFileAction,SIGNAL(triggered()),this,SLOT(saveAsFileSlot())); connect(textArea,SIGNAL(textChanged()),this,SLOT(isModified())); connect(textArea,SIGNAL(undoAvailable(bool)),undoEditAction,SLOT(setEnabled(bool))); connect(textArea,SIGNAL(redoAvailable(bool)),redoEditAction,SLOT(setEnabled(bool))); connect(textArea,SIGNAL(pasteAvailable(bool)),pasteEditAction,SLOT(setEnabled(bool))); toolEditAction->setCheckable(true); toolEditAction->setChecked(true); /*Menu Init*/ fileMenu = menuBar()->addMenu(tr("&File")); //fileMenu->setStyle(); fileMenu->addAction(newFileAction); fileMenu->addAction(openFileAction); fileMenu->addAction(saveFileAction); fileMenu->addAction(saveAsFileAction); fileMenu->addAction(exitFileAction); /*---*/ editMenu = menuBar()->addMenu(tr("&Edit")); editMenu->addAction(cutEditAction); editMenu->addAction(copyEditAction); editMenu->addAction(pasteEditAction); editMenu->addAction(undoEditAction); editMenu->addAction(redoEditAction); editMenu->addAction(findEditAction); editMenu->addAction(selectEditAction); editMenu->addSeparator(); editMenu->addAction(fontEditAction); editMenu->addAction(colorEditAction); editMenu->addAction(toolEditAction); /*---*/ helpMenu = menuBar()->addMenu(tr("&Help")); helpMenu->addAction(aboutHelpAction); }
void free(void* pData) { assert(isNotEmpty()); m_UsedSlot[findSlot(pData)] = false; ++m_AvailableSlots; }
int reserveSlot(int set, int slot) { TSlotSet::iterator at = findSlot(set, slot); slots[set].insert(at, slot); return slot; }
bool checkEmpty(int set, int slot) { TSlotSet::iterator at = findSlot(set, slot); return !(at != slots[set].end() && *at == slot); }
void getWidget(int bin) { int slot=findSlot(bin); assert(slot>=0); assert(slot<NUMSLOTS); packed++; }
// The main function int main(int argc, char* argv[]) { int option_index = 0; int opt; char* dbPath = NULL; char* userPIN = NULL; char* module = NULL; char* slot = NULL; char* serial = NULL; char* token = NULL; char *errMsg = NULL; int noPublicKey = 0; int result = 0; CK_RV rv; moduleHandle = NULL; p11 = NULL; CK_SLOT_ID slotID = 0; if (argc == 1) { usage(); exit(0); } while ((opt = getopt_long(argc, argv, "hv", long_options, &option_index)) != -1) { switch (opt) { case OPT_DB: dbPath = optarg; break; case OPT_SLOT: slot = optarg; break; case OPT_SERIAL: serial = optarg; break; case OPT_TOKEN: token = optarg; break; case OPT_MODULE: module = optarg; break; case OPT_NO_PUBLIC_KEY: noPublicKey = 1; break; case OPT_PIN: userPIN = optarg; break; case OPT_VERSION: case 'v': printf("%s\n", PACKAGE_VERSION); exit(0); break; case OPT_HELP: case 'h': default: usage(); exit(0); break; } } // Get a pointer to the function list for PKCS#11 library CK_C_GetFunctionList pGetFunctionList = loadLibrary(module, &moduleHandle, &errMsg); if (pGetFunctionList == NULL) { fprintf(stderr, "ERROR: Could not load the library: %s\n", errMsg); exit(1); } // Load the function list (*pGetFunctionList)(&p11); // Initialize the library rv = p11->C_Initialize(NULL_PTR); if (rv != CKR_OK) { fprintf(stderr, "ERROR: Could not initialize the library.\n"); exit(1); } // Get the slotID result = findSlot(slot, serial, token, slotID); if (!result) { // Migrate the database result = migrate(dbPath, slotID, userPIN, noPublicKey); } // Finalize the library p11->C_Finalize(NULL_PTR); unloadLibrary(moduleHandle); return result; }
MWWorld::ConstContainerStoreIterator MWWorld::InventoryStore::getSlot (int slot) const { return findSlot (slot); }
void updateSlot(Layer *layer, GContext *ctx) { int t, tx1, tx2, ty1, ty2, ox, oy; int cornerRadius = 0; uint8_t curCorner, prevCorner; GCornerMask cornerMask; digitSlot *slot; static unsigned int animMiddle = ANIMATION_NORMALIZED_MAX / 2; slot = findSlot(layer); curCorner=slot->curDigit; prevCorner=slot->prevDigit; for (t=0; t<13; t++) { cornerMask = GCornerNone; cornerRadius = 0; if (digits[slot->curDigit][t][0] != digits[slot->prevDigit][t][0] || digits[slot->curDigit][t][1] != digits[slot->prevDigit][t][1]) { if (slot->normTime == ANIMATION_NORMALIZED_MAX) { ox = digits[slot->curDigit][t][0]*slot->tileWidth; oy = digits[slot->curDigit][t][1]*slot->tileHeight; } else { tx1 = digits[slot->prevDigit][t][0]*slot->tileWidth; tx2 = digits[slot->curDigit][t][0]*slot->tileWidth; ty1 = digits[slot->prevDigit][t][1]*slot->tileHeight; ty2 = digits[slot->curDigit][t][1]*slot->tileHeight; ox = slot->normTime * (tx2-tx1) / ANIMATION_NORMALIZED_MAX + tx1; oy = slot->normTime * (ty2-ty1) / ANIMATION_NORMALIZED_MAX + ty1; } } else { ox = digits[slot->curDigit][t][0]*slot->tileWidth; oy = digits[slot->curDigit][t][1]*slot->tileHeight; } if (roundCorners) { if (digitCorners[curCorner][t] != digitCorners[prevCorner][t]) { // Corner become smaller till half, and bigger afterward; if (slot->normTime > ANIMATION_NORMALIZED_MAX) { cornerRadius = 0; cornerMask = digitCorners[prevCorner][t]; //point to corner of prv digit } else { cornerRadius = 2*slot->cornerRadius * slot->normTime / ANIMATION_NORMALIZED_MAX - slot->cornerRadius; if (cornerRadius < 0) { cornerRadius = -cornerRadius; } if (slot->normTime < animMiddle) { cornerMask = digitCorners[prevCorner][t]; } else { cornerMask = digitCorners[curCorner][t]; } } } else { cornerRadius = slot->cornerRadius; cornerMask = digitCorners[curCorner][t]; } } #ifdef PBL_COLOR graphics_context_set_fill_color(ctx, color[colorTheme][(digits[slot->curDigit][t][1]%5)]); #else if (invertStatus) { graphics_context_set_fill_color(ctx, GColorBlack); } else { graphics_context_set_fill_color(ctx, GColorWhite); } #endif graphics_fill_rect(ctx, GRect(ox, oy, slot->tileWidth, slot->tileHeight-stripedDigits), cornerRadius, cornerMask); } }
void * getTextureSlot(size_t size) { return findSlot(size); }