Skip to content

Commit

Permalink
Use vector icons from Zumi's toolbar design
Browse files Browse the repository at this point in the history
No need for the XPM translator anymore. Saves some bytes off the app
resources because the HVIF icons are smaller than the bitmaps they
replace.

Fixes #1
  • Loading branch information
pulkomandy committed Apr 29, 2023
1 parent 2560136 commit 0a6ead9
Show file tree
Hide file tree
Showing 15 changed files with 108 additions and 822 deletions.
5 changes: 1 addition & 4 deletions README.md
Expand Up @@ -20,12 +20,9 @@ Requirements
============

- Ghostscript (tested with versions 9 and up)
- XPMTranslator (for the toolbar icons)
- libprefs

Ghostscript and libprefs are available in Haikuports and installable as usual. xpm_translator
currently isn't, due to licensing problems (the original author did not specify a license for it).
Ideally the icons should be replaced with HVIF ones.
Ghostscript and libprefs are available in Haikuports and installable as usual.

Installation
============
Expand Down
59 changes: 37 additions & 22 deletions src/BGhostview.cpp
Expand Up @@ -17,6 +17,8 @@
#include "BGhostview.h"
#include "BGVDropTarget.h"

#include "IconUtils.h"

#ifndef BUFSIZE
#define BUFSIZE 1024
#endif
Expand Down Expand Up @@ -315,29 +317,42 @@ BView *BGhostview::createMenubar(BRect frame)
BView* BGhostview::createToolbar(BRect frame)
{
AToolBar *toolBar=new AToolBar(frame,"BGV_Toolbar");
icons[0] = BTranslationUtils::GetBitmap("fileopen");
icons[1] = BTranslationUtils::GetBitmap("reload");
icons[2] = BTranslationUtils::GetBitmap("printpage");
icons[3] = BTranslationUtils::GetBitmap("zoomin");
icons[4] = BTranslationUtils::GetBitmap("zoomout");
icons[5] = BTranslationUtils::GetBitmap("firstpage");
icons[6] = BTranslationUtils::GetBitmap("prevpage");
icons[7] = BTranslationUtils::GetBitmap("next");
icons[8] = BTranslationUtils::GetBitmap("nextpage");
icons[9] = BTranslationUtils::GetBitmap("lastpage");
if (icons[0] && icons[1] && icons[2] && icons[3] && icons[4] && icons[5] && icons[6] && icons[7] && icons[8] && icons[9]) {
toolBar->AddIcon(icons[0] ,"fileopen", new BMessage(BGV_OLD_FILE));
toolBar->AddIcon(icons[1] ,"reload",new BMessage(BGV_REDISPLAY),false);
toolBar->AddIcon(icons[2] ,"printpage",new BMessage(BGV_PRINT_ALL),false);
toolBar->AddIcon(icons[3] ,"zoomin",new BMessage(BGV_ZOOMIN),false);
toolBar->AddIcon(icons[4] ,"zoomout",new BMessage(BGV_ZOOMOUT),false);
toolBar->AddIcon(icons[5] ,"firstpage",new BMessage(BGV_GOTO_START),false);
toolBar->AddIcon(icons[6] ,"prevpage",new BMessage(BGV_PREV_PAGE),false);
toolBar->AddIcon(icons[7] ,"page",new BMessage(BGV_READ_DOWN),false);
toolBar->AddIcon(icons[8] ,"nextpage",new BMessage(BGV_NEXT_PAGE),false);
toolBar->AddIcon(icons[9] ,"lastpage",new BMessage(BGV_GOTO_END),false);

BResources resources;
status_t status = resources.SetToImage((void*)&BGhostview::createToolbar);

bool allOK = true;

const char* names[] = {"fileopen", "reload", "printpage", "zoomin", "zoomout", "firstpage",
"prevpage", "next", "nextpage", "lastpage"};

for (int i = 0; i < B_COUNT_OF(names); i++) {
BBitmap temp(BRect(0, 0, 31, 31), 0, B_RGBA32);
size_t size;
const void* buffer = resources.LoadResource(B_VECTOR_ICON_TYPE, names[i], &size);
status_t status = BIconUtils::GetVectorIcon((const uint8*)buffer, size, &temp);

if (status == B_OK) {
icons[i] = new BBitmap(BRect(0, 0, 23, 23), 0, B_RGBA32);
status = icons[i]->ImportBits(&temp, B_ORIGIN, B_ORIGIN, BSize(24, 24));
}
if (status != B_OK)
allOK = false;
}

if (allOK) {
toolBar->AddIcon(icons[0], names[0], new BMessage(BGV_OLD_FILE));
toolBar->AddIcon(icons[1], names[1], new BMessage(BGV_REDISPLAY), false);
toolBar->AddIcon(icons[2], names[2], new BMessage(BGV_PRINT_ALL), false);
toolBar->AddIcon(icons[3], names[3], new BMessage(BGV_ZOOMIN), false);
toolBar->AddIcon(icons[4], names[4], new BMessage(BGV_ZOOMOUT), false);
toolBar->AddIcon(icons[5], names[5], new BMessage(BGV_GOTO_START), false);
toolBar->AddIcon(icons[6], names[6], new BMessage(BGV_PREV_PAGE), false);
toolBar->AddIcon(icons[7], names[7], new BMessage(BGV_READ_DOWN), false);
toolBar->AddIcon(icons[8], names[8], new BMessage(BGV_NEXT_PAGE), false);
toolBar->AddIcon(icons[9], names[9], new BMessage(BGV_GOTO_END), false);
} else {
BAlert *d = new BAlert("Error","Could not locate icons.\nMake sure XPMTranslator is installed.","Ok");
BAlert *d = new BAlert("Error","Could not locate icons.\nMake sure BGhostview is compiled correctly?","Ok");
d->Go();
}

Expand Down
497 changes: 70 additions & 427 deletions src/BGhostview.rdef

Large diffs are not rendered by default.

75 changes: 0 additions & 75 deletions src/BGhostview_basic.rdef

This file was deleted.

28 changes: 0 additions & 28 deletions src/generate_rdef.sh

This file was deleted.

30 changes: 0 additions & 30 deletions src/icons/fileopen.xpm

This file was deleted.

25 changes: 0 additions & 25 deletions src/icons/firstpage.xpm

This file was deleted.

24 changes: 0 additions & 24 deletions src/icons/lastpage.xpm

This file was deleted.

30 changes: 0 additions & 30 deletions src/icons/next.xpm

This file was deleted.

24 changes: 0 additions & 24 deletions src/icons/nextpage.xpm

This file was deleted.

25 changes: 0 additions & 25 deletions src/icons/prevpage.xpm

This file was deleted.

28 changes: 0 additions & 28 deletions src/icons/printpage.xpm

This file was deleted.

0 comments on commit 0a6ead9

Please sign in to comment.