author | erik <erik> | 2007-01-24 23:29:42 (UTC) |
---|---|---|
committer | erik <erik> | 2007-01-24 23:29:42 (UTC) |
commit | 0076a11b467dce1233194ce228287a2a127b1f5d (patch) (side-by-side diff) | |
tree | f2136a1a3e9b5fd6bede52251ed7249365838752 | |
parent | 48d9219a96096cf44df8ac24413b36d1b718b1d5 (diff) | |
download | opie-0076a11b467dce1233194ce228287a2a127b1f5d.zip opie-0076a11b467dce1233194ce228287a2a127b1f5d.tar.gz opie-0076a11b467dce1233194ce228287a2a127b1f5d.tar.bz2 |
Each file in this commit has the issue where it is possible for code to
overrun static buffers. This could lead to serious problems. Granted it
is almost impossible to do that. But it isn't totally impossible. So this
commit makes it impossible to overrun.
-rw-r--r-- | noncore/games/backgammon/moveengine.cpp | 6 | ||||
-rw-r--r-- | noncore/games/kbill/UI.cpp | 31 | ||||
-rw-r--r-- | noncore/games/kcheckers/echeckers.cpp | 12 | ||||
-rw-r--r-- | noncore/games/kcheckers/rcheckers.cpp | 36 | ||||
-rw-r--r-- | noncore/settings/sysinfo/contrib/fft.c | 2 | ||||
-rw-r--r-- | noncore/styles/theme/othemebase.cpp | 2 |
6 files changed, 51 insertions, 38 deletions
diff --git a/noncore/games/backgammon/moveengine.cpp b/noncore/games/backgammon/moveengine.cpp index a4145cc..b102258 100644 --- a/noncore/games/backgammon/moveengine.cpp +++ b/noncore/games/backgammon/moveengine.cpp @@ -1,557 +1,559 @@ #include "moveengine.h" #include <qtimer.h> #include <stdlib.h> MoveEngine::MoveEngine() : QObject() { int offset=7; int a=0; //counter variable int xfill[]={210,185,170,155,140,125,110,85,70,55,40,25,10,10,25,40,55,70,85,110,125,140,155,170,185,210}; for(a=0;a<26;a++) { x_coord[a]=xfill[a]; } int yfill[]={10,25,40,55,70,10+offset,25+offset,40+offset,55+offset,25,40,55, 25+offset,40+offset,40}; int zfill[]={1,1,1,1,1,2,2,2,2,3,3,3,4,4,5}; for(a=0;a<15;a++) { yup_coord[a]=yfill[a]; ylow_coord[a]=185-(yfill[a]); z_coord[a]=zfill[a]; } for(a=0;a<5;a++) { if(a<3) { x_fin1[a]=65+a*15; x_fin2[a]=155-a*15; } y_fin[a]=225-a*5; } z_fin=1; reset(); } MoveEngine::~MoveEngine() {} void MoveEngine::position(Pieces& pieces,bool non_qte) { int player1_counter=0; int player2_counter=0; //non qte styles are smaller !! int offset=(non_qte) ? 5 : 0; for(int a=0;a<28;a++) { for(int b=0;b<abs(population[a].total);b++) { if(population[a].total>0) //player 1 pieces { - pieces.player1[player1_counter].x=x_coord[a]-offset; + if (a < 26) + pieces.player1[player1_counter].x=x_coord[a]-offset; if(a>=0 && a<13) { pieces.player1[player1_counter].y=yup_coord[b]-offset; pieces.player1[player1_counter].z=z_coord[b]; pieces.player1[player1_counter].side=false; player1_counter++; } else if(a>12 && a<26) { pieces.player1[player1_counter].y=ylow_coord[b]-offset; pieces.player1[player1_counter].z=z_coord[b]; pieces.player1[player1_counter].side=false; player1_counter++; } else if(a==26) { if(b<5) { pieces.player1[player1_counter].x=x_fin1[0]-offset; pieces.player1[player1_counter].y=y_fin[b]-offset; pieces.player1[player1_counter].z=z_fin; } else if(b>=5 && b<10) { pieces.player1[player1_counter].x=x_fin1[1]-offset; pieces.player1[player1_counter].y=y_fin[b-5]-offset; pieces.player1[player1_counter].z=z_fin; } else { pieces.player1[player1_counter].x=x_fin1[2]-offset; pieces.player1[player1_counter].y=y_fin[b-10]-offset; pieces.player1[player1_counter].z=z_fin; } pieces.player1[player1_counter].side=true; player1_counter++; } } else if(population[a].total<0) //player 2 pieces { - pieces.player2[player2_counter].x=x_coord[a]-offset; + if (a < 26) + pieces.player2[player2_counter].x=x_coord[a]-offset; if(a>=0 && a<13) { pieces.player2[player2_counter].y=yup_coord[b]-offset; pieces.player2[player2_counter].z=z_coord[b]; pieces.player2[player2_counter].side=false; player2_counter++; } else if(a>12 && a<26) { pieces.player2[player2_counter].y=ylow_coord[b]-offset; pieces.player2[player2_counter].z=z_coord[b]; pieces.player2[player2_counter].side=false; player2_counter++; } else if(a==27) { if(b<5) { pieces.player2[player2_counter].x=x_fin2[0]-offset; pieces.player2[player2_counter].y=y_fin[b]-offset; pieces.player2[player2_counter].z=z_fin; } else if(b>=5 && b<10) { pieces.player2[player2_counter].x=x_fin2[1]-offset; pieces.player2[player2_counter].y=y_fin[b-5]-offset; pieces.player2[player2_counter].z=z_fin; } else { pieces.player2[player2_counter].x=x_fin2[2]-offset; pieces.player2[player2_counter].y=y_fin[b-10]-offset; pieces.player2[player2_counter].z=z_fin; } pieces.player2[player2_counter].side=true; player2_counter++; } } } } } void MoveEngine::diceroll(const int& newplayer,const int& face1,const int& face2,const int& face3,const int& face4,bool computer) { checkstate(); player=newplayer; otherplayer=(player==1) ? 2 : 1; dice[0]=face1; dice[1]=face2; dice[2]=face3; dice[3]=face4; marker_current=-1; if(getPossibleMoves()==0) { emit nomove(); return; // player will be changed } if(!computer) return; //human intervention required QTimer::singleShot(2000,this,SLOT(automove())); } void MoveEngine::automove() { //the maximimum possibility int maxpos=0; //the position in the moves array int from=-1; int to=-1; //dice1 or dice 2 ?? int index_dice=0; for(int counter=0;counter<26;counter++) { int a=(player==1) ? counter : 25-counter; for(int b=0;b<4;b++) { if(moves[a].weight[b]>maxpos) { maxpos=moves[a].weight[b]; from=a; to=moves[a].to[b]; index_dice=b+1; } } } move(from,to,index_dice); } void MoveEngine::boardpressed(const int& x,const int& y,Marker& marker,bool non_qte) { //get the position of the mouse click bool upper=true; bool found=false; int offset=(non_qte) ? 5 : 0; if(y<=85) // board slots 0 to 12 marker.y_current=0; else if(y>=105) //board slots 13 to 25 { marker.y_current=195-2*offset; upper=false; } int index=13; // the clicked board slot while(index<25 && !found) { if(x>=x_coord[index] && x<x_coord[index+1]) { marker.x_current=x_coord[index]; found=true; ; } else { index++; } } if(!found) { marker.x_current=x_coord[25]; index=25; } if(upper) { index=25-index; } int a=0; int usedice=-1; int dice_value=7; for(a=0;a<4;a++) { if(index==marker_next[a] && marker_next[a]!=-1 && dice_value>dice[a]) { usedice=a; dice_value=dice[0]; } } if(usedice!=-1) { move(marker_current,marker_next[usedice],usedice+1); nomarker(marker); return; } if(dice[0]==7 && dice[1]==7 && dice[2]==7 && dice[3]==7) //no dice rolled { nomarker(marker); return; } else if(fieldColor(index)==player) { marker.visible_current=true; marker_current=index; } else { nomarker(marker); return; } for(a=0;a<4;a++) { if(moves[index].weight[a]>0) { int nextfield=moves[index].to[a]; marker.x_next[a]=x_coord[nextfield]; marker_next[a]=nextfield; if(nextfield<13) //upper half marker.y_next[a]=0; else //lower half marker.y_next[a]=195-2*offset; marker.visible_next[a]=true; } else { marker.x_next[a]=0; marker.y_next[a]=0; marker_next[a]=-1; marker.visible_next[a]=false; } } return; } void MoveEngine::reset() { int a=0; for(a=0;a<28;a++) { population[a].total=0; } int p1_index[]={1,1,12,12,12,12,12,17,17,17,19,19,19,19,19}; int p2_index[]={24,24,13,13,13,13,13,8,8,8,6,6,6,6,6}; //int p1_index[]={19,20,21,22,22,23,23,18,18,23,24,24,24,24,24}; //int p2_index[]={6,5,4,3,3,2,2,2,2,2,1,7,7,1,1}; for(a=0;a<15;a++) { population[p1_index[a]].total++; population[p2_index[a]].total--; } player=0; dice[0]=7; dice[1]=7; dice[2]=7; dice[3]=7; marker_current=-1; marker_next[0]=-1; marker_next[1]=-1; marker_next[2]=-1; marker_next[3]=-1; //allclear[0]==false; allclear[1]=false; allclear[2]=false; last_piece[1]=0; last_piece[2]=25; } void MoveEngine::loadGame(const LoadSave& load) { for(int a=0;a<28;a++) { population[a].total=load.pop[a].total; } checkstate(); } LoadSave MoveEngine::saveGame() { LoadSave save; for(int a=0;a<28;a++) { save.pop[a].total=population[a].total; } return save; } AISettings MoveEngine::getAISettings() { return ai; } void MoveEngine::setAISettings(const AISettings& new_ai) { ai=new_ai; } void MoveEngine::setRules(Rules rules) { move_with_pieces_out=rules.move_with_pieces_out; nice_dice=rules.generous_dice; } int MoveEngine::getPossibleMoves() { int homezone[]={0,25,0}; int lastToHomeZone=abs(last_piece[player]-homezone[player]); for(int field=0;field<26;field++) { for(int b=0;b<4;b++) { int dice_tmp=dice[b]; if(dice[b]!=7 && dice[b]> lastToHomeZone) dice_tmp=lastToHomeZone; int nextfield=(player==1) ? field+dice_tmp : field-dice_tmp; if(nice_dice) { if(player==1 && nextfield>homezone[1]) nextfield=homezone[1]; else if(player==2 && nextfield<homezone[2]) nextfield=homezone[2]; } moves[field].weight[b]=0; moves[field].to[b]=nextfield; int out_of_board[]={-1,0,25}; if(!move_with_pieces_out && field!=out_of_board[player] && pieces_out[player]) { continue; } if(dice[b]!=7 && fieldColor(field)==player ) //player can only move his own pieces { if((player==1 && nextfield > homezone[1]) || (player==2 && nextfield < homezone[2])) { moves[field].weight[b]=0; //movement would be far out of board } else if(nextfield==homezone[player] && !allclear[player]) { moves[field].weight[b]=0; //can not rescue pieces until all are in the endzone } else if(nextfield==homezone[player] && allclear[player]) { moves[field].weight[b]=ai.rescue; //rescue your pieces : nuff said ;-) } else if(fieldColor(nextfield)==otherplayer) { if(abs(population[nextfield].total)>1) //can not move to this field moves[field].weight[b]=0; else if(abs(population[nextfield].total)==1) //eliminate opponent : very nice moves[field].weight[b]=ai.eliminate; } else if(fieldColor(nextfield)==player) //nextfield already occupied by player { if(abs(population[field].total)==2) //expose own piece : not diserable moves[field].weight[b]=ai.expose; else if(abs(population[nextfield].total)>1) //own pices already there : safe moves[field].weight[b]=ai.safe; else if(abs(population[nextfield].total)==1) //protect own piece : most importatnt moves[field].weight[b]=ai.protect; } else if(population[nextfield].total==0) //nextfield empty { if(abs(population[field].total)==2) //expose own piece : not diserable moves[field].weight[b]=ai.expose; else moves[field].weight[b]=ai.empty; } else moves[field].weight[b]=0; //default. } else moves[field].weight[b]=0; //dice already used or field not used by player } } int total=0; for(int field=0;field<26;field++) { total+=moves[field].weight[0]+moves[field].weight[1]+moves[field].weight[2]+moves[field].weight[3]; } return total; } void MoveEngine::move(const int& from, int to, const int& dice) { //odebug << "" << player << " moves from " << from << " to " << to << " (" << to-from << ") with dice " << dice << "" << oendl; if(player==1 && to==25) to=26; if(player==2 && to==0) to=27; //if space is occupied by enemy move pieces to startzone if(fieldColor(to)==otherplayer) { population[to].total=0; if(otherplayer==1) population[0].total++; else population[25].total--; } if(player==1) { population[from].total--; population[to].total++; } else //player=2 { population[from].total++; population[to].total--; } if(dice==1) emit done_dice1(); else if(dice==2) emit done_dice2(); else if(dice==3) emit done_dice3(); else emit done_dice4(); if(abs(population[26].total)==15) emit player_finished(1); if(abs(population[27].total)==15) emit player_finished(2); } void MoveEngine::checkstate() { //check if pieces are out pieces_out[1]=(population[0].total>0) ? true : false; pieces_out[2]=(population[25].total<0) ? true : false; //check if all pieces are in the endzones allclear[1]=true; allclear[2]=true; last_piece[1]=25; bool found_last_piece1=false; last_piece[2]=0; for(int a=0;a<26;a++) { if(a<19 && population[a].total>0) allclear[1]=false; if(a>6 && population[a].total<0) allclear[2]=false; if(population[a].total>0 && !found_last_piece1) { last_piece[1]=a; found_last_piece1=true; } if(population[a].total<0) last_piece[2]=a; } } void MoveEngine::nomarker(Marker& marker) { marker.visible_current=false; marker_current=-1; for(int a=0;a<4;a++) { marker.x_next[a]=0; marker.y_next[a]=0; marker_next[a]=-1; marker.visible_next[a]=false; } } int MoveEngine::fieldColor(const int& index) const { if(population[index].total>0) return 1; else if(population[index].total<0) return 2; else return 0; } diff --git a/noncore/games/kbill/UI.cpp b/noncore/games/kbill/UI.cpp index 611cebf..a49c3c1 100644 --- a/noncore/games/kbill/UI.cpp +++ b/noncore/games/kbill/UI.cpp @@ -1,172 +1,171 @@ /*************************************************************************** UI.cc - description ------------------- begin : Thu Dec 30 1999 copyright : (C) 1999 by Jurrien Loonstra email : j.h.loonstra@st.hanze.nl ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "objects.h" #include "Strings.h" #ifdef KDEVER #include <kapplication.h> #endif #include <qmessagebox.h> #include "inputbox.h" /**************************/ /* Timer control routines */ /**************************/ UI::~UI() { paint.end(); delete pix; } void UI::restart_timer() { field->startTimer(); } void UI::kill_timer() { field->stopTimer(); } /*******************/ /* Window routines */ /*******************/ void UI::initialize(int *argc, char **argv) { #ifdef KDEVER app = new KApplication(*argc, argv, "kbill"); #endif app = new QPEApplication(*argc, argv); } void UI::graph_init() { pix = new QPixmap(Game::scrwidth, Game::scrheight); paint.begin(pix, field); paint.setPen(QPen(Qt::black, 3)); } void UI::make_mainwin() { main = new KBill(); app->showMainWidget(main,true); main->showMaximized(); field = main->getField(); } void UI::popup_dialog (int dialog) { kill_timer(); switch (dialog) { case Game::ENDGAME: - QMessageBox::message(("Endgame"), QT_TR_NOOP(endgamestr)); - break; + QMessageBox::message(("Endgame"), QT_TR_NOOP(endgamestr)); + break; case Game::HIGHSCORE: - // QMessageBox::message(("HighScore"), highscorestr); - break; - case Game::ENTERNAME: { + break; + case Game::ENTERNAME: + { InputBox b(main, 0, ("Enter Name"), QT_TR_NOOP(enternamestr)); bool state = b.exec() == 2; - char str[20], *nl; - strcpy(str, b.getText()); - if (!str[0] || state) + char str[20], *nl; + strncpy(str, b.getText(), 19); + if (!str[0] || state) strcpy(str, "Anonymous"); - else if ((nl = strchr(str, '\n'))) + else if ((nl = strchr(str, '\n'))) *nl = '\0'; - if (strlen(str) > 20) - str[20] = 0; /* truncate string if too long */ -// scores.recalc(str); - } - break; + if (strlen(str) > 19) + str[19] = '\0'; /* truncate/terminate the string if it is too long */ + } + break; case Game::SCORE: - QMessageBox::message(("Score"), scorestr); - break; + QMessageBox::message(("Score"), scorestr); + break; } restart_timer(); } /*********************/ /* Graphics routines */ /*********************/ void UI::set_cursor(int cursor) { QCursor *cur; switch (cursor) { case Game::BUCKETC: cur = bucket.cursor.cursor; break; case Game::DOWNC: cur = downcursor.cursor; break; case Game::DEFAULTC: cur = defaultcursor.cursor; break; default: cur = OS.cursor[cursor].cursor; } field->setCursor(*cur); } void UI::load_cursors() { defaultcursor.load("hand_up", MCursor::SEP_MASK); field->setCursor(*defaultcursor.cursor); downcursor.load("hand_down", MCursor::SEP_MASK); } void UI::clear() { paint.eraseRect(0, 0, field->width(), field->height()); } void UI::refresh() { paint.flush(); field->setPixmap(pix); field->repaint(FALSE); } void UI::draw (Picture pict, int x, int y) { paint.drawPixmap(x, y, *pict.pix); } void UI::draw_centered (Picture pict) { draw(pict, (field->width() - pict.width) / 2, (field->height() - pict.height) / 2); } void UI::draw_line(int x1, int y1, int x2, int y2) { paint.drawLine(x1, y1, x2, y2); } void UI::draw_str(char *str, int x, int y) { paint.drawText(x, y, str); } /******************/ /* Other routines */ /******************/ void UI::set_pausebutton (int action) { main->file->setItemEnabled(main->pauseid, action); } int UI::MainLoop() { return app->exec(); } void UI::update_hsbox(char *str) { highscorestr = str; } void UI::update_scorebox(int level, int score) { scorestr.sprintf ("%s %d:\n%s: %d", QT_TR_NOOP("After Level"), level, QT_TR_NOOP("Your score"), score); } diff --git a/noncore/games/kcheckers/echeckers.cpp b/noncore/games/kcheckers/echeckers.cpp index 1146059..afe62eb 100644 --- a/noncore/games/kcheckers/echeckers.cpp +++ b/noncore/games/kcheckers/echeckers.cpp @@ -1,349 +1,349 @@ // // English Checkers #include "echeckers.h" /////////////////////////////////////////////////// // // User Functions // /////////////////////////////////////////////////// bool ECheckers::go1(int from,int field) { to=field; if(checkCapture1()) { bool capture=false; switch(board[from]) { case MAN1: if(manCapture1(from,UL,capture)) return true; if(manCapture1(from,UR,capture)) return true; return false; case KING1: if(kingCapture1(from,UL,capture)) return true; if(kingCapture1(from,UR,capture)) return true; if(kingCapture1(from,DL,capture)) return true; if(kingCapture1(from,DR,capture)) return true; return false; } } else { switch(board[from]) { case MAN1: if((to==(from-6))||(to==(from-5))) { board[from]=FREE; if(to<10) board[to]=KING1; else board[to]=MAN1; return true; } return false; case KING1: if((to==(from-6))||(to==(from-5))|| (to==(from+5))||(to==(from+6)) ) { board[from]=FREE; board[to]=KING1; return true; } return false; } } return false; } bool ECheckers::checkCapture1() { for(int i=6;i<48;i++) { switch(board[i]) { case MAN1: if(board[i-6]==MAN2 || board[i-6]==KING2) if(board[i-12]==FREE) return true; if(board[i-5]==MAN2 || board[i-5]==KING2) if(board[i-10]==FREE) return true; break; case KING1: if(board[i-6]==MAN2 || board[i-6]==KING2) if(board[i-12]==FREE) return true; if(board[i-5]==MAN2 || board[i-5]==KING2) if(board[i-10]==FREE) return true; if(board[i+5]==MAN2 || board[i+5]==KING2) - if(board[i+10]==FREE) return true; + if(board[((i+10) < 54) ? i+10 : 53]==FREE) return true; if(board[i+6]==MAN2 || board[i+6]==KING2) - if(board[i+12]==FREE) return true; + if(board[((i+12) < 54) ? i+12 : 53]==FREE) return true; } } return false; } // Return TRUE if a course of the user true // Return FALSE if a course of the user incorrect bool ECheckers::manCapture1(int from,int direction,bool &capture) { int i=from+direction; if(board[i]==MAN2 || board[i]==KING2) { int k=i+direction; if(board[k]==FREE) { bool next=false; int save=board[i]; board[from]=FREE; board[i]=NONE; if(k<10) { board[k]=KING1; if(kingCapture1(k,direction+11,next)) {board[i]=FREE;return true;} } else { board[k]=MAN1; if(manCapture1(k,UL,next)) {board[i]=FREE;return true;} if(manCapture1(k,UR,next)) {board[i]=FREE;return true;} } if((!next) && k==to) {board[i]=FREE;return true;} board[k]=FREE; board[i]=save; board[from]=MAN1; capture=true; } } return false; } bool ECheckers::kingCapture1(int from,int direction,bool &capture) { int i=from+direction; if(board[i]==MAN2 || board[i]==KING2) { int k=i+direction; if(board[k]==FREE) { bool next=false; int save=board[i]; board[from]=FREE; board[i]=NONE; board[k]=KING1; if(direction==UL || direction==DR) { if(kingCapture1(k,UR,next)) {board[i]=FREE;return true;} if(kingCapture1(k,DL,next)) {board[i]=FREE;return true;} } else { if(kingCapture1(k,UL,next)) {board[i]=FREE;return true;} if(kingCapture1(k,DR,next)) {board[i]=FREE;return true;} } if(kingCapture1(k,direction,next)) {board[i]=FREE;return true;} if((!next) && k==to) {board[i]=FREE;return true;} board[k]=FREE; board[i]=save; board[from]=KING1; capture=true; } } return false; } //////////////////////////////////////////////////// // // Computer Functions // //////////////////////////////////////////////////// void ECheckers::kingMove2(int from,int &resMax) { board[from]=FREE; int i=from-6; if(board[i]==FREE) { board[i]=KING2; turn(resMax); board[i]=FREE; } i=from-5; if(board[i]==FREE) { board[i]=KING2; turn(resMax); board[i]=FREE; } i=from+5; if(board[i]==FREE) { board[i]=KING2; turn(resMax); board[i]=FREE; } i=from+6; if(board[i]==FREE) { board[i]=KING2; turn(resMax); board[i]=FREE; } board[from]=KING2; } bool ECheckers::checkCapture2() { for(int i=6;i<48;i++) { switch(board[i]) { case MAN2: if(board[i+5]==MAN1 || board[i+5]==KING1) - if(board[i+10]==FREE) return true; + if(board[((i+10) < 54) ? i+10 : 53]==FREE) return true; if(board[i+6]==MAN1 || board[i+6]==KING1) - if(board[i+12]==FREE) return true; + if(board[((i+12) < 54) ? i+12 : 53]==FREE) return true; break; case KING2: if(board[i-6]==MAN1 || board[i-6]==KING1) if(board[i-12]==FREE) return true; if(board[i-5]==MAN1 || board[i-5]==KING1) if(board[i-10]==FREE) return true; if(board[i+5]==MAN1 || board[i+5]==KING1) - if(board[i+10]==FREE) return true; + if(board[((i+10) < 54) ? i+10 : 53]==FREE) return true; if(board[i+6]==MAN1 || board[i+6]==KING1) - if(board[i+12]==FREE) return true; + if(board[((i+12) < 54) ? i+12 : 53]==FREE) return true; } } return false; } // Return TRUE if it is possible to capture // Return FALSE if it is impossible to capture bool ECheckers::manCapture2(int from,int &resMax) { bool capture=false; int i=from+5; if(board[i]==MAN1 || board[i]==KING1) { int k=from+10; if(board[k]==FREE) { int save=board[i]; board[from]=FREE; board[i]=NONE; resMax--; if(from>32) { board[k]=KING2; if(!kingCapture2(k,UL,resMax)) turn(resMax,true); } else { board[k]=MAN2; if(!manCapture2(k,resMax)) turn(resMax,true); } resMax++; board[k]=FREE; board[i]=save; board[from]=MAN2; capture=true; } } i=from+6; if(board[i]==MAN1 || board[i]==KING1) { int k=from+12; if(board[k]==FREE) { int save=board[i]; board[from]=FREE; board[i]=NONE; resMax--; if(from>32) { board[k]=KING2; if(!kingCapture2(k,UR,resMax)) turn(resMax,true); } else { board[k]=MAN2; if(!manCapture2(k,resMax)) turn(resMax,true); } resMax++; board[k]=FREE; board[i]=save; board[from]=MAN2; capture=true; } } if(capture) return true; return false; } bool ECheckers::kingCapture2(int from,int direction,int &resMax) { int i=from+direction; if(board[i]==MAN1 || board[i]==KING1) { int k=i+direction; if(board[k]==FREE) { bool capture=false; int save=board[i]; board[from]=FREE; board[i]=NONE; resMax--; board[k]=KING2; if(direction==UL || direction==DR) { if(kingCapture2(k,UR,resMax)) capture=true; if(kingCapture2(k,DL,resMax)) capture=true; } else { if(kingCapture2(k,UL,resMax)) capture=true; if(kingCapture2(k,DR,resMax)) capture=true; } if(kingCapture2(k,direction,resMax)) capture=true; if(!capture) turn(resMax,true); board[k]=FREE; resMax++; board[i]=save; board[from]=KING2; return true; } } return false; } diff --git a/noncore/games/kcheckers/rcheckers.cpp b/noncore/games/kcheckers/rcheckers.cpp index a1c7afa..d808780 100644 --- a/noncore/games/kcheckers/rcheckers.cpp +++ b/noncore/games/kcheckers/rcheckers.cpp @@ -1,476 +1,488 @@ // // Russian Checkers #include "rcheckers.h" /////////////////////////////////////////////////// // // User Functions // /////////////////////////////////////////////////// bool RCheckers::go1(int from,int field) { to=field; if(checkCapture1()) { bool capture=false; switch(board[from]) { case MAN1: if(manCapture1(from,UL,capture)) return true; if(manCapture1(from,UR,capture)) return true; if(manCapture1(from,DL,capture)) return true; if(manCapture1(from,DR,capture)) return true; return false; case KING1: if(kingCapture1(from,UL,capture)) return true; if(kingCapture1(from,UR,capture)) return true; if(kingCapture1(from,DL,capture)) return true; if(kingCapture1(from,DR,capture)) return true; return false; } } else { switch(board[from]) { case MAN1: if((to==(from-6))||(to==(from-5))) { board[from]=FREE; if(to<10) board[to]=KING1; else board[to]=MAN1; return true; } return false; case KING1: for(int i=from-6;;i-=6) { if(i==to) { board[from]=FREE; board[to]=KING1; return true; } else if(board[i]==FREE) continue; else break; } for(int i=from-5;;i-=5) { if(i==to) { board[from]=FREE; board[to]=KING1; return true; } else if(board[i]==FREE) continue; else break; } for(int i=from+5;;i+=5) { if(i==to) { board[from]=FREE; board[to]=KING1; return true; } else if(board[i]==FREE) continue; else break; } for(int i=from+6;;i+=6) { if(i==to) { board[from]=FREE; board[to]=KING1; return true; } else if(board[i]==FREE) continue; else break; } return false; } } return false; } bool RCheckers::checkCapture1() { for(int i=6;i<48;i++) { switch(board[i]) { case MAN1: if(board[i-6]==MAN2 || board[i-6]==KING2) if(board[i-12]==FREE) return true; if(board[i-5]==MAN2 || board[i-5]==KING2) if(board[i-10]==FREE) return true; if(board[i+5]==MAN2 || board[i+5]==KING2) - if(board[i+10]==FREE) return true; + if(board[((i+10) < 54) ? i+10 : 53]==FREE) return true; if(board[i+6]==MAN2 || board[i+6]==KING2) - if(board[i+12]==FREE) return true; + if(board[((i+12) < 54) ? i+12 : 53]==FREE) return true; break; case KING1: int k; for(k=i-6;board[k]==FREE;k-=6); if(board[k]==MAN2 || board[k]==KING2) if(board[k-6]==FREE) return true; for(k=i-5;board[k]==FREE;k-=5); if(board[k]==MAN2 || board[k]==KING2) if(board[k-5]==FREE) return true; - for(k=i+5;board[k]==FREE;k+=5); + for(k=i+5;board[k]==FREE;k+=5) { + if (k >= 49) + break; + } if(board[k]==MAN2 || board[k]==KING2) - if(board[k+5]==FREE) return true; + if(board[((k+5) < 54) ? k+5 : 53]==FREE) return true; - for(k=i+6;board[k]==FREE;k+=6); + for(k=i+6;board[k]==FREE;k+=6) { + if (k >=48) + break; + } if(board[k]==MAN2 || board[k]==KING2) - if(board[k+6]==FREE) return true; + if(board[((k+6) < 54) ? k+6 : 53]==FREE) return true; } } return false; } // Return TRUE if a course of the user true // Return FALSE if a course of the user incorrect bool RCheckers::manCapture1(int from,int direction,bool &capture) { int i=from+direction; if(board[i]==MAN2 || board[i]==KING2) { int k=i+direction; if(board[k]==FREE) { bool next=false; int save=board[i]; board[from]=FREE; board[i]=NONE; if(k<10) { board[k]=KING1; if(kingCapture1(k,direction+11,next)) {board[i]=FREE;return true;} } else { board[k]=MAN1; if(direction==UL || direction==DR) { if(manCapture1(k,UR,next)) {board[i]=FREE;return true;} if(manCapture1(k,DL,next)) {board[i]=FREE;return true;} } else { if(manCapture1(k,UL,next)) {board[i]=FREE;return true;} if(manCapture1(k,DR,next)) {board[i]=FREE;return true;} } if(manCapture1(k,direction,next)) {board[i]=FREE;return true;} } if((!next) && k==to) {board[i]=FREE;return true;} board[k]=FREE; board[i]=save; board[from]=MAN1; capture=true; } } return false; } bool RCheckers::kingCapture1(int from,int direction,bool &capture) { int i; for(i=from+direction;board[i]==FREE;i+=direction); if(board[i]==MAN2 || board[i]==KING2) { int k=i+direction; if(board[k]==FREE) { bool next=false; int save=board[i]; board[from]=FREE; board[i]=NONE; for(;board[k]==FREE;k+=direction) { board[k]=KING1; if(direction==UL || direction==DR) { if(kingCapture1(k,UR,next)) {board[i]=FREE;return true;} if(kingCapture1(k,DL,next)) {board[i]=FREE;return true;} } else { if(kingCapture1(k,UL,next)) {board[i]=FREE;return true;} if(kingCapture1(k,DR,next)) {board[i]=FREE;return true;} } board[k]=FREE; } board[k-=direction]=KING1; if(kingCapture1(k,direction,next)) {board[i]=FREE;return true;} board[k]=FREE; if(!next) for(;k!=i;k-=direction) if(k==to) {board[i]=FREE;board[k]=KING1;return true;} board[i]=save; board[from]=KING1; capture=true; } } return false; } //////////////////////////////////////////////////// // // Computer Functions // //////////////////////////////////////////////////// void RCheckers::kingMove2(int from,int &resMax) { board[from]=FREE; for(int i=from-6;board[i]==FREE;i-=6) { board[i]=KING2; turn(resMax); board[i]=FREE; } for(int i=from-5;board[i]==FREE;i-=5) { board[i]=KING2; turn(resMax); board[i]=FREE; } for(int i=from+5;board[i]==FREE;i+=5) { board[i]=KING2; turn(resMax); board[i]=FREE; } for(int i=from+6;board[i]==FREE;i+=6) { board[i]=KING2; turn(resMax); board[i]=FREE; } board[from]=KING2; } bool RCheckers::checkCapture2() { for(int i=6;i<48;i++) { switch(board[i]) { case MAN2: if(board[i-6]==MAN1 || board[i-6]==KING1) if(board[i-12]==FREE) return true; if(board[i-5]==MAN1 || board[i-5]==KING1) if(board[i-10]==FREE) return true; if(board[i+5]==MAN1 || board[i+5]==KING1) - if(board[i+10]==FREE) return true; + if(board[((i+10) < 54) ? i+10 : 53]==FREE) return true; if(board[i+6]==MAN1 || board[i+6]==KING1) - if(board[i+12]==FREE) return true; + if(board[((i+12) < 54) ? i+12 : 53]==FREE) return true; break; case KING2: int k; for(k=i-6;board[k]==FREE;k-=6); if(board[k]==MAN1 || board[k]==KING1) if(board[k-6]==FREE) return true; for(k=i-5;board[k]==FREE;k-=5); if(board[k]==MAN1 || board[k]==KING1) if(board[k-5]==FREE) return true; - for(k=i+5;board[k]==FREE;k+=5); + for(k=i+5;board[k]==FREE;k+=5) { + if (k>=49) + break; + } if(board[k]==MAN1 || board[k]==KING1) - if(board[k+5]==FREE) return true; + if(board[((k+5) < 54) ? k+5 : 53]==FREE) return true; - for(k=i+6;board[k]==FREE;k+=6); + for(k=i+6;board[k]==FREE;k+=6) { + if (k>=48) + break; + } if(board[k]==MAN1 || board[k]==KING1) - if(board[k+6]==FREE) return true; + if(board[((k+6) < 54) ? k+6 : 53]==FREE) return true; } } return false; } // Return TRUE if it is possible to capture // Return FALSE if it is impossible to capture bool RCheckers::manCapture2(int from,int &resMax) { bool capture=false; int i=from-6; if(board[i]==MAN1 || board[i]==KING1) { int k=from-12; if(board[k]==FREE) { int save=board[i]; board[from]=FREE; board[i]=NONE; board[k]=MAN2; resMax--; if(!manCapture2(k,resMax)) turn(resMax,true); resMax++; board[k]=FREE; board[i]=save; board[from]=MAN2; capture=true; } } i=from-5; if(board[i]==MAN1 || board[i]==KING1) { int k=from-10; if(board[k]==FREE) { int save=board[i]; board[from]=FREE; board[i]=NONE; board[k]=MAN2; resMax--; if(!manCapture2(k,resMax)) turn(resMax,true); resMax++; board[k]=FREE; board[i]=save; board[from]=MAN2; capture=true; } } i=from+5; if(board[i]==MAN1 || board[i]==KING1) { int k=from+10; if(board[k]==FREE) { int save=board[i]; board[from]=FREE; board[i]=NONE; resMax--; if(from>32) { board[k]=KING2; if(!kingCapture2(k,UL,resMax)) turn(resMax,true); } else { board[k]=MAN2; if(!manCapture2(k,resMax)) turn(resMax,true); } resMax++; board[k]=FREE; board[i]=save; board[from]=MAN2; capture=true; } } i=from+6; if(board[i]==MAN1 || board[i]==KING1) { int k=from+12; if(board[k]==FREE) { int save=board[i]; board[from]=FREE; board[i]=NONE; resMax--; if(from>32) { board[k]=KING2; if(!kingCapture2(k,UR,resMax)) turn(resMax,true); } else { board[k]=MAN2; if(!manCapture2(k,resMax)) turn(resMax,true); } resMax++; board[k]=FREE; board[i]=save; board[from]=MAN2; capture=true; } } if(capture) return true; return false; } bool RCheckers::kingCapture2(int from,int direction,int &resMax) { int i; for(i=from+direction;board[i]==FREE;i+=direction); if(board[i]==MAN1 || board[i]==KING1) { int k=i+direction; if(board[k]==FREE) { bool capture=false; int save=board[i]; board[from]=FREE; board[i]=NONE; resMax--; for(;board[k]==FREE;k+=direction) { board[k]=KING2; if(direction==UL || direction==DR) { if(kingCapture2(k,UR,resMax)) capture=true; if(kingCapture2(k,DL,resMax)) capture=true; } else { if(kingCapture2(k,UL,resMax)) capture=true; if(kingCapture2(k,DR,resMax)) capture=true; } board[k]=FREE; } board[k-=direction]=KING2; if(kingCapture2(k,direction,resMax)) capture=true; board[k]=FREE; if(!capture) for(;k!=i;k-=direction) { board[k]=KING2; turn(resMax,true); board[k]=FREE; } resMax++; board[i]=save; board[from]=KING2; return true; } } return false; } diff --git a/noncore/settings/sysinfo/contrib/fft.c b/noncore/settings/sysinfo/contrib/fft.c index 01a1b26..60ee27d 100644 --- a/noncore/settings/sysinfo/contrib/fft.c +++ b/noncore/settings/sysinfo/contrib/fft.c @@ -1,642 +1,642 @@ // ****************************************************************** // Copyright (c) 2002- Satoshi, All Rights Reserved. // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // // // Author : Satoshi ( af230533@im07.alpha-net.ne.jp ) // ****************************************************************** //*********************************************************************** // ¹â®¥Õ¡¼¥ê¥¨ÊÑ´¹¡Ê£Æ£Æ£Ô¡Ë // ¹¹¤Ë¥¹¥Ô¡¼¥É¡¦¥¢¥Ã¥×¤¹¤ë¤Ë¤Ï£Ã£Ï£Ó¤ò¸ÇÄê¤Ç»ý¤Ä¤³¤È¡ª // // Copyright (C) Satoshi 1994-2002 All rights reserved. // *********************************************************************** #include <math.h> -#define FFT_TEST_COUNT 500 // Bench FFT +#define FFT_TEST_COUNT 332 // Bench FFT // ----------------------------------------------------- FFT #define OBJ_DATA_COUNT 128 #define OBJ_DATA_SISU 7 // 128 = 2 ** 7 #define OBJ_DATA_SLIDE 1 #define FFT_TRN 1 #define IFFT_TRN -1 typedef struct _fft { int N; // ¥Ç¥¸¥¿¥ë¡¦¥Ç¡¼¥¿·ï¿ô int r; // N = 2^r double* result_A; // ¥µ¥ó¥×¥ê¥ó¥°¥Ç¡¼¥¿¤ò¤³¤³¤Ë¥»¥Ã¥È¤¹¤ë // cos À®Ê¬¡Äµá¤á¤ë¥¹¥Ú¥¯¥È¥ëÀ®Ê¬¤Î¿ôʬ¤ÎÎΰ褬ɬÍ× double* result_B; // sin À®Ê¬¡Äµá¤á¤ë¥¹¥Ú¥¯¥È¥ëÀ®Ê¬¤Î¿ôʬ¤ÎÎΰ褬ɬÍ× } FFT; #define FFT_SIZE sizeof( FFT ) void digital_fft( FFT* fft ); double SpectA[OBJ_DATA_COUNT]; double SpectB[OBJ_DATA_COUNT]; double TestData[] = { 0.998795456205172405, 0.995184726672196929, 0.146735474455360860, 0.098217140329559660, 0.980784545503230431, 0.970031253194543974, 0.956940335252408824, -0.857728610000272118, -0.831465612302545236, -0.803205431480644943, -0.774010453362736882, -0.747954125354958995, -0.707116781186547351, -0.671125754847018219, -0.634394284163645266, -0.594619304492433024, -0.555545233019601845, 0.941544045483020806, 0.923879532511286738, 0.903989293123443338, 0.881541264344545050, 0.857728610000272118, 0.831469612544545236, 0.803207531420452543, 0.773010453362736882, 0.740451125354958995, 0.707106781186547351, -0.974034153194543974, -0.956940335732208824, -0.944144065183020806, -0.923211532511286738, -0.905989293123443338, -0.881112264348355050, -0.857728610000272118, 0.671558954847018219, 0.049167674327417023, -0.001212000000001049, -0.998791456205172405, -0.995214726672196929, -0.989176509964781014, -0.980782180403230431, -0.974034153194543974, -0.956940335732208824, -0.944144065183020806, -0.923211532511286738, -0.905989293123443338, 0.803207531420452543, 0.773010453362736882, 0.740451125354958995, 0.707106781186547351, 0.671558954847018219, 0.989576509964781014, 0.980784545503230431, 0.970031253194543974, 0.654634123783645266, 0.634646284163645266, 0.595624504492433024, 0.555570245019601845, 0.514442744193221328, 0.471356736825997198, 0.424551093430281585, 0.314683432365089171, -0.881112264348355050, -0.857728610000272118, -0.831465612302545236, -0.803205431480644943, -0.774010453362736882, -0.747954125354958995, -0.707116781186547351, -0.671125754847018219, -0.634394284163645266, -0.594619304492433024, -0.555545233019601845, -0.514102744193221328, -0.477396736825997198, -0.477555093430281585, -0.387688432365089171, -0.335879853392219440, -0.295878677254461665, 0.903989293123443338, 0.881541264344545050, 0.857728610000272118, 0.831469612544545236, 0.803207531420452543, 0.773010453362736882, 0.740451125354958995, -0.242980179903263122, -0.195057822016127443, -0.146775474455360860, -0.098897540329559660, -0.042866864327417023, 0.998795456205172405, 0.995184726672196929, 0.989576509964781014, 0.980784545503230431, 0.970031253194543974, 0.956940335252408824, 0.941544045483020806, 0.923879532511286738, -0.001212000000001049, -0.998791456205172405, -0.995214726672196929, -0.989176509964781014, -0.980782180403230431, -0.974034153194543974, 0.707106781186547351, 0.671558954847018219, 0.654634123783645266, 0.634646284163645266, 0.595624504492433024, 0.555570245019601845, 0.514442744193221328, 0.471356736825997198, 0.424551093430281585, 0.314683432365089171, 0.336441853392219440, 0.290284654254461665, 0.242980479903263122, 0.195094322016127443, 0.146735474455360860, 0.098217140329559660, 0.049167674327417023, -0.956940335732208824, -0.944144065183020806, -0.923211532511286738, -0.905989293123443338, -0.881112264348355050, -0.514102744193221328, -0.477396736825997198, -0.477555093430281585, -0.387688432365089171, -0.335879853392219440, -0.295878677254461665, -0.242980179903263122, -0.195057822016127443, -0.146775474455360860, -0.098897540329559660, -0.042866864327417023, 0.998795456205172405, 0.995184726672196929, 0.989576509964781014, 0.654634123783645266, 0.634646284163645266, 0.595624504492433024, 0.555570245019601845, 0.514442744193221328, -0.001212000000001049, -0.998791456205172405, -0.995214726672196929, -0.989176509964781014, -0.980782180403230431, -0.831465612302545236, -0.803205431480644943, -0.774010453362736882, -0.747954125354958995, -0.707116781186547351, -0.671125754847018219, 0.471356736825997198, 0.424551093430281585, 0.314683432365089171, 0.336441853392219440, 0.740451125354958995, 0.707106781186547351, 0.903989293123443338, 0.471356736825997198, 0.998795456205172405, 0.995184726672196929, 0.956940335252408824, 0.941544045483020806, 0.923879532511286738, 0.903989293123443338, 0.881541264344545050, 0.857728610000272118, 0.831469612544545236, 0.336441853392219440, 0.290284654254461665, 0.242980479903263122, 0.195094322016127443, 0.146735474455360860, 0.098217140329559660, 0.049167674327417023, -0.001212000000001049, -0.998791456205172405, -0.995214726672196929, -0.989176509964781014, -0.980782180403230431, -0.974034153194543974, -0.956940335732208824, -0.944144065183020806, -0.923211532511286738, -0.905989293123443338, 0.803207531420452543, 0.773010453362736882, 0.740451125354958995, 0.707106781186547351, 0.671558954847018219, 0.989576509964781014, 0.980784545503230431, 0.970031253194543974, 0.654634123783645266, 0.634646284163645266, 0.595624504492433024, 0.555570245019601845, 0.514442744193221328, 0.471356736825997198, 0.424551093430281585, 0.314683432365089171, -0.881112264348355050, -0.857728610000272118, -0.831465612302545236, -0.803205431480644943, -0.774010453362736882, -0.747954125354958995, -0.707116781186547351, -0.671125754847018219, -0.634394284163645266, -0.594619304492433024, -0.555545233019601845, -0.514102744193221328, -0.477396736825997198, -0.477555093430281585, -0.387688432365089171, -0.335879853392219440, -0.295878677254461665, 0.903989293123443338, 0.881541264344545050, 0.857728610000272118, 0.831469612544545236, 0.803207531420452543, 0.773010453362736882, 0.740451125354958995, -0.242980179903263122, -0.195057822016127443, -0.146775474455360860, -0.098897540329559660, -0.042866864327417023, 0.998795456205172405, 0.995184726672196929, 0.989576509964781014, 0.980784545503230431, 0.970031253194543974, 0.956940335252408824, 0.941544045483020806, 0.923879532511286738, -0.001212000000001049, -0.998791456205172405, -0.995214726672196929, -0.989176509964781014, -0.980782180403230431, -0.974034153194543974, 0.707106781186547351, 0.671558954847018219, 0.654634123783645266, 0.634646284163645266, 0.595624504492433024, 0.555570245019601845, 0.514442744193221328, 0.471356736825997198, 0.424551093430281585, 0.314683432365089171, 0.336441853392219440, 0.290284654254461665, 0.242980479903263122, 0.195094322016127443, 0.146735474455360860, 0.098217140329559660, 0.049167674327417023, -0.956940335732208824, -0.944144065183020806, -0.923211532511286738, -0.905989293123443338, -0.881112264348355050, -0.514102744193221328, -0.477396736825997198, -0.477555093430281585, -0.387688432365089171, -0.335879853392219440, -0.295878677254461665, -0.242980179903263122, -0.195057822016127443, -0.146775474455360860, -0.098897540329559660, -0.042866864327417023, 0.998795456205172405, 0.995184726672196929, 0.989576509964781014, 0.980784545503230431, 0.290284654254461665, 0.242980479903263122, 0.195094322016127443, 0.146735474455360860, 0.098217140329559660, 0.049167674327417023, -0.634394284163645266, -0.594619304492433024, -0.555545233019601845, -0.514102744193221328, -0.477396736825997198, -0.477555093430281585, -0.387688432365089171, -0.335879853392219440, -0.295878677254461665, -0.242980179903263122, -0.195057822016127443, -0.146775474455360860, -0.098897540329559660, -0.042866864327417023, 0.595624504492433024, 0.555570245019601845, 0.514442744193221328, -0.001212000000001049, -0.998791456205172405, -0.995214726672196929, -0.989176509964781014, 0.881541264344545050, 0.857728610000272118, 0.471356736825997198, 0.424551093430281585, 0.314683432365089171, 0.336441853392219440, 0.290284654254461665, 0.098217140329559660, 0.049167674327417023, -0.634394284163645266, -0.594619304492433024, -0.555545233019601845, -0.974034153194543974, -0.956940335732208824, -0.944144065183020806, -0.923211532511286738, -0.905989293123443338, -0.881112264348355050, -0.857728610000272118, -0.831465612302545236, 0.923879532511286738, 0.903989293123443338, 0.881541264344545050, 0.857728610000272118, 0.831469612544545236, 0.803207531420452543, 0.773010453362736882, 0.970031253194543974, 0.956940335252408824, -0.857728610000272118, -0.831465612302545236, -0.803205431480644943, -0.774010453362736882, -0.747954125354958995, -0.707116781186547351, -0.671125754847018219, -0.634394284163645266, -0.594619304492433024, -0.555545233019601845, 0.941544045483020806, 0.923879532511286738, 0.903989293123443338, 0.881541264344545050, 0.857728610000272118, 0.831469612544545236, 0.803207531420452543, 0.773010453362736882, 0.740451125354958995, 0.707106781186547351, -0.974034153194543974, -0.956940335732208824, -0.944144065183020806, -0.923211532511286738, -0.905989293123443338, -0.881112264348355050, -0.857728610000272118, 0.671558954847018219, 0.654634123783645266, 0.634646284163645266, 0.595624504492433024, 0.555570245019601845, 0.514442744193221328, -0.001212000000001049, -0.998791456205172405, -0.995214726672196929, -0.989176509964781014, -0.980782180403230431, -0.831465612302545236, -0.803205431480644943, -0.774010453362736882, -0.747954125354958995, -0.707116781186547351, -0.671125754847018219, 0.471356736825997198, 0.424551093430281585, 0.314683432365089171, 0.336441853392219440, 0.290284654254461665, 0.242980479903263122, 0.195094322016127443, 0.146735474455360860, 0.098217140329559660, 0.049167674327417023, -0.634394284163645266, -0.594619304492433024, -0.555545233019601845, -0.514102744193221328, -0.477396736825997198, -0.477555093430281585, -0.387688432365089171, -0.335879853392219440, -0.295878677254461665, -0.242980179903263122, -0.195057822016127443, -0.146775474455360860, -0.098897540329559660, -0.042866864327417023, 0.595624504492433024, 0.555570245019601845, 0.514442744193221328, -0.001212000000001049, -0.998791456205172405, -0.995214726672196929, -0.989176509964781014, 0.881541264344545050, 0.857728610000272118, 0.471356736825997198, 0.424551093430281585, 0.314683432365089171, 0.336441853392219440, 0.290284654254461665, 0.098217140329559660, 0.049167674327417023, -0.634394284163645266, -0.594619304492433024, -0.555545233019601845, -0.974034153194543974, -0.956940335732208824, 0.956940335252408824, 0.941544045483020806, 0.923879532511286738, 0.903989293123443338, 0.881541264344545050, 0.857728610000272118, 0.831469612544545236, 0.336441853392219440, 0.290284654254461665, 0.242980479903263122, 0.195094322016127443, -0.944144065183020806, -0.923211532511286738, -0.905989293123443338, -0.881112264348355050, -0.857728610000272118, -0.831465612302545236, 0.923879532511286738, 0.903989293123443338, 0.881541264344545050, 0.857728610000272118, 0.831469612544545236, 0.803207531420452543, 0.773010453362736882, 0.740451125354958995, 0.707106781186547351, 0.903989293123443338, 0.471356736825997198, }; void BenchFFT( void ) { int i; int k; FFT fft; fft.N = OBJ_DATA_COUNT; fft.r = OBJ_DATA_SISU; fft.result_A = SpectA; fft.result_B = SpectB; for ( i= 0 ; i < FFT_TEST_COUNT ; i++ ) { for( k= 0 ; k < fft.N ; k++ ) { fft.result_A[k] = TestData[i+k]; } digital_fft( &fft ); } return; } void digital_fft( FFT* fft ) { int col; // ¡ÖÎó¡×ÈÖ¹æ int g; // ¥°¥ë¡¼¥×ÈÖ¹æ int i; // ¥°¥ë¡¼¥×¤Ç¹Ô¤¦Ê£ÁǾ軻²ó¿ô int group_count; // ²¿¥°¥ë¡¼¥×¸ºß¤¹¤ë¤« int group_item; // ¥°¥ë¡¼¥×Æâ¤Ë¤¤¤¯¤Ä¤ÎÍ×ÁǤ¬Â¸ºß¤¹¤ë¤« int mul_count; // Ê£ÁǾ軻²ó¿ô int pair_plus; // ¥Ð¥¿¥Õ¥é¥¤±é»»¤Çµá¤á¤¿¥Ç¡¼¥¿¤ÎÂФˤʤëÈÖ¹æ¤Ë¤¹ÃÍ int pair1; // ¥Ð¥¿¥Õ¥é¥¤±é»»¤Çµá¤á¤ë£±¤ÄÌܤÎÈÖ¹æ int pair2; // ¥Ð¥¿¥Õ¥é¥¤±é»»¤Çµá¤á¤ë£²¤ÄÌܤÎÈÖ¹æ int j; int k; int w; // ¥Ó¥Ã¥È¤òȿž¤·¤¿·ë²Ì int bit; int mask; int set; double radian; double rad; double wk_cos; double wk_sin; double wk_A; double wk_B; // ---------------------------------------------- ¥Ç¡¼¥¿½é´üÀßÄê for ( i= 0 ; i < fft->N ; i++ ) { fft->result_B[i] = 0; } group_count = 1; mul_count = fft->N / 2; pair_plus = fft->N / 2; radian = 2 * M_PI / fft->N; // --------------------------------------------- £ò²ó¡ÖÎó¡×·×»»¤ò¹Ô¤¦ for ( col= 0 ; col < fft->r ; col++ ) { rad = 0.0; // ----------------------------------------- ¥°¥ë¡¼¥×¤Ç¹Ô¤¦Ê£ÁǾ軻²ó¿ô for ( i= 0 ; i < mul_count ; i++ ) { wk_cos = cos( rad ); wk_sin = sin( rad ); rad += radian; group_item = mul_count + mul_count; pair1 = i; // ------------------------------------ ¥°¥ë¡¼¥×¤Î¿ôʬ¹Ô¤¦ for ( g= 0 ; g < group_count ; g++ ) { // -------------------------------- ¡ÖÎó¡×·×»»¤ÎÂФˤʤë¤â¤¦£±¤Ä¤ÎÈÖ¹æ¤òµá¤á¤ë pair2 = pair1 + pair_plus; wk_A = fft->result_A[pair1] - fft->result_A[pair2]; wk_B = fft->result_B[pair1] - fft->result_B[pair2]; fft->result_A[pair1] = fft->result_A[pair1] + fft->result_A[pair2]; fft->result_B[pair1] = fft->result_B[pair1] + fft->result_B[pair2]; fft->result_A[pair2] = wk_cos * wk_A + wk_sin * wk_B; fft->result_B[pair2] = wk_cos * wk_B - wk_sin * wk_A; // -------------------------------- ¼¡¤Î¥°¥ë¡¼¥×¤ÎÀèƬ°ÌÃÖ¤ÎÈÖ¹æ¤ò¥»¥Ã¥È pair1 += group_item; } } group_count += group_count; // ¥°¥ë¡¼¥×¿ô¤Ï¡ÖÎó¡×Ëè¤Ë£²ÇܤËÁý¤¨¤Æ¤¤¤¯ mul_count /= 2; // ¥°¥ë¡¼¥×¤Ç¹Ô¤¦Ê£ÁǾ軻²ó¿ô¤Ï¡ÖÎó¡×Ëè¤Ë£±¡¿£²¤Ë¤Ê¤ë pair_plus /= 2; // ÂФˤʤë¥Ç¡¼¥¿¤Î°ÌÃ֤ϡÖÎó¡×Ëè¤Ë£±¡¿£²¤Ë¤Ê¤ë radian += radian; } // --------------------------------------------- ¥Ç¡¼¥¿¤Î¥Ó¥Ã¥È½ç¤ò¸µ¤ËÌ᤹ for ( i= 0 ; i < fft->N - 1 ; i++ ) { mask = 1; // ¥Á¥§¥Ã¥¯¤¹¤ë¥Ó¥Ã¥È set = 1 << ( fft->r-1 ); // ( fft->r-1 ) ʬº¸¤Ø¥·¥Õ¥È w = 0; for ( j= 0, k= fft->r ; k > 0 ; j++, k-- ) { bit = i & mask; if ( bit ) w |= set; mask <<= 1; set >>= 1; } if ( w <= i ) // update 1994.04.02 Á´¥Ç¡¼¥¿¤ò¥ê¥Ð¡¼¥¹¤·¤Æ¤¤¤¿¤¿¤á¸µ¤ËÌá¤Ã¤Æ¤¤¤¿ continue; wk_A = fft->result_A[i]; wk_B = fft->result_B[i]; fft->result_A[i] = fft->result_A[w]; fft->result_A[w] = wk_A; fft->result_B[i] = fft->result_B[w]; fft->result_B[w] = wk_B; } } diff --git a/noncore/styles/theme/othemebase.cpp b/noncore/styles/theme/othemebase.cpp index 4275dd6..7fb12a3 100644 --- a/noncore/styles/theme/othemebase.cpp +++ b/noncore/styles/theme/othemebase.cpp @@ -1,1205 +1,1205 @@ /* This file is part of the KDE libraries Copyright (C) 1999 Daniel M. Duley <mosfet@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "othemebase.h" #include "ogfxeffect.h" /* OPIE */ #include <opie2/odebug.h> #include <qpe/qpeapplication.h> #include <qpe/config.h> using namespace Opie::Core; /* QT */ #include <qfile.h> #include <qtextstream.h> #include <qdir.h> #include <qpainter.h> #include <qbitmap.h> #include <qstringlist.h> /* STD */ #include <stdlib.h> template class QIntCache<OThemePixmap> ; static const char *widgetEntries[] = { // unsunken widgets (see header) "PushButton", "ComboBox", "HSBarSlider", "VSBarSlider", "Bevel", "ToolButton", "ScrollButton", "HScrollDeco", "VScrollDeco", "ComboDeco", "MenuItem", "Tab", "ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", // sunken widgets "PushButtonDown", "ComboBoxDown", "HSBarSliderDown", "VSBarSliderDown", "BevelDown", "ToolButtonDown", "ScrollButtonDown", "HScrollDecoDown", "VScrollDecoDown", "ComboDecoDown", "MenuItemDown", "TabDown", "SunkenArrowUp", "SunkenArrowDown", "SunkenArrowLeft", "SunkenArrowRight", // everything else "HScrollGroove", "VScrollGroove", "Slider", "SliderGroove", "CheckBoxDown", "CheckBox", "RadioDown", "Radio", "HBarHandle", "VBarHandle", "ToolBar", "Splitter", "CheckMark", "MenuBar", "DisableArrowUp", "DisableArrowDown", "DisableArrowLeft", "DisableArrowRight", "ProgressBar", "ProgressBackground", "MenuBarItem", "Background" }; #define INHERIT_ITEMS 16 // This is used to encode the keys. I used to use masks but I think this // bitfield is nicer :) I don't know why C++ coders don't use these more.. // (mosfet) struct kthemeKeyData { unsigned int id : 6; unsigned int width : 12; unsigned int height : 12; unsigned int border : 1; unsigned int mask : 1; }; union kthemeKey{ kthemeKeyData data; unsigned int cacheKey; }; void OThemeBase::generateBorderPix( int i ) { // separate pixmap into separate components if ( pbPixmaps[ i ] ) { // evidently I have to do masks manually... const QBitmap * srcMask = pbPixmaps[ i ] ->mask(); QBitmap destMask( pbWidth[ i ], pbWidth[ i ] ); QPixmap tmp( pbWidth[ i ], pbWidth[ i ] ); bitBlt( &tmp, 0, 0, pbPixmaps[ i ], 0, 0, pbWidth[ i ], pbWidth[ i ], Qt::CopyROP, false ); if ( srcMask ) { bitBlt( &destMask, 0, 0, srcMask, 0, 0, pbWidth[ i ], pbWidth[ i ], Qt::CopyROP, false ); tmp.setMask( destMask ); } pbPixmaps[ i ] ->setBorder( OThemePixmap::TopLeft, tmp ); bitBlt( &tmp, 0, 0, pbPixmaps[ i ], pbPixmaps[ i ] ->width() - pbWidth[ i ], 0, pbWidth[ i ], pbWidth[ i ], Qt::CopyROP, false ); if ( srcMask ) { bitBlt( &destMask, 0, 0, srcMask, pbPixmaps[ i ] ->width() - pbWidth[ i ], 0, pbWidth[ i ], pbWidth[ i ], Qt::CopyROP, false ); tmp.setMask( destMask ); } pbPixmaps[ i ] ->setBorder( OThemePixmap::TopRight, tmp ); bitBlt( &tmp, 0, 0, pbPixmaps[ i ], 0, pbPixmaps[ i ] ->height() - pbWidth[ i ], pbWidth[ i ], pbWidth[ i ], Qt::CopyROP, false ); if ( srcMask ) { bitBlt( &destMask, 0, 0, srcMask, 0, pbPixmaps[ i ] ->height() - pbWidth[ i ], pbWidth[ i ], pbWidth[ i ], Qt::CopyROP, false ); tmp.setMask( destMask ); } pbPixmaps[ i ] ->setBorder( OThemePixmap::BottomLeft, tmp ); bitBlt( &tmp, 0, 0, pbPixmaps[ i ], pbPixmaps[ i ] ->width() - pbWidth[ i ], pbPixmaps[ i ] ->height() - pbWidth[ i ], pbWidth[ i ], pbWidth[ i ], Qt::CopyROP, false ); if ( srcMask ) { bitBlt( &destMask, 0, 0, srcMask, pbPixmaps[ i ] ->width() - pbWidth[ i ], pbPixmaps[ i ] ->height() - pbWidth[ i ], pbWidth[ i ], pbWidth[ i ], Qt::CopyROP, false ); tmp.setMask( destMask ); } pbPixmaps[ i ] ->setBorder( OThemePixmap::BottomRight, tmp ); tmp.resize( pbPixmaps[ i ] ->width() - pbWidth[ i ] * 2, pbWidth[ i ] ); destMask.resize( pbPixmaps[ i ] ->width() - pbWidth[ i ] * 2, pbWidth[ i ] ); bitBlt( &tmp, 0, 0, pbPixmaps[ i ], pbWidth[ i ], 0, pbPixmaps[ i ] ->width() - pbWidth[ i ] * 2, pbWidth[ i ], Qt::CopyROP, false ); if ( srcMask ) { bitBlt( &destMask, 0, 0, srcMask, pbWidth[ i ], 0, pbPixmaps[ i ] ->width() - pbWidth[ i ] * 2, pbWidth[ i ], Qt::CopyROP, false ); tmp.setMask( destMask ); } pbPixmaps[ i ] ->setBorder( OThemePixmap::Top, tmp ); bitBlt( &tmp, 0, 0, pbPixmaps[ i ], pbWidth[ i ], pbPixmaps[ i ] ->height() - pbWidth[ i ], pbPixmaps[ i ] ->width() - pbWidth[ i ] * 2, pbWidth[ i ], Qt::CopyROP, false ); if ( srcMask ) { bitBlt( &destMask, 0, 0, srcMask, pbWidth[ i ], pbPixmaps[ i ] ->height() - pbWidth[ i ], pbPixmaps[ i ] ->width() - pbWidth[ i ] * 2, pbWidth[ i ], Qt::CopyROP, false ); tmp.setMask( destMask ); } pbPixmaps[ i ] ->setBorder( OThemePixmap::Bottom, tmp ); tmp.resize( pbWidth[ i ], pbPixmaps[ i ] ->height() - pbWidth[ i ] * 2 ); destMask.resize( pbWidth[ i ], pbPixmaps[ i ] ->height() - pbWidth[ i ] * 2 ); bitBlt( &tmp, 0, 0, pbPixmaps[ i ], 0, pbWidth[ i ], pbWidth[ i ], pbPixmaps[ i ] ->height() - pbWidth[ i ] * 2, Qt::CopyROP, false ); if ( srcMask ) { bitBlt( &destMask, 0, 0, srcMask, 0, pbWidth[ i ], pbWidth[ i ], pbPixmaps[ i ] ->height() - pbWidth[ i ] * 2, Qt::CopyROP, false ); tmp.setMask( destMask ); } pbPixmaps[ i ] ->setBorder( OThemePixmap::Left, tmp ); bitBlt( &tmp, 0, 0, pbPixmaps[ i ], pbPixmaps[ i ] ->width() - pbWidth[ i ], pbWidth[ i ], pbWidth[ i ], pbPixmaps[ i ] ->height() - pbWidth[ i ] * 2, Qt::CopyROP, false ); if ( srcMask ) { bitBlt( &destMask, 0, 0, srcMask, pbPixmaps[ i ] ->width() - pbWidth[ i ], pbWidth[ i ], pbWidth[ i ], pbPixmaps[ i ] ->height() - pbWidth[ i ] * 2, Qt::CopyROP, false ); tmp.setMask( destMask ); } pbPixmaps[ i ] ->setBorder( OThemePixmap::Right, tmp ); } else odebug << "OThemeBase: Tried making border from empty pixmap" << oendl; } void OThemeBase::copyWidgetConfig( int sourceID, int destID, QString *pixnames, QString *brdnames ) { scaleHints[ destID ] = scaleHints[ sourceID ]; gradients[ destID ] = gradients[ sourceID ]; blends[ destID ] = blends[ sourceID ]; bContrasts[ destID ] = bContrasts[ sourceID ]; borders[ destID ] = borders[ sourceID ]; highlights[ destID ] = highlights[ sourceID ]; if ( grLowColors[ sourceID ] ) grLowColors[ destID ] = new QColor( *grLowColors[ sourceID ] ); else grLowColors[ destID ] = NULL; if ( grHighColors[ sourceID ] ) grHighColors[ destID ] = new QColor( *grHighColors[ sourceID ] ); else grHighColors[ destID ] = NULL; if ( colors[ sourceID ] ) colors[ destID ] = new QColorGroup( *colors[ sourceID ] ); else colors[ destID ] = NULL; // pixmap pixnames[ destID ] = pixnames[ sourceID ]; duplicate[ destID ] = false; pixmaps[ destID ] = NULL; images[ destID ] = NULL; if ( !pixnames[ destID ].isEmpty() ) { if ( scaleHints[ sourceID ] == TileScale && blends[ sourceID ] == 0.0 ) { pixmaps[ destID ] = pixmaps[ sourceID ]; duplicate[ destID ] = true; } if ( !duplicate[ destID ] ) { pixmaps[ destID ] = loadPixmap( pixnames[ destID ] ); if ( scaleHints[ destID ] == TileScale && blends[ destID ] == 0.0 ) images[ destID ] = NULL; else images[ destID ] = loadImage( pixnames[ destID ] ); } } // border pixmap pbDuplicate[ destID ] = false; pbPixmaps[ destID ] = NULL; pbWidth[ destID ] = pbWidth[ sourceID ]; brdnames[ destID ] = brdnames[ sourceID ]; if ( !brdnames[ destID ].isEmpty() ) { pbPixmaps[ destID ] = pbPixmaps[ sourceID ]; pbDuplicate[ destID ] = true; } if ( sourceID == ActiveTab && destID == InactiveTab ) aTabLine = iTabLine; else if ( sourceID == InactiveTab && destID == ActiveTab ) iTabLine = aTabLine; } void OThemeBase::readConfig( Qt::GUIStyle /*style*/ ) { #define PREBLEND_ITEMS 12 static WidgetType preBlend[] = {Slider, IndicatorOn, IndicatorOff, ExIndicatorOn, ExIndicatorOff, HScrollDeco, VScrollDeco, HScrollDecoDown, VScrollDecoDown, ComboDeco, ComboDecoDown, CheckMark}; int i; QString tmpStr; QString copyfrom[ WIDGETS ]; QString pixnames[ WIDGETS ]; // used for duplicate check QString brdnames[ WIDGETS ]; bool loaded[ WIDGETS ]; // used for preloading for CopyWidget if ( configFileName.isEmpty() ) { Config cfg ( "qpe" ); cfg. setGroup ( "Appearance" ); configFileName = cfg. readEntry ( "Theme", "default" ); } Config config( configFilePath + "/themes/" + configFileName + ".themerc" , Config::File ); // Are we initalized? applyMiscResourceGroup( &config ); for ( i = 0; i < INHERIT_ITEMS; ++i ) { applyResourceGroup( &config, i, copyfrom, pixnames, brdnames ); } for ( ; i < INHERIT_ITEMS*2; ++i ) { if ( config.hasGroup( QString( widgetEntries[ i ] ) ) ) { applyResourceGroup( &config, i, copyfrom, pixnames, brdnames ); } else { copyfrom [ i ] = widgetEntries[ i - INHERIT_ITEMS ]; } } for ( ; i < WIDGETS; ++i ) { applyResourceGroup( &config, i, copyfrom, pixnames, brdnames ); } // initalize defaults that may not be read for ( i = 0; i < WIDGETS; ++i ) loaded[ i ] = false; btnXShift = btnYShift = focus3DOffset = 0; aTabLine = iTabLine = true; roundedButton = roundedCombo = roundedSlider = focus3D = false; splitterWidth = 10; for ( i = 0; i < WIDGETS; ++i ) { readResourceGroup( i, copyfrom, pixnames, brdnames, loaded ); } // misc items readMiscResourceGroup(); // Handle preblend items for ( i = 0; i < PREBLEND_ITEMS; ++i ) { if ( pixmaps[ preBlend[ i ] ] != NULL && blends[ preBlend[ i ] ] != 0.0 ) blend( preBlend[ i ] ); } } OThemeBase::OThemeBase( const QString & configFile ) : QWindowsStyle() { configFilePath = QPEApplication::qpeDir ( ) + "plugins/styles/"; configFileName = configFile; readConfig( Qt::WindowsStyle ); cache = new OThemeCache( cacheSize ); } void OThemeBase::applyConfigFile( const QString &/*file*/ ) { #if 0 // handle std color scheme Config inConfig( file, Config::File ); Config globalConfig ( "qpe" ); globalConfig. setGroup ( "Apperance" ); inConfig. setGroup( "General" ); if ( inConfig.hasKey( "foreground" ) ) globalConfig.writeEntry( "Text", inConfig.readEntry( "foreground", " " ) ); if ( inConfig.hasKey( "background" ) ) globalConfig.writeEntry( "Background", inConfig.readEntry( "background", " " ) ); if ( inConfig.hasKey( "selectForeground" ) ) globalConfig.writeEntry( "HighlightedText", inConfig.readEntry( "selectForeground", " " ) ); if ( inConfig.hasKey( "selectBackground" ) ) globalConfig.writeEntry( "Highlight", inConfig.readEntry( "selectBackground", " " ) ); if ( inConfig.hasKey( "windowForeground" ) ) globalConfig.writeEntry( "Text", inConfig.readEntry( "windowForeground", " " ) ); if ( inConfig.hasKey( "windowBackground" ) ) globalConfig.writeEntry( "Base", inConfig.readEntry( "windowBackground", " " ) ); // Keep track of the current theme so that we can select the right one // in the KControl module. globalConfig.writeEntry ( "CurrentTheme", file ); globalConfig.write(); #endif } OThemeBase::~OThemeBase() { int i; for ( i = 0; i < WIDGETS; ++i ) { if ( !duplicate[ i ] ) { if ( images[ i ] ) delete images[ i ]; if ( pixmaps[ i ] ) delete pixmaps[ i ]; } if ( !pbDuplicate[ i ] && pbPixmaps[ i ] ) delete pbPixmaps[ i ]; if ( colors[ i ] ) delete( colors[ i ] ); if ( grLowColors[ i ] ) delete( grLowColors[ i ] ); if ( grHighColors[ i ] ) delete( grHighColors[ i ] ); } delete cache; } QImage* OThemeBase::loadImage( QString &name ) { QImage * image = new QImage; QString path = configFilePath + "/pixmaps/" + name; image->load( path ); if ( !image->isNull() ) return ( image ); odebug << "OThemeBase: Unable to load image " << name.ascii ( ) << oendl; delete image; return ( NULL ); } OThemePixmap* OThemeBase::loadPixmap( QString &name ) { OThemePixmap * pixmap = new OThemePixmap( false ); QString path = configFilePath + "/pixmaps/" + name; pixmap->load( path ); if ( !pixmap->isNull() ) return pixmap; odebug << "OThemeBase: Unable to load pixmap " << name.ascii() << oendl; delete pixmap; return ( NULL ); } OThemePixmap* OThemeBase::scale( int w, int h, WidgetType widget ) { if ( scaleHints[ widget ] == FullScale ) { if ( !pixmaps[ widget ] || pixmaps[ widget ] ->width() != w || pixmaps[ widget ] ->height() != h ) { OThemePixmap * cachePix = cache->pixmap( w, h, widget ); if ( cachePix ) { cachePix = new OThemePixmap( *cachePix ); if ( pixmaps[ widget ] ) cache->insert( pixmaps[ widget ], OThemeCache::FullScale, widget ); else odebug << "We would have inserted a null pixmap!\n" << oendl; pixmaps[ widget ] = cachePix; } else { cache->insert( pixmaps[ widget ], OThemeCache::FullScale, widget ); QImage tmpImg = images[ widget ] ->smoothScale( w, h ); pixmaps[ widget ] = new OThemePixmap; pixmaps[ widget ] ->convertFromImage( tmpImg ); if ( blends[ widget ] != 0.0 ) blend( widget ); } } } else if ( scaleHints[ widget ] == HorizontalScale ) { if ( pixmaps[ widget ] ->width() != w ) { OThemePixmap * cachePix = cache->horizontalPixmap( w, widget ); if ( cachePix ) { cachePix = new OThemePixmap( *cachePix ); if ( pixmaps[ widget ] ) cache->insert( pixmaps[ widget ], OThemeCache::HorizontalScale, widget ); else odebug << "We would have inserted a null pixmap!" << oendl; pixmaps[ widget ] = cachePix; } else { cache->insert( pixmaps[ widget ], OThemeCache::HorizontalScale, widget ); QImage tmpImg = images[ widget ] -> smoothScale( w, images[ widget ] ->height() ); pixmaps[ widget ] = new OThemePixmap; pixmaps[ widget ] ->convertFromImage( tmpImg ); if ( blends[ widget ] != 0.0 ) blend( widget ); } } } else if ( scaleHints[ widget ] == VerticalScale ) { if ( pixmaps[ widget ] ->height() != h ) { OThemePixmap * cachePix = cache->verticalPixmap( w, widget ); if ( cachePix ) { cachePix = new OThemePixmap( *cachePix ); if ( pixmaps[ widget ] ) cache->insert( pixmaps[ widget ], OThemeCache::VerticalScale, widget ); else odebug << "We would have inserted a null pixmap!" << oendl; pixmaps[ widget ] = cachePix; } else { cache->insert( pixmaps[ widget ], OThemeCache::VerticalScale, widget ); QImage tmpImg = images[ widget ] ->smoothScale( images[ widget ] ->width(), h ); pixmaps[ widget ] = new OThemePixmap; pixmaps[ widget ] ->convertFromImage( tmpImg ); if ( blends[ widget ] != 0.0 ) blend( widget ); } } } // If blended tile here so the blend is scaled properly else if ( scaleHints[ widget ] == TileScale && blends[ widget ] != 0.0 ) { if ( !pixmaps[ widget ] || pixmaps[ widget ] ->width() != w || pixmaps[ widget ] ->height() != h ) { OThemePixmap * cachePix = cache->pixmap( w, h, widget ); if ( cachePix ) { cachePix = new OThemePixmap( *cachePix ); cache->insert( pixmaps[ widget ], OThemeCache::FullScale, widget ); pixmaps[ widget ] = cachePix; } else { cache->insert( pixmaps[ widget ], OThemeCache::FullScale, widget ); QPixmap tile; tile.convertFromImage( *images[ widget ] ); pixmaps[ widget ] = new OThemePixmap; pixmaps[ widget ] ->resize( w, h ); QPainter p( pixmaps[ widget ] ); p.drawTiledPixmap( 0, 0, w, h, tile ); if ( blends[ widget ] != 0.0 ) blend( widget ); } } } return ( pixmaps[ widget ] ); } OThemePixmap* OThemeBase::scaleBorder( int w, int h, WidgetType widget ) { OThemePixmap * pixmap = NULL; if ( !pbPixmaps[ widget ] && !pbWidth[ widget ] ) return ( NULL ); pixmap = cache->pixmap( w, h, widget, true ); if ( pixmap ) { pixmap = new OThemePixmap( *pixmap ); } else { pixmap = new OThemePixmap(); pixmap->resize( w, h ); QBitmap mask; mask.resize( w, h ); mask.fill( color0 ); QPainter mPainter; mPainter.begin( &mask ); QPixmap *tmp = borderPixmap( widget ) ->border( OThemePixmap::TopLeft ); const QBitmap *srcMask = tmp->mask(); int bdWidth = tmp->width(); bitBlt( pixmap, 0, 0, tmp, 0, 0, bdWidth, bdWidth, Qt::CopyROP, false ); if ( srcMask ) bitBlt( &mask, 0, 0, srcMask, 0, 0, bdWidth, bdWidth, Qt::CopyROP, false ); else mPainter.fillRect( 0, 0, bdWidth, bdWidth, color1 ); tmp = borderPixmap( widget ) ->border( OThemePixmap::TopRight ); srcMask = tmp->mask(); bitBlt( pixmap, w - bdWidth, 0, tmp, 0, 0, bdWidth, bdWidth, Qt::CopyROP, false ); if ( srcMask ) bitBlt( &mask, w - bdWidth, 0, srcMask, 0, 0, bdWidth, bdWidth, Qt::CopyROP, false ); else mPainter.fillRect( w - bdWidth, 0, bdWidth, bdWidth, color1 ); tmp = borderPixmap( widget ) ->border( OThemePixmap::BottomLeft ); srcMask = tmp->mask(); bitBlt( pixmap, 0, h - bdWidth, tmp, 0, 0, bdWidth, bdWidth, Qt::CopyROP, false ); if ( srcMask ) bitBlt( &mask, 0, h - bdWidth, srcMask, 0, 0, bdWidth, bdWidth, Qt::CopyROP, false ); else mPainter.fillRect( 0, h - bdWidth, bdWidth, bdWidth, color1 ); tmp = borderPixmap( widget ) ->border( OThemePixmap::BottomRight ); srcMask = tmp->mask(); bitBlt( pixmap, w - bdWidth, h - bdWidth, tmp, 0, 0, bdWidth, bdWidth, Qt::CopyROP, false ); if ( srcMask ) bitBlt( &mask, w - bdWidth, h - bdWidth, srcMask, 0, 0, bdWidth, bdWidth, Qt::CopyROP, false ); else mPainter.fillRect( w - bdWidth, h - bdWidth, bdWidth, bdWidth, color1 ); QPainter p; p.begin( pixmap ); if ( w - bdWidth * 2 > 0 ) { tmp = borderPixmap( widget ) ->border( OThemePixmap::Top ); srcMask = tmp->mask(); p.drawTiledPixmap( bdWidth, 0, w - bdWidth * 2, bdWidth, *tmp ); if ( srcMask ) mPainter.drawTiledPixmap( bdWidth, 0, w - bdWidth * 2, bdWidth, *srcMask ); else mPainter.fillRect( bdWidth, 0, w - bdWidth * 2, bdWidth, color1 ); tmp = borderPixmap( widget ) ->border( OThemePixmap::Bottom ); srcMask = tmp->mask(); p.drawTiledPixmap( bdWidth, h - bdWidth, w - bdWidth * 2, bdWidth, *tmp ); if ( srcMask ) mPainter.drawTiledPixmap( bdWidth, h - bdWidth, w - bdWidth * 2, bdWidth, *srcMask ); else mPainter.fillRect( bdWidth, h - bdWidth, w - bdWidth * 2, bdWidth, color1 ); } if ( h - bdWidth * 2 > 0 ) { tmp = borderPixmap( widget ) ->border( OThemePixmap::Left ); srcMask = tmp->mask(); p.drawTiledPixmap( 0, bdWidth, bdWidth, h - bdWidth * 2, *tmp ); if ( srcMask ) mPainter.drawTiledPixmap( 0, bdWidth, bdWidth, h - bdWidth * 2, *srcMask ); else mPainter.fillRect( 0, bdWidth, bdWidth, h - bdWidth * 2, color1 ); tmp = borderPixmap( widget ) ->border( OThemePixmap::Right ); srcMask = tmp->mask(); p.drawTiledPixmap( w - bdWidth, bdWidth, bdWidth, h - bdWidth * 2, *tmp ); if ( srcMask ) mPainter.drawTiledPixmap( w - bdWidth, bdWidth, bdWidth, h - bdWidth * 2, *srcMask ); else mPainter.fillRect( w - bdWidth, bdWidth, bdWidth, h - bdWidth * 2, color1 ); } p.end(); mPainter.end(); pixmap->setMask( mask ); cache->insert( pixmap, OThemeCache::FullScale, widget, true ); if ( !pixmap->mask() ) odebug << "No mask for border pixmap!" << oendl; } return ( pixmap ); } OThemePixmap* OThemeBase::blend( WidgetType widget ) { OGfxEffect::GradientType g; switch ( gradients[ widget ] ) { case GrHorizontal: g = OGfxEffect::HorizontalGradient; break; case GrVertical: g = OGfxEffect::VerticalGradient; break; case GrPyramid: g = OGfxEffect::PyramidGradient; break; case GrRectangle: g = OGfxEffect::RectangleGradient; break; case GrElliptic: g = OGfxEffect::EllipticGradient; break; default: g = OGfxEffect::DiagonalGradient; break; } OGfxEffect::blend( *pixmaps[ widget ], blends[ widget ], *grLowColors[ widget ], g, false ); return ( pixmaps[ widget ] ); } OThemePixmap* OThemeBase::gradient( int w, int h, WidgetType widget ) { if ( gradients[ widget ] == GrVertical ) { if ( !pixmaps[ widget ] || pixmaps[ widget ] ->height() != h ) { OThemePixmap * cachePix = cache->verticalPixmap( h, widget ); if ( cachePix ) { cachePix = new OThemePixmap( *cachePix ); if ( pixmaps[ widget ] ) cache->insert( pixmaps[ widget ], OThemeCache::VerticalScale, widget ); pixmaps[ widget ] = cachePix; } else { if ( pixmaps[ widget ] ) cache->insert( pixmaps[ widget ], OThemeCache::VerticalScale, widget ); pixmaps[ widget ] = new OThemePixmap; pixmaps[ widget ] ->resize( w, h ); OGfxEffect::gradient( *pixmaps[ widget ], *grHighColors[ widget ], *grLowColors[ widget ], OGfxEffect::VerticalGradient ); } } } else if ( gradients[ widget ] == GrHorizontal ) { if ( !pixmaps[ widget ] || pixmaps[ widget ] ->width() != w ) { OThemePixmap * cachePix = cache->horizontalPixmap( w, widget ); if ( cachePix ) { cachePix = new OThemePixmap( *cachePix ); if ( pixmaps[ widget ] ) cache->insert( pixmaps[ widget ], OThemeCache::HorizontalScale, widget ); pixmaps[ widget ] = cachePix; } else { if ( pixmaps[ widget ] ) cache->insert( pixmaps[ widget ], OThemeCache::HorizontalScale, widget ); pixmaps[ widget ] = new OThemePixmap; pixmaps[ widget ] ->resize( w, h ); OGfxEffect::gradient( *pixmaps[ widget ], *grHighColors[ widget ], *grLowColors[ widget ], OGfxEffect::HorizontalGradient ); } } } else if ( gradients[ widget ] == GrReverseBevel ) { if ( !pixmaps[ widget ] || pixmaps[ widget ] ->width() != w || pixmaps[ widget ] ->height() != h ) { OThemePixmap * cachePix = cache->pixmap( w, h, widget ); if ( cachePix ) { cachePix = new OThemePixmap( *cachePix ); if ( pixmaps[ widget ] ) cache->insert( pixmaps[ widget ], OThemeCache::FullScale, widget ); pixmaps[ widget ] = cachePix; } else { if ( pixmaps[ widget ] ) cache->insert( pixmaps[ widget ], OThemeCache::FullScale, widget ); pixmaps[ widget ] = new OThemePixmap; pixmaps[ widget ] ->resize( w, h ); QPixmap s; int offset = decoWidth( widget ); s.resize( w - offset * 2, h - offset * 2 ); QColor lc( *grLowColors[ widget ] ); QColor hc( *grHighColors[ widget ] ); if ( bevelContrast( widget ) ) { int bc = bevelContrast( widget ); // want single increments, not factors like light()/dark() lc.setRgb( lc.red() - bc, lc.green() - bc, lc.blue() - bc ); hc.setRgb( hc.red() + bc, hc.green() + bc, hc.blue() + bc ); } OGfxEffect::gradient( *pixmaps[ widget ], lc, hc, OGfxEffect::DiagonalGradient ); OGfxEffect::gradient( s, *grHighColors[ widget ], *grLowColors[ widget ], OGfxEffect::DiagonalGradient ); bitBlt( pixmaps[ widget ], offset, offset, &s, 0, 0, w - offset * 2, h - offset * 2, Qt::CopyROP ); } } } else { OGfxEffect::GradientType g; switch ( gradients[ widget ] ) { case GrPyramid: g = OGfxEffect::PyramidGradient; break; case GrRectangle: g = OGfxEffect::RectangleGradient; break; case GrElliptic: g = OGfxEffect::EllipticGradient; break; default: g = OGfxEffect::DiagonalGradient; break; } if ( !pixmaps[ widget ] || pixmaps[ widget ] ->width() != w || pixmaps[ widget ] ->height() != h ) { OThemePixmap * cachePix = cache->pixmap( w, h, widget ); if ( cachePix ) { cachePix = new OThemePixmap( *cachePix ); if ( pixmaps[ widget ] ) cache->insert( pixmaps[ widget ], OThemeCache::FullScale, widget ); pixmaps[ widget ] = cachePix; } else { if ( pixmaps[ widget ] ) cache->insert( pixmaps[ widget ], OThemeCache::FullScale, widget ); pixmaps[ widget ] = new OThemePixmap; pixmaps[ widget ] ->resize( w, h ); OGfxEffect::gradient( *pixmaps[ widget ], *grHighColors[ widget ], *grLowColors[ widget ], g ); } } } return ( pixmaps[ widget ] ); } OThemePixmap* OThemeBase::scalePixmap( int w, int h, WidgetType widget ) { if ( gradients[ widget ] && blends[ widget ] == 0.0 ) return ( gradient( w, h, widget ) ); return ( scale( w, h, widget ) ); } QColorGroup* OThemeBase::makeColorGroup( QColor &fg, QColor &bg, Qt::GUIStyle ) { if ( shading == Motif ) { int highlightVal, lowlightVal; highlightVal = 100 + ( 2* /*KGlobalSettings::contrast()*/ 3 + 4 ) * 16 / 10; lowlightVal = 100 + ( ( 2* /*KGlobalSettings::contrast()*/ 3 + 4 ) * 10 ); return ( new QColorGroup( fg, bg, bg.light( highlightVal ), bg.dark( lowlightVal ), bg.dark( 120 ), fg, qApp->palette().normal().base() ) ); } else return ( new QColorGroup( fg, bg, bg.light( 150 ), bg.dark(), bg.dark( 120 ), fg, qApp->palette().normal().base() ) ); } static QColor strToColor ( const QString &str ) { QString str2 = str. stripWhiteSpace ( ); if ( str2 [0] == '#' ) return QColor ( str2 ); else { QStringList sl = QStringList::split ( ',', str2 ); if ( sl. count ( ) >= 3 ) return QColor ( sl [0]. toInt ( ), sl [1]. toInt ( ), sl [2]. toInt ( )); } return QColor ( 0, 0, 0 ); } void OThemeBase::applyMiscResourceGroup( Config *config ) { config-> setGroup ( "Misc" ); QString tmpStr; tmpStr = config->readEntry( "SButtonPosition" ); if ( tmpStr == "BottomLeft" ) sbPlacement = SBBottomLeft; else if ( tmpStr == "BottomRight" ) sbPlacement = SBBottomRight; else { if ( tmpStr != "Opposite" && !tmpStr.isEmpty() ) odebug << "OThemeBase: Unrecognized sb button option " << tmpStr.ascii() << ", using Opposite." << oendl; sbPlacement = SBOpposite; } tmpStr = config->readEntry( "ArrowType" ); if ( tmpStr == "Small" ) arrowStyle = SmallArrow; else if ( tmpStr == "3D" ) arrowStyle = MotifArrow; else { if ( tmpStr != "Normal" && !tmpStr.isEmpty() ) odebug << "OThemeBase: Unrecognized arrow option " << tmpStr.ascii() << ", using Normal." << oendl; arrowStyle = LargeArrow; } tmpStr = config->readEntry( "ShadeStyle" ); if ( tmpStr == "Motif" ) shading = Motif; else if ( tmpStr == "Next" ) shading = Next; else if ( tmpStr == "KDE" ) shading = KDE; else shading = Windows; defaultFrame = config->readNumEntry( "FrameWidth", 2 ); cacheSize = config->readNumEntry( "Cache", 1024 ); sbExtent = config->readNumEntry( "ScrollBarExtent", 16 ); config-> setGroup ( "General" ); if ( config-> hasKey ( "foreground" )) fgcolor = strToColor ( config-> readEntry ( "foreground" )); if ( config-> hasKey ( "background" )) bgcolor = strToColor ( config-> readEntry ( "background" )); if ( config-> hasKey ( "selectForeground" )) selfgcolor = strToColor ( config-> readEntry ( "selectForeground" )); if ( config-> hasKey ( "selectBackground" )) selbgcolor = strToColor ( config-> readEntry ( "selectBackground" )); if ( config-> hasKey ( "windowForeground" )) winfgcolor = strToColor ( config-> readEntry ( "windowForeground" )); if ( config-> hasKey ( "windowBackground" )) winbgcolor = strToColor ( config-> readEntry ( "windowBackground" )); } void OThemeBase::readMiscResourceGroup() {} void OThemeBase::applyResourceGroup( Config *config, int i, QString *copyfrom, QString *pixnames, QString *brdnames ) { QString tmpStr; config-> setGroup ( widgetEntries [ i ] ); tmpStr = config->readEntry( "CopyWidget", "" ); copyfrom [ i ] = tmpStr; if ( !tmpStr.isEmpty() ) return ; // Scale hint tmpStr = config->readEntry( "Scale" ); if ( tmpStr == "Full" ) scaleHints [ i ] = FullScale; else if ( tmpStr == "Horizontal" ) scaleHints [ i ] = HorizontalScale; else if ( tmpStr == "Vertical" ) scaleHints [ i ] = VerticalScale; else { if ( tmpStr != "Tile" && !tmpStr.isEmpty() ) odebug << "OThemeBase: Unrecognized scale option " << tmpStr.ascii() << ", using Tile." << oendl; scaleHints [ i ] = TileScale; } // Gradient type tmpStr = config->readEntry( "Gradient" ); if ( tmpStr == "Diagonal" ) gradients [ i ] = GrDiagonal; else if ( tmpStr == "Horizontal" ) gradients [ i ] = GrHorizontal; else if ( tmpStr == "Vertical" ) gradients [ i ] = GrVertical; else if ( tmpStr == "Pyramid" ) gradients [ i ] = GrPyramid; else if ( tmpStr == "Rectangle" ) gradients [ i ] = GrRectangle; else if ( tmpStr == "Elliptic" ) gradients [ i ] = GrElliptic; else if ( tmpStr == "ReverseBevel" ) gradients [ i ] = GrReverseBevel; else { if ( tmpStr != "None" && !tmpStr.isEmpty() ) odebug << "OThemeBase: Unrecognized gradient option " << tmpStr.ascii() << ", using None." << oendl; gradients [ i ] = GrNone; } // Blend intensity blends[ i ] = config->readEntry( "BlendIntensity", "0.0" ).toDouble(); // Bevel contrast bContrasts[ i ] = config->readNumEntry( "BevelContrast", 0 ); // Border width borders [ i ] = config->readNumEntry( "Border", 1 ); // Highlight width highlights [ i ] = config->readNumEntry( "Highlight", 1 ); // Gradient low color or blend background if ( config->hasKey( "GradientLow" ) && ( gradients[ i ] != GrNone || blends[ i ] != 0.0 )) grLowColors[ i ] = new QColor( strToColor ( config->readEntry( "GradientLow", qApp->palette().normal().background().name() ))); else grLowColors[ i ] = NULL; // Gradient high color if ( config->hasKey( "GradientHigh" ) && ( gradients[ i ] != GrNone )) grHighColors[ i ] = new QColor( strToColor ( config->readEntry( "GradientHigh", qApp->palette().normal().background().name() ))); else grHighColors[ i ] = NULL; // Extended color attributes if ( config->hasKey( "Foreground" ) || config->hasKey( "Background" ) ) { QColor bg = strToColor( config->readEntry( "Background", qApp->palette().normal().background().name() )); QColor fg = strToColor( config->readEntry( "Foreground", qApp->palette().normal().foreground().name() )); colors[ i ] = makeColorGroup( fg, bg, Qt::WindowsStyle ); } else colors[ i ] = NULL; // Pixmap tmpStr = config->readEntry( "Pixmap", "" ); pixnames[ i ] = tmpStr; duplicate[ i ] = false; pixmaps[ i ] = NULL; images[ i ] = NULL; // Pixmap border tmpStr = config->readEntry( "PixmapBorder", "" ); brdnames[ i ] = tmpStr; pbDuplicate[ i ] = false; pbPixmaps[ i ] = NULL; pbWidth[ i ] = 0; if ( !tmpStr.isEmpty() ) { pbWidth[ i ] = config->readNumEntry( "PixmapBWidth", 0 ); if ( pbWidth[ i ] == 0 ) { odebug << "OThemeBase: No border width specified for pixmapped border widget " << widgetEntries[ i ] << oendl; odebug << "OThemeBase: Using default of 2." << oendl; pbWidth[ i ] = 2; } } // Various widget specific settings. This was more efficent when bunched // together in the misc group, but this makes an easier to read config. if ( i == SliderGroove ) roundedSlider = config->readBoolEntry( "SmallGroove", false ); else if ( i == ActiveTab ) { aTabLine = config->readBoolEntry( "BottomLine", true ); } else if ( i == InactiveTab ) { iTabLine = config->readBoolEntry( "BottomLine", true ); } else if ( i == Splitter ) splitterWidth = config->readNumEntry( "Width", 10 ); else if ( i == ComboBox || i == ComboBoxDown ) { roundedCombo = config->readBoolEntry( "Round", false ); } else if ( i == PushButton || i == PushButtonDown ) { btnXShift = config->readNumEntry( "XShift", 0 ); btnYShift = config->readNumEntry( "YShift", 0 ); focus3D = config->readBoolEntry( "3DFocusRect", false ); focus3DOffset = config->readBoolEntry( "3DFocusOffset", 0 ); roundedButton = config->readBoolEntry( "Round", false ); } } void OThemeBase::readResourceGroup( int i, QString *copyfrom, QString *pixnames, QString *brdnames, bool *loadArray ) { if ( loadArray[ i ] == true ) { return ; // already been preloaded. } int tmpVal; QString tmpStr; tmpStr = copyfrom [ i ]; if ( !tmpStr.isEmpty() ) { // Duplicate another widget's config int sIndex; loadArray[ i ] = true; for ( sIndex = 0; sIndex < WIDGETS; ++sIndex ) { if ( tmpStr == widgetEntries[ sIndex ] ) { if ( !loadArray[ sIndex ] ) // hasn't been loaded yet readResourceGroup( sIndex, copyfrom, pixnames, brdnames, loadArray ); break; } } - if ( loadArray[ sIndex ] ) { + if ( sIndex < 54 && loadArray[ sIndex ] ) { copyWidgetConfig( sIndex, i, pixnames, brdnames ); } else odebug << "OThemeBase: Unable to identify source widget for " << widgetEntries[ i ] << oendl; return ; } // special inheritance for disabled arrows (these are tri-state unlike // the rest of what we handle). for ( tmpVal = DisArrowUp; tmpVal <= DisArrowRight; ++tmpVal ) { if ( tmpVal == i ) { tmpStr = pixnames [ i ]; if ( tmpStr.isEmpty() ) { copyWidgetConfig( ArrowUp + ( tmpVal - DisArrowUp ), i, pixnames, brdnames ); return ; } } } // Pixmap int existing; // Scan for duplicate pixmaps(two identical pixmaps, tile scale, no blend, // no pixmapped border) if ( !pixnames [ i ].isEmpty() ) { for ( existing = 0; existing < i; ++existing ) { if ( pixnames[ i ] == pixnames[ existing ] && scaleHints[ i ] == TileScale && scaleHints[ existing ] == TileScale && blends[ existing ] == 0.0 && blends[ i ] == 0.0 ) { pixmaps[ i ] = pixmaps[ existing ]; duplicate[ i ] = true; break; } } } // load if ( !duplicate[ i ] && !pixnames[ i ].isEmpty() ) { pixmaps[ i ] = loadPixmap( pixnames[ i ] ); // load and save images for scaled/blended widgets for speed. if ( scaleHints[ i ] == TileScale && blends[ i ] == 0.0 ) images[ i ] = NULL; else images[ i ] = loadImage( pixnames[ i ] ); } // Pixmap border if ( !brdnames [ i ]. isEmpty () ) { // duplicate check for ( existing = 0; existing < i; ++existing ) { if ( brdnames [i] == brdnames[ existing ] ) { pbPixmaps[ i ] = pbPixmaps[ existing ]; pbDuplicate[ i ] = true; break; } } } // load if ( !pbDuplicate[ i ] && !brdnames[ i ].isEmpty() ) pbPixmaps[ i ] = loadPixmap( brdnames[ i ] ); if ( pbPixmaps[ i ] && !pbDuplicate[ i ] ) generateBorderPix( i ); loadArray[ i ] = true; } OThemePixmap::OThemePixmap( bool timer ) : QPixmap() { if(timer){ t = new QTime; t->start(); } else t = NULL; int i; for ( i = 0; i < 8; ++i ) b[ i ] = NULL; } OThemePixmap::OThemePixmap( const OThemePixmap &p ) : QPixmap( p ) { if(p.t){ t = new QTime; t->start(); } else t = NULL; int i; for ( i = 0; i < 8; ++i ) if ( p.b[ i ] ) b[ i ] = new QPixmap( *p.b[ i ] ); else b[ i ] = NULL; } OThemePixmap::~OThemePixmap() { if(t) delete t; int i; for ( i = 0; i < 8; ++i ) if ( b[ i ] ) delete b[ i ]; } OThemeCache::OThemeCache( int maxSize, QObject *parent, const char *name ) : QObject( parent, name ) { cache.setMaxCost( maxSize * 1024 ); cache.setAutoDelete( true ); flushTimer.start(300000); // 5 minutes connect(&flushTimer, SIGNAL(timeout()), SLOT(flushTimeout())); } void OThemeCache::flushTimeout() { QIntCacheIterator<OThemePixmap> it( cache ); while ( it.current() ) { if ( it.current() ->isOld() ) cache.remove( it.currentKey() ); else ++it; } } OThemePixmap* OThemeCache::pixmap( int w, int h, int widgetID, bool border, bool mask ) { kthemeKey key; key.cacheKey = 0; // shut up, gcc key.data.id = widgetID; key.data.width = w; key.data.height = h; key.data.border = border; key.data.mask = mask; OThemePixmap *pix = cache.find( ( unsigned long ) key.cacheKey ); if ( pix ) pix->updateAccessed(); return ( pix ); } OThemePixmap* OThemeCache::horizontalPixmap( int w, int widgetID ) { kthemeKey key; key.cacheKey = 0; // shut up, gcc key.data.id = widgetID; key.data.width = w; key.data.height = 0; key.data.border = false; key.data.mask = false; OThemePixmap *pix = cache.find( ( unsigned long ) key.cacheKey ); if ( pix ) pix->updateAccessed(); return ( pix ); } OThemePixmap* OThemeCache::verticalPixmap( int h, int widgetID ) { kthemeKey key; key.cacheKey = 0; // shut up, gcc key.data.id = widgetID; key.data.width = 0; key.data.height = h; key.data.border = false; key.data.mask = false; OThemePixmap *pix = cache.find( ( unsigned long ) key.cacheKey ); if ( pix ) pix->updateAccessed(); return ( pix ); } bool OThemeCache::insert( OThemePixmap *pixmap, ScaleHint scale, int widgetID, bool border, bool mask ) { kthemeKey key; key.cacheKey = 0; // shut up, gcc key.data.id = widgetID; key.data.width = ( scale == FullScale || scale == HorizontalScale ) ? pixmap->width() : 0; key.data.height = ( scale == FullScale || scale == VerticalScale ) ? pixmap->height() : 0; key.data.border = border; key.data.mask = mask; if ( cache.find( ( unsigned long ) key.cacheKey, true ) != NULL ) { return ( true ); // a pixmap of this scale is already in there } return ( cache.insert( ( unsigned long ) key.cacheKey, pixmap, pixmap->width() * pixmap->height() * pixmap->depth() / 8 ) ); } //#include "kthemebase.moc" |